blob: b22eb049e27d55e6cc37ed2057f1bc9175df487b [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
45#include <linux/mii.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
48#include <linux/cpu.h>
49#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020050#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000051#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000052#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040053#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070054
55#include "e1000.h"
56
Bruce Allanb3ccf262011-05-19 01:53:41 +000057#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000058
Bruce Allan076d8072012-08-17 06:18:23 +000059#define DRV_VERSION "2.1.4" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
stephen hemmingerb3f4d592012-03-13 06:04:20 +000063#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64static int debug = -1;
65module_param(debug, int, 0);
66MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
67
Bruce Allan78cd29d2011-03-24 03:09:03 +000068static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
69
Auke Kokbc7f75f2007-09-17 12:30:59 -070070static const struct e1000_info *e1000_info_tbl[] = {
71 [board_82571] = &e1000_82571_info,
72 [board_82572] = &e1000_82572_info,
73 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070074 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000075 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070076 [board_80003es2lan] = &e1000_es2_info,
77 [board_ich8lan] = &e1000_ich8_info,
78 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070079 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000080 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000081 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000082 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070083};
84
Taku Izumi84f4ee92010-04-27 14:39:08 +000085struct e1000_reg_info {
86 u32 ofs;
87 char *name;
88};
89
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
91#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
92#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
93#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
94#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
Bruce Allanaf667a22010-12-31 06:10:01 +000096#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
97#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
98#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
99#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
100#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000101
102static const struct e1000_reg_info e1000_reg_info_tbl[] = {
103
104 /* General Registers */
105 {E1000_CTRL, "CTRL"},
106 {E1000_STATUS, "STATUS"},
107 {E1000_CTRL_EXT, "CTRL_EXT"},
108
109 /* Interrupt Registers */
110 {E1000_ICR, "ICR"},
111
Bruce Allanaf667a22010-12-31 06:10:01 +0000112 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000113 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000114 {E1000_RDLEN(0), "RDLEN"},
115 {E1000_RDH(0), "RDH"},
116 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000117 {E1000_RDTR, "RDTR"},
118 {E1000_RXDCTL(0), "RXDCTL"},
119 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000120 {E1000_RDBAL(0), "RDBAL"},
121 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000122 {E1000_RDFH, "RDFH"},
123 {E1000_RDFT, "RDFT"},
124 {E1000_RDFHS, "RDFHS"},
125 {E1000_RDFTS, "RDFTS"},
126 {E1000_RDFPC, "RDFPC"},
127
Bruce Allanaf667a22010-12-31 06:10:01 +0000128 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000129 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000130 {E1000_TDBAL(0), "TDBAL"},
131 {E1000_TDBAH(0), "TDBAH"},
132 {E1000_TDLEN(0), "TDLEN"},
133 {E1000_TDH(0), "TDH"},
134 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000135 {E1000_TIDV, "TIDV"},
136 {E1000_TXDCTL(0), "TXDCTL"},
137 {E1000_TADV, "TADV"},
138 {E1000_TARC(0), "TARC"},
139 {E1000_TDFH, "TDFH"},
140 {E1000_TDFT, "TDFT"},
141 {E1000_TDFHS, "TDFHS"},
142 {E1000_TDFTS, "TDFTS"},
143 {E1000_TDFPC, "TDFPC"},
144
145 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000146 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000147};
148
Bruce Allane921eb12012-11-28 09:28:37 +0000149/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000150 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000151 * @hw: pointer to the HW structure
152 * @reginfo: pointer to the register info table
153 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000154static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
155{
156 int n = 0;
157 char rname[16];
158 u32 regs[8];
159
160 switch (reginfo->ofs) {
161 case E1000_RXDCTL(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_RXDCTL(n));
164 break;
165 case E1000_TXDCTL(0):
166 for (n = 0; n < 2; n++)
167 regs[n] = __er32(hw, E1000_TXDCTL(n));
168 break;
169 case E1000_TARC(0):
170 for (n = 0; n < 2; n++)
171 regs[n] = __er32(hw, E1000_TARC(n));
172 break;
173 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000174 pr_info("%-15s %08x\n",
175 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176 return;
177 }
178
179 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000180 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000181}
182
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000183static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
184 struct e1000_buffer *bi)
185{
186 int i;
187 struct e1000_ps_page *ps_page;
188
189 for (i = 0; i < adapter->rx_ps_pages; i++) {
190 ps_page = &bi->ps_pages[i];
191
192 if (ps_page->page) {
193 pr_info("packet dump for ps_page %d:\n", i);
194 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
195 16, 1, page_address(ps_page->page),
196 PAGE_SIZE, true);
197 }
198 }
199}
200
Bruce Allane921eb12012-11-28 09:28:37 +0000201/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000202 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000203 * @adapter: board private structure
204 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000205static void e1000e_dump(struct e1000_adapter *adapter)
206{
207 struct net_device *netdev = adapter->netdev;
208 struct e1000_hw *hw = &adapter->hw;
209 struct e1000_reg_info *reginfo;
210 struct e1000_ring *tx_ring = adapter->tx_ring;
211 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000212 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000213 __le64 a;
214 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000215 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000216 struct e1000_buffer *buffer_info;
217 struct e1000_ring *rx_ring = adapter->rx_ring;
218 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000219 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000220 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000221 __le64 a;
222 __le64 b;
223 __le64 c;
224 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000225 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 u32 staterr;
227 int i = 0;
228
229 if (!netif_msg_hw(adapter))
230 return;
231
232 /* Print netdevice Info */
233 if (netdev) {
234 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000235 pr_info("Device Name state trans_start last_rx\n");
236 pr_info("%-15s %016lX %016lX %016lX\n",
237 netdev->name, netdev->state, netdev->trans_start,
238 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000239 }
240
241 /* Print Registers */
242 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000243 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
245 reginfo->name; reginfo++) {
246 e1000_regdump(hw, reginfo);
247 }
248
Bruce Allanaf667a22010-12-31 06:10:01 +0000249 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000250 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000251 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000252
Bruce Allanaf667a22010-12-31 06:10:01 +0000253 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000254 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000255 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000256 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
257 0, tx_ring->next_to_use, tx_ring->next_to_clean,
258 (unsigned long long)buffer_info->dma,
259 buffer_info->length,
260 buffer_info->next_to_watch,
261 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000262
Bruce Allanaf667a22010-12-31 06:10:01 +0000263 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000264 if (!netif_msg_tx_done(adapter))
265 goto rx_ring_summary;
266
Bruce Allanaf667a22010-12-31 06:10:01 +0000267 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000268
269 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
270 *
271 * Legacy Transmit Descriptor
272 * +--------------------------------------------------------------+
273 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
274 * +--------------------------------------------------------------+
275 * 8 | Special | CSS | Status | CMD | CSO | Length |
276 * +--------------------------------------------------------------+
277 * 63 48 47 36 35 32 31 24 23 16 15 0
278 *
279 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
280 * 63 48 47 40 39 32 31 16 15 8 7 0
281 * +----------------------------------------------------------------+
282 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
283 * +----------------------------------------------------------------+
284 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
285 * +----------------------------------------------------------------+
286 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
287 *
288 * Extended Data Descriptor (DTYP=0x1)
289 * +----------------------------------------------------------------+
290 * 0 | Buffer Address [63:0] |
291 * +----------------------------------------------------------------+
292 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
293 * +----------------------------------------------------------------+
294 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
295 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000296 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
297 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
298 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000299 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000300 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000301 tx_desc = E1000_TX_DESC(*tx_ring, i);
302 buffer_info = &tx_ring->buffer_info[i];
303 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000304 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000305 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000307 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000309 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000311 next_desc = "";
312 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
313 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
314 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
315 i,
316 (unsigned long long)le64_to_cpu(u0->a),
317 (unsigned long long)le64_to_cpu(u0->b),
318 (unsigned long long)buffer_info->dma,
319 buffer_info->length, buffer_info->next_to_watch,
320 (unsigned long long)buffer_info->time_stamp,
321 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000322
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000323 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000325 16, 1, buffer_info->skb->data,
326 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000327 }
328
Bruce Allanaf667a22010-12-31 06:10:01 +0000329 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000330rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000331 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000332 pr_info("Queue [NTU] [NTC]\n");
333 pr_info(" %5d %5X %5X\n",
334 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000335
Bruce Allanaf667a22010-12-31 06:10:01 +0000336 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000337 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000338 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000339
Bruce Allanaf667a22010-12-31 06:10:01 +0000340 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000341 switch (adapter->rx_ps_pages) {
342 case 1:
343 case 2:
344 case 3:
345 /* [Extended] Packet Split Receive Descriptor Format
346 *
347 * +-----------------------------------------------------+
348 * 0 | Buffer Address 0 [63:0] |
349 * +-----------------------------------------------------+
350 * 8 | Buffer Address 1 [63:0] |
351 * +-----------------------------------------------------+
352 * 16 | Buffer Address 2 [63:0] |
353 * +-----------------------------------------------------+
354 * 24 | Buffer Address 3 [63:0] |
355 * +-----------------------------------------------------+
356 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000357 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000358 /* [Extended] Receive Descriptor (Write-Back) Format
359 *
360 * 63 48 47 32 31 13 12 8 7 4 3 0
361 * +------------------------------------------------------+
362 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
363 * | Checksum | Ident | | Queue | | Type |
364 * +------------------------------------------------------+
365 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
366 * +------------------------------------------------------+
367 * 63 48 47 32 31 20 19 0
368 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000369 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000370 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000371 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000372 buffer_info = &rx_ring->buffer_info[i];
373 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
374 u1 = (struct my_u1 *)rx_desc_ps;
375 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000376 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000377
378 if (i == rx_ring->next_to_use)
379 next_desc = " NTU";
380 else if (i == rx_ring->next_to_clean)
381 next_desc = " NTC";
382 else
383 next_desc = "";
384
Taku Izumi84f4ee92010-04-27 14:39:08 +0000385 if (staterr & E1000_RXD_STAT_DD) {
386 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000387 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
388 "RWB", i,
389 (unsigned long long)le64_to_cpu(u1->a),
390 (unsigned long long)le64_to_cpu(u1->b),
391 (unsigned long long)le64_to_cpu(u1->c),
392 (unsigned long long)le64_to_cpu(u1->d),
393 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000394 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000395 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
396 "R ", i,
397 (unsigned long long)le64_to_cpu(u1->a),
398 (unsigned long long)le64_to_cpu(u1->b),
399 (unsigned long long)le64_to_cpu(u1->c),
400 (unsigned long long)le64_to_cpu(u1->d),
401 (unsigned long long)buffer_info->dma,
402 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000403
404 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000405 e1000e_dump_ps_pages(adapter,
406 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000407 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000408 }
409 break;
410 default:
411 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000412 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000413 *
Bruce Allan5f450212011-07-22 06:21:46 +0000414 * +-----------------------------------------------------+
415 * 0 | Buffer Address [63:0] |
416 * +-----------------------------------------------------+
417 * 8 | Reserved |
418 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000419 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000420 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000421 /* Extended Receive Descriptor (Write-Back) Format
422 *
423 * 63 48 47 32 31 24 23 4 3 0
424 * +------------------------------------------------------+
425 * | RSS Hash | | | |
426 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
427 * | Packet | IP | | | Type |
428 * | Checksum | Ident | | | |
429 * +------------------------------------------------------+
430 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
431 * +------------------------------------------------------+
432 * 63 48 47 32 31 20 19 0
433 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000434 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000435
436 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000437 const char *next_desc;
438
Taku Izumi84f4ee92010-04-27 14:39:08 +0000439 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000440 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
441 u1 = (struct my_u1 *)rx_desc;
442 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000443
444 if (i == rx_ring->next_to_use)
445 next_desc = " NTU";
446 else if (i == rx_ring->next_to_clean)
447 next_desc = " NTC";
448 else
449 next_desc = "";
450
Bruce Allan5f450212011-07-22 06:21:46 +0000451 if (staterr & E1000_RXD_STAT_DD) {
452 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000453 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
454 "RWB", i,
455 (unsigned long long)le64_to_cpu(u1->a),
456 (unsigned long long)le64_to_cpu(u1->b),
457 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000458 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000459 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
460 "R ", i,
461 (unsigned long long)le64_to_cpu(u1->a),
462 (unsigned long long)le64_to_cpu(u1->b),
463 (unsigned long long)buffer_info->dma,
464 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000465
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000466 if (netif_msg_pktdata(adapter) &&
467 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000468 print_hex_dump(KERN_INFO, "",
469 DUMP_PREFIX_ADDRESS, 16,
470 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000471 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000472 adapter->rx_buffer_len,
473 true);
474 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000475 }
476 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000477}
478
Auke Kokbc7f75f2007-09-17 12:30:59 -0700479/**
480 * e1000_desc_unused - calculate if we have unused descriptors
481 **/
482static int e1000_desc_unused(struct e1000_ring *ring)
483{
484 if (ring->next_to_clean > ring->next_to_use)
485 return ring->next_to_clean - ring->next_to_use - 1;
486
487 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
488}
489
490/**
Bruce Allanad680762008-03-28 09:15:03 -0700491 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700492 * @adapter: board private structure
493 * @status: descriptor status field as written by hardware
494 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
495 * @skb: pointer to sk_buff to be indicated to stack
496 **/
497static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000498 struct net_device *netdev, struct sk_buff *skb,
Al Viroa39fe742007-12-11 19:50:34 +0000499 u8 status, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700500{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000501 u16 tag = le16_to_cpu(vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502 skb->protocol = eth_type_trans(skb, netdev);
503
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000504 if (status & E1000_RXD_STAT_VP)
505 __vlan_hwaccel_put_tag(skb, tag);
506
507 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508}
509
510/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000511 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000512 * @adapter: board private structure
513 * @status_err: receive descriptor status and error fields
514 * @csum: receive descriptor csum field
515 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700516 **/
517static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000518 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700519{
520 u16 status = (u16)status_err;
521 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700522
523 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524
Bruce Allanafd12932012-01-05 00:34:05 +0000525 /* Rx checksum disabled */
526 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
527 return;
528
Auke Kokbc7f75f2007-09-17 12:30:59 -0700529 /* Ignore Checksum bit is set */
530 if (status & E1000_RXD_STAT_IXSM)
531 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000532
Bruce Allan2e1706f2012-06-30 20:02:42 +0000533 /* TCP/UDP checksum error bit or IP checksum error bit is set */
534 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700535 /* let the stack verify checksum errors */
536 adapter->hw_csum_err++;
537 return;
538 }
539
540 /* TCP/UDP Checksum has not been calculated */
541 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
542 return;
543
544 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000545 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700546 adapter->hw_csum_good++;
547}
548
Bruce Allan55aa6982011-12-16 00:45:45 +0000549static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700550{
Bruce Allan55aa6982011-12-16 00:45:45 +0000551 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700552 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000553 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700554
Bruce Allanbdc125f2012-03-20 03:47:52 +0000555 writel(i, rx_ring->tail);
556
557 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700558 u32 rctl = er32(RCTL);
559 ew32(RCTL, rctl & ~E1000_RCTL_EN);
560 e_err("ME firmware caused invalid RDT - resetting\n");
561 schedule_work(&adapter->reset_task);
562 }
563}
564
Bruce Allan55aa6982011-12-16 00:45:45 +0000565static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700566{
Bruce Allan55aa6982011-12-16 00:45:45 +0000567 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700568 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000569 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700570
Bruce Allanbdc125f2012-03-20 03:47:52 +0000571 writel(i, tx_ring->tail);
572
573 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700574 u32 tctl = er32(TCTL);
575 ew32(TCTL, tctl & ~E1000_TCTL_EN);
576 e_err("ME firmware caused invalid TDT - resetting\n");
577 schedule_work(&adapter->reset_task);
578 }
579}
580
581/**
Bruce Allan5f450212011-07-22 06:21:46 +0000582 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000583 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000585static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000586 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587{
Bruce Allan55aa6982011-12-16 00:45:45 +0000588 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700589 struct net_device *netdev = adapter->netdev;
590 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000591 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700592 struct e1000_buffer *buffer_info;
593 struct sk_buff *skb;
594 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000595 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596
597 i = rx_ring->next_to_use;
598 buffer_info = &rx_ring->buffer_info[i];
599
600 while (cleaned_count--) {
601 skb = buffer_info->skb;
602 if (skb) {
603 skb_trim(skb, 0);
604 goto map_skb;
605 }
606
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000607 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608 if (!skb) {
609 /* Better luck next round */
610 adapter->alloc_rx_buff_failed++;
611 break;
612 }
613
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 buffer_info->skb = skb;
615map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000616 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700617 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000618 DMA_FROM_DEVICE);
619 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000620 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700621 adapter->rx_dma_failed++;
622 break;
623 }
624
Bruce Allan5f450212011-07-22 06:21:46 +0000625 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
626 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627
Tom Herbert50849d72010-05-05 14:02:49 +0000628 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000629 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000630 * know there are new descriptors to fetch. (Only
631 * applicable for weak-ordered memory model archs,
632 * such as IA-64).
633 */
634 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700635 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000636 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700637 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000638 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000639 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 i++;
641 if (i == rx_ring->count)
642 i = 0;
643 buffer_info = &rx_ring->buffer_info[i];
644 }
645
Tom Herbert50849d72010-05-05 14:02:49 +0000646 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647}
648
649/**
650 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000651 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000653static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000654 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655{
Bruce Allan55aa6982011-12-16 00:45:45 +0000656 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700657 struct net_device *netdev = adapter->netdev;
658 struct pci_dev *pdev = adapter->pdev;
659 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 struct e1000_buffer *buffer_info;
661 struct e1000_ps_page *ps_page;
662 struct sk_buff *skb;
663 unsigned int i, j;
664
665 i = rx_ring->next_to_use;
666 buffer_info = &rx_ring->buffer_info[i];
667
668 while (cleaned_count--) {
669 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
670
671 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700672 ps_page = &buffer_info->ps_pages[j];
673 if (j >= adapter->rx_ps_pages) {
674 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000675 rx_desc->read.buffer_addr[j + 1] =
676 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700677 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700678 }
Auke Kok47f44e42007-10-25 13:57:44 -0700679 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000680 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700681 if (!ps_page->page) {
682 adapter->alloc_rx_buff_failed++;
683 goto no_buffers;
684 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000685 ps_page->dma = dma_map_page(&pdev->dev,
686 ps_page->page,
687 0, PAGE_SIZE,
688 DMA_FROM_DEVICE);
689 if (dma_mapping_error(&pdev->dev,
690 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700691 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000692 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700693 adapter->rx_dma_failed++;
694 goto no_buffers;
695 }
696 }
Bruce Allane921eb12012-11-28 09:28:37 +0000697 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700698 * didn't change because each write-back
699 * erases this info.
700 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000701 rx_desc->read.buffer_addr[j + 1] =
702 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703 }
704
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000705 skb = __netdev_alloc_skb_ip_align(netdev,
706 adapter->rx_ps_bsize0,
707 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708
709 if (!skb) {
710 adapter->alloc_rx_buff_failed++;
711 break;
712 }
713
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000715 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700716 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000717 DMA_FROM_DEVICE);
718 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000719 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700720 adapter->rx_dma_failed++;
721 /* cleanup skb */
722 dev_kfree_skb_any(skb);
723 buffer_info->skb = NULL;
724 break;
725 }
726
727 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
728
Tom Herbert50849d72010-05-05 14:02:49 +0000729 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000730 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000731 * know there are new descriptors to fetch. (Only
732 * applicable for weak-ordered memory model archs,
733 * such as IA-64).
734 */
735 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700736 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000737 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700738 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000739 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000740 }
741
Auke Kokbc7f75f2007-09-17 12:30:59 -0700742 i++;
743 if (i == rx_ring->count)
744 i = 0;
745 buffer_info = &rx_ring->buffer_info[i];
746 }
747
748no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000749 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700750}
751
752/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700753 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000754 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700755 * @cleaned_count: number of buffers to allocate this pass
756 **/
757
Bruce Allan55aa6982011-12-16 00:45:45 +0000758static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000759 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700760{
Bruce Allan55aa6982011-12-16 00:45:45 +0000761 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700762 struct net_device *netdev = adapter->netdev;
763 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000764 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700765 struct e1000_buffer *buffer_info;
766 struct sk_buff *skb;
767 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000768 unsigned int bufsz = 256 - 16 /* for skb_reserve */;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700769
770 i = rx_ring->next_to_use;
771 buffer_info = &rx_ring->buffer_info[i];
772
773 while (cleaned_count--) {
774 skb = buffer_info->skb;
775 if (skb) {
776 skb_trim(skb, 0);
777 goto check_page;
778 }
779
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000780 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700781 if (unlikely(!skb)) {
782 /* Better luck next round */
783 adapter->alloc_rx_buff_failed++;
784 break;
785 }
786
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700787 buffer_info->skb = skb;
788check_page:
789 /* allocate a new page if necessary */
790 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000791 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700792 if (unlikely(!buffer_info->page)) {
793 adapter->alloc_rx_buff_failed++;
794 break;
795 }
796 }
797
798 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000799 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700800 buffer_info->page, 0,
801 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000802 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700803
Bruce Allan5f450212011-07-22 06:21:46 +0000804 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
805 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700806
807 if (unlikely(++i == rx_ring->count))
808 i = 0;
809 buffer_info = &rx_ring->buffer_info[i];
810 }
811
812 if (likely(rx_ring->next_to_use != i)) {
813 rx_ring->next_to_use = i;
814 if (unlikely(i-- == 0))
815 i = (rx_ring->count - 1);
816
817 /* Force memory writes to complete before letting h/w
818 * know there are new descriptors to fetch. (Only
819 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000820 * such as IA-64).
821 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700822 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700823 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000824 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700825 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000826 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700827 }
828}
829
Bruce Allan70495a52012-01-11 01:26:50 +0000830static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
831 struct sk_buff *skb)
832{
833 if (netdev->features & NETIF_F_RXHASH)
834 skb->rxhash = le32_to_cpu(rss);
835}
836
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700837/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000838 * e1000_clean_rx_irq - Send received data up the network stack
839 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700840 *
841 * the return value indicates whether actual cleaning was done, there
842 * is no guarantee that everything was cleaned
843 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000844static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
845 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700846{
Bruce Allan55aa6982011-12-16 00:45:45 +0000847 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848 struct net_device *netdev = adapter->netdev;
849 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000850 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000851 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000853 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854 unsigned int i;
855 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000856 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700857 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
858
859 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000860 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
861 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700862 buffer_info = &rx_ring->buffer_info[i];
863
Bruce Allan5f450212011-07-22 06:21:46 +0000864 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700865 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700866
867 if (*work_done >= work_to_do)
868 break;
869 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000870 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 skb = buffer_info->skb;
873 buffer_info->skb = NULL;
874
875 prefetch(skb->data - NET_IP_ALIGN);
876
877 i++;
878 if (i == rx_ring->count)
879 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000880 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700881 prefetch(next_rxd);
882
883 next_buffer = &rx_ring->buffer_info[i];
884
Rusty Russell3db1cd52011-12-19 13:56:45 +0000885 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700886 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000887 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700888 buffer_info->dma,
889 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000890 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700891 buffer_info->dma = 0;
892
Bruce Allan5f450212011-07-22 06:21:46 +0000893 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894
Bruce Allane921eb12012-11-28 09:28:37 +0000895 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000896 * packet, if that's the case we need to toss it. In fact, we
897 * need to toss every packet with the EOP bit clear and the
898 * next frame that _does_ have the EOP bit set, as it is by
899 * definition only a frame fragment
900 */
Bruce Allan5f450212011-07-22 06:21:46 +0000901 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000902 adapter->flags2 |= FLAG2_IS_DISCARDING;
903
904 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000906 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700907 /* recycle */
908 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000909 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000910 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 goto next_desc;
912 }
913
Ben Greearcf955e62012-02-11 15:39:51 +0000914 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
915 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916 /* recycle */
917 buffer_info->skb = skb;
918 goto next_desc;
919 }
920
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000921 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000922 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
923 /* If configured to store CRC, don't subtract FCS,
924 * but keep the FCS bytes out of the total_rx_bytes
925 * counter
926 */
927 if (netdev->features & NETIF_F_RXFCS)
928 total_rx_bytes -= 4;
929 else
930 length -= 4;
931 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000932
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 total_rx_bytes += length;
934 total_rx_packets++;
935
Bruce Allane921eb12012-11-28 09:28:37 +0000936 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700938 * of reassembly being done in the stack
939 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 if (length < copybreak) {
941 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000942 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700944 skb_copy_to_linear_data_offset(new_skb,
945 -NET_IP_ALIGN,
946 (skb->data -
947 NET_IP_ALIGN),
948 (length +
949 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 /* save the skb in buffer_info as good */
951 buffer_info->skb = skb;
952 skb = new_skb;
953 }
954 /* else just continue with the old one */
955 }
956 /* end copybreak code */
957 skb_put(skb, length);
958
959 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000960 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961
Bruce Allan70495a52012-01-11 01:26:50 +0000962 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
963
Bruce Allan5f450212011-07-22 06:21:46 +0000964 e1000_receive_skb(adapter, netdev, skb, staterr,
965 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966
967next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +0000968 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969
970 /* return some buffers to hardware, one at a time is too slow */
971 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +0000972 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000973 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700974 cleaned_count = 0;
975 }
976
977 /* use prefetched values */
978 rx_desc = next_rxd;
979 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000980
981 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 }
983 rx_ring->next_to_clean = i;
984
985 cleaned_count = e1000_desc_unused(rx_ring);
986 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +0000987 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -0700990 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 return cleaned;
992}
993
Bruce Allan55aa6982011-12-16 00:45:45 +0000994static void e1000_put_txbuf(struct e1000_ring *tx_ring,
995 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996{
Bruce Allan55aa6982011-12-16 00:45:45 +0000997 struct e1000_adapter *adapter = tx_ring->adapter;
998
Alexander Duyck03b13202009-12-02 16:45:31 +0000999 if (buffer_info->dma) {
1000 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001001 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1002 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001003 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001004 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1005 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001006 buffer_info->dma = 0;
1007 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 if (buffer_info->skb) {
1009 dev_kfree_skb_any(buffer_info->skb);
1010 buffer_info->skb = NULL;
1011 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001012 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013}
1014
Bruce Allan41cec6f2009-11-20 23:28:56 +00001015static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001017 struct e1000_adapter *adapter = container_of(work,
1018 struct e1000_adapter,
1019 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001020 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 struct e1000_ring *tx_ring = adapter->tx_ring;
1022 unsigned int i = tx_ring->next_to_clean;
1023 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1024 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001025 struct e1000_hw *hw = &adapter->hw;
1026 u16 phy_status, phy_1000t_status, phy_ext_status;
1027 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001029 if (test_bit(__E1000_DOWN, &adapter->state))
1030 return;
1031
Jeff Kirsher09357b02011-11-18 14:25:00 +00001032 if (!adapter->tx_hang_recheck &&
1033 (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001034 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001035 * flush pending descriptor writebacks to memory
1036 */
1037 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1038 /* execute the writes immediately */
1039 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001040 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001041 * the write is successful
1042 */
1043 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1044 /* execute the writes immediately */
1045 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001046 adapter->tx_hang_recheck = true;
1047 return;
1048 }
1049 /* Real hang detected */
1050 adapter->tx_hang_recheck = false;
1051 netif_stop_queue(netdev);
1052
Bruce Allan41cec6f2009-11-20 23:28:56 +00001053 e1e_rphy(hw, PHY_STATUS, &phy_status);
1054 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1055 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1056
1057 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1058
1059 /* detected Hardware unit hang */
1060 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001061 " TDH <%x>\n"
1062 " TDT <%x>\n"
1063 " next_to_use <%x>\n"
1064 " next_to_clean <%x>\n"
1065 "buffer_info[next_to_clean]:\n"
1066 " time_stamp <%lx>\n"
1067 " next_to_watch <%x>\n"
1068 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001069 " next_to_watch.status <%x>\n"
1070 "MAC Status <%x>\n"
1071 "PHY Status <%x>\n"
1072 "PHY 1000BASE-T Status <%x>\n"
1073 "PHY Extended Status <%x>\n"
1074 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001075 readl(tx_ring->head),
1076 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001077 tx_ring->next_to_use,
1078 tx_ring->next_to_clean,
1079 tx_ring->buffer_info[eop].time_stamp,
1080 eop,
1081 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001082 eop_desc->upper.fields.status,
1083 er32(STATUS),
1084 phy_status,
1085 phy_1000t_status,
1086 phy_ext_status,
1087 pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001088
1089 /* Suggest workaround for known h/w issue */
1090 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1091 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092}
1093
1094/**
1095 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001096 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 *
1098 * the return value indicates whether actual cleaning was done, there
1099 * is no guarantee that everything was cleaned
1100 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001101static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102{
Bruce Allan55aa6982011-12-16 00:45:45 +00001103 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 struct net_device *netdev = adapter->netdev;
1105 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 struct e1000_tx_desc *tx_desc, *eop_desc;
1107 struct e1000_buffer *buffer_info;
1108 unsigned int i, eop;
1109 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001110 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001111 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112
1113 i = tx_ring->next_to_clean;
1114 eop = tx_ring->buffer_info[i].next_to_watch;
1115 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1116
Alexander Duyck12d04a32009-03-25 22:05:03 +00001117 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1118 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001119 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001120 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001121 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001122 tx_desc = E1000_TX_DESC(*tx_ring, i);
1123 buffer_info = &tx_ring->buffer_info[i];
1124 cleaned = (i == eop);
1125
1126 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001127 total_tx_packets += buffer_info->segs;
1128 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001129 if (buffer_info->skb) {
1130 bytes_compl += buffer_info->skb->len;
1131 pkts_compl++;
1132 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 }
1134
Bruce Allan55aa6982011-12-16 00:45:45 +00001135 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 tx_desc->upper.data = 0;
1137
1138 i++;
1139 if (i == tx_ring->count)
1140 i = 0;
1141 }
1142
Terry Loftindac87612010-04-09 10:29:49 +00001143 if (i == tx_ring->next_to_use)
1144 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 eop = tx_ring->buffer_info[i].next_to_watch;
1146 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001147 }
1148
1149 tx_ring->next_to_clean = i;
1150
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001151 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1152
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001154 if (count && netif_carrier_ok(netdev) &&
1155 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 /* Make sure that anybody stopping the queue after this
1157 * sees the new next_to_clean.
1158 */
1159 smp_mb();
1160
1161 if (netif_queue_stopped(netdev) &&
1162 !(test_bit(__E1000_DOWN, &adapter->state))) {
1163 netif_wake_queue(netdev);
1164 ++adapter->restart_queue;
1165 }
1166 }
1167
1168 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001169 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001170 * check with the clearing of time_stamp and movement of i
1171 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001172 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001173 if (tx_ring->buffer_info[i].time_stamp &&
1174 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001175 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001176 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001177 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001178 else
1179 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 }
1181 adapter->total_tx_bytes += total_tx_bytes;
1182 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001183 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184}
1185
1186/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001188 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 *
1190 * the return value indicates whether actual cleaning was done, there
1191 * is no guarantee that everything was cleaned
1192 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001193static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1194 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195{
Bruce Allan55aa6982011-12-16 00:45:45 +00001196 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001197 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1199 struct net_device *netdev = adapter->netdev;
1200 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001201 struct e1000_buffer *buffer_info, *next_buffer;
1202 struct e1000_ps_page *ps_page;
1203 struct sk_buff *skb;
1204 unsigned int i, j;
1205 u32 length, staterr;
1206 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001207 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1209
1210 i = rx_ring->next_to_clean;
1211 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1212 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1213 buffer_info = &rx_ring->buffer_info[i];
1214
1215 while (staterr & E1000_RXD_STAT_DD) {
1216 if (*work_done >= work_to_do)
1217 break;
1218 (*work_done)++;
1219 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001220 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221
1222 /* in the packet split case this is header only */
1223 prefetch(skb->data - NET_IP_ALIGN);
1224
1225 i++;
1226 if (i == rx_ring->count)
1227 i = 0;
1228 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1229 prefetch(next_rxd);
1230
1231 next_buffer = &rx_ring->buffer_info[i];
1232
Rusty Russell3db1cd52011-12-19 13:56:45 +00001233 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001235 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001236 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 buffer_info->dma = 0;
1238
Bruce Allanaf667a22010-12-31 06:10:01 +00001239 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001240 if (!(staterr & E1000_RXD_STAT_EOP))
1241 adapter->flags2 |= FLAG2_IS_DISCARDING;
1242
1243 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001244 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001246 if (staterr & E1000_RXD_STAT_EOP)
1247 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 goto next_desc;
1249 }
1250
Ben Greearcf955e62012-02-11 15:39:51 +00001251 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1252 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 dev_kfree_skb_irq(skb);
1254 goto next_desc;
1255 }
1256
1257 length = le16_to_cpu(rx_desc->wb.middle.length0);
1258
1259 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001260 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 dev_kfree_skb_irq(skb);
1262 goto next_desc;
1263 }
1264
1265 /* Good Receive */
1266 skb_put(skb, length);
1267
1268 {
Bruce Allane921eb12012-11-28 09:28:37 +00001269 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001270 * it more efficient than reusing j
1271 */
1272 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001273
Bruce Allane921eb12012-11-28 09:28:37 +00001274 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001275 * packet throughput, so unsplit small packets and
1276 * save the alloc/put only valid in softirq (napi)
1277 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001278 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001279 if (l1 && (l1 <= copybreak) &&
1280 ((length + l1) <= adapter->rx_ps_bsize0)) {
1281 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001282
Bruce Allan0e15df42012-01-31 06:37:11 +00001283 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001284
Bruce Allane921eb12012-11-28 09:28:37 +00001285 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001286 * kmap_atomic, so we can't hold the mapping
1287 * very long
1288 */
1289 dma_sync_single_for_cpu(&pdev->dev,
1290 ps_page->dma,
1291 PAGE_SIZE,
1292 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001293 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001294 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001295 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001296 dma_sync_single_for_device(&pdev->dev,
1297 ps_page->dma,
1298 PAGE_SIZE,
1299 DMA_FROM_DEVICE);
1300
1301 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001302 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1303 if (!(netdev->features & NETIF_F_RXFCS))
1304 l1 -= 4;
1305 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001306
1307 skb_put(skb, l1);
1308 goto copydone;
1309 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310 }
1311
1312 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1313 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1314 if (!length)
1315 break;
1316
Auke Kok47f44e42007-10-25 13:57:44 -07001317 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001318 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1319 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001320 ps_page->dma = 0;
1321 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1322 ps_page->page = NULL;
1323 skb->len += length;
1324 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001325 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001326 }
1327
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001328 /* strip the ethernet crc, problem is we're using pages now so
1329 * this whole operation can get a little cpu intensive
1330 */
Ben Greear01840392012-02-11 15:39:25 +00001331 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1332 if (!(netdev->features & NETIF_F_RXFCS))
1333 pskb_trim(skb, skb->len - 4);
1334 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001335
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336copydone:
1337 total_rx_bytes += skb->len;
1338 total_rx_packets++;
1339
Bruce Allan2e1706f2012-06-30 20:02:42 +00001340 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001341
Bruce Allan70495a52012-01-11 01:26:50 +00001342 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1343
Auke Kokbc7f75f2007-09-17 12:30:59 -07001344 if (rx_desc->wb.upper.header_status &
1345 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1346 adapter->rx_hdr_split++;
1347
1348 e1000_receive_skb(adapter, netdev, skb,
1349 staterr, rx_desc->wb.middle.vlan);
1350
1351next_desc:
1352 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1353 buffer_info->skb = NULL;
1354
1355 /* return some buffers to hardware, one at a time is too slow */
1356 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001357 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001358 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001359 cleaned_count = 0;
1360 }
1361
1362 /* use prefetched values */
1363 rx_desc = next_rxd;
1364 buffer_info = next_buffer;
1365
1366 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1367 }
1368 rx_ring->next_to_clean = i;
1369
1370 cleaned_count = e1000_desc_unused(rx_ring);
1371 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001372 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001373
Auke Kokbc7f75f2007-09-17 12:30:59 -07001374 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001375 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001376 return cleaned;
1377}
1378
1379/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001380 * e1000_consume_page - helper function
1381 **/
1382static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1383 u16 length)
1384{
1385 bi->page = NULL;
1386 skb->len += length;
1387 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001388 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001389}
1390
1391/**
1392 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1393 * @adapter: board private structure
1394 *
1395 * the return value indicates whether actual cleaning was done, there
1396 * is no guarantee that everything was cleaned
1397 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001398static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1399 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001400{
Bruce Allan55aa6982011-12-16 00:45:45 +00001401 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001402 struct net_device *netdev = adapter->netdev;
1403 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001404 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001405 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001406 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001407 unsigned int i;
1408 int cleaned_count = 0;
1409 bool cleaned = false;
1410 unsigned int total_rx_bytes=0, total_rx_packets=0;
1411
1412 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001413 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1414 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001415 buffer_info = &rx_ring->buffer_info[i];
1416
Bruce Allan5f450212011-07-22 06:21:46 +00001417 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001418 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001419
1420 if (*work_done >= work_to_do)
1421 break;
1422 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001423 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001424
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001425 skb = buffer_info->skb;
1426 buffer_info->skb = NULL;
1427
1428 ++i;
1429 if (i == rx_ring->count)
1430 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001431 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001432 prefetch(next_rxd);
1433
1434 next_buffer = &rx_ring->buffer_info[i];
1435
1436 cleaned = true;
1437 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001438 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1439 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001440 buffer_info->dma = 0;
1441
Bruce Allan5f450212011-07-22 06:21:46 +00001442 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001443
1444 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001445 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001446 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1447 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001448 /* recycle both page and skb */
1449 buffer_info->skb = skb;
1450 /* an error means any chain goes out the window too */
1451 if (rx_ring->rx_skb_top)
1452 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1453 rx_ring->rx_skb_top = NULL;
1454 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001455 }
1456
Bruce Allanf0f1a172010-12-11 05:53:32 +00001457#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001458 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459 /* this descriptor is only the beginning (or middle) */
1460 if (!rxtop) {
1461 /* this is the beginning of a chain */
1462 rxtop = skb;
1463 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1464 0, length);
1465 } else {
1466 /* this is the middle of a chain */
1467 skb_fill_page_desc(rxtop,
1468 skb_shinfo(rxtop)->nr_frags,
1469 buffer_info->page, 0, length);
1470 /* re-use the skb, only consumed the page */
1471 buffer_info->skb = skb;
1472 }
1473 e1000_consume_page(buffer_info, rxtop, length);
1474 goto next_desc;
1475 } else {
1476 if (rxtop) {
1477 /* end of the chain */
1478 skb_fill_page_desc(rxtop,
1479 skb_shinfo(rxtop)->nr_frags,
1480 buffer_info->page, 0, length);
1481 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001482 * page
1483 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001484 buffer_info->skb = skb;
1485 skb = rxtop;
1486 rxtop = NULL;
1487 e1000_consume_page(buffer_info, skb, length);
1488 } else {
1489 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001490 * copybreak to save the put_page/alloc_page
1491 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001492 if (length <= copybreak &&
1493 skb_tailroom(skb) >= length) {
1494 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001495 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001496 memcpy(skb_tail_pointer(skb), vaddr,
1497 length);
Cong Wang46790262011-11-25 23:14:23 +08001498 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001499 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001500 * buffer_info->page
1501 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001502 skb_put(skb, length);
1503 } else {
1504 skb_fill_page_desc(skb, 0,
1505 buffer_info->page, 0,
1506 length);
1507 e1000_consume_page(buffer_info, skb,
1508 length);
1509 }
1510 }
1511 }
1512
Bruce Allan2e1706f2012-06-30 20:02:42 +00001513 /* Receive Checksum Offload */
1514 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001515
Bruce Allan70495a52012-01-11 01:26:50 +00001516 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1517
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001518 /* probably a little skewed due to removing CRC */
1519 total_rx_bytes += skb->len;
1520 total_rx_packets++;
1521
1522 /* eth type trans needs skb->data to point to something */
1523 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001524 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001525 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 goto next_desc;
1527 }
1528
Bruce Allan5f450212011-07-22 06:21:46 +00001529 e1000_receive_skb(adapter, netdev, skb, staterr,
1530 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001531
1532next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001533 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001534
1535 /* return some buffers to hardware, one at a time is too slow */
1536 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001537 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001538 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001539 cleaned_count = 0;
1540 }
1541
1542 /* use prefetched values */
1543 rx_desc = next_rxd;
1544 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001545
1546 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001547 }
1548 rx_ring->next_to_clean = i;
1549
1550 cleaned_count = e1000_desc_unused(rx_ring);
1551 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001552 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001553
1554 adapter->total_rx_bytes += total_rx_bytes;
1555 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001556 return cleaned;
1557}
1558
1559/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001561 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001563static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564{
Bruce Allan55aa6982011-12-16 00:45:45 +00001565 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001566 struct e1000_buffer *buffer_info;
1567 struct e1000_ps_page *ps_page;
1568 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001569 unsigned int i, j;
1570
1571 /* Free all the Rx ring sk_buffs */
1572 for (i = 0; i < rx_ring->count; i++) {
1573 buffer_info = &rx_ring->buffer_info[i];
1574 if (buffer_info->dma) {
1575 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001576 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001580 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001581 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001582 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001584 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001586 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 buffer_info->dma = 0;
1588 }
1589
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001590 if (buffer_info->page) {
1591 put_page(buffer_info->page);
1592 buffer_info->page = NULL;
1593 }
1594
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 if (buffer_info->skb) {
1596 dev_kfree_skb(buffer_info->skb);
1597 buffer_info->skb = NULL;
1598 }
1599
1600 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001601 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 if (!ps_page->page)
1603 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001604 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1605 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 ps_page->dma = 0;
1607 put_page(ps_page->page);
1608 ps_page->page = NULL;
1609 }
1610 }
1611
1612 /* there also may be some cached data from a chained receive */
1613 if (rx_ring->rx_skb_top) {
1614 dev_kfree_skb(rx_ring->rx_skb_top);
1615 rx_ring->rx_skb_top = NULL;
1616 }
1617
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618 /* Zero out the descriptor ring */
1619 memset(rx_ring->desc, 0, rx_ring->size);
1620
1621 rx_ring->next_to_clean = 0;
1622 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001623 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624
Bruce Allanc5083cf2011-12-16 00:45:40 +00001625 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001626 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1627 e1000e_update_rdt_wa(rx_ring, 0);
1628 else
1629 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001630}
1631
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001632static void e1000e_downshift_workaround(struct work_struct *work)
1633{
1634 struct e1000_adapter *adapter = container_of(work,
1635 struct e1000_adapter, downshift_task);
1636
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001637 if (test_bit(__E1000_DOWN, &adapter->state))
1638 return;
1639
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001640 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1641}
1642
Auke Kokbc7f75f2007-09-17 12:30:59 -07001643/**
1644 * e1000_intr_msi - Interrupt Handler
1645 * @irq: interrupt number
1646 * @data: pointer to a network interface device structure
1647 **/
1648static irqreturn_t e1000_intr_msi(int irq, void *data)
1649{
1650 struct net_device *netdev = data;
1651 struct e1000_adapter *adapter = netdev_priv(netdev);
1652 struct e1000_hw *hw = &adapter->hw;
1653 u32 icr = er32(ICR);
1654
Bruce Allane921eb12012-11-28 09:28:37 +00001655 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001656 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001657 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001658 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001659 * disconnect (LSC) before accessing any PHY registers
1660 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1662 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001663 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001664
Bruce Allane921eb12012-11-28 09:28:37 +00001665 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001667 * adapter in watchdog
1668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 if (netif_carrier_ok(netdev) &&
1670 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1671 /* disable receives */
1672 u32 rctl = er32(RCTL);
1673 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001674 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 }
1676 /* guard against interrupt when we're going down */
1677 if (!test_bit(__E1000_DOWN, &adapter->state))
1678 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1679 }
1680
Ben Hutchings288379f2009-01-19 16:43:59 -08001681 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 adapter->total_tx_bytes = 0;
1683 adapter->total_tx_packets = 0;
1684 adapter->total_rx_bytes = 0;
1685 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001686 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 }
1688
1689 return IRQ_HANDLED;
1690}
1691
1692/**
1693 * e1000_intr - Interrupt Handler
1694 * @irq: interrupt number
1695 * @data: pointer to a network interface device structure
1696 **/
1697static irqreturn_t e1000_intr(int irq, void *data)
1698{
1699 struct net_device *netdev = data;
1700 struct e1000_adapter *adapter = netdev_priv(netdev);
1701 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001703
Bruce Allana68ea772009-11-20 23:23:16 +00001704 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 return IRQ_NONE; /* Not our interrupt */
1706
Bruce Allane921eb12012-11-28 09:28:37 +00001707 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001708 * not set, then the adapter didn't send an interrupt
1709 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001710 if (!(icr & E1000_ICR_INT_ASSERTED))
1711 return IRQ_NONE;
1712
Bruce Allane921eb12012-11-28 09:28:37 +00001713 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001714 * interrupts are masked. No need for the
1715 * IMC write
1716 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717
dave graham573cca82009-02-10 12:52:05 +00001718 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001719 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001720 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001721 * disconnect (LSC) before accessing any PHY registers
1722 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1724 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001725 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726
Bruce Allane921eb12012-11-28 09:28:37 +00001727 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728 * For packet buffer work-around on link down event;
1729 * disable receives here in the ISR and
1730 * reset adapter in watchdog
1731 */
1732 if (netif_carrier_ok(netdev) &&
1733 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1734 /* disable receives */
1735 rctl = er32(RCTL);
1736 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001737 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 }
1739 /* guard against interrupt when we're going down */
1740 if (!test_bit(__E1000_DOWN, &adapter->state))
1741 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1742 }
1743
Ben Hutchings288379f2009-01-19 16:43:59 -08001744 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745 adapter->total_tx_bytes = 0;
1746 adapter->total_tx_packets = 0;
1747 adapter->total_rx_bytes = 0;
1748 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001749 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001750 }
1751
1752 return IRQ_HANDLED;
1753}
1754
Bruce Allan4662e822008-08-26 18:37:06 -07001755static irqreturn_t e1000_msix_other(int irq, void *data)
1756{
1757 struct net_device *netdev = data;
1758 struct e1000_adapter *adapter = netdev_priv(netdev);
1759 struct e1000_hw *hw = &adapter->hw;
1760 u32 icr = er32(ICR);
1761
1762 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001763 if (!test_bit(__E1000_DOWN, &adapter->state))
1764 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001765 return IRQ_NONE;
1766 }
1767
1768 if (icr & adapter->eiac_mask)
1769 ew32(ICS, (icr & adapter->eiac_mask));
1770
1771 if (icr & E1000_ICR_OTHER) {
1772 if (!(icr & E1000_ICR_LSC))
1773 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001774 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001775 /* guard against interrupt when we're going down */
1776 if (!test_bit(__E1000_DOWN, &adapter->state))
1777 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1778 }
1779
1780no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001781 if (!test_bit(__E1000_DOWN, &adapter->state))
1782 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001783
1784 return IRQ_HANDLED;
1785}
1786
1787
1788static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1789{
1790 struct net_device *netdev = data;
1791 struct e1000_adapter *adapter = netdev_priv(netdev);
1792 struct e1000_hw *hw = &adapter->hw;
1793 struct e1000_ring *tx_ring = adapter->tx_ring;
1794
1795
1796 adapter->total_tx_bytes = 0;
1797 adapter->total_tx_packets = 0;
1798
Bruce Allan55aa6982011-12-16 00:45:45 +00001799 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001800 /* Ring was not completely cleaned, so fire another interrupt */
1801 ew32(ICS, tx_ring->ims_val);
1802
1803 return IRQ_HANDLED;
1804}
1805
1806static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1807{
1808 struct net_device *netdev = data;
1809 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001810 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001811
1812 /* Write the ITR value calculated at the end of the
1813 * previous interrupt.
1814 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001815 if (rx_ring->set_itr) {
1816 writel(1000000000 / (rx_ring->itr_val * 256),
1817 rx_ring->itr_register);
1818 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001819 }
1820
Ben Hutchings288379f2009-01-19 16:43:59 -08001821 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001822 adapter->total_rx_bytes = 0;
1823 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001824 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001825 }
1826 return IRQ_HANDLED;
1827}
1828
1829/**
1830 * e1000_configure_msix - Configure MSI-X hardware
1831 *
1832 * e1000_configure_msix sets up the hardware to properly
1833 * generate MSI-X interrupts.
1834 **/
1835static void e1000_configure_msix(struct e1000_adapter *adapter)
1836{
1837 struct e1000_hw *hw = &adapter->hw;
1838 struct e1000_ring *rx_ring = adapter->rx_ring;
1839 struct e1000_ring *tx_ring = adapter->tx_ring;
1840 int vector = 0;
1841 u32 ctrl_ext, ivar = 0;
1842
1843 adapter->eiac_mask = 0;
1844
1845 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1846 if (hw->mac.type == e1000_82574) {
1847 u32 rfctl = er32(RFCTL);
1848 rfctl |= E1000_RFCTL_ACK_DIS;
1849 ew32(RFCTL, rfctl);
1850 }
1851
1852#define E1000_IVAR_INT_ALLOC_VALID 0x8
1853 /* Configure Rx vector */
1854 rx_ring->ims_val = E1000_IMS_RXQ0;
1855 adapter->eiac_mask |= rx_ring->ims_val;
1856 if (rx_ring->itr_val)
1857 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001858 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001859 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001860 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001861 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1862
1863 /* Configure Tx vector */
1864 tx_ring->ims_val = E1000_IMS_TXQ0;
1865 vector++;
1866 if (tx_ring->itr_val)
1867 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001868 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001869 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001870 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001871 adapter->eiac_mask |= tx_ring->ims_val;
1872 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1873
1874 /* set vector for Other Causes, e.g. link changes */
1875 vector++;
1876 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1877 if (rx_ring->itr_val)
1878 writel(1000000000 / (rx_ring->itr_val * 256),
1879 hw->hw_addr + E1000_EITR_82574(vector));
1880 else
1881 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1882
1883 /* Cause Tx interrupts on every write back */
1884 ivar |= (1 << 31);
1885
1886 ew32(IVAR, ivar);
1887
1888 /* enable MSI-X PBA support */
1889 ctrl_ext = er32(CTRL_EXT);
1890 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1891
1892 /* Auto-Mask Other interrupts upon ICR read */
1893#define E1000_EIAC_MASK_82574 0x01F00000
1894 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1895 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1896 ew32(CTRL_EXT, ctrl_ext);
1897 e1e_flush();
1898}
1899
1900void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
1901{
1902 if (adapter->msix_entries) {
1903 pci_disable_msix(adapter->pdev);
1904 kfree(adapter->msix_entries);
1905 adapter->msix_entries = NULL;
1906 } else if (adapter->flags & FLAG_MSI_ENABLED) {
1907 pci_disable_msi(adapter->pdev);
1908 adapter->flags &= ~FLAG_MSI_ENABLED;
1909 }
Bruce Allan4662e822008-08-26 18:37:06 -07001910}
1911
1912/**
1913 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
1914 *
1915 * Attempt to configure interrupts using the best available
1916 * capabilities of the hardware and kernel.
1917 **/
1918void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
1919{
1920 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001921 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001922
1923 switch (adapter->int_mode) {
1924 case E1000E_INT_MODE_MSIX:
1925 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001926 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
1927 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07001928 sizeof(struct msix_entry),
1929 GFP_KERNEL);
1930 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001931 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07001932 adapter->msix_entries[i].entry = i;
1933
1934 err = pci_enable_msix(adapter->pdev,
1935 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001936 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001937 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07001938 return;
1939 }
1940 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00001941 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001942 e1000e_reset_interrupt_capability(adapter);
1943 }
1944 adapter->int_mode = E1000E_INT_MODE_MSI;
1945 /* Fall through */
1946 case E1000E_INT_MODE_MSI:
1947 if (!pci_enable_msi(adapter->pdev)) {
1948 adapter->flags |= FLAG_MSI_ENABLED;
1949 } else {
1950 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00001951 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07001952 }
1953 /* Fall through */
1954 case E1000E_INT_MODE_LEGACY:
1955 /* Don't do anything; this is the system default */
1956 break;
1957 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00001958
1959 /* store the number of vectors being used */
1960 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001961}
1962
1963/**
1964 * e1000_request_msix - Initialize MSI-X interrupts
1965 *
1966 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
1967 * kernel.
1968 **/
1969static int e1000_request_msix(struct e1000_adapter *adapter)
1970{
1971 struct net_device *netdev = adapter->netdev;
1972 int err = 0, vector = 0;
1973
1974 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001975 snprintf(adapter->rx_ring->name,
1976 sizeof(adapter->rx_ring->name) - 1,
1977 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001978 else
1979 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1980 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001981 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001982 netdev);
1983 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00001984 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00001985 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
1986 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07001987 adapter->rx_ring->itr_val = adapter->itr;
1988 vector++;
1989
1990 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00001991 snprintf(adapter->tx_ring->name,
1992 sizeof(adapter->tx_ring->name) - 1,
1993 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07001994 else
1995 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1996 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001997 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07001998 netdev);
1999 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002000 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002001 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2002 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002003 adapter->tx_ring->itr_val = adapter->itr;
2004 vector++;
2005
2006 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002007 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002008 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002009 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002010
2011 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002012
Bruce Allan4662e822008-08-26 18:37:06 -07002013 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002014}
2015
Bruce Allanf8d59f72008-08-08 18:36:11 -07002016/**
2017 * e1000_request_irq - initialize interrupts
2018 *
2019 * Attempts to configure interrupts using the best available
2020 * capabilities of the hardware and kernel.
2021 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002022static int e1000_request_irq(struct e1000_adapter *adapter)
2023{
2024 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002025 int err;
2026
Bruce Allan4662e822008-08-26 18:37:06 -07002027 if (adapter->msix_entries) {
2028 err = e1000_request_msix(adapter);
2029 if (!err)
2030 return err;
2031 /* fall back to MSI */
2032 e1000e_reset_interrupt_capability(adapter);
2033 adapter->int_mode = E1000E_INT_MODE_MSI;
2034 e1000e_set_interrupt_capability(adapter);
2035 }
2036 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002037 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002038 netdev->name, netdev);
2039 if (!err)
2040 return err;
2041
2042 /* fall back to legacy interrupt */
2043 e1000e_reset_interrupt_capability(adapter);
2044 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002045 }
2046
Joe Perchesa0607fd2009-11-18 23:29:17 -08002047 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002048 netdev->name, netdev);
2049 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002050 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002051
2052 return err;
2053}
2054
2055static void e1000_free_irq(struct e1000_adapter *adapter)
2056{
2057 struct net_device *netdev = adapter->netdev;
2058
Bruce Allan4662e822008-08-26 18:37:06 -07002059 if (adapter->msix_entries) {
2060 int vector = 0;
2061
2062 free_irq(adapter->msix_entries[vector].vector, netdev);
2063 vector++;
2064
2065 free_irq(adapter->msix_entries[vector].vector, netdev);
2066 vector++;
2067
2068 /* Other Causes interrupt vector */
2069 free_irq(adapter->msix_entries[vector].vector, netdev);
2070 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071 }
Bruce Allan4662e822008-08-26 18:37:06 -07002072
2073 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002074}
2075
2076/**
2077 * e1000_irq_disable - Mask off interrupt generation on the NIC
2078 **/
2079static void e1000_irq_disable(struct e1000_adapter *adapter)
2080{
2081 struct e1000_hw *hw = &adapter->hw;
2082
Auke Kokbc7f75f2007-09-17 12:30:59 -07002083 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002084 if (adapter->msix_entries)
2085 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002086 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002087
2088 if (adapter->msix_entries) {
2089 int i;
2090 for (i = 0; i < adapter->num_vectors; i++)
2091 synchronize_irq(adapter->msix_entries[i].vector);
2092 } else {
2093 synchronize_irq(adapter->pdev->irq);
2094 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095}
2096
2097/**
2098 * e1000_irq_enable - Enable default interrupt generation settings
2099 **/
2100static void e1000_irq_enable(struct e1000_adapter *adapter)
2101{
2102 struct e1000_hw *hw = &adapter->hw;
2103
Bruce Allan4662e822008-08-26 18:37:06 -07002104 if (adapter->msix_entries) {
2105 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2106 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2107 } else {
2108 ew32(IMS, IMS_ENABLE_MASK);
2109 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002110 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002111}
2112
2113/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002114 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002115 * @adapter: address of board private structure
2116 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002117 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002118 * For ASF and Pass Through versions of f/w this means that
2119 * the driver is loaded. For AMT version (only with 82573)
2120 * of the f/w this means that the network i/f is open.
2121 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002122void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002123{
2124 struct e1000_hw *hw = &adapter->hw;
2125 u32 ctrl_ext;
2126 u32 swsm;
2127
2128 /* Let firmware know the driver has taken over */
2129 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2130 swsm = er32(SWSM);
2131 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2132 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2133 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002134 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002135 }
2136}
2137
2138/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002139 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002140 * @adapter: address of board private structure
2141 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002142 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002143 * For ASF and Pass Through versions of f/w this means that the
2144 * driver is no longer loaded. For AMT version (only with 82573) i
2145 * of the f/w this means that the network i/f is closed.
2146 *
2147 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002148void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002149{
2150 struct e1000_hw *hw = &adapter->hw;
2151 u32 ctrl_ext;
2152 u32 swsm;
2153
2154 /* Let firmware taken over control of h/w */
2155 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2156 swsm = er32(SWSM);
2157 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2158 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2159 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002160 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002161 }
2162}
2163
Auke Kokbc7f75f2007-09-17 12:30:59 -07002164/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002165 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002166 **/
2167static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2168 struct e1000_ring *ring)
2169{
2170 struct pci_dev *pdev = adapter->pdev;
2171
2172 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2173 GFP_KERNEL);
2174 if (!ring->desc)
2175 return -ENOMEM;
2176
2177 return 0;
2178}
2179
2180/**
2181 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002182 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002183 *
2184 * Return 0 on success, negative on failure
2185 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002186int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187{
Bruce Allan55aa6982011-12-16 00:45:45 +00002188 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 int err = -ENOMEM, size;
2190
2191 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002192 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193 if (!tx_ring->buffer_info)
2194 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002195
2196 /* round up to nearest 4K */
2197 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2198 tx_ring->size = ALIGN(tx_ring->size, 4096);
2199
2200 err = e1000_alloc_ring_dma(adapter, tx_ring);
2201 if (err)
2202 goto err;
2203
2204 tx_ring->next_to_use = 0;
2205 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206
2207 return 0;
2208err:
2209 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002210 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211 return err;
2212}
2213
2214/**
2215 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002216 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002217 *
2218 * Returns 0 on success, negative on failure
2219 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002220int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221{
Bruce Allan55aa6982011-12-16 00:45:45 +00002222 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002223 struct e1000_buffer *buffer_info;
2224 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002225
2226 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002227 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228 if (!rx_ring->buffer_info)
2229 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230
Auke Kok47f44e42007-10-25 13:57:44 -07002231 for (i = 0; i < rx_ring->count; i++) {
2232 buffer_info = &rx_ring->buffer_info[i];
2233 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2234 sizeof(struct e1000_ps_page),
2235 GFP_KERNEL);
2236 if (!buffer_info->ps_pages)
2237 goto err_pages;
2238 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239
2240 desc_len = sizeof(union e1000_rx_desc_packet_split);
2241
2242 /* Round up to nearest 4K */
2243 rx_ring->size = rx_ring->count * desc_len;
2244 rx_ring->size = ALIGN(rx_ring->size, 4096);
2245
2246 err = e1000_alloc_ring_dma(adapter, rx_ring);
2247 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002248 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249
2250 rx_ring->next_to_clean = 0;
2251 rx_ring->next_to_use = 0;
2252 rx_ring->rx_skb_top = NULL;
2253
2254 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002255
2256err_pages:
2257 for (i = 0; i < rx_ring->count; i++) {
2258 buffer_info = &rx_ring->buffer_info[i];
2259 kfree(buffer_info->ps_pages);
2260 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261err:
2262 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002263 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002264 return err;
2265}
2266
2267/**
2268 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002269 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002271static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272{
Bruce Allan55aa6982011-12-16 00:45:45 +00002273 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 struct e1000_buffer *buffer_info;
2275 unsigned long size;
2276 unsigned int i;
2277
2278 for (i = 0; i < tx_ring->count; i++) {
2279 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002280 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002281 }
2282
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002283 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002284 size = sizeof(struct e1000_buffer) * tx_ring->count;
2285 memset(tx_ring->buffer_info, 0, size);
2286
2287 memset(tx_ring->desc, 0, tx_ring->size);
2288
2289 tx_ring->next_to_use = 0;
2290 tx_ring->next_to_clean = 0;
2291
Bruce Allanc5083cf2011-12-16 00:45:40 +00002292 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002293 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2294 e1000e_update_tdt_wa(tx_ring, 0);
2295 else
2296 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297}
2298
2299/**
2300 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002301 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302 *
2303 * Free all transmit software resources
2304 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002305void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306{
Bruce Allan55aa6982011-12-16 00:45:45 +00002307 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309
Bruce Allan55aa6982011-12-16 00:45:45 +00002310 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311
2312 vfree(tx_ring->buffer_info);
2313 tx_ring->buffer_info = NULL;
2314
2315 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2316 tx_ring->dma);
2317 tx_ring->desc = NULL;
2318}
2319
2320/**
2321 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002322 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 *
2324 * Free all receive software resources
2325 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002326void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327{
Bruce Allan55aa6982011-12-16 00:45:45 +00002328 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002330 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002331
Bruce Allan55aa6982011-12-16 00:45:45 +00002332 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002334 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002335 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002336
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337 vfree(rx_ring->buffer_info);
2338 rx_ring->buffer_info = NULL;
2339
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2341 rx_ring->dma);
2342 rx_ring->desc = NULL;
2343}
2344
2345/**
2346 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002347 * @adapter: pointer to adapter
2348 * @itr_setting: current adapter->itr
2349 * @packets: the number of packets during this measurement interval
2350 * @bytes: the number of bytes during this measurement interval
2351 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002352 * Stores a new ITR value based on packets and byte
2353 * counts during the last interrupt. The advantage of per interrupt
2354 * computation is faster updates and more accurate ITR for the current
2355 * traffic pattern. Constants in this function were computed
2356 * based on theoretical maximum wire speed and thresholds were set based
2357 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002358 * while increasing bulk throughput. This functionality is controlled
2359 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360 **/
2361static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2362 u16 itr_setting, int packets,
2363 int bytes)
2364{
2365 unsigned int retval = itr_setting;
2366
2367 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002368 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369
2370 switch (itr_setting) {
2371 case lowest_latency:
2372 /* handle TSO and jumbo frames */
2373 if (bytes/packets > 8000)
2374 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002375 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377 break;
2378 case low_latency: /* 50 usec aka 20000 ints/s */
2379 if (bytes > 10000) {
2380 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002381 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002383 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002385 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387 } else if (bytes/packets > 2000) {
2388 retval = bulk_latency;
2389 } else if (packets <= 2 && bytes < 512) {
2390 retval = lowest_latency;
2391 }
2392 break;
2393 case bulk_latency: /* 250 usec aka 4000 ints/s */
2394 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002395 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 } else if (bytes < 6000) {
2398 retval = low_latency;
2399 }
2400 break;
2401 }
2402
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 return retval;
2404}
2405
2406static void e1000_set_itr(struct e1000_adapter *adapter)
2407{
2408 struct e1000_hw *hw = &adapter->hw;
2409 u16 current_itr;
2410 u32 new_itr = adapter->itr;
2411
2412 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2413 if (adapter->link_speed != SPEED_1000) {
2414 current_itr = 0;
2415 new_itr = 4000;
2416 goto set_itr_now;
2417 }
2418
Bruce Allan828bac82010-09-29 21:39:37 +00002419 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2420 new_itr = 0;
2421 goto set_itr_now;
2422 }
2423
Auke Kokbc7f75f2007-09-17 12:30:59 -07002424 adapter->tx_itr = e1000_update_itr(adapter,
2425 adapter->tx_itr,
2426 adapter->total_tx_packets,
2427 adapter->total_tx_bytes);
2428 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2429 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2430 adapter->tx_itr = low_latency;
2431
2432 adapter->rx_itr = e1000_update_itr(adapter,
2433 adapter->rx_itr,
2434 adapter->total_rx_packets,
2435 adapter->total_rx_bytes);
2436 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2437 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2438 adapter->rx_itr = low_latency;
2439
2440 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2441
2442 switch (current_itr) {
2443 /* counts and packets in update_itr are dependent on these numbers */
2444 case lowest_latency:
2445 new_itr = 70000;
2446 break;
2447 case low_latency:
2448 new_itr = 20000; /* aka hwitr = ~200 */
2449 break;
2450 case bulk_latency:
2451 new_itr = 4000;
2452 break;
2453 default:
2454 break;
2455 }
2456
2457set_itr_now:
2458 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002459 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002461 * increasing
2462 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002463 new_itr = new_itr > adapter->itr ?
2464 min(adapter->itr + (new_itr >> 2), new_itr) :
2465 new_itr;
2466 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002467 adapter->rx_ring->itr_val = new_itr;
2468 if (adapter->msix_entries)
2469 adapter->rx_ring->set_itr = 1;
2470 else
Bruce Allan828bac82010-09-29 21:39:37 +00002471 if (new_itr)
2472 ew32(ITR, 1000000000 / (new_itr * 256));
2473 else
2474 ew32(ITR, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475 }
2476}
2477
2478/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002479 * e1000e_write_itr - write the ITR value to the appropriate registers
2480 * @adapter: address of board private structure
2481 * @itr: new ITR value to program
2482 *
2483 * e1000e_write_itr determines if the adapter is in MSI-X mode
2484 * and, if so, writes the EITR registers with the ITR value.
2485 * Otherwise, it writes the ITR value into the ITR register.
2486 **/
2487void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2488{
2489 struct e1000_hw *hw = &adapter->hw;
2490 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2491
2492 if (adapter->msix_entries) {
2493 int vector;
2494
2495 for (vector = 0; vector < adapter->num_vectors; vector++)
2496 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2497 } else {
2498 ew32(ITR, new_itr);
2499 }
2500}
2501
2502/**
Bruce Allan4662e822008-08-26 18:37:06 -07002503 * e1000_alloc_queues - Allocate memory for all rings
2504 * @adapter: board private structure to initialize
2505 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002506static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002507{
Bruce Allan55aa6982011-12-16 00:45:45 +00002508 int size = sizeof(struct e1000_ring);
2509
2510 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002511 if (!adapter->tx_ring)
2512 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002513 adapter->tx_ring->count = adapter->tx_ring_count;
2514 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002515
Bruce Allan55aa6982011-12-16 00:45:45 +00002516 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002517 if (!adapter->rx_ring)
2518 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002519 adapter->rx_ring->count = adapter->rx_ring_count;
2520 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002521
2522 return 0;
2523err:
2524 e_err("Unable to allocate memory for queues\n");
2525 kfree(adapter->rx_ring);
2526 kfree(adapter->tx_ring);
2527 return -ENOMEM;
2528}
2529
2530/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002531 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002532 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002533 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002535static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002537 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2538 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002539 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002540 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002541 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542
Wang Chen4cf16532008-11-12 23:38:14 -08002543 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002544
Bruce Allanc58c8a72012-03-20 03:48:19 +00002545 if (!adapter->msix_entries ||
2546 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2547 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002548
Bruce Allanc58c8a72012-03-20 03:48:19 +00002549 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550
Alexander Duyck12d04a32009-03-25 22:05:03 +00002551 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002552 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002553
Bruce Allanc58c8a72012-03-20 03:48:19 +00002554 /* If weight not fully consumed, exit the polling mode */
2555 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002556 if (adapter->itr_setting & 3)
2557 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002558 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002559 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2560 if (adapter->msix_entries)
2561 ew32(IMS, adapter->rx_ring->ims_val);
2562 else
2563 e1000_irq_enable(adapter);
2564 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002565 }
2566
2567 return work_done;
2568}
2569
Jiri Pirko8e586132011-12-08 19:52:37 -05002570static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571{
2572 struct e1000_adapter *adapter = netdev_priv(netdev);
2573 struct e1000_hw *hw = &adapter->hw;
2574 u32 vfta, index;
2575
2576 /* don't update vlan cookie if already programmed */
2577 if ((adapter->hw.mng_cookie.status &
2578 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2579 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002580 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002581
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002583 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2584 index = (vid >> 5) & 0x7F;
2585 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2586 vfta |= (1 << (vid & 0x1F));
2587 hw->mac.ops.write_vfta(hw, index, vfta);
2588 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002589
2590 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002591
2592 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593}
2594
Jiri Pirko8e586132011-12-08 19:52:37 -05002595static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002596{
2597 struct e1000_adapter *adapter = netdev_priv(netdev);
2598 struct e1000_hw *hw = &adapter->hw;
2599 u32 vfta, index;
2600
Auke Kokbc7f75f2007-09-17 12:30:59 -07002601 if ((adapter->hw.mng_cookie.status &
2602 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2603 (vid == adapter->mng_vlan_id)) {
2604 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002605 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002606 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002607 }
2608
2609 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002610 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2611 index = (vid >> 5) & 0x7F;
2612 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2613 vfta &= ~(1 << (vid & 0x1F));
2614 hw->mac.ops.write_vfta(hw, index, vfta);
2615 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002616
2617 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002618
2619 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002620}
2621
2622/**
2623 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2624 * @adapter: board private structure to initialize
2625 **/
2626static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2627{
2628 struct net_device *netdev = adapter->netdev;
2629 struct e1000_hw *hw = &adapter->hw;
2630 u32 rctl;
2631
2632 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2633 /* disable VLAN receive filtering */
2634 rctl = er32(RCTL);
2635 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2636 ew32(RCTL, rctl);
2637
2638 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2639 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2640 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2641 }
2642 }
2643}
2644
2645/**
2646 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2647 * @adapter: board private structure to initialize
2648 **/
2649static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2650{
2651 struct e1000_hw *hw = &adapter->hw;
2652 u32 rctl;
2653
2654 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2655 /* enable VLAN receive filtering */
2656 rctl = er32(RCTL);
2657 rctl |= E1000_RCTL_VFE;
2658 rctl &= ~E1000_RCTL_CFIEN;
2659 ew32(RCTL, rctl);
2660 }
2661}
2662
2663/**
2664 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2665 * @adapter: board private structure to initialize
2666 **/
2667static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2668{
2669 struct e1000_hw *hw = &adapter->hw;
2670 u32 ctrl;
2671
2672 /* disable VLAN tag insert/strip */
2673 ctrl = er32(CTRL);
2674 ctrl &= ~E1000_CTRL_VME;
2675 ew32(CTRL, ctrl);
2676}
2677
2678/**
2679 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2680 * @adapter: board private structure to initialize
2681 **/
2682static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2683{
2684 struct e1000_hw *hw = &adapter->hw;
2685 u32 ctrl;
2686
2687 /* enable VLAN tag insert/strip */
2688 ctrl = er32(CTRL);
2689 ctrl |= E1000_CTRL_VME;
2690 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691}
2692
2693static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2694{
2695 struct net_device *netdev = adapter->netdev;
2696 u16 vid = adapter->hw.mng_cookie.vlan_id;
2697 u16 old_vid = adapter->mng_vlan_id;
2698
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002699 if (adapter->hw.mng_cookie.status &
2700 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2701 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 adapter->mng_vlan_id = vid;
2703 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002705 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2706 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002707}
2708
2709static void e1000_restore_vlan(struct e1000_adapter *adapter)
2710{
2711 u16 vid;
2712
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002713 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002714
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002715 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002717}
2718
Bruce Allancd791612010-05-10 14:59:51 +00002719static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002720{
2721 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002722 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723
2724 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2725 return;
2726
2727 manc = er32(MANC);
2728
Bruce Allane921eb12012-11-28 09:28:37 +00002729 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002731 * the packets will be handled on SMBUS
2732 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002733 manc |= E1000_MANC_EN_MNG2HOST;
2734 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002735
2736 switch (hw->mac.type) {
2737 default:
2738 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2739 break;
2740 case e1000_82574:
2741 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002742 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002743 * if so, enable it.
2744 */
2745 for (i = 0, j = 0; i < 8; i++) {
2746 mdef = er32(MDEF(i));
2747
2748 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002749 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002750 continue;
2751
2752 /* Enable this decision filter in MANC2H */
2753 if (mdef)
2754 manc2h |= (1 << i);
2755
2756 j |= mdef;
2757 }
2758
2759 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2760 break;
2761
2762 /* Create new decision filter in an empty filter */
2763 for (i = 0, j = 0; i < 8; i++)
2764 if (er32(MDEF(i)) == 0) {
2765 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2766 E1000_MDEF_PORT_664));
2767 manc2h |= (1 << 1);
2768 j++;
2769 break;
2770 }
2771
2772 if (!j)
2773 e_warn("Unable to create IPMI pass-through filter\n");
2774 break;
2775 }
2776
Auke Kokbc7f75f2007-09-17 12:30:59 -07002777 ew32(MANC2H, manc2h);
2778 ew32(MANC, manc);
2779}
2780
2781/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002782 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002783 * @adapter: board private structure
2784 *
2785 * Configure the Tx unit of the MAC after a reset.
2786 **/
2787static void e1000_configure_tx(struct e1000_adapter *adapter)
2788{
2789 struct e1000_hw *hw = &adapter->hw;
2790 struct e1000_ring *tx_ring = adapter->tx_ring;
2791 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002792 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793
2794 /* Setup the HW Tx Head and Tail descriptor pointers */
2795 tdba = tx_ring->dma;
2796 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002797 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2798 ew32(TDBAH(0), (tdba >> 32));
2799 ew32(TDLEN(0), tdlen);
2800 ew32(TDH(0), 0);
2801 ew32(TDT(0), 0);
2802 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2803 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002804
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805 /* Set the Tx Interrupt Delay register */
2806 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002807 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002808 ew32(TADV, adapter->tx_abs_int_delay);
2809
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002810 if (adapter->flags2 & FLAG2_DMA_BURST) {
2811 u32 txdctl = er32(TXDCTL(0));
2812 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2813 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002814 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002815 * hardware to use the bus more efficiently in bursts, depends
2816 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002817 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002818 * hthresh = 1 ==> prefetch when one or more available
2819 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2820 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002821 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002822 */
2823 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2824 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002825 }
Bruce Allan56032be2011-12-16 00:46:01 +00002826 /* erratum work around: set txdctl the same for both queues */
2827 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002828
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002830 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002831 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002832 * gigabit link later
2833 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834#define SPEED_MODE_BIT (1 << 21)
2835 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002836 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837 }
2838
2839 /* errata: program both queues to unweighted RR */
2840 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002841 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002843 ew32(TARC(0), tarc);
2844 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002846 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002847 }
2848
Auke Kokbc7f75f2007-09-17 12:30:59 -07002849 /* Setup Transmit Descriptor Settings for eop descriptor */
2850 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2851
2852 /* only set IDE if we are delaying interrupts using the timers */
2853 if (adapter->tx_int_delay)
2854 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2855
2856 /* enable Report Status bit */
2857 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2858
Bruce Allan57cde762012-02-22 09:02:58 +00002859 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860}
2861
2862/**
2863 * e1000_setup_rctl - configure the receive control registers
2864 * @adapter: Board private structure
2865 **/
2866#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2867 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2868static void e1000_setup_rctl(struct e1000_adapter *adapter)
2869{
2870 struct e1000_hw *hw = &adapter->hw;
2871 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002872 u32 pages = 0;
2873
Bruce Allan2fbe4522012-04-19 03:21:47 +00002874 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2875 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002876 s32 ret_val;
2877
2878 if (adapter->netdev->mtu > ETH_DATA_LEN)
2879 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2880 else
2881 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002882
2883 if (ret_val)
2884 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002885 }
2886
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887 /* Program MC offset vector base */
2888 rctl = er32(RCTL);
2889 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2890 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2891 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2892 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2893
2894 /* Do not Store bad packets */
2895 rctl &= ~E1000_RCTL_SBP;
2896
2897 /* Enable Long Packet receive */
2898 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2899 rctl &= ~E1000_RCTL_LPE;
2900 else
2901 rctl |= E1000_RCTL_LPE;
2902
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002903 /* Some systems expect that the CRC is included in SMBUS traffic. The
2904 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2905 * host memory when this is enabled
2906 */
2907 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
2908 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08002909
Bruce Allana4f58f52009-06-02 11:29:18 +00002910 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
2911 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
2912 u16 phy_data;
2913
2914 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
2915 phy_data &= 0xfff8;
2916 phy_data |= (1 << 2);
2917 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
2918
2919 e1e_rphy(hw, 22, &phy_data);
2920 phy_data &= 0x0fff;
2921 phy_data |= (1 << 14);
2922 e1e_wphy(hw, 0x10, 0x2823);
2923 e1e_wphy(hw, 0x11, 0x0003);
2924 e1e_wphy(hw, 22, phy_data);
2925 }
2926
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 /* Setup buffer sizes */
2928 rctl &= ~E1000_RCTL_SZ_4096;
2929 rctl |= E1000_RCTL_BSEX;
2930 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 case 2048:
2932 default:
2933 rctl |= E1000_RCTL_SZ_2048;
2934 rctl &= ~E1000_RCTL_BSEX;
2935 break;
2936 case 4096:
2937 rctl |= E1000_RCTL_SZ_4096;
2938 break;
2939 case 8192:
2940 rctl |= E1000_RCTL_SZ_8192;
2941 break;
2942 case 16384:
2943 rctl |= E1000_RCTL_SZ_16384;
2944 break;
2945 }
2946
Bruce Allan5f450212011-07-22 06:21:46 +00002947 /* Enable Extended Status in all Receive Descriptors */
2948 rfctl = er32(RFCTL);
2949 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00002950 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00002951
Bruce Allane921eb12012-11-28 09:28:37 +00002952 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07002953 * header is placed in skb->data and the packet data is
2954 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2955 * In the case of a non-split, skb->data is linearly filled,
2956 * followed by the page buffers. Therefore, skb->data is
2957 * sized to hold the largest protocol header.
2958 *
2959 * allocations using alloc_page take too long for regular MTU
2960 * so only enable packet split for jumbo frames
2961 *
2962 * Using pages when the page size is greater than 16k wastes
2963 * a lot of memory, since we allocate 3 pages at all times
2964 * per packet.
2965 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00002967 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002968 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002969 else
2970 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971
2972 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00002973 u32 psrctl = 0;
2974
Auke Kok140a7482007-10-25 13:57:58 -07002975 /* Enable Packet split descriptors */
2976 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977
2978 psrctl |= adapter->rx_ps_bsize0 >>
2979 E1000_PSRCTL_BSIZE0_SHIFT;
2980
2981 switch (adapter->rx_ps_pages) {
2982 case 3:
2983 psrctl |= PAGE_SIZE <<
2984 E1000_PSRCTL_BSIZE3_SHIFT;
2985 case 2:
2986 psrctl |= PAGE_SIZE <<
2987 E1000_PSRCTL_BSIZE2_SHIFT;
2988 case 1:
2989 psrctl |= PAGE_SIZE >>
2990 E1000_PSRCTL_BSIZE1_SHIFT;
2991 break;
2992 }
2993
2994 ew32(PSRCTL, psrctl);
2995 }
2996
Ben Greearcf955e62012-02-11 15:39:51 +00002997 /* This is useful for sniffing bad packets. */
2998 if (adapter->netdev->features & NETIF_F_RXALL) {
2999 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003000 * in e1000e_set_rx_mode
3001 */
Ben Greearcf955e62012-02-11 15:39:51 +00003002 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3003 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3004 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3005
3006 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3007 E1000_RCTL_DPF | /* Allow filtered pause */
3008 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3009 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3010 * and that breaks VLANs.
3011 */
3012 }
3013
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003015 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003016 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017}
3018
3019/**
3020 * e1000_configure_rx - Configure Receive Unit after Reset
3021 * @adapter: board private structure
3022 *
3023 * Configure the Rx unit of the MAC after a reset.
3024 **/
3025static void e1000_configure_rx(struct e1000_adapter *adapter)
3026{
3027 struct e1000_hw *hw = &adapter->hw;
3028 struct e1000_ring *rx_ring = adapter->rx_ring;
3029 u64 rdba;
3030 u32 rdlen, rctl, rxcsum, ctrl_ext;
3031
3032 if (adapter->rx_ps_pages) {
3033 /* this is a 32 byte descriptor */
3034 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003035 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003036 adapter->clean_rx = e1000_clean_rx_irq_ps;
3037 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003038 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003039 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003040 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3041 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003043 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044 adapter->clean_rx = e1000_clean_rx_irq;
3045 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3046 }
3047
3048 /* disable receives while setting up the descriptors */
3049 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003050 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3051 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003052 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003053 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003055 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003056 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003057 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003058 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003059 * granularity = 01
3060 * wthresh = 04,
3061 * hthresh = 04,
3062 * pthresh = 0x20
3063 */
3064 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3065 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3066
Bruce Allane921eb12012-11-28 09:28:37 +00003067 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003068 * the value was not set by the user via module options
3069 */
3070 if (adapter->rx_int_delay == DEFAULT_RDTR)
3071 adapter->rx_int_delay = BURST_RDTR;
3072 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3073 adapter->rx_abs_int_delay = BURST_RADV;
3074 }
3075
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076 /* set the Receive Delay Timer Register */
3077 ew32(RDTR, adapter->rx_int_delay);
3078
3079 /* irq moderation */
3080 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003081 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003082 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083
3084 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085 /* Auto-Mask interrupts upon ICR access */
3086 ctrl_ext |= E1000_CTRL_EXT_IAME;
3087 ew32(IAM, 0xffffffff);
3088 ew32(CTRL_EXT, ctrl_ext);
3089 e1e_flush();
3090
Bruce Allane921eb12012-11-28 09:28:37 +00003091 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003092 * the Base and Length of the Rx Descriptor Ring
3093 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003095 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3096 ew32(RDBAH(0), (rdba >> 32));
3097 ew32(RDLEN(0), rdlen);
3098 ew32(RDH(0), 0);
3099 ew32(RDT(0), 0);
3100 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3101 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102
3103 /* Enable Receive Checksum Offload for TCP and UDP */
3104 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003105 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003106 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003107 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003108 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109 ew32(RXCSUM, rxcsum);
3110
Bruce Allan79d4e902011-12-16 00:46:27 +00003111 if (adapter->hw.mac.type == e1000_pch2lan) {
Bruce Allane921eb12012-11-28 09:28:37 +00003112 /* With jumbo frames, excessive C-state transition
Bruce Allan79d4e902011-12-16 00:46:27 +00003113 * latencies result in dropped transactions.
3114 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003115 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3116 u32 rxdctl = er32(RXDCTL(0));
3117 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003118 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003119 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003120 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3121 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003122 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003123 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124
3125 /* Enable Receives */
3126 ew32(RCTL, rctl);
3127}
3128
3129/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003130 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 * @netdev: network interface device structure
3132 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003133 * Writes multicast address list to the MTA hash table.
3134 * Returns: -ENOMEM on failure
3135 * 0 on no addresses written
3136 * X on writing X addresses to MTA
3137 */
3138static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139{
3140 struct e1000_adapter *adapter = netdev_priv(netdev);
3141 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003142 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003143 u8 *mta_list;
3144 int i;
3145
3146 if (netdev_mc_empty(netdev)) {
3147 /* nothing to program, so clear mc list */
3148 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3149 return 0;
3150 }
3151
3152 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3153 if (!mta_list)
3154 return -ENOMEM;
3155
3156 /* update_mc_addr_list expects a packed array of only addresses. */
3157 i = 0;
3158 netdev_for_each_mc_addr(ha, netdev)
3159 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3160
3161 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3162 kfree(mta_list);
3163
3164 return netdev_mc_count(netdev);
3165}
3166
3167/**
3168 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3169 * @netdev: network interface device structure
3170 *
3171 * Writes unicast address list to the RAR table.
3172 * Returns: -ENOMEM on failure/insufficient address space
3173 * 0 on no addresses written
3174 * X on writing X addresses to the RAR table
3175 **/
3176static int e1000e_write_uc_addr_list(struct net_device *netdev)
3177{
3178 struct e1000_adapter *adapter = netdev_priv(netdev);
3179 struct e1000_hw *hw = &adapter->hw;
3180 unsigned int rar_entries = hw->mac.rar_entry_count;
3181 int count = 0;
3182
3183 /* save a rar entry for our hardware address */
3184 rar_entries--;
3185
3186 /* save a rar entry for the LAA workaround */
3187 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3188 rar_entries--;
3189
3190 /* return ENOMEM indicating insufficient memory for addresses */
3191 if (netdev_uc_count(netdev) > rar_entries)
3192 return -ENOMEM;
3193
3194 if (!netdev_uc_empty(netdev) && rar_entries) {
3195 struct netdev_hw_addr *ha;
3196
Bruce Allane921eb12012-11-28 09:28:37 +00003197 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003198 * combining
3199 */
3200 netdev_for_each_uc_addr(ha, netdev) {
3201 if (!rar_entries)
3202 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003203 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003204 count++;
3205 }
3206 }
3207
3208 /* zero out the remaining RAR entries not used above */
3209 for (; rar_entries > 0; rar_entries--) {
3210 ew32(RAH(rar_entries), 0);
3211 ew32(RAL(rar_entries), 0);
3212 }
3213 e1e_flush();
3214
3215 return count;
3216}
3217
3218/**
3219 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3220 * @netdev: network interface device structure
3221 *
3222 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3223 * address list or the network interface flags are updated. This routine is
3224 * responsible for configuring the hardware for proper unicast, multicast,
3225 * promiscuous mode, and all-multi behavior.
3226 **/
3227static void e1000e_set_rx_mode(struct net_device *netdev)
3228{
3229 struct e1000_adapter *adapter = netdev_priv(netdev);
3230 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003232
3233 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 rctl = er32(RCTL);
3235
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003236 /* clear the affected bits */
3237 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3238
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239 if (netdev->flags & IFF_PROMISC) {
3240 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003241 /* Do not hardware filter VLANs in promisc mode */
3242 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003244 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003245
Patrick McHardy746b9f02008-07-16 20:15:45 -07003246 if (netdev->flags & IFF_ALLMULTI) {
3247 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003248 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003249 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003250 * then we should just turn on promiscuous mode so
3251 * that we can at least receive multicast traffic
3252 */
3253 count = e1000e_write_mc_addr_list(netdev);
3254 if (count < 0)
3255 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003256 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003257 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003258 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003259 * sufficient space to store all the addresses then enable
3260 * unicast promiscuous mode
3261 */
3262 count = e1000e_write_uc_addr_list(netdev);
3263 if (count < 0)
3264 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 }
3266
3267 ew32(RCTL, rctl);
3268
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003269 if (netdev->features & NETIF_F_HW_VLAN_RX)
3270 e1000e_vlan_strip_enable(adapter);
3271 else
3272 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003273}
3274
Bruce Allan70495a52012-01-11 01:26:50 +00003275static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3276{
3277 struct e1000_hw *hw = &adapter->hw;
3278 u32 mrqc, rxcsum;
3279 int i;
3280 static const u32 rsskey[10] = {
3281 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3282 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3283 };
3284
3285 /* Fill out hash function seed */
3286 for (i = 0; i < 10; i++)
3287 ew32(RSSRK(i), rsskey[i]);
3288
3289 /* Direct all traffic to queue 0 */
3290 for (i = 0; i < 32; i++)
3291 ew32(RETA(i), 0);
3292
Bruce Allane921eb12012-11-28 09:28:37 +00003293 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003294 * descriptor on writeback.
3295 */
3296 rxcsum = er32(RXCSUM);
3297 rxcsum |= E1000_RXCSUM_PCSD;
3298
3299 ew32(RXCSUM, rxcsum);
3300
3301 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3302 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3303 E1000_MRQC_RSS_FIELD_IPV6 |
3304 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3305 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3306
3307 ew32(MRQC, mrqc);
3308}
3309
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310/**
Bruce Allanad680762008-03-28 09:15:03 -07003311 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003312 * @adapter: private board structure
3313 **/
3314static void e1000_configure(struct e1000_adapter *adapter)
3315{
Bruce Allan55aa6982011-12-16 00:45:45 +00003316 struct e1000_ring *rx_ring = adapter->rx_ring;
3317
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003318 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003319
3320 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003321 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003322
3323 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003324
3325 if (adapter->netdev->features & NETIF_F_RXHASH)
3326 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003327 e1000_setup_rctl(adapter);
3328 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003329 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330}
3331
3332/**
3333 * e1000e_power_up_phy - restore link in case the phy was powered down
3334 * @adapter: address of board private structure
3335 *
3336 * The phy may be powered down to save power and turn off link when the
3337 * driver is unloaded and wake on lan is not enabled (among others)
3338 * *** this routine MUST be followed by a call to e1000e_reset ***
3339 **/
3340void e1000e_power_up_phy(struct e1000_adapter *adapter)
3341{
Bruce Allan17f208d2009-12-01 15:47:22 +00003342 if (adapter->hw.phy.ops.power_up)
3343 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344
3345 adapter->hw.mac.ops.setup_link(&adapter->hw);
3346}
3347
3348/**
3349 * e1000_power_down_phy - Power down the PHY
3350 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003351 * Power down the PHY so no link is implied when interface is down.
3352 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 */
3354static void e1000_power_down_phy(struct e1000_adapter *adapter)
3355{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003357 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003358 return;
3359
Bruce Allan17f208d2009-12-01 15:47:22 +00003360 if (adapter->hw.phy.ops.power_down)
3361 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003362}
3363
3364/**
3365 * e1000e_reset - bring the hardware into a known good state
3366 *
3367 * This function boots the hardware and enables some settings that
3368 * require a configuration cycle of the hardware - those cannot be
3369 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003370 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371 */
3372void e1000e_reset(struct e1000_adapter *adapter)
3373{
3374 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003375 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376 struct e1000_hw *hw = &adapter->hw;
3377 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003378 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003379 u16 hwm;
3380
Bruce Allanad680762008-03-28 09:15:03 -07003381 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003382 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003383
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003384 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003385 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003386 * large enough to accommodate two full transmit packets,
3387 * rounded up to the next 1KB and expressed in KB. Likewise,
3388 * the Rx FIFO should be large enough to accommodate at least
3389 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003390 * expressed in KB.
3391 */
Auke Kokdf762462007-10-25 13:57:53 -07003392 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003394 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003395 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003396 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003397 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003398 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003399 */
3400 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003401 sizeof(struct e1000_tx_desc) -
3402 ETH_FCS_LEN) * 2;
3403 min_tx_space = ALIGN(min_tx_space, 1024);
3404 min_tx_space >>= 10;
3405 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003406 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407 min_rx_space = ALIGN(min_rx_space, 1024);
3408 min_rx_space >>= 10;
3409
Bruce Allane921eb12012-11-28 09:28:37 +00003410 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003411 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003412 * allocation, take space away from current Rx allocation
3413 */
Auke Kokdf762462007-10-25 13:57:53 -07003414 if ((tx_space < min_tx_space) &&
3415 ((min_tx_space - tx_space) < pba)) {
3416 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417
Bruce Allane921eb12012-11-28 09:28:37 +00003418 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003419 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003420 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003421 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003422 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 }
Auke Kokdf762462007-10-25 13:57:53 -07003424
3425 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426 }
3427
Bruce Allane921eb12012-11-28 09:28:37 +00003428 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003429 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003430 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003431 * (or the size used for early receive) above it in the Rx FIFO.
3432 * Set it to the lower of:
3433 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003434 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003435 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003436 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3437 fc->pause_time = 0xFFFF;
3438 else
3439 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003440 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003441 fc->current_mode = fc->requested_mode;
3442
3443 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003444 case e1000_ich9lan:
3445 case e1000_ich10lan:
3446 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3447 pba = 14;
3448 ew32(PBA, pba);
3449 fc->high_water = 0x2800;
3450 fc->low_water = fc->high_water - 8;
3451 break;
3452 }
3453 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003454 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003455 hwm = min(((pba << 10) * 9 / 10),
3456 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003457
3458 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3459 fc->low_water = fc->high_water - 8;
3460 break;
3461 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003462 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003463 * loads. If hangs persist, try disabling Tx flow control.
3464 */
3465 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3466 fc->high_water = 0x3500;
3467 fc->low_water = 0x1500;
3468 } else {
3469 fc->high_water = 0x5000;
3470 fc->low_water = 0x3000;
3471 }
Bruce Allana3055952010-05-10 15:02:12 +00003472 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003473 break;
3474 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003475 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003476 fc->high_water = 0x05C20;
3477 fc->low_water = 0x05048;
3478 fc->pause_time = 0x0650;
3479 fc->refresh_time = 0x0400;
Bruce Allan828bac82010-09-29 21:39:37 +00003480 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3481 pba = 14;
3482 ew32(PBA, pba);
3483 }
Bruce Alland3738bb2010-06-16 13:27:28 +00003484 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003485 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003486
Bruce Allane921eb12012-11-28 09:28:37 +00003487 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003488 * maximum size per Tx descriptor limited only to the transmit
3489 * allocation of the packet buffer minus 96 bytes with an upper
3490 * limit of 24KB due to receive synchronization limitations.
3491 */
3492 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3493 24 << 10);
3494
Bruce Allane921eb12012-11-28 09:28:37 +00003495 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003496 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003497 */
3498 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003499 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003500 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3501 dev_info(&adapter->pdev->dev,
3502 "Interrupt Throttle Rate turned off\n");
3503 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003504 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003505 }
3506 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3507 dev_info(&adapter->pdev->dev,
3508 "Interrupt Throttle Rate turned on\n");
3509 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3510 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003511 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003512 }
3513 }
3514
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515 /* Allow time for pending master requests to run */
3516 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003517
Bruce Allane921eb12012-11-28 09:28:37 +00003518 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003519 * that the network interface is in control
3520 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003521 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003522 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003523
Auke Kokbc7f75f2007-09-17 12:30:59 -07003524 ew32(WUC, 0);
3525
3526 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003527 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003528
3529 e1000_update_mng_vlan(adapter);
3530
3531 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3532 ew32(VET, ETH_P_8021Q);
3533
3534 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003535
3536 if (!netif_running(adapter->netdev) &&
3537 !test_bit(__E1000_TESTING, &adapter->state)) {
3538 e1000_power_down_phy(adapter);
3539 return;
3540 }
3541
Auke Kokbc7f75f2007-09-17 12:30:59 -07003542 e1000_get_phy_info(hw);
3543
Bruce Allan918d7192009-06-02 11:28:20 +00003544 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3545 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003547 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003548 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003549 * different we would do if it failed
3550 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003551 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3552 phy_data &= ~IGP02E1000_PM_SPD;
3553 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3554 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003555}
3556
3557int e1000e_up(struct e1000_adapter *adapter)
3558{
3559 struct e1000_hw *hw = &adapter->hw;
3560
3561 /* hardware has been reset, we need to reload some things */
3562 e1000_configure(adapter);
3563
3564 clear_bit(__E1000_DOWN, &adapter->state);
3565
Bruce Allan4662e822008-08-26 18:37:06 -07003566 if (adapter->msix_entries)
3567 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 e1000_irq_enable(adapter);
3569
Bruce Allan400484f2011-05-13 07:20:03 +00003570 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003571
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003573 if (adapter->msix_entries)
3574 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3575 else
3576 ew32(ICS, E1000_ICS_LSC);
3577
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578 return 0;
3579}
3580
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003581static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3582{
3583 struct e1000_hw *hw = &adapter->hw;
3584
3585 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3586 return;
3587
3588 /* flush pending descriptor writebacks to memory */
3589 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3590 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3591
3592 /* execute the writes immediately */
3593 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003594
Bruce Allane921eb12012-11-28 09:28:37 +00003595 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003596 * write is successful
3597 */
3598 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3599 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3600
3601 /* execute the writes immediately */
3602 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003603}
3604
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003605static void e1000e_update_stats(struct e1000_adapter *adapter);
3606
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607void e1000e_down(struct e1000_adapter *adapter)
3608{
3609 struct net_device *netdev = adapter->netdev;
3610 struct e1000_hw *hw = &adapter->hw;
3611 u32 tctl, rctl;
3612
Bruce Allane921eb12012-11-28 09:28:37 +00003613 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003614 * reschedule our watchdog timer
3615 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003616 set_bit(__E1000_DOWN, &adapter->state);
3617
3618 /* disable receives in the hardware */
3619 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003620 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3621 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003622 /* flush and sleep below */
3623
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003624 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625
3626 /* disable transmits in the hardware */
3627 tctl = er32(TCTL);
3628 tctl &= ~E1000_TCTL_EN;
3629 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003630
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 /* flush both disables and wait for them to finish */
3632 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003633 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635 e1000_irq_disable(adapter);
3636
3637 del_timer_sync(&adapter->watchdog_timer);
3638 del_timer_sync(&adapter->phy_info_timer);
3639
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003641
3642 spin_lock(&adapter->stats64_lock);
3643 e1000e_update_stats(adapter);
3644 spin_unlock(&adapter->stats64_lock);
3645
Bruce Allan400484f2011-05-13 07:20:03 +00003646 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003647 e1000_clean_tx_ring(adapter->tx_ring);
3648 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003649
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 adapter->link_speed = 0;
3651 adapter->link_duplex = 0;
3652
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003653 if (!pci_channel_offline(adapter->pdev))
3654 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003655
Bruce Allane921eb12012-11-28 09:28:37 +00003656 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07003657 * pci_disable_device here.
3658 */
3659}
3660
3661void e1000e_reinit_locked(struct e1000_adapter *adapter)
3662{
3663 might_sleep();
3664 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003665 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003666 e1000e_down(adapter);
3667 e1000e_up(adapter);
3668 clear_bit(__E1000_RESETTING, &adapter->state);
3669}
3670
3671/**
3672 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3673 * @adapter: board private structure to initialize
3674 *
3675 * e1000_sw_init initializes the Adapter private data structure.
3676 * Fields are initialized based on PCI device information and
3677 * OS network device settings (MTU size).
3678 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05003679static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 struct net_device *netdev = adapter->netdev;
3682
3683 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3684 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003685 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3686 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003687 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3688 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003689
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003690 spin_lock_init(&adapter->stats64_lock);
3691
Bruce Allan4662e822008-08-26 18:37:06 -07003692 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693
Bruce Allan4662e822008-08-26 18:37:06 -07003694 if (e1000_alloc_queues(adapter))
3695 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696
Auke Kokbc7f75f2007-09-17 12:30:59 -07003697 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003698 e1000_irq_disable(adapter);
3699
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700 set_bit(__E1000_DOWN, &adapter->state);
3701 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702}
3703
3704/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003705 * e1000_intr_msi_test - Interrupt Handler
3706 * @irq: interrupt number
3707 * @data: pointer to a network interface device structure
3708 **/
3709static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3710{
3711 struct net_device *netdev = data;
3712 struct e1000_adapter *adapter = netdev_priv(netdev);
3713 struct e1000_hw *hw = &adapter->hw;
3714 u32 icr = er32(ICR);
3715
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003716 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003717 if (icr & E1000_ICR_RXSEQ) {
3718 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00003719 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00003720 * interrupt is handled.
3721 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07003722 wmb();
3723 }
3724
3725 return IRQ_HANDLED;
3726}
3727
3728/**
3729 * e1000_test_msi_interrupt - Returns 0 for successful test
3730 * @adapter: board private struct
3731 *
3732 * code flow taken from tg3.c
3733 **/
3734static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
3735{
3736 struct net_device *netdev = adapter->netdev;
3737 struct e1000_hw *hw = &adapter->hw;
3738 int err;
3739
3740 /* poll_enable hasn't been called yet, so don't need disable */
3741 /* clear any pending events */
3742 er32(ICR);
3743
3744 /* free the real vector and request a test handler */
3745 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07003746 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003747
3748 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00003749 * MSI irq handler will unset this flag
3750 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07003751 adapter->flags |= FLAG_MSI_TEST_FAILED;
3752
3753 err = pci_enable_msi(adapter->pdev);
3754 if (err)
3755 goto msi_test_failed;
3756
Joe Perchesa0607fd2009-11-18 23:29:17 -08003757 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07003758 netdev->name, netdev);
3759 if (err) {
3760 pci_disable_msi(adapter->pdev);
3761 goto msi_test_failed;
3762 }
3763
Bruce Allane921eb12012-11-28 09:28:37 +00003764 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00003765 * interrupt.
3766 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07003767 wmb();
3768
3769 e1000_irq_enable(adapter);
3770
3771 /* fire an unusual interrupt on the test handler */
3772 ew32(ICS, E1000_ICS_RXSEQ);
3773 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00003774 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003775
3776 e1000_irq_disable(adapter);
3777
Bruce Allanbc763292012-08-17 06:18:07 +00003778 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07003779
3780 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07003781 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00003782 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003783 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00003784 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00003785 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003786
3787 free_irq(adapter->pdev->irq, netdev);
3788 pci_disable_msi(adapter->pdev);
3789
Bruce Allanf8d59f72008-08-08 18:36:11 -07003790msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07003791 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00003792 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003793}
3794
3795/**
3796 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
3797 * @adapter: board private struct
3798 *
3799 * code flow taken from tg3.c, called with e1000 interrupts disabled.
3800 **/
3801static int e1000_test_msi(struct e1000_adapter *adapter)
3802{
3803 int err;
3804 u16 pci_cmd;
3805
3806 if (!(adapter->flags & FLAG_MSI_ENABLED))
3807 return 0;
3808
3809 /* disable SERR in case the MSI write causes a master abort */
3810 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00003811 if (pci_cmd & PCI_COMMAND_SERR)
3812 pci_write_config_word(adapter->pdev, PCI_COMMAND,
3813 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07003814
3815 err = e1000_test_msi_interrupt(adapter);
3816
Dean Nelson36f24072010-06-29 18:12:05 +00003817 /* re-enable SERR */
3818 if (pci_cmd & PCI_COMMAND_SERR) {
3819 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
3820 pci_cmd |= PCI_COMMAND_SERR;
3821 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
3822 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07003823
Bruce Allanf8d59f72008-08-08 18:36:11 -07003824 return err;
3825}
3826
3827/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003828 * e1000_open - Called when a network interface is made active
3829 * @netdev: network interface device structure
3830 *
3831 * Returns 0 on success, negative value on failure
3832 *
3833 * The open entry point is called when a network interface is made
3834 * active by the system (IFF_UP). At this point all resources needed
3835 * for transmit and receive operations are allocated, the interrupt
3836 * handler is registered with the OS, the watchdog timer is started,
3837 * and the stack is notified that the interface is ready.
3838 **/
3839static int e1000_open(struct net_device *netdev)
3840{
3841 struct e1000_adapter *adapter = netdev_priv(netdev);
3842 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003843 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003844 int err;
3845
3846 /* disallow open during test */
3847 if (test_bit(__E1000_TESTING, &adapter->state))
3848 return -EBUSY;
3849
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003850 pm_runtime_get_sync(&pdev->dev);
3851
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00003852 netif_carrier_off(netdev);
3853
Auke Kokbc7f75f2007-09-17 12:30:59 -07003854 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003855 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003856 if (err)
3857 goto err_setup_tx;
3858
3859 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00003860 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003861 if (err)
3862 goto err_setup_rx;
3863
Bruce Allane921eb12012-11-28 09:28:37 +00003864 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00003865 * interface is now open and reset the part to a known state.
3866 */
3867 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003868 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00003869 e1000e_reset(adapter);
3870 }
3871
Auke Kokbc7f75f2007-09-17 12:30:59 -07003872 e1000e_power_up_phy(adapter);
3873
3874 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3875 if ((adapter->hw.mng_cookie.status &
3876 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
3877 e1000_update_mng_vlan(adapter);
3878
Bruce Allan79d4e902011-12-16 00:46:27 +00003879 /* DMA latency requirement to workaround jumbo issue */
3880 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003881 pm_qos_add_request(&adapter->netdev->pm_qos_req,
3882 PM_QOS_CPU_DMA_LATENCY,
3883 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00003884
Bruce Allane921eb12012-11-28 09:28:37 +00003885 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003886 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3887 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07003888 * clean_rx handler before we do so.
3889 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003890 e1000_configure(adapter);
3891
3892 err = e1000_request_irq(adapter);
3893 if (err)
3894 goto err_req_irq;
3895
Bruce Allane921eb12012-11-28 09:28:37 +00003896 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07003897 * ignore e1000e MSI messages, which means we need to test our MSI
3898 * interrupt now
3899 */
Bruce Allan4662e822008-08-26 18:37:06 -07003900 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07003901 err = e1000_test_msi(adapter);
3902 if (err) {
3903 e_err("Interrupt allocation failed\n");
3904 goto err_req_irq;
3905 }
3906 }
3907
Auke Kokbc7f75f2007-09-17 12:30:59 -07003908 /* From here on the code is the same as e1000e_up() */
3909 clear_bit(__E1000_DOWN, &adapter->state);
3910
3911 napi_enable(&adapter->napi);
3912
3913 e1000_irq_enable(adapter);
3914
Jeff Kirsher09357b02011-11-18 14:25:00 +00003915 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003916 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003917
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003918 adapter->idle_check = true;
3919 pm_runtime_put(&pdev->dev);
3920
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003922 if (adapter->msix_entries)
3923 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3924 else
3925 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003926
3927 return 0;
3928
3929err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003930 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003932 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003933err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00003934 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935err_setup_tx:
3936 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003937 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938
3939 return err;
3940}
3941
3942/**
3943 * e1000_close - Disables a network interface
3944 * @netdev: network interface device structure
3945 *
3946 * Returns 0, this is not allowed to fail
3947 *
3948 * The close entry point is called when an interface is de-activated
3949 * by the OS. The hardware is still under the drivers control, but
3950 * needs to be disabled. A global MAC reset is issued to stop the
3951 * hardware, and all transmit and receive resources are freed.
3952 **/
3953static int e1000_close(struct net_device *netdev)
3954{
3955 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003956 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00003957 int count = E1000_CHECK_RESET_COUNT;
3958
3959 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
3960 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961
3962 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003963
3964 pm_runtime_get_sync(&pdev->dev);
3965
Bruce Allan5f4a7802011-11-29 08:09:19 +00003966 napi_disable(&adapter->napi);
3967
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003968 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3969 e1000e_down(adapter);
3970 e1000_free_irq(adapter);
3971 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003972 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973
Bruce Allan55aa6982011-12-16 00:45:45 +00003974 e1000e_free_tx_resources(adapter->tx_ring);
3975 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003976
Bruce Allane921eb12012-11-28 09:28:37 +00003977 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07003978 * the same ID is registered on the host OS (let 8021q kill it)
3979 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003980 if (adapter->hw.mng_cookie.status &
3981 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3983
Bruce Allane921eb12012-11-28 09:28:37 +00003984 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07003985 * interface is now closed
3986 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003987 if ((adapter->flags & FLAG_HAS_AMT) &&
3988 !test_bit(__E1000_TESTING, &adapter->state))
3989 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990
Bruce Allan79d4e902011-12-16 00:46:27 +00003991 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07003992 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00003993
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00003994 pm_runtime_put_sync(&pdev->dev);
3995
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 return 0;
3997}
3998/**
3999 * e1000_set_mac - Change the Ethernet Address of the NIC
4000 * @netdev: network interface device structure
4001 * @p: pointer to an address structure
4002 *
4003 * Returns 0 on success, negative on failure
4004 **/
4005static int e1000_set_mac(struct net_device *netdev, void *p)
4006{
4007 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004008 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 struct sockaddr *addr = p;
4010
4011 if (!is_valid_ether_addr(addr->sa_data))
4012 return -EADDRNOTAVAIL;
4013
4014 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4015 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4016
Bruce Allan69e1e012012-04-14 03:28:50 +00004017 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004018
4019 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4020 /* activate the work around */
4021 e1000e_set_laa_state_82571(&adapter->hw, 1);
4022
Bruce Allane921eb12012-11-28 09:28:37 +00004023 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 * between the time RAR[0] gets clobbered and the time it
4025 * gets fixed (in e1000_watchdog), the actual LAA is in one
4026 * of the RARs and no incoming packets directed to this port
4027 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004028 * RAR[14]
4029 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004030 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4031 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004032 }
4033
4034 return 0;
4035}
4036
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004037/**
4038 * e1000e_update_phy_task - work thread to update phy
4039 * @work: pointer to our work struct
4040 *
4041 * this worker thread exists because we must acquire a
4042 * semaphore to read the phy, which we could msleep while
4043 * waiting for it, and we can't msleep in a timer.
4044 **/
4045static void e1000e_update_phy_task(struct work_struct *work)
4046{
4047 struct e1000_adapter *adapter = container_of(work,
4048 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004049
4050 if (test_bit(__E1000_DOWN, &adapter->state))
4051 return;
4052
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004053 e1000_get_phy_info(&adapter->hw);
4054}
4055
Bruce Allane921eb12012-11-28 09:28:37 +00004056/**
4057 * e1000_update_phy_info - timre call-back to update PHY info
4058 * @data: pointer to adapter cast into an unsigned long
4059 *
Bruce Allanad680762008-03-28 09:15:03 -07004060 * Need to wait a few seconds after link up to get diagnostic information from
4061 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004062 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004063static void e1000_update_phy_info(unsigned long data)
4064{
4065 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004066
4067 if (test_bit(__E1000_DOWN, &adapter->state))
4068 return;
4069
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004070 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071}
4072
4073/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004074 * e1000e_update_phy_stats - Update the PHY statistics counters
4075 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004076 *
4077 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004078 **/
4079static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4080{
4081 struct e1000_hw *hw = &adapter->hw;
4082 s32 ret_val;
4083 u16 phy_data;
4084
4085 ret_val = hw->phy.ops.acquire(hw);
4086 if (ret_val)
4087 return;
4088
Bruce Allane921eb12012-11-28 09:28:37 +00004089 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004090 * If not, set to the page with the PHY status registers.
4091 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004092 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004093 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4094 &phy_data);
4095 if (ret_val)
4096 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004097 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4098 ret_val = hw->phy.ops.set_page(hw,
4099 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004100 if (ret_val)
4101 goto release;
4102 }
4103
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004104 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004105 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4106 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004107 if (!ret_val)
4108 adapter->stats.scc += phy_data;
4109
4110 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004111 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4112 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004113 if (!ret_val)
4114 adapter->stats.ecol += phy_data;
4115
4116 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004117 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4118 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004119 if (!ret_val)
4120 adapter->stats.mcc += phy_data;
4121
4122 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004123 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4124 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004125 if (!ret_val)
4126 adapter->stats.latecol += phy_data;
4127
4128 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004129 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4130 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004131 if (!ret_val)
4132 hw->mac.collision_delta = phy_data;
4133
4134 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004135 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4136 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004137 if (!ret_val)
4138 adapter->stats.dc += phy_data;
4139
4140 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004141 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4142 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004143 if (!ret_val)
4144 adapter->stats.tncrs += phy_data;
4145
4146release:
4147 hw->phy.ops.release(hw);
4148}
4149
4150/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004151 * e1000e_update_stats - Update the board statistics counters
4152 * @adapter: board private structure
4153 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004154static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004155{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004156 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004157 struct e1000_hw *hw = &adapter->hw;
4158 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159
Bruce Allane921eb12012-11-28 09:28:37 +00004160 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004161 * connection is down.
4162 */
4163 if (adapter->link_speed == 0)
4164 return;
4165 if (pci_channel_offline(pdev))
4166 return;
4167
Auke Kokbc7f75f2007-09-17 12:30:59 -07004168 adapter->stats.crcerrs += er32(CRCERRS);
4169 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004170 adapter->stats.gorc += er32(GORCL);
4171 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004172 adapter->stats.bprc += er32(BPRC);
4173 adapter->stats.mprc += er32(MPRC);
4174 adapter->stats.roc += er32(ROC);
4175
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004177
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004178 /* Half-duplex statistics */
4179 if (adapter->link_duplex == HALF_DUPLEX) {
4180 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4181 e1000e_update_phy_stats(adapter);
4182 } else {
4183 adapter->stats.scc += er32(SCC);
4184 adapter->stats.ecol += er32(ECOL);
4185 adapter->stats.mcc += er32(MCC);
4186 adapter->stats.latecol += er32(LATECOL);
4187 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004188
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004189 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004190
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004191 if ((hw->mac.type != e1000_82574) &&
4192 (hw->mac.type != e1000_82583))
4193 adapter->stats.tncrs += er32(TNCRS);
4194 }
4195 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004196 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004197
Auke Kokbc7f75f2007-09-17 12:30:59 -07004198 adapter->stats.xonrxc += er32(XONRXC);
4199 adapter->stats.xontxc += er32(XONTXC);
4200 adapter->stats.xoffrxc += er32(XOFFRXC);
4201 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004202 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004203 adapter->stats.gotc += er32(GOTCL);
4204 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004205 adapter->stats.rnbc += er32(RNBC);
4206 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004207
4208 adapter->stats.mptc += er32(MPTC);
4209 adapter->stats.bptc += er32(BPTC);
4210
4211 /* used for adaptive IFS */
4212
4213 hw->mac.tx_packet_delta = er32(TPT);
4214 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215
4216 adapter->stats.algnerrc += er32(ALGNERRC);
4217 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 adapter->stats.cexterr += er32(CEXTERR);
4219 adapter->stats.tsctc += er32(TSCTC);
4220 adapter->stats.tsctfc += er32(TSCTFC);
4221
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004223 netdev->stats.multicast = adapter->stats.mprc;
4224 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004225
4226 /* Rx Errors */
4227
Bruce Allane921eb12012-11-28 09:28:37 +00004228 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004229 * our own version based on RUC and ROC
4230 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004231 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004232 adapter->stats.crcerrs + adapter->stats.algnerrc +
4233 adapter->stats.ruc + adapter->stats.roc +
4234 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004235 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004236 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004237 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4238 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4239 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004240
4241 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004242 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004243 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004244 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4245 netdev->stats.tx_window_errors = adapter->stats.latecol;
4246 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004247
4248 /* Tx Dropped needs to be maintained elsewhere */
4249
Auke Kokbc7f75f2007-09-17 12:30:59 -07004250 /* Management Stats */
4251 adapter->stats.mgptc += er32(MGTPTC);
4252 adapter->stats.mgprc += er32(MGTPRC);
4253 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254}
4255
Bruce Allan7c257692008-04-23 11:09:00 -07004256/**
4257 * e1000_phy_read_status - Update the PHY register status snapshot
4258 * @adapter: board private structure
4259 **/
4260static void e1000_phy_read_status(struct e1000_adapter *adapter)
4261{
4262 struct e1000_hw *hw = &adapter->hw;
4263 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004264
4265 if ((er32(STATUS) & E1000_STATUS_LU) &&
4266 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004267 int ret_val;
4268
Bruce Allan7c257692008-04-23 11:09:00 -07004269 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4270 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4271 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4272 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4273 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4274 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4275 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4276 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4277 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004278 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004279 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004280 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004281 * Set values to typical power-on defaults
4282 */
4283 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4284 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4285 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4286 BMSR_ERCAP);
4287 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4288 ADVERTISE_ALL | ADVERTISE_CSMA);
4289 phy->lpa = 0;
4290 phy->expansion = EXPANSION_ENABLENPAGE;
4291 phy->ctrl1000 = ADVERTISE_1000FULL;
4292 phy->stat1000 = 0;
4293 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4294 }
Bruce Allan7c257692008-04-23 11:09:00 -07004295}
4296
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297static void e1000_print_link_info(struct e1000_adapter *adapter)
4298{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004299 struct e1000_hw *hw = &adapter->hw;
4300 u32 ctrl = er32(CTRL);
4301
Bruce Allan8f12fe82008-11-21 16:54:43 -08004302 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004303 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4304 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004305 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4306 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4307 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4308 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309}
4310
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004311static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004312{
4313 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004314 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004315 s32 ret_val = 0;
4316
Bruce Allane921eb12012-11-28 09:28:37 +00004317 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004318 * Rx sequence error interrupt. get_link_status will stay
4319 * false until the check_for_link establishes link
4320 * for copper adapters ONLY
4321 */
4322 switch (hw->phy.media_type) {
4323 case e1000_media_type_copper:
4324 if (hw->mac.get_link_status) {
4325 ret_val = hw->mac.ops.check_for_link(hw);
4326 link_active = !hw->mac.get_link_status;
4327 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004328 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004329 }
4330 break;
4331 case e1000_media_type_fiber:
4332 ret_val = hw->mac.ops.check_for_link(hw);
4333 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4334 break;
4335 case e1000_media_type_internal_serdes:
4336 ret_val = hw->mac.ops.check_for_link(hw);
4337 link_active = adapter->hw.mac.serdes_has_link;
4338 break;
4339 default:
4340 case e1000_media_type_unknown:
4341 break;
4342 }
4343
4344 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4345 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4346 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004347 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004348 }
4349
4350 return link_active;
4351}
4352
4353static void e1000e_enable_receives(struct e1000_adapter *adapter)
4354{
4355 /* make sure the receive unit is started */
4356 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004357 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004358 struct e1000_hw *hw = &adapter->hw;
4359 u32 rctl = er32(RCTL);
4360 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004361 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004362 }
4363}
4364
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004365static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4366{
4367 struct e1000_hw *hw = &adapter->hw;
4368
Bruce Allane921eb12012-11-28 09:28:37 +00004369 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004370 * for hung state and reset, if two calls return true
4371 */
4372 if (e1000_check_phy_82574(hw))
4373 adapter->phy_hang_count++;
4374 else
4375 adapter->phy_hang_count = 0;
4376
4377 if (adapter->phy_hang_count > 1) {
4378 adapter->phy_hang_count = 0;
4379 schedule_work(&adapter->reset_task);
4380 }
4381}
4382
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383/**
4384 * e1000_watchdog - Timer Call-back
4385 * @data: pointer to adapter cast into an unsigned long
4386 **/
4387static void e1000_watchdog(unsigned long data)
4388{
4389 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4390
4391 /* Do the rest outside of interrupt context */
4392 schedule_work(&adapter->watchdog_task);
4393
4394 /* TODO: make this use queue_delayed_work() */
4395}
4396
4397static void e1000_watchdog_task(struct work_struct *work)
4398{
4399 struct e1000_adapter *adapter = container_of(work,
4400 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401 struct net_device *netdev = adapter->netdev;
4402 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004403 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004404 struct e1000_ring *tx_ring = adapter->tx_ring;
4405 struct e1000_hw *hw = &adapter->hw;
4406 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004408 if (test_bit(__E1000_DOWN, &adapter->state))
4409 return;
4410
David S. Millerb405e8d2010-02-04 22:31:41 -08004411 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004412 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004413 /* Cancel scheduled suspend requests. */
4414 pm_runtime_resume(netdev->dev.parent);
4415
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004416 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004417 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418 }
4419
4420 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4421 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4422 e1000_update_mng_vlan(adapter);
4423
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 if (link) {
4425 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004426 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004427
4428 /* Cancel scheduled suspend requests. */
4429 pm_runtime_resume(netdev->dev.parent);
4430
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004431 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004432 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433 mac->ops.get_link_up_info(&adapter->hw,
4434 &adapter->link_speed,
4435 &adapter->link_duplex);
4436 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004437 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004438 * if link has autonegotiated at 10/100 half
4439 */
4440 if ((hw->phy.type == e1000_phy_igp_3 ||
4441 hw->phy.type == e1000_phy_bm) &&
4442 (hw->mac.autoneg == true) &&
4443 (adapter->link_speed == SPEED_10 ||
4444 adapter->link_speed == SPEED_100) &&
4445 (adapter->link_duplex == HALF_DUPLEX)) {
4446 u16 autoneg_exp;
4447
4448 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4449
4450 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004451 e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07004452 }
4453
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004454 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455 adapter->tx_timeout_factor = 1;
4456 switch (adapter->link_speed) {
4457 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004458 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004459 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004460 break;
4461 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004462 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004463 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004464 break;
4465 }
4466
Bruce Allane921eb12012-11-28 09:28:37 +00004467 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004468 * link-up event
4469 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004470 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4471 !txb2b) {
4472 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004473 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004474 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004475 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476 }
4477
Bruce Allane921eb12012-11-28 09:28:37 +00004478 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004479 * some hardware issues
4480 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004481 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4482 switch (adapter->link_speed) {
4483 case SPEED_10:
4484 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004485 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486 netdev->features &= ~NETIF_F_TSO;
4487 netdev->features &= ~NETIF_F_TSO6;
4488 break;
4489 case SPEED_1000:
4490 netdev->features |= NETIF_F_TSO;
4491 netdev->features |= NETIF_F_TSO6;
4492 break;
4493 default:
4494 /* oops */
4495 break;
4496 }
4497 }
4498
Bruce Allane921eb12012-11-28 09:28:37 +00004499 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004500 * after setting TARC(0)
4501 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502 tctl = er32(TCTL);
4503 tctl |= E1000_TCTL_EN;
4504 ew32(TCTL, tctl);
4505
Bruce Allane921eb12012-11-28 09:28:37 +00004506 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004507 * reporting link up.
4508 */
4509 if (phy->ops.cfg_on_link_up)
4510 phy->ops.cfg_on_link_up(hw);
4511
Auke Kokbc7f75f2007-09-17 12:30:59 -07004512 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004513
4514 if (!test_bit(__E1000_DOWN, &adapter->state))
4515 mod_timer(&adapter->phy_info_timer,
4516 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004517 }
4518 } else {
4519 if (netif_carrier_ok(netdev)) {
4520 adapter->link_speed = 0;
4521 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004522 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004523 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004525 if (!test_bit(__E1000_DOWN, &adapter->state))
4526 mod_timer(&adapter->phy_info_timer,
4527 round_jiffies(jiffies + 2 * HZ));
4528
Bruce Allan12d43f72012-12-05 06:26:14 +00004529 /* The link is lost so the controller stops DMA.
4530 * If there is queued Tx work that cannot be done
4531 * or if on an 8000ES2LAN which requires a Rx packet
4532 * buffer work-around on link down event, reset the
4533 * controller to flush the Tx/Rx packet buffers.
4534 * (Do the reset outside of interrupt context).
4535 */
4536 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4537 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4538 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004539 else
4540 pm_schedule_suspend(netdev->dev.parent,
4541 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004542 }
4543 }
4544
4545link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004546 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 e1000e_update_stats(adapter);
4548
4549 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4550 adapter->tpt_old = adapter->stats.tpt;
4551 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4552 adapter->colc_old = adapter->stats.colc;
4553
Bruce Allan7c257692008-04-23 11:09:00 -07004554 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4555 adapter->gorc_old = adapter->stats.gorc;
4556 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4557 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004558 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559
Bruce Allan12d43f72012-12-05 06:26:14 +00004560 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004561 schedule_work(&adapter->reset_task);
4562 /* return immediately since reset is imminent */
4563 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564 }
4565
Bruce Allan12d43f72012-12-05 06:26:14 +00004566 e1000e_update_adaptive(&adapter->hw);
4567
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004568 /* Simple mode for Interrupt Throttle Rate (ITR) */
4569 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004570 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004571 * Total asymmetrical Tx or Rx gets ITR=8000;
4572 * everyone else is between 2000-8000.
4573 */
4574 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4575 u32 dif = (adapter->gotc > adapter->gorc ?
4576 adapter->gotc - adapter->gorc :
4577 adapter->gorc - adapter->gotc) / 10000;
4578 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4579
Matthew Vick22a4cca2012-07-12 00:02:42 +00004580 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004581 }
4582
Bruce Allanad680762008-03-28 09:15:03 -07004583 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004584 if (adapter->msix_entries)
4585 ew32(ICS, adapter->rx_ring->ims_val);
4586 else
4587 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004589 /* flush pending descriptors to memory before detecting Tx hang */
4590 e1000e_flush_descriptors(adapter);
4591
Auke Kokbc7f75f2007-09-17 12:30:59 -07004592 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004593 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004594
Bruce Allane921eb12012-11-28 09:28:37 +00004595 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07004596 * reset from the other port. Set the appropriate LAA in RAR[0]
4597 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004598 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00004599 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004601 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4602 e1000e_check_82574_phy_workaround(adapter);
4603
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604 /* Reset the timer */
4605 if (!test_bit(__E1000_DOWN, &adapter->state))
4606 mod_timer(&adapter->watchdog_timer,
4607 round_jiffies(jiffies + 2 * HZ));
4608}
4609
4610#define E1000_TX_FLAGS_CSUM 0x00000001
4611#define E1000_TX_FLAGS_VLAN 0x00000002
4612#define E1000_TX_FLAGS_TSO 0x00000004
4613#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00004614#define E1000_TX_FLAGS_NO_FCS 0x00000010
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4616#define E1000_TX_FLAGS_VLAN_SHIFT 16
4617
Bruce Allan55aa6982011-12-16 00:45:45 +00004618static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004619{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620 struct e1000_context_desc *context_desc;
4621 struct e1000_buffer *buffer_info;
4622 unsigned int i;
4623 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00004624 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004626
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004627 if (!skb_is_gso(skb))
4628 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004630 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004631 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4632
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004633 if (err)
4634 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635 }
4636
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004637 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4638 mss = skb_shinfo(skb)->gso_size;
4639 if (skb->protocol == htons(ETH_P_IP)) {
4640 struct iphdr *iph = ip_hdr(skb);
4641 iph->tot_len = 0;
4642 iph->check = 0;
4643 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4644 0, IPPROTO_TCP, 0);
4645 cmd_length = E1000_TXD_CMD_IP;
4646 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004647 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004648 ipv6_hdr(skb)->payload_len = 0;
4649 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4650 &ipv6_hdr(skb)->daddr,
4651 0, IPPROTO_TCP, 0);
4652 ipcse = 0;
4653 }
4654 ipcss = skb_network_offset(skb);
4655 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4656 tucss = skb_transport_offset(skb);
4657 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004658
4659 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4660 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4661
4662 i = tx_ring->next_to_use;
4663 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4664 buffer_info = &tx_ring->buffer_info[i];
4665
4666 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4667 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4668 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4669 context_desc->upper_setup.tcp_fields.tucss = tucss;
4670 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00004671 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004672 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4673 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4674 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4675
4676 buffer_info->time_stamp = jiffies;
4677 buffer_info->next_to_watch = i;
4678
4679 i++;
4680 if (i == tx_ring->count)
4681 i = 0;
4682 tx_ring->next_to_use = i;
4683
4684 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004685}
4686
Bruce Allan55aa6982011-12-16 00:45:45 +00004687static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004688{
Bruce Allan55aa6982011-12-16 00:45:45 +00004689 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004690 struct e1000_context_desc *context_desc;
4691 struct e1000_buffer *buffer_info;
4692 unsigned int i;
4693 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004694 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004695 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004696
Dave Grahamaf807c82008-10-09 14:28:58 -07004697 if (skb->ip_summed != CHECKSUM_PARTIAL)
4698 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004699
Arthur Jones5f66f202009-03-19 01:13:08 +00004700 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4701 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
4702 else
4703 protocol = skb->protocol;
4704
Arthur Jones3f518392009-03-20 15:56:35 -07004705 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004706 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07004707 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4708 cmd_len |= E1000_TXD_CMD_TCP;
4709 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004710 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07004711 /* XXX not handling all IPV6 headers */
4712 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4713 cmd_len |= E1000_TXD_CMD_TCP;
4714 break;
4715 default:
4716 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00004717 e_warn("checksum_partial proto=%x!\n",
4718 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07004719 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004720 }
4721
Michał Mirosław0d0b1672010-12-14 15:24:08 +00004722 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07004723
4724 i = tx_ring->next_to_use;
4725 buffer_info = &tx_ring->buffer_info[i];
4726 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4727
4728 context_desc->lower_setup.ip_config = 0;
4729 context_desc->upper_setup.tcp_fields.tucss = css;
4730 context_desc->upper_setup.tcp_fields.tucso =
4731 css + skb->csum_offset;
4732 context_desc->upper_setup.tcp_fields.tucse = 0;
4733 context_desc->tcp_seg_setup.data = 0;
4734 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
4735
4736 buffer_info->time_stamp = jiffies;
4737 buffer_info->next_to_watch = i;
4738
4739 i++;
4740 if (i == tx_ring->count)
4741 i = 0;
4742 tx_ring->next_to_use = i;
4743
4744 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004745}
4746
Bruce Allan55aa6982011-12-16 00:45:45 +00004747static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
4748 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00004749 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004750{
Bruce Allan55aa6982011-12-16 00:45:45 +00004751 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00004752 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004753 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08004754 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00004755 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004756 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004757
4758 i = tx_ring->next_to_use;
4759
4760 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004761 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762 size = min(len, max_per_txd);
4763
Auke Kokbc7f75f2007-09-17 12:30:59 -07004764 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004765 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004766 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00004767 buffer_info->dma = dma_map_single(&pdev->dev,
4768 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00004769 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004770 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00004771 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004772 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004773
4774 len -= size;
4775 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00004776 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004777
4778 if (len) {
4779 i++;
4780 if (i == tx_ring->count)
4781 i = 0;
4782 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004783 }
4784
4785 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00004786 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004787
4788 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00004789 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00004790 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004791
4792 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00004793 i++;
4794 if (i == tx_ring->count)
4795 i = 0;
4796
Auke Kokbc7f75f2007-09-17 12:30:59 -07004797 buffer_info = &tx_ring->buffer_info[i];
4798 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799
4800 buffer_info->length = size;
4801 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00004803 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
4804 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00004805 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00004806 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00004807 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004808
4809 len -= size;
4810 offset += size;
4811 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812 }
4813 }
4814
Bruce Allanaf667a22010-12-31 06:10:01 +00004815 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004816 /* multiply data chunks by size of headers */
4817 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
4818
Auke Kokbc7f75f2007-09-17 12:30:59 -07004819 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00004820 tx_ring->buffer_info[i].segs = segs;
4821 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822 tx_ring->buffer_info[first].next_to_watch = i;
4823
4824 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00004825
4826dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00004827 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00004828 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004829 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00004830 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004831
4832 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00004833 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00004834 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00004835 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00004836 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00004837 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00004838 }
4839
4840 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004841}
4842
Bruce Allan55aa6982011-12-16 00:45:45 +00004843static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844{
Bruce Allan55aa6982011-12-16 00:45:45 +00004845 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004846 struct e1000_tx_desc *tx_desc = NULL;
4847 struct e1000_buffer *buffer_info;
4848 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
4849 unsigned int i;
4850
4851 if (tx_flags & E1000_TX_FLAGS_TSO) {
4852 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
4853 E1000_TXD_CMD_TSE;
4854 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4855
4856 if (tx_flags & E1000_TX_FLAGS_IPV4)
4857 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
4858 }
4859
4860 if (tx_flags & E1000_TX_FLAGS_CSUM) {
4861 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
4862 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
4863 }
4864
4865 if (tx_flags & E1000_TX_FLAGS_VLAN) {
4866 txd_lower |= E1000_TXD_CMD_VLE;
4867 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
4868 }
4869
Ben Greear943146d2012-02-11 15:39:40 +00004870 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4871 txd_lower &= ~(E1000_TXD_CMD_IFCS);
4872
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873 i = tx_ring->next_to_use;
4874
Bruce Allan36b973d2010-11-24 07:42:43 +00004875 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876 buffer_info = &tx_ring->buffer_info[i];
4877 tx_desc = E1000_TX_DESC(*tx_ring, i);
4878 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4879 tx_desc->lower.data =
4880 cpu_to_le32(txd_lower | buffer_info->length);
4881 tx_desc->upper.data = cpu_to_le32(txd_upper);
4882
4883 i++;
4884 if (i == tx_ring->count)
4885 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00004886 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887
4888 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
4889
Ben Greear943146d2012-02-11 15:39:40 +00004890 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
4891 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
4892 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
4893
Bruce Allane921eb12012-11-28 09:28:37 +00004894 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07004895 * know there are new descriptors to fetch. (Only
4896 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07004897 * such as IA-64).
4898 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004899 wmb();
4900
4901 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07004902
4903 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00004904 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07004905 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00004906 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07004907
Bruce Allane921eb12012-11-28 09:28:37 +00004908 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07004909 * at a time, it synchronizes IO on IA64/Altix systems
4910 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 mmiowb();
4912}
4913
4914#define MINIMUM_DHCP_PACKET_SIZE 282
4915static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
4916 struct sk_buff *skb)
4917{
4918 struct e1000_hw *hw = &adapter->hw;
4919 u16 length, offset;
4920
4921 if (vlan_tx_tag_present(skb)) {
Joe Perches8e95a202009-12-03 07:58:21 +00004922 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
4923 (adapter->hw.mng_cookie.status &
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
4925 return 0;
4926 }
4927
4928 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
4929 return 0;
4930
4931 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
4932 return 0;
4933
4934 {
4935 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
4936 struct udphdr *udp;
4937
4938 if (ip->protocol != IPPROTO_UDP)
4939 return 0;
4940
4941 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
4942 if (ntohs(udp->dest) != 67)
4943 return 0;
4944
4945 offset = (u8 *)udp + 8 - skb->data;
4946 length = skb->len - offset;
4947 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
4948 }
4949
4950 return 0;
4951}
4952
Bruce Allan55aa6982011-12-16 00:45:45 +00004953static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954{
Bruce Allan55aa6982011-12-16 00:45:45 +00004955 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956
Bruce Allan55aa6982011-12-16 00:45:45 +00004957 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00004958 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004959 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07004960 * but since that doesn't exist yet, just open code it.
4961 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004962 smp_mb();
4963
Bruce Allane921eb12012-11-28 09:28:37 +00004964 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07004965 * made room available.
4966 */
Bruce Allan55aa6982011-12-16 00:45:45 +00004967 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968 return -EBUSY;
4969
4970 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00004971 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972 ++adapter->restart_queue;
4973 return 0;
4974}
4975
Bruce Allan55aa6982011-12-16 00:45:45 +00004976static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004977{
Bruce Alland821a4c2012-08-24 20:38:11 +00004978 BUG_ON(size > tx_ring->count);
4979
Bruce Allan55aa6982011-12-16 00:45:45 +00004980 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004981 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00004982 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983}
4984
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004985static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
4986 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004987{
4988 struct e1000_adapter *adapter = netdev_priv(netdev);
4989 struct e1000_ring *tx_ring = adapter->tx_ring;
4990 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07004992 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07004993 unsigned int nr_frags;
4994 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004995 int count = 0;
4996 int tso;
4997 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998
4999 if (test_bit(__E1000_DOWN, &adapter->state)) {
5000 dev_kfree_skb_any(skb);
5001 return NETDEV_TX_OK;
5002 }
5003
5004 if (skb->len <= 0) {
5005 dev_kfree_skb_any(skb);
5006 return NETDEV_TX_OK;
5007 }
5008
Bruce Allane921eb12012-11-28 09:28:37 +00005009 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005010 * pad skb in order to meet this minimum size requirement
5011 */
5012 if (unlikely(skb->len < 17)) {
5013 if (skb_pad(skb, 17 - skb->len))
5014 return NETDEV_TX_OK;
5015 skb->len = 17;
5016 skb_set_tail_pointer(skb, 17);
5017 }
5018
Auke Kokbc7f75f2007-09-17 12:30:59 -07005019 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005020 if (mss) {
5021 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005022
Bruce Allane921eb12012-11-28 09:28:37 +00005023 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005024 * points to just header, pull a few bytes of payload from
5025 * frags into skb->data
5026 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005027 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005028 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005029 * avoiding it could save a lot of cycles
5030 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005031 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005032 unsigned int pull_size;
5033
Bruce Allana2a5b322012-01-31 06:37:17 +00005034 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005035 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005036 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 dev_kfree_skb_any(skb);
5038 return NETDEV_TX_OK;
5039 }
Eric Dumazete743d312010-04-14 15:59:40 -07005040 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041 }
5042 }
5043
5044 /* reserve a descriptor for the offload context */
5045 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5046 count++;
5047 count++;
5048
Bruce Alland821a4c2012-08-24 20:38:11 +00005049 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050
5051 nr_frags = skb_shinfo(skb)->nr_frags;
5052 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005053 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5054 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055
5056 if (adapter->hw.mac.tx_pkt_filtering)
5057 e1000_transfer_dhcp_info(adapter, skb);
5058
Bruce Allane921eb12012-11-28 09:28:37 +00005059 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005060 * head, otherwise try next time
5061 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005062 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005064
Jesse Grosseab6d182010-10-20 13:56:03 +00005065 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005066 tx_flags |= E1000_TX_FLAGS_VLAN;
5067 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5068 }
5069
5070 first = tx_ring->next_to_use;
5071
Bruce Allan55aa6982011-12-16 00:45:45 +00005072 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073 if (tso < 0) {
5074 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005075 return NETDEV_TX_OK;
5076 }
5077
5078 if (tso)
5079 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005080 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005081 tx_flags |= E1000_TX_FLAGS_CSUM;
5082
Bruce Allane921eb12012-11-28 09:28:37 +00005083 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005084 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005085 * no longer assume, we must.
5086 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005087 if (skb->protocol == htons(ETH_P_IP))
5088 tx_flags |= E1000_TX_FLAGS_IPV4;
5089
Ben Greear943146d2012-02-11 15:39:40 +00005090 if (unlikely(skb->no_fcs))
5091 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5092
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005093 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005094 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5095 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005096 if (count) {
Willem de Bruijn80be3122012-04-27 09:04:05 +00005097 skb_tx_timestamp(skb);
5098
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005099 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005100 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005101 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005102 e1000_maybe_stop_tx(tx_ring,
5103 (MAX_SKB_FRAGS *
5104 DIV_ROUND_UP(PAGE_SIZE,
5105 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005106 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005108 tx_ring->buffer_info[first].time_stamp = 0;
5109 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110 }
5111
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112 return NETDEV_TX_OK;
5113}
5114
5115/**
5116 * e1000_tx_timeout - Respond to a Tx Hang
5117 * @netdev: network interface device structure
5118 **/
5119static void e1000_tx_timeout(struct net_device *netdev)
5120{
5121 struct e1000_adapter *adapter = netdev_priv(netdev);
5122
5123 /* Do the reset outside of interrupt context */
5124 adapter->tx_timeout_count++;
5125 schedule_work(&adapter->reset_task);
5126}
5127
5128static void e1000_reset_task(struct work_struct *work)
5129{
5130 struct e1000_adapter *adapter;
5131 adapter = container_of(work, struct e1000_adapter, reset_task);
5132
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005133 /* don't run the task if already down */
5134 if (test_bit(__E1000_DOWN, &adapter->state))
5135 return;
5136
Bruce Allan12d43f72012-12-05 06:26:14 +00005137 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005138 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005139 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005140 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 e1000e_reinit_locked(adapter);
5142}
5143
5144/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005145 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005146 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005147 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005148 *
5149 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005150 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005151struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5152 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005153{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005154 struct e1000_adapter *adapter = netdev_priv(netdev);
5155
5156 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5157 spin_lock(&adapter->stats64_lock);
5158 e1000e_update_stats(adapter);
5159 /* Fill out the OS statistics structure */
5160 stats->rx_bytes = adapter->stats.gorc;
5161 stats->rx_packets = adapter->stats.gprc;
5162 stats->tx_bytes = adapter->stats.gotc;
5163 stats->tx_packets = adapter->stats.gptc;
5164 stats->multicast = adapter->stats.mprc;
5165 stats->collisions = adapter->stats.colc;
5166
5167 /* Rx Errors */
5168
Bruce Allane921eb12012-11-28 09:28:37 +00005169 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005170 * our own version based on RUC and ROC
5171 */
5172 stats->rx_errors = adapter->stats.rxerrc +
5173 adapter->stats.crcerrs + adapter->stats.algnerrc +
5174 adapter->stats.ruc + adapter->stats.roc +
5175 adapter->stats.cexterr;
5176 stats->rx_length_errors = adapter->stats.ruc +
5177 adapter->stats.roc;
5178 stats->rx_crc_errors = adapter->stats.crcerrs;
5179 stats->rx_frame_errors = adapter->stats.algnerrc;
5180 stats->rx_missed_errors = adapter->stats.mpc;
5181
5182 /* Tx Errors */
5183 stats->tx_errors = adapter->stats.ecol +
5184 adapter->stats.latecol;
5185 stats->tx_aborted_errors = adapter->stats.ecol;
5186 stats->tx_window_errors = adapter->stats.latecol;
5187 stats->tx_carrier_errors = adapter->stats.tncrs;
5188
5189 /* Tx Dropped needs to be maintained elsewhere */
5190
5191 spin_unlock(&adapter->stats64_lock);
5192 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193}
5194
5195/**
5196 * e1000_change_mtu - Change the Maximum Transfer Unit
5197 * @netdev: network interface device structure
5198 * @new_mtu: new value for maximum frame size
5199 *
5200 * Returns 0 on success, negative on failure
5201 **/
5202static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5203{
5204 struct e1000_adapter *adapter = netdev_priv(netdev);
5205 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5206
Bruce Allan2adc55c2009-06-02 11:28:58 +00005207 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005208 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5209 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5210 e_err("Jumbo Frames not supported.\n");
5211 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212 }
5213
Bruce Allan2adc55c2009-06-02 11:28:58 +00005214 /* Supported frame sizes */
5215 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5216 (max_frame > adapter->max_hw_frame_size)) {
5217 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005218 return -EINVAL;
5219 }
5220
Bruce Allan2fbe4522012-04-19 03:21:47 +00005221 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5222 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005223 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5224 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005225 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005226 return -EINVAL;
5227 }
5228
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005230 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005231 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005232 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005233 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5234 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005235 if (netif_running(netdev))
5236 e1000e_down(adapter);
5237
Bruce Allane921eb12012-11-28 09:28:37 +00005238 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239 * means we reserve 2 more, this pushes us to allocate from the next
5240 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005241 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005242 * However with the new *_jumbo_rx* routines, jumbo receives will use
5243 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005244 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005245
Jesse Brandeburg99261462010-01-22 22:56:16 +00005246 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005247 adapter->rx_buffer_len = 2048;
5248 else
5249 adapter->rx_buffer_len = 4096;
5250
5251 /* adjust allocation if LPE protects us, and we aren't using SBP */
5252 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5253 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5254 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005255 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256
Auke Kokbc7f75f2007-09-17 12:30:59 -07005257 if (netif_running(netdev))
5258 e1000e_up(adapter);
5259 else
5260 e1000e_reset(adapter);
5261
5262 clear_bit(__E1000_RESETTING, &adapter->state);
5263
5264 return 0;
5265}
5266
5267static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5268 int cmd)
5269{
5270 struct e1000_adapter *adapter = netdev_priv(netdev);
5271 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005273 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005274 return -EOPNOTSUPP;
5275
5276 switch (cmd) {
5277 case SIOCGMIIPHY:
5278 data->phy_id = adapter->hw.phy.addr;
5279 break;
5280 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005281 e1000_phy_read_status(adapter);
5282
Bruce Allan7c257692008-04-23 11:09:00 -07005283 switch (data->reg_num & 0x1F) {
5284 case MII_BMCR:
5285 data->val_out = adapter->phy_regs.bmcr;
5286 break;
5287 case MII_BMSR:
5288 data->val_out = adapter->phy_regs.bmsr;
5289 break;
5290 case MII_PHYSID1:
5291 data->val_out = (adapter->hw.phy.id >> 16);
5292 break;
5293 case MII_PHYSID2:
5294 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5295 break;
5296 case MII_ADVERTISE:
5297 data->val_out = adapter->phy_regs.advertise;
5298 break;
5299 case MII_LPA:
5300 data->val_out = adapter->phy_regs.lpa;
5301 break;
5302 case MII_EXPANSION:
5303 data->val_out = adapter->phy_regs.expansion;
5304 break;
5305 case MII_CTRL1000:
5306 data->val_out = adapter->phy_regs.ctrl1000;
5307 break;
5308 case MII_STAT1000:
5309 data->val_out = adapter->phy_regs.stat1000;
5310 break;
5311 case MII_ESTATUS:
5312 data->val_out = adapter->phy_regs.estatus;
5313 break;
5314 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005315 return -EIO;
5316 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005317 break;
5318 case SIOCSMIIREG:
5319 default:
5320 return -EOPNOTSUPP;
5321 }
5322 return 0;
5323}
5324
5325static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5326{
5327 switch (cmd) {
5328 case SIOCGMIIPHY:
5329 case SIOCGMIIREG:
5330 case SIOCSMIIREG:
5331 return e1000_mii_ioctl(netdev, ifr, cmd);
5332 default:
5333 return -EOPNOTSUPP;
5334 }
5335}
5336
Bruce Allana4f58f52009-06-02 11:29:18 +00005337static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5338{
5339 struct e1000_hw *hw = &adapter->hw;
5340 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005341 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005342 int retval = 0;
5343
5344 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005345 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005346
Bruce Allan2b6b1682011-05-13 07:20:09 +00005347 retval = hw->phy.ops.acquire(hw);
5348 if (retval) {
5349 e_err("Could not acquire PHY\n");
5350 return retval;
5351 }
5352
5353 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5354 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5355 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005356 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005357
5358 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005359 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5360 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005361 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5362 (u16)(mac_reg & 0xFFFF));
5363 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5364 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005365 }
5366
5367 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005368 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005369 mac_reg = er32(RCTL);
5370 if (mac_reg & E1000_RCTL_UPE)
5371 phy_reg |= BM_RCTL_UPE;
5372 if (mac_reg & E1000_RCTL_MPE)
5373 phy_reg |= BM_RCTL_MPE;
5374 phy_reg &= ~(BM_RCTL_MO_MASK);
5375 if (mac_reg & E1000_RCTL_MO_3)
5376 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5377 << BM_RCTL_MO_SHIFT);
5378 if (mac_reg & E1000_RCTL_BAM)
5379 phy_reg |= BM_RCTL_BAM;
5380 if (mac_reg & E1000_RCTL_PMCF)
5381 phy_reg |= BM_RCTL_PMCF;
5382 mac_reg = er32(CTRL);
5383 if (mac_reg & E1000_CTRL_RFCE)
5384 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005385 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005386
5387 /* enable PHY wakeup in MAC register */
5388 ew32(WUFC, wufc);
5389 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5390
5391 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005392 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5393 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005394
5395 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005396 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5397 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005398 if (retval)
5399 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005400release:
Bruce Allan94d81862009-11-20 23:25:26 +00005401 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005402
5403 return retval;
5404}
5405
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005406static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5407 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408{
5409 struct net_device *netdev = pci_get_drvdata(pdev);
5410 struct e1000_adapter *adapter = netdev_priv(netdev);
5411 struct e1000_hw *hw = &adapter->hw;
5412 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005413 /* Runtime suspend should only enable wakeup for link changes */
5414 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005415 int retval = 0;
5416
5417 netif_device_detach(netdev);
5418
5419 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005420 int count = E1000_CHECK_RESET_COUNT;
5421
5422 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5423 usleep_range(10000, 20000);
5424
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5426 e1000e_down(adapter);
5427 e1000_free_irq(adapter);
5428 }
Bruce Allan4662e822008-08-26 18:37:06 -07005429 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430
5431 retval = pci_save_state(pdev);
5432 if (retval)
5433 return retval;
5434
5435 status = er32(STATUS);
5436 if (status & E1000_STATUS_LU)
5437 wufc &= ~E1000_WUFC_LNKC;
5438
5439 if (wufc) {
5440 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005441 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005442
5443 /* turn on all-multi mode if wake on multicast is enabled */
5444 if (wufc & E1000_WUFC_MC) {
5445 rctl = er32(RCTL);
5446 rctl |= E1000_RCTL_MPE;
5447 ew32(RCTL, rctl);
5448 }
5449
5450 ctrl = er32(CTRL);
5451 /* advertise wake from D3Cold */
5452 #define E1000_CTRL_ADVD3WUC 0x00100000
5453 /* phy power management enable */
5454 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005455 ctrl |= E1000_CTRL_ADVD3WUC;
5456 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5457 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005458 ew32(CTRL, ctrl);
5459
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005460 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5461 adapter->hw.phy.media_type ==
5462 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 /* keep the laser running in D3 */
5464 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005465 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466 ew32(CTRL_EXT, ctrl_ext);
5467 }
5468
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005469 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005470 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005471
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472 /* Allow time for pending master requests to run */
5473 e1000e_disable_pcie_master(&adapter->hw);
5474
Bruce Allan82776a42009-08-14 14:35:33 +00005475 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005476 /* enable wakeup by the PHY */
5477 retval = e1000_init_phy_wakeup(adapter, wufc);
5478 if (retval)
5479 return retval;
5480 } else {
5481 /* enable wakeup by the MAC */
5482 ew32(WUFC, wufc);
5483 ew32(WUC, E1000_WUC_PME_EN);
5484 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005485 } else {
5486 ew32(WUC, 0);
5487 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488 }
5489
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005490 *enable_wake = !!wufc;
5491
Auke Kokbc7f75f2007-09-17 12:30:59 -07005492 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005493 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5494 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005495 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005496
5497 if (adapter->hw.phy.type == e1000_phy_igp_3)
5498 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5499
Bruce Allane921eb12012-11-28 09:28:37 +00005500 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005501 * would have already happened in close and is redundant.
5502 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005503 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005504
5505 pci_disable_device(pdev);
5506
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005507 return 0;
5508}
5509
5510static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5511{
5512 if (sleep && wake) {
5513 pci_prepare_to_sleep(pdev);
5514 return;
5515 }
5516
5517 pci_wake_from_d3(pdev, wake);
5518 pci_set_power_state(pdev, PCI_D3hot);
5519}
5520
5521static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5522 bool wake)
5523{
5524 struct net_device *netdev = pci_get_drvdata(pdev);
5525 struct e1000_adapter *adapter = netdev_priv(netdev);
5526
Bruce Allane921eb12012-11-28 09:28:37 +00005527 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005528 * correctable error when the MAC transitions from D0 to D3. To
5529 * prevent this we need to mask off the correctable errors on the
5530 * downstream port of the pci-e switch.
5531 */
5532 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5533 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005534 u16 devctl;
5535
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005536 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
5537 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
5538 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005539
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005540 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005541
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005542 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005543 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005544 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005545 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005546}
5547
Bruce Allan6f461f62010-04-27 03:33:04 +00005548#ifdef CONFIG_PCIEASPM
5549static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5550{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005551 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005552}
5553#else
5554static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005555{
Bruce Allane921eb12012-11-28 09:28:37 +00005556 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00005557 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005558 */
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005559 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005560
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005561 if (pdev->bus->self)
5562 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
5563 state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005564}
5565#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005566static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005567{
5568 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5569 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5570 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5571
5572 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005573}
5574
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005575#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005576static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005577{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005578 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005579}
5580
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005581static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005582{
5583 struct net_device *netdev = pci_get_drvdata(pdev);
5584 struct e1000_adapter *adapter = netdev_priv(netdev);
5585 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005586 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005587 u32 err;
5588
Bruce Allan78cd29d2011-03-24 03:09:03 +00005589 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5590 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5591 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5592 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5593 if (aspm_disable_flag)
5594 e1000e_disable_aspm(pdev, aspm_disable_flag);
5595
Auke Kokbc7f75f2007-09-17 12:30:59 -07005596 pci_set_power_state(pdev, PCI_D0);
5597 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005598 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005599
Bruce Allan4662e822008-08-26 18:37:06 -07005600 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005601 if (netif_running(netdev)) {
5602 err = e1000_request_irq(adapter);
5603 if (err)
5604 return err;
5605 }
5606
Bruce Allan2fbe4522012-04-19 03:21:47 +00005607 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00005608 e1000_resume_workarounds_pchlan(&adapter->hw);
5609
Auke Kokbc7f75f2007-09-17 12:30:59 -07005610 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005611
5612 /* report the system wakeup cause from S3/S4 */
5613 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5614 u16 phy_data;
5615
5616 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5617 if (phy_data) {
5618 e_info("PHY Wakeup cause - %s\n",
5619 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5620 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5621 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5622 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005623 phy_data & E1000_WUS_LNKC ?
5624 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005625 }
5626 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5627 } else {
5628 u32 wus = er32(WUS);
5629 if (wus) {
5630 e_info("MAC Wakeup cause - %s\n",
5631 wus & E1000_WUS_EX ? "Unicast Packet" :
5632 wus & E1000_WUS_MC ? "Multicast Packet" :
5633 wus & E1000_WUS_BC ? "Broadcast Packet" :
5634 wus & E1000_WUS_MAG ? "Magic Packet" :
5635 wus & E1000_WUS_LNKC ? "Link Status Change" :
5636 "other");
5637 }
5638 ew32(WUS, ~0);
5639 }
5640
Auke Kokbc7f75f2007-09-17 12:30:59 -07005641 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005642
Bruce Allancd791612010-05-10 14:59:51 +00005643 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005644
5645 if (netif_running(netdev))
5646 e1000e_up(adapter);
5647
5648 netif_device_attach(netdev);
5649
Bruce Allane921eb12012-11-28 09:28:37 +00005650 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005651 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005652 * under the control of the driver.
5653 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005654 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005655 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005656
5657 return 0;
5658}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005659
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005660#ifdef CONFIG_PM_SLEEP
5661static int e1000_suspend(struct device *dev)
5662{
5663 struct pci_dev *pdev = to_pci_dev(dev);
5664 int retval;
5665 bool wake;
5666
5667 retval = __e1000_shutdown(pdev, &wake, false);
5668 if (!retval)
5669 e1000_complete_shutdown(pdev, true, wake);
5670
5671 return retval;
5672}
5673
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005674static int e1000_resume(struct device *dev)
5675{
5676 struct pci_dev *pdev = to_pci_dev(dev);
5677 struct net_device *netdev = pci_get_drvdata(pdev);
5678 struct e1000_adapter *adapter = netdev_priv(netdev);
5679
5680 if (e1000e_pm_ready(adapter))
5681 adapter->idle_check = true;
5682
5683 return __e1000_resume(pdev);
5684}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005685#endif /* CONFIG_PM_SLEEP */
5686
5687#ifdef CONFIG_PM_RUNTIME
5688static int e1000_runtime_suspend(struct device *dev)
5689{
5690 struct pci_dev *pdev = to_pci_dev(dev);
5691 struct net_device *netdev = pci_get_drvdata(pdev);
5692 struct e1000_adapter *adapter = netdev_priv(netdev);
5693
5694 if (e1000e_pm_ready(adapter)) {
5695 bool wake;
5696
5697 __e1000_shutdown(pdev, &wake, true);
5698 }
5699
5700 return 0;
5701}
5702
5703static int e1000_idle(struct device *dev)
5704{
5705 struct pci_dev *pdev = to_pci_dev(dev);
5706 struct net_device *netdev = pci_get_drvdata(pdev);
5707 struct e1000_adapter *adapter = netdev_priv(netdev);
5708
5709 if (!e1000e_pm_ready(adapter))
5710 return 0;
5711
5712 if (adapter->idle_check) {
5713 adapter->idle_check = false;
5714 if (!e1000e_has_link(adapter))
5715 pm_schedule_suspend(dev, MSEC_PER_SEC);
5716 }
5717
5718 return -EBUSY;
5719}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005720
5721static int e1000_runtime_resume(struct device *dev)
5722{
5723 struct pci_dev *pdev = to_pci_dev(dev);
5724 struct net_device *netdev = pci_get_drvdata(pdev);
5725 struct e1000_adapter *adapter = netdev_priv(netdev);
5726
5727 if (!e1000e_pm_ready(adapter))
5728 return 0;
5729
5730 adapter->idle_check = !dev->power.runtime_auto;
5731 return __e1000_resume(pdev);
5732}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07005733#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005734#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005735
5736static void e1000_shutdown(struct pci_dev *pdev)
5737{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005738 bool wake = false;
5739
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005740 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005741
5742 if (system_state == SYSTEM_POWER_OFF)
5743 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005744}
5745
5746#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08005747
5748static irqreturn_t e1000_intr_msix(int irq, void *data)
5749{
5750 struct net_device *netdev = data;
5751 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08005752
5753 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00005754 int vector, msix_irq;
5755
Dongdong Deng147b2c82010-11-16 19:50:15 -08005756 vector = 0;
5757 msix_irq = adapter->msix_entries[vector].vector;
5758 disable_irq(msix_irq);
5759 e1000_intr_msix_rx(msix_irq, netdev);
5760 enable_irq(msix_irq);
5761
5762 vector++;
5763 msix_irq = adapter->msix_entries[vector].vector;
5764 disable_irq(msix_irq);
5765 e1000_intr_msix_tx(msix_irq, netdev);
5766 enable_irq(msix_irq);
5767
5768 vector++;
5769 msix_irq = adapter->msix_entries[vector].vector;
5770 disable_irq(msix_irq);
5771 e1000_msix_other(msix_irq, netdev);
5772 enable_irq(msix_irq);
5773 }
5774
5775 return IRQ_HANDLED;
5776}
5777
Bruce Allane921eb12012-11-28 09:28:37 +00005778/**
5779 * e1000_netpoll
5780 * @netdev: network interface device structure
5781 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07005782 * Polling 'interrupt' - used by things like netconsole to send skbs
5783 * without having to re-enable interrupts. It's not called while
5784 * the interrupt routine is executing.
5785 */
5786static void e1000_netpoll(struct net_device *netdev)
5787{
5788 struct e1000_adapter *adapter = netdev_priv(netdev);
5789
Dongdong Deng147b2c82010-11-16 19:50:15 -08005790 switch (adapter->int_mode) {
5791 case E1000E_INT_MODE_MSIX:
5792 e1000_intr_msix(adapter->pdev->irq, netdev);
5793 break;
5794 case E1000E_INT_MODE_MSI:
5795 disable_irq(adapter->pdev->irq);
5796 e1000_intr_msi(adapter->pdev->irq, netdev);
5797 enable_irq(adapter->pdev->irq);
5798 break;
5799 default: /* E1000E_INT_MODE_LEGACY */
5800 disable_irq(adapter->pdev->irq);
5801 e1000_intr(adapter->pdev->irq, netdev);
5802 enable_irq(adapter->pdev->irq);
5803 break;
5804 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005805}
5806#endif
5807
5808/**
5809 * e1000_io_error_detected - called when PCI error is detected
5810 * @pdev: Pointer to PCI device
5811 * @state: The current pci connection state
5812 *
5813 * This function is called after a PCI bus error affecting
5814 * this device has been detected.
5815 */
5816static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5817 pci_channel_state_t state)
5818{
5819 struct net_device *netdev = pci_get_drvdata(pdev);
5820 struct e1000_adapter *adapter = netdev_priv(netdev);
5821
5822 netif_device_detach(netdev);
5823
Mike Masonc93b5a72009-06-30 12:45:53 +00005824 if (state == pci_channel_io_perm_failure)
5825 return PCI_ERS_RESULT_DISCONNECT;
5826
Auke Kokbc7f75f2007-09-17 12:30:59 -07005827 if (netif_running(netdev))
5828 e1000e_down(adapter);
5829 pci_disable_device(pdev);
5830
5831 /* Request a slot slot reset. */
5832 return PCI_ERS_RESULT_NEED_RESET;
5833}
5834
5835/**
5836 * e1000_io_slot_reset - called after the pci bus has been reset.
5837 * @pdev: Pointer to PCI device
5838 *
5839 * Restart the card from scratch, as if from a cold-boot. Implementation
5840 * resembles the first-half of the e1000_resume routine.
5841 */
5842static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5843{
5844 struct net_device *netdev = pci_get_drvdata(pdev);
5845 struct e1000_adapter *adapter = netdev_priv(netdev);
5846 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005847 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005848 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005849 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005850
Bruce Allan78cd29d2011-03-24 03:09:03 +00005851 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5852 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00005853 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00005854 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5855 if (aspm_disable_flag)
5856 e1000e_disable_aspm(pdev, aspm_disable_flag);
5857
Bruce Allanf0f422e2008-08-04 17:21:53 -07005858 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005859 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005860 dev_err(&pdev->dev,
5861 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005862 result = PCI_ERS_RESULT_DISCONNECT;
5863 } else {
5864 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005865 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005866 pci_restore_state(pdev);
5867
5868 pci_enable_wake(pdev, PCI_D3hot, 0);
5869 pci_enable_wake(pdev, PCI_D3cold, 0);
5870
5871 e1000e_reset(adapter);
5872 ew32(WUS, ~0);
5873 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005874 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005875
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005876 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005877
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00005878 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005879}
5880
5881/**
5882 * e1000_io_resume - called when traffic can start flowing again.
5883 * @pdev: Pointer to PCI device
5884 *
5885 * This callback is called when the error recovery driver tells us that
5886 * its OK to resume normal operation. Implementation resembles the
5887 * second-half of the e1000_resume routine.
5888 */
5889static void e1000_io_resume(struct pci_dev *pdev)
5890{
5891 struct net_device *netdev = pci_get_drvdata(pdev);
5892 struct e1000_adapter *adapter = netdev_priv(netdev);
5893
Bruce Allancd791612010-05-10 14:59:51 +00005894 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895
5896 if (netif_running(netdev)) {
5897 if (e1000e_up(adapter)) {
5898 dev_err(&pdev->dev,
5899 "can't bring device back up after reset\n");
5900 return;
5901 }
5902 }
5903
5904 netif_device_attach(netdev);
5905
Bruce Allane921eb12012-11-28 09:28:37 +00005906 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07005908 * under the control of the driver.
5909 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07005910 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005911 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912
5913}
5914
5915static void e1000_print_device_info(struct e1000_adapter *adapter)
5916{
5917 struct e1000_hw *hw = &adapter->hw;
5918 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00005919 u32 ret_val;
5920 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921
5922 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00005923 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005924 /* bus width */
5925 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
5926 "Width x1"),
5927 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07005928 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005929 e_info("Intel(R) PRO/%s Network Connection\n",
5930 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00005931 ret_val = e1000_read_pba_string_generic(hw, pba_str,
5932 E1000_PBANUM_LENGTH);
5933 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00005934 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00005935 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
5936 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937}
5938
Auke Kok10aa4c02008-08-04 17:21:20 -07005939static void e1000_eeprom_checks(struct e1000_adapter *adapter)
5940{
5941 struct e1000_hw *hw = &adapter->hw;
5942 int ret_val;
5943 u16 buf = 0;
5944
5945 if (hw->mac.type != e1000_82573)
5946 return;
5947
5948 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00005949 le16_to_cpus(&buf);
5950 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07005951 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07005952 dev_warn(&adapter->pdev->dev,
5953 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07005954 }
Auke Kok10aa4c02008-08-04 17:21:20 -07005955}
5956
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005957static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00005958 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00005959{
5960 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005961 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00005962
5963 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
5964 adapter->flags |= FLAG_TSO_FORCE;
5965
5966 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00005967 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
5968 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00005969 return 0;
5970
Ben Greear01840392012-02-11 15:39:25 +00005971 if (changed & NETIF_F_RXFCS) {
5972 if (features & NETIF_F_RXFCS) {
5973 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
5974 } else {
5975 /* We need to take it back to defaults, which might mean
5976 * stripping is still disabled at the adapter level.
5977 */
5978 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
5979 adapter->flags2 |= FLAG2_CRC_STRIPPING;
5980 else
5981 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
5982 }
5983 }
5984
Bruce Allan70495a52012-01-11 01:26:50 +00005985 netdev->features = features;
5986
Bruce Allandc221292011-08-19 03:23:48 +00005987 if (netif_running(netdev))
5988 e1000e_reinit_locked(adapter);
5989 else
5990 e1000e_reset(adapter);
5991
5992 return 0;
5993}
5994
Stephen Hemminger651c2462008-11-19 21:57:48 -08005995static const struct net_device_ops e1000e_netdev_ops = {
5996 .ndo_open = e1000_open,
5997 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005998 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005999 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006000 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006001 .ndo_set_mac_address = e1000_set_mac,
6002 .ndo_change_mtu = e1000_change_mtu,
6003 .ndo_do_ioctl = e1000_ioctl,
6004 .ndo_tx_timeout = e1000_tx_timeout,
6005 .ndo_validate_addr = eth_validate_addr,
6006
Stephen Hemminger651c2462008-11-19 21:57:48 -08006007 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6008 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6009#ifdef CONFIG_NET_POLL_CONTROLLER
6010 .ndo_poll_controller = e1000_netpoll,
6011#endif
Bruce Allandc221292011-08-19 03:23:48 +00006012 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006013};
6014
Auke Kokbc7f75f2007-09-17 12:30:59 -07006015/**
6016 * e1000_probe - Device Initialization Routine
6017 * @pdev: PCI device information struct
6018 * @ent: entry in e1000_pci_tbl
6019 *
6020 * Returns 0 on success, negative on failure
6021 *
6022 * e1000_probe initializes an adapter identified by a pci_dev structure.
6023 * The OS initialization, configuring of the adapter private structure,
6024 * and a hardware reset occur.
6025 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006026static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006027{
6028 struct net_device *netdev;
6029 struct e1000_adapter *adapter;
6030 struct e1000_hw *hw;
6031 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006032 resource_size_t mmio_start, mmio_len;
6033 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006034 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006035 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006036 int i, err, pci_using_dac;
6037 u16 eeprom_data = 0;
6038 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6039
Bruce Allan78cd29d2011-03-24 03:09:03 +00006040 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6041 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006042 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006043 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6044 if (aspm_disable_flag)
6045 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006046
Bruce Allanf0f422e2008-08-04 17:21:53 -07006047 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006048 if (err)
6049 return err;
6050
6051 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006052 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006053 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006054 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006055 if (!err)
6056 pci_using_dac = 1;
6057 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006058 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006059 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006060 err = dma_set_coherent_mask(&pdev->dev,
6061 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006062 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006063 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006064 goto err_dma;
6065 }
6066 }
6067 }
6068
Arjan van de Vene8de1482008-10-22 19:55:31 -07006069 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006070 pci_select_bars(pdev, IORESOURCE_MEM),
6071 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006072 if (err)
6073 goto err_pci_reg;
6074
Xiaotian Feng68eac462009-08-14 14:35:52 +00006075 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006076 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006077
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006079 /* PCI config space info */
6080 err = pci_save_state(pdev);
6081 if (err)
6082 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006083
6084 err = -ENOMEM;
6085 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6086 if (!netdev)
6087 goto err_alloc_etherdev;
6088
Auke Kokbc7f75f2007-09-17 12:30:59 -07006089 SET_NETDEV_DEV(netdev, &pdev->dev);
6090
Tom Herbertf85e4df2010-05-05 14:03:32 +00006091 netdev->irq = pdev->irq;
6092
Auke Kokbc7f75f2007-09-17 12:30:59 -07006093 pci_set_drvdata(pdev, netdev);
6094 adapter = netdev_priv(netdev);
6095 hw = &adapter->hw;
6096 adapter->netdev = netdev;
6097 adapter->pdev = pdev;
6098 adapter->ei = ei;
6099 adapter->pba = ei->pba;
6100 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006101 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006102 adapter->hw.adapter = adapter;
6103 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006104 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006105 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006106
6107 mmio_start = pci_resource_start(pdev, 0);
6108 mmio_len = pci_resource_len(pdev, 0);
6109
6110 err = -EIO;
6111 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6112 if (!adapter->hw.hw_addr)
6113 goto err_ioremap;
6114
6115 if ((adapter->flags & FLAG_HAS_FLASH) &&
6116 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6117 flash_start = pci_resource_start(pdev, 1);
6118 flash_len = pci_resource_len(pdev, 1);
6119 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6120 if (!adapter->hw.flash_address)
6121 goto err_flashmap;
6122 }
6123
6124 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006125 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006127 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006128 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006129 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006130
6131 netdev->mem_start = mmio_start;
6132 netdev->mem_end = mmio_start + mmio_len;
6133
6134 adapter->bd_number = cards_found++;
6135
Bruce Allan4662e822008-08-26 18:37:06 -07006136 e1000e_check_options(adapter);
6137
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138 /* setup adapter struct */
6139 err = e1000_sw_init(adapter);
6140 if (err)
6141 goto err_sw_init;
6142
Auke Kokbc7f75f2007-09-17 12:30:59 -07006143 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6144 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6145 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6146
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006147 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006148 if (err)
6149 goto err_hw_init;
6150
Bruce Allan4a770352008-10-01 17:18:35 -07006151 if ((adapter->flags & FLAG_IS_ICH) &&
6152 (adapter->flags & FLAG_READ_ONLY_NVM))
6153 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6154
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155 hw->mac.ops.get_bus_info(&adapter->hw);
6156
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006157 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006158
6159 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006160 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006161 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6162 adapter->hw.phy.disable_polarity_correction = 0;
6163 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6164 }
6165
Bruce Allan470a5422012-05-26 06:08:48 +00006166 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006167 dev_info(&pdev->dev,
6168 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006169
Bruce Allandc221292011-08-19 03:23:48 +00006170 /* Set initial default active device features */
6171 netdev->features = (NETIF_F_SG |
6172 NETIF_F_HW_VLAN_RX |
6173 NETIF_F_HW_VLAN_TX |
6174 NETIF_F_TSO |
6175 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006176 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006177 NETIF_F_RXCSUM |
6178 NETIF_F_HW_CSUM);
6179
6180 /* Set user-changeable features (subset of all device features) */
6181 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006182 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006183 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006184 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006185
6186 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6187 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6188
Bruce Allandc221292011-08-19 03:23:48 +00006189 netdev->vlan_features |= (NETIF_F_SG |
6190 NETIF_F_TSO |
6191 NETIF_F_TSO6 |
6192 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006193
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006194 netdev->priv_flags |= IFF_UNICAST_FLT;
6195
Yi Zou7b872a52010-09-22 17:57:58 +00006196 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006197 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006198 netdev->vlan_features |= NETIF_F_HIGHDMA;
6199 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200
Auke Kokbc7f75f2007-09-17 12:30:59 -07006201 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6202 adapter->flags |= FLAG_MNG_PT_ENABLED;
6203
Bruce Allane921eb12012-11-28 09:28:37 +00006204 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006205 * put the device in a known good starting state
6206 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006207 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6208
Bruce Allane921eb12012-11-28 09:28:37 +00006209 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006210 * attempt. Let's give it a few tries
6211 */
6212 for (i = 0;; i++) {
6213 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6214 break;
6215 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006216 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006217 err = -EIO;
6218 goto err_eeprom;
6219 }
6220 }
6221
Auke Kok10aa4c02008-08-04 17:21:20 -07006222 e1000_eeprom_checks(adapter);
6223
Bruce Allan608f8a02010-01-13 02:04:58 +00006224 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006225 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006226 dev_err(&pdev->dev,
6227 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006228
6229 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006230
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006231 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006232 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006233 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234 err = -EIO;
6235 goto err_eeprom;
6236 }
6237
6238 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006239 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006240 adapter->watchdog_timer.data = (unsigned long) adapter;
6241
6242 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006243 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006244 adapter->phy_info_timer.data = (unsigned long) adapter;
6245
6246 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6247 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006248 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6249 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006250 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006251
Auke Kokbc7f75f2007-09-17 12:30:59 -07006252 /* Initialize link parameters. User can change them with ethtool */
6253 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006254 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006255 adapter->hw.fc.requested_mode = e1000_fc_default;
6256 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006257 adapter->hw.phy.autoneg_advertised = 0x2f;
6258
6259 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006260 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6261 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006262
Bruce Allane921eb12012-11-28 09:28:37 +00006263 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006264 * the EEPROM, enable the ACPI Magic Packet filter
6265 */
6266 if (adapter->flags & FLAG_APME_IN_WUC) {
6267 /* APME bit in EEPROM is mapped to WUC.APME */
6268 eeprom_data = er32(WUC);
6269 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006270 if ((hw->mac.type > e1000_ich10lan) &&
6271 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006272 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006273 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6274 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6275 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006276 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6277 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006278 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006279 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6280 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006281 }
6282
6283 /* fetch WoL from EEPROM */
6284 if (eeprom_data & eeprom_apme_mask)
6285 adapter->eeprom_wol |= E1000_WUFC_MAG;
6286
Bruce Allane921eb12012-11-28 09:28:37 +00006287 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006288 * where the eeprom may be wrong or the board simply won't support
6289 * wake on lan on a particular port
6290 */
6291 if (!(adapter->flags & FLAG_HAS_WOL))
6292 adapter->eeprom_wol = 0;
6293
6294 /* initialize the wol settings based on the eeprom settings */
6295 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006296 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006297
Bruce Allan84527592008-11-21 17:00:22 -08006298 /* save off EEPROM version number */
6299 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6300
Auke Kokbc7f75f2007-09-17 12:30:59 -07006301 /* reset the hardware with the new settings */
6302 e1000e_reset(adapter);
6303
Bruce Allane921eb12012-11-28 09:28:37 +00006304 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006305 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006306 * under the control of the driver.
6307 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006308 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006309 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006310
Bruce Allanf2315bf2011-12-16 00:46:59 +00006311 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006312 err = register_netdev(netdev);
6313 if (err)
6314 goto err_register;
6315
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006316 /* carrier off reporting is important to ethtool even BEFORE open */
6317 netif_carrier_off(netdev);
6318
Auke Kokbc7f75f2007-09-17 12:30:59 -07006319 e1000_print_device_info(adapter);
6320
Alan Sternf3ec4f82010-06-08 15:23:51 -04006321 if (pci_dev_run_wake(pdev))
6322 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006323
Auke Kokbc7f75f2007-09-17 12:30:59 -07006324 return 0;
6325
6326err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006327 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006328 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006329err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006330 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006331 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006332err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006333 kfree(adapter->tx_ring);
6334 kfree(adapter->rx_ring);
6335err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006336 if (adapter->hw.flash_address)
6337 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006338 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006339err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006340 iounmap(adapter->hw.hw_addr);
6341err_ioremap:
6342 free_netdev(netdev);
6343err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006344 pci_release_selected_regions(pdev,
6345 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006346err_pci_reg:
6347err_dma:
6348 pci_disable_device(pdev);
6349 return err;
6350}
6351
6352/**
6353 * e1000_remove - Device Removal Routine
6354 * @pdev: PCI device information struct
6355 *
6356 * e1000_remove is called by the PCI subsystem to alert the driver
6357 * that it should release a PCI device. The could be caused by a
6358 * Hot-Plug event, or because the driver is going to be removed from
6359 * memory.
6360 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006361static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006362{
6363 struct net_device *netdev = pci_get_drvdata(pdev);
6364 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006365 bool down = test_bit(__E1000_DOWN, &adapter->state);
6366
Bruce Allane921eb12012-11-28 09:28:37 +00006367 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006368 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006369 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006370 if (!down)
6371 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372 del_timer_sync(&adapter->watchdog_timer);
6373 del_timer_sync(&adapter->phy_info_timer);
6374
Bruce Allan41cec6f2009-11-20 23:28:56 +00006375 cancel_work_sync(&adapter->reset_task);
6376 cancel_work_sync(&adapter->watchdog_task);
6377 cancel_work_sync(&adapter->downshift_task);
6378 cancel_work_sync(&adapter->update_phy_task);
6379 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006380
Bruce Allan17f208d2009-12-01 15:47:22 +00006381 if (!(netdev->flags & IFF_UP))
6382 e1000_power_down_phy(adapter);
6383
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006384 /* Don't lie to e1000_close() down the road. */
6385 if (!down)
6386 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006387 unregister_netdev(netdev);
6388
Alan Sternf3ec4f82010-06-08 15:23:51 -04006389 if (pci_dev_run_wake(pdev))
6390 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006391
Bruce Allane921eb12012-11-28 09:28:37 +00006392 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006393 * would have already happened in close and is redundant.
6394 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006395 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006396
Bruce Allan4662e822008-08-26 18:37:06 -07006397 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006398 kfree(adapter->tx_ring);
6399 kfree(adapter->rx_ring);
6400
6401 iounmap(adapter->hw.hw_addr);
6402 if (adapter->hw.flash_address)
6403 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006404 pci_release_selected_regions(pdev,
6405 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006406
6407 free_netdev(netdev);
6408
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006409 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006410 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006411
Auke Kokbc7f75f2007-09-17 12:30:59 -07006412 pci_disable_device(pdev);
6413}
6414
6415/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006416static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006417 .error_detected = e1000_io_error_detected,
6418 .slot_reset = e1000_io_slot_reset,
6419 .resume = e1000_io_resume,
6420};
6421
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006422static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006423 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6424 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6425 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6426 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6427 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6428 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006429 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6430 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6431 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006432
Auke Kokbc7f75f2007-09-17 12:30:59 -07006433 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6434 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6435 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6436 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006437
Auke Kokbc7f75f2007-09-17 12:30:59 -07006438 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6439 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6440 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006441
Bruce Allan4662e822008-08-26 18:37:06 -07006442 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006443 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006444 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006445
Auke Kokbc7f75f2007-09-17 12:30:59 -07006446 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6447 board_80003es2lan },
6448 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6449 board_80003es2lan },
6450 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6451 board_80003es2lan },
6452 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6453 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006454
Auke Kokbc7f75f2007-09-17 12:30:59 -07006455 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6456 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6457 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6458 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6459 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6460 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6461 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006462 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006463
Auke Kokbc7f75f2007-09-17 12:30:59 -07006464 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6465 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6466 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6467 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6468 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006469 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006470 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6471 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6472 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6473
6474 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6475 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6476 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006477
Bruce Allanf4187b52008-08-26 18:36:50 -07006478 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6479 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006480 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006481
Bruce Allana4f58f52009-06-02 11:29:18 +00006482 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6483 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6484 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6485 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6486
Bruce Alland3738bb2010-06-16 13:27:28 +00006487 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6488 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6489
Bruce Allan2fbe4522012-04-19 03:21:47 +00006490 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6491 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006492 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6493 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006494
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006495 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006496};
6497MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6498
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006499#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006500static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006501 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6502 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6503 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006504};
David S. Millere50208a2010-03-16 23:36:24 -07006505#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006506
Auke Kokbc7f75f2007-09-17 12:30:59 -07006507/* PCI Device API Driver */
6508static struct pci_driver e1000_driver = {
6509 .name = e1000e_driver_name,
6510 .id_table = e1000_pci_tbl,
6511 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006512 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006513#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006514 .driver = {
6515 .pm = &e1000_pm_ops,
6516 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006517#endif
6518 .shutdown = e1000_shutdown,
6519 .err_handler = &e1000_err_handler
6520};
6521
6522/**
6523 * e1000_init_module - Driver Registration Routine
6524 *
6525 * e1000_init_module is the first routine called when the driver is
6526 * loaded. All it does is register with the PCI subsystem.
6527 **/
6528static int __init e1000_init_module(void)
6529{
6530 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006531 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6532 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006533 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006535
Auke Kokbc7f75f2007-09-17 12:30:59 -07006536 return ret;
6537}
6538module_init(e1000_init_module);
6539
6540/**
6541 * e1000_exit_module - Driver Exit Cleanup Routine
6542 *
6543 * e1000_exit_module is called just before the driver is removed
6544 * from memory.
6545 **/
6546static void __exit e1000_exit_module(void)
6547{
6548 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006549}
6550module_exit(e1000_exit_module);
6551
6552
6553MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6554MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6555MODULE_LICENSE("GPL");
6556MODULE_VERSION(DRV_VERSION);
6557
Bruce Allan06c24b92012-02-23 03:13:13 +00006558/* netdev.c */