blob: 5129c4cd14bc600512cc23213410b272f331da1f [file] [log] [blame]
David Ertmane78b80b2014-02-04 01:56:06 +00001/* Intel PRO/1000 Linux driver
2 * Copyright(c) 1999 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * Linux NICS <linux.nics@intel.com>
18 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
20 */
Auke Kokbc7f75f2007-09-17 12:30:59 -070021
Bruce Allan8544b9f2010-03-24 12:55:30 +000022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Auke Kokbc7f75f2007-09-17 12:30:59 -070024#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/vmalloc.h>
29#include <linux/pagemap.h>
30#include <linux/delay.h>
31#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#include <linux/tcp.h>
34#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <net/checksum.h>
37#include <net/ip6_checksum.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070038#include <linux/ethtool.h>
39#include <linux/if_vlan.h>
40#include <linux/cpu.h>
41#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020042#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000043#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000044#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040045#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070046
47#include "e1000.h"
48
Bruce Allanb3ccf262011-05-19 01:53:41 +000049#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000050
Bruce Allan8defe712013-03-06 09:03:13 +000051#define DRV_VERSION "2.3.2" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070052char e1000e_driver_name[] = "e1000e";
53const char e1000e_driver_version[] = DRV_VERSION;
54
stephen hemmingerb3f4d592012-03-13 06:04:20 +000055#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
56static int debug = -1;
57module_param(debug, int, 0);
58MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
59
Auke Kokbc7f75f2007-09-17 12:30:59 -070060static const struct e1000_info *e1000_info_tbl[] = {
61 [board_82571] = &e1000_82571_info,
62 [board_82572] = &e1000_82572_info,
63 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070064 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000065 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 [board_80003es2lan] = &e1000_es2_info,
67 [board_ich8lan] = &e1000_ich8_info,
68 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070069 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000070 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000071 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000072 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070073};
74
Taku Izumi84f4ee92010-04-27 14:39:08 +000075struct e1000_reg_info {
76 u32 ofs;
77 char *name;
78};
79
Taku Izumi84f4ee92010-04-27 14:39:08 +000080static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000081 /* General Registers */
82 {E1000_CTRL, "CTRL"},
83 {E1000_STATUS, "STATUS"},
84 {E1000_CTRL_EXT, "CTRL_EXT"},
85
86 /* Interrupt Registers */
87 {E1000_ICR, "ICR"},
88
Bruce Allanaf667a22010-12-31 06:10:01 +000089 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000090 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000091 {E1000_RDLEN(0), "RDLEN"},
92 {E1000_RDH(0), "RDH"},
93 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000094 {E1000_RDTR, "RDTR"},
95 {E1000_RXDCTL(0), "RXDCTL"},
96 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +000097 {E1000_RDBAL(0), "RDBAL"},
98 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000099 {E1000_RDFH, "RDFH"},
100 {E1000_RDFT, "RDFT"},
101 {E1000_RDFHS, "RDFHS"},
102 {E1000_RDFTS, "RDFTS"},
103 {E1000_RDFPC, "RDFPC"},
104
Bruce Allanaf667a22010-12-31 06:10:01 +0000105 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000106 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000107 {E1000_TDBAL(0), "TDBAL"},
108 {E1000_TDBAH(0), "TDBAH"},
109 {E1000_TDLEN(0), "TDLEN"},
110 {E1000_TDH(0), "TDH"},
111 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000112 {E1000_TIDV, "TIDV"},
113 {E1000_TXDCTL(0), "TXDCTL"},
114 {E1000_TADV, "TADV"},
115 {E1000_TARC(0), "TARC"},
116 {E1000_TDFH, "TDFH"},
117 {E1000_TDFT, "TDFT"},
118 {E1000_TDFHS, "TDFHS"},
119 {E1000_TDFTS, "TDFTS"},
120 {E1000_TDFPC, "TDFPC"},
121
122 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000123 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000124};
125
Bruce Allane921eb12012-11-28 09:28:37 +0000126/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000127 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000128 * @hw: pointer to the HW structure
129 * @reginfo: pointer to the register info table
130 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000131static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
132{
133 int n = 0;
134 char rname[16];
135 u32 regs[8];
136
137 switch (reginfo->ofs) {
138 case E1000_RXDCTL(0):
139 for (n = 0; n < 2; n++)
140 regs[n] = __er32(hw, E1000_RXDCTL(n));
141 break;
142 case E1000_TXDCTL(0):
143 for (n = 0; n < 2; n++)
144 regs[n] = __er32(hw, E1000_TXDCTL(n));
145 break;
146 case E1000_TARC(0):
147 for (n = 0; n < 2; n++)
148 regs[n] = __er32(hw, E1000_TARC(n));
149 break;
150 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000151 pr_info("%-15s %08x\n",
152 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000153 return;
154 }
155
156 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000157 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000158}
159
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000160static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
161 struct e1000_buffer *bi)
162{
163 int i;
164 struct e1000_ps_page *ps_page;
165
166 for (i = 0; i < adapter->rx_ps_pages; i++) {
167 ps_page = &bi->ps_pages[i];
168
169 if (ps_page->page) {
170 pr_info("packet dump for ps_page %d:\n", i);
171 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
172 16, 1, page_address(ps_page->page),
173 PAGE_SIZE, true);
174 }
175 }
176}
177
Bruce Allane921eb12012-11-28 09:28:37 +0000178/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000179 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000180 * @adapter: board private structure
181 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000182static void e1000e_dump(struct e1000_adapter *adapter)
183{
184 struct net_device *netdev = adapter->netdev;
185 struct e1000_hw *hw = &adapter->hw;
186 struct e1000_reg_info *reginfo;
187 struct e1000_ring *tx_ring = adapter->tx_ring;
188 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000189 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000190 __le64 a;
191 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000192 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000193 struct e1000_buffer *buffer_info;
194 struct e1000_ring *rx_ring = adapter->rx_ring;
195 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000196 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000197 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000198 __le64 a;
199 __le64 b;
200 __le64 c;
201 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000202 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000203 u32 staterr;
204 int i = 0;
205
206 if (!netif_msg_hw(adapter))
207 return;
208
209 /* Print netdevice Info */
210 if (netdev) {
211 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000212 pr_info("Device Name state trans_start last_rx\n");
Bruce Allane5fe2542013-02-20 04:06:27 +0000213 pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
214 netdev->state, netdev->trans_start, netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000215 }
216
217 /* Print Registers */
218 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000219 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000220 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
221 reginfo->name; reginfo++) {
222 e1000_regdump(hw, reginfo);
223 }
224
Bruce Allanaf667a22010-12-31 06:10:01 +0000225 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000227 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000228
Bruce Allanaf667a22010-12-31 06:10:01 +0000229 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000230 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000232 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
233 0, tx_ring->next_to_use, tx_ring->next_to_clean,
234 (unsigned long long)buffer_info->dma,
235 buffer_info->length,
236 buffer_info->next_to_watch,
237 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238
Bruce Allanaf667a22010-12-31 06:10:01 +0000239 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240 if (!netif_msg_tx_done(adapter))
241 goto rx_ring_summary;
242
Bruce Allanaf667a22010-12-31 06:10:01 +0000243 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244
245 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
246 *
247 * Legacy Transmit Descriptor
248 * +--------------------------------------------------------------+
249 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
250 * +--------------------------------------------------------------+
251 * 8 | Special | CSS | Status | CMD | CSO | Length |
252 * +--------------------------------------------------------------+
253 * 63 48 47 36 35 32 31 24 23 16 15 0
254 *
255 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
256 * 63 48 47 40 39 32 31 16 15 8 7 0
257 * +----------------------------------------------------------------+
258 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
259 * +----------------------------------------------------------------+
260 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
261 * +----------------------------------------------------------------+
262 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
263 *
264 * Extended Data Descriptor (DTYP=0x1)
265 * +----------------------------------------------------------------+
266 * 0 | Buffer Address [63:0] |
267 * +----------------------------------------------------------------+
268 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
269 * +----------------------------------------------------------------+
270 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
271 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000272 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
273 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
274 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 +0000275 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000276 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 tx_desc = E1000_TX_DESC(*tx_ring, i);
278 buffer_info = &tx_ring->buffer_info[i];
279 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000280 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000281 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000282 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000283 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000284 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000285 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000286 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000287 next_desc = "";
288 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
289 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
290 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
291 i,
292 (unsigned long long)le64_to_cpu(u0->a),
293 (unsigned long long)le64_to_cpu(u0->b),
294 (unsigned long long)buffer_info->dma,
295 buffer_info->length, buffer_info->next_to_watch,
296 (unsigned long long)buffer_info->time_stamp,
297 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000298
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000299 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000300 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000301 16, 1, buffer_info->skb->data,
302 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000303 }
304
Bruce Allanaf667a22010-12-31 06:10:01 +0000305 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000307 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000308 pr_info("Queue [NTU] [NTC]\n");
309 pr_info(" %5d %5X %5X\n",
310 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311
Bruce Allanaf667a22010-12-31 06:10:01 +0000312 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000314 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315
Bruce Allanaf667a22010-12-31 06:10:01 +0000316 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000317 switch (adapter->rx_ps_pages) {
318 case 1:
319 case 2:
320 case 3:
321 /* [Extended] Packet Split Receive Descriptor Format
322 *
323 * +-----------------------------------------------------+
324 * 0 | Buffer Address 0 [63:0] |
325 * +-----------------------------------------------------+
326 * 8 | Buffer Address 1 [63:0] |
327 * +-----------------------------------------------------+
328 * 16 | Buffer Address 2 [63:0] |
329 * +-----------------------------------------------------+
330 * 24 | Buffer Address 3 [63:0] |
331 * +-----------------------------------------------------+
332 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000333 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 +0000334 /* [Extended] Receive Descriptor (Write-Back) Format
335 *
336 * 63 48 47 32 31 13 12 8 7 4 3 0
337 * +------------------------------------------------------+
338 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
339 * | Checksum | Ident | | Queue | | Type |
340 * +------------------------------------------------------+
341 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
342 * +------------------------------------------------------+
343 * 63 48 47 32 31 20 19 0
344 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000345 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 +0000346 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000347 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000348 buffer_info = &rx_ring->buffer_info[i];
349 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
350 u1 = (struct my_u1 *)rx_desc_ps;
351 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000352 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000353
354 if (i == rx_ring->next_to_use)
355 next_desc = " NTU";
356 else if (i == rx_ring->next_to_clean)
357 next_desc = " NTC";
358 else
359 next_desc = "";
360
Taku Izumi84f4ee92010-04-27 14:39:08 +0000361 if (staterr & E1000_RXD_STAT_DD) {
362 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000363 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
364 "RWB", i,
365 (unsigned long long)le64_to_cpu(u1->a),
366 (unsigned long long)le64_to_cpu(u1->b),
367 (unsigned long long)le64_to_cpu(u1->c),
368 (unsigned long long)le64_to_cpu(u1->d),
369 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000370 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000371 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
372 "R ", i,
373 (unsigned long long)le64_to_cpu(u1->a),
374 (unsigned long long)le64_to_cpu(u1->b),
375 (unsigned long long)le64_to_cpu(u1->c),
376 (unsigned long long)le64_to_cpu(u1->d),
377 (unsigned long long)buffer_info->dma,
378 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000379
380 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000381 e1000e_dump_ps_pages(adapter,
382 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000383 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000384 }
385 break;
386 default:
387 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000388 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000389 *
Bruce Allan5f450212011-07-22 06:21:46 +0000390 * +-----------------------------------------------------+
391 * 0 | Buffer Address [63:0] |
392 * +-----------------------------------------------------+
393 * 8 | Reserved |
394 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000395 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000396 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 +0000397 /* Extended Receive Descriptor (Write-Back) Format
398 *
399 * 63 48 47 32 31 24 23 4 3 0
400 * +------------------------------------------------------+
401 * | RSS Hash | | | |
402 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
403 * | Packet | IP | | | Type |
404 * | Checksum | Ident | | | |
405 * +------------------------------------------------------+
406 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
407 * +------------------------------------------------------+
408 * 63 48 47 32 31 20 19 0
409 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000410 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 +0000411
412 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000413 const char *next_desc;
414
Taku Izumi84f4ee92010-04-27 14:39:08 +0000415 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000416 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
417 u1 = (struct my_u1 *)rx_desc;
418 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000419
420 if (i == rx_ring->next_to_use)
421 next_desc = " NTU";
422 else if (i == rx_ring->next_to_clean)
423 next_desc = " NTC";
424 else
425 next_desc = "";
426
Bruce Allan5f450212011-07-22 06:21:46 +0000427 if (staterr & E1000_RXD_STAT_DD) {
428 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000429 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
430 "RWB", i,
431 (unsigned long long)le64_to_cpu(u1->a),
432 (unsigned long long)le64_to_cpu(u1->b),
433 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000434 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000435 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
436 "R ", i,
437 (unsigned long long)le64_to_cpu(u1->a),
438 (unsigned long long)le64_to_cpu(u1->b),
439 (unsigned long long)buffer_info->dma,
440 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000441
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000442 if (netif_msg_pktdata(adapter) &&
443 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000444 print_hex_dump(KERN_INFO, "",
445 DUMP_PREFIX_ADDRESS, 16,
446 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000447 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000448 adapter->rx_buffer_len,
449 true);
450 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000451 }
452 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000453}
454
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455/**
456 * e1000_desc_unused - calculate if we have unused descriptors
457 **/
458static int e1000_desc_unused(struct e1000_ring *ring)
459{
460 if (ring->next_to_clean > ring->next_to_use)
461 return ring->next_to_clean - ring->next_to_use - 1;
462
463 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
464}
465
466/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000467 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
468 * @adapter: board private structure
469 * @hwtstamps: time stamp structure to update
470 * @systim: unsigned 64bit system time value.
471 *
472 * Convert the system time value stored in the RX/TXSTMP registers into a
473 * hwtstamp which can be used by the upper level time stamping functions.
474 *
475 * The 'systim_lock' spinlock is used to protect the consistency of the
476 * system time value. This is needed because reading the 64 bit time
477 * value involves reading two 32 bit registers. The first read latches the
478 * value.
479 **/
480static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
481 struct skb_shared_hwtstamps *hwtstamps,
482 u64 systim)
483{
484 u64 ns;
485 unsigned long flags;
486
487 spin_lock_irqsave(&adapter->systim_lock, flags);
488 ns = timecounter_cyc2time(&adapter->tc, systim);
489 spin_unlock_irqrestore(&adapter->systim_lock, flags);
490
491 memset(hwtstamps, 0, sizeof(*hwtstamps));
492 hwtstamps->hwtstamp = ns_to_ktime(ns);
493}
494
495/**
496 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
497 * @adapter: board private structure
498 * @status: descriptor extended error and status field
499 * @skb: particular skb to include time stamp
500 *
501 * If the time stamp is valid, convert it into the timecounter ns value
502 * and store that result into the shhwtstamps structure which is passed
503 * up the network stack.
504 **/
505static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
506 struct sk_buff *skb)
507{
508 struct e1000_hw *hw = &adapter->hw;
509 u64 rxstmp;
510
511 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
512 !(status & E1000_RXDEXT_STATERR_TST) ||
513 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
514 return;
515
516 /* The Rx time stamp registers contain the time stamp. No other
517 * received packet will be time stamped until the Rx time stamp
518 * registers are read. Because only one packet can be time stamped
519 * at a time, the register values must belong to this packet and
520 * therefore none of the other additional attributes need to be
521 * compared.
522 */
523 rxstmp = (u64)er32(RXSTMPL);
524 rxstmp |= (u64)er32(RXSTMPH) << 32;
525 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
526
527 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
528}
529
530/**
Bruce Allanad680762008-03-28 09:15:03 -0700531 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000533 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
535 * @skb: pointer to sk_buff to be indicated to stack
536 **/
537static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000538 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000539 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000541 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000542
543 e1000e_rx_hwtstamp(adapter, staterr, skb);
544
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545 skb->protocol = eth_type_trans(skb, netdev);
546
Bruce Allanb67e1912012-12-27 08:32:33 +0000547 if (staterr & E1000_RXD_STAT_VP)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000548 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000549
550 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700551}
552
553/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000554 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000555 * @adapter: board private structure
556 * @status_err: receive descriptor status and error fields
557 * @csum: receive descriptor csum field
558 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 **/
560static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000561 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562{
563 u16 status = (u16)status_err;
564 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700565
566 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700567
Bruce Allanafd12932012-01-05 00:34:05 +0000568 /* Rx checksum disabled */
569 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
570 return;
571
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572 /* Ignore Checksum bit is set */
573 if (status & E1000_RXD_STAT_IXSM)
574 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000575
Bruce Allan2e1706f2012-06-30 20:02:42 +0000576 /* TCP/UDP checksum error bit or IP checksum error bit is set */
577 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 /* let the stack verify checksum errors */
579 adapter->hw_csum_err++;
580 return;
581 }
582
583 /* TCP/UDP Checksum has not been calculated */
584 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
585 return;
586
587 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000588 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700589 adapter->hw_csum_good++;
590}
591
Bruce Allan55aa6982011-12-16 00:45:45 +0000592static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700593{
Bruce Allan55aa6982011-12-16 00:45:45 +0000594 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700595 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000596 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700597
Bruce Allanbdc125f2012-03-20 03:47:52 +0000598 writel(i, rx_ring->tail);
599
600 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700601 u32 rctl = er32(RCTL);
602 ew32(RCTL, rctl & ~E1000_RCTL_EN);
603 e_err("ME firmware caused invalid RDT - resetting\n");
604 schedule_work(&adapter->reset_task);
605 }
606}
607
Bruce Allan55aa6982011-12-16 00:45:45 +0000608static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700609{
Bruce Allan55aa6982011-12-16 00:45:45 +0000610 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700611 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000612 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700613
Bruce Allanbdc125f2012-03-20 03:47:52 +0000614 writel(i, tx_ring->tail);
615
616 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700617 u32 tctl = er32(TCTL);
618 ew32(TCTL, tctl & ~E1000_TCTL_EN);
619 e_err("ME firmware caused invalid TDT - resetting\n");
620 schedule_work(&adapter->reset_task);
621 }
622}
623
624/**
Bruce Allan5f450212011-07-22 06:21:46 +0000625 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000626 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000628static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000629 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630{
Bruce Allan55aa6982011-12-16 00:45:45 +0000631 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700632 struct net_device *netdev = adapter->netdev;
633 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000634 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 struct e1000_buffer *buffer_info;
636 struct sk_buff *skb;
637 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000638 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639
640 i = rx_ring->next_to_use;
641 buffer_info = &rx_ring->buffer_info[i];
642
643 while (cleaned_count--) {
644 skb = buffer_info->skb;
645 if (skb) {
646 skb_trim(skb, 0);
647 goto map_skb;
648 }
649
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000650 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 if (!skb) {
652 /* Better luck next round */
653 adapter->alloc_rx_buff_failed++;
654 break;
655 }
656
Auke Kokbc7f75f2007-09-17 12:30:59 -0700657 buffer_info->skb = skb;
658map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000659 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000661 DMA_FROM_DEVICE);
662 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000663 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700664 adapter->rx_dma_failed++;
665 break;
666 }
667
Bruce Allan5f450212011-07-22 06:21:46 +0000668 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
669 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670
Tom Herbert50849d72010-05-05 14:02:49 +0000671 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000672 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000673 * know there are new descriptors to fetch. (Only
674 * applicable for weak-ordered memory model archs,
675 * such as IA-64).
676 */
677 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700678 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000679 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700680 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000681 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000682 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683 i++;
684 if (i == rx_ring->count)
685 i = 0;
686 buffer_info = &rx_ring->buffer_info[i];
687 }
688
Tom Herbert50849d72010-05-05 14:02:49 +0000689 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700690}
691
692/**
693 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000694 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700695 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000696static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000697 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698{
Bruce Allan55aa6982011-12-16 00:45:45 +0000699 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700700 struct net_device *netdev = adapter->netdev;
701 struct pci_dev *pdev = adapter->pdev;
702 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703 struct e1000_buffer *buffer_info;
704 struct e1000_ps_page *ps_page;
705 struct sk_buff *skb;
706 unsigned int i, j;
707
708 i = rx_ring->next_to_use;
709 buffer_info = &rx_ring->buffer_info[i];
710
711 while (cleaned_count--) {
712 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
713
714 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700715 ps_page = &buffer_info->ps_pages[j];
716 if (j >= adapter->rx_ps_pages) {
717 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000718 rx_desc->read.buffer_addr[j + 1] =
719 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700720 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700721 }
Auke Kok47f44e42007-10-25 13:57:44 -0700722 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000723 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700724 if (!ps_page->page) {
725 adapter->alloc_rx_buff_failed++;
726 goto no_buffers;
727 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000728 ps_page->dma = dma_map_page(&pdev->dev,
729 ps_page->page,
730 0, PAGE_SIZE,
731 DMA_FROM_DEVICE);
732 if (dma_mapping_error(&pdev->dev,
733 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700734 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000735 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700736 adapter->rx_dma_failed++;
737 goto no_buffers;
738 }
739 }
Bruce Allane921eb12012-11-28 09:28:37 +0000740 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700741 * didn't change because each write-back
742 * erases this info.
743 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000744 rx_desc->read.buffer_addr[j + 1] =
745 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700746 }
747
Bruce Allane5fe2542013-02-20 04:06:27 +0000748 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000749 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700750
751 if (!skb) {
752 adapter->alloc_rx_buff_failed++;
753 break;
754 }
755
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000757 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000759 DMA_FROM_DEVICE);
760 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000761 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 adapter->rx_dma_failed++;
763 /* cleanup skb */
764 dev_kfree_skb_any(skb);
765 buffer_info->skb = NULL;
766 break;
767 }
768
769 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
770
Tom Herbert50849d72010-05-05 14:02:49 +0000771 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000772 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000773 * know there are new descriptors to fetch. (Only
774 * applicable for weak-ordered memory model archs,
775 * such as IA-64).
776 */
777 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700778 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000779 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700780 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000781 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000782 }
783
Auke Kokbc7f75f2007-09-17 12:30:59 -0700784 i++;
785 if (i == rx_ring->count)
786 i = 0;
787 buffer_info = &rx_ring->buffer_info[i];
788 }
789
790no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000791 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792}
793
794/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700795 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000796 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700797 * @cleaned_count: number of buffers to allocate this pass
798 **/
799
Bruce Allan55aa6982011-12-16 00:45:45 +0000800static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000801 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700802{
Bruce Allan55aa6982011-12-16 00:45:45 +0000803 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700804 struct net_device *netdev = adapter->netdev;
805 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000806 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700807 struct e1000_buffer *buffer_info;
808 struct sk_buff *skb;
809 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000810 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700811
812 i = rx_ring->next_to_use;
813 buffer_info = &rx_ring->buffer_info[i];
814
815 while (cleaned_count--) {
816 skb = buffer_info->skb;
817 if (skb) {
818 skb_trim(skb, 0);
819 goto check_page;
820 }
821
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000822 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700823 if (unlikely(!skb)) {
824 /* Better luck next round */
825 adapter->alloc_rx_buff_failed++;
826 break;
827 }
828
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700829 buffer_info->skb = skb;
830check_page:
831 /* allocate a new page if necessary */
832 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000833 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700834 if (unlikely(!buffer_info->page)) {
835 adapter->alloc_rx_buff_failed++;
836 break;
837 }
838 }
839
Christoph Paasch37287fae2013-03-20 08:59:46 +0000840 if (!buffer_info->dma) {
Nick Nunley0be3f552010-04-27 13:09:05 +0000841 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000842 buffer_info->page, 0,
843 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000844 DMA_FROM_DEVICE);
Christoph Paasch37287fae2013-03-20 08:59:46 +0000845 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
846 adapter->alloc_rx_buff_failed++;
847 break;
848 }
849 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700850
Bruce Allan5f450212011-07-22 06:21:46 +0000851 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
852 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700853
854 if (unlikely(++i == rx_ring->count))
855 i = 0;
856 buffer_info = &rx_ring->buffer_info[i];
857 }
858
859 if (likely(rx_ring->next_to_use != i)) {
860 rx_ring->next_to_use = i;
861 if (unlikely(i-- == 0))
862 i = (rx_ring->count - 1);
863
864 /* Force memory writes to complete before letting h/w
865 * know there are new descriptors to fetch. (Only
866 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000867 * such as IA-64).
868 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700869 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700870 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000871 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700872 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000873 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700874 }
875}
876
Bruce Allan70495a52012-01-11 01:26:50 +0000877static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
878 struct sk_buff *skb)
879{
880 if (netdev->features & NETIF_F_RXHASH)
881 skb->rxhash = le32_to_cpu(rss);
882}
883
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700884/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000885 * e1000_clean_rx_irq - Send received data up the network stack
886 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 *
888 * the return value indicates whether actual cleaning was done, there
889 * is no guarantee that everything was cleaned
890 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000891static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
892 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700893{
Bruce Allan55aa6982011-12-16 00:45:45 +0000894 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895 struct net_device *netdev = adapter->netdev;
896 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000897 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000898 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000900 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 unsigned int i;
902 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000903 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700904 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
905
906 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000907 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
908 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909 buffer_info = &rx_ring->buffer_info[i];
910
Bruce Allan5f450212011-07-22 06:21:46 +0000911 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913
914 if (*work_done >= work_to_do)
915 break;
916 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000917 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919 skb = buffer_info->skb;
920 buffer_info->skb = NULL;
921
922 prefetch(skb->data - NET_IP_ALIGN);
923
924 i++;
925 if (i == rx_ring->count)
926 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000927 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928 prefetch(next_rxd);
929
930 next_buffer = &rx_ring->buffer_info[i];
931
Rusty Russell3db1cd52011-12-19 13:56:45 +0000932 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 cleaned_count++;
Bruce Allane5fe2542013-02-20 04:06:27 +0000934 dma_unmap_single(&pdev->dev, buffer_info->dma,
935 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 buffer_info->dma = 0;
937
Bruce Allan5f450212011-07-22 06:21:46 +0000938 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939
Bruce Allane921eb12012-11-28 09:28:37 +0000940 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000941 * packet, if that's the case we need to toss it. In fact, we
942 * need to toss every packet with the EOP bit clear and the
943 * next frame that _does_ have the EOP bit set, as it is by
944 * definition only a frame fragment
945 */
Bruce Allan5f450212011-07-22 06:21:46 +0000946 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000947 adapter->flags2 |= FLAG2_IS_DISCARDING;
948
949 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000951 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 /* recycle */
953 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000954 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000955 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700956 goto next_desc;
957 }
958
Ben Greearcf955e62012-02-11 15:39:51 +0000959 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
960 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 /* recycle */
962 buffer_info->skb = skb;
963 goto next_desc;
964 }
965
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000966 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000967 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
968 /* If configured to store CRC, don't subtract FCS,
969 * but keep the FCS bytes out of the total_rx_bytes
970 * counter
971 */
972 if (netdev->features & NETIF_F_RXFCS)
973 total_rx_bytes -= 4;
974 else
975 length -= 4;
976 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000977
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978 total_rx_bytes += length;
979 total_rx_packets++;
980
Bruce Allane921eb12012-11-28 09:28:37 +0000981 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700983 * of reassembly being done in the stack
984 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700985 if (length < copybreak) {
986 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000987 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700989 skb_copy_to_linear_data_offset(new_skb,
990 -NET_IP_ALIGN,
991 (skb->data -
992 NET_IP_ALIGN),
993 (length +
994 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700995 /* save the skb in buffer_info as good */
996 buffer_info->skb = skb;
997 skb = new_skb;
998 }
999 /* else just continue with the old one */
1000 }
1001 /* end copybreak code */
1002 skb_put(skb, length);
1003
1004 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001005 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006
Bruce Allan70495a52012-01-11 01:26:50 +00001007 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1008
Bruce Allan5f450212011-07-22 06:21:46 +00001009 e1000_receive_skb(adapter, netdev, skb, staterr,
1010 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011
1012next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001013 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014
1015 /* return some buffers to hardware, one at a time is too slow */
1016 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001017 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001018 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 cleaned_count = 0;
1020 }
1021
1022 /* use prefetched values */
1023 rx_desc = next_rxd;
1024 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001025
1026 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 }
1028 rx_ring->next_to_clean = i;
1029
1030 cleaned_count = e1000_desc_unused(rx_ring);
1031 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001032 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033
Auke Kokbc7f75f2007-09-17 12:30:59 -07001034 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001035 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036 return cleaned;
1037}
1038
Bruce Allan55aa6982011-12-16 00:45:45 +00001039static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1040 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041{
Bruce Allan55aa6982011-12-16 00:45:45 +00001042 struct e1000_adapter *adapter = tx_ring->adapter;
1043
Alexander Duyck03b13202009-12-02 16:45:31 +00001044 if (buffer_info->dma) {
1045 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001046 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1047 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001048 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001049 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1050 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001051 buffer_info->dma = 0;
1052 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053 if (buffer_info->skb) {
1054 dev_kfree_skb_any(buffer_info->skb);
1055 buffer_info->skb = NULL;
1056 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001057 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058}
1059
Bruce Allan41cec6f2009-11-20 23:28:56 +00001060static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001062 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001063 struct e1000_adapter,
1064 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001065 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066 struct e1000_ring *tx_ring = adapter->tx_ring;
1067 unsigned int i = tx_ring->next_to_clean;
1068 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1069 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001070 struct e1000_hw *hw = &adapter->hw;
1071 u16 phy_status, phy_1000t_status, phy_ext_status;
1072 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001074 if (test_bit(__E1000_DOWN, &adapter->state))
1075 return;
1076
Bruce Allane5fe2542013-02-20 04:06:27 +00001077 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001078 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001079 * flush pending descriptor writebacks to memory
1080 */
1081 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1082 /* execute the writes immediately */
1083 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001084 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001085 * the write is successful
1086 */
1087 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1088 /* execute the writes immediately */
1089 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001090 adapter->tx_hang_recheck = true;
1091 return;
1092 }
1093 /* Real hang detected */
1094 adapter->tx_hang_recheck = false;
1095 netif_stop_queue(netdev);
1096
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001097 e1e_rphy(hw, MII_BMSR, &phy_status);
1098 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1099 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001100
1101 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1102
1103 /* detected Hardware unit hang */
1104 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001105 " TDH <%x>\n"
1106 " TDT <%x>\n"
1107 " next_to_use <%x>\n"
1108 " next_to_clean <%x>\n"
1109 "buffer_info[next_to_clean]:\n"
1110 " time_stamp <%lx>\n"
1111 " next_to_watch <%x>\n"
1112 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001113 " next_to_watch.status <%x>\n"
1114 "MAC Status <%x>\n"
1115 "PHY Status <%x>\n"
1116 "PHY 1000BASE-T Status <%x>\n"
1117 "PHY Extended Status <%x>\n"
1118 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001119 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1120 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1121 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1122 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001123
1124 /* Suggest workaround for known h/w issue */
1125 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1126 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127}
1128
1129/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001130 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1131 * @work: pointer to work struct
1132 *
1133 * This work function polls the TSYNCTXCTL valid bit to determine when a
1134 * timestamp has been taken for the current stored skb. The timestamp must
1135 * be for this skb because only one such packet is allowed in the queue.
1136 */
1137static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1138{
1139 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1140 tx_hwtstamp_work);
1141 struct e1000_hw *hw = &adapter->hw;
1142
1143 if (!adapter->tx_hwtstamp_skb)
1144 return;
1145
1146 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1147 struct skb_shared_hwtstamps shhwtstamps;
1148 u64 txstmp;
1149
1150 txstmp = er32(TXSTMPL);
1151 txstmp |= (u64)er32(TXSTMPH) << 32;
1152
1153 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1154
1155 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1156 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1157 adapter->tx_hwtstamp_skb = NULL;
1158 } else {
1159 /* reschedule to check later */
1160 schedule_work(&adapter->tx_hwtstamp_work);
1161 }
1162}
1163
1164/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001166 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 *
1168 * the return value indicates whether actual cleaning was done, there
1169 * is no guarantee that everything was cleaned
1170 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001171static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172{
Bruce Allan55aa6982011-12-16 00:45:45 +00001173 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 struct net_device *netdev = adapter->netdev;
1175 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 struct e1000_tx_desc *tx_desc, *eop_desc;
1177 struct e1000_buffer *buffer_info;
1178 unsigned int i, eop;
1179 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001181 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182
1183 i = tx_ring->next_to_clean;
1184 eop = tx_ring->buffer_info[i].next_to_watch;
1185 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1186
Alexander Duyck12d04a32009-03-25 22:05:03 +00001187 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1188 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001189 bool cleaned = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001190 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001191 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 tx_desc = E1000_TX_DESC(*tx_ring, i);
1193 buffer_info = &tx_ring->buffer_info[i];
1194 cleaned = (i == eop);
1195
1196 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001197 total_tx_packets += buffer_info->segs;
1198 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001199 if (buffer_info->skb) {
1200 bytes_compl += buffer_info->skb->len;
1201 pkts_compl++;
1202 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 }
1204
Bruce Allan55aa6982011-12-16 00:45:45 +00001205 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 tx_desc->upper.data = 0;
1207
1208 i++;
1209 if (i == tx_ring->count)
1210 i = 0;
1211 }
1212
Terry Loftindac87612010-04-09 10:29:49 +00001213 if (i == tx_ring->next_to_use)
1214 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001215 eop = tx_ring->buffer_info[i].next_to_watch;
1216 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 }
1218
1219 tx_ring->next_to_clean = i;
1220
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001221 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1222
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001224 if (count && netif_carrier_ok(netdev) &&
1225 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001226 /* Make sure that anybody stopping the queue after this
1227 * sees the new next_to_clean.
1228 */
1229 smp_mb();
1230
1231 if (netif_queue_stopped(netdev) &&
1232 !(test_bit(__E1000_DOWN, &adapter->state))) {
1233 netif_wake_queue(netdev);
1234 ++adapter->restart_queue;
1235 }
1236 }
1237
1238 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001239 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001240 * check with the clearing of time_stamp and movement of i
1241 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001242 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001243 if (tx_ring->buffer_info[i].time_stamp &&
1244 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001245 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001246 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001247 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001248 else
1249 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 }
1251 adapter->total_tx_bytes += total_tx_bytes;
1252 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001253 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254}
1255
1256/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001258 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259 *
1260 * the return value indicates whether actual cleaning was done, there
1261 * is no guarantee that everything was cleaned
1262 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001263static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1264 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265{
Bruce Allan55aa6982011-12-16 00:45:45 +00001266 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001267 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1269 struct net_device *netdev = adapter->netdev;
1270 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271 struct e1000_buffer *buffer_info, *next_buffer;
1272 struct e1000_ps_page *ps_page;
1273 struct sk_buff *skb;
1274 unsigned int i, j;
1275 u32 length, staterr;
1276 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001277 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1279
1280 i = rx_ring->next_to_clean;
1281 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1282 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1283 buffer_info = &rx_ring->buffer_info[i];
1284
1285 while (staterr & E1000_RXD_STAT_DD) {
1286 if (*work_done >= work_to_do)
1287 break;
1288 (*work_done)++;
1289 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001290 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001291
1292 /* in the packet split case this is header only */
1293 prefetch(skb->data - NET_IP_ALIGN);
1294
1295 i++;
1296 if (i == rx_ring->count)
1297 i = 0;
1298 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1299 prefetch(next_rxd);
1300
1301 next_buffer = &rx_ring->buffer_info[i];
1302
Rusty Russell3db1cd52011-12-19 13:56:45 +00001303 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001305 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001306 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 buffer_info->dma = 0;
1308
Bruce Allanaf667a22010-12-31 06:10:01 +00001309 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001310 if (!(staterr & E1000_RXD_STAT_EOP))
1311 adapter->flags2 |= FLAG2_IS_DISCARDING;
1312
1313 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001314 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001315 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001316 if (staterr & E1000_RXD_STAT_EOP)
1317 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001318 goto next_desc;
1319 }
1320
Ben Greearcf955e62012-02-11 15:39:51 +00001321 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1322 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 dev_kfree_skb_irq(skb);
1324 goto next_desc;
1325 }
1326
1327 length = le16_to_cpu(rx_desc->wb.middle.length0);
1328
1329 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001330 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 dev_kfree_skb_irq(skb);
1332 goto next_desc;
1333 }
1334
1335 /* Good Receive */
1336 skb_put(skb, length);
1337
1338 {
Bruce Allane921eb12012-11-28 09:28:37 +00001339 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001340 * it more efficient than reusing j
1341 */
1342 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001343
Bruce Allane921eb12012-11-28 09:28:37 +00001344 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001345 * packet throughput, so unsplit small packets and
1346 * save the alloc/put only valid in softirq (napi)
1347 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001348 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001349 if (l1 && (l1 <= copybreak) &&
1350 ((length + l1) <= adapter->rx_ps_bsize0)) {
1351 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001352
Bruce Allan0e15df42012-01-31 06:37:11 +00001353 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001354
Bruce Allane921eb12012-11-28 09:28:37 +00001355 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001356 * kmap_atomic, so we can't hold the mapping
1357 * very long
1358 */
1359 dma_sync_single_for_cpu(&pdev->dev,
1360 ps_page->dma,
1361 PAGE_SIZE,
1362 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001363 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001364 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001365 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001366 dma_sync_single_for_device(&pdev->dev,
1367 ps_page->dma,
1368 PAGE_SIZE,
1369 DMA_FROM_DEVICE);
1370
1371 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001372 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1373 if (!(netdev->features & NETIF_F_RXFCS))
1374 l1 -= 4;
1375 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001376
1377 skb_put(skb, l1);
1378 goto copydone;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001379 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001380 }
1381
1382 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1383 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1384 if (!length)
1385 break;
1386
Auke Kok47f44e42007-10-25 13:57:44 -07001387 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001388 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1389 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390 ps_page->dma = 0;
1391 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1392 ps_page->page = NULL;
1393 skb->len += length;
1394 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001395 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001396 }
1397
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001398 /* strip the ethernet crc, problem is we're using pages now so
1399 * this whole operation can get a little cpu intensive
1400 */
Ben Greear01840392012-02-11 15:39:25 +00001401 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1402 if (!(netdev->features & NETIF_F_RXFCS))
1403 pskb_trim(skb, skb->len - 4);
1404 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001405
Auke Kokbc7f75f2007-09-17 12:30:59 -07001406copydone:
1407 total_rx_bytes += skb->len;
1408 total_rx_packets++;
1409
Bruce Allan2e1706f2012-06-30 20:02:42 +00001410 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001411
Bruce Allan70495a52012-01-11 01:26:50 +00001412 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1413
Auke Kokbc7f75f2007-09-17 12:30:59 -07001414 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001415 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 adapter->rx_hdr_split++;
1417
Bruce Allanb67e1912012-12-27 08:32:33 +00001418 e1000_receive_skb(adapter, netdev, skb, staterr,
1419 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001420
1421next_desc:
1422 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1423 buffer_info->skb = NULL;
1424
1425 /* return some buffers to hardware, one at a time is too slow */
1426 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001427 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001428 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001429 cleaned_count = 0;
1430 }
1431
1432 /* use prefetched values */
1433 rx_desc = next_rxd;
1434 buffer_info = next_buffer;
1435
1436 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1437 }
1438 rx_ring->next_to_clean = i;
1439
1440 cleaned_count = e1000_desc_unused(rx_ring);
1441 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001442 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001443
Auke Kokbc7f75f2007-09-17 12:30:59 -07001444 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001445 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446 return cleaned;
1447}
1448
1449/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001450 * e1000_consume_page - helper function
1451 **/
1452static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001453 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454{
1455 bi->page = NULL;
1456 skb->len += length;
1457 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001458 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459}
1460
1461/**
1462 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1463 * @adapter: board private structure
1464 *
1465 * the return value indicates whether actual cleaning was done, there
1466 * is no guarantee that everything was cleaned
1467 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001468static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1469 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001470{
Bruce Allan55aa6982011-12-16 00:45:45 +00001471 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001472 struct net_device *netdev = adapter->netdev;
1473 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001474 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001475 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001476 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001477 unsigned int i;
1478 int cleaned_count = 0;
1479 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001480 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001481 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001482
1483 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001484 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1485 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001486 buffer_info = &rx_ring->buffer_info[i];
1487
Bruce Allan5f450212011-07-22 06:21:46 +00001488 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001489 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490
1491 if (*work_done >= work_to_do)
1492 break;
1493 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001494 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001495
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001496 skb = buffer_info->skb;
1497 buffer_info->skb = NULL;
1498
1499 ++i;
1500 if (i == rx_ring->count)
1501 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001502 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 prefetch(next_rxd);
1504
1505 next_buffer = &rx_ring->buffer_info[i];
1506
1507 cleaned = true;
1508 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001509 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1510 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001511 buffer_info->dma = 0;
1512
Bruce Allan5f450212011-07-22 06:21:46 +00001513 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001514
1515 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001516 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001517 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1518 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001519 /* recycle both page and skb */
1520 buffer_info->skb = skb;
1521 /* an error means any chain goes out the window too */
1522 if (rx_ring->rx_skb_top)
1523 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1524 rx_ring->rx_skb_top = NULL;
1525 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001527#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001528 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529 /* this descriptor is only the beginning (or middle) */
1530 if (!rxtop) {
1531 /* this is the beginning of a chain */
1532 rxtop = skb;
1533 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001534 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001535 } else {
1536 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001537 shinfo = skb_shinfo(rxtop);
1538 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1539 buffer_info->page, 0,
1540 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001541 /* re-use the skb, only consumed the page */
1542 buffer_info->skb = skb;
1543 }
1544 e1000_consume_page(buffer_info, rxtop, length);
1545 goto next_desc;
1546 } else {
1547 if (rxtop) {
1548 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001549 shinfo = skb_shinfo(rxtop);
1550 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1551 buffer_info->page, 0,
1552 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001553 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001554 * page
1555 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001556 buffer_info->skb = skb;
1557 skb = rxtop;
1558 rxtop = NULL;
1559 e1000_consume_page(buffer_info, skb, length);
1560 } else {
1561 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001562 * copybreak to save the put_page/alloc_page
1563 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001564 if (length <= copybreak &&
1565 skb_tailroom(skb) >= length) {
1566 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001567 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001568 memcpy(skb_tail_pointer(skb), vaddr,
1569 length);
Cong Wang46790262011-11-25 23:14:23 +08001570 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001571 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001572 * buffer_info->page
1573 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001574 skb_put(skb, length);
1575 } else {
1576 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001577 buffer_info->page, 0,
1578 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001580 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001581 }
1582 }
1583 }
1584
Bruce Allan2e1706f2012-06-30 20:02:42 +00001585 /* Receive Checksum Offload */
1586 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001587
Bruce Allan70495a52012-01-11 01:26:50 +00001588 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1589
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001590 /* probably a little skewed due to removing CRC */
1591 total_rx_bytes += skb->len;
1592 total_rx_packets++;
1593
1594 /* eth type trans needs skb->data to point to something */
1595 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001596 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001597 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001598 goto next_desc;
1599 }
1600
Bruce Allan5f450212011-07-22 06:21:46 +00001601 e1000_receive_skb(adapter, netdev, skb, staterr,
1602 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001603
1604next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001605 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001606
1607 /* return some buffers to hardware, one at a time is too slow */
1608 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001609 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001610 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001611 cleaned_count = 0;
1612 }
1613
1614 /* use prefetched values */
1615 rx_desc = next_rxd;
1616 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001617
1618 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001619 }
1620 rx_ring->next_to_clean = i;
1621
1622 cleaned_count = e1000_desc_unused(rx_ring);
1623 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001624 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001625
1626 adapter->total_rx_bytes += total_rx_bytes;
1627 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001628 return cleaned;
1629}
1630
1631/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001633 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001635static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636{
Bruce Allan55aa6982011-12-16 00:45:45 +00001637 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 struct e1000_buffer *buffer_info;
1639 struct e1000_ps_page *ps_page;
1640 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 unsigned int i, j;
1642
1643 /* Free all the Rx ring sk_buffs */
1644 for (i = 0; i < rx_ring->count; i++) {
1645 buffer_info = &rx_ring->buffer_info[i];
1646 if (buffer_info->dma) {
1647 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001648 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001650 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001651 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001652 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001653 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001655 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001657 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 buffer_info->dma = 0;
1659 }
1660
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001661 if (buffer_info->page) {
1662 put_page(buffer_info->page);
1663 buffer_info->page = NULL;
1664 }
1665
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 if (buffer_info->skb) {
1667 dev_kfree_skb(buffer_info->skb);
1668 buffer_info->skb = NULL;
1669 }
1670
1671 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001672 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001673 if (!ps_page->page)
1674 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001675 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1676 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677 ps_page->dma = 0;
1678 put_page(ps_page->page);
1679 ps_page->page = NULL;
1680 }
1681 }
1682
1683 /* there also may be some cached data from a chained receive */
1684 if (rx_ring->rx_skb_top) {
1685 dev_kfree_skb(rx_ring->rx_skb_top);
1686 rx_ring->rx_skb_top = NULL;
1687 }
1688
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 /* Zero out the descriptor ring */
1690 memset(rx_ring->desc, 0, rx_ring->size);
1691
1692 rx_ring->next_to_clean = 0;
1693 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001694 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695
Bruce Allanc5083cf2011-12-16 00:45:40 +00001696 writel(0, rx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00001697 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00001698 e1000e_update_rdt_wa(rx_ring, 0);
1699 else
1700 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701}
1702
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001703static void e1000e_downshift_workaround(struct work_struct *work)
1704{
1705 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001706 struct e1000_adapter,
1707 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001708
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001709 if (test_bit(__E1000_DOWN, &adapter->state))
1710 return;
1711
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001712 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1713}
1714
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715/**
1716 * e1000_intr_msi - Interrupt Handler
1717 * @irq: interrupt number
1718 * @data: pointer to a network interface device structure
1719 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001720static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721{
1722 struct net_device *netdev = data;
1723 struct e1000_adapter *adapter = netdev_priv(netdev);
1724 struct e1000_hw *hw = &adapter->hw;
1725 u32 icr = er32(ICR);
1726
Bruce Allane921eb12012-11-28 09:28:37 +00001727 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001728 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001729 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001730 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001731 * disconnect (LSC) before accessing any PHY registers
1732 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1734 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001735 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736
Bruce Allane921eb12012-11-28 09:28:37 +00001737 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001739 * adapter in watchdog
1740 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if (netif_carrier_ok(netdev) &&
1742 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1743 /* disable receives */
1744 u32 rctl = er32(RCTL);
1745 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001746 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001747 }
1748 /* guard against interrupt when we're going down */
1749 if (!test_bit(__E1000_DOWN, &adapter->state))
1750 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1751 }
1752
Bruce Allan94fb8482013-01-23 09:00:03 +00001753 /* Reset on uncorrectable ECC error */
1754 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1755 u32 pbeccsts = er32(PBECCSTS);
1756
1757 adapter->corr_errors +=
1758 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1759 adapter->uncorr_errors +=
1760 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1761 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1762
1763 /* Do the reset outside of interrupt context */
1764 schedule_work(&adapter->reset_task);
1765
1766 /* return immediately since reset is imminent */
1767 return IRQ_HANDLED;
1768 }
1769
Ben Hutchings288379f2009-01-19 16:43:59 -08001770 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 adapter->total_tx_bytes = 0;
1772 adapter->total_tx_packets = 0;
1773 adapter->total_rx_bytes = 0;
1774 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001775 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 }
1777
1778 return IRQ_HANDLED;
1779}
1780
1781/**
1782 * e1000_intr - Interrupt Handler
1783 * @irq: interrupt number
1784 * @data: pointer to a network interface device structure
1785 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001786static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787{
1788 struct net_device *netdev = data;
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1790 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001792
Bruce Allana68ea772009-11-20 23:23:16 +00001793 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Bruce Allane80bd1d2013-05-01 01:19:46 +00001794 return IRQ_NONE; /* Not our interrupt */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795
Bruce Allane921eb12012-11-28 09:28:37 +00001796 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001797 * not set, then the adapter didn't send an interrupt
1798 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799 if (!(icr & E1000_ICR_INT_ASSERTED))
1800 return IRQ_NONE;
1801
Bruce Allane921eb12012-11-28 09:28:37 +00001802 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001803 * interrupts are masked. No need for the
1804 * IMC write
1805 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806
dave graham573cca82009-02-10 12:52:05 +00001807 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001808 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001809 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001810 * disconnect (LSC) before accessing any PHY registers
1811 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1813 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001814 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815
Bruce Allane921eb12012-11-28 09:28:37 +00001816 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 * For packet buffer work-around on link down event;
1818 * disable receives here in the ISR and
1819 * reset adapter in watchdog
1820 */
1821 if (netif_carrier_ok(netdev) &&
1822 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1823 /* disable receives */
1824 rctl = er32(RCTL);
1825 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001826 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001827 }
1828 /* guard against interrupt when we're going down */
1829 if (!test_bit(__E1000_DOWN, &adapter->state))
1830 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1831 }
1832
Bruce Allan94fb8482013-01-23 09:00:03 +00001833 /* Reset on uncorrectable ECC error */
1834 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1835 u32 pbeccsts = er32(PBECCSTS);
1836
1837 adapter->corr_errors +=
1838 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1839 adapter->uncorr_errors +=
1840 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1841 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1842
1843 /* Do the reset outside of interrupt context */
1844 schedule_work(&adapter->reset_task);
1845
1846 /* return immediately since reset is imminent */
1847 return IRQ_HANDLED;
1848 }
1849
Ben Hutchings288379f2009-01-19 16:43:59 -08001850 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851 adapter->total_tx_bytes = 0;
1852 adapter->total_tx_packets = 0;
1853 adapter->total_rx_bytes = 0;
1854 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001855 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 }
1857
1858 return IRQ_HANDLED;
1859}
1860
Bruce Allan8bb62862013-01-16 08:46:49 +00001861static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001862{
1863 struct net_device *netdev = data;
1864 struct e1000_adapter *adapter = netdev_priv(netdev);
1865 struct e1000_hw *hw = &adapter->hw;
1866 u32 icr = er32(ICR);
1867
1868 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001869 if (!test_bit(__E1000_DOWN, &adapter->state))
1870 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001871 return IRQ_NONE;
1872 }
1873
1874 if (icr & adapter->eiac_mask)
1875 ew32(ICS, (icr & adapter->eiac_mask));
1876
1877 if (icr & E1000_ICR_OTHER) {
1878 if (!(icr & E1000_ICR_LSC))
1879 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001880 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001881 /* guard against interrupt when we're going down */
1882 if (!test_bit(__E1000_DOWN, &adapter->state))
1883 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1884 }
1885
1886no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001887 if (!test_bit(__E1000_DOWN, &adapter->state))
1888 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001889
1890 return IRQ_HANDLED;
1891}
1892
Bruce Allan8bb62862013-01-16 08:46:49 +00001893static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001894{
1895 struct net_device *netdev = data;
1896 struct e1000_adapter *adapter = netdev_priv(netdev);
1897 struct e1000_hw *hw = &adapter->hw;
1898 struct e1000_ring *tx_ring = adapter->tx_ring;
1899
Bruce Allan4662e822008-08-26 18:37:06 -07001900 adapter->total_tx_bytes = 0;
1901 adapter->total_tx_packets = 0;
1902
Bruce Allan55aa6982011-12-16 00:45:45 +00001903 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001904 /* Ring was not completely cleaned, so fire another interrupt */
1905 ew32(ICS, tx_ring->ims_val);
1906
1907 return IRQ_HANDLED;
1908}
1909
Bruce Allan8bb62862013-01-16 08:46:49 +00001910static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001911{
1912 struct net_device *netdev = data;
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001914 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001915
1916 /* Write the ITR value calculated at the end of the
1917 * previous interrupt.
1918 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001919 if (rx_ring->set_itr) {
1920 writel(1000000000 / (rx_ring->itr_val * 256),
1921 rx_ring->itr_register);
1922 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001923 }
1924
Ben Hutchings288379f2009-01-19 16:43:59 -08001925 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001926 adapter->total_rx_bytes = 0;
1927 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001928 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001929 }
1930 return IRQ_HANDLED;
1931}
1932
1933/**
1934 * e1000_configure_msix - Configure MSI-X hardware
1935 *
1936 * e1000_configure_msix sets up the hardware to properly
1937 * generate MSI-X interrupts.
1938 **/
1939static void e1000_configure_msix(struct e1000_adapter *adapter)
1940{
1941 struct e1000_hw *hw = &adapter->hw;
1942 struct e1000_ring *rx_ring = adapter->rx_ring;
1943 struct e1000_ring *tx_ring = adapter->tx_ring;
1944 int vector = 0;
1945 u32 ctrl_ext, ivar = 0;
1946
1947 adapter->eiac_mask = 0;
1948
1949 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1950 if (hw->mac.type == e1000_82574) {
1951 u32 rfctl = er32(RFCTL);
1952 rfctl |= E1000_RFCTL_ACK_DIS;
1953 ew32(RFCTL, rfctl);
1954 }
1955
Bruce Allan4662e822008-08-26 18:37:06 -07001956 /* Configure Rx vector */
1957 rx_ring->ims_val = E1000_IMS_RXQ0;
1958 adapter->eiac_mask |= rx_ring->ims_val;
1959 if (rx_ring->itr_val)
1960 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001961 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001962 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001963 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001964 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1965
1966 /* Configure Tx vector */
1967 tx_ring->ims_val = E1000_IMS_TXQ0;
1968 vector++;
1969 if (tx_ring->itr_val)
1970 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001971 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001972 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001973 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001974 adapter->eiac_mask |= tx_ring->ims_val;
1975 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1976
1977 /* set vector for Other Causes, e.g. link changes */
1978 vector++;
1979 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1980 if (rx_ring->itr_val)
1981 writel(1000000000 / (rx_ring->itr_val * 256),
1982 hw->hw_addr + E1000_EITR_82574(vector));
1983 else
1984 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1985
1986 /* Cause Tx interrupts on every write back */
1987 ivar |= (1 << 31);
1988
1989 ew32(IVAR, ivar);
1990
1991 /* enable MSI-X PBA support */
1992 ctrl_ext = er32(CTRL_EXT);
1993 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1994
1995 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07001996 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1997 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1998 ew32(CTRL_EXT, ctrl_ext);
1999 e1e_flush();
2000}
2001
2002void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2003{
2004 if (adapter->msix_entries) {
2005 pci_disable_msix(adapter->pdev);
2006 kfree(adapter->msix_entries);
2007 adapter->msix_entries = NULL;
2008 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2009 pci_disable_msi(adapter->pdev);
2010 adapter->flags &= ~FLAG_MSI_ENABLED;
2011 }
Bruce Allan4662e822008-08-26 18:37:06 -07002012}
2013
2014/**
2015 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2016 *
2017 * Attempt to configure interrupts using the best available
2018 * capabilities of the hardware and kernel.
2019 **/
2020void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2021{
2022 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002023 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002024
2025 switch (adapter->int_mode) {
2026 case E1000E_INT_MODE_MSIX:
2027 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002028 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2029 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002030 sizeof(struct
2031 msix_entry),
2032 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002033 if (adapter->msix_entries) {
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002034 struct e1000_adapter *a = adapter;
2035
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002036 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002037 adapter->msix_entries[i].entry = i;
2038
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002039 err = pci_enable_msix_range(a->pdev,
2040 a->msix_entries,
2041 a->num_vectors,
2042 a->num_vectors);
2043 if (err > 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002044 return;
2045 }
2046 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002047 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002048 e1000e_reset_interrupt_capability(adapter);
2049 }
2050 adapter->int_mode = E1000E_INT_MODE_MSI;
2051 /* Fall through */
2052 case E1000E_INT_MODE_MSI:
2053 if (!pci_enable_msi(adapter->pdev)) {
2054 adapter->flags |= FLAG_MSI_ENABLED;
2055 } else {
2056 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002057 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002058 }
2059 /* Fall through */
2060 case E1000E_INT_MODE_LEGACY:
2061 /* Don't do anything; this is the system default */
2062 break;
2063 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002064
2065 /* store the number of vectors being used */
2066 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002067}
2068
2069/**
2070 * e1000_request_msix - Initialize MSI-X interrupts
2071 *
2072 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2073 * kernel.
2074 **/
2075static int e1000_request_msix(struct e1000_adapter *adapter)
2076{
2077 struct net_device *netdev = adapter->netdev;
2078 int err = 0, vector = 0;
2079
2080 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002081 snprintf(adapter->rx_ring->name,
2082 sizeof(adapter->rx_ring->name) - 1,
2083 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002084 else
2085 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2086 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002087 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002088 netdev);
2089 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002090 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002091 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2092 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002093 adapter->rx_ring->itr_val = adapter->itr;
2094 vector++;
2095
2096 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002097 snprintf(adapter->tx_ring->name,
2098 sizeof(adapter->tx_ring->name) - 1,
2099 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002100 else
2101 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2102 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002103 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002104 netdev);
2105 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002106 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002107 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2108 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002109 adapter->tx_ring->itr_val = adapter->itr;
2110 vector++;
2111
2112 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002113 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002114 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002115 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002116
2117 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002118
Bruce Allan4662e822008-08-26 18:37:06 -07002119 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002120}
2121
Bruce Allanf8d59f72008-08-08 18:36:11 -07002122/**
2123 * e1000_request_irq - initialize interrupts
2124 *
2125 * Attempts to configure interrupts using the best available
2126 * capabilities of the hardware and kernel.
2127 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128static int e1000_request_irq(struct e1000_adapter *adapter)
2129{
2130 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002131 int err;
2132
Bruce Allan4662e822008-08-26 18:37:06 -07002133 if (adapter->msix_entries) {
2134 err = e1000_request_msix(adapter);
2135 if (!err)
2136 return err;
2137 /* fall back to MSI */
2138 e1000e_reset_interrupt_capability(adapter);
2139 adapter->int_mode = E1000E_INT_MODE_MSI;
2140 e1000e_set_interrupt_capability(adapter);
2141 }
2142 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002143 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002144 netdev->name, netdev);
2145 if (!err)
2146 return err;
2147
2148 /* fall back to legacy interrupt */
2149 e1000e_reset_interrupt_capability(adapter);
2150 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002151 }
2152
Joe Perchesa0607fd2009-11-18 23:29:17 -08002153 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002154 netdev->name, netdev);
2155 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002156 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157
2158 return err;
2159}
2160
2161static void e1000_free_irq(struct e1000_adapter *adapter)
2162{
2163 struct net_device *netdev = adapter->netdev;
2164
Bruce Allan4662e822008-08-26 18:37:06 -07002165 if (adapter->msix_entries) {
2166 int vector = 0;
2167
2168 free_irq(adapter->msix_entries[vector].vector, netdev);
2169 vector++;
2170
2171 free_irq(adapter->msix_entries[vector].vector, netdev);
2172 vector++;
2173
2174 /* Other Causes interrupt vector */
2175 free_irq(adapter->msix_entries[vector].vector, netdev);
2176 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002177 }
Bruce Allan4662e822008-08-26 18:37:06 -07002178
2179 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180}
2181
2182/**
2183 * e1000_irq_disable - Mask off interrupt generation on the NIC
2184 **/
2185static void e1000_irq_disable(struct e1000_adapter *adapter)
2186{
2187 struct e1000_hw *hw = &adapter->hw;
2188
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002190 if (adapter->msix_entries)
2191 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002192 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002193
2194 if (adapter->msix_entries) {
2195 int i;
2196 for (i = 0; i < adapter->num_vectors; i++)
2197 synchronize_irq(adapter->msix_entries[i].vector);
2198 } else {
2199 synchronize_irq(adapter->pdev->irq);
2200 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002201}
2202
2203/**
2204 * e1000_irq_enable - Enable default interrupt generation settings
2205 **/
2206static void e1000_irq_enable(struct e1000_adapter *adapter)
2207{
2208 struct e1000_hw *hw = &adapter->hw;
2209
Bruce Allan4662e822008-08-26 18:37:06 -07002210 if (adapter->msix_entries) {
2211 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2212 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002213 } else if (hw->mac.type == e1000_pch_lpt) {
2214 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002215 } else {
2216 ew32(IMS, IMS_ENABLE_MASK);
2217 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002218 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219}
2220
2221/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002222 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223 * @adapter: address of board private structure
2224 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002225 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 * For ASF and Pass Through versions of f/w this means that
2227 * the driver is loaded. For AMT version (only with 82573)
2228 * of the f/w this means that the network i/f is open.
2229 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002230void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231{
2232 struct e1000_hw *hw = &adapter->hw;
2233 u32 ctrl_ext;
2234 u32 swsm;
2235
2236 /* Let firmware know the driver has taken over */
2237 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2238 swsm = er32(SWSM);
2239 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2240 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2241 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002242 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243 }
2244}
2245
2246/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002247 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248 * @adapter: address of board private structure
2249 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002250 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 * For ASF and Pass Through versions of f/w this means that the
2252 * driver is no longer loaded. For AMT version (only with 82573) i
2253 * of the f/w this means that the network i/f is closed.
2254 *
2255 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002256void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257{
2258 struct e1000_hw *hw = &adapter->hw;
2259 u32 ctrl_ext;
2260 u32 swsm;
2261
2262 /* Let firmware taken over control of h/w */
2263 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2264 swsm = er32(SWSM);
2265 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2266 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2267 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002268 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 }
2270}
2271
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002273 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 **/
2275static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2276 struct e1000_ring *ring)
2277{
2278 struct pci_dev *pdev = adapter->pdev;
2279
2280 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2281 GFP_KERNEL);
2282 if (!ring->desc)
2283 return -ENOMEM;
2284
2285 return 0;
2286}
2287
2288/**
2289 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002290 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291 *
2292 * Return 0 on success, negative on failure
2293 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002294int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002295{
Bruce Allan55aa6982011-12-16 00:45:45 +00002296 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 int err = -ENOMEM, size;
2298
2299 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002300 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002301 if (!tx_ring->buffer_info)
2302 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303
2304 /* round up to nearest 4K */
2305 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2306 tx_ring->size = ALIGN(tx_ring->size, 4096);
2307
2308 err = e1000_alloc_ring_dma(adapter, tx_ring);
2309 if (err)
2310 goto err;
2311
2312 tx_ring->next_to_use = 0;
2313 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314
2315 return 0;
2316err:
2317 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002318 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 return err;
2320}
2321
2322/**
2323 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002324 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 *
2326 * Returns 0 on success, negative on failure
2327 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002328int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329{
Bruce Allan55aa6982011-12-16 00:45:45 +00002330 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002331 struct e1000_buffer *buffer_info;
2332 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333
2334 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002335 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 if (!rx_ring->buffer_info)
2337 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338
Auke Kok47f44e42007-10-25 13:57:44 -07002339 for (i = 0; i < rx_ring->count; i++) {
2340 buffer_info = &rx_ring->buffer_info[i];
2341 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2342 sizeof(struct e1000_ps_page),
2343 GFP_KERNEL);
2344 if (!buffer_info->ps_pages)
2345 goto err_pages;
2346 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347
2348 desc_len = sizeof(union e1000_rx_desc_packet_split);
2349
2350 /* Round up to nearest 4K */
2351 rx_ring->size = rx_ring->count * desc_len;
2352 rx_ring->size = ALIGN(rx_ring->size, 4096);
2353
2354 err = e1000_alloc_ring_dma(adapter, rx_ring);
2355 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002356 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357
2358 rx_ring->next_to_clean = 0;
2359 rx_ring->next_to_use = 0;
2360 rx_ring->rx_skb_top = NULL;
2361
2362 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002363
2364err_pages:
2365 for (i = 0; i < rx_ring->count; i++) {
2366 buffer_info = &rx_ring->buffer_info[i];
2367 kfree(buffer_info->ps_pages);
2368 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369err:
2370 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002371 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 return err;
2373}
2374
2375/**
2376 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002377 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002379static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380{
Bruce Allan55aa6982011-12-16 00:45:45 +00002381 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 struct e1000_buffer *buffer_info;
2383 unsigned long size;
2384 unsigned int i;
2385
2386 for (i = 0; i < tx_ring->count; i++) {
2387 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002388 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 }
2390
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002391 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 size = sizeof(struct e1000_buffer) * tx_ring->count;
2393 memset(tx_ring->buffer_info, 0, size);
2394
2395 memset(tx_ring->desc, 0, tx_ring->size);
2396
2397 tx_ring->next_to_use = 0;
2398 tx_ring->next_to_clean = 0;
2399
Bruce Allanc5083cf2011-12-16 00:45:40 +00002400 writel(0, tx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00002401 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00002402 e1000e_update_tdt_wa(tx_ring, 0);
2403 else
2404 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405}
2406
2407/**
2408 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002409 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 *
2411 * Free all transmit software resources
2412 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002413void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414{
Bruce Allan55aa6982011-12-16 00:45:45 +00002415 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417
Bruce Allan55aa6982011-12-16 00:45:45 +00002418 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419
2420 vfree(tx_ring->buffer_info);
2421 tx_ring->buffer_info = NULL;
2422
2423 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2424 tx_ring->dma);
2425 tx_ring->desc = NULL;
2426}
2427
2428/**
2429 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002430 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 *
2432 * Free all receive software resources
2433 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002434void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435{
Bruce Allan55aa6982011-12-16 00:45:45 +00002436 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002438 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439
Bruce Allan55aa6982011-12-16 00:45:45 +00002440 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002442 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002443 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002444
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445 vfree(rx_ring->buffer_info);
2446 rx_ring->buffer_info = NULL;
2447
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2449 rx_ring->dma);
2450 rx_ring->desc = NULL;
2451}
2452
2453/**
2454 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002455 * @adapter: pointer to adapter
2456 * @itr_setting: current adapter->itr
2457 * @packets: the number of packets during this measurement interval
2458 * @bytes: the number of bytes during this measurement interval
2459 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 * Stores a new ITR value based on packets and byte
2461 * counts during the last interrupt. The advantage of per interrupt
2462 * computation is faster updates and more accurate ITR for the current
2463 * traffic pattern. Constants in this function were computed
2464 * based on theoretical maximum wire speed and thresholds were set based
2465 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002466 * while increasing bulk throughput. This functionality is controlled
2467 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002469static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470{
2471 unsigned int retval = itr_setting;
2472
2473 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002474 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475
2476 switch (itr_setting) {
2477 case lowest_latency:
2478 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002479 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002480 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002481 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002482 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002484 case low_latency: /* 50 usec aka 20000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 if (bytes > 10000) {
2486 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002487 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002489 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002491 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002493 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494 retval = bulk_latency;
2495 } else if (packets <= 2 && bytes < 512) {
2496 retval = lowest_latency;
2497 }
2498 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002499 case bulk_latency: /* 250 usec aka 4000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002501 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 } else if (bytes < 6000) {
2504 retval = low_latency;
2505 }
2506 break;
2507 }
2508
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 return retval;
2510}
2511
2512static void e1000_set_itr(struct e1000_adapter *adapter)
2513{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 u16 current_itr;
2515 u32 new_itr = adapter->itr;
2516
2517 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2518 if (adapter->link_speed != SPEED_1000) {
2519 current_itr = 0;
2520 new_itr = 4000;
2521 goto set_itr_now;
2522 }
2523
Bruce Allan828bac82010-09-29 21:39:37 +00002524 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2525 new_itr = 0;
2526 goto set_itr_now;
2527 }
2528
Bruce Allan8bb62862013-01-16 08:46:49 +00002529 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2530 adapter->total_tx_packets,
2531 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2533 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2534 adapter->tx_itr = low_latency;
2535
Bruce Allan8bb62862013-01-16 08:46:49 +00002536 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2537 adapter->total_rx_packets,
2538 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2540 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2541 adapter->rx_itr = low_latency;
2542
2543 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2544
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002546 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 case lowest_latency:
2548 new_itr = 70000;
2549 break;
2550 case low_latency:
Bruce Allane80bd1d2013-05-01 01:19:46 +00002551 new_itr = 20000; /* aka hwitr = ~200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552 break;
2553 case bulk_latency:
2554 new_itr = 4000;
2555 break;
2556 default:
2557 break;
2558 }
2559
2560set_itr_now:
2561 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002562 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002564 * increasing
2565 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002567 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002569 adapter->rx_ring->itr_val = new_itr;
2570 if (adapter->msix_entries)
2571 adapter->rx_ring->set_itr = 1;
2572 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002573 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 }
2575}
2576
2577/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002578 * e1000e_write_itr - write the ITR value to the appropriate registers
2579 * @adapter: address of board private structure
2580 * @itr: new ITR value to program
2581 *
2582 * e1000e_write_itr determines if the adapter is in MSI-X mode
2583 * and, if so, writes the EITR registers with the ITR value.
2584 * Otherwise, it writes the ITR value into the ITR register.
2585 **/
2586void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2587{
2588 struct e1000_hw *hw = &adapter->hw;
2589 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2590
2591 if (adapter->msix_entries) {
2592 int vector;
2593
2594 for (vector = 0; vector < adapter->num_vectors; vector++)
2595 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2596 } else {
2597 ew32(ITR, new_itr);
2598 }
2599}
2600
2601/**
Bruce Allan4662e822008-08-26 18:37:06 -07002602 * e1000_alloc_queues - Allocate memory for all rings
2603 * @adapter: board private structure to initialize
2604 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002605static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002606{
Bruce Allan55aa6982011-12-16 00:45:45 +00002607 int size = sizeof(struct e1000_ring);
2608
2609 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002610 if (!adapter->tx_ring)
2611 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002612 adapter->tx_ring->count = adapter->tx_ring_count;
2613 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002614
Bruce Allan55aa6982011-12-16 00:45:45 +00002615 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002616 if (!adapter->rx_ring)
2617 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002618 adapter->rx_ring->count = adapter->rx_ring_count;
2619 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002620
2621 return 0;
2622err:
2623 e_err("Unable to allocate memory for queues\n");
2624 kfree(adapter->rx_ring);
2625 kfree(adapter->tx_ring);
2626 return -ENOMEM;
2627}
2628
2629/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002630 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002631 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002632 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002633 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002634static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002635{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002636 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2637 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002638 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002639 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002640 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641
Wang Chen4cf16532008-11-12 23:38:14 -08002642 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002643
Bruce Allanc58c8a72012-03-20 03:48:19 +00002644 if (!adapter->msix_entries ||
2645 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2646 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002647
Bruce Allanc58c8a72012-03-20 03:48:19 +00002648 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649
Alexander Duyck12d04a32009-03-25 22:05:03 +00002650 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002651 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002652
Bruce Allanc58c8a72012-03-20 03:48:19 +00002653 /* If weight not fully consumed, exit the polling mode */
2654 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 if (adapter->itr_setting & 3)
2656 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002657 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002658 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2659 if (adapter->msix_entries)
2660 ew32(IMS, adapter->rx_ring->ims_val);
2661 else
2662 e1000_irq_enable(adapter);
2663 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664 }
2665
2666 return work_done;
2667}
2668
Patrick McHardy80d5c362013-04-19 02:04:28 +00002669static int e1000_vlan_rx_add_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002670 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671{
2672 struct e1000_adapter *adapter = netdev_priv(netdev);
2673 struct e1000_hw *hw = &adapter->hw;
2674 u32 vfta, index;
2675
2676 /* don't update vlan cookie if already programmed */
2677 if ((adapter->hw.mng_cookie.status &
2678 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2679 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002680 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002681
Auke Kokbc7f75f2007-09-17 12:30:59 -07002682 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002683 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2684 index = (vid >> 5) & 0x7F;
2685 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2686 vfta |= (1 << (vid & 0x1F));
2687 hw->mac.ops.write_vfta(hw, index, vfta);
2688 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002689
2690 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002691
2692 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002693}
2694
Patrick McHardy80d5c362013-04-19 02:04:28 +00002695static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002696 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697{
2698 struct e1000_adapter *adapter = netdev_priv(netdev);
2699 struct e1000_hw *hw = &adapter->hw;
2700 u32 vfta, index;
2701
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 if ((adapter->hw.mng_cookie.status &
2703 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2704 (vid == adapter->mng_vlan_id)) {
2705 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002706 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002707 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708 }
2709
2710 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002711 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2712 index = (vid >> 5) & 0x7F;
2713 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2714 vfta &= ~(1 << (vid & 0x1F));
2715 hw->mac.ops.write_vfta(hw, index, vfta);
2716 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002717
2718 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002719
2720 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002721}
2722
2723/**
2724 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2725 * @adapter: board private structure to initialize
2726 **/
2727static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2728{
2729 struct net_device *netdev = adapter->netdev;
2730 struct e1000_hw *hw = &adapter->hw;
2731 u32 rctl;
2732
2733 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2734 /* disable VLAN receive filtering */
2735 rctl = er32(RCTL);
2736 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2737 ew32(RCTL, rctl);
2738
2739 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002740 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2741 adapter->mng_vlan_id);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002742 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2743 }
2744 }
2745}
2746
2747/**
2748 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2749 * @adapter: board private structure to initialize
2750 **/
2751static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2752{
2753 struct e1000_hw *hw = &adapter->hw;
2754 u32 rctl;
2755
2756 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2757 /* enable VLAN receive filtering */
2758 rctl = er32(RCTL);
2759 rctl |= E1000_RCTL_VFE;
2760 rctl &= ~E1000_RCTL_CFIEN;
2761 ew32(RCTL, rctl);
2762 }
2763}
2764
2765/**
2766 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2767 * @adapter: board private structure to initialize
2768 **/
2769static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2770{
2771 struct e1000_hw *hw = &adapter->hw;
2772 u32 ctrl;
2773
2774 /* disable VLAN tag insert/strip */
2775 ctrl = er32(CTRL);
2776 ctrl &= ~E1000_CTRL_VME;
2777 ew32(CTRL, ctrl);
2778}
2779
2780/**
2781 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2782 * @adapter: board private structure to initialize
2783 **/
2784static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2785{
2786 struct e1000_hw *hw = &adapter->hw;
2787 u32 ctrl;
2788
2789 /* enable VLAN tag insert/strip */
2790 ctrl = er32(CTRL);
2791 ctrl |= E1000_CTRL_VME;
2792 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793}
2794
2795static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2796{
2797 struct net_device *netdev = adapter->netdev;
2798 u16 vid = adapter->hw.mng_cookie.vlan_id;
2799 u16 old_vid = adapter->mng_vlan_id;
2800
Bruce Allane5fe2542013-02-20 04:06:27 +00002801 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002802 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803 adapter->mng_vlan_id = vid;
2804 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002806 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
Patrick McHardy80d5c362013-04-19 02:04:28 +00002807 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002808}
2809
2810static void e1000_restore_vlan(struct e1000_adapter *adapter)
2811{
2812 u16 vid;
2813
Patrick McHardy80d5c362013-04-19 02:04:28 +00002814 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002816 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00002817 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818}
2819
Bruce Allancd791612010-05-10 14:59:51 +00002820static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821{
2822 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002823 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824
2825 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2826 return;
2827
2828 manc = er32(MANC);
2829
Bruce Allane921eb12012-11-28 09:28:37 +00002830 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002832 * the packets will be handled on SMBUS
2833 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834 manc |= E1000_MANC_EN_MNG2HOST;
2835 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002836
2837 switch (hw->mac.type) {
2838 default:
2839 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2840 break;
2841 case e1000_82574:
2842 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002843 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002844 * if so, enable it.
2845 */
2846 for (i = 0, j = 0; i < 8; i++) {
2847 mdef = er32(MDEF(i));
2848
2849 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002850 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002851 continue;
2852
2853 /* Enable this decision filter in MANC2H */
2854 if (mdef)
2855 manc2h |= (1 << i);
2856
2857 j |= mdef;
2858 }
2859
2860 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2861 break;
2862
2863 /* Create new decision filter in an empty filter */
2864 for (i = 0, j = 0; i < 8; i++)
2865 if (er32(MDEF(i)) == 0) {
2866 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2867 E1000_MDEF_PORT_664));
2868 manc2h |= (1 << 1);
2869 j++;
2870 break;
2871 }
2872
2873 if (!j)
2874 e_warn("Unable to create IPMI pass-through filter\n");
2875 break;
2876 }
2877
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878 ew32(MANC2H, manc2h);
2879 ew32(MANC, manc);
2880}
2881
2882/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002883 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002884 * @adapter: board private structure
2885 *
2886 * Configure the Tx unit of the MAC after a reset.
2887 **/
2888static void e1000_configure_tx(struct e1000_adapter *adapter)
2889{
2890 struct e1000_hw *hw = &adapter->hw;
2891 struct e1000_ring *tx_ring = adapter->tx_ring;
2892 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002893 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894
2895 /* Setup the HW Tx Head and Tail descriptor pointers */
2896 tdba = tx_ring->dma;
2897 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002898 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2899 ew32(TDBAH(0), (tdba >> 32));
2900 ew32(TDLEN(0), tdlen);
2901 ew32(TDH(0), 0);
2902 ew32(TDT(0), 0);
2903 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2904 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 /* Set the Tx Interrupt Delay register */
2907 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002908 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909 ew32(TADV, adapter->tx_abs_int_delay);
2910
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002911 if (adapter->flags2 & FLAG2_DMA_BURST) {
2912 u32 txdctl = er32(TXDCTL(0));
2913 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2914 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002915 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002916 * hardware to use the bus more efficiently in bursts, depends
2917 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002918 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002919 * hthresh = 1 ==> prefetch when one or more available
2920 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2921 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002922 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002923 */
2924 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2925 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002926 }
Bruce Allan56032be2011-12-16 00:46:01 +00002927 /* erratum work around: set txdctl the same for both queues */
2928 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002929
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002931 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002932 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002933 * gigabit link later
2934 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935#define SPEED_MODE_BIT (1 << 21)
2936 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002937 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 }
2939
2940 /* errata: program both queues to unweighted RR */
2941 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002942 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002944 ew32(TARC(0), tarc);
2945 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002947 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 }
2949
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 /* Setup Transmit Descriptor Settings for eop descriptor */
2951 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2952
2953 /* only set IDE if we are delaying interrupts using the timers */
2954 if (adapter->tx_int_delay)
2955 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2956
2957 /* enable Report Status bit */
2958 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2959
Bruce Allan57cde762012-02-22 09:02:58 +00002960 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961}
2962
2963/**
2964 * e1000_setup_rctl - configure the receive control registers
2965 * @adapter: Board private structure
2966 **/
2967#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2968 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2969static void e1000_setup_rctl(struct e1000_adapter *adapter)
2970{
2971 struct e1000_hw *hw = &adapter->hw;
2972 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002973 u32 pages = 0;
2974
Bruce Allan2fbe4522012-04-19 03:21:47 +00002975 /* Workaround Si errata on PCHx - configure jumbo frame flow */
Bruce Allanda1e20462013-06-21 09:07:02 +00002976 if ((hw->mac.type >= e1000_pch2lan) &&
2977 (adapter->netdev->mtu > ETH_DATA_LEN) &&
2978 e1000_lv_jumbo_workaround_ich8lan(hw, true))
2979 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002980
Auke Kokbc7f75f2007-09-17 12:30:59 -07002981 /* Program MC offset vector base */
2982 rctl = er32(RCTL);
2983 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2984 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002985 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2986 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987
2988 /* Do not Store bad packets */
2989 rctl &= ~E1000_RCTL_SBP;
2990
2991 /* Enable Long Packet receive */
2992 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2993 rctl &= ~E1000_RCTL_LPE;
2994 else
2995 rctl |= E1000_RCTL_LPE;
2996
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002997 /* Some systems expect that the CRC is included in SMBUS traffic. The
2998 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2999 * host memory when this is enabled
3000 */
3001 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3002 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003003
Bruce Allana4f58f52009-06-02 11:29:18 +00003004 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3005 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3006 u16 phy_data;
3007
3008 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3009 phy_data &= 0xfff8;
3010 phy_data |= (1 << 2);
3011 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3012
3013 e1e_rphy(hw, 22, &phy_data);
3014 phy_data &= 0x0fff;
3015 phy_data |= (1 << 14);
3016 e1e_wphy(hw, 0x10, 0x2823);
3017 e1e_wphy(hw, 0x11, 0x0003);
3018 e1e_wphy(hw, 22, phy_data);
3019 }
3020
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021 /* Setup buffer sizes */
3022 rctl &= ~E1000_RCTL_SZ_4096;
3023 rctl |= E1000_RCTL_BSEX;
3024 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025 case 2048:
3026 default:
3027 rctl |= E1000_RCTL_SZ_2048;
3028 rctl &= ~E1000_RCTL_BSEX;
3029 break;
3030 case 4096:
3031 rctl |= E1000_RCTL_SZ_4096;
3032 break;
3033 case 8192:
3034 rctl |= E1000_RCTL_SZ_8192;
3035 break;
3036 case 16384:
3037 rctl |= E1000_RCTL_SZ_16384;
3038 break;
3039 }
3040
Bruce Allan5f450212011-07-22 06:21:46 +00003041 /* Enable Extended Status in all Receive Descriptors */
3042 rfctl = er32(RFCTL);
3043 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003044 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003045
Bruce Allane921eb12012-11-28 09:28:37 +00003046 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 * header is placed in skb->data and the packet data is
3048 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3049 * In the case of a non-split, skb->data is linearly filled,
3050 * followed by the page buffers. Therefore, skb->data is
3051 * sized to hold the largest protocol header.
3052 *
3053 * allocations using alloc_page take too long for regular MTU
3054 * so only enable packet split for jumbo frames
3055 *
3056 * Using pages when the page size is greater than 16k wastes
3057 * a lot of memory, since we allocate 3 pages at all times
3058 * per packet.
3059 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003061 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003062 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003063 else
3064 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065
3066 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003067 u32 psrctl = 0;
3068
Auke Kok140a7482007-10-25 13:57:58 -07003069 /* Enable Packet split descriptors */
3070 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003071
Bruce Allane5fe2542013-02-20 04:06:27 +00003072 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073
3074 switch (adapter->rx_ps_pages) {
3075 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003076 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3077 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003079 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3080 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003082 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 break;
3084 }
3085
3086 ew32(PSRCTL, psrctl);
3087 }
3088
Ben Greearcf955e62012-02-11 15:39:51 +00003089 /* This is useful for sniffing bad packets. */
3090 if (adapter->netdev->features & NETIF_F_RXALL) {
3091 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003092 * in e1000e_set_rx_mode
3093 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003094 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3095 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3096 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
Ben Greearcf955e62012-02-11 15:39:51 +00003097
Bruce Allane80bd1d2013-05-01 01:19:46 +00003098 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3099 E1000_RCTL_DPF | /* Allow filtered pause */
3100 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
Ben Greearcf955e62012-02-11 15:39:51 +00003101 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3102 * and that breaks VLANs.
3103 */
3104 }
3105
Auke Kokbc7f75f2007-09-17 12:30:59 -07003106 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003107 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003108 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109}
3110
3111/**
3112 * e1000_configure_rx - Configure Receive Unit after Reset
3113 * @adapter: board private structure
3114 *
3115 * Configure the Rx unit of the MAC after a reset.
3116 **/
3117static void e1000_configure_rx(struct e1000_adapter *adapter)
3118{
3119 struct e1000_hw *hw = &adapter->hw;
3120 struct e1000_ring *rx_ring = adapter->rx_ring;
3121 u64 rdba;
3122 u32 rdlen, rctl, rxcsum, ctrl_ext;
3123
3124 if (adapter->rx_ps_pages) {
3125 /* this is a 32 byte descriptor */
3126 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003127 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 adapter->clean_rx = e1000_clean_rx_irq_ps;
3129 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003130 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003131 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003132 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3133 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003134 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003135 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003136 adapter->clean_rx = e1000_clean_rx_irq;
3137 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3138 }
3139
3140 /* disable receives while setting up the descriptors */
3141 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003142 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3143 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003145 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003147 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003148 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003149 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003150 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003151 * granularity = 01
3152 * wthresh = 04,
3153 * hthresh = 04,
3154 * pthresh = 0x20
3155 */
3156 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3157 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3158
Bruce Allane921eb12012-11-28 09:28:37 +00003159 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003160 * the value was not set by the user via module options
3161 */
3162 if (adapter->rx_int_delay == DEFAULT_RDTR)
3163 adapter->rx_int_delay = BURST_RDTR;
3164 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3165 adapter->rx_abs_int_delay = BURST_RADV;
3166 }
3167
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 /* set the Receive Delay Timer Register */
3169 ew32(RDTR, adapter->rx_int_delay);
3170
3171 /* irq moderation */
3172 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003173 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003174 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003175
3176 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003177 /* Auto-Mask interrupts upon ICR access */
3178 ctrl_ext |= E1000_CTRL_EXT_IAME;
3179 ew32(IAM, 0xffffffff);
3180 ew32(CTRL_EXT, ctrl_ext);
3181 e1e_flush();
3182
Bruce Allane921eb12012-11-28 09:28:37 +00003183 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003184 * the Base and Length of the Rx Descriptor Ring
3185 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003186 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003187 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3188 ew32(RDBAH(0), (rdba >> 32));
3189 ew32(RDLEN(0), rdlen);
3190 ew32(RDH(0), 0);
3191 ew32(RDT(0), 0);
3192 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3193 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003194
3195 /* Enable Receive Checksum Offload for TCP and UDP */
3196 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003197 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003199 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003200 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 ew32(RXCSUM, rxcsum);
3202
Bruce Allan3e35d992013-01-12 07:25:22 +00003203 /* With jumbo frames, excessive C-state transition latencies result
3204 * in dropped transactions.
3205 */
3206 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3207 u32 lat =
3208 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3209 adapter->max_frame_size) * 8 / 1000;
3210
3211 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003212 u32 rxdctl = er32(RXDCTL(0));
3213 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003214 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003215
3216 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3217 } else {
3218 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3219 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003220 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221
3222 /* Enable Receives */
3223 ew32(RCTL, rctl);
3224}
3225
3226/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003227 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 * @netdev: network interface device structure
3229 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003230 * Writes multicast address list to the MTA hash table.
3231 * Returns: -ENOMEM on failure
3232 * 0 on no addresses written
3233 * X on writing X addresses to MTA
3234 */
3235static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236{
3237 struct e1000_adapter *adapter = netdev_priv(netdev);
3238 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003239 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003240 u8 *mta_list;
3241 int i;
3242
3243 if (netdev_mc_empty(netdev)) {
3244 /* nothing to program, so clear mc list */
3245 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3246 return 0;
3247 }
3248
3249 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3250 if (!mta_list)
3251 return -ENOMEM;
3252
3253 /* update_mc_addr_list expects a packed array of only addresses. */
3254 i = 0;
3255 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003256 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003257
3258 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3259 kfree(mta_list);
3260
3261 return netdev_mc_count(netdev);
3262}
3263
3264/**
3265 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3266 * @netdev: network interface device structure
3267 *
3268 * Writes unicast address list to the RAR table.
3269 * Returns: -ENOMEM on failure/insufficient address space
3270 * 0 on no addresses written
3271 * X on writing X addresses to the RAR table
3272 **/
3273static int e1000e_write_uc_addr_list(struct net_device *netdev)
3274{
3275 struct e1000_adapter *adapter = netdev_priv(netdev);
3276 struct e1000_hw *hw = &adapter->hw;
3277 unsigned int rar_entries = hw->mac.rar_entry_count;
3278 int count = 0;
3279
3280 /* save a rar entry for our hardware address */
3281 rar_entries--;
3282
3283 /* save a rar entry for the LAA workaround */
3284 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3285 rar_entries--;
3286
3287 /* return ENOMEM indicating insufficient memory for addresses */
3288 if (netdev_uc_count(netdev) > rar_entries)
3289 return -ENOMEM;
3290
3291 if (!netdev_uc_empty(netdev) && rar_entries) {
3292 struct netdev_hw_addr *ha;
3293
Bruce Allane921eb12012-11-28 09:28:37 +00003294 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003295 * combining
3296 */
3297 netdev_for_each_uc_addr(ha, netdev) {
3298 if (!rar_entries)
3299 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003300 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003301 count++;
3302 }
3303 }
3304
3305 /* zero out the remaining RAR entries not used above */
3306 for (; rar_entries > 0; rar_entries--) {
3307 ew32(RAH(rar_entries), 0);
3308 ew32(RAL(rar_entries), 0);
3309 }
3310 e1e_flush();
3311
3312 return count;
3313}
3314
3315/**
3316 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3317 * @netdev: network interface device structure
3318 *
3319 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3320 * address list or the network interface flags are updated. This routine is
3321 * responsible for configuring the hardware for proper unicast, multicast,
3322 * promiscuous mode, and all-multi behavior.
3323 **/
3324static void e1000e_set_rx_mode(struct net_device *netdev)
3325{
3326 struct e1000_adapter *adapter = netdev_priv(netdev);
3327 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329
David Ertman63eb48f2014-02-14 07:16:46 +00003330 if (pm_runtime_suspended(netdev->dev.parent))
3331 return;
3332
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334 rctl = er32(RCTL);
3335
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003336 /* clear the affected bits */
3337 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3338
Auke Kokbc7f75f2007-09-17 12:30:59 -07003339 if (netdev->flags & IFF_PROMISC) {
3340 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003341 /* Do not hardware filter VLANs in promisc mode */
3342 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003343 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003344 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003345
Patrick McHardy746b9f02008-07-16 20:15:45 -07003346 if (netdev->flags & IFF_ALLMULTI) {
3347 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003348 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003349 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003350 * then we should just turn on promiscuous mode so
3351 * that we can at least receive multicast traffic
3352 */
3353 count = e1000e_write_mc_addr_list(netdev);
3354 if (count < 0)
3355 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003356 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003357 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003358 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003359 * sufficient space to store all the addresses then enable
3360 * unicast promiscuous mode
3361 */
3362 count = e1000e_write_uc_addr_list(netdev);
3363 if (count < 0)
3364 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 }
3366
3367 ew32(RCTL, rctl);
3368
Patrick McHardyf6469682013-04-19 02:04:27 +00003369 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003370 e1000e_vlan_strip_enable(adapter);
3371 else
3372 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373}
3374
Bruce Allan70495a52012-01-11 01:26:50 +00003375static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3376{
3377 struct e1000_hw *hw = &adapter->hw;
3378 u32 mrqc, rxcsum;
3379 int i;
3380 static const u32 rsskey[10] = {
3381 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3382 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3383 };
3384
3385 /* Fill out hash function seed */
3386 for (i = 0; i < 10; i++)
3387 ew32(RSSRK(i), rsskey[i]);
3388
3389 /* Direct all traffic to queue 0 */
3390 for (i = 0; i < 32; i++)
3391 ew32(RETA(i), 0);
3392
Bruce Allane921eb12012-11-28 09:28:37 +00003393 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003394 * descriptor on writeback.
3395 */
3396 rxcsum = er32(RXCSUM);
3397 rxcsum |= E1000_RXCSUM_PCSD;
3398
3399 ew32(RXCSUM, rxcsum);
3400
3401 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3402 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3403 E1000_MRQC_RSS_FIELD_IPV6 |
3404 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3405 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3406
3407 ew32(MRQC, mrqc);
3408}
3409
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003411 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3412 * @adapter: board private structure
3413 * @timinca: pointer to returned time increment attributes
3414 *
3415 * Get attributes for incrementing the System Time Register SYSTIML/H at
3416 * the default base frequency, and set the cyclecounter shift value.
3417 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003418s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003419{
3420 struct e1000_hw *hw = &adapter->hw;
3421 u32 incvalue, incperiod, shift;
3422
3423 /* Make sure clock is enabled on I217 before checking the frequency */
3424 if ((hw->mac.type == e1000_pch_lpt) &&
3425 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3426 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3427 u32 fextnvm7 = er32(FEXTNVM7);
3428
3429 if (!(fextnvm7 & (1 << 0))) {
3430 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3431 e1e_flush();
3432 }
3433 }
3434
3435 switch (hw->mac.type) {
3436 case e1000_pch2lan:
3437 case e1000_pch_lpt:
3438 /* On I217, the clock frequency is 25MHz or 96MHz as
3439 * indicated by the System Clock Frequency Indication
3440 */
3441 if ((hw->mac.type != e1000_pch_lpt) ||
3442 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3443 /* Stable 96MHz frequency */
3444 incperiod = INCPERIOD_96MHz;
3445 incvalue = INCVALUE_96MHz;
3446 shift = INCVALUE_SHIFT_96MHz;
3447 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3448 break;
3449 }
3450 /* fall-through */
3451 case e1000_82574:
3452 case e1000_82583:
3453 /* Stable 25MHz frequency */
3454 incperiod = INCPERIOD_25MHz;
3455 incvalue = INCVALUE_25MHz;
3456 shift = INCVALUE_SHIFT_25MHz;
3457 adapter->cc.shift = shift;
3458 break;
3459 default:
3460 return -EINVAL;
3461 }
3462
3463 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3464 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3465
3466 return 0;
3467}
3468
3469/**
3470 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3471 * @adapter: board private structure
3472 *
3473 * Outgoing time stamping can be enabled and disabled. Play nice and
3474 * disable it when requested, although it shouldn't cause any overhead
3475 * when no packet needs it. At most one packet in the queue may be
3476 * marked for time stamping, otherwise it would be impossible to tell
3477 * for sure to which packet the hardware time stamp belongs.
3478 *
3479 * Incoming time stamping has to be configured via the hardware filters.
3480 * Not all combinations are supported, in particular event type has to be
3481 * specified. Matching the kind of event packet is not supported, with the
3482 * exception of "all V2 events regardless of level 2 or 4".
3483 **/
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003484static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3485 struct hwtstamp_config *config)
Bruce Allanb67e1912012-12-27 08:32:33 +00003486{
3487 struct e1000_hw *hw = &adapter->hw;
Bruce Allanb67e1912012-12-27 08:32:33 +00003488 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3489 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003490 u32 rxmtrl = 0;
3491 u16 rxudp = 0;
3492 bool is_l4 = false;
3493 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003494 u32 regval;
3495 s32 ret_val;
3496
3497 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3498 return -EINVAL;
3499
3500 /* flags reserved for future extensions - must be zero */
3501 if (config->flags)
3502 return -EINVAL;
3503
3504 switch (config->tx_type) {
3505 case HWTSTAMP_TX_OFF:
3506 tsync_tx_ctl = 0;
3507 break;
3508 case HWTSTAMP_TX_ON:
3509 break;
3510 default:
3511 return -ERANGE;
3512 }
3513
3514 switch (config->rx_filter) {
3515 case HWTSTAMP_FILTER_NONE:
3516 tsync_rx_ctl = 0;
3517 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003518 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3519 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3520 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3521 is_l4 = true;
3522 break;
3523 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3524 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3525 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3526 is_l4 = true;
3527 break;
3528 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3529 /* Also time stamps V2 L2 Path Delay Request/Response */
3530 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3531 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3532 is_l2 = true;
3533 break;
3534 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3535 /* Also time stamps V2 L2 Path Delay Request/Response. */
3536 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3537 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3538 is_l2 = true;
3539 break;
3540 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3541 /* Hardware cannot filter just V2 L4 Sync messages;
3542 * fall-through to V2 (both L2 and L4) Sync.
3543 */
3544 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3545 /* Also time stamps V2 Path Delay Request/Response. */
3546 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3547 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3548 is_l2 = true;
3549 is_l4 = true;
3550 break;
3551 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3552 /* Hardware cannot filter just V2 L4 Delay Request messages;
3553 * fall-through to V2 (both L2 and L4) Delay Request.
3554 */
3555 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3556 /* Also time stamps V2 Path Delay Request/Response. */
3557 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3558 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3559 is_l2 = true;
3560 is_l4 = true;
3561 break;
3562 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3563 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3564 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3565 * fall-through to all V2 (both L2 and L4) Events.
3566 */
3567 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3568 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3569 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3570 is_l2 = true;
3571 is_l4 = true;
3572 break;
3573 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3574 /* For V1, the hardware can only filter Sync messages or
3575 * Delay Request messages but not both so fall-through to
3576 * time stamp all packets.
3577 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003578 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003579 is_l2 = true;
3580 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003581 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3582 config->rx_filter = HWTSTAMP_FILTER_ALL;
3583 break;
3584 default:
3585 return -ERANGE;
3586 }
3587
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003588 adapter->hwtstamp_config = *config;
3589
Bruce Allanb67e1912012-12-27 08:32:33 +00003590 /* enable/disable Tx h/w time stamping */
3591 regval = er32(TSYNCTXCTL);
3592 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3593 regval |= tsync_tx_ctl;
3594 ew32(TSYNCTXCTL, regval);
3595 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3596 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3597 e_err("Timesync Tx Control register not set as expected\n");
3598 return -EAGAIN;
3599 }
3600
3601 /* enable/disable Rx h/w time stamping */
3602 regval = er32(TSYNCRXCTL);
3603 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3604 regval |= tsync_rx_ctl;
3605 ew32(TSYNCRXCTL, regval);
3606 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3607 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3608 (regval & (E1000_TSYNCRXCTL_ENABLED |
3609 E1000_TSYNCRXCTL_TYPE_MASK))) {
3610 e_err("Timesync Rx Control register not set as expected\n");
3611 return -EAGAIN;
3612 }
3613
Bruce Alland89777b2013-01-19 01:09:58 +00003614 /* L2: define ethertype filter for time stamped packets */
3615 if (is_l2)
3616 rxmtrl |= ETH_P_1588;
3617
3618 /* define which PTP packets get time stamped */
3619 ew32(RXMTRL, rxmtrl);
3620
3621 /* Filter by destination port */
3622 if (is_l4) {
3623 rxudp = PTP_EV_PORT;
3624 cpu_to_be16s(&rxudp);
3625 }
3626 ew32(RXUDP, rxudp);
3627
3628 e1e_flush();
3629
Bruce Allanb67e1912012-12-27 08:32:33 +00003630 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003631 er32(RXSTMPH);
3632 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003633
3634 /* Get and set the System Time Register SYSTIM base frequency */
3635 ret_val = e1000e_get_base_timinca(adapter, &regval);
3636 if (ret_val)
3637 return ret_val;
3638 ew32(TIMINCA, regval);
3639
3640 /* reset the ns time counter */
3641 timecounter_init(&adapter->tc, &adapter->cc,
3642 ktime_to_ns(ktime_get_real()));
3643
3644 return 0;
3645}
3646
3647/**
Bruce Allanad680762008-03-28 09:15:03 -07003648 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649 * @adapter: private board structure
3650 **/
3651static void e1000_configure(struct e1000_adapter *adapter)
3652{
Bruce Allan55aa6982011-12-16 00:45:45 +00003653 struct e1000_ring *rx_ring = adapter->rx_ring;
3654
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003655 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656
3657 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003658 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003659
3660 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003661
3662 if (adapter->netdev->features & NETIF_F_RXHASH)
3663 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664 e1000_setup_rctl(adapter);
3665 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003666 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003667}
3668
3669/**
3670 * e1000e_power_up_phy - restore link in case the phy was powered down
3671 * @adapter: address of board private structure
3672 *
3673 * The phy may be powered down to save power and turn off link when the
3674 * driver is unloaded and wake on lan is not enabled (among others)
3675 * *** this routine MUST be followed by a call to e1000e_reset ***
3676 **/
3677void e1000e_power_up_phy(struct e1000_adapter *adapter)
3678{
Bruce Allan17f208d2009-12-01 15:47:22 +00003679 if (adapter->hw.phy.ops.power_up)
3680 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681
3682 adapter->hw.mac.ops.setup_link(&adapter->hw);
3683}
3684
3685/**
3686 * e1000_power_down_phy - Power down the PHY
3687 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003688 * Power down the PHY so no link is implied when interface is down.
3689 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690 */
3691static void e1000_power_down_phy(struct e1000_adapter *adapter)
3692{
Bruce Allan17f208d2009-12-01 15:47:22 +00003693 if (adapter->hw.phy.ops.power_down)
3694 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695}
3696
3697/**
3698 * e1000e_reset - bring the hardware into a known good state
3699 *
3700 * This function boots the hardware and enables some settings that
3701 * require a configuration cycle of the hardware - those cannot be
3702 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003703 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003704 */
3705void e1000e_reset(struct e1000_adapter *adapter)
3706{
3707 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003708 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709 struct e1000_hw *hw = &adapter->hw;
3710 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003711 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712 u16 hwm;
3713
Bruce Allanad680762008-03-28 09:15:03 -07003714 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003715 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003716
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003717 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003718 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719 * large enough to accommodate two full transmit packets,
3720 * rounded up to the next 1KB and expressed in KB. Likewise,
3721 * the Rx FIFO should be large enough to accommodate at least
3722 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003723 * expressed in KB.
3724 */
Auke Kokdf762462007-10-25 13:57:53 -07003725 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003727 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003729 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003730 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003731 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003732 */
3733 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00003734 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003735 min_tx_space = ALIGN(min_tx_space, 1024);
3736 min_tx_space >>= 10;
3737 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003738 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 min_rx_space = ALIGN(min_rx_space, 1024);
3740 min_rx_space >>= 10;
3741
Bruce Allane921eb12012-11-28 09:28:37 +00003742 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003744 * allocation, take space away from current Rx allocation
3745 */
Auke Kokdf762462007-10-25 13:57:53 -07003746 if ((tx_space < min_tx_space) &&
3747 ((min_tx_space - tx_space) < pba)) {
3748 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003749
Bruce Allane921eb12012-11-28 09:28:37 +00003750 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003751 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003752 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003753 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003754 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 }
Auke Kokdf762462007-10-25 13:57:53 -07003756
3757 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003758 }
3759
Bruce Allane921eb12012-11-28 09:28:37 +00003760 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003761 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003762 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 * (or the size used for early receive) above it in the Rx FIFO.
3764 * Set it to the lower of:
3765 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003766 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003767 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003768 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3769 fc->pause_time = 0xFFFF;
3770 else
3771 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003772 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003773 fc->current_mode = fc->requested_mode;
3774
3775 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003776 case e1000_ich9lan:
3777 case e1000_ich10lan:
3778 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3779 pba = 14;
3780 ew32(PBA, pba);
3781 fc->high_water = 0x2800;
3782 fc->low_water = fc->high_water - 8;
3783 break;
3784 }
3785 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003786 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003787 hwm = min(((pba << 10) * 9 / 10),
3788 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003789
Bruce Allane80bd1d2013-05-01 01:19:46 +00003790 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
Bruce Alland3738bb2010-06-16 13:27:28 +00003791 fc->low_water = fc->high_water - 8;
3792 break;
3793 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003794 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003795 * loads. If hangs persist, try disabling Tx flow control.
3796 */
3797 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3798 fc->high_water = 0x3500;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003799 fc->low_water = 0x1500;
Bruce Allan38eb3942009-11-19 12:34:20 +00003800 } else {
3801 fc->high_water = 0x5000;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003802 fc->low_water = 0x3000;
Bruce Allan38eb3942009-11-19 12:34:20 +00003803 }
Bruce Allana3055952010-05-10 15:02:12 +00003804 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003805 break;
3806 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003807 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003808 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003809
3810 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3811 fc->high_water = 0x05C20;
3812 fc->low_water = 0x05048;
3813 fc->pause_time = 0x0650;
3814 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003815 }
Bruce Allan347b5202012-12-08 00:35:35 +00003816
Bruce Allance345e02013-06-21 09:07:07 +00003817 pba = 14;
3818 ew32(PBA, pba);
Bruce Allan347b5202012-12-08 00:35:35 +00003819 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3820 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003821 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003822 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003823
Bruce Allane921eb12012-11-28 09:28:37 +00003824 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003825 * maximum size per Tx descriptor limited only to the transmit
3826 * allocation of the packet buffer minus 96 bytes with an upper
3827 * limit of 24KB due to receive synchronization limitations.
3828 */
3829 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3830 24 << 10);
3831
Bruce Allane921eb12012-11-28 09:28:37 +00003832 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003833 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003834 */
3835 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003836 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003837 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3838 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003839 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003840 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003841 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003842 }
3843 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3844 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003845 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003846 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3847 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003848 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003849 }
3850 }
3851
Auke Kokbc7f75f2007-09-17 12:30:59 -07003852 /* Allow time for pending master requests to run */
3853 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003854
Bruce Allane921eb12012-11-28 09:28:37 +00003855 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003856 * that the network interface is in control
3857 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003858 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003859 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003860
Auke Kokbc7f75f2007-09-17 12:30:59 -07003861 ew32(WUC, 0);
3862
3863 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003864 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003865
3866 e1000_update_mng_vlan(adapter);
3867
3868 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3869 ew32(VET, ETH_P_8021Q);
3870
3871 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003872
Bruce Allanb67e1912012-12-27 08:32:33 +00003873 /* initialize systim and reset the ns time counter */
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003874 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
Bruce Allanb67e1912012-12-27 08:32:33 +00003875
Bruce Alland495bcb2013-03-20 07:23:11 +00003876 /* Set EEE advertisement as appropriate */
3877 if (adapter->flags2 & FLAG2_HAS_EEE) {
3878 s32 ret_val;
3879 u16 adv_addr;
3880
3881 switch (hw->phy.type) {
3882 case e1000_phy_82579:
3883 adv_addr = I82579_EEE_ADVERTISEMENT;
3884 break;
3885 case e1000_phy_i217:
3886 adv_addr = I217_EEE_ADVERTISEMENT;
3887 break;
3888 default:
3889 dev_err(&adapter->pdev->dev,
3890 "Invalid PHY type setting EEE advertisement\n");
3891 return;
3892 }
3893
3894 ret_val = hw->phy.ops.acquire(hw);
3895 if (ret_val) {
3896 dev_err(&adapter->pdev->dev,
3897 "EEE advertisement - unable to acquire PHY\n");
3898 return;
3899 }
3900
3901 e1000_write_emi_reg_locked(hw, adv_addr,
3902 hw->dev_spec.ich8lan.eee_disable ?
3903 0 : adapter->eee_advert);
3904
3905 hw->phy.ops.release(hw);
3906 }
3907
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003908 if (!netif_running(adapter->netdev) &&
David Ertman28002092014-02-14 07:16:41 +00003909 !test_bit(__E1000_TESTING, &adapter->state))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003910 e1000_power_down_phy(adapter);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003911
Auke Kokbc7f75f2007-09-17 12:30:59 -07003912 e1000_get_phy_info(hw);
3913
Bruce Allan918d7192009-06-02 11:28:20 +00003914 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3915 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003917 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003919 * different we would do if it failed
3920 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3922 phy_data &= ~IGP02E1000_PM_SPD;
3923 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3924 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925}
3926
3927int e1000e_up(struct e1000_adapter *adapter)
3928{
3929 struct e1000_hw *hw = &adapter->hw;
3930
3931 /* hardware has been reset, we need to reload some things */
3932 e1000_configure(adapter);
3933
3934 clear_bit(__E1000_DOWN, &adapter->state);
3935
Bruce Allan4662e822008-08-26 18:37:06 -07003936 if (adapter->msix_entries)
3937 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 e1000_irq_enable(adapter);
3939
Bruce Allan400484f2011-05-13 07:20:03 +00003940 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003941
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003943 if (adapter->msix_entries)
3944 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3945 else
3946 ew32(ICS, E1000_ICS_LSC);
3947
Auke Kokbc7f75f2007-09-17 12:30:59 -07003948 return 0;
3949}
3950
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003951static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3952{
3953 struct e1000_hw *hw = &adapter->hw;
3954
3955 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3956 return;
3957
3958 /* flush pending descriptor writebacks to memory */
3959 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3960 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3961
3962 /* execute the writes immediately */
3963 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003964
Bruce Allane921eb12012-11-28 09:28:37 +00003965 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003966 * write is successful
3967 */
3968 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3969 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3970
3971 /* execute the writes immediately */
3972 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003973}
3974
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003975static void e1000e_update_stats(struct e1000_adapter *adapter);
3976
David Ertman28002092014-02-14 07:16:41 +00003977/**
3978 * e1000e_down - quiesce the device and optionally reset the hardware
3979 * @adapter: board private structure
3980 * @reset: boolean flag to reset the hardware or not
3981 */
3982void e1000e_down(struct e1000_adapter *adapter, bool reset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983{
3984 struct net_device *netdev = adapter->netdev;
3985 struct e1000_hw *hw = &adapter->hw;
3986 u32 tctl, rctl;
3987
Bruce Allane921eb12012-11-28 09:28:37 +00003988 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003989 * reschedule our watchdog timer
3990 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991 set_bit(__E1000_DOWN, &adapter->state);
3992
3993 /* disable receives in the hardware */
3994 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003995 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3996 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003997 /* flush and sleep below */
3998
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003999 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004000
4001 /* disable transmits in the hardware */
4002 tctl = er32(TCTL);
4003 tctl &= ~E1000_TCTL_EN;
4004 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004005
Auke Kokbc7f75f2007-09-17 12:30:59 -07004006 /* flush both disables and wait for them to finish */
4007 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004008 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010 e1000_irq_disable(adapter);
4011
Bruce Allana3b87a42013-04-20 05:37:29 +00004012 napi_synchronize(&adapter->napi);
4013
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 del_timer_sync(&adapter->watchdog_timer);
4015 del_timer_sync(&adapter->phy_info_timer);
4016
Auke Kokbc7f75f2007-09-17 12:30:59 -07004017 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004018
4019 spin_lock(&adapter->stats64_lock);
4020 e1000e_update_stats(adapter);
4021 spin_unlock(&adapter->stats64_lock);
4022
Bruce Allan400484f2011-05-13 07:20:03 +00004023 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004024 e1000_clean_tx_ring(adapter->tx_ring);
4025 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004026
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027 adapter->link_speed = 0;
4028 adapter->link_duplex = 0;
4029
Bruce Allanda1e20462013-06-21 09:07:02 +00004030 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4031 if ((hw->mac.type >= e1000_pch2lan) &&
4032 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4033 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4034 e_dbg("failed to disable jumbo frame workaround mode\n");
4035
David Ertman28002092014-02-14 07:16:41 +00004036 if (reset && !pci_channel_offline(adapter->pdev))
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004037 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038}
4039
4040void e1000e_reinit_locked(struct e1000_adapter *adapter)
4041{
4042 might_sleep();
4043 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004044 usleep_range(1000, 2000);
David Ertman28002092014-02-14 07:16:41 +00004045 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004046 e1000e_up(adapter);
4047 clear_bit(__E1000_RESETTING, &adapter->state);
4048}
4049
4050/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004051 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4052 * @cc: cyclecounter structure
4053 **/
4054static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4055{
4056 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4057 cc);
4058 struct e1000_hw *hw = &adapter->hw;
4059 cycle_t systim;
4060
4061 /* latch SYSTIMH on read of SYSTIML */
4062 systim = (cycle_t)er32(SYSTIML);
4063 systim |= (cycle_t)er32(SYSTIMH) << 32;
4064
4065 return systim;
4066}
4067
4068/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004069 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4070 * @adapter: board private structure to initialize
4071 *
4072 * e1000_sw_init initializes the Adapter private data structure.
4073 * Fields are initialized based on PCI device information and
4074 * OS network device settings (MTU size).
4075 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004076static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004077{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078 struct net_device *netdev = adapter->netdev;
4079
4080 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4081 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004082 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4083 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004084 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4085 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004087 spin_lock_init(&adapter->stats64_lock);
4088
Bruce Allan4662e822008-08-26 18:37:06 -07004089 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090
Bruce Allan4662e822008-08-26 18:37:06 -07004091 if (e1000_alloc_queues(adapter))
4092 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004093
Bruce Allanb67e1912012-12-27 08:32:33 +00004094 /* Setup hardware time stamping cyclecounter */
4095 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4096 adapter->cc.read = e1000e_cyclecounter_read;
4097 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4098 adapter->cc.mult = 1;
4099 /* cc.shift set in e1000e_get_base_tininca() */
4100
4101 spin_lock_init(&adapter->systim_lock);
4102 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4103 }
4104
Auke Kokbc7f75f2007-09-17 12:30:59 -07004105 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106 e1000_irq_disable(adapter);
4107
Auke Kokbc7f75f2007-09-17 12:30:59 -07004108 set_bit(__E1000_DOWN, &adapter->state);
4109 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004110}
4111
4112/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004113 * e1000_intr_msi_test - Interrupt Handler
4114 * @irq: interrupt number
4115 * @data: pointer to a network interface device structure
4116 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004117static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004118{
4119 struct net_device *netdev = data;
4120 struct e1000_adapter *adapter = netdev_priv(netdev);
4121 struct e1000_hw *hw = &adapter->hw;
4122 u32 icr = er32(ICR);
4123
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004124 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004125 if (icr & E1000_ICR_RXSEQ) {
4126 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004127 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004128 * interrupt is handled.
4129 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004130 wmb();
4131 }
4132
4133 return IRQ_HANDLED;
4134}
4135
4136/**
4137 * e1000_test_msi_interrupt - Returns 0 for successful test
4138 * @adapter: board private struct
4139 *
4140 * code flow taken from tg3.c
4141 **/
4142static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4143{
4144 struct net_device *netdev = adapter->netdev;
4145 struct e1000_hw *hw = &adapter->hw;
4146 int err;
4147
4148 /* poll_enable hasn't been called yet, so don't need disable */
4149 /* clear any pending events */
4150 er32(ICR);
4151
4152 /* free the real vector and request a test handler */
4153 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004154 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004155
4156 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004157 * MSI irq handler will unset this flag
4158 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004159 adapter->flags |= FLAG_MSI_TEST_FAILED;
4160
4161 err = pci_enable_msi(adapter->pdev);
4162 if (err)
4163 goto msi_test_failed;
4164
Joe Perchesa0607fd2009-11-18 23:29:17 -08004165 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004166 netdev->name, netdev);
4167 if (err) {
4168 pci_disable_msi(adapter->pdev);
4169 goto msi_test_failed;
4170 }
4171
Bruce Allane921eb12012-11-28 09:28:37 +00004172 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004173 * interrupt.
4174 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004175 wmb();
4176
4177 e1000_irq_enable(adapter);
4178
4179 /* fire an unusual interrupt on the test handler */
4180 ew32(ICS, E1000_ICS_RXSEQ);
4181 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004182 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004183
4184 e1000_irq_disable(adapter);
4185
Bruce Allanbc763292012-08-17 06:18:07 +00004186 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004187
4188 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004189 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004190 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004191 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004192 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004193 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004194
4195 free_irq(adapter->pdev->irq, netdev);
4196 pci_disable_msi(adapter->pdev);
4197
Bruce Allanf8d59f72008-08-08 18:36:11 -07004198msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004199 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004200 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004201}
4202
4203/**
4204 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4205 * @adapter: board private struct
4206 *
4207 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4208 **/
4209static int e1000_test_msi(struct e1000_adapter *adapter)
4210{
4211 int err;
4212 u16 pci_cmd;
4213
4214 if (!(adapter->flags & FLAG_MSI_ENABLED))
4215 return 0;
4216
4217 /* disable SERR in case the MSI write causes a master abort */
4218 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004219 if (pci_cmd & PCI_COMMAND_SERR)
4220 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4221 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004222
4223 err = e1000_test_msi_interrupt(adapter);
4224
Dean Nelson36f24072010-06-29 18:12:05 +00004225 /* re-enable SERR */
4226 if (pci_cmd & PCI_COMMAND_SERR) {
4227 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4228 pci_cmd |= PCI_COMMAND_SERR;
4229 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4230 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004231
Bruce Allanf8d59f72008-08-08 18:36:11 -07004232 return err;
4233}
4234
4235/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004236 * e1000_open - Called when a network interface is made active
4237 * @netdev: network interface device structure
4238 *
4239 * Returns 0 on success, negative value on failure
4240 *
4241 * The open entry point is called when a network interface is made
4242 * active by the system (IFF_UP). At this point all resources needed
4243 * for transmit and receive operations are allocated, the interrupt
4244 * handler is registered with the OS, the watchdog timer is started,
4245 * and the stack is notified that the interface is ready.
4246 **/
4247static int e1000_open(struct net_device *netdev)
4248{
4249 struct e1000_adapter *adapter = netdev_priv(netdev);
4250 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004251 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 int err;
4253
4254 /* disallow open during test */
4255 if (test_bit(__E1000_TESTING, &adapter->state))
4256 return -EBUSY;
4257
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004258 pm_runtime_get_sync(&pdev->dev);
4259
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004260 netif_carrier_off(netdev);
4261
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004263 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 if (err)
4265 goto err_setup_tx;
4266
4267 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004268 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004269 if (err)
4270 goto err_setup_rx;
4271
Bruce Allane921eb12012-11-28 09:28:37 +00004272 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004273 * interface is now open and reset the part to a known state.
4274 */
4275 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004276 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004277 e1000e_reset(adapter);
4278 }
4279
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 e1000e_power_up_phy(adapter);
4281
4282 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004283 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004284 e1000_update_mng_vlan(adapter);
4285
Bruce Allan79d4e902011-12-16 00:46:27 +00004286 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004287 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4288 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004289
Bruce Allane921eb12012-11-28 09:28:37 +00004290 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4292 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004293 * clean_rx handler before we do so.
4294 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295 e1000_configure(adapter);
4296
4297 err = e1000_request_irq(adapter);
4298 if (err)
4299 goto err_req_irq;
4300
Bruce Allane921eb12012-11-28 09:28:37 +00004301 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004302 * ignore e1000e MSI messages, which means we need to test our MSI
4303 * interrupt now
4304 */
Bruce Allan4662e822008-08-26 18:37:06 -07004305 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004306 err = e1000_test_msi(adapter);
4307 if (err) {
4308 e_err("Interrupt allocation failed\n");
4309 goto err_req_irq;
4310 }
4311 }
4312
Auke Kokbc7f75f2007-09-17 12:30:59 -07004313 /* From here on the code is the same as e1000e_up() */
4314 clear_bit(__E1000_DOWN, &adapter->state);
4315
4316 napi_enable(&adapter->napi);
4317
4318 e1000_irq_enable(adapter);
4319
Jeff Kirsher09357b02011-11-18 14:25:00 +00004320 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004321 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004322
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004323 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004324 pm_runtime_put(&pdev->dev);
4325
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004327 if (adapter->msix_entries)
4328 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4329 else
4330 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004331
4332 return 0;
4333
4334err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004335 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004337 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004339 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004340err_setup_tx:
4341 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004342 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004343
4344 return err;
4345}
4346
4347/**
4348 * e1000_close - Disables a network interface
4349 * @netdev: network interface device structure
4350 *
4351 * Returns 0, this is not allowed to fail
4352 *
4353 * The close entry point is called when an interface is de-activated
4354 * by the OS. The hardware is still under the drivers control, but
4355 * needs to be disabled. A global MAC reset is issued to stop the
4356 * hardware, and all transmit and receive resources are freed.
4357 **/
4358static int e1000_close(struct net_device *netdev)
4359{
4360 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004361 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004362 int count = E1000_CHECK_RESET_COUNT;
4363
4364 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4365 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366
4367 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004368
4369 pm_runtime_get_sync(&pdev->dev);
4370
4371 if (!test_bit(__E1000_DOWN, &adapter->state)) {
David Ertman28002092014-02-14 07:16:41 +00004372 e1000e_down(adapter, true);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004373 e1000_free_irq(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00004374
4375 /* Link status message must follow this format */
4376 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004377 }
Bruce Allana3b87a42013-04-20 05:37:29 +00004378
4379 napi_disable(&adapter->napi);
4380
Bruce Allan55aa6982011-12-16 00:45:45 +00004381 e1000e_free_tx_resources(adapter->tx_ring);
4382 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383
Bruce Allane921eb12012-11-28 09:28:37 +00004384 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004385 * the same ID is registered on the host OS (let 8021q kill it)
4386 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004387 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004388 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4389 adapter->mng_vlan_id);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004390
Bruce Allane921eb12012-11-28 09:28:37 +00004391 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004392 * interface is now closed
4393 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004394 if ((adapter->flags & FLAG_HAS_AMT) &&
4395 !test_bit(__E1000_TESTING, &adapter->state))
4396 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397
Bruce Allan3e35d992013-01-12 07:25:22 +00004398 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004399
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004400 pm_runtime_put_sync(&pdev->dev);
4401
Auke Kokbc7f75f2007-09-17 12:30:59 -07004402 return 0;
4403}
Bruce Allanfc830b72013-02-20 04:06:11 +00004404
Auke Kokbc7f75f2007-09-17 12:30:59 -07004405/**
4406 * e1000_set_mac - Change the Ethernet Address of the NIC
4407 * @netdev: network interface device structure
4408 * @p: pointer to an address structure
4409 *
4410 * Returns 0 on success, negative on failure
4411 **/
4412static int e1000_set_mac(struct net_device *netdev, void *p)
4413{
4414 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004415 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 struct sockaddr *addr = p;
4417
4418 if (!is_valid_ether_addr(addr->sa_data))
4419 return -EADDRNOTAVAIL;
4420
4421 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4422 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4423
Bruce Allan69e1e012012-04-14 03:28:50 +00004424 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004425
4426 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4427 /* activate the work around */
4428 e1000e_set_laa_state_82571(&adapter->hw, 1);
4429
Bruce Allane921eb12012-11-28 09:28:37 +00004430 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004431 * between the time RAR[0] gets clobbered and the time it
4432 * gets fixed (in e1000_watchdog), the actual LAA is in one
4433 * of the RARs and no incoming packets directed to this port
4434 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004435 * RAR[14]
4436 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004437 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4438 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439 }
4440
4441 return 0;
4442}
4443
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004444/**
4445 * e1000e_update_phy_task - work thread to update phy
4446 * @work: pointer to our work struct
4447 *
4448 * this worker thread exists because we must acquire a
4449 * semaphore to read the phy, which we could msleep while
4450 * waiting for it, and we can't msleep in a timer.
4451 **/
4452static void e1000e_update_phy_task(struct work_struct *work)
4453{
4454 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004455 struct e1000_adapter,
4456 update_phy_task);
David Ertmana03206e2014-01-24 23:07:48 +00004457 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004458
4459 if (test_bit(__E1000_DOWN, &adapter->state))
4460 return;
4461
David Ertmana03206e2014-01-24 23:07:48 +00004462 e1000_get_phy_info(hw);
4463
4464 /* Enable EEE on 82579 after link up */
4465 if (hw->phy.type == e1000_phy_82579)
4466 e1000_set_eee_pchlan(hw);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004467}
4468
Bruce Allane921eb12012-11-28 09:28:37 +00004469/**
4470 * e1000_update_phy_info - timre call-back to update PHY info
4471 * @data: pointer to adapter cast into an unsigned long
4472 *
Bruce Allanad680762008-03-28 09:15:03 -07004473 * Need to wait a few seconds after link up to get diagnostic information from
4474 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004475 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476static void e1000_update_phy_info(unsigned long data)
4477{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004478 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004479
4480 if (test_bit(__E1000_DOWN, &adapter->state))
4481 return;
4482
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004483 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004484}
4485
4486/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004487 * e1000e_update_phy_stats - Update the PHY statistics counters
4488 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004489 *
4490 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004491 **/
4492static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4493{
4494 struct e1000_hw *hw = &adapter->hw;
4495 s32 ret_val;
4496 u16 phy_data;
4497
4498 ret_val = hw->phy.ops.acquire(hw);
4499 if (ret_val)
4500 return;
4501
Bruce Allane921eb12012-11-28 09:28:37 +00004502 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004503 * If not, set to the page with the PHY status registers.
4504 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004505 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004506 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4507 &phy_data);
4508 if (ret_val)
4509 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004510 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4511 ret_val = hw->phy.ops.set_page(hw,
4512 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004513 if (ret_val)
4514 goto release;
4515 }
4516
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004517 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004518 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4519 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004520 if (!ret_val)
4521 adapter->stats.scc += phy_data;
4522
4523 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004524 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4525 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004526 if (!ret_val)
4527 adapter->stats.ecol += phy_data;
4528
4529 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004530 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4531 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004532 if (!ret_val)
4533 adapter->stats.mcc += phy_data;
4534
4535 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004536 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4537 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004538 if (!ret_val)
4539 adapter->stats.latecol += phy_data;
4540
4541 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004542 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4543 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004544 if (!ret_val)
4545 hw->mac.collision_delta = phy_data;
4546
4547 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004548 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4549 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004550 if (!ret_val)
4551 adapter->stats.dc += phy_data;
4552
4553 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004554 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4555 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004556 if (!ret_val)
4557 adapter->stats.tncrs += phy_data;
4558
4559release:
4560 hw->phy.ops.release(hw);
4561}
4562
4563/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564 * e1000e_update_stats - Update the board statistics counters
4565 * @adapter: board private structure
4566 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004567static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004568{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004569 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570 struct e1000_hw *hw = &adapter->hw;
4571 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572
Bruce Allane921eb12012-11-28 09:28:37 +00004573 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 * connection is down.
4575 */
4576 if (adapter->link_speed == 0)
4577 return;
4578 if (pci_channel_offline(pdev))
4579 return;
4580
Auke Kokbc7f75f2007-09-17 12:30:59 -07004581 adapter->stats.crcerrs += er32(CRCERRS);
4582 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004583 adapter->stats.gorc += er32(GORCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004584 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004585 adapter->stats.bprc += er32(BPRC);
4586 adapter->stats.mprc += er32(MPRC);
4587 adapter->stats.roc += er32(ROC);
4588
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004590
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004591 /* Half-duplex statistics */
4592 if (adapter->link_duplex == HALF_DUPLEX) {
4593 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4594 e1000e_update_phy_stats(adapter);
4595 } else {
4596 adapter->stats.scc += er32(SCC);
4597 adapter->stats.ecol += er32(ECOL);
4598 adapter->stats.mcc += er32(MCC);
4599 adapter->stats.latecol += er32(LATECOL);
4600 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004601
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004602 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004603
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004604 if ((hw->mac.type != e1000_82574) &&
4605 (hw->mac.type != e1000_82583))
4606 adapter->stats.tncrs += er32(TNCRS);
4607 }
4608 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004609 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004610
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 adapter->stats.xonrxc += er32(XONRXC);
4612 adapter->stats.xontxc += er32(XONTXC);
4613 adapter->stats.xoffrxc += er32(XOFFRXC);
4614 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004616 adapter->stats.gotc += er32(GOTCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004617 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618 adapter->stats.rnbc += er32(RNBC);
4619 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620
4621 adapter->stats.mptc += er32(MPTC);
4622 adapter->stats.bptc += er32(BPTC);
4623
4624 /* used for adaptive IFS */
4625
4626 hw->mac.tx_packet_delta = er32(TPT);
4627 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004628
4629 adapter->stats.algnerrc += er32(ALGNERRC);
4630 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631 adapter->stats.cexterr += er32(CEXTERR);
4632 adapter->stats.tsctc += er32(TSCTC);
4633 adapter->stats.tsctfc += er32(TSCTFC);
4634
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004636 netdev->stats.multicast = adapter->stats.mprc;
4637 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004638
4639 /* Rx Errors */
4640
Bruce Allane921eb12012-11-28 09:28:37 +00004641 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004642 * our own version based on RUC and ROC
4643 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004644 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004645 adapter->stats.crcerrs + adapter->stats.algnerrc +
4646 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004647 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004648 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004649 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4650 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4651 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004652
4653 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004654 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004655 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4656 netdev->stats.tx_window_errors = adapter->stats.latecol;
4657 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004658
4659 /* Tx Dropped needs to be maintained elsewhere */
4660
Auke Kokbc7f75f2007-09-17 12:30:59 -07004661 /* Management Stats */
4662 adapter->stats.mgptc += er32(MGTPTC);
4663 adapter->stats.mgprc += er32(MGTPRC);
4664 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004665
4666 /* Correctable ECC Errors */
4667 if (hw->mac.type == e1000_pch_lpt) {
4668 u32 pbeccsts = er32(PBECCSTS);
4669 adapter->corr_errors +=
4670 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4671 adapter->uncorr_errors +=
4672 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4673 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4674 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004675}
4676
Bruce Allan7c257692008-04-23 11:09:00 -07004677/**
4678 * e1000_phy_read_status - Update the PHY register status snapshot
4679 * @adapter: board private structure
4680 **/
4681static void e1000_phy_read_status(struct e1000_adapter *adapter)
4682{
4683 struct e1000_hw *hw = &adapter->hw;
4684 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004685
Bruce Allan97390ab2013-06-29 07:42:25 +00004686 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
4687 (er32(STATUS) & E1000_STATUS_LU) &&
Bruce Allan7c257692008-04-23 11:09:00 -07004688 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004689 int ret_val;
4690
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004691 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4692 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4693 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4694 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4695 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4696 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4697 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4698 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004699 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004700 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004701 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004702 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004703 * Set values to typical power-on defaults
4704 */
4705 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4706 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4707 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4708 BMSR_ERCAP);
4709 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4710 ADVERTISE_ALL | ADVERTISE_CSMA);
4711 phy->lpa = 0;
4712 phy->expansion = EXPANSION_ENABLENPAGE;
4713 phy->ctrl1000 = ADVERTISE_1000FULL;
4714 phy->stat1000 = 0;
4715 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4716 }
Bruce Allan7c257692008-04-23 11:09:00 -07004717}
4718
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719static void e1000_print_link_info(struct e1000_adapter *adapter)
4720{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004721 struct e1000_hw *hw = &adapter->hw;
4722 u32 ctrl = er32(CTRL);
4723
Bruce Allan8f12fe82008-11-21 16:54:43 -08004724 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004725 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4726 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004727 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4728 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4729 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4730 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004731}
4732
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004733static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004734{
4735 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004736 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004737 s32 ret_val = 0;
4738
Bruce Allane921eb12012-11-28 09:28:37 +00004739 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004740 * Rx sequence error interrupt. get_link_status will stay
4741 * false until the check_for_link establishes link
4742 * for copper adapters ONLY
4743 */
4744 switch (hw->phy.media_type) {
4745 case e1000_media_type_copper:
4746 if (hw->mac.get_link_status) {
4747 ret_val = hw->mac.ops.check_for_link(hw);
4748 link_active = !hw->mac.get_link_status;
4749 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004750 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004751 }
4752 break;
4753 case e1000_media_type_fiber:
4754 ret_val = hw->mac.ops.check_for_link(hw);
4755 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4756 break;
4757 case e1000_media_type_internal_serdes:
4758 ret_val = hw->mac.ops.check_for_link(hw);
4759 link_active = adapter->hw.mac.serdes_has_link;
4760 break;
4761 default:
4762 case e1000_media_type_unknown:
4763 break;
4764 }
4765
4766 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4767 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4768 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004769 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004770 }
4771
4772 return link_active;
4773}
4774
4775static void e1000e_enable_receives(struct e1000_adapter *adapter)
4776{
4777 /* make sure the receive unit is started */
4778 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004779 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004780 struct e1000_hw *hw = &adapter->hw;
4781 u32 rctl = er32(RCTL);
4782 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004783 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004784 }
4785}
4786
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004787static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4788{
4789 struct e1000_hw *hw = &adapter->hw;
4790
Bruce Allane921eb12012-11-28 09:28:37 +00004791 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004792 * for hung state and reset, if two calls return true
4793 */
4794 if (e1000_check_phy_82574(hw))
4795 adapter->phy_hang_count++;
4796 else
4797 adapter->phy_hang_count = 0;
4798
4799 if (adapter->phy_hang_count > 1) {
4800 adapter->phy_hang_count = 0;
4801 schedule_work(&adapter->reset_task);
4802 }
4803}
4804
Auke Kokbc7f75f2007-09-17 12:30:59 -07004805/**
4806 * e1000_watchdog - Timer Call-back
4807 * @data: pointer to adapter cast into an unsigned long
4808 **/
4809static void e1000_watchdog(unsigned long data)
4810{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004811 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812
4813 /* Do the rest outside of interrupt context */
4814 schedule_work(&adapter->watchdog_task);
4815
4816 /* TODO: make this use queue_delayed_work() */
4817}
4818
4819static void e1000_watchdog_task(struct work_struct *work)
4820{
4821 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004822 struct e1000_adapter,
4823 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004824 struct net_device *netdev = adapter->netdev;
4825 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004826 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 struct e1000_ring *tx_ring = adapter->tx_ring;
4828 struct e1000_hw *hw = &adapter->hw;
4829 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004830
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004831 if (test_bit(__E1000_DOWN, &adapter->state))
4832 return;
4833
David S. Millerb405e8d2010-02-04 22:31:41 -08004834 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004835 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004836 /* Cancel scheduled suspend requests. */
4837 pm_runtime_resume(netdev->dev.parent);
4838
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004839 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004840 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004841 }
4842
4843 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4844 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4845 e1000_update_mng_vlan(adapter);
4846
Auke Kokbc7f75f2007-09-17 12:30:59 -07004847 if (link) {
4848 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004849 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004850
4851 /* Cancel scheduled suspend requests. */
4852 pm_runtime_resume(netdev->dev.parent);
4853
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004854 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004855 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004856 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004857 &adapter->link_speed,
4858 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004859 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004860
4861 /* check if SmartSpeed worked */
4862 e1000e_check_downshift(hw);
4863 if (phy->speed_downgraded)
4864 netdev_warn(netdev,
4865 "Link Speed was downgraded by SmartSpeed\n");
4866
Bruce Allane921eb12012-11-28 09:28:37 +00004867 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004868 * if link has autonegotiated at 10/100 half
4869 */
4870 if ((hw->phy.type == e1000_phy_igp_3 ||
4871 hw->phy.type == e1000_phy_bm) &&
David Ertman138953b2013-08-30 05:45:25 +00004872 hw->mac.autoneg &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004873 (adapter->link_speed == SPEED_10 ||
4874 adapter->link_speed == SPEED_100) &&
4875 (adapter->link_duplex == HALF_DUPLEX)) {
4876 u16 autoneg_exp;
4877
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004878 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004879
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004880 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004881 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 -07004882 }
4883
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004884 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004885 adapter->tx_timeout_factor = 1;
4886 switch (adapter->link_speed) {
4887 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004888 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004889 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004890 break;
4891 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004892 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004893 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004894 break;
4895 }
4896
Bruce Allane921eb12012-11-28 09:28:37 +00004897 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004898 * link-up event
4899 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4901 !txb2b) {
4902 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004903 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004904 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004905 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004906 }
4907
Bruce Allane921eb12012-11-28 09:28:37 +00004908 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004909 * some hardware issues
4910 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4912 switch (adapter->link_speed) {
4913 case SPEED_10:
4914 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004915 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916 netdev->features &= ~NETIF_F_TSO;
4917 netdev->features &= ~NETIF_F_TSO6;
4918 break;
4919 case SPEED_1000:
4920 netdev->features |= NETIF_F_TSO;
4921 netdev->features |= NETIF_F_TSO6;
4922 break;
4923 default:
4924 /* oops */
4925 break;
4926 }
4927 }
4928
Bruce Allane921eb12012-11-28 09:28:37 +00004929 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004930 * after setting TARC(0)
4931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932 tctl = er32(TCTL);
4933 tctl |= E1000_TCTL_EN;
4934 ew32(TCTL, tctl);
4935
Bruce Allane921eb12012-11-28 09:28:37 +00004936 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004937 * reporting link up.
4938 */
4939 if (phy->ops.cfg_on_link_up)
4940 phy->ops.cfg_on_link_up(hw);
4941
Auke Kokbc7f75f2007-09-17 12:30:59 -07004942 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004943
4944 if (!test_bit(__E1000_DOWN, &adapter->state))
4945 mod_timer(&adapter->phy_info_timer,
4946 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004947 }
4948 } else {
4949 if (netif_carrier_ok(netdev)) {
4950 adapter->link_speed = 0;
4951 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004952 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004953 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 if (!test_bit(__E1000_DOWN, &adapter->state))
4956 mod_timer(&adapter->phy_info_timer,
4957 round_jiffies(jiffies + 2 * HZ));
4958
Bruce Allan12d43f72012-12-05 06:26:14 +00004959 /* The link is lost so the controller stops DMA.
4960 * If there is queued Tx work that cannot be done
4961 * or if on an 8000ES2LAN which requires a Rx packet
4962 * buffer work-around on link down event, reset the
4963 * controller to flush the Tx/Rx packet buffers.
4964 * (Do the reset outside of interrupt context).
4965 */
4966 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4967 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4968 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004969 else
4970 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004971 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972 }
4973 }
4974
4975link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004976 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004977 e1000e_update_stats(adapter);
4978
4979 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4980 adapter->tpt_old = adapter->stats.tpt;
4981 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4982 adapter->colc_old = adapter->stats.colc;
4983
Bruce Allan7c257692008-04-23 11:09:00 -07004984 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4985 adapter->gorc_old = adapter->stats.gorc;
4986 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4987 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004988 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004989
Bruce Allan12d43f72012-12-05 06:26:14 +00004990 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004991 schedule_work(&adapter->reset_task);
4992 /* return immediately since reset is imminent */
4993 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994 }
4995
Bruce Allan12d43f72012-12-05 06:26:14 +00004996 e1000e_update_adaptive(&adapter->hw);
4997
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004998 /* Simple mode for Interrupt Throttle Rate (ITR) */
4999 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00005000 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005001 * Total asymmetrical Tx or Rx gets ITR=8000;
5002 * everyone else is between 2000-8000.
5003 */
5004 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5005 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00005006 adapter->gotc - adapter->gorc :
5007 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005008 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5009
Matthew Vick22a4cca2012-07-12 00:02:42 +00005010 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005011 }
5012
Bruce Allanad680762008-03-28 09:15:03 -07005013 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005014 if (adapter->msix_entries)
5015 ew32(ICS, adapter->rx_ring->ims_val);
5016 else
5017 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005018
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005019 /* flush pending descriptors to memory before detecting Tx hang */
5020 e1000e_flush_descriptors(adapter);
5021
Auke Kokbc7f75f2007-09-17 12:30:59 -07005022 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005023 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024
Bruce Allane921eb12012-11-28 09:28:37 +00005025 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005026 * reset from the other port. Set the appropriate LAA in RAR[0]
5027 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005029 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005030
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005031 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5032 e1000e_check_82574_phy_workaround(adapter);
5033
Bruce Allanb67e1912012-12-27 08:32:33 +00005034 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5035 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5036 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5037 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5038 er32(RXSTMPH);
5039 adapter->rx_hwtstamp_cleared++;
5040 } else {
5041 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5042 }
5043 }
5044
Auke Kokbc7f75f2007-09-17 12:30:59 -07005045 /* Reset the timer */
5046 if (!test_bit(__E1000_DOWN, &adapter->state))
5047 mod_timer(&adapter->watchdog_timer,
5048 round_jiffies(jiffies + 2 * HZ));
5049}
5050
5051#define E1000_TX_FLAGS_CSUM 0x00000001
5052#define E1000_TX_FLAGS_VLAN 0x00000002
5053#define E1000_TX_FLAGS_TSO 0x00000004
5054#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005055#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005056#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5058#define E1000_TX_FLAGS_VLAN_SHIFT 16
5059
Bruce Allan55aa6982011-12-16 00:45:45 +00005060static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005061{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062 struct e1000_context_desc *context_desc;
5063 struct e1000_buffer *buffer_info;
5064 unsigned int i;
5065 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005066 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005069 if (!skb_is_gso(skb))
5070 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005072 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005073 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5074
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005075 if (err)
5076 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005077 }
5078
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005079 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5080 mss = skb_shinfo(skb)->gso_size;
5081 if (skb->protocol == htons(ETH_P_IP)) {
5082 struct iphdr *iph = ip_hdr(skb);
5083 iph->tot_len = 0;
5084 iph->check = 0;
5085 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005086 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005087 cmd_length = E1000_TXD_CMD_IP;
5088 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005089 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005090 ipv6_hdr(skb)->payload_len = 0;
5091 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005092 &ipv6_hdr(skb)->daddr,
5093 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005094 ipcse = 0;
5095 }
5096 ipcss = skb_network_offset(skb);
5097 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5098 tucss = skb_transport_offset(skb);
5099 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005100
5101 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005102 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005103
5104 i = tx_ring->next_to_use;
5105 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5106 buffer_info = &tx_ring->buffer_info[i];
5107
Bruce Allane80bd1d2013-05-01 01:19:46 +00005108 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5109 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5110 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005111 context_desc->upper_setup.tcp_fields.tucss = tucss;
5112 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005113 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allane80bd1d2013-05-01 01:19:46 +00005114 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005115 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5116 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5117
5118 buffer_info->time_stamp = jiffies;
5119 buffer_info->next_to_watch = i;
5120
5121 i++;
5122 if (i == tx_ring->count)
5123 i = 0;
5124 tx_ring->next_to_use = i;
5125
5126 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005127}
5128
Bruce Allan55aa6982011-12-16 00:45:45 +00005129static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005130{
Bruce Allan55aa6982011-12-16 00:45:45 +00005131 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005132 struct e1000_context_desc *context_desc;
5133 struct e1000_buffer *buffer_info;
5134 unsigned int i;
5135 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005136 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005137 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005138
Dave Grahamaf807c82008-10-09 14:28:58 -07005139 if (skb->ip_summed != CHECKSUM_PARTIAL)
5140 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141
Arthur Jones5f66f202009-03-19 01:13:08 +00005142 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5143 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5144 else
5145 protocol = skb->protocol;
5146
Arthur Jones3f518392009-03-20 15:56:35 -07005147 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08005148 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005149 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5150 cmd_len |= E1000_TXD_CMD_TCP;
5151 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08005152 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005153 /* XXX not handling all IPV6 headers */
5154 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5155 cmd_len |= E1000_TXD_CMD_TCP;
5156 break;
5157 default:
5158 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005159 e_warn("checksum_partial proto=%x!\n",
5160 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005161 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005162 }
5163
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005164 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005165
5166 i = tx_ring->next_to_use;
5167 buffer_info = &tx_ring->buffer_info[i];
5168 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5169
5170 context_desc->lower_setup.ip_config = 0;
5171 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005172 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005173 context_desc->upper_setup.tcp_fields.tucse = 0;
5174 context_desc->tcp_seg_setup.data = 0;
5175 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5176
5177 buffer_info->time_stamp = jiffies;
5178 buffer_info->next_to_watch = i;
5179
5180 i++;
5181 if (i == tx_ring->count)
5182 i = 0;
5183 tx_ring->next_to_use = i;
5184
5185 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005186}
5187
Bruce Allan55aa6982011-12-16 00:45:45 +00005188static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5189 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005190 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005191{
Bruce Allan55aa6982011-12-16 00:45:45 +00005192 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005193 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005194 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005195 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005196 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005197 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005198
5199 i = tx_ring->next_to_use;
5200
5201 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005202 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005203 size = min(len, max_per_txd);
5204
Auke Kokbc7f75f2007-09-17 12:30:59 -07005205 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005206 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005208 buffer_info->dma = dma_map_single(&pdev->dev,
5209 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005210 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005211 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005212 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005213 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214
5215 len -= size;
5216 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005217 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005218
5219 if (len) {
5220 i++;
5221 if (i == tx_ring->count)
5222 i = 0;
5223 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005224 }
5225
5226 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005227 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005228
5229 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005230 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005231 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005232
5233 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005234 i++;
5235 if (i == tx_ring->count)
5236 i = 0;
5237
Auke Kokbc7f75f2007-09-17 12:30:59 -07005238 buffer_info = &tx_ring->buffer_info[i];
5239 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240
5241 buffer_info->length = size;
5242 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005243 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005244 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005245 offset, size,
5246 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005247 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005248 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005249 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005250
5251 len -= size;
5252 offset += size;
5253 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005254 }
5255 }
5256
Bruce Allanaf667a22010-12-31 06:10:01 +00005257 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005258 /* multiply data chunks by size of headers */
5259 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5260
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005262 tx_ring->buffer_info[i].segs = segs;
5263 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005264 tx_ring->buffer_info[first].next_to_watch = i;
5265
5266 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005267
5268dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005269 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005270 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005271 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005272 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005273
5274 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005275 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005276 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005277 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005278 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005279 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005280 }
5281
5282 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005283}
5284
Bruce Allan55aa6982011-12-16 00:45:45 +00005285static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005286{
Bruce Allan55aa6982011-12-16 00:45:45 +00005287 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005288 struct e1000_tx_desc *tx_desc = NULL;
5289 struct e1000_buffer *buffer_info;
5290 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5291 unsigned int i;
5292
5293 if (tx_flags & E1000_TX_FLAGS_TSO) {
5294 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005295 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5297
5298 if (tx_flags & E1000_TX_FLAGS_IPV4)
5299 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5300 }
5301
5302 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5303 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5304 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5305 }
5306
5307 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5308 txd_lower |= E1000_TXD_CMD_VLE;
5309 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5310 }
5311
Ben Greear943146d2012-02-11 15:39:40 +00005312 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5313 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5314
Bruce Allanb67e1912012-12-27 08:32:33 +00005315 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5316 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5317 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5318 }
5319
Auke Kokbc7f75f2007-09-17 12:30:59 -07005320 i = tx_ring->next_to_use;
5321
Bruce Allan36b973d2010-11-24 07:42:43 +00005322 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323 buffer_info = &tx_ring->buffer_info[i];
5324 tx_desc = E1000_TX_DESC(*tx_ring, i);
5325 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005326 tx_desc->lower.data = cpu_to_le32(txd_lower |
5327 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005328 tx_desc->upper.data = cpu_to_le32(txd_upper);
5329
5330 i++;
5331 if (i == tx_ring->count)
5332 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005333 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005334
5335 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5336
Ben Greear943146d2012-02-11 15:39:40 +00005337 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5338 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5339 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5340
Bruce Allane921eb12012-11-28 09:28:37 +00005341 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005342 * know there are new descriptors to fetch. (Only
5343 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005344 * such as IA-64).
5345 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005346 wmb();
5347
5348 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005349
5350 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005351 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005352 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005353 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005354
Bruce Allane921eb12012-11-28 09:28:37 +00005355 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005356 * at a time, it synchronizes IO on IA64/Altix systems
5357 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005358 mmiowb();
5359}
5360
5361#define MINIMUM_DHCP_PACKET_SIZE 282
5362static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5363 struct sk_buff *skb)
5364{
Bruce Allane80bd1d2013-05-01 01:19:46 +00005365 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005366 u16 length, offset;
5367
Bruce Alland60923c2012-12-05 06:26:56 +00005368 if (vlan_tx_tag_present(skb) &&
5369 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5370 (adapter->hw.mng_cookie.status &
5371 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5372 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005373
5374 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5375 return 0;
5376
Bruce Allan53aa82d2013-02-20 04:06:06 +00005377 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378 return 0;
5379
5380 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005381 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005382 struct udphdr *udp;
5383
5384 if (ip->protocol != IPPROTO_UDP)
5385 return 0;
5386
5387 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5388 if (ntohs(udp->dest) != 67)
5389 return 0;
5390
5391 offset = (u8 *)udp + 8 - skb->data;
5392 length = skb->len - offset;
5393 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5394 }
5395
5396 return 0;
5397}
5398
Bruce Allan55aa6982011-12-16 00:45:45 +00005399static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005400{
Bruce Allan55aa6982011-12-16 00:45:45 +00005401 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005402
Bruce Allan55aa6982011-12-16 00:45:45 +00005403 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005404 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005405 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005406 * but since that doesn't exist yet, just open code it.
5407 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408 smp_mb();
5409
Bruce Allane921eb12012-11-28 09:28:37 +00005410 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005411 * made room available.
5412 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005413 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005414 return -EBUSY;
5415
5416 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005417 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005418 ++adapter->restart_queue;
5419 return 0;
5420}
5421
Bruce Allan55aa6982011-12-16 00:45:45 +00005422static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005423{
Bruce Alland821a4c2012-08-24 20:38:11 +00005424 BUG_ON(size > tx_ring->count);
5425
Bruce Allan55aa6982011-12-16 00:45:45 +00005426 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005428 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005429}
5430
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005431static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5432 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005433{
5434 struct e1000_adapter *adapter = netdev_priv(netdev);
5435 struct e1000_ring *tx_ring = adapter->tx_ring;
5436 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005437 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005438 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005439 unsigned int nr_frags;
5440 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005441 int count = 0;
5442 int tso;
5443 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005444
5445 if (test_bit(__E1000_DOWN, &adapter->state)) {
5446 dev_kfree_skb_any(skb);
5447 return NETDEV_TX_OK;
5448 }
5449
5450 if (skb->len <= 0) {
5451 dev_kfree_skb_any(skb);
5452 return NETDEV_TX_OK;
5453 }
5454
Bruce Allane921eb12012-11-28 09:28:37 +00005455 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005456 * pad skb in order to meet this minimum size requirement
5457 */
5458 if (unlikely(skb->len < 17)) {
5459 if (skb_pad(skb, 17 - skb->len))
5460 return NETDEV_TX_OK;
5461 skb->len = 17;
5462 skb_set_tail_pointer(skb, 17);
5463 }
5464
Auke Kokbc7f75f2007-09-17 12:30:59 -07005465 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466 if (mss) {
5467 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468
Bruce Allane921eb12012-11-28 09:28:37 +00005469 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005470 * points to just header, pull a few bytes of payload from
5471 * frags into skb->data
5472 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005473 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005474 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005475 * avoiding it could save a lot of cycles
5476 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005477 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005478 unsigned int pull_size;
5479
Bruce Allana2a5b322012-01-31 06:37:17 +00005480 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005481 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005482 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005483 dev_kfree_skb_any(skb);
5484 return NETDEV_TX_OK;
5485 }
Eric Dumazete743d312010-04-14 15:59:40 -07005486 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005487 }
5488 }
5489
5490 /* reserve a descriptor for the offload context */
5491 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5492 count++;
5493 count++;
5494
Bruce Alland821a4c2012-08-24 20:38:11 +00005495 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005496
5497 nr_frags = skb_shinfo(skb)->nr_frags;
5498 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005499 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5500 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005501
5502 if (adapter->hw.mac.tx_pkt_filtering)
5503 e1000_transfer_dhcp_info(adapter, skb);
5504
Bruce Allane921eb12012-11-28 09:28:37 +00005505 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005506 * head, otherwise try next time
5507 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005508 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005509 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005510
Jesse Grosseab6d182010-10-20 13:56:03 +00005511 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005512 tx_flags |= E1000_TX_FLAGS_VLAN;
5513 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5514 }
5515
5516 first = tx_ring->next_to_use;
5517
Bruce Allan55aa6982011-12-16 00:45:45 +00005518 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005519 if (tso < 0) {
5520 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005521 return NETDEV_TX_OK;
5522 }
5523
5524 if (tso)
5525 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005526 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005527 tx_flags |= E1000_TX_FLAGS_CSUM;
5528
Bruce Allane921eb12012-11-28 09:28:37 +00005529 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005530 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005531 * no longer assume, we must.
5532 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005533 if (skb->protocol == htons(ETH_P_IP))
5534 tx_flags |= E1000_TX_FLAGS_IPV4;
5535
Ben Greear943146d2012-02-11 15:39:40 +00005536 if (unlikely(skb->no_fcs))
5537 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5538
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005539 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005540 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5541 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005542 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005543 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5544 !adapter->tx_hwtstamp_skb)) {
5545 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5546 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5547 adapter->tx_hwtstamp_skb = skb_get(skb);
5548 schedule_work(&adapter->tx_hwtstamp_work);
5549 } else {
5550 skb_tx_timestamp(skb);
5551 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005552
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005553 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005554 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005555 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005556 e1000_maybe_stop_tx(tx_ring,
5557 (MAX_SKB_FRAGS *
5558 DIV_ROUND_UP(PAGE_SIZE,
5559 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005560 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005561 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005562 tx_ring->buffer_info[first].time_stamp = 0;
5563 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005564 }
5565
Auke Kokbc7f75f2007-09-17 12:30:59 -07005566 return NETDEV_TX_OK;
5567}
5568
5569/**
5570 * e1000_tx_timeout - Respond to a Tx Hang
5571 * @netdev: network interface device structure
5572 **/
5573static void e1000_tx_timeout(struct net_device *netdev)
5574{
5575 struct e1000_adapter *adapter = netdev_priv(netdev);
5576
5577 /* Do the reset outside of interrupt context */
5578 adapter->tx_timeout_count++;
5579 schedule_work(&adapter->reset_task);
5580}
5581
5582static void e1000_reset_task(struct work_struct *work)
5583{
5584 struct e1000_adapter *adapter;
5585 adapter = container_of(work, struct e1000_adapter, reset_task);
5586
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005587 /* don't run the task if already down */
5588 if (test_bit(__E1000_DOWN, &adapter->state))
5589 return;
5590
Bruce Allan12d43f72012-12-05 06:26:14 +00005591 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005592 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005593 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005594 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005595 e1000e_reinit_locked(adapter);
5596}
5597
5598/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005599 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005600 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005601 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005602 *
5603 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005604 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005605struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005606 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005607{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005608 struct e1000_adapter *adapter = netdev_priv(netdev);
5609
5610 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5611 spin_lock(&adapter->stats64_lock);
5612 e1000e_update_stats(adapter);
5613 /* Fill out the OS statistics structure */
5614 stats->rx_bytes = adapter->stats.gorc;
5615 stats->rx_packets = adapter->stats.gprc;
5616 stats->tx_bytes = adapter->stats.gotc;
5617 stats->tx_packets = adapter->stats.gptc;
5618 stats->multicast = adapter->stats.mprc;
5619 stats->collisions = adapter->stats.colc;
5620
5621 /* Rx Errors */
5622
Bruce Allane921eb12012-11-28 09:28:37 +00005623 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005624 * our own version based on RUC and ROC
5625 */
5626 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005627 adapter->stats.crcerrs + adapter->stats.algnerrc +
5628 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5629 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005630 stats->rx_crc_errors = adapter->stats.crcerrs;
5631 stats->rx_frame_errors = adapter->stats.algnerrc;
5632 stats->rx_missed_errors = adapter->stats.mpc;
5633
5634 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005635 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005636 stats->tx_aborted_errors = adapter->stats.ecol;
5637 stats->tx_window_errors = adapter->stats.latecol;
5638 stats->tx_carrier_errors = adapter->stats.tncrs;
5639
5640 /* Tx Dropped needs to be maintained elsewhere */
5641
5642 spin_unlock(&adapter->stats64_lock);
5643 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005644}
5645
5646/**
5647 * e1000_change_mtu - Change the Maximum Transfer Unit
5648 * @netdev: network interface device structure
5649 * @new_mtu: new value for maximum frame size
5650 *
5651 * Returns 0 on success, negative on failure
5652 **/
5653static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5654{
5655 struct e1000_adapter *adapter = netdev_priv(netdev);
5656 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5657
Bruce Allan2adc55c2009-06-02 11:28:58 +00005658 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005659 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5660 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5661 e_err("Jumbo Frames not supported.\n");
5662 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005663 }
5664
Bruce Allan2adc55c2009-06-02 11:28:58 +00005665 /* Supported frame sizes */
5666 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5667 (max_frame > adapter->max_hw_frame_size)) {
5668 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 return -EINVAL;
5670 }
5671
Bruce Allan2fbe4522012-04-19 03:21:47 +00005672 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5673 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005674 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5675 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005676 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005677 return -EINVAL;
5678 }
5679
Auke Kokbc7f75f2007-09-17 12:30:59 -07005680 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005681 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005682 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005683 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005684 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5685 netdev->mtu = new_mtu;
David Ertman63eb48f2014-02-14 07:16:46 +00005686
5687 pm_runtime_get_sync(netdev->dev.parent);
5688
Auke Kokbc7f75f2007-09-17 12:30:59 -07005689 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00005690 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691
Bruce Allane921eb12012-11-28 09:28:37 +00005692 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005693 * means we reserve 2 more, this pushes us to allocate from the next
5694 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005695 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005696 * However with the new *_jumbo_rx* routines, jumbo receives will use
5697 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005698 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005699
Jesse Brandeburg99261462010-01-22 22:56:16 +00005700 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005701 adapter->rx_buffer_len = 2048;
5702 else
5703 adapter->rx_buffer_len = 4096;
5704
5705 /* adjust allocation if LPE protects us, and we aren't using SBP */
5706 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005707 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005708 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005709 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005710
Auke Kokbc7f75f2007-09-17 12:30:59 -07005711 if (netif_running(netdev))
5712 e1000e_up(adapter);
5713 else
5714 e1000e_reset(adapter);
5715
David Ertman63eb48f2014-02-14 07:16:46 +00005716 pm_runtime_put_sync(netdev->dev.parent);
5717
Auke Kokbc7f75f2007-09-17 12:30:59 -07005718 clear_bit(__E1000_RESETTING, &adapter->state);
5719
5720 return 0;
5721}
5722
5723static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5724 int cmd)
5725{
5726 struct e1000_adapter *adapter = netdev_priv(netdev);
5727 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005728
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005729 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005730 return -EOPNOTSUPP;
5731
5732 switch (cmd) {
5733 case SIOCGMIIPHY:
5734 data->phy_id = adapter->hw.phy.addr;
5735 break;
5736 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005737 e1000_phy_read_status(adapter);
5738
Bruce Allan7c257692008-04-23 11:09:00 -07005739 switch (data->reg_num & 0x1F) {
5740 case MII_BMCR:
5741 data->val_out = adapter->phy_regs.bmcr;
5742 break;
5743 case MII_BMSR:
5744 data->val_out = adapter->phy_regs.bmsr;
5745 break;
5746 case MII_PHYSID1:
5747 data->val_out = (adapter->hw.phy.id >> 16);
5748 break;
5749 case MII_PHYSID2:
5750 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5751 break;
5752 case MII_ADVERTISE:
5753 data->val_out = adapter->phy_regs.advertise;
5754 break;
5755 case MII_LPA:
5756 data->val_out = adapter->phy_regs.lpa;
5757 break;
5758 case MII_EXPANSION:
5759 data->val_out = adapter->phy_regs.expansion;
5760 break;
5761 case MII_CTRL1000:
5762 data->val_out = adapter->phy_regs.ctrl1000;
5763 break;
5764 case MII_STAT1000:
5765 data->val_out = adapter->phy_regs.stat1000;
5766 break;
5767 case MII_ESTATUS:
5768 data->val_out = adapter->phy_regs.estatus;
5769 break;
5770 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005771 return -EIO;
5772 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005773 break;
5774 case SIOCSMIIREG:
5775 default:
5776 return -EOPNOTSUPP;
5777 }
5778 return 0;
5779}
5780
Bruce Allanb67e1912012-12-27 08:32:33 +00005781/**
5782 * e1000e_hwtstamp_ioctl - control hardware time stamping
5783 * @netdev: network interface device structure
5784 * @ifreq: interface request
5785 *
5786 * Outgoing time stamping can be enabled and disabled. Play nice and
5787 * disable it when requested, although it shouldn't cause any overhead
5788 * when no packet needs it. At most one packet in the queue may be
5789 * marked for time stamping, otherwise it would be impossible to tell
5790 * for sure to which packet the hardware time stamp belongs.
5791 *
5792 * Incoming time stamping has to be configured via the hardware filters.
5793 * Not all combinations are supported, in particular event type has to be
5794 * specified. Matching the kind of event packet is not supported, with the
5795 * exception of "all V2 events regardless of level 2 or 4".
5796 **/
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005797static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Bruce Allanb67e1912012-12-27 08:32:33 +00005798{
5799 struct e1000_adapter *adapter = netdev_priv(netdev);
5800 struct hwtstamp_config config;
5801 int ret_val;
5802
5803 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5804 return -EFAULT;
5805
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00005806 ret_val = e1000e_config_hwtstamp(adapter, &config);
Bruce Allanb67e1912012-12-27 08:32:33 +00005807 if (ret_val)
5808 return ret_val;
5809
Bruce Alland89777b2013-01-19 01:09:58 +00005810 switch (config.rx_filter) {
5811 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5812 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5813 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5814 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5815 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5816 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5817 /* With V2 type filters which specify a Sync or Delay Request,
5818 * Path Delay Request/Response messages are also time stamped
5819 * by hardware so notify the caller the requested packets plus
5820 * some others are time stamped.
5821 */
5822 config.rx_filter = HWTSTAMP_FILTER_SOME;
5823 break;
5824 default:
5825 break;
5826 }
5827
Bruce Allanb67e1912012-12-27 08:32:33 +00005828 return copy_to_user(ifr->ifr_data, &config,
5829 sizeof(config)) ? -EFAULT : 0;
5830}
5831
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005832static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
5833{
5834 struct e1000_adapter *adapter = netdev_priv(netdev);
5835
5836 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
5837 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
5838}
5839
Auke Kokbc7f75f2007-09-17 12:30:59 -07005840static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5841{
5842 switch (cmd) {
5843 case SIOCGMIIPHY:
5844 case SIOCGMIIREG:
5845 case SIOCSMIIREG:
5846 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005847 case SIOCSHWTSTAMP:
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005848 return e1000e_hwtstamp_set(netdev, ifr);
5849 case SIOCGHWTSTAMP:
5850 return e1000e_hwtstamp_get(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005851 default:
5852 return -EOPNOTSUPP;
5853 }
5854}
5855
Bruce Allana4f58f52009-06-02 11:29:18 +00005856static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5857{
5858 struct e1000_hw *hw = &adapter->hw;
David Ertman74f350e2014-02-22 03:15:17 +00005859 u32 i, mac_reg, wuc;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005860 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005861 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005862
5863 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005864 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005865
Bruce Allan2b6b1682011-05-13 07:20:09 +00005866 retval = hw->phy.ops.acquire(hw);
5867 if (retval) {
5868 e_err("Could not acquire PHY\n");
5869 return retval;
5870 }
5871
5872 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5873 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5874 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005875 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005876
5877 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005878 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5879 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005880 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5881 (u16)(mac_reg & 0xFFFF));
5882 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5883 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005884 }
5885
5886 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005887 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005888 mac_reg = er32(RCTL);
5889 if (mac_reg & E1000_RCTL_UPE)
5890 phy_reg |= BM_RCTL_UPE;
5891 if (mac_reg & E1000_RCTL_MPE)
5892 phy_reg |= BM_RCTL_MPE;
5893 phy_reg &= ~(BM_RCTL_MO_MASK);
5894 if (mac_reg & E1000_RCTL_MO_3)
5895 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005896 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005897 if (mac_reg & E1000_RCTL_BAM)
5898 phy_reg |= BM_RCTL_BAM;
5899 if (mac_reg & E1000_RCTL_PMCF)
5900 phy_reg |= BM_RCTL_PMCF;
5901 mac_reg = er32(CTRL);
5902 if (mac_reg & E1000_CTRL_RFCE)
5903 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005904 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005905
David Ertman74f350e2014-02-22 03:15:17 +00005906 wuc = E1000_WUC_PME_EN;
5907 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
5908 wuc |= E1000_WUC_APME;
5909
Bruce Allana4f58f52009-06-02 11:29:18 +00005910 /* enable PHY wakeup in MAC register */
5911 ew32(WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00005912 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
5913 E1000_WUC_PME_STATUS | wuc));
Bruce Allana4f58f52009-06-02 11:29:18 +00005914
5915 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005916 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00005917 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
Bruce Allana4f58f52009-06-02 11:29:18 +00005918
5919 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005920 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5921 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005922 if (retval)
5923 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005924release:
Bruce Allan94d81862009-11-20 23:25:26 +00005925 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005926
5927 return retval;
5928}
5929
David Ertman28002092014-02-14 07:16:41 +00005930static int e1000e_pm_freeze(struct device *dev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005931{
David Ertman28002092014-02-14 07:16:41 +00005932 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005933 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934
5935 netif_device_detach(netdev);
5936
5937 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005938 int count = E1000_CHECK_RESET_COUNT;
5939
5940 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5941 usleep_range(10000, 20000);
5942
Auke Kokbc7f75f2007-09-17 12:30:59 -07005943 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
David Ertman28002092014-02-14 07:16:41 +00005944
5945 /* Quiesce the device without resetting the hardware */
5946 e1000e_down(adapter, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005947 e1000_free_irq(adapter);
5948 }
Bruce Allan4662e822008-08-26 18:37:06 -07005949 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005950
David Ertman28002092014-02-14 07:16:41 +00005951 /* Allow time for pending master requests to run */
5952 e1000e_disable_pcie_master(&adapter->hw);
5953
5954 return 0;
5955}
5956
5957static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
5958{
5959 struct net_device *netdev = pci_get_drvdata(pdev);
5960 struct e1000_adapter *adapter = netdev_priv(netdev);
5961 struct e1000_hw *hw = &adapter->hw;
5962 u32 ctrl, ctrl_ext, rctl, status;
5963 /* Runtime suspend should only enable wakeup for link changes */
5964 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5965 int retval = 0;
5966
Auke Kokbc7f75f2007-09-17 12:30:59 -07005967 status = er32(STATUS);
5968 if (status & E1000_STATUS_LU)
5969 wufc &= ~E1000_WUFC_LNKC;
5970
5971 if (wufc) {
5972 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005973 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005974
5975 /* turn on all-multi mode if wake on multicast is enabled */
5976 if (wufc & E1000_WUFC_MC) {
5977 rctl = er32(RCTL);
5978 rctl |= E1000_RCTL_MPE;
5979 ew32(RCTL, rctl);
5980 }
5981
5982 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00005983 ctrl |= E1000_CTRL_ADVD3WUC;
5984 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5985 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005986 ew32(CTRL, ctrl);
5987
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005988 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5989 adapter->hw.phy.media_type ==
5990 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005991 /* keep the laser running in D3 */
5992 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005993 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005994 ew32(CTRL_EXT, ctrl_ext);
5995 }
5996
David Ertman63eb48f2014-02-14 07:16:46 +00005997 if (!runtime)
5998 e1000e_power_up_phy(adapter);
5999
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006000 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00006001 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006002
Bruce Allan82776a42009-08-14 14:35:33 +00006003 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00006004 /* enable wakeup by the PHY */
6005 retval = e1000_init_phy_wakeup(adapter, wufc);
6006 if (retval)
6007 return retval;
6008 } else {
6009 /* enable wakeup by the MAC */
6010 ew32(WUFC, wufc);
6011 ew32(WUC, E1000_WUC_PME_EN);
6012 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006013 } else {
6014 ew32(WUC, 0);
6015 ew32(WUFC, 0);
David Ertman28002092014-02-14 07:16:41 +00006016
6017 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006018 }
6019
David Ertman74f350e2014-02-22 03:15:17 +00006020 if (adapter->hw.phy.type == e1000_phy_igp_3) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006021 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
David Ertman74f350e2014-02-22 03:15:17 +00006022 } else if (hw->mac.type == e1000_pch_lpt) {
6023 if (!(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
6024 /* ULP does not support wake from unicast, multicast
6025 * or broadcast.
6026 */
6027 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6028
6029 if (retval)
6030 return retval;
6031 }
6032
Auke Kokbc7f75f2007-09-17 12:30:59 -07006033
Bruce Allane921eb12012-11-28 09:28:37 +00006034 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006035 * would have already happened in close and is redundant.
6036 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006037 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038
Dean Nelson24b41c92013-06-13 03:55:44 +00006039 pci_clear_master(pdev);
6040
Bruce Allane921eb12012-11-28 09:28:37 +00006041 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006042 * correctable error when the MAC transitions from D0 to D3. To
6043 * prevent this we need to mask off the correctable errors on the
6044 * downstream port of the pci-e switch.
Li Zhange8c254c2013-08-13 18:42:58 +00006045 *
6046 * We don't have the associated upstream bridge while assigning
6047 * the PCI device into guest. For example, the KVM on power is
6048 * one of the cases.
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006049 */
6050 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6051 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006052 u16 devctl;
6053
Li Zhange8c254c2013-08-13 18:42:58 +00006054 if (!us_dev)
6055 return 0;
6056
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006057 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6058 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6059 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006060
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006061 pci_save_state(pdev);
6062 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006063
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006064 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006065 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006066
6067 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006068}
6069
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006070/**
6071 * e1000e_disable_aspm - Disable ASPM states
6072 * @pdev: pointer to PCI device struct
6073 * @state: bit-mask of ASPM states to disable
6074 *
6075 * Some devices *must* have certain ASPM states disabled per hardware errata.
6076 **/
6077static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006078{
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006079 struct pci_dev *parent = pdev->bus->self;
6080 u16 aspm_dis_mask = 0;
6081 u16 pdev_aspmc, parent_aspmc;
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006082
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006083 switch (state) {
6084 case PCIE_LINK_STATE_L0S:
6085 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6086 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6087 /* fall-through - can't have L1 without L0s */
6088 case PCIE_LINK_STATE_L1:
6089 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6090 break;
6091 default:
6092 return;
6093 }
6094
6095 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6096 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6097
6098 if (parent) {
6099 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6100 &parent_aspmc);
6101 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6102 }
6103
6104 /* Nothing to do if the ASPM states to be disabled already are */
6105 if (!(pdev_aspmc & aspm_dis_mask) &&
6106 (!parent || !(parent_aspmc & aspm_dis_mask)))
6107 return;
6108
6109 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6110 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6111 "L0s" : "",
6112 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6113 "L1" : "");
6114
6115#ifdef CONFIG_PCIEASPM
6116 pci_disable_link_state_locked(pdev, state);
6117
6118 /* Double-check ASPM control. If not disabled by the above, the
6119 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6120 * not enabled); override by writing PCI config space directly.
6121 */
6122 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6123 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6124
6125 if (!(aspm_dis_mask & pdev_aspmc))
6126 return;
6127#endif
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006128
Bruce Allane921eb12012-11-28 09:28:37 +00006129 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006130 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006131 */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006132 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
Bruce Allan6f461f62010-04-27 03:33:04 +00006133
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006134 if (parent)
6135 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6136 aspm_dis_mask);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006137}
6138
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006139#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006140static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141{
6142 struct net_device *netdev = pci_get_drvdata(pdev);
6143 struct e1000_adapter *adapter = netdev_priv(netdev);
6144 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006145 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006146
Bruce Allan78cd29d2011-03-24 03:09:03 +00006147 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6148 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6149 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6150 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6151 if (aspm_disable_flag)
6152 e1000e_disable_aspm(pdev, aspm_disable_flag);
6153
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006154 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006155
Bruce Allan2fbe4522012-04-19 03:21:47 +00006156 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006157 e1000_resume_workarounds_pchlan(&adapter->hw);
6158
Auke Kokbc7f75f2007-09-17 12:30:59 -07006159 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006160
6161 /* report the system wakeup cause from S3/S4 */
6162 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6163 u16 phy_data;
6164
6165 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6166 if (phy_data) {
6167 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006168 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6169 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6170 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6171 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6172 phy_data & E1000_WUS_LNKC ?
6173 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006174 }
6175 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6176 } else {
6177 u32 wus = er32(WUS);
6178 if (wus) {
6179 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006180 wus & E1000_WUS_EX ? "Unicast Packet" :
6181 wus & E1000_WUS_MC ? "Multicast Packet" :
6182 wus & E1000_WUS_BC ? "Broadcast Packet" :
6183 wus & E1000_WUS_MAG ? "Magic Packet" :
6184 wus & E1000_WUS_LNKC ? "Link Status Change" :
6185 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006186 }
6187 ew32(WUS, ~0);
6188 }
6189
Auke Kokbc7f75f2007-09-17 12:30:59 -07006190 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191
Bruce Allancd791612010-05-10 14:59:51 +00006192 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006193
Bruce Allane921eb12012-11-28 09:28:37 +00006194 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006195 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006196 * under the control of the driver.
6197 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006198 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006199 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200
6201 return 0;
6202}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006203
David Ertman28002092014-02-14 07:16:41 +00006204static int e1000e_pm_thaw(struct device *dev)
6205{
6206 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6207 struct e1000_adapter *adapter = netdev_priv(netdev);
6208
6209 e1000e_set_interrupt_capability(adapter);
6210 if (netif_running(netdev)) {
6211 u32 err = e1000_request_irq(adapter);
6212
6213 if (err)
6214 return err;
6215
6216 e1000e_up(adapter);
6217 }
6218
6219 netif_device_attach(netdev);
6220
6221 return 0;
6222}
6223
Mika Westerberg38a529b2014-01-16 14:39:39 +02006224#ifdef CONFIG_PM_SLEEP
David Ertman28002092014-02-14 07:16:41 +00006225static int e1000e_pm_suspend(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006226{
6227 struct pci_dev *pdev = to_pci_dev(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006228
David Ertman28002092014-02-14 07:16:41 +00006229 e1000e_pm_freeze(dev);
6230
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006231 return __e1000_shutdown(pdev, false);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006232}
6233
David Ertman28002092014-02-14 07:16:41 +00006234static int e1000e_pm_resume(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006235{
6236 struct pci_dev *pdev = to_pci_dev(dev);
David Ertman28002092014-02-14 07:16:41 +00006237 int rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006238
David Ertman28002092014-02-14 07:16:41 +00006239 rc = __e1000_resume(pdev);
6240 if (rc)
6241 return rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006242
David Ertman28002092014-02-14 07:16:41 +00006243 return e1000e_pm_thaw(dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006244}
Mika Westerberg38a529b2014-01-16 14:39:39 +02006245#endif /* CONFIG_PM_SLEEP */
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006246
6247#ifdef CONFIG_PM_RUNTIME
David Ertman63eb48f2014-02-14 07:16:46 +00006248static int e1000e_pm_runtime_idle(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006249{
6250 struct pci_dev *pdev = to_pci_dev(dev);
6251 struct net_device *netdev = pci_get_drvdata(pdev);
6252 struct e1000_adapter *adapter = netdev_priv(netdev);
6253
David Ertman63eb48f2014-02-14 07:16:46 +00006254 if (!e1000e_has_link(adapter))
6255 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006256
6257 return -EBUSY;
6258}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006259
David Ertman63eb48f2014-02-14 07:16:46 +00006260static int e1000e_pm_runtime_resume(struct device *dev)
6261{
6262 struct pci_dev *pdev = to_pci_dev(dev);
6263 struct net_device *netdev = pci_get_drvdata(pdev);
6264 struct e1000_adapter *adapter = netdev_priv(netdev);
6265 int rc;
6266
6267 rc = __e1000_resume(pdev);
6268 if (rc)
6269 return rc;
6270
6271 if (netdev->flags & IFF_UP)
6272 rc = e1000e_up(adapter);
6273
6274 return rc;
6275}
6276
6277static int e1000e_pm_runtime_suspend(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006278{
6279 struct pci_dev *pdev = to_pci_dev(dev);
6280 struct net_device *netdev = pci_get_drvdata(pdev);
6281 struct e1000_adapter *adapter = netdev_priv(netdev);
6282
David Ertman63eb48f2014-02-14 07:16:46 +00006283 if (netdev->flags & IFF_UP) {
6284 int count = E1000_CHECK_RESET_COUNT;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006285
David Ertman63eb48f2014-02-14 07:16:46 +00006286 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
6287 usleep_range(10000, 20000);
6288
6289 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
6290
6291 /* Down the device without resetting the hardware */
6292 e1000e_down(adapter, false);
6293 }
6294
6295 if (__e1000_shutdown(pdev, true)) {
6296 e1000e_pm_runtime_resume(dev);
6297 return -EBUSY;
6298 }
6299
6300 return 0;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006301}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006302#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006303#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006304
6305static void e1000_shutdown(struct pci_dev *pdev)
6306{
David Ertman28002092014-02-14 07:16:41 +00006307 e1000e_pm_freeze(&pdev->dev);
6308
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006309 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006310}
6311
6312#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006313
Bruce Allan8bb62862013-01-16 08:46:49 +00006314static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006315{
6316 struct net_device *netdev = data;
6317 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006318
6319 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006320 int vector, msix_irq;
6321
Dongdong Deng147b2c82010-11-16 19:50:15 -08006322 vector = 0;
6323 msix_irq = adapter->msix_entries[vector].vector;
6324 disable_irq(msix_irq);
6325 e1000_intr_msix_rx(msix_irq, netdev);
6326 enable_irq(msix_irq);
6327
6328 vector++;
6329 msix_irq = adapter->msix_entries[vector].vector;
6330 disable_irq(msix_irq);
6331 e1000_intr_msix_tx(msix_irq, netdev);
6332 enable_irq(msix_irq);
6333
6334 vector++;
6335 msix_irq = adapter->msix_entries[vector].vector;
6336 disable_irq(msix_irq);
6337 e1000_msix_other(msix_irq, netdev);
6338 enable_irq(msix_irq);
6339 }
6340
6341 return IRQ_HANDLED;
6342}
6343
Bruce Allane921eb12012-11-28 09:28:37 +00006344/**
6345 * e1000_netpoll
6346 * @netdev: network interface device structure
6347 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006348 * Polling 'interrupt' - used by things like netconsole to send skbs
6349 * without having to re-enable interrupts. It's not called while
6350 * the interrupt routine is executing.
6351 */
6352static void e1000_netpoll(struct net_device *netdev)
6353{
6354 struct e1000_adapter *adapter = netdev_priv(netdev);
6355
Dongdong Deng147b2c82010-11-16 19:50:15 -08006356 switch (adapter->int_mode) {
6357 case E1000E_INT_MODE_MSIX:
6358 e1000_intr_msix(adapter->pdev->irq, netdev);
6359 break;
6360 case E1000E_INT_MODE_MSI:
6361 disable_irq(adapter->pdev->irq);
6362 e1000_intr_msi(adapter->pdev->irq, netdev);
6363 enable_irq(adapter->pdev->irq);
6364 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00006365 default: /* E1000E_INT_MODE_LEGACY */
Dongdong Deng147b2c82010-11-16 19:50:15 -08006366 disable_irq(adapter->pdev->irq);
6367 e1000_intr(adapter->pdev->irq, netdev);
6368 enable_irq(adapter->pdev->irq);
6369 break;
6370 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006371}
6372#endif
6373
6374/**
6375 * e1000_io_error_detected - called when PCI error is detected
6376 * @pdev: Pointer to PCI device
6377 * @state: The current pci connection state
6378 *
6379 * This function is called after a PCI bus error affecting
6380 * this device has been detected.
6381 */
6382static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6383 pci_channel_state_t state)
6384{
6385 struct net_device *netdev = pci_get_drvdata(pdev);
6386 struct e1000_adapter *adapter = netdev_priv(netdev);
6387
6388 netif_device_detach(netdev);
6389
Mike Masonc93b5a72009-06-30 12:45:53 +00006390 if (state == pci_channel_io_perm_failure)
6391 return PCI_ERS_RESULT_DISCONNECT;
6392
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00006394 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006395 pci_disable_device(pdev);
6396
6397 /* Request a slot slot reset. */
6398 return PCI_ERS_RESULT_NEED_RESET;
6399}
6400
6401/**
6402 * e1000_io_slot_reset - called after the pci bus has been reset.
6403 * @pdev: Pointer to PCI device
6404 *
6405 * Restart the card from scratch, as if from a cold-boot. Implementation
David Ertman28002092014-02-14 07:16:41 +00006406 * resembles the first-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006407 */
6408static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6409{
6410 struct net_device *netdev = pci_get_drvdata(pdev);
6411 struct e1000_adapter *adapter = netdev_priv(netdev);
6412 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006413 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006414 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006415 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416
Bruce Allan78cd29d2011-03-24 03:09:03 +00006417 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6418 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006419 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006420 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6421 if (aspm_disable_flag)
6422 e1000e_disable_aspm(pdev, aspm_disable_flag);
6423
Bruce Allanf0f422e2008-08-04 17:21:53 -07006424 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006425 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006426 dev_err(&pdev->dev,
6427 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006428 result = PCI_ERS_RESULT_DISCONNECT;
6429 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006430 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006431 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006432 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006433
6434 pci_enable_wake(pdev, PCI_D3hot, 0);
6435 pci_enable_wake(pdev, PCI_D3cold, 0);
6436
6437 e1000e_reset(adapter);
6438 ew32(WUS, ~0);
6439 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006440 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006441
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006442 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006443
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006444 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006445}
6446
6447/**
6448 * e1000_io_resume - called when traffic can start flowing again.
6449 * @pdev: Pointer to PCI device
6450 *
6451 * This callback is called when the error recovery driver tells us that
6452 * its OK to resume normal operation. Implementation resembles the
David Ertman28002092014-02-14 07:16:41 +00006453 * second-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006454 */
6455static void e1000_io_resume(struct pci_dev *pdev)
6456{
6457 struct net_device *netdev = pci_get_drvdata(pdev);
6458 struct e1000_adapter *adapter = netdev_priv(netdev);
6459
Bruce Allancd791612010-05-10 14:59:51 +00006460 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006461
6462 if (netif_running(netdev)) {
6463 if (e1000e_up(adapter)) {
6464 dev_err(&pdev->dev,
6465 "can't bring device back up after reset\n");
6466 return;
6467 }
6468 }
6469
6470 netif_device_attach(netdev);
6471
Bruce Allane921eb12012-11-28 09:28:37 +00006472 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006473 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006474 * under the control of the driver.
6475 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006476 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006477 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006478}
6479
6480static void e1000_print_device_info(struct e1000_adapter *adapter)
6481{
6482 struct e1000_hw *hw = &adapter->hw;
6483 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006484 u32 ret_val;
6485 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006486
6487 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006488 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006489 /* bus width */
6490 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006491 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006492 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006493 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006494 e_info("Intel(R) PRO/%s Network Connection\n",
6495 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006496 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6497 E1000_PBANUM_LENGTH);
6498 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006499 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006500 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6501 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006502}
6503
Auke Kok10aa4c02008-08-04 17:21:20 -07006504static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6505{
6506 struct e1000_hw *hw = &adapter->hw;
6507 int ret_val;
6508 u16 buf = 0;
6509
6510 if (hw->mac.type != e1000_82573)
6511 return;
6512
6513 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006514 le16_to_cpus(&buf);
6515 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006516 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006517 dev_warn(&adapter->pdev->dev,
6518 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006519 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006520}
6521
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006522static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006523 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006524{
6525 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006526 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006527
6528 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6529 adapter->flags |= FLAG_TSO_FORCE;
6530
Patrick McHardyf6469682013-04-19 02:04:27 +00006531 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006532 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6533 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006534 return 0;
6535
Ben Greear01840392012-02-11 15:39:25 +00006536 if (changed & NETIF_F_RXFCS) {
6537 if (features & NETIF_F_RXFCS) {
6538 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6539 } else {
6540 /* We need to take it back to defaults, which might mean
6541 * stripping is still disabled at the adapter level.
6542 */
6543 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6544 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6545 else
6546 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6547 }
6548 }
6549
Bruce Allan70495a52012-01-11 01:26:50 +00006550 netdev->features = features;
6551
Bruce Allandc221292011-08-19 03:23:48 +00006552 if (netif_running(netdev))
6553 e1000e_reinit_locked(adapter);
6554 else
6555 e1000e_reset(adapter);
6556
6557 return 0;
6558}
6559
Stephen Hemminger651c2462008-11-19 21:57:48 -08006560static const struct net_device_ops e1000e_netdev_ops = {
6561 .ndo_open = e1000_open,
6562 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006563 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006564 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006565 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006566 .ndo_set_mac_address = e1000_set_mac,
6567 .ndo_change_mtu = e1000_change_mtu,
6568 .ndo_do_ioctl = e1000_ioctl,
6569 .ndo_tx_timeout = e1000_tx_timeout,
6570 .ndo_validate_addr = eth_validate_addr,
6571
Stephen Hemminger651c2462008-11-19 21:57:48 -08006572 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6573 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6574#ifdef CONFIG_NET_POLL_CONTROLLER
6575 .ndo_poll_controller = e1000_netpoll,
6576#endif
Bruce Allandc221292011-08-19 03:23:48 +00006577 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006578};
6579
Auke Kokbc7f75f2007-09-17 12:30:59 -07006580/**
6581 * e1000_probe - Device Initialization Routine
6582 * @pdev: PCI device information struct
6583 * @ent: entry in e1000_pci_tbl
6584 *
6585 * Returns 0 on success, negative on failure
6586 *
6587 * e1000_probe initializes an adapter identified by a pci_dev structure.
6588 * The OS initialization, configuring of the adapter private structure,
6589 * and a hardware reset occur.
6590 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006591static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006592{
6593 struct net_device *netdev;
6594 struct e1000_adapter *adapter;
6595 struct e1000_hw *hw;
6596 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006597 resource_size_t mmio_start, mmio_len;
6598 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006599 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006600 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006601 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006602 u16 eeprom_data = 0;
6603 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6604
Bruce Allan78cd29d2011-03-24 03:09:03 +00006605 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6606 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006607 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006608 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6609 if (aspm_disable_flag)
6610 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006611
Bruce Allanf0f422e2008-08-04 17:21:53 -07006612 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006613 if (err)
6614 return err;
6615
6616 pci_using_dac = 0;
Russell King718a39e2013-06-10 12:22:30 +01006617 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006618 if (!err) {
Russell King718a39e2013-06-10 12:22:30 +01006619 pci_using_dac = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006620 } else {
Russell King718a39e2013-06-10 12:22:30 +01006621 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006622 if (err) {
Russell King718a39e2013-06-10 12:22:30 +01006623 dev_err(&pdev->dev,
6624 "No usable DMA configuration, aborting\n");
6625 goto err_dma;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006626 }
6627 }
6628
Bruce Allan17e813e2013-02-20 04:06:01 +00006629 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6630 err = pci_request_selected_regions_exclusive(pdev, bars,
6631 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006632 if (err)
6633 goto err_pci_reg;
6634
Xiaotian Feng68eac462009-08-14 14:35:52 +00006635 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006636 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006637
Auke Kokbc7f75f2007-09-17 12:30:59 -07006638 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006639 /* PCI config space info */
6640 err = pci_save_state(pdev);
6641 if (err)
6642 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006643
6644 err = -ENOMEM;
6645 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6646 if (!netdev)
6647 goto err_alloc_etherdev;
6648
Auke Kokbc7f75f2007-09-17 12:30:59 -07006649 SET_NETDEV_DEV(netdev, &pdev->dev);
6650
Tom Herbertf85e4df2010-05-05 14:03:32 +00006651 netdev->irq = pdev->irq;
6652
Auke Kokbc7f75f2007-09-17 12:30:59 -07006653 pci_set_drvdata(pdev, netdev);
6654 adapter = netdev_priv(netdev);
6655 hw = &adapter->hw;
6656 adapter->netdev = netdev;
6657 adapter->pdev = pdev;
6658 adapter->ei = ei;
6659 adapter->pba = ei->pba;
6660 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006661 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006662 adapter->hw.adapter = adapter;
6663 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006664 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006665 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006666
6667 mmio_start = pci_resource_start(pdev, 0);
6668 mmio_len = pci_resource_len(pdev, 0);
6669
6670 err = -EIO;
6671 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6672 if (!adapter->hw.hw_addr)
6673 goto err_ioremap;
6674
6675 if ((adapter->flags & FLAG_HAS_FLASH) &&
6676 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6677 flash_start = pci_resource_start(pdev, 1);
6678 flash_len = pci_resource_len(pdev, 1);
6679 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6680 if (!adapter->hw.flash_address)
6681 goto err_flashmap;
6682 }
6683
Bruce Alland495bcb2013-03-20 07:23:11 +00006684 /* Set default EEE advertisement */
6685 if (adapter->flags2 & FLAG2_HAS_EEE)
6686 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
6687
Auke Kokbc7f75f2007-09-17 12:30:59 -07006688 /* construct the net_device struct */
Bruce Allane80bd1d2013-05-01 01:19:46 +00006689 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006690 e1000e_set_ethtool_ops(netdev);
Bruce Allane80bd1d2013-05-01 01:19:46 +00006691 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006692 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006693 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006694
6695 netdev->mem_start = mmio_start;
6696 netdev->mem_end = mmio_start + mmio_len;
6697
6698 adapter->bd_number = cards_found++;
6699
Bruce Allan4662e822008-08-26 18:37:06 -07006700 e1000e_check_options(adapter);
6701
Auke Kokbc7f75f2007-09-17 12:30:59 -07006702 /* setup adapter struct */
6703 err = e1000_sw_init(adapter);
6704 if (err)
6705 goto err_sw_init;
6706
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6708 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6709 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6710
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006711 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712 if (err)
6713 goto err_hw_init;
6714
Bruce Allan4a770352008-10-01 17:18:35 -07006715 if ((adapter->flags & FLAG_IS_ICH) &&
6716 (adapter->flags & FLAG_READ_ONLY_NVM))
6717 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6718
Auke Kokbc7f75f2007-09-17 12:30:59 -07006719 hw->mac.ops.get_bus_info(&adapter->hw);
6720
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006721 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006722
6723 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006724 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006725 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6726 adapter->hw.phy.disable_polarity_correction = 0;
6727 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6728 }
6729
Bruce Allan470a5422012-05-26 06:08:48 +00006730 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006731 dev_info(&pdev->dev,
6732 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006733
Bruce Allandc221292011-08-19 03:23:48 +00006734 /* Set initial default active device features */
6735 netdev->features = (NETIF_F_SG |
Patrick McHardyf6469682013-04-19 02:04:27 +00006736 NETIF_F_HW_VLAN_CTAG_RX |
6737 NETIF_F_HW_VLAN_CTAG_TX |
Bruce Allandc221292011-08-19 03:23:48 +00006738 NETIF_F_TSO |
6739 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006740 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006741 NETIF_F_RXCSUM |
6742 NETIF_F_HW_CSUM);
6743
6744 /* Set user-changeable features (subset of all device features) */
6745 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006746 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006747 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006748 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006749
6750 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardyf6469682013-04-19 02:04:27 +00006751 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006752
Bruce Allandc221292011-08-19 03:23:48 +00006753 netdev->vlan_features |= (NETIF_F_SG |
6754 NETIF_F_TSO |
6755 NETIF_F_TSO6 |
6756 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006757
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006758 netdev->priv_flags |= IFF_UNICAST_FLT;
6759
Yi Zou7b872a52010-09-22 17:57:58 +00006760 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006761 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006762 netdev->vlan_features |= NETIF_F_HIGHDMA;
6763 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006764
Auke Kokbc7f75f2007-09-17 12:30:59 -07006765 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6766 adapter->flags |= FLAG_MNG_PT_ENABLED;
6767
Bruce Allane921eb12012-11-28 09:28:37 +00006768 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006769 * put the device in a known good starting state
6770 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006771 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6772
Bruce Allane921eb12012-11-28 09:28:37 +00006773 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006774 * attempt. Let's give it a few tries
6775 */
6776 for (i = 0;; i++) {
6777 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6778 break;
6779 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006780 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006781 err = -EIO;
6782 goto err_eeprom;
6783 }
6784 }
6785
Auke Kok10aa4c02008-08-04 17:21:20 -07006786 e1000_eeprom_checks(adapter);
6787
Bruce Allan608f8a02010-01-13 02:04:58 +00006788 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006789 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006790 dev_err(&pdev->dev,
6791 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006792
6793 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006794
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006795 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006796 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006797 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006798 err = -EIO;
6799 goto err_eeprom;
6800 }
6801
6802 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006803 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006804 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006805
6806 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006807 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006808 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809
6810 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6811 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006812 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6813 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006814 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006815
Auke Kokbc7f75f2007-09-17 12:30:59 -07006816 /* Initialize link parameters. User can change them with ethtool */
6817 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006818 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006819 adapter->hw.fc.requested_mode = e1000_fc_default;
6820 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006821 adapter->hw.phy.autoneg_advertised = 0x2f;
6822
Bruce Allane921eb12012-11-28 09:28:37 +00006823 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006824 * the EEPROM, enable the ACPI Magic Packet filter
6825 */
6826 if (adapter->flags & FLAG_APME_IN_WUC) {
6827 /* APME bit in EEPROM is mapped to WUC.APME */
6828 eeprom_data = er32(WUC);
6829 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006830 if ((hw->mac.type > e1000_ich10lan) &&
6831 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006832 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006833 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6834 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6835 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006836 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6837 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006838 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006839 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6840 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006841 }
6842
6843 /* fetch WoL from EEPROM */
6844 if (eeprom_data & eeprom_apme_mask)
6845 adapter->eeprom_wol |= E1000_WUFC_MAG;
6846
Bruce Allane921eb12012-11-28 09:28:37 +00006847 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006848 * where the eeprom may be wrong or the board simply won't support
6849 * wake on lan on a particular port
6850 */
6851 if (!(adapter->flags & FLAG_HAS_WOL))
6852 adapter->eeprom_wol = 0;
6853
6854 /* initialize the wol settings based on the eeprom settings */
6855 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006856
6857 /* make sure adapter isn't asleep if manageability is enabled */
6858 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
6859 (hw->mac.ops.check_mng_mode(hw)))
6860 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006861
Bruce Allan84527592008-11-21 17:00:22 -08006862 /* save off EEPROM version number */
6863 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6864
Auke Kokbc7f75f2007-09-17 12:30:59 -07006865 /* reset the hardware with the new settings */
6866 e1000e_reset(adapter);
6867
Bruce Allane921eb12012-11-28 09:28:37 +00006868 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006869 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006870 * under the control of the driver.
6871 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006872 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006873 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006874
Bruce Allanf2315bf2011-12-16 00:46:59 +00006875 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006876 err = register_netdev(netdev);
6877 if (err)
6878 goto err_register;
6879
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006880 /* carrier off reporting is important to ethtool even BEFORE open */
6881 netif_carrier_off(netdev);
6882
Bruce Alland89777b2013-01-19 01:09:58 +00006883 /* init PTP hardware clock */
6884 e1000e_ptp_init(adapter);
6885
Auke Kokbc7f75f2007-09-17 12:30:59 -07006886 e1000_print_device_info(adapter);
6887
Alan Sternf3ec4f82010-06-08 15:23:51 -04006888 if (pci_dev_run_wake(pdev))
6889 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006890
Auke Kokbc7f75f2007-09-17 12:30:59 -07006891 return 0;
6892
6893err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006894 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006895 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006896err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006897 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006898 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006899err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006900 kfree(adapter->tx_ring);
6901 kfree(adapter->rx_ring);
6902err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006903 if (adapter->hw.flash_address)
6904 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006905 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006906err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006907 iounmap(adapter->hw.hw_addr);
6908err_ioremap:
6909 free_netdev(netdev);
6910err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006911 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006912 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006913err_pci_reg:
6914err_dma:
6915 pci_disable_device(pdev);
6916 return err;
6917}
6918
6919/**
6920 * e1000_remove - Device Removal Routine
6921 * @pdev: PCI device information struct
6922 *
6923 * e1000_remove is called by the PCI subsystem to alert the driver
6924 * that it should release a PCI device. The could be caused by a
6925 * Hot-Plug event, or because the driver is going to be removed from
6926 * memory.
6927 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006928static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006929{
6930 struct net_device *netdev = pci_get_drvdata(pdev);
6931 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006932 bool down = test_bit(__E1000_DOWN, &adapter->state);
6933
Bruce Alland89777b2013-01-19 01:09:58 +00006934 e1000e_ptp_remove(adapter);
6935
Bruce Allane921eb12012-11-28 09:28:37 +00006936 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006937 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006938 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006939 if (!down)
6940 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006941 del_timer_sync(&adapter->watchdog_timer);
6942 del_timer_sync(&adapter->phy_info_timer);
6943
Bruce Allan41cec6f2009-11-20 23:28:56 +00006944 cancel_work_sync(&adapter->reset_task);
6945 cancel_work_sync(&adapter->watchdog_task);
6946 cancel_work_sync(&adapter->downshift_task);
6947 cancel_work_sync(&adapter->update_phy_task);
6948 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006949
Bruce Allanb67e1912012-12-27 08:32:33 +00006950 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6951 cancel_work_sync(&adapter->tx_hwtstamp_work);
6952 if (adapter->tx_hwtstamp_skb) {
6953 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6954 adapter->tx_hwtstamp_skb = NULL;
6955 }
6956 }
6957
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006958 /* Don't lie to e1000_close() down the road. */
6959 if (!down)
6960 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006961 unregister_netdev(netdev);
6962
Alan Sternf3ec4f82010-06-08 15:23:51 -04006963 if (pci_dev_run_wake(pdev))
6964 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006965
Bruce Allane921eb12012-11-28 09:28:37 +00006966 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006967 * would have already happened in close and is redundant.
6968 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006969 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006970
Bruce Allan4662e822008-08-26 18:37:06 -07006971 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006972 kfree(adapter->tx_ring);
6973 kfree(adapter->rx_ring);
6974
6975 iounmap(adapter->hw.hw_addr);
6976 if (adapter->hw.flash_address)
6977 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006978 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006979 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006980
6981 free_netdev(netdev);
6982
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006983 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006984 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006985
Auke Kokbc7f75f2007-09-17 12:30:59 -07006986 pci_disable_device(pdev);
6987}
6988
6989/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006990static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006991 .error_detected = e1000_io_error_detected,
6992 .slot_reset = e1000_io_slot_reset,
6993 .resume = e1000_io_resume,
6994};
6995
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006996static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6998 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6999 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00007000 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7001 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7003 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07007004 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7005 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7006 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07007007
Auke Kokbc7f75f2007-09-17 12:30:59 -07007008 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7009 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7010 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7011 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07007012
Auke Kokbc7f75f2007-09-17 12:30:59 -07007013 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7014 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7015 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07007016
Bruce Allan4662e822008-08-26 18:37:06 -07007017 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07007018 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00007019 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07007020
Auke Kokbc7f75f2007-09-17 12:30:59 -07007021 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7022 board_80003es2lan },
7023 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7024 board_80003es2lan },
7025 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7026 board_80003es2lan },
7027 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7028 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07007029
Auke Kokbc7f75f2007-09-17 12:30:59 -07007030 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7031 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7032 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7033 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7034 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7035 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7036 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00007037 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07007038
Auke Kokbc7f75f2007-09-17 12:30:59 -07007039 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7040 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7041 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7042 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7043 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07007044 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07007045 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7046 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7047 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7048
7049 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7050 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7051 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007052
Bruce Allanf4187b52008-08-26 18:36:50 -07007053 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7054 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00007055 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07007056
Bruce Allana4f58f52009-06-02 11:29:18 +00007057 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7058 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7059 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7060 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7061
Bruce Alland3738bb2010-06-16 13:27:28 +00007062 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7063 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7064
Bruce Allan2fbe4522012-04-19 03:21:47 +00007065 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7066 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007067 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7068 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan91a3d822013-06-29 01:15:16 +00007069 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7070 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7071 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7072 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007073
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007074 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007075};
7076MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7077
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007078static const struct dev_pm_ops e1000_pm_ops = {
David Ertman28002092014-02-14 07:16:41 +00007079 .suspend = e1000e_pm_suspend,
7080 .resume = e1000e_pm_resume,
7081 .freeze = e1000e_pm_freeze,
7082 .thaw = e1000e_pm_thaw,
7083 .poweroff = e1000e_pm_suspend,
7084 .restore = e1000e_pm_resume,
David Ertman63eb48f2014-02-14 07:16:46 +00007085 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7086 e1000e_pm_runtime_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007087};
7088
Auke Kokbc7f75f2007-09-17 12:30:59 -07007089/* PCI Device API Driver */
7090static struct pci_driver e1000_driver = {
7091 .name = e1000e_driver_name,
7092 .id_table = e1000_pci_tbl,
7093 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007094 .remove = e1000_remove,
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007095 .driver = {
7096 .pm = &e1000_pm_ops,
7097 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007098 .shutdown = e1000_shutdown,
7099 .err_handler = &e1000_err_handler
7100};
7101
7102/**
7103 * e1000_init_module - Driver Registration Routine
7104 *
7105 * e1000_init_module is the first routine called when the driver is
7106 * loaded. All it does is register with the PCI subsystem.
7107 **/
7108static int __init e1000_init_module(void)
7109{
7110 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007111 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7112 e1000e_driver_version);
David Ertmane78b80b2014-02-04 01:56:06 +00007113 pr_info("Copyright(c) 1999 - 2014 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007114 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007115
Auke Kokbc7f75f2007-09-17 12:30:59 -07007116 return ret;
7117}
7118module_init(e1000_init_module);
7119
7120/**
7121 * e1000_exit_module - Driver Exit Cleanup Routine
7122 *
7123 * e1000_exit_module is called just before the driver is removed
7124 * from memory.
7125 **/
7126static void __exit e1000_exit_module(void)
7127{
7128 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007129}
7130module_exit(e1000_exit_module);
7131
Auke Kokbc7f75f2007-09-17 12:30:59 -07007132MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7133MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7134MODULE_LICENSE("GPL");
7135MODULE_VERSION(DRV_VERSION);
7136
Bruce Allan06c24b92012-02-23 03:13:13 +00007137/* netdev.c */