blob: 6bd1832e3f3e72636f4d478e278e1a8b0f8f1569 [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)
Tom Herberte25909b2013-12-18 16:46:48 +0000881 skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
Bruce Allan70495a52012-01-11 01:26:50 +0000882}
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 }
Jeff Kirsher09357b02011-11-18 14:25:00 +00001093 adapter->tx_hang_recheck = false;
David Ertmand9554e92014-01-08 01:07:55 +00001094
1095 if (er32(TDH(0)) == er32(TDT(0))) {
1096 e_dbg("false hang detected, ignoring\n");
1097 return;
1098 }
1099
1100 /* Real hang detected */
Jeff Kirsher09357b02011-11-18 14:25:00 +00001101 netif_stop_queue(netdev);
1102
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001103 e1e_rphy(hw, MII_BMSR, &phy_status);
1104 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1105 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001106
1107 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1108
1109 /* detected Hardware unit hang */
1110 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001111 " TDH <%x>\n"
1112 " TDT <%x>\n"
1113 " next_to_use <%x>\n"
1114 " next_to_clean <%x>\n"
1115 "buffer_info[next_to_clean]:\n"
1116 " time_stamp <%lx>\n"
1117 " next_to_watch <%x>\n"
1118 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001119 " next_to_watch.status <%x>\n"
1120 "MAC Status <%x>\n"
1121 "PHY Status <%x>\n"
1122 "PHY 1000BASE-T Status <%x>\n"
1123 "PHY Extended Status <%x>\n"
1124 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001125 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1126 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1127 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1128 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001129
David Ertmand9554e92014-01-08 01:07:55 +00001130 e1000e_dump(adapter);
1131
Bruce Allan7c0427e2012-03-20 03:48:08 +00001132 /* Suggest workaround for known h/w issue */
1133 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1134 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135}
1136
1137/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001138 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1139 * @work: pointer to work struct
1140 *
1141 * This work function polls the TSYNCTXCTL valid bit to determine when a
1142 * timestamp has been taken for the current stored skb. The timestamp must
1143 * be for this skb because only one such packet is allowed in the queue.
1144 */
1145static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1146{
1147 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1148 tx_hwtstamp_work);
1149 struct e1000_hw *hw = &adapter->hw;
1150
1151 if (!adapter->tx_hwtstamp_skb)
1152 return;
1153
1154 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1155 struct skb_shared_hwtstamps shhwtstamps;
1156 u64 txstmp;
1157
1158 txstmp = er32(TXSTMPL);
1159 txstmp |= (u64)er32(TXSTMPH) << 32;
1160
1161 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1162
1163 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1164 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1165 adapter->tx_hwtstamp_skb = NULL;
1166 } else {
1167 /* reschedule to check later */
1168 schedule_work(&adapter->tx_hwtstamp_work);
1169 }
1170}
1171
1172/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001173 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001174 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 *
1176 * the return value indicates whether actual cleaning was done, there
1177 * is no guarantee that everything was cleaned
1178 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001179static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180{
Bruce Allan55aa6982011-12-16 00:45:45 +00001181 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182 struct net_device *netdev = adapter->netdev;
1183 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 struct e1000_tx_desc *tx_desc, *eop_desc;
1185 struct e1000_buffer *buffer_info;
1186 unsigned int i, eop;
1187 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001189 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190
1191 i = tx_ring->next_to_clean;
1192 eop = tx_ring->buffer_info[i].next_to_watch;
1193 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1194
Alexander Duyck12d04a32009-03-25 22:05:03 +00001195 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1196 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001197 bool cleaned = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001198 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001199 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 tx_desc = E1000_TX_DESC(*tx_ring, i);
1201 buffer_info = &tx_ring->buffer_info[i];
1202 cleaned = (i == eop);
1203
1204 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001205 total_tx_packets += buffer_info->segs;
1206 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001207 if (buffer_info->skb) {
1208 bytes_compl += buffer_info->skb->len;
1209 pkts_compl++;
1210 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 }
1212
Bruce Allan55aa6982011-12-16 00:45:45 +00001213 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214 tx_desc->upper.data = 0;
1215
1216 i++;
1217 if (i == tx_ring->count)
1218 i = 0;
1219 }
1220
Terry Loftindac87612010-04-09 10:29:49 +00001221 if (i == tx_ring->next_to_use)
1222 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223 eop = tx_ring->buffer_info[i].next_to_watch;
1224 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001225 }
1226
1227 tx_ring->next_to_clean = i;
1228
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001229 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1230
Auke Kokbc7f75f2007-09-17 12:30:59 -07001231#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001232 if (count && netif_carrier_ok(netdev) &&
1233 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 /* Make sure that anybody stopping the queue after this
1235 * sees the new next_to_clean.
1236 */
1237 smp_mb();
1238
1239 if (netif_queue_stopped(netdev) &&
1240 !(test_bit(__E1000_DOWN, &adapter->state))) {
1241 netif_wake_queue(netdev);
1242 ++adapter->restart_queue;
1243 }
1244 }
1245
1246 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001247 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001248 * check with the clearing of time_stamp and movement of i
1249 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001250 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001251 if (tx_ring->buffer_info[i].time_stamp &&
1252 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001253 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001254 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001255 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001256 else
1257 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258 }
1259 adapter->total_tx_bytes += total_tx_bytes;
1260 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001261 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001262}
1263
1264/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001266 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 *
1268 * the return value indicates whether actual cleaning was done, there
1269 * is no guarantee that everything was cleaned
1270 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001271static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1272 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001273{
Bruce Allan55aa6982011-12-16 00:45:45 +00001274 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001275 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001276 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1277 struct net_device *netdev = adapter->netdev;
1278 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001279 struct e1000_buffer *buffer_info, *next_buffer;
1280 struct e1000_ps_page *ps_page;
1281 struct sk_buff *skb;
1282 unsigned int i, j;
1283 u32 length, staterr;
1284 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001285 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1287
1288 i = rx_ring->next_to_clean;
1289 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1290 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1291 buffer_info = &rx_ring->buffer_info[i];
1292
1293 while (staterr & E1000_RXD_STAT_DD) {
1294 if (*work_done >= work_to_do)
1295 break;
1296 (*work_done)++;
1297 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001298 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001299
1300 /* in the packet split case this is header only */
1301 prefetch(skb->data - NET_IP_ALIGN);
1302
1303 i++;
1304 if (i == rx_ring->count)
1305 i = 0;
1306 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1307 prefetch(next_rxd);
1308
1309 next_buffer = &rx_ring->buffer_info[i];
1310
Rusty Russell3db1cd52011-12-19 13:56:45 +00001311 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001312 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001313 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001314 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001315 buffer_info->dma = 0;
1316
Bruce Allanaf667a22010-12-31 06:10:01 +00001317 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001318 if (!(staterr & E1000_RXD_STAT_EOP))
1319 adapter->flags2 |= FLAG2_IS_DISCARDING;
1320
1321 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001322 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001324 if (staterr & E1000_RXD_STAT_EOP)
1325 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001326 goto next_desc;
1327 }
1328
Ben Greearcf955e62012-02-11 15:39:51 +00001329 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1330 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 dev_kfree_skb_irq(skb);
1332 goto next_desc;
1333 }
1334
1335 length = le16_to_cpu(rx_desc->wb.middle.length0);
1336
1337 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001338 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339 dev_kfree_skb_irq(skb);
1340 goto next_desc;
1341 }
1342
1343 /* Good Receive */
1344 skb_put(skb, length);
1345
1346 {
Bruce Allane921eb12012-11-28 09:28:37 +00001347 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001348 * it more efficient than reusing j
1349 */
1350 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001351
Bruce Allane921eb12012-11-28 09:28:37 +00001352 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001353 * packet throughput, so unsplit small packets and
1354 * save the alloc/put only valid in softirq (napi)
1355 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001356 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001357 if (l1 && (l1 <= copybreak) &&
1358 ((length + l1) <= adapter->rx_ps_bsize0)) {
1359 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001360
Bruce Allan0e15df42012-01-31 06:37:11 +00001361 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001362
Bruce Allane921eb12012-11-28 09:28:37 +00001363 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001364 * kmap_atomic, so we can't hold the mapping
1365 * very long
1366 */
1367 dma_sync_single_for_cpu(&pdev->dev,
1368 ps_page->dma,
1369 PAGE_SIZE,
1370 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001371 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001372 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001373 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001374 dma_sync_single_for_device(&pdev->dev,
1375 ps_page->dma,
1376 PAGE_SIZE,
1377 DMA_FROM_DEVICE);
1378
1379 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001380 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1381 if (!(netdev->features & NETIF_F_RXFCS))
1382 l1 -= 4;
1383 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001384
1385 skb_put(skb, l1);
1386 goto copydone;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001387 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001388 }
1389
1390 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1391 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1392 if (!length)
1393 break;
1394
Auke Kok47f44e42007-10-25 13:57:44 -07001395 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001396 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1397 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001398 ps_page->dma = 0;
1399 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1400 ps_page->page = NULL;
1401 skb->len += length;
1402 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001403 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001404 }
1405
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001406 /* strip the ethernet crc, problem is we're using pages now so
1407 * this whole operation can get a little cpu intensive
1408 */
Ben Greear01840392012-02-11 15:39:25 +00001409 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1410 if (!(netdev->features & NETIF_F_RXFCS))
1411 pskb_trim(skb, skb->len - 4);
1412 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001413
Auke Kokbc7f75f2007-09-17 12:30:59 -07001414copydone:
1415 total_rx_bytes += skb->len;
1416 total_rx_packets++;
1417
Bruce Allan2e1706f2012-06-30 20:02:42 +00001418 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001419
Bruce Allan70495a52012-01-11 01:26:50 +00001420 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1421
Auke Kokbc7f75f2007-09-17 12:30:59 -07001422 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001423 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001424 adapter->rx_hdr_split++;
1425
Bruce Allanb67e1912012-12-27 08:32:33 +00001426 e1000_receive_skb(adapter, netdev, skb, staterr,
1427 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001428
1429next_desc:
1430 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1431 buffer_info->skb = NULL;
1432
1433 /* return some buffers to hardware, one at a time is too slow */
1434 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001435 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001436 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437 cleaned_count = 0;
1438 }
1439
1440 /* use prefetched values */
1441 rx_desc = next_rxd;
1442 buffer_info = next_buffer;
1443
1444 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1445 }
1446 rx_ring->next_to_clean = i;
1447
1448 cleaned_count = e1000_desc_unused(rx_ring);
1449 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001450 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001453 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454 return cleaned;
1455}
1456
1457/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001458 * e1000_consume_page - helper function
1459 **/
1460static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001461 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001462{
1463 bi->page = NULL;
1464 skb->len += length;
1465 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001466 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001467}
1468
1469/**
1470 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1471 * @adapter: board private structure
1472 *
1473 * the return value indicates whether actual cleaning was done, there
1474 * is no guarantee that everything was cleaned
1475 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001476static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1477 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001478{
Bruce Allan55aa6982011-12-16 00:45:45 +00001479 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001480 struct net_device *netdev = adapter->netdev;
1481 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001482 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001483 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001484 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001485 unsigned int i;
1486 int cleaned_count = 0;
1487 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001488 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001489 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490
1491 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001492 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1493 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001494 buffer_info = &rx_ring->buffer_info[i];
1495
Bruce Allan5f450212011-07-22 06:21:46 +00001496 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001497 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001498
1499 if (*work_done >= work_to_do)
1500 break;
1501 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001502 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001504 skb = buffer_info->skb;
1505 buffer_info->skb = NULL;
1506
1507 ++i;
1508 if (i == rx_ring->count)
1509 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001510 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001511 prefetch(next_rxd);
1512
1513 next_buffer = &rx_ring->buffer_info[i];
1514
1515 cleaned = true;
1516 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001517 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1518 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001519 buffer_info->dma = 0;
1520
Bruce Allan5f450212011-07-22 06:21:46 +00001521 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001522
1523 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001524 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001525 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1526 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001527 /* recycle both page and skb */
1528 buffer_info->skb = skb;
1529 /* an error means any chain goes out the window too */
1530 if (rx_ring->rx_skb_top)
1531 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1532 rx_ring->rx_skb_top = NULL;
1533 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001534 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001535#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001536 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001537 /* this descriptor is only the beginning (or middle) */
1538 if (!rxtop) {
1539 /* this is the beginning of a chain */
1540 rxtop = skb;
1541 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001542 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001543 } else {
1544 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001545 shinfo = skb_shinfo(rxtop);
1546 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1547 buffer_info->page, 0,
1548 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001549 /* re-use the skb, only consumed the page */
1550 buffer_info->skb = skb;
1551 }
1552 e1000_consume_page(buffer_info, rxtop, length);
1553 goto next_desc;
1554 } else {
1555 if (rxtop) {
1556 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001557 shinfo = skb_shinfo(rxtop);
1558 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1559 buffer_info->page, 0,
1560 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001561 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001562 * page
1563 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001564 buffer_info->skb = skb;
1565 skb = rxtop;
1566 rxtop = NULL;
1567 e1000_consume_page(buffer_info, skb, length);
1568 } else {
1569 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001570 * copybreak to save the put_page/alloc_page
1571 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001572 if (length <= copybreak &&
1573 skb_tailroom(skb) >= length) {
1574 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001575 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001576 memcpy(skb_tail_pointer(skb), vaddr,
1577 length);
Cong Wang46790262011-11-25 23:14:23 +08001578 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001580 * buffer_info->page
1581 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001582 skb_put(skb, length);
1583 } else {
1584 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001585 buffer_info->page, 0,
1586 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001587 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001588 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001589 }
1590 }
1591 }
1592
Bruce Allan2e1706f2012-06-30 20:02:42 +00001593 /* Receive Checksum Offload */
1594 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001595
Bruce Allan70495a52012-01-11 01:26:50 +00001596 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1597
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001598 /* probably a little skewed due to removing CRC */
1599 total_rx_bytes += skb->len;
1600 total_rx_packets++;
1601
1602 /* eth type trans needs skb->data to point to something */
1603 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001604 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001605 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001606 goto next_desc;
1607 }
1608
Bruce Allan5f450212011-07-22 06:21:46 +00001609 e1000_receive_skb(adapter, netdev, skb, staterr,
1610 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001611
1612next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001613 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001614
1615 /* return some buffers to hardware, one at a time is too slow */
1616 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001617 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001618 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001619 cleaned_count = 0;
1620 }
1621
1622 /* use prefetched values */
1623 rx_desc = next_rxd;
1624 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001625
1626 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001627 }
1628 rx_ring->next_to_clean = i;
1629
1630 cleaned_count = e1000_desc_unused(rx_ring);
1631 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001632 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001633
1634 adapter->total_rx_bytes += total_rx_bytes;
1635 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001636 return cleaned;
1637}
1638
1639/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001641 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001643static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001644{
Bruce Allan55aa6982011-12-16 00:45:45 +00001645 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646 struct e1000_buffer *buffer_info;
1647 struct e1000_ps_page *ps_page;
1648 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 unsigned int i, j;
1650
1651 /* Free all the Rx ring sk_buffs */
1652 for (i = 0; i < rx_ring->count; i++) {
1653 buffer_info = &rx_ring->buffer_info[i];
1654 if (buffer_info->dma) {
1655 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001656 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001658 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001659 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001660 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001661 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001663 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001664 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001665 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 buffer_info->dma = 0;
1667 }
1668
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001669 if (buffer_info->page) {
1670 put_page(buffer_info->page);
1671 buffer_info->page = NULL;
1672 }
1673
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674 if (buffer_info->skb) {
1675 dev_kfree_skb(buffer_info->skb);
1676 buffer_info->skb = NULL;
1677 }
1678
1679 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001680 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 if (!ps_page->page)
1682 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001683 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1684 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685 ps_page->dma = 0;
1686 put_page(ps_page->page);
1687 ps_page->page = NULL;
1688 }
1689 }
1690
1691 /* there also may be some cached data from a chained receive */
1692 if (rx_ring->rx_skb_top) {
1693 dev_kfree_skb(rx_ring->rx_skb_top);
1694 rx_ring->rx_skb_top = NULL;
1695 }
1696
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 /* Zero out the descriptor ring */
1698 memset(rx_ring->desc, 0, rx_ring->size);
1699
1700 rx_ring->next_to_clean = 0;
1701 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001702 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001703
Bruce Allanc5083cf2011-12-16 00:45:40 +00001704 writel(0, rx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00001705 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00001706 e1000e_update_rdt_wa(rx_ring, 0);
1707 else
1708 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709}
1710
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001711static void e1000e_downshift_workaround(struct work_struct *work)
1712{
1713 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001714 struct e1000_adapter,
1715 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001716
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001717 if (test_bit(__E1000_DOWN, &adapter->state))
1718 return;
1719
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001720 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1721}
1722
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723/**
1724 * e1000_intr_msi - Interrupt Handler
1725 * @irq: interrupt number
1726 * @data: pointer to a network interface device structure
1727 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001728static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729{
1730 struct net_device *netdev = data;
1731 struct e1000_adapter *adapter = netdev_priv(netdev);
1732 struct e1000_hw *hw = &adapter->hw;
1733 u32 icr = er32(ICR);
1734
Bruce Allane921eb12012-11-28 09:28:37 +00001735 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001736 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001737 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001738 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001739 * disconnect (LSC) before accessing any PHY registers
1740 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1742 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001743 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744
Bruce Allane921eb12012-11-28 09:28:37 +00001745 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001747 * adapter in watchdog
1748 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001749 if (netif_carrier_ok(netdev) &&
1750 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1751 /* disable receives */
1752 u32 rctl = er32(RCTL);
1753 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001754 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755 }
1756 /* guard against interrupt when we're going down */
1757 if (!test_bit(__E1000_DOWN, &adapter->state))
1758 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1759 }
1760
Bruce Allan94fb8482013-01-23 09:00:03 +00001761 /* Reset on uncorrectable ECC error */
1762 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1763 u32 pbeccsts = er32(PBECCSTS);
1764
1765 adapter->corr_errors +=
1766 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1767 adapter->uncorr_errors +=
1768 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1769 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1770
1771 /* Do the reset outside of interrupt context */
1772 schedule_work(&adapter->reset_task);
1773
1774 /* return immediately since reset is imminent */
1775 return IRQ_HANDLED;
1776 }
1777
Ben Hutchings288379f2009-01-19 16:43:59 -08001778 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001779 adapter->total_tx_bytes = 0;
1780 adapter->total_tx_packets = 0;
1781 adapter->total_rx_bytes = 0;
1782 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001783 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 }
1785
1786 return IRQ_HANDLED;
1787}
1788
1789/**
1790 * e1000_intr - Interrupt Handler
1791 * @irq: interrupt number
1792 * @data: pointer to a network interface device structure
1793 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001794static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795{
1796 struct net_device *netdev = data;
1797 struct e1000_adapter *adapter = netdev_priv(netdev);
1798 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001800
Bruce Allana68ea772009-11-20 23:23:16 +00001801 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Bruce Allane80bd1d2013-05-01 01:19:46 +00001802 return IRQ_NONE; /* Not our interrupt */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803
Bruce Allane921eb12012-11-28 09:28:37 +00001804 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001805 * not set, then the adapter didn't send an interrupt
1806 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 if (!(icr & E1000_ICR_INT_ASSERTED))
1808 return IRQ_NONE;
1809
Bruce Allane921eb12012-11-28 09:28:37 +00001810 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001811 * interrupts are masked. No need for the
1812 * IMC write
1813 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001814
dave graham573cca82009-02-10 12:52:05 +00001815 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001816 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001817 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001818 * disconnect (LSC) before accessing any PHY registers
1819 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001820 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1821 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001822 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823
Bruce Allane921eb12012-11-28 09:28:37 +00001824 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825 * For packet buffer work-around on link down event;
1826 * disable receives here in the ISR and
1827 * reset adapter in watchdog
1828 */
1829 if (netif_carrier_ok(netdev) &&
1830 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1831 /* disable receives */
1832 rctl = er32(RCTL);
1833 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001834 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835 }
1836 /* guard against interrupt when we're going down */
1837 if (!test_bit(__E1000_DOWN, &adapter->state))
1838 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1839 }
1840
Bruce Allan94fb8482013-01-23 09:00:03 +00001841 /* Reset on uncorrectable ECC error */
1842 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1843 u32 pbeccsts = er32(PBECCSTS);
1844
1845 adapter->corr_errors +=
1846 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1847 adapter->uncorr_errors +=
1848 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1849 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1850
1851 /* Do the reset outside of interrupt context */
1852 schedule_work(&adapter->reset_task);
1853
1854 /* return immediately since reset is imminent */
1855 return IRQ_HANDLED;
1856 }
1857
Ben Hutchings288379f2009-01-19 16:43:59 -08001858 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859 adapter->total_tx_bytes = 0;
1860 adapter->total_tx_packets = 0;
1861 adapter->total_rx_bytes = 0;
1862 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001863 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001864 }
1865
1866 return IRQ_HANDLED;
1867}
1868
Bruce Allan8bb62862013-01-16 08:46:49 +00001869static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001870{
1871 struct net_device *netdev = data;
1872 struct e1000_adapter *adapter = netdev_priv(netdev);
1873 struct e1000_hw *hw = &adapter->hw;
1874 u32 icr = er32(ICR);
1875
1876 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001877 if (!test_bit(__E1000_DOWN, &adapter->state))
1878 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001879 return IRQ_NONE;
1880 }
1881
1882 if (icr & adapter->eiac_mask)
1883 ew32(ICS, (icr & adapter->eiac_mask));
1884
1885 if (icr & E1000_ICR_OTHER) {
1886 if (!(icr & E1000_ICR_LSC))
1887 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001888 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001889 /* guard against interrupt when we're going down */
1890 if (!test_bit(__E1000_DOWN, &adapter->state))
1891 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1892 }
1893
1894no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001895 if (!test_bit(__E1000_DOWN, &adapter->state))
1896 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001897
1898 return IRQ_HANDLED;
1899}
1900
Bruce Allan8bb62862013-01-16 08:46:49 +00001901static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001902{
1903 struct net_device *netdev = data;
1904 struct e1000_adapter *adapter = netdev_priv(netdev);
1905 struct e1000_hw *hw = &adapter->hw;
1906 struct e1000_ring *tx_ring = adapter->tx_ring;
1907
Bruce Allan4662e822008-08-26 18:37:06 -07001908 adapter->total_tx_bytes = 0;
1909 adapter->total_tx_packets = 0;
1910
Bruce Allan55aa6982011-12-16 00:45:45 +00001911 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001912 /* Ring was not completely cleaned, so fire another interrupt */
1913 ew32(ICS, tx_ring->ims_val);
1914
1915 return IRQ_HANDLED;
1916}
1917
Bruce Allan8bb62862013-01-16 08:46:49 +00001918static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001919{
1920 struct net_device *netdev = data;
1921 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001922 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001923
1924 /* Write the ITR value calculated at the end of the
1925 * previous interrupt.
1926 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001927 if (rx_ring->set_itr) {
1928 writel(1000000000 / (rx_ring->itr_val * 256),
1929 rx_ring->itr_register);
1930 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001931 }
1932
Ben Hutchings288379f2009-01-19 16:43:59 -08001933 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001934 adapter->total_rx_bytes = 0;
1935 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001936 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001937 }
1938 return IRQ_HANDLED;
1939}
1940
1941/**
1942 * e1000_configure_msix - Configure MSI-X hardware
1943 *
1944 * e1000_configure_msix sets up the hardware to properly
1945 * generate MSI-X interrupts.
1946 **/
1947static void e1000_configure_msix(struct e1000_adapter *adapter)
1948{
1949 struct e1000_hw *hw = &adapter->hw;
1950 struct e1000_ring *rx_ring = adapter->rx_ring;
1951 struct e1000_ring *tx_ring = adapter->tx_ring;
1952 int vector = 0;
1953 u32 ctrl_ext, ivar = 0;
1954
1955 adapter->eiac_mask = 0;
1956
1957 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1958 if (hw->mac.type == e1000_82574) {
1959 u32 rfctl = er32(RFCTL);
1960 rfctl |= E1000_RFCTL_ACK_DIS;
1961 ew32(RFCTL, rfctl);
1962 }
1963
Bruce Allan4662e822008-08-26 18:37:06 -07001964 /* Configure Rx vector */
1965 rx_ring->ims_val = E1000_IMS_RXQ0;
1966 adapter->eiac_mask |= rx_ring->ims_val;
1967 if (rx_ring->itr_val)
1968 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001969 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001970 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001971 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001972 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1973
1974 /* Configure Tx vector */
1975 tx_ring->ims_val = E1000_IMS_TXQ0;
1976 vector++;
1977 if (tx_ring->itr_val)
1978 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001979 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001980 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001981 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001982 adapter->eiac_mask |= tx_ring->ims_val;
1983 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1984
1985 /* set vector for Other Causes, e.g. link changes */
1986 vector++;
1987 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1988 if (rx_ring->itr_val)
1989 writel(1000000000 / (rx_ring->itr_val * 256),
1990 hw->hw_addr + E1000_EITR_82574(vector));
1991 else
1992 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1993
1994 /* Cause Tx interrupts on every write back */
1995 ivar |= (1 << 31);
1996
1997 ew32(IVAR, ivar);
1998
1999 /* enable MSI-X PBA support */
2000 ctrl_ext = er32(CTRL_EXT);
2001 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2002
2003 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07002004 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2005 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2006 ew32(CTRL_EXT, ctrl_ext);
2007 e1e_flush();
2008}
2009
2010void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2011{
2012 if (adapter->msix_entries) {
2013 pci_disable_msix(adapter->pdev);
2014 kfree(adapter->msix_entries);
2015 adapter->msix_entries = NULL;
2016 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2017 pci_disable_msi(adapter->pdev);
2018 adapter->flags &= ~FLAG_MSI_ENABLED;
2019 }
Bruce Allan4662e822008-08-26 18:37:06 -07002020}
2021
2022/**
2023 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2024 *
2025 * Attempt to configure interrupts using the best available
2026 * capabilities of the hardware and kernel.
2027 **/
2028void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2029{
2030 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002031 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002032
2033 switch (adapter->int_mode) {
2034 case E1000E_INT_MODE_MSIX:
2035 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002036 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2037 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002038 sizeof(struct
2039 msix_entry),
2040 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002041 if (adapter->msix_entries) {
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002042 struct e1000_adapter *a = adapter;
2043
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002044 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002045 adapter->msix_entries[i].entry = i;
2046
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002047 err = pci_enable_msix_range(a->pdev,
2048 a->msix_entries,
2049 a->num_vectors,
2050 a->num_vectors);
2051 if (err > 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002052 return;
2053 }
2054 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002055 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002056 e1000e_reset_interrupt_capability(adapter);
2057 }
2058 adapter->int_mode = E1000E_INT_MODE_MSI;
2059 /* Fall through */
2060 case E1000E_INT_MODE_MSI:
2061 if (!pci_enable_msi(adapter->pdev)) {
2062 adapter->flags |= FLAG_MSI_ENABLED;
2063 } else {
2064 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002065 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002066 }
2067 /* Fall through */
2068 case E1000E_INT_MODE_LEGACY:
2069 /* Don't do anything; this is the system default */
2070 break;
2071 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002072
2073 /* store the number of vectors being used */
2074 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002075}
2076
2077/**
2078 * e1000_request_msix - Initialize MSI-X interrupts
2079 *
2080 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2081 * kernel.
2082 **/
2083static int e1000_request_msix(struct e1000_adapter *adapter)
2084{
2085 struct net_device *netdev = adapter->netdev;
2086 int err = 0, vector = 0;
2087
2088 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002089 snprintf(adapter->rx_ring->name,
2090 sizeof(adapter->rx_ring->name) - 1,
2091 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002092 else
2093 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2094 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002095 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002096 netdev);
2097 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002098 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002099 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2100 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002101 adapter->rx_ring->itr_val = adapter->itr;
2102 vector++;
2103
2104 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002105 snprintf(adapter->tx_ring->name,
2106 sizeof(adapter->tx_ring->name) - 1,
2107 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002108 else
2109 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2110 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002111 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002112 netdev);
2113 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002114 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002115 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2116 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002117 adapter->tx_ring->itr_val = adapter->itr;
2118 vector++;
2119
2120 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002121 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002122 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002123 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002124
2125 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002126
Bruce Allan4662e822008-08-26 18:37:06 -07002127 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002128}
2129
Bruce Allanf8d59f72008-08-08 18:36:11 -07002130/**
2131 * e1000_request_irq - initialize interrupts
2132 *
2133 * Attempts to configure interrupts using the best available
2134 * capabilities of the hardware and kernel.
2135 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002136static int e1000_request_irq(struct e1000_adapter *adapter)
2137{
2138 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002139 int err;
2140
Bruce Allan4662e822008-08-26 18:37:06 -07002141 if (adapter->msix_entries) {
2142 err = e1000_request_msix(adapter);
2143 if (!err)
2144 return err;
2145 /* fall back to MSI */
2146 e1000e_reset_interrupt_capability(adapter);
2147 adapter->int_mode = E1000E_INT_MODE_MSI;
2148 e1000e_set_interrupt_capability(adapter);
2149 }
2150 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002151 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002152 netdev->name, netdev);
2153 if (!err)
2154 return err;
2155
2156 /* fall back to legacy interrupt */
2157 e1000e_reset_interrupt_capability(adapter);
2158 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 }
2160
Joe Perchesa0607fd2009-11-18 23:29:17 -08002161 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002162 netdev->name, netdev);
2163 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002164 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002165
2166 return err;
2167}
2168
2169static void e1000_free_irq(struct e1000_adapter *adapter)
2170{
2171 struct net_device *netdev = adapter->netdev;
2172
Bruce Allan4662e822008-08-26 18:37:06 -07002173 if (adapter->msix_entries) {
2174 int vector = 0;
2175
2176 free_irq(adapter->msix_entries[vector].vector, netdev);
2177 vector++;
2178
2179 free_irq(adapter->msix_entries[vector].vector, netdev);
2180 vector++;
2181
2182 /* Other Causes interrupt vector */
2183 free_irq(adapter->msix_entries[vector].vector, netdev);
2184 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185 }
Bruce Allan4662e822008-08-26 18:37:06 -07002186
2187 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002188}
2189
2190/**
2191 * e1000_irq_disable - Mask off interrupt generation on the NIC
2192 **/
2193static void e1000_irq_disable(struct e1000_adapter *adapter)
2194{
2195 struct e1000_hw *hw = &adapter->hw;
2196
Auke Kokbc7f75f2007-09-17 12:30:59 -07002197 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002198 if (adapter->msix_entries)
2199 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002200 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002201
2202 if (adapter->msix_entries) {
2203 int i;
2204 for (i = 0; i < adapter->num_vectors; i++)
2205 synchronize_irq(adapter->msix_entries[i].vector);
2206 } else {
2207 synchronize_irq(adapter->pdev->irq);
2208 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209}
2210
2211/**
2212 * e1000_irq_enable - Enable default interrupt generation settings
2213 **/
2214static void e1000_irq_enable(struct e1000_adapter *adapter)
2215{
2216 struct e1000_hw *hw = &adapter->hw;
2217
Bruce Allan4662e822008-08-26 18:37:06 -07002218 if (adapter->msix_entries) {
2219 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2220 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002221 } else if (hw->mac.type == e1000_pch_lpt) {
2222 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002223 } else {
2224 ew32(IMS, IMS_ENABLE_MASK);
2225 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002226 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227}
2228
2229/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002230 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231 * @adapter: address of board private structure
2232 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002233 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002234 * For ASF and Pass Through versions of f/w this means that
2235 * the driver is loaded. For AMT version (only with 82573)
2236 * of the f/w this means that the network i/f is open.
2237 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002238void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239{
2240 struct e1000_hw *hw = &adapter->hw;
2241 u32 ctrl_ext;
2242 u32 swsm;
2243
2244 /* Let firmware know the driver has taken over */
2245 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2246 swsm = er32(SWSM);
2247 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2248 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2249 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002250 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 }
2252}
2253
2254/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002255 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002256 * @adapter: address of board private structure
2257 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002258 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 * For ASF and Pass Through versions of f/w this means that the
2260 * driver is no longer loaded. For AMT version (only with 82573) i
2261 * of the f/w this means that the network i/f is closed.
2262 *
2263 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002264void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265{
2266 struct e1000_hw *hw = &adapter->hw;
2267 u32 ctrl_ext;
2268 u32 swsm;
2269
2270 /* Let firmware taken over control of h/w */
2271 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2272 swsm = er32(SWSM);
2273 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2274 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2275 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002276 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277 }
2278}
2279
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002281 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002282 **/
2283static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2284 struct e1000_ring *ring)
2285{
2286 struct pci_dev *pdev = adapter->pdev;
2287
2288 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2289 GFP_KERNEL);
2290 if (!ring->desc)
2291 return -ENOMEM;
2292
2293 return 0;
2294}
2295
2296/**
2297 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002298 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002299 *
2300 * Return 0 on success, negative on failure
2301 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002302int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303{
Bruce Allan55aa6982011-12-16 00:45:45 +00002304 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002305 int err = -ENOMEM, size;
2306
2307 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002308 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 if (!tx_ring->buffer_info)
2310 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311
2312 /* round up to nearest 4K */
2313 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2314 tx_ring->size = ALIGN(tx_ring->size, 4096);
2315
2316 err = e1000_alloc_ring_dma(adapter, tx_ring);
2317 if (err)
2318 goto err;
2319
2320 tx_ring->next_to_use = 0;
2321 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322
2323 return 0;
2324err:
2325 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002326 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327 return err;
2328}
2329
2330/**
2331 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002332 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 *
2334 * Returns 0 on success, negative on failure
2335 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002336int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337{
Bruce Allan55aa6982011-12-16 00:45:45 +00002338 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002339 struct e1000_buffer *buffer_info;
2340 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341
2342 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002343 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 if (!rx_ring->buffer_info)
2345 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002346
Auke Kok47f44e42007-10-25 13:57:44 -07002347 for (i = 0; i < rx_ring->count; i++) {
2348 buffer_info = &rx_ring->buffer_info[i];
2349 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2350 sizeof(struct e1000_ps_page),
2351 GFP_KERNEL);
2352 if (!buffer_info->ps_pages)
2353 goto err_pages;
2354 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002355
2356 desc_len = sizeof(union e1000_rx_desc_packet_split);
2357
2358 /* Round up to nearest 4K */
2359 rx_ring->size = rx_ring->count * desc_len;
2360 rx_ring->size = ALIGN(rx_ring->size, 4096);
2361
2362 err = e1000_alloc_ring_dma(adapter, rx_ring);
2363 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002364 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365
2366 rx_ring->next_to_clean = 0;
2367 rx_ring->next_to_use = 0;
2368 rx_ring->rx_skb_top = NULL;
2369
2370 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002371
2372err_pages:
2373 for (i = 0; i < rx_ring->count; i++) {
2374 buffer_info = &rx_ring->buffer_info[i];
2375 kfree(buffer_info->ps_pages);
2376 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377err:
2378 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002379 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380 return err;
2381}
2382
2383/**
2384 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002385 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002387static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388{
Bruce Allan55aa6982011-12-16 00:45:45 +00002389 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 struct e1000_buffer *buffer_info;
2391 unsigned long size;
2392 unsigned int i;
2393
2394 for (i = 0; i < tx_ring->count; i++) {
2395 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002396 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 }
2398
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002399 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 size = sizeof(struct e1000_buffer) * tx_ring->count;
2401 memset(tx_ring->buffer_info, 0, size);
2402
2403 memset(tx_ring->desc, 0, tx_ring->size);
2404
2405 tx_ring->next_to_use = 0;
2406 tx_ring->next_to_clean = 0;
2407
Bruce Allanc5083cf2011-12-16 00:45:40 +00002408 writel(0, tx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00002409 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00002410 e1000e_update_tdt_wa(tx_ring, 0);
2411 else
2412 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413}
2414
2415/**
2416 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002417 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418 *
2419 * Free all transmit software resources
2420 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002421void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422{
Bruce Allan55aa6982011-12-16 00:45:45 +00002423 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002424 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425
Bruce Allan55aa6982011-12-16 00:45:45 +00002426 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002427
2428 vfree(tx_ring->buffer_info);
2429 tx_ring->buffer_info = NULL;
2430
2431 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2432 tx_ring->dma);
2433 tx_ring->desc = NULL;
2434}
2435
2436/**
2437 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002438 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 *
2440 * Free all receive software resources
2441 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002442void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443{
Bruce Allan55aa6982011-12-16 00:45:45 +00002444 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002446 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447
Bruce Allan55aa6982011-12-16 00:45:45 +00002448 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002449
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002450 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002451 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002452
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453 vfree(rx_ring->buffer_info);
2454 rx_ring->buffer_info = NULL;
2455
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2457 rx_ring->dma);
2458 rx_ring->desc = NULL;
2459}
2460
2461/**
2462 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002463 * @adapter: pointer to adapter
2464 * @itr_setting: current adapter->itr
2465 * @packets: the number of packets during this measurement interval
2466 * @bytes: the number of bytes during this measurement interval
2467 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 * Stores a new ITR value based on packets and byte
2469 * counts during the last interrupt. The advantage of per interrupt
2470 * computation is faster updates and more accurate ITR for the current
2471 * traffic pattern. Constants in this function were computed
2472 * based on theoretical maximum wire speed and thresholds were set based
2473 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002474 * while increasing bulk throughput. This functionality is controlled
2475 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002477static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478{
2479 unsigned int retval = itr_setting;
2480
2481 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002482 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483
2484 switch (itr_setting) {
2485 case lowest_latency:
2486 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002487 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002489 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002491 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002492 case low_latency: /* 50 usec aka 20000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002493 if (bytes > 10000) {
2494 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002495 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002497 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002499 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002501 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 retval = bulk_latency;
2503 } else if (packets <= 2 && bytes < 512) {
2504 retval = lowest_latency;
2505 }
2506 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002507 case bulk_latency: /* 250 usec aka 4000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002509 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002511 } else if (bytes < 6000) {
2512 retval = low_latency;
2513 }
2514 break;
2515 }
2516
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 return retval;
2518}
2519
2520static void e1000_set_itr(struct e1000_adapter *adapter)
2521{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522 u16 current_itr;
2523 u32 new_itr = adapter->itr;
2524
2525 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2526 if (adapter->link_speed != SPEED_1000) {
2527 current_itr = 0;
2528 new_itr = 4000;
2529 goto set_itr_now;
2530 }
2531
Bruce Allan828bac82010-09-29 21:39:37 +00002532 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2533 new_itr = 0;
2534 goto set_itr_now;
2535 }
2536
Bruce Allan8bb62862013-01-16 08:46:49 +00002537 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2538 adapter->total_tx_packets,
2539 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002540 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2541 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2542 adapter->tx_itr = low_latency;
2543
Bruce Allan8bb62862013-01-16 08:46:49 +00002544 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2545 adapter->total_rx_packets,
2546 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2548 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2549 adapter->rx_itr = low_latency;
2550
2551 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2552
Auke Kokbc7f75f2007-09-17 12:30:59 -07002553 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002554 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 case lowest_latency:
2556 new_itr = 70000;
2557 break;
2558 case low_latency:
Bruce Allane80bd1d2013-05-01 01:19:46 +00002559 new_itr = 20000; /* aka hwitr = ~200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 break;
2561 case bulk_latency:
2562 new_itr = 4000;
2563 break;
2564 default:
2565 break;
2566 }
2567
2568set_itr_now:
2569 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002570 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002572 * increasing
2573 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002575 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002576 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002577 adapter->rx_ring->itr_val = new_itr;
2578 if (adapter->msix_entries)
2579 adapter->rx_ring->set_itr = 1;
2580 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002581 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 }
2583}
2584
2585/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002586 * e1000e_write_itr - write the ITR value to the appropriate registers
2587 * @adapter: address of board private structure
2588 * @itr: new ITR value to program
2589 *
2590 * e1000e_write_itr determines if the adapter is in MSI-X mode
2591 * and, if so, writes the EITR registers with the ITR value.
2592 * Otherwise, it writes the ITR value into the ITR register.
2593 **/
2594void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2595{
2596 struct e1000_hw *hw = &adapter->hw;
2597 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2598
2599 if (adapter->msix_entries) {
2600 int vector;
2601
2602 for (vector = 0; vector < adapter->num_vectors; vector++)
2603 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2604 } else {
2605 ew32(ITR, new_itr);
2606 }
2607}
2608
2609/**
Bruce Allan4662e822008-08-26 18:37:06 -07002610 * e1000_alloc_queues - Allocate memory for all rings
2611 * @adapter: board private structure to initialize
2612 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002613static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002614{
Bruce Allan55aa6982011-12-16 00:45:45 +00002615 int size = sizeof(struct e1000_ring);
2616
2617 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002618 if (!adapter->tx_ring)
2619 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002620 adapter->tx_ring->count = adapter->tx_ring_count;
2621 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002622
Bruce Allan55aa6982011-12-16 00:45:45 +00002623 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002624 if (!adapter->rx_ring)
2625 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002626 adapter->rx_ring->count = adapter->rx_ring_count;
2627 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002628
2629 return 0;
2630err:
2631 e_err("Unable to allocate memory for queues\n");
2632 kfree(adapter->rx_ring);
2633 kfree(adapter->tx_ring);
2634 return -ENOMEM;
2635}
2636
2637/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002638 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002639 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002640 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002642static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002643{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002644 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2645 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002646 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002648 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649
Wang Chen4cf16532008-11-12 23:38:14 -08002650 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651
Bruce Allanc58c8a72012-03-20 03:48:19 +00002652 if (!adapter->msix_entries ||
2653 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2654 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002655
Bruce Allanc58c8a72012-03-20 03:48:19 +00002656 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657
Alexander Duyck12d04a32009-03-25 22:05:03 +00002658 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002659 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002660
Bruce Allanc58c8a72012-03-20 03:48:19 +00002661 /* If weight not fully consumed, exit the polling mode */
2662 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 if (adapter->itr_setting & 3)
2664 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002665 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002666 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2667 if (adapter->msix_entries)
2668 ew32(IMS, adapter->rx_ring->ims_val);
2669 else
2670 e1000_irq_enable(adapter);
2671 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 }
2673
2674 return work_done;
2675}
2676
Patrick McHardy80d5c362013-04-19 02:04:28 +00002677static int e1000_vlan_rx_add_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002678 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002679{
2680 struct e1000_adapter *adapter = netdev_priv(netdev);
2681 struct e1000_hw *hw = &adapter->hw;
2682 u32 vfta, index;
2683
2684 /* don't update vlan cookie if already programmed */
2685 if ((adapter->hw.mng_cookie.status &
2686 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2687 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002688 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002689
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002691 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2692 index = (vid >> 5) & 0x7F;
2693 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2694 vfta |= (1 << (vid & 0x1F));
2695 hw->mac.ops.write_vfta(hw, index, vfta);
2696 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002697
2698 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002699
2700 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701}
2702
Patrick McHardy80d5c362013-04-19 02:04:28 +00002703static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002704 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705{
2706 struct e1000_adapter *adapter = netdev_priv(netdev);
2707 struct e1000_hw *hw = &adapter->hw;
2708 u32 vfta, index;
2709
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710 if ((adapter->hw.mng_cookie.status &
2711 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2712 (vid == adapter->mng_vlan_id)) {
2713 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002714 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002715 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 }
2717
2718 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002719 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2720 index = (vid >> 5) & 0x7F;
2721 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2722 vfta &= ~(1 << (vid & 0x1F));
2723 hw->mac.ops.write_vfta(hw, index, vfta);
2724 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002725
2726 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002727
2728 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002729}
2730
2731/**
2732 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2733 * @adapter: board private structure to initialize
2734 **/
2735static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2736{
2737 struct net_device *netdev = adapter->netdev;
2738 struct e1000_hw *hw = &adapter->hw;
2739 u32 rctl;
2740
2741 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2742 /* disable VLAN receive filtering */
2743 rctl = er32(RCTL);
2744 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2745 ew32(RCTL, rctl);
2746
2747 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002748 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2749 adapter->mng_vlan_id);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002750 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2751 }
2752 }
2753}
2754
2755/**
2756 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2757 * @adapter: board private structure to initialize
2758 **/
2759static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2760{
2761 struct e1000_hw *hw = &adapter->hw;
2762 u32 rctl;
2763
2764 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2765 /* enable VLAN receive filtering */
2766 rctl = er32(RCTL);
2767 rctl |= E1000_RCTL_VFE;
2768 rctl &= ~E1000_RCTL_CFIEN;
2769 ew32(RCTL, rctl);
2770 }
2771}
2772
2773/**
2774 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2775 * @adapter: board private structure to initialize
2776 **/
2777static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2778{
2779 struct e1000_hw *hw = &adapter->hw;
2780 u32 ctrl;
2781
2782 /* disable VLAN tag insert/strip */
2783 ctrl = er32(CTRL);
2784 ctrl &= ~E1000_CTRL_VME;
2785 ew32(CTRL, ctrl);
2786}
2787
2788/**
2789 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2790 * @adapter: board private structure to initialize
2791 **/
2792static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2793{
2794 struct e1000_hw *hw = &adapter->hw;
2795 u32 ctrl;
2796
2797 /* enable VLAN tag insert/strip */
2798 ctrl = er32(CTRL);
2799 ctrl |= E1000_CTRL_VME;
2800 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801}
2802
2803static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2804{
2805 struct net_device *netdev = adapter->netdev;
2806 u16 vid = adapter->hw.mng_cookie.vlan_id;
2807 u16 old_vid = adapter->mng_vlan_id;
2808
Bruce Allane5fe2542013-02-20 04:06:27 +00002809 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002810 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002811 adapter->mng_vlan_id = vid;
2812 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002814 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
Patrick McHardy80d5c362013-04-19 02:04:28 +00002815 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002816}
2817
2818static void e1000_restore_vlan(struct e1000_adapter *adapter)
2819{
2820 u16 vid;
2821
Patrick McHardy80d5c362013-04-19 02:04:28 +00002822 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002824 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00002825 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002826}
2827
Bruce Allancd791612010-05-10 14:59:51 +00002828static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829{
2830 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002831 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832
2833 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2834 return;
2835
2836 manc = er32(MANC);
2837
Bruce Allane921eb12012-11-28 09:28:37 +00002838 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002839 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002840 * the packets will be handled on SMBUS
2841 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 manc |= E1000_MANC_EN_MNG2HOST;
2843 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002844
2845 switch (hw->mac.type) {
2846 default:
2847 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2848 break;
2849 case e1000_82574:
2850 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002851 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002852 * if so, enable it.
2853 */
2854 for (i = 0, j = 0; i < 8; i++) {
2855 mdef = er32(MDEF(i));
2856
2857 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002858 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002859 continue;
2860
2861 /* Enable this decision filter in MANC2H */
2862 if (mdef)
2863 manc2h |= (1 << i);
2864
2865 j |= mdef;
2866 }
2867
2868 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2869 break;
2870
2871 /* Create new decision filter in an empty filter */
2872 for (i = 0, j = 0; i < 8; i++)
2873 if (er32(MDEF(i)) == 0) {
2874 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2875 E1000_MDEF_PORT_664));
2876 manc2h |= (1 << 1);
2877 j++;
2878 break;
2879 }
2880
2881 if (!j)
2882 e_warn("Unable to create IPMI pass-through filter\n");
2883 break;
2884 }
2885
Auke Kokbc7f75f2007-09-17 12:30:59 -07002886 ew32(MANC2H, manc2h);
2887 ew32(MANC, manc);
2888}
2889
2890/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002891 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002892 * @adapter: board private structure
2893 *
2894 * Configure the Tx unit of the MAC after a reset.
2895 **/
2896static void e1000_configure_tx(struct e1000_adapter *adapter)
2897{
2898 struct e1000_hw *hw = &adapter->hw;
2899 struct e1000_ring *tx_ring = adapter->tx_ring;
2900 u64 tdba;
David Ertmane7e834a2014-01-13 23:19:27 +00002901 u32 tdlen, tctl, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902
2903 /* Setup the HW Tx Head and Tail descriptor pointers */
2904 tdba = tx_ring->dma;
2905 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002906 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2907 ew32(TDBAH(0), (tdba >> 32));
2908 ew32(TDLEN(0), tdlen);
2909 ew32(TDH(0), 0);
2910 ew32(TDT(0), 0);
2911 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2912 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002913
Auke Kokbc7f75f2007-09-17 12:30:59 -07002914 /* Set the Tx Interrupt Delay register */
2915 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002916 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 ew32(TADV, adapter->tx_abs_int_delay);
2918
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002919 if (adapter->flags2 & FLAG2_DMA_BURST) {
2920 u32 txdctl = er32(TXDCTL(0));
2921 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2922 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002923 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002924 * hardware to use the bus more efficiently in bursts, depends
2925 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002926 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002927 * hthresh = 1 ==> prefetch when one or more available
2928 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2929 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002930 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002931 */
2932 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2933 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002934 }
Bruce Allan56032be2011-12-16 00:46:01 +00002935 /* erratum work around: set txdctl the same for both queues */
2936 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002937
David Ertmane7e834a2014-01-13 23:19:27 +00002938 /* Program the Transmit Control Register */
2939 tctl = er32(TCTL);
2940 tctl &= ~E1000_TCTL_CT;
2941 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2942 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2943
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002945 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002946 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002947 * gigabit link later
2948 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949#define SPEED_MODE_BIT (1 << 21)
2950 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002951 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 }
2953
2954 /* errata: program both queues to unweighted RR */
2955 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002956 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002958 ew32(TARC(0), tarc);
2959 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002960 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002961 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 }
2963
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 /* Setup Transmit Descriptor Settings for eop descriptor */
2965 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2966
2967 /* only set IDE if we are delaying interrupts using the timers */
2968 if (adapter->tx_int_delay)
2969 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2970
2971 /* enable Report Status bit */
2972 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2973
David Ertmane7e834a2014-01-13 23:19:27 +00002974 ew32(TCTL, tctl);
2975
Bruce Allan57cde762012-02-22 09:02:58 +00002976 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977}
2978
2979/**
2980 * e1000_setup_rctl - configure the receive control registers
2981 * @adapter: Board private structure
2982 **/
2983#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2984 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2985static void e1000_setup_rctl(struct e1000_adapter *adapter)
2986{
2987 struct e1000_hw *hw = &adapter->hw;
2988 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989 u32 pages = 0;
2990
Bruce Allan2fbe4522012-04-19 03:21:47 +00002991 /* Workaround Si errata on PCHx - configure jumbo frame flow */
Bruce Allanda1e2042013-06-21 09:07:02 +00002992 if ((hw->mac.type >= e1000_pch2lan) &&
2993 (adapter->netdev->mtu > ETH_DATA_LEN) &&
2994 e1000_lv_jumbo_workaround_ich8lan(hw, true))
2995 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002996
Auke Kokbc7f75f2007-09-17 12:30:59 -07002997 /* Program MC offset vector base */
2998 rctl = er32(RCTL);
2999 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3000 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003001 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3002 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003003
3004 /* Do not Store bad packets */
3005 rctl &= ~E1000_RCTL_SBP;
3006
3007 /* Enable Long Packet receive */
3008 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3009 rctl &= ~E1000_RCTL_LPE;
3010 else
3011 rctl |= E1000_RCTL_LPE;
3012
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003013 /* Some systems expect that the CRC is included in SMBUS traffic. The
3014 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3015 * host memory when this is enabled
3016 */
3017 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3018 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003019
Bruce Allana4f58f52009-06-02 11:29:18 +00003020 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3021 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3022 u16 phy_data;
3023
3024 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3025 phy_data &= 0xfff8;
3026 phy_data |= (1 << 2);
3027 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3028
3029 e1e_rphy(hw, 22, &phy_data);
3030 phy_data &= 0x0fff;
3031 phy_data |= (1 << 14);
3032 e1e_wphy(hw, 0x10, 0x2823);
3033 e1e_wphy(hw, 0x11, 0x0003);
3034 e1e_wphy(hw, 22, phy_data);
3035 }
3036
Auke Kokbc7f75f2007-09-17 12:30:59 -07003037 /* Setup buffer sizes */
3038 rctl &= ~E1000_RCTL_SZ_4096;
3039 rctl |= E1000_RCTL_BSEX;
3040 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041 case 2048:
3042 default:
3043 rctl |= E1000_RCTL_SZ_2048;
3044 rctl &= ~E1000_RCTL_BSEX;
3045 break;
3046 case 4096:
3047 rctl |= E1000_RCTL_SZ_4096;
3048 break;
3049 case 8192:
3050 rctl |= E1000_RCTL_SZ_8192;
3051 break;
3052 case 16384:
3053 rctl |= E1000_RCTL_SZ_16384;
3054 break;
3055 }
3056
Bruce Allan5f450212011-07-22 06:21:46 +00003057 /* Enable Extended Status in all Receive Descriptors */
3058 rfctl = er32(RFCTL);
3059 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003060 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003061
Bruce Allane921eb12012-11-28 09:28:37 +00003062 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003063 * header is placed in skb->data and the packet data is
3064 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3065 * In the case of a non-split, skb->data is linearly filled,
3066 * followed by the page buffers. Therefore, skb->data is
3067 * sized to hold the largest protocol header.
3068 *
3069 * allocations using alloc_page take too long for regular MTU
3070 * so only enable packet split for jumbo frames
3071 *
3072 * Using pages when the page size is greater than 16k wastes
3073 * a lot of memory, since we allocate 3 pages at all times
3074 * per packet.
3075 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003077 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003079 else
3080 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081
3082 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003083 u32 psrctl = 0;
3084
Auke Kok140a7482007-10-25 13:57:58 -07003085 /* Enable Packet split descriptors */
3086 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087
Bruce Allane5fe2542013-02-20 04:06:27 +00003088 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003089
3090 switch (adapter->rx_ps_pages) {
3091 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003092 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3093 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003095 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3096 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003098 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099 break;
3100 }
3101
3102 ew32(PSRCTL, psrctl);
3103 }
3104
Ben Greearcf955e62012-02-11 15:39:51 +00003105 /* This is useful for sniffing bad packets. */
3106 if (adapter->netdev->features & NETIF_F_RXALL) {
3107 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003108 * in e1000e_set_rx_mode
3109 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003110 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3111 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3112 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
Ben Greearcf955e62012-02-11 15:39:51 +00003113
Bruce Allane80bd1d2013-05-01 01:19:46 +00003114 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3115 E1000_RCTL_DPF | /* Allow filtered pause */
3116 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
Ben Greearcf955e62012-02-11 15:39:51 +00003117 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3118 * and that breaks VLANs.
3119 */
3120 }
3121
Auke Kokbc7f75f2007-09-17 12:30:59 -07003122 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003123 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003124 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125}
3126
3127/**
3128 * e1000_configure_rx - Configure Receive Unit after Reset
3129 * @adapter: board private structure
3130 *
3131 * Configure the Rx unit of the MAC after a reset.
3132 **/
3133static void e1000_configure_rx(struct e1000_adapter *adapter)
3134{
3135 struct e1000_hw *hw = &adapter->hw;
3136 struct e1000_ring *rx_ring = adapter->rx_ring;
3137 u64 rdba;
3138 u32 rdlen, rctl, rxcsum, ctrl_ext;
3139
3140 if (adapter->rx_ps_pages) {
3141 /* this is a 32 byte descriptor */
3142 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003143 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 adapter->clean_rx = e1000_clean_rx_irq_ps;
3145 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003146 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003147 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003148 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3149 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003151 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 adapter->clean_rx = e1000_clean_rx_irq;
3153 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3154 }
3155
3156 /* disable receives while setting up the descriptors */
3157 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003158 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3159 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003160 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003161 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003163 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003164 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003165 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003166 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003167 * granularity = 01
3168 * wthresh = 04,
3169 * hthresh = 04,
3170 * pthresh = 0x20
3171 */
3172 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3173 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3174
Bruce Allane921eb12012-11-28 09:28:37 +00003175 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003176 * the value was not set by the user via module options
3177 */
3178 if (adapter->rx_int_delay == DEFAULT_RDTR)
3179 adapter->rx_int_delay = BURST_RDTR;
3180 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3181 adapter->rx_abs_int_delay = BURST_RADV;
3182 }
3183
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 /* set the Receive Delay Timer Register */
3185 ew32(RDTR, adapter->rx_int_delay);
3186
3187 /* irq moderation */
3188 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003189 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003190 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191
3192 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003193 /* Auto-Mask interrupts upon ICR access */
3194 ctrl_ext |= E1000_CTRL_EXT_IAME;
3195 ew32(IAM, 0xffffffff);
3196 ew32(CTRL_EXT, ctrl_ext);
3197 e1e_flush();
3198
Bruce Allane921eb12012-11-28 09:28:37 +00003199 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003200 * the Base and Length of the Rx Descriptor Ring
3201 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003202 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003203 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3204 ew32(RDBAH(0), (rdba >> 32));
3205 ew32(RDLEN(0), rdlen);
3206 ew32(RDH(0), 0);
3207 ew32(RDT(0), 0);
3208 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3209 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210
3211 /* Enable Receive Checksum Offload for TCP and UDP */
3212 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003213 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003215 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003216 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003217 ew32(RXCSUM, rxcsum);
3218
Bruce Allan3e35d992013-01-12 07:25:22 +00003219 /* With jumbo frames, excessive C-state transition latencies result
3220 * in dropped transactions.
3221 */
3222 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3223 u32 lat =
3224 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3225 adapter->max_frame_size) * 8 / 1000;
3226
3227 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003228 u32 rxdctl = er32(RXDCTL(0));
3229 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003230 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003231
3232 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3233 } else {
3234 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3235 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003236 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237
3238 /* Enable Receives */
3239 ew32(RCTL, rctl);
3240}
3241
3242/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003243 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 * @netdev: network interface device structure
3245 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003246 * Writes multicast address list to the MTA hash table.
3247 * Returns: -ENOMEM on failure
3248 * 0 on no addresses written
3249 * X on writing X addresses to MTA
3250 */
3251static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252{
3253 struct e1000_adapter *adapter = netdev_priv(netdev);
3254 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003255 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003256 u8 *mta_list;
3257 int i;
3258
3259 if (netdev_mc_empty(netdev)) {
3260 /* nothing to program, so clear mc list */
3261 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3262 return 0;
3263 }
3264
3265 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3266 if (!mta_list)
3267 return -ENOMEM;
3268
3269 /* update_mc_addr_list expects a packed array of only addresses. */
3270 i = 0;
3271 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003272 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003273
3274 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3275 kfree(mta_list);
3276
3277 return netdev_mc_count(netdev);
3278}
3279
3280/**
3281 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3282 * @netdev: network interface device structure
3283 *
3284 * Writes unicast address list to the RAR table.
3285 * Returns: -ENOMEM on failure/insufficient address space
3286 * 0 on no addresses written
3287 * X on writing X addresses to the RAR table
3288 **/
3289static int e1000e_write_uc_addr_list(struct net_device *netdev)
3290{
3291 struct e1000_adapter *adapter = netdev_priv(netdev);
3292 struct e1000_hw *hw = &adapter->hw;
3293 unsigned int rar_entries = hw->mac.rar_entry_count;
3294 int count = 0;
3295
3296 /* save a rar entry for our hardware address */
3297 rar_entries--;
3298
3299 /* save a rar entry for the LAA workaround */
3300 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3301 rar_entries--;
3302
3303 /* return ENOMEM indicating insufficient memory for addresses */
3304 if (netdev_uc_count(netdev) > rar_entries)
3305 return -ENOMEM;
3306
3307 if (!netdev_uc_empty(netdev) && rar_entries) {
3308 struct netdev_hw_addr *ha;
3309
Bruce Allane921eb12012-11-28 09:28:37 +00003310 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003311 * combining
3312 */
3313 netdev_for_each_uc_addr(ha, netdev) {
3314 if (!rar_entries)
3315 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003316 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003317 count++;
3318 }
3319 }
3320
3321 /* zero out the remaining RAR entries not used above */
3322 for (; rar_entries > 0; rar_entries--) {
3323 ew32(RAH(rar_entries), 0);
3324 ew32(RAL(rar_entries), 0);
3325 }
3326 e1e_flush();
3327
3328 return count;
3329}
3330
3331/**
3332 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3333 * @netdev: network interface device structure
3334 *
3335 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3336 * address list or the network interface flags are updated. This routine is
3337 * responsible for configuring the hardware for proper unicast, multicast,
3338 * promiscuous mode, and all-multi behavior.
3339 **/
3340static void e1000e_set_rx_mode(struct net_device *netdev)
3341{
3342 struct e1000_adapter *adapter = netdev_priv(netdev);
3343 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345
David Ertman63eb48f2014-02-14 07:16:46 +00003346 if (pm_runtime_suspended(netdev->dev.parent))
3347 return;
3348
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003350 rctl = er32(RCTL);
3351
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003352 /* clear the affected bits */
3353 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3354
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355 if (netdev->flags & IFF_PROMISC) {
3356 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003357 /* Do not hardware filter VLANs in promisc mode */
3358 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003360 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003361
Patrick McHardy746b9f02008-07-16 20:15:45 -07003362 if (netdev->flags & IFF_ALLMULTI) {
3363 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003364 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003365 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003366 * then we should just turn on promiscuous mode so
3367 * that we can at least receive multicast traffic
3368 */
3369 count = e1000e_write_mc_addr_list(netdev);
3370 if (count < 0)
3371 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003372 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003373 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003374 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003375 * sufficient space to store all the addresses then enable
3376 * unicast promiscuous mode
3377 */
3378 count = e1000e_write_uc_addr_list(netdev);
3379 if (count < 0)
3380 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 }
3382
3383 ew32(RCTL, rctl);
3384
Patrick McHardyf6469682013-04-19 02:04:27 +00003385 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003386 e1000e_vlan_strip_enable(adapter);
3387 else
3388 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003389}
3390
Bruce Allan70495a52012-01-11 01:26:50 +00003391static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3392{
3393 struct e1000_hw *hw = &adapter->hw;
3394 u32 mrqc, rxcsum;
3395 int i;
3396 static const u32 rsskey[10] = {
3397 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3398 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3399 };
3400
3401 /* Fill out hash function seed */
3402 for (i = 0; i < 10; i++)
3403 ew32(RSSRK(i), rsskey[i]);
3404
3405 /* Direct all traffic to queue 0 */
3406 for (i = 0; i < 32; i++)
3407 ew32(RETA(i), 0);
3408
Bruce Allane921eb12012-11-28 09:28:37 +00003409 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003410 * descriptor on writeback.
3411 */
3412 rxcsum = er32(RXCSUM);
3413 rxcsum |= E1000_RXCSUM_PCSD;
3414
3415 ew32(RXCSUM, rxcsum);
3416
3417 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3418 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3419 E1000_MRQC_RSS_FIELD_IPV6 |
3420 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3421 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3422
3423 ew32(MRQC, mrqc);
3424}
3425
Auke Kokbc7f75f2007-09-17 12:30:59 -07003426/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003427 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3428 * @adapter: board private structure
3429 * @timinca: pointer to returned time increment attributes
3430 *
3431 * Get attributes for incrementing the System Time Register SYSTIML/H at
3432 * the default base frequency, and set the cyclecounter shift value.
3433 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003434s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003435{
3436 struct e1000_hw *hw = &adapter->hw;
3437 u32 incvalue, incperiod, shift;
3438
3439 /* Make sure clock is enabled on I217 before checking the frequency */
3440 if ((hw->mac.type == e1000_pch_lpt) &&
3441 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3442 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3443 u32 fextnvm7 = er32(FEXTNVM7);
3444
3445 if (!(fextnvm7 & (1 << 0))) {
3446 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3447 e1e_flush();
3448 }
3449 }
3450
3451 switch (hw->mac.type) {
3452 case e1000_pch2lan:
3453 case e1000_pch_lpt:
3454 /* On I217, the clock frequency is 25MHz or 96MHz as
3455 * indicated by the System Clock Frequency Indication
3456 */
3457 if ((hw->mac.type != e1000_pch_lpt) ||
3458 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3459 /* Stable 96MHz frequency */
3460 incperiod = INCPERIOD_96MHz;
3461 incvalue = INCVALUE_96MHz;
3462 shift = INCVALUE_SHIFT_96MHz;
3463 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3464 break;
3465 }
3466 /* fall-through */
3467 case e1000_82574:
3468 case e1000_82583:
3469 /* Stable 25MHz frequency */
3470 incperiod = INCPERIOD_25MHz;
3471 incvalue = INCVALUE_25MHz;
3472 shift = INCVALUE_SHIFT_25MHz;
3473 adapter->cc.shift = shift;
3474 break;
3475 default:
3476 return -EINVAL;
3477 }
3478
3479 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3480 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3481
3482 return 0;
3483}
3484
3485/**
3486 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3487 * @adapter: board private structure
3488 *
3489 * Outgoing time stamping can be enabled and disabled. Play nice and
3490 * disable it when requested, although it shouldn't cause any overhead
3491 * when no packet needs it. At most one packet in the queue may be
3492 * marked for time stamping, otherwise it would be impossible to tell
3493 * for sure to which packet the hardware time stamp belongs.
3494 *
3495 * Incoming time stamping has to be configured via the hardware filters.
3496 * Not all combinations are supported, in particular event type has to be
3497 * specified. Matching the kind of event packet is not supported, with the
3498 * exception of "all V2 events regardless of level 2 or 4".
3499 **/
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003500static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3501 struct hwtstamp_config *config)
Bruce Allanb67e1912012-12-27 08:32:33 +00003502{
3503 struct e1000_hw *hw = &adapter->hw;
Bruce Allanb67e1912012-12-27 08:32:33 +00003504 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3505 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003506 u32 rxmtrl = 0;
3507 u16 rxudp = 0;
3508 bool is_l4 = false;
3509 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003510 u32 regval;
3511 s32 ret_val;
3512
3513 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3514 return -EINVAL;
3515
3516 /* flags reserved for future extensions - must be zero */
3517 if (config->flags)
3518 return -EINVAL;
3519
3520 switch (config->tx_type) {
3521 case HWTSTAMP_TX_OFF:
3522 tsync_tx_ctl = 0;
3523 break;
3524 case HWTSTAMP_TX_ON:
3525 break;
3526 default:
3527 return -ERANGE;
3528 }
3529
3530 switch (config->rx_filter) {
3531 case HWTSTAMP_FILTER_NONE:
3532 tsync_rx_ctl = 0;
3533 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003534 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3535 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3536 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3537 is_l4 = true;
3538 break;
3539 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3540 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3541 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3542 is_l4 = true;
3543 break;
3544 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3545 /* Also time stamps V2 L2 Path Delay Request/Response */
3546 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3547 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3548 is_l2 = true;
3549 break;
3550 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3551 /* Also time stamps V2 L2 Path Delay Request/Response. */
3552 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3553 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3554 is_l2 = true;
3555 break;
3556 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3557 /* Hardware cannot filter just V2 L4 Sync messages;
3558 * fall-through to V2 (both L2 and L4) Sync.
3559 */
3560 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3561 /* Also time stamps V2 Path Delay Request/Response. */
3562 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3563 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3564 is_l2 = true;
3565 is_l4 = true;
3566 break;
3567 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3568 /* Hardware cannot filter just V2 L4 Delay Request messages;
3569 * fall-through to V2 (both L2 and L4) Delay Request.
3570 */
3571 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3572 /* Also time stamps V2 Path Delay Request/Response. */
3573 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3574 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3575 is_l2 = true;
3576 is_l4 = true;
3577 break;
3578 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3579 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3580 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3581 * fall-through to all V2 (both L2 and L4) Events.
3582 */
3583 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3584 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3585 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3586 is_l2 = true;
3587 is_l4 = true;
3588 break;
3589 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3590 /* For V1, the hardware can only filter Sync messages or
3591 * Delay Request messages but not both so fall-through to
3592 * time stamp all packets.
3593 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003594 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003595 is_l2 = true;
3596 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003597 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3598 config->rx_filter = HWTSTAMP_FILTER_ALL;
3599 break;
3600 default:
3601 return -ERANGE;
3602 }
3603
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003604 adapter->hwtstamp_config = *config;
3605
Bruce Allanb67e1912012-12-27 08:32:33 +00003606 /* enable/disable Tx h/w time stamping */
3607 regval = er32(TSYNCTXCTL);
3608 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3609 regval |= tsync_tx_ctl;
3610 ew32(TSYNCTXCTL, regval);
3611 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3612 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3613 e_err("Timesync Tx Control register not set as expected\n");
3614 return -EAGAIN;
3615 }
3616
3617 /* enable/disable Rx h/w time stamping */
3618 regval = er32(TSYNCRXCTL);
3619 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3620 regval |= tsync_rx_ctl;
3621 ew32(TSYNCRXCTL, regval);
3622 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3623 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3624 (regval & (E1000_TSYNCRXCTL_ENABLED |
3625 E1000_TSYNCRXCTL_TYPE_MASK))) {
3626 e_err("Timesync Rx Control register not set as expected\n");
3627 return -EAGAIN;
3628 }
3629
Bruce Alland89777b2013-01-19 01:09:58 +00003630 /* L2: define ethertype filter for time stamped packets */
3631 if (is_l2)
3632 rxmtrl |= ETH_P_1588;
3633
3634 /* define which PTP packets get time stamped */
3635 ew32(RXMTRL, rxmtrl);
3636
3637 /* Filter by destination port */
3638 if (is_l4) {
3639 rxudp = PTP_EV_PORT;
3640 cpu_to_be16s(&rxudp);
3641 }
3642 ew32(RXUDP, rxudp);
3643
3644 e1e_flush();
3645
Bruce Allanb67e1912012-12-27 08:32:33 +00003646 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003647 er32(RXSTMPH);
3648 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003649
3650 /* Get and set the System Time Register SYSTIM base frequency */
3651 ret_val = e1000e_get_base_timinca(adapter, &regval);
3652 if (ret_val)
3653 return ret_val;
3654 ew32(TIMINCA, regval);
3655
3656 /* reset the ns time counter */
3657 timecounter_init(&adapter->tc, &adapter->cc,
3658 ktime_to_ns(ktime_get_real()));
3659
3660 return 0;
3661}
3662
3663/**
Bruce Allanad680762008-03-28 09:15:03 -07003664 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003665 * @adapter: private board structure
3666 **/
3667static void e1000_configure(struct e1000_adapter *adapter)
3668{
Bruce Allan55aa6982011-12-16 00:45:45 +00003669 struct e1000_ring *rx_ring = adapter->rx_ring;
3670
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003671 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003672
3673 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003674 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003675
3676 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003677
3678 if (adapter->netdev->features & NETIF_F_RXHASH)
3679 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680 e1000_setup_rctl(adapter);
3681 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003682 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003683}
3684
3685/**
3686 * e1000e_power_up_phy - restore link in case the phy was powered down
3687 * @adapter: address of board private structure
3688 *
3689 * The phy may be powered down to save power and turn off link when the
3690 * driver is unloaded and wake on lan is not enabled (among others)
3691 * *** this routine MUST be followed by a call to e1000e_reset ***
3692 **/
3693void e1000e_power_up_phy(struct e1000_adapter *adapter)
3694{
Bruce Allan17f208d2009-12-01 15:47:22 +00003695 if (adapter->hw.phy.ops.power_up)
3696 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003697
3698 adapter->hw.mac.ops.setup_link(&adapter->hw);
3699}
3700
3701/**
3702 * e1000_power_down_phy - Power down the PHY
3703 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003704 * Power down the PHY so no link is implied when interface is down.
3705 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003706 */
3707static void e1000_power_down_phy(struct e1000_adapter *adapter)
3708{
Bruce Allan17f208d2009-12-01 15:47:22 +00003709 if (adapter->hw.phy.ops.power_down)
3710 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003711}
3712
3713/**
3714 * e1000e_reset - bring the hardware into a known good state
3715 *
3716 * This function boots the hardware and enables some settings that
3717 * require a configuration cycle of the hardware - those cannot be
3718 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003719 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 */
3721void e1000e_reset(struct e1000_adapter *adapter)
3722{
3723 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003724 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003725 struct e1000_hw *hw = &adapter->hw;
3726 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003727 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 u16 hwm;
3729
Bruce Allanad680762008-03-28 09:15:03 -07003730 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003731 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003732
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003733 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003734 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003735 * large enough to accommodate two full transmit packets,
3736 * rounded up to the next 1KB and expressed in KB. Likewise,
3737 * the Rx FIFO should be large enough to accommodate at least
3738 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003739 * expressed in KB.
3740 */
Auke Kokdf762462007-10-25 13:57:53 -07003741 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003743 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003745 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003746 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003747 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003748 */
3749 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00003750 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003751 min_tx_space = ALIGN(min_tx_space, 1024);
3752 min_tx_space >>= 10;
3753 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003754 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 min_rx_space = ALIGN(min_rx_space, 1024);
3756 min_rx_space >>= 10;
3757
Bruce Allane921eb12012-11-28 09:28:37 +00003758 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003760 * allocation, take space away from current Rx allocation
3761 */
Auke Kokdf762462007-10-25 13:57:53 -07003762 if ((tx_space < min_tx_space) &&
3763 ((min_tx_space - tx_space) < pba)) {
3764 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003765
Bruce Allane921eb12012-11-28 09:28:37 +00003766 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003767 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003768 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003769 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003770 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003771 }
Auke Kokdf762462007-10-25 13:57:53 -07003772
3773 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774 }
3775
Bruce Allane921eb12012-11-28 09:28:37 +00003776 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003777 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003778 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779 * (or the size used for early receive) above it in the Rx FIFO.
3780 * Set it to the lower of:
3781 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003782 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003783 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003784 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3785 fc->pause_time = 0xFFFF;
3786 else
3787 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003788 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003789 fc->current_mode = fc->requested_mode;
3790
3791 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003792 case e1000_ich9lan:
3793 case e1000_ich10lan:
3794 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3795 pba = 14;
3796 ew32(PBA, pba);
3797 fc->high_water = 0x2800;
3798 fc->low_water = fc->high_water - 8;
3799 break;
3800 }
3801 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003802 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003803 hwm = min(((pba << 10) * 9 / 10),
3804 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003805
Bruce Allane80bd1d2013-05-01 01:19:46 +00003806 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
Bruce Alland3738bb2010-06-16 13:27:28 +00003807 fc->low_water = fc->high_water - 8;
3808 break;
3809 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003810 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003811 * loads. If hangs persist, try disabling Tx flow control.
3812 */
3813 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3814 fc->high_water = 0x3500;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003815 fc->low_water = 0x1500;
Bruce Allan38eb3942009-11-19 12:34:20 +00003816 } else {
3817 fc->high_water = 0x5000;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003818 fc->low_water = 0x3000;
Bruce Allan38eb3942009-11-19 12:34:20 +00003819 }
Bruce Allana3055952010-05-10 15:02:12 +00003820 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003821 break;
3822 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003823 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003824 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003825
3826 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3827 fc->high_water = 0x05C20;
3828 fc->low_water = 0x05048;
3829 fc->pause_time = 0x0650;
3830 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003831 }
Bruce Allan347b5202012-12-08 00:35:35 +00003832
Bruce Allance345e02013-06-21 09:07:07 +00003833 pba = 14;
3834 ew32(PBA, pba);
Bruce Allan347b5202012-12-08 00:35:35 +00003835 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3836 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003837 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003838 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003839
Bruce Allane921eb12012-11-28 09:28:37 +00003840 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003841 * maximum size per Tx descriptor limited only to the transmit
3842 * allocation of the packet buffer minus 96 bytes with an upper
3843 * limit of 24KB due to receive synchronization limitations.
3844 */
3845 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3846 24 << 10);
3847
Bruce Allane921eb12012-11-28 09:28:37 +00003848 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003849 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003850 */
3851 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003852 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003853 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3854 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003855 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003856 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003857 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003858 }
3859 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3860 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003861 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003862 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3863 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003864 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003865 }
3866 }
3867
Auke Kokbc7f75f2007-09-17 12:30:59 -07003868 /* Allow time for pending master requests to run */
3869 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003870
Bruce Allane921eb12012-11-28 09:28:37 +00003871 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003872 * that the network interface is in control
3873 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003874 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003875 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003876
Auke Kokbc7f75f2007-09-17 12:30:59 -07003877 ew32(WUC, 0);
3878
3879 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003880 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003881
3882 e1000_update_mng_vlan(adapter);
3883
3884 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3885 ew32(VET, ETH_P_8021Q);
3886
3887 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003888
Bruce Allanb67e1912012-12-27 08:32:33 +00003889 /* initialize systim and reset the ns time counter */
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003890 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
Bruce Allanb67e1912012-12-27 08:32:33 +00003891
Bruce Alland495bcb2013-03-20 07:23:11 +00003892 /* Set EEE advertisement as appropriate */
3893 if (adapter->flags2 & FLAG2_HAS_EEE) {
3894 s32 ret_val;
3895 u16 adv_addr;
3896
3897 switch (hw->phy.type) {
3898 case e1000_phy_82579:
3899 adv_addr = I82579_EEE_ADVERTISEMENT;
3900 break;
3901 case e1000_phy_i217:
3902 adv_addr = I217_EEE_ADVERTISEMENT;
3903 break;
3904 default:
3905 dev_err(&adapter->pdev->dev,
3906 "Invalid PHY type setting EEE advertisement\n");
3907 return;
3908 }
3909
3910 ret_val = hw->phy.ops.acquire(hw);
3911 if (ret_val) {
3912 dev_err(&adapter->pdev->dev,
3913 "EEE advertisement - unable to acquire PHY\n");
3914 return;
3915 }
3916
3917 e1000_write_emi_reg_locked(hw, adv_addr,
3918 hw->dev_spec.ich8lan.eee_disable ?
3919 0 : adapter->eee_advert);
3920
3921 hw->phy.ops.release(hw);
3922 }
3923
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003924 if (!netif_running(adapter->netdev) &&
David Ertman28002092014-02-14 07:16:41 +00003925 !test_bit(__E1000_TESTING, &adapter->state))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003926 e1000_power_down_phy(adapter);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003927
Auke Kokbc7f75f2007-09-17 12:30:59 -07003928 e1000_get_phy_info(hw);
3929
Bruce Allan918d7192009-06-02 11:28:20 +00003930 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3931 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003932 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003933 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003934 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003935 * different we would do if it failed
3936 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3938 phy_data &= ~IGP02E1000_PM_SPD;
3939 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3940 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941}
3942
3943int e1000e_up(struct e1000_adapter *adapter)
3944{
3945 struct e1000_hw *hw = &adapter->hw;
3946
3947 /* hardware has been reset, we need to reload some things */
3948 e1000_configure(adapter);
3949
3950 clear_bit(__E1000_DOWN, &adapter->state);
3951
Bruce Allan4662e822008-08-26 18:37:06 -07003952 if (adapter->msix_entries)
3953 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003954 e1000_irq_enable(adapter);
3955
Bruce Allan400484f2011-05-13 07:20:03 +00003956 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003957
Auke Kokbc7f75f2007-09-17 12:30:59 -07003958 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003959 if (adapter->msix_entries)
3960 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3961 else
3962 ew32(ICS, E1000_ICS_LSC);
3963
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964 return 0;
3965}
3966
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003967static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3968{
3969 struct e1000_hw *hw = &adapter->hw;
3970
3971 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3972 return;
3973
3974 /* flush pending descriptor writebacks to memory */
3975 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3976 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3977
3978 /* execute the writes immediately */
3979 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003980
Bruce Allane921eb12012-11-28 09:28:37 +00003981 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003982 * write is successful
3983 */
3984 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3985 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3986
3987 /* execute the writes immediately */
3988 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003989}
3990
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003991static void e1000e_update_stats(struct e1000_adapter *adapter);
3992
David Ertman28002092014-02-14 07:16:41 +00003993/**
3994 * e1000e_down - quiesce the device and optionally reset the hardware
3995 * @adapter: board private structure
3996 * @reset: boolean flag to reset the hardware or not
3997 */
3998void e1000e_down(struct e1000_adapter *adapter, bool reset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999{
4000 struct net_device *netdev = adapter->netdev;
4001 struct e1000_hw *hw = &adapter->hw;
4002 u32 tctl, rctl;
4003
Bruce Allane921eb12012-11-28 09:28:37 +00004004 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07004005 * reschedule our watchdog timer
4006 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004007 set_bit(__E1000_DOWN, &adapter->state);
4008
4009 /* disable receives in the hardware */
4010 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07004011 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4012 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013 /* flush and sleep below */
4014
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004015 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004016
4017 /* disable transmits in the hardware */
4018 tctl = er32(TCTL);
4019 tctl &= ~E1000_TCTL_EN;
4020 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004021
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022 /* flush both disables and wait for them to finish */
4023 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004024 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004025
Auke Kokbc7f75f2007-09-17 12:30:59 -07004026 e1000_irq_disable(adapter);
4027
Bruce Allana3b87a42013-04-20 05:37:29 +00004028 napi_synchronize(&adapter->napi);
4029
Auke Kokbc7f75f2007-09-17 12:30:59 -07004030 del_timer_sync(&adapter->watchdog_timer);
4031 del_timer_sync(&adapter->phy_info_timer);
4032
Auke Kokbc7f75f2007-09-17 12:30:59 -07004033 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004034
4035 spin_lock(&adapter->stats64_lock);
4036 e1000e_update_stats(adapter);
4037 spin_unlock(&adapter->stats64_lock);
4038
Bruce Allan400484f2011-05-13 07:20:03 +00004039 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004040 e1000_clean_tx_ring(adapter->tx_ring);
4041 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004042
Auke Kokbc7f75f2007-09-17 12:30:59 -07004043 adapter->link_speed = 0;
4044 adapter->link_duplex = 0;
4045
Bruce Allanda1e2042013-06-21 09:07:02 +00004046 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4047 if ((hw->mac.type >= e1000_pch2lan) &&
4048 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4049 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4050 e_dbg("failed to disable jumbo frame workaround mode\n");
4051
David Ertman28002092014-02-14 07:16:41 +00004052 if (reset && !pci_channel_offline(adapter->pdev))
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004053 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004054}
4055
4056void e1000e_reinit_locked(struct e1000_adapter *adapter)
4057{
4058 might_sleep();
4059 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004060 usleep_range(1000, 2000);
David Ertman28002092014-02-14 07:16:41 +00004061 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062 e1000e_up(adapter);
4063 clear_bit(__E1000_RESETTING, &adapter->state);
4064}
4065
4066/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004067 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4068 * @cc: cyclecounter structure
4069 **/
4070static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4071{
4072 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4073 cc);
4074 struct e1000_hw *hw = &adapter->hw;
4075 cycle_t systim;
4076
4077 /* latch SYSTIMH on read of SYSTIML */
4078 systim = (cycle_t)er32(SYSTIML);
4079 systim |= (cycle_t)er32(SYSTIMH) << 32;
4080
4081 return systim;
4082}
4083
4084/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4086 * @adapter: board private structure to initialize
4087 *
4088 * e1000_sw_init initializes the Adapter private data structure.
4089 * Fields are initialized based on PCI device information and
4090 * OS network device settings (MTU size).
4091 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004092static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004093{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004094 struct net_device *netdev = adapter->netdev;
4095
4096 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4097 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004098 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4099 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004100 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4101 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004103 spin_lock_init(&adapter->stats64_lock);
4104
Bruce Allan4662e822008-08-26 18:37:06 -07004105 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106
Bruce Allan4662e822008-08-26 18:37:06 -07004107 if (e1000_alloc_queues(adapter))
4108 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004109
Bruce Allanb67e1912012-12-27 08:32:33 +00004110 /* Setup hardware time stamping cyclecounter */
4111 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4112 adapter->cc.read = e1000e_cyclecounter_read;
4113 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4114 adapter->cc.mult = 1;
4115 /* cc.shift set in e1000e_get_base_tininca() */
4116
4117 spin_lock_init(&adapter->systim_lock);
4118 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4119 }
4120
Auke Kokbc7f75f2007-09-17 12:30:59 -07004121 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004122 e1000_irq_disable(adapter);
4123
Auke Kokbc7f75f2007-09-17 12:30:59 -07004124 set_bit(__E1000_DOWN, &adapter->state);
4125 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004126}
4127
4128/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004129 * e1000_intr_msi_test - Interrupt Handler
4130 * @irq: interrupt number
4131 * @data: pointer to a network interface device structure
4132 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004133static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004134{
4135 struct net_device *netdev = data;
4136 struct e1000_adapter *adapter = netdev_priv(netdev);
4137 struct e1000_hw *hw = &adapter->hw;
4138 u32 icr = er32(ICR);
4139
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004140 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004141 if (icr & E1000_ICR_RXSEQ) {
4142 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004143 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004144 * interrupt is handled.
4145 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004146 wmb();
4147 }
4148
4149 return IRQ_HANDLED;
4150}
4151
4152/**
4153 * e1000_test_msi_interrupt - Returns 0 for successful test
4154 * @adapter: board private struct
4155 *
4156 * code flow taken from tg3.c
4157 **/
4158static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4159{
4160 struct net_device *netdev = adapter->netdev;
4161 struct e1000_hw *hw = &adapter->hw;
4162 int err;
4163
4164 /* poll_enable hasn't been called yet, so don't need disable */
4165 /* clear any pending events */
4166 er32(ICR);
4167
4168 /* free the real vector and request a test handler */
4169 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004170 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004171
4172 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004173 * MSI irq handler will unset this flag
4174 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004175 adapter->flags |= FLAG_MSI_TEST_FAILED;
4176
4177 err = pci_enable_msi(adapter->pdev);
4178 if (err)
4179 goto msi_test_failed;
4180
Joe Perchesa0607fd2009-11-18 23:29:17 -08004181 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004182 netdev->name, netdev);
4183 if (err) {
4184 pci_disable_msi(adapter->pdev);
4185 goto msi_test_failed;
4186 }
4187
Bruce Allane921eb12012-11-28 09:28:37 +00004188 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004189 * interrupt.
4190 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004191 wmb();
4192
4193 e1000_irq_enable(adapter);
4194
4195 /* fire an unusual interrupt on the test handler */
4196 ew32(ICS, E1000_ICS_RXSEQ);
4197 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004198 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004199
4200 e1000_irq_disable(adapter);
4201
Bruce Allanbc763292012-08-17 06:18:07 +00004202 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004203
4204 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004205 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004206 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004207 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004208 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004209 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004210
4211 free_irq(adapter->pdev->irq, netdev);
4212 pci_disable_msi(adapter->pdev);
4213
Bruce Allanf8d59f72008-08-08 18:36:11 -07004214msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004215 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004216 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004217}
4218
4219/**
4220 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4221 * @adapter: board private struct
4222 *
4223 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4224 **/
4225static int e1000_test_msi(struct e1000_adapter *adapter)
4226{
4227 int err;
4228 u16 pci_cmd;
4229
4230 if (!(adapter->flags & FLAG_MSI_ENABLED))
4231 return 0;
4232
4233 /* disable SERR in case the MSI write causes a master abort */
4234 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004235 if (pci_cmd & PCI_COMMAND_SERR)
4236 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4237 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004238
4239 err = e1000_test_msi_interrupt(adapter);
4240
Dean Nelson36f24072010-06-29 18:12:05 +00004241 /* re-enable SERR */
4242 if (pci_cmd & PCI_COMMAND_SERR) {
4243 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4244 pci_cmd |= PCI_COMMAND_SERR;
4245 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4246 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004247
Bruce Allanf8d59f72008-08-08 18:36:11 -07004248 return err;
4249}
4250
4251/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 * e1000_open - Called when a network interface is made active
4253 * @netdev: network interface device structure
4254 *
4255 * Returns 0 on success, negative value on failure
4256 *
4257 * The open entry point is called when a network interface is made
4258 * active by the system (IFF_UP). At this point all resources needed
4259 * for transmit and receive operations are allocated, the interrupt
4260 * handler is registered with the OS, the watchdog timer is started,
4261 * and the stack is notified that the interface is ready.
4262 **/
4263static int e1000_open(struct net_device *netdev)
4264{
4265 struct e1000_adapter *adapter = netdev_priv(netdev);
4266 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004267 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268 int err;
4269
4270 /* disallow open during test */
4271 if (test_bit(__E1000_TESTING, &adapter->state))
4272 return -EBUSY;
4273
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004274 pm_runtime_get_sync(&pdev->dev);
4275
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004276 netif_carrier_off(netdev);
4277
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004279 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 if (err)
4281 goto err_setup_tx;
4282
4283 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004284 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004285 if (err)
4286 goto err_setup_rx;
4287
Bruce Allane921eb12012-11-28 09:28:37 +00004288 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004289 * interface is now open and reset the part to a known state.
4290 */
4291 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004292 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004293 e1000e_reset(adapter);
4294 }
4295
Auke Kokbc7f75f2007-09-17 12:30:59 -07004296 e1000e_power_up_phy(adapter);
4297
4298 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004299 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004300 e1000_update_mng_vlan(adapter);
4301
Bruce Allan79d4e902011-12-16 00:46:27 +00004302 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004303 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4304 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004305
Bruce Allane921eb12012-11-28 09:28:37 +00004306 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004307 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4308 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004309 * clean_rx handler before we do so.
4310 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004311 e1000_configure(adapter);
4312
4313 err = e1000_request_irq(adapter);
4314 if (err)
4315 goto err_req_irq;
4316
Bruce Allane921eb12012-11-28 09:28:37 +00004317 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004318 * ignore e1000e MSI messages, which means we need to test our MSI
4319 * interrupt now
4320 */
Bruce Allan4662e822008-08-26 18:37:06 -07004321 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004322 err = e1000_test_msi(adapter);
4323 if (err) {
4324 e_err("Interrupt allocation failed\n");
4325 goto err_req_irq;
4326 }
4327 }
4328
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329 /* From here on the code is the same as e1000e_up() */
4330 clear_bit(__E1000_DOWN, &adapter->state);
4331
4332 napi_enable(&adapter->napi);
4333
4334 e1000_irq_enable(adapter);
4335
Jeff Kirsher09357b02011-11-18 14:25:00 +00004336 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004337 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004338
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004339 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004340 pm_runtime_put(&pdev->dev);
4341
Auke Kokbc7f75f2007-09-17 12:30:59 -07004342 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004343 if (adapter->msix_entries)
4344 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4345 else
4346 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004347
4348 return 0;
4349
4350err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004351 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004352 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004353 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004354err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004355 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004356err_setup_tx:
4357 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004358 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004359
4360 return err;
4361}
4362
4363/**
4364 * e1000_close - Disables a network interface
4365 * @netdev: network interface device structure
4366 *
4367 * Returns 0, this is not allowed to fail
4368 *
4369 * The close entry point is called when an interface is de-activated
4370 * by the OS. The hardware is still under the drivers control, but
4371 * needs to be disabled. A global MAC reset is issued to stop the
4372 * hardware, and all transmit and receive resources are freed.
4373 **/
4374static int e1000_close(struct net_device *netdev)
4375{
4376 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004377 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004378 int count = E1000_CHECK_RESET_COUNT;
4379
4380 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4381 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382
4383 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004384
4385 pm_runtime_get_sync(&pdev->dev);
4386
4387 if (!test_bit(__E1000_DOWN, &adapter->state)) {
David Ertman28002092014-02-14 07:16:41 +00004388 e1000e_down(adapter, true);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004389 e1000_free_irq(adapter);
David Ertman63eb48f2014-02-14 07:16:46 +00004390
4391 /* Link status message must follow this format */
4392 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004393 }
Bruce Allana3b87a42013-04-20 05:37:29 +00004394
4395 napi_disable(&adapter->napi);
4396
Bruce Allan55aa6982011-12-16 00:45:45 +00004397 e1000e_free_tx_resources(adapter->tx_ring);
4398 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004399
Bruce Allane921eb12012-11-28 09:28:37 +00004400 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004401 * the same ID is registered on the host OS (let 8021q kill it)
4402 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004403 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004404 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4405 adapter->mng_vlan_id);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406
Bruce Allane921eb12012-11-28 09:28:37 +00004407 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004408 * interface is now closed
4409 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004410 if ((adapter->flags & FLAG_HAS_AMT) &&
4411 !test_bit(__E1000_TESTING, &adapter->state))
4412 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004413
Bruce Allan3e35d992013-01-12 07:25:22 +00004414 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004415
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004416 pm_runtime_put_sync(&pdev->dev);
4417
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418 return 0;
4419}
Bruce Allanfc830b72013-02-20 04:06:11 +00004420
Auke Kokbc7f75f2007-09-17 12:30:59 -07004421/**
4422 * e1000_set_mac - Change the Ethernet Address of the NIC
4423 * @netdev: network interface device structure
4424 * @p: pointer to an address structure
4425 *
4426 * Returns 0 on success, negative on failure
4427 **/
4428static int e1000_set_mac(struct net_device *netdev, void *p)
4429{
4430 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004431 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432 struct sockaddr *addr = p;
4433
4434 if (!is_valid_ether_addr(addr->sa_data))
4435 return -EADDRNOTAVAIL;
4436
4437 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4438 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4439
Bruce Allan69e1e012012-04-14 03:28:50 +00004440 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441
4442 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4443 /* activate the work around */
4444 e1000e_set_laa_state_82571(&adapter->hw, 1);
4445
Bruce Allane921eb12012-11-28 09:28:37 +00004446 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447 * between the time RAR[0] gets clobbered and the time it
4448 * gets fixed (in e1000_watchdog), the actual LAA is in one
4449 * of the RARs and no incoming packets directed to this port
4450 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004451 * RAR[14]
4452 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004453 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4454 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455 }
4456
4457 return 0;
4458}
4459
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004460/**
4461 * e1000e_update_phy_task - work thread to update phy
4462 * @work: pointer to our work struct
4463 *
4464 * this worker thread exists because we must acquire a
4465 * semaphore to read the phy, which we could msleep while
4466 * waiting for it, and we can't msleep in a timer.
4467 **/
4468static void e1000e_update_phy_task(struct work_struct *work)
4469{
4470 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004471 struct e1000_adapter,
4472 update_phy_task);
David Ertmana03206e2014-01-24 23:07:48 +00004473 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004474
4475 if (test_bit(__E1000_DOWN, &adapter->state))
4476 return;
4477
David Ertmana03206e2014-01-24 23:07:48 +00004478 e1000_get_phy_info(hw);
4479
4480 /* Enable EEE on 82579 after link up */
4481 if (hw->phy.type == e1000_phy_82579)
4482 e1000_set_eee_pchlan(hw);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004483}
4484
Bruce Allane921eb12012-11-28 09:28:37 +00004485/**
4486 * e1000_update_phy_info - timre call-back to update PHY info
4487 * @data: pointer to adapter cast into an unsigned long
4488 *
Bruce Allanad680762008-03-28 09:15:03 -07004489 * Need to wait a few seconds after link up to get diagnostic information from
4490 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004491 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004492static void e1000_update_phy_info(unsigned long data)
4493{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004494 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004495
4496 if (test_bit(__E1000_DOWN, &adapter->state))
4497 return;
4498
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004499 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004500}
4501
4502/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004503 * e1000e_update_phy_stats - Update the PHY statistics counters
4504 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004505 *
4506 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004507 **/
4508static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4509{
4510 struct e1000_hw *hw = &adapter->hw;
4511 s32 ret_val;
4512 u16 phy_data;
4513
4514 ret_val = hw->phy.ops.acquire(hw);
4515 if (ret_val)
4516 return;
4517
Bruce Allane921eb12012-11-28 09:28:37 +00004518 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004519 * If not, set to the page with the PHY status registers.
4520 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004521 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004522 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4523 &phy_data);
4524 if (ret_val)
4525 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004526 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4527 ret_val = hw->phy.ops.set_page(hw,
4528 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004529 if (ret_val)
4530 goto release;
4531 }
4532
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004533 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004534 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4535 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004536 if (!ret_val)
4537 adapter->stats.scc += phy_data;
4538
4539 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004540 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4541 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004542 if (!ret_val)
4543 adapter->stats.ecol += phy_data;
4544
4545 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004546 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4547 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004548 if (!ret_val)
4549 adapter->stats.mcc += phy_data;
4550
4551 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004552 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4553 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004554 if (!ret_val)
4555 adapter->stats.latecol += phy_data;
4556
4557 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004558 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4559 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004560 if (!ret_val)
4561 hw->mac.collision_delta = phy_data;
4562
4563 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004564 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4565 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004566 if (!ret_val)
4567 adapter->stats.dc += phy_data;
4568
4569 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004570 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4571 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004572 if (!ret_val)
4573 adapter->stats.tncrs += phy_data;
4574
4575release:
4576 hw->phy.ops.release(hw);
4577}
4578
4579/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004580 * e1000e_update_stats - Update the board statistics counters
4581 * @adapter: board private structure
4582 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004583static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004584{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004585 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586 struct e1000_hw *hw = &adapter->hw;
4587 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588
Bruce Allane921eb12012-11-28 09:28:37 +00004589 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590 * connection is down.
4591 */
4592 if (adapter->link_speed == 0)
4593 return;
4594 if (pci_channel_offline(pdev))
4595 return;
4596
Auke Kokbc7f75f2007-09-17 12:30:59 -07004597 adapter->stats.crcerrs += er32(CRCERRS);
4598 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004599 adapter->stats.gorc += er32(GORCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004600 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004601 adapter->stats.bprc += er32(BPRC);
4602 adapter->stats.mprc += er32(MPRC);
4603 adapter->stats.roc += er32(ROC);
4604
Auke Kokbc7f75f2007-09-17 12:30:59 -07004605 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004606
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004607 /* Half-duplex statistics */
4608 if (adapter->link_duplex == HALF_DUPLEX) {
4609 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4610 e1000e_update_phy_stats(adapter);
4611 } else {
4612 adapter->stats.scc += er32(SCC);
4613 adapter->stats.ecol += er32(ECOL);
4614 adapter->stats.mcc += er32(MCC);
4615 adapter->stats.latecol += er32(LATECOL);
4616 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004617
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004618 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004619
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004620 if ((hw->mac.type != e1000_82574) &&
4621 (hw->mac.type != e1000_82583))
4622 adapter->stats.tncrs += er32(TNCRS);
4623 }
4624 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004625 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004626
Auke Kokbc7f75f2007-09-17 12:30:59 -07004627 adapter->stats.xonrxc += er32(XONRXC);
4628 adapter->stats.xontxc += er32(XONTXC);
4629 adapter->stats.xoffrxc += er32(XOFFRXC);
4630 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004632 adapter->stats.gotc += er32(GOTCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004633 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004634 adapter->stats.rnbc += er32(RNBC);
4635 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004636
4637 adapter->stats.mptc += er32(MPTC);
4638 adapter->stats.bptc += er32(BPTC);
4639
4640 /* used for adaptive IFS */
4641
4642 hw->mac.tx_packet_delta = er32(TPT);
4643 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004644
4645 adapter->stats.algnerrc += er32(ALGNERRC);
4646 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004647 adapter->stats.cexterr += er32(CEXTERR);
4648 adapter->stats.tsctc += er32(TSCTC);
4649 adapter->stats.tsctfc += er32(TSCTFC);
4650
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004652 netdev->stats.multicast = adapter->stats.mprc;
4653 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654
4655 /* Rx Errors */
4656
Bruce Allane921eb12012-11-28 09:28:37 +00004657 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004658 * our own version based on RUC and ROC
4659 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004660 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004661 adapter->stats.crcerrs + adapter->stats.algnerrc +
4662 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004663 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004664 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004665 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4666 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4667 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004668
4669 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004670 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004671 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4672 netdev->stats.tx_window_errors = adapter->stats.latecol;
4673 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004674
4675 /* Tx Dropped needs to be maintained elsewhere */
4676
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677 /* Management Stats */
4678 adapter->stats.mgptc += er32(MGTPTC);
4679 adapter->stats.mgprc += er32(MGTPRC);
4680 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004681
4682 /* Correctable ECC Errors */
4683 if (hw->mac.type == e1000_pch_lpt) {
4684 u32 pbeccsts = er32(PBECCSTS);
4685 adapter->corr_errors +=
4686 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4687 adapter->uncorr_errors +=
4688 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4689 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4690 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004691}
4692
Bruce Allan7c257692008-04-23 11:09:00 -07004693/**
4694 * e1000_phy_read_status - Update the PHY register status snapshot
4695 * @adapter: board private structure
4696 **/
4697static void e1000_phy_read_status(struct e1000_adapter *adapter)
4698{
4699 struct e1000_hw *hw = &adapter->hw;
4700 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004701
Bruce Allan97390ab2013-06-29 07:42:25 +00004702 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
4703 (er32(STATUS) & E1000_STATUS_LU) &&
Bruce Allan7c257692008-04-23 11:09:00 -07004704 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004705 int ret_val;
4706
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004707 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4708 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4709 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4710 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4711 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4712 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4713 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4714 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004715 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004716 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004717 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004718 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004719 * Set values to typical power-on defaults
4720 */
4721 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4722 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4723 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4724 BMSR_ERCAP);
4725 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4726 ADVERTISE_ALL | ADVERTISE_CSMA);
4727 phy->lpa = 0;
4728 phy->expansion = EXPANSION_ENABLENPAGE;
4729 phy->ctrl1000 = ADVERTISE_1000FULL;
4730 phy->stat1000 = 0;
4731 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4732 }
Bruce Allan7c257692008-04-23 11:09:00 -07004733}
4734
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735static void e1000_print_link_info(struct e1000_adapter *adapter)
4736{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004737 struct e1000_hw *hw = &adapter->hw;
4738 u32 ctrl = er32(CTRL);
4739
Bruce Allan8f12fe82008-11-21 16:54:43 -08004740 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004741 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4742 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004743 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4744 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4745 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4746 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004747}
4748
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004749static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004750{
4751 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004752 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004753 s32 ret_val = 0;
4754
Bruce Allane921eb12012-11-28 09:28:37 +00004755 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004756 * Rx sequence error interrupt. get_link_status will stay
4757 * false until the check_for_link establishes link
4758 * for copper adapters ONLY
4759 */
4760 switch (hw->phy.media_type) {
4761 case e1000_media_type_copper:
4762 if (hw->mac.get_link_status) {
4763 ret_val = hw->mac.ops.check_for_link(hw);
4764 link_active = !hw->mac.get_link_status;
4765 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004766 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004767 }
4768 break;
4769 case e1000_media_type_fiber:
4770 ret_val = hw->mac.ops.check_for_link(hw);
4771 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4772 break;
4773 case e1000_media_type_internal_serdes:
4774 ret_val = hw->mac.ops.check_for_link(hw);
4775 link_active = adapter->hw.mac.serdes_has_link;
4776 break;
4777 default:
4778 case e1000_media_type_unknown:
4779 break;
4780 }
4781
4782 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4783 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4784 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004785 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004786 }
4787
4788 return link_active;
4789}
4790
4791static void e1000e_enable_receives(struct e1000_adapter *adapter)
4792{
4793 /* make sure the receive unit is started */
4794 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004795 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004796 struct e1000_hw *hw = &adapter->hw;
4797 u32 rctl = er32(RCTL);
4798 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004799 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004800 }
4801}
4802
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004803static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4804{
4805 struct e1000_hw *hw = &adapter->hw;
4806
Bruce Allane921eb12012-11-28 09:28:37 +00004807 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004808 * for hung state and reset, if two calls return true
4809 */
4810 if (e1000_check_phy_82574(hw))
4811 adapter->phy_hang_count++;
4812 else
4813 adapter->phy_hang_count = 0;
4814
4815 if (adapter->phy_hang_count > 1) {
4816 adapter->phy_hang_count = 0;
David Ertmand9554e92014-01-08 01:07:55 +00004817 e_dbg("PHY appears hung - resetting\n");
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004818 schedule_work(&adapter->reset_task);
4819 }
4820}
4821
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822/**
4823 * e1000_watchdog - Timer Call-back
4824 * @data: pointer to adapter cast into an unsigned long
4825 **/
4826static void e1000_watchdog(unsigned long data)
4827{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004828 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004829
4830 /* Do the rest outside of interrupt context */
4831 schedule_work(&adapter->watchdog_task);
4832
4833 /* TODO: make this use queue_delayed_work() */
4834}
4835
4836static void e1000_watchdog_task(struct work_struct *work)
4837{
4838 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004839 struct e1000_adapter,
4840 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004841 struct net_device *netdev = adapter->netdev;
4842 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004843 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844 struct e1000_ring *tx_ring = adapter->tx_ring;
4845 struct e1000_hw *hw = &adapter->hw;
4846 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004847
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004848 if (test_bit(__E1000_DOWN, &adapter->state))
4849 return;
4850
David S. Millerb405e8d2010-02-04 22:31:41 -08004851 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004852 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004853 /* Cancel scheduled suspend requests. */
4854 pm_runtime_resume(netdev->dev.parent);
4855
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004856 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004857 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004858 }
4859
4860 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4861 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4862 e1000_update_mng_vlan(adapter);
4863
Auke Kokbc7f75f2007-09-17 12:30:59 -07004864 if (link) {
4865 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004866 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004867
4868 /* Cancel scheduled suspend requests. */
4869 pm_runtime_resume(netdev->dev.parent);
4870
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004871 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004872 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004874 &adapter->link_speed,
4875 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004877
4878 /* check if SmartSpeed worked */
4879 e1000e_check_downshift(hw);
4880 if (phy->speed_downgraded)
4881 netdev_warn(netdev,
4882 "Link Speed was downgraded by SmartSpeed\n");
4883
Bruce Allane921eb12012-11-28 09:28:37 +00004884 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004885 * if link has autonegotiated at 10/100 half
4886 */
4887 if ((hw->phy.type == e1000_phy_igp_3 ||
4888 hw->phy.type == e1000_phy_bm) &&
David Ertman138953b2013-08-30 05:45:25 +00004889 hw->mac.autoneg &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004890 (adapter->link_speed == SPEED_10 ||
4891 adapter->link_speed == SPEED_100) &&
4892 (adapter->link_duplex == HALF_DUPLEX)) {
4893 u16 autoneg_exp;
4894
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004895 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004896
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004897 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004898 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 -07004899 }
4900
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004901 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 adapter->tx_timeout_factor = 1;
4903 switch (adapter->link_speed) {
4904 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004905 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004906 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004907 break;
4908 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004909 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004910 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 break;
4912 }
4913
Bruce Allane921eb12012-11-28 09:28:37 +00004914 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004915 * link-up event
4916 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004917 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4918 !txb2b) {
4919 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004920 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004921 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004922 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 }
4924
Bruce Allane921eb12012-11-28 09:28:37 +00004925 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004926 * some hardware issues
4927 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4929 switch (adapter->link_speed) {
4930 case SPEED_10:
4931 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004932 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933 netdev->features &= ~NETIF_F_TSO;
4934 netdev->features &= ~NETIF_F_TSO6;
4935 break;
4936 case SPEED_1000:
4937 netdev->features |= NETIF_F_TSO;
4938 netdev->features |= NETIF_F_TSO6;
4939 break;
4940 default:
4941 /* oops */
4942 break;
4943 }
4944 }
4945
Bruce Allane921eb12012-11-28 09:28:37 +00004946 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004947 * after setting TARC(0)
4948 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004949 tctl = er32(TCTL);
4950 tctl |= E1000_TCTL_EN;
4951 ew32(TCTL, tctl);
4952
Bruce Allane921eb12012-11-28 09:28:37 +00004953 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004954 * reporting link up.
4955 */
4956 if (phy->ops.cfg_on_link_up)
4957 phy->ops.cfg_on_link_up(hw);
4958
Auke Kokbc7f75f2007-09-17 12:30:59 -07004959 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960
4961 if (!test_bit(__E1000_DOWN, &adapter->state))
4962 mod_timer(&adapter->phy_info_timer,
4963 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004964 }
4965 } else {
4966 if (netif_carrier_ok(netdev)) {
4967 adapter->link_speed = 0;
4968 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004969 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004970 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004971 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004972 if (!test_bit(__E1000_DOWN, &adapter->state))
4973 mod_timer(&adapter->phy_info_timer,
4974 round_jiffies(jiffies + 2 * HZ));
4975
David Ertmand9554e92014-01-08 01:07:55 +00004976 /* 8000ES2LAN requires a Rx packet buffer work-around
4977 * on link down event; reset the controller to flush
4978 * the Rx packet buffer.
Bruce Allan12d43f72012-12-05 06:26:14 +00004979 */
David Ertmand9554e92014-01-08 01:07:55 +00004980 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
Bruce Allan12d43f72012-12-05 06:26:14 +00004981 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004982 else
4983 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004984 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004985 }
4986 }
4987
4988link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004989 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004990 e1000e_update_stats(adapter);
4991
4992 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4993 adapter->tpt_old = adapter->stats.tpt;
4994 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4995 adapter->colc_old = adapter->stats.colc;
4996
Bruce Allan7c257692008-04-23 11:09:00 -07004997 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4998 adapter->gorc_old = adapter->stats.gorc;
4999 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
5000 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00005001 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005002
David Ertmand9554e92014-01-08 01:07:55 +00005003 /* If the link is lost the controller stops DMA, but
5004 * if there is queued Tx work it cannot be done. So
5005 * reset the controller to flush the Tx packet buffers.
5006 */
5007 if (!netif_carrier_ok(netdev) &&
5008 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
5009 adapter->flags |= FLAG_RESTART_NOW;
5010
5011 /* If reset is necessary, do it outside of interrupt context. */
Bruce Allan12d43f72012-12-05 06:26:14 +00005012 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00005013 schedule_work(&adapter->reset_task);
5014 /* return immediately since reset is imminent */
5015 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016 }
5017
Bruce Allan12d43f72012-12-05 06:26:14 +00005018 e1000e_update_adaptive(&adapter->hw);
5019
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005020 /* Simple mode for Interrupt Throttle Rate (ITR) */
5021 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00005022 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005023 * Total asymmetrical Tx or Rx gets ITR=8000;
5024 * everyone else is between 2000-8000.
5025 */
5026 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5027 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00005028 adapter->gotc - adapter->gorc :
5029 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005030 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5031
Matthew Vick22a4cca2012-07-12 00:02:42 +00005032 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005033 }
5034
Bruce Allanad680762008-03-28 09:15:03 -07005035 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005036 if (adapter->msix_entries)
5037 ew32(ICS, adapter->rx_ring->ims_val);
5038 else
5039 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005041 /* flush pending descriptors to memory before detecting Tx hang */
5042 e1000e_flush_descriptors(adapter);
5043
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005045 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046
Bruce Allane921eb12012-11-28 09:28:37 +00005047 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005048 * reset from the other port. Set the appropriate LAA in RAR[0]
5049 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005051 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005053 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5054 e1000e_check_82574_phy_workaround(adapter);
5055
Bruce Allanb67e1912012-12-27 08:32:33 +00005056 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5057 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5058 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5059 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5060 er32(RXSTMPH);
5061 adapter->rx_hwtstamp_cleared++;
5062 } else {
5063 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5064 }
5065 }
5066
Auke Kokbc7f75f2007-09-17 12:30:59 -07005067 /* Reset the timer */
5068 if (!test_bit(__E1000_DOWN, &adapter->state))
5069 mod_timer(&adapter->watchdog_timer,
5070 round_jiffies(jiffies + 2 * HZ));
5071}
5072
5073#define E1000_TX_FLAGS_CSUM 0x00000001
5074#define E1000_TX_FLAGS_VLAN 0x00000002
5075#define E1000_TX_FLAGS_TSO 0x00000004
5076#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005077#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005078#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5080#define E1000_TX_FLAGS_VLAN_SHIFT 16
5081
Bruce Allan55aa6982011-12-16 00:45:45 +00005082static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005083{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005084 struct e1000_context_desc *context_desc;
5085 struct e1000_buffer *buffer_info;
5086 unsigned int i;
5087 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005088 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005089 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005090
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005091 if (!skb_is_gso(skb))
5092 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005093
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005094 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005095 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5096
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005097 if (err)
5098 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005099 }
5100
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005101 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5102 mss = skb_shinfo(skb)->gso_size;
5103 if (skb->protocol == htons(ETH_P_IP)) {
5104 struct iphdr *iph = ip_hdr(skb);
5105 iph->tot_len = 0;
5106 iph->check = 0;
5107 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005108 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005109 cmd_length = E1000_TXD_CMD_IP;
5110 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005111 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005112 ipv6_hdr(skb)->payload_len = 0;
5113 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005114 &ipv6_hdr(skb)->daddr,
5115 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005116 ipcse = 0;
5117 }
5118 ipcss = skb_network_offset(skb);
5119 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5120 tucss = skb_transport_offset(skb);
5121 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005122
5123 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005124 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005125
5126 i = tx_ring->next_to_use;
5127 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5128 buffer_info = &tx_ring->buffer_info[i];
5129
Bruce Allane80bd1d2013-05-01 01:19:46 +00005130 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5131 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5132 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005133 context_desc->upper_setup.tcp_fields.tucss = tucss;
5134 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005135 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allane80bd1d2013-05-01 01:19:46 +00005136 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005137 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5138 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5139
5140 buffer_info->time_stamp = jiffies;
5141 buffer_info->next_to_watch = i;
5142
5143 i++;
5144 if (i == tx_ring->count)
5145 i = 0;
5146 tx_ring->next_to_use = i;
5147
5148 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005149}
5150
Bruce Allan55aa6982011-12-16 00:45:45 +00005151static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005152{
Bruce Allan55aa6982011-12-16 00:45:45 +00005153 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005154 struct e1000_context_desc *context_desc;
5155 struct e1000_buffer *buffer_info;
5156 unsigned int i;
5157 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005158 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005159 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005160
Dave Grahamaf807c82008-10-09 14:28:58 -07005161 if (skb->ip_summed != CHECKSUM_PARTIAL)
5162 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005163
Arthur Jones5f66f202009-03-19 01:13:08 +00005164 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5165 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5166 else
5167 protocol = skb->protocol;
5168
Arthur Jones3f518392009-03-20 15:56:35 -07005169 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005170 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005171 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5172 cmd_len |= E1000_TXD_CMD_TCP;
5173 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005174 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005175 /* XXX not handling all IPV6 headers */
5176 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5177 cmd_len |= E1000_TXD_CMD_TCP;
5178 break;
5179 default:
5180 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005181 e_warn("checksum_partial proto=%x!\n",
5182 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005183 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184 }
5185
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005186 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005187
5188 i = tx_ring->next_to_use;
5189 buffer_info = &tx_ring->buffer_info[i];
5190 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5191
5192 context_desc->lower_setup.ip_config = 0;
5193 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005194 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005195 context_desc->upper_setup.tcp_fields.tucse = 0;
5196 context_desc->tcp_seg_setup.data = 0;
5197 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5198
5199 buffer_info->time_stamp = jiffies;
5200 buffer_info->next_to_watch = i;
5201
5202 i++;
5203 if (i == tx_ring->count)
5204 i = 0;
5205 tx_ring->next_to_use = i;
5206
5207 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005208}
5209
Bruce Allan55aa6982011-12-16 00:45:45 +00005210static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5211 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005212 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213{
Bruce Allan55aa6982011-12-16 00:45:45 +00005214 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005215 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005216 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005217 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005218 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005219 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220
5221 i = tx_ring->next_to_use;
5222
5223 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005224 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225 size = min(len, max_per_txd);
5226
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005228 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005230 buffer_info->dma = dma_map_single(&pdev->dev,
5231 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005232 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005233 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005234 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005235 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005236
5237 len -= size;
5238 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005239 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005240
5241 if (len) {
5242 i++;
5243 if (i == tx_ring->count)
5244 i = 0;
5245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005246 }
5247
5248 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005249 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005250
5251 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005252 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005253 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005254
5255 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005256 i++;
5257 if (i == tx_ring->count)
5258 i = 0;
5259
Auke Kokbc7f75f2007-09-17 12:30:59 -07005260 buffer_info = &tx_ring->buffer_info[i];
5261 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262
5263 buffer_info->length = size;
5264 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005265 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005266 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005267 offset, size,
5268 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005269 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005270 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005271 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272
5273 len -= size;
5274 offset += size;
5275 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005276 }
5277 }
5278
Bruce Allanaf667a22010-12-31 06:10:01 +00005279 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005280 /* multiply data chunks by size of headers */
5281 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5282
Auke Kokbc7f75f2007-09-17 12:30:59 -07005283 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005284 tx_ring->buffer_info[i].segs = segs;
5285 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005286 tx_ring->buffer_info[first].next_to_watch = i;
5287
5288 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005289
5290dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005291 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005292 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005293 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005294 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005295
5296 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005297 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005298 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005299 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005300 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005301 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005302 }
5303
5304 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005305}
5306
Bruce Allan55aa6982011-12-16 00:45:45 +00005307static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005308{
Bruce Allan55aa6982011-12-16 00:45:45 +00005309 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005310 struct e1000_tx_desc *tx_desc = NULL;
5311 struct e1000_buffer *buffer_info;
5312 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5313 unsigned int i;
5314
5315 if (tx_flags & E1000_TX_FLAGS_TSO) {
5316 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005317 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005318 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5319
5320 if (tx_flags & E1000_TX_FLAGS_IPV4)
5321 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5322 }
5323
5324 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5325 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5326 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5327 }
5328
5329 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5330 txd_lower |= E1000_TXD_CMD_VLE;
5331 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5332 }
5333
Ben Greear943146d2012-02-11 15:39:40 +00005334 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5335 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5336
Bruce Allanb67e1912012-12-27 08:32:33 +00005337 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5338 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5339 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5340 }
5341
Auke Kokbc7f75f2007-09-17 12:30:59 -07005342 i = tx_ring->next_to_use;
5343
Bruce Allan36b973d2010-11-24 07:42:43 +00005344 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005345 buffer_info = &tx_ring->buffer_info[i];
5346 tx_desc = E1000_TX_DESC(*tx_ring, i);
5347 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005348 tx_desc->lower.data = cpu_to_le32(txd_lower |
5349 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005350 tx_desc->upper.data = cpu_to_le32(txd_upper);
5351
5352 i++;
5353 if (i == tx_ring->count)
5354 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005355 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005356
5357 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5358
Ben Greear943146d2012-02-11 15:39:40 +00005359 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5360 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5361 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5362
Bruce Allane921eb12012-11-28 09:28:37 +00005363 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005364 * know there are new descriptors to fetch. (Only
5365 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005366 * such as IA-64).
5367 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368 wmb();
5369
5370 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005371
5372 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005373 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005374 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005375 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005376
Bruce Allane921eb12012-11-28 09:28:37 +00005377 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005378 * at a time, it synchronizes IO on IA64/Altix systems
5379 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005380 mmiowb();
5381}
5382
5383#define MINIMUM_DHCP_PACKET_SIZE 282
5384static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5385 struct sk_buff *skb)
5386{
Bruce Allane80bd1d2013-05-01 01:19:46 +00005387 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005388 u16 length, offset;
5389
Bruce Alland60923c2012-12-05 06:26:56 +00005390 if (vlan_tx_tag_present(skb) &&
5391 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5392 (adapter->hw.mng_cookie.status &
5393 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5394 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005395
5396 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5397 return 0;
5398
Bruce Allan53aa82d2013-02-20 04:06:06 +00005399 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005400 return 0;
5401
5402 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005403 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404 struct udphdr *udp;
5405
5406 if (ip->protocol != IPPROTO_UDP)
5407 return 0;
5408
5409 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5410 if (ntohs(udp->dest) != 67)
5411 return 0;
5412
5413 offset = (u8 *)udp + 8 - skb->data;
5414 length = skb->len - offset;
5415 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5416 }
5417
5418 return 0;
5419}
5420
Bruce Allan55aa6982011-12-16 00:45:45 +00005421static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422{
Bruce Allan55aa6982011-12-16 00:45:45 +00005423 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005424
Bruce Allan55aa6982011-12-16 00:45:45 +00005425 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005426 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005428 * but since that doesn't exist yet, just open code it.
5429 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430 smp_mb();
5431
Bruce Allane921eb12012-11-28 09:28:37 +00005432 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005433 * made room available.
5434 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005435 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005436 return -EBUSY;
5437
5438 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005439 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005440 ++adapter->restart_queue;
5441 return 0;
5442}
5443
Bruce Allan55aa6982011-12-16 00:45:45 +00005444static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005445{
Bruce Alland821a4c2012-08-24 20:38:11 +00005446 BUG_ON(size > tx_ring->count);
5447
Bruce Allan55aa6982011-12-16 00:45:45 +00005448 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005450 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005451}
5452
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005453static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5454 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005455{
5456 struct e1000_adapter *adapter = netdev_priv(netdev);
5457 struct e1000_ring *tx_ring = adapter->tx_ring;
5458 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005460 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005461 unsigned int nr_frags;
5462 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 int count = 0;
5464 int tso;
5465 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466
5467 if (test_bit(__E1000_DOWN, &adapter->state)) {
5468 dev_kfree_skb_any(skb);
5469 return NETDEV_TX_OK;
5470 }
5471
5472 if (skb->len <= 0) {
5473 dev_kfree_skb_any(skb);
5474 return NETDEV_TX_OK;
5475 }
5476
Bruce Allane921eb12012-11-28 09:28:37 +00005477 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005478 * pad skb in order to meet this minimum size requirement
5479 */
5480 if (unlikely(skb->len < 17)) {
5481 if (skb_pad(skb, 17 - skb->len))
5482 return NETDEV_TX_OK;
5483 skb->len = 17;
5484 skb_set_tail_pointer(skb, 17);
5485 }
5486
Auke Kokbc7f75f2007-09-17 12:30:59 -07005487 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488 if (mss) {
5489 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490
Bruce Allane921eb12012-11-28 09:28:37 +00005491 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005492 * points to just header, pull a few bytes of payload from
5493 * frags into skb->data
5494 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005495 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005496 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005497 * avoiding it could save a lot of cycles
5498 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005499 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005500 unsigned int pull_size;
5501
Bruce Allana2a5b322012-01-31 06:37:17 +00005502 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005503 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005504 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005505 dev_kfree_skb_any(skb);
5506 return NETDEV_TX_OK;
5507 }
Eric Dumazete743d312010-04-14 15:59:40 -07005508 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005509 }
5510 }
5511
5512 /* reserve a descriptor for the offload context */
5513 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5514 count++;
5515 count++;
5516
Bruce Alland821a4c2012-08-24 20:38:11 +00005517 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005518
5519 nr_frags = skb_shinfo(skb)->nr_frags;
5520 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005521 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5522 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005523
5524 if (adapter->hw.mac.tx_pkt_filtering)
5525 e1000_transfer_dhcp_info(adapter, skb);
5526
Bruce Allane921eb12012-11-28 09:28:37 +00005527 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005528 * head, otherwise try next time
5529 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005530 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005531 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005532
Jesse Grosseab6d182010-10-20 13:56:03 +00005533 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005534 tx_flags |= E1000_TX_FLAGS_VLAN;
5535 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5536 }
5537
5538 first = tx_ring->next_to_use;
5539
Bruce Allan55aa6982011-12-16 00:45:45 +00005540 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005541 if (tso < 0) {
5542 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005543 return NETDEV_TX_OK;
5544 }
5545
5546 if (tso)
5547 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005548 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005549 tx_flags |= E1000_TX_FLAGS_CSUM;
5550
Bruce Allane921eb12012-11-28 09:28:37 +00005551 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005552 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005553 * no longer assume, we must.
5554 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005555 if (skb->protocol == htons(ETH_P_IP))
5556 tx_flags |= E1000_TX_FLAGS_IPV4;
5557
Ben Greear943146d2012-02-11 15:39:40 +00005558 if (unlikely(skb->no_fcs))
5559 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5560
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005561 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005562 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5563 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005564 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005565 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5566 !adapter->tx_hwtstamp_skb)) {
5567 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5568 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5569 adapter->tx_hwtstamp_skb = skb_get(skb);
5570 schedule_work(&adapter->tx_hwtstamp_work);
5571 } else {
5572 skb_tx_timestamp(skb);
5573 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005574
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005575 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005576 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005577 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005578 e1000_maybe_stop_tx(tx_ring,
5579 (MAX_SKB_FRAGS *
5580 DIV_ROUND_UP(PAGE_SIZE,
5581 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005582 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005583 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005584 tx_ring->buffer_info[first].time_stamp = 0;
5585 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005586 }
5587
Auke Kokbc7f75f2007-09-17 12:30:59 -07005588 return NETDEV_TX_OK;
5589}
5590
5591/**
5592 * e1000_tx_timeout - Respond to a Tx Hang
5593 * @netdev: network interface device structure
5594 **/
5595static void e1000_tx_timeout(struct net_device *netdev)
5596{
5597 struct e1000_adapter *adapter = netdev_priv(netdev);
5598
5599 /* Do the reset outside of interrupt context */
5600 adapter->tx_timeout_count++;
5601 schedule_work(&adapter->reset_task);
5602}
5603
5604static void e1000_reset_task(struct work_struct *work)
5605{
5606 struct e1000_adapter *adapter;
5607 adapter = container_of(work, struct e1000_adapter, reset_task);
5608
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005609 /* don't run the task if already down */
5610 if (test_bit(__E1000_DOWN, &adapter->state))
5611 return;
5612
Bruce Allan12d43f72012-12-05 06:26:14 +00005613 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005614 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005615 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005616 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005617 e1000e_reinit_locked(adapter);
5618}
5619
5620/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005621 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005622 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005623 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005624 *
5625 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005626 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005627struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005628 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005629{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005630 struct e1000_adapter *adapter = netdev_priv(netdev);
5631
5632 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5633 spin_lock(&adapter->stats64_lock);
5634 e1000e_update_stats(adapter);
5635 /* Fill out the OS statistics structure */
5636 stats->rx_bytes = adapter->stats.gorc;
5637 stats->rx_packets = adapter->stats.gprc;
5638 stats->tx_bytes = adapter->stats.gotc;
5639 stats->tx_packets = adapter->stats.gptc;
5640 stats->multicast = adapter->stats.mprc;
5641 stats->collisions = adapter->stats.colc;
5642
5643 /* Rx Errors */
5644
Bruce Allane921eb12012-11-28 09:28:37 +00005645 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005646 * our own version based on RUC and ROC
5647 */
5648 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005649 adapter->stats.crcerrs + adapter->stats.algnerrc +
5650 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5651 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005652 stats->rx_crc_errors = adapter->stats.crcerrs;
5653 stats->rx_frame_errors = adapter->stats.algnerrc;
5654 stats->rx_missed_errors = adapter->stats.mpc;
5655
5656 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005657 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005658 stats->tx_aborted_errors = adapter->stats.ecol;
5659 stats->tx_window_errors = adapter->stats.latecol;
5660 stats->tx_carrier_errors = adapter->stats.tncrs;
5661
5662 /* Tx Dropped needs to be maintained elsewhere */
5663
5664 spin_unlock(&adapter->stats64_lock);
5665 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005666}
5667
5668/**
5669 * e1000_change_mtu - Change the Maximum Transfer Unit
5670 * @netdev: network interface device structure
5671 * @new_mtu: new value for maximum frame size
5672 *
5673 * Returns 0 on success, negative on failure
5674 **/
5675static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5676{
5677 struct e1000_adapter *adapter = netdev_priv(netdev);
5678 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5679
Bruce Allan2adc55c2009-06-02 11:28:58 +00005680 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005681 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5682 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5683 e_err("Jumbo Frames not supported.\n");
5684 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005685 }
5686
Bruce Allan2adc55c2009-06-02 11:28:58 +00005687 /* Supported frame sizes */
5688 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5689 (max_frame > adapter->max_hw_frame_size)) {
5690 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691 return -EINVAL;
5692 }
5693
Bruce Allan2fbe4522012-04-19 03:21:47 +00005694 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5695 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005696 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5697 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005698 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005699 return -EINVAL;
5700 }
5701
Auke Kokbc7f75f2007-09-17 12:30:59 -07005702 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005703 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005704 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005705 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005706 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5707 netdev->mtu = new_mtu;
David Ertman63eb48f2014-02-14 07:16:46 +00005708
5709 pm_runtime_get_sync(netdev->dev.parent);
5710
Auke Kokbc7f75f2007-09-17 12:30:59 -07005711 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00005712 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005713
Bruce Allane921eb12012-11-28 09:28:37 +00005714 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005715 * means we reserve 2 more, this pushes us to allocate from the next
5716 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005717 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005718 * However with the new *_jumbo_rx* routines, jumbo receives will use
5719 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005720 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005721
Jesse Brandeburg99261462010-01-22 22:56:16 +00005722 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005723 adapter->rx_buffer_len = 2048;
5724 else
5725 adapter->rx_buffer_len = 4096;
5726
5727 /* adjust allocation if LPE protects us, and we aren't using SBP */
5728 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005729 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005730 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005731 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005732
Auke Kokbc7f75f2007-09-17 12:30:59 -07005733 if (netif_running(netdev))
5734 e1000e_up(adapter);
5735 else
5736 e1000e_reset(adapter);
5737
David Ertman63eb48f2014-02-14 07:16:46 +00005738 pm_runtime_put_sync(netdev->dev.parent);
5739
Auke Kokbc7f75f2007-09-17 12:30:59 -07005740 clear_bit(__E1000_RESETTING, &adapter->state);
5741
5742 return 0;
5743}
5744
5745static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5746 int cmd)
5747{
5748 struct e1000_adapter *adapter = netdev_priv(netdev);
5749 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005750
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005751 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005752 return -EOPNOTSUPP;
5753
5754 switch (cmd) {
5755 case SIOCGMIIPHY:
5756 data->phy_id = adapter->hw.phy.addr;
5757 break;
5758 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005759 e1000_phy_read_status(adapter);
5760
Bruce Allan7c257692008-04-23 11:09:00 -07005761 switch (data->reg_num & 0x1F) {
5762 case MII_BMCR:
5763 data->val_out = adapter->phy_regs.bmcr;
5764 break;
5765 case MII_BMSR:
5766 data->val_out = adapter->phy_regs.bmsr;
5767 break;
5768 case MII_PHYSID1:
5769 data->val_out = (adapter->hw.phy.id >> 16);
5770 break;
5771 case MII_PHYSID2:
5772 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5773 break;
5774 case MII_ADVERTISE:
5775 data->val_out = adapter->phy_regs.advertise;
5776 break;
5777 case MII_LPA:
5778 data->val_out = adapter->phy_regs.lpa;
5779 break;
5780 case MII_EXPANSION:
5781 data->val_out = adapter->phy_regs.expansion;
5782 break;
5783 case MII_CTRL1000:
5784 data->val_out = adapter->phy_regs.ctrl1000;
5785 break;
5786 case MII_STAT1000:
5787 data->val_out = adapter->phy_regs.stat1000;
5788 break;
5789 case MII_ESTATUS:
5790 data->val_out = adapter->phy_regs.estatus;
5791 break;
5792 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005793 return -EIO;
5794 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005795 break;
5796 case SIOCSMIIREG:
5797 default:
5798 return -EOPNOTSUPP;
5799 }
5800 return 0;
5801}
5802
Bruce Allanb67e1912012-12-27 08:32:33 +00005803/**
5804 * e1000e_hwtstamp_ioctl - control hardware time stamping
5805 * @netdev: network interface device structure
5806 * @ifreq: interface request
5807 *
5808 * Outgoing time stamping can be enabled and disabled. Play nice and
5809 * disable it when requested, although it shouldn't cause any overhead
5810 * when no packet needs it. At most one packet in the queue may be
5811 * marked for time stamping, otherwise it would be impossible to tell
5812 * for sure to which packet the hardware time stamp belongs.
5813 *
5814 * Incoming time stamping has to be configured via the hardware filters.
5815 * Not all combinations are supported, in particular event type has to be
5816 * specified. Matching the kind of event packet is not supported, with the
5817 * exception of "all V2 events regardless of level 2 or 4".
5818 **/
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005819static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Bruce Allanb67e1912012-12-27 08:32:33 +00005820{
5821 struct e1000_adapter *adapter = netdev_priv(netdev);
5822 struct hwtstamp_config config;
5823 int ret_val;
5824
5825 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5826 return -EFAULT;
5827
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00005828 ret_val = e1000e_config_hwtstamp(adapter, &config);
Bruce Allanb67e1912012-12-27 08:32:33 +00005829 if (ret_val)
5830 return ret_val;
5831
Bruce Alland89777b2013-01-19 01:09:58 +00005832 switch (config.rx_filter) {
5833 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5834 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5835 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5836 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5837 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5838 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5839 /* With V2 type filters which specify a Sync or Delay Request,
5840 * Path Delay Request/Response messages are also time stamped
5841 * by hardware so notify the caller the requested packets plus
5842 * some others are time stamped.
5843 */
5844 config.rx_filter = HWTSTAMP_FILTER_SOME;
5845 break;
5846 default:
5847 break;
5848 }
5849
Bruce Allanb67e1912012-12-27 08:32:33 +00005850 return copy_to_user(ifr->ifr_data, &config,
5851 sizeof(config)) ? -EFAULT : 0;
5852}
5853
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005854static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
5855{
5856 struct e1000_adapter *adapter = netdev_priv(netdev);
5857
5858 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
5859 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
5860}
5861
Auke Kokbc7f75f2007-09-17 12:30:59 -07005862static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5863{
5864 switch (cmd) {
5865 case SIOCGMIIPHY:
5866 case SIOCGMIIREG:
5867 case SIOCSMIIREG:
5868 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005869 case SIOCSHWTSTAMP:
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005870 return e1000e_hwtstamp_set(netdev, ifr);
5871 case SIOCGHWTSTAMP:
5872 return e1000e_hwtstamp_get(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005873 default:
5874 return -EOPNOTSUPP;
5875 }
5876}
5877
Bruce Allana4f58f52009-06-02 11:29:18 +00005878static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5879{
5880 struct e1000_hw *hw = &adapter->hw;
David Ertman74f350e2014-02-22 03:15:17 +00005881 u32 i, mac_reg, wuc;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005882 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005883 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005884
5885 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005886 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005887
Bruce Allan2b6b1682011-05-13 07:20:09 +00005888 retval = hw->phy.ops.acquire(hw);
5889 if (retval) {
5890 e_err("Could not acquire PHY\n");
5891 return retval;
5892 }
5893
5894 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5895 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5896 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005897 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005898
5899 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005900 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5901 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005902 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5903 (u16)(mac_reg & 0xFFFF));
5904 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5905 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005906 }
5907
5908 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005909 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005910 mac_reg = er32(RCTL);
5911 if (mac_reg & E1000_RCTL_UPE)
5912 phy_reg |= BM_RCTL_UPE;
5913 if (mac_reg & E1000_RCTL_MPE)
5914 phy_reg |= BM_RCTL_MPE;
5915 phy_reg &= ~(BM_RCTL_MO_MASK);
5916 if (mac_reg & E1000_RCTL_MO_3)
5917 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005918 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005919 if (mac_reg & E1000_RCTL_BAM)
5920 phy_reg |= BM_RCTL_BAM;
5921 if (mac_reg & E1000_RCTL_PMCF)
5922 phy_reg |= BM_RCTL_PMCF;
5923 mac_reg = er32(CTRL);
5924 if (mac_reg & E1000_CTRL_RFCE)
5925 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005926 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005927
David Ertman74f350e2014-02-22 03:15:17 +00005928 wuc = E1000_WUC_PME_EN;
5929 if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
5930 wuc |= E1000_WUC_APME;
5931
Bruce Allana4f58f52009-06-02 11:29:18 +00005932 /* enable PHY wakeup in MAC register */
5933 ew32(WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00005934 ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
5935 E1000_WUC_PME_STATUS | wuc));
Bruce Allana4f58f52009-06-02 11:29:18 +00005936
5937 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005938 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
David Ertman74f350e2014-02-22 03:15:17 +00005939 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
Bruce Allana4f58f52009-06-02 11:29:18 +00005940
5941 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005942 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5943 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005944 if (retval)
5945 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005946release:
Bruce Allan94d81862009-11-20 23:25:26 +00005947 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005948
5949 return retval;
5950}
5951
David Ertman28002092014-02-14 07:16:41 +00005952static int e1000e_pm_freeze(struct device *dev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005953{
David Ertman28002092014-02-14 07:16:41 +00005954 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005956
5957 netif_device_detach(netdev);
5958
5959 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005960 int count = E1000_CHECK_RESET_COUNT;
5961
5962 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5963 usleep_range(10000, 20000);
5964
Auke Kokbc7f75f2007-09-17 12:30:59 -07005965 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
David Ertman28002092014-02-14 07:16:41 +00005966
5967 /* Quiesce the device without resetting the hardware */
5968 e1000e_down(adapter, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005969 e1000_free_irq(adapter);
5970 }
Bruce Allan4662e822008-08-26 18:37:06 -07005971 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972
David Ertman28002092014-02-14 07:16:41 +00005973 /* Allow time for pending master requests to run */
5974 e1000e_disable_pcie_master(&adapter->hw);
5975
5976 return 0;
5977}
5978
5979static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
5980{
5981 struct net_device *netdev = pci_get_drvdata(pdev);
5982 struct e1000_adapter *adapter = netdev_priv(netdev);
5983 struct e1000_hw *hw = &adapter->hw;
5984 u32 ctrl, ctrl_ext, rctl, status;
5985 /* Runtime suspend should only enable wakeup for link changes */
5986 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
5987 int retval = 0;
5988
Auke Kokbc7f75f2007-09-17 12:30:59 -07005989 status = er32(STATUS);
5990 if (status & E1000_STATUS_LU)
5991 wufc &= ~E1000_WUFC_LNKC;
5992
5993 if (wufc) {
5994 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005995 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005996
5997 /* turn on all-multi mode if wake on multicast is enabled */
5998 if (wufc & E1000_WUFC_MC) {
5999 rctl = er32(RCTL);
6000 rctl |= E1000_RCTL_MPE;
6001 ew32(RCTL, rctl);
6002 }
6003
6004 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00006005 ctrl |= E1000_CTRL_ADVD3WUC;
6006 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
6007 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006008 ew32(CTRL, ctrl);
6009
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006010 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
6011 adapter->hw.phy.media_type ==
6012 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006013 /* keep the laser running in D3 */
6014 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00006015 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006016 ew32(CTRL_EXT, ctrl_ext);
6017 }
6018
David Ertman63eb48f2014-02-14 07:16:46 +00006019 if (!runtime)
6020 e1000e_power_up_phy(adapter);
6021
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006022 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00006023 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006024
Bruce Allan82776a42009-08-14 14:35:33 +00006025 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00006026 /* enable wakeup by the PHY */
6027 retval = e1000_init_phy_wakeup(adapter, wufc);
6028 if (retval)
6029 return retval;
6030 } else {
6031 /* enable wakeup by the MAC */
6032 ew32(WUFC, wufc);
6033 ew32(WUC, E1000_WUC_PME_EN);
6034 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006035 } else {
6036 ew32(WUC, 0);
6037 ew32(WUFC, 0);
David Ertman28002092014-02-14 07:16:41 +00006038
6039 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006040 }
6041
David Ertman74f350e2014-02-22 03:15:17 +00006042 if (adapter->hw.phy.type == e1000_phy_igp_3) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006043 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
David Ertman74f350e2014-02-22 03:15:17 +00006044 } else if (hw->mac.type == e1000_pch_lpt) {
6045 if (!(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
6046 /* ULP does not support wake from unicast, multicast
6047 * or broadcast.
6048 */
6049 retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
6050
6051 if (retval)
6052 return retval;
6053 }
6054
Auke Kokbc7f75f2007-09-17 12:30:59 -07006055
Bruce Allane921eb12012-11-28 09:28:37 +00006056 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006057 * would have already happened in close and is redundant.
6058 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006059 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006060
Dean Nelson24b41c92013-06-13 03:55:44 +00006061 pci_clear_master(pdev);
6062
Bruce Allane921eb12012-11-28 09:28:37 +00006063 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006064 * correctable error when the MAC transitions from D0 to D3. To
6065 * prevent this we need to mask off the correctable errors on the
6066 * downstream port of the pci-e switch.
Li Zhange8c254c2013-08-13 18:42:58 +00006067 *
6068 * We don't have the associated upstream bridge while assigning
6069 * the PCI device into guest. For example, the KVM on power is
6070 * one of the cases.
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006071 */
6072 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6073 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006074 u16 devctl;
6075
Li Zhange8c254c2013-08-13 18:42:58 +00006076 if (!us_dev)
6077 return 0;
6078
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006079 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6080 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6081 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006082
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006083 pci_save_state(pdev);
6084 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006085
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006086 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006087 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006088
6089 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006090}
6091
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006092/**
6093 * e1000e_disable_aspm - Disable ASPM states
6094 * @pdev: pointer to PCI device struct
6095 * @state: bit-mask of ASPM states to disable
6096 *
6097 * Some devices *must* have certain ASPM states disabled per hardware errata.
6098 **/
6099static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006100{
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006101 struct pci_dev *parent = pdev->bus->self;
6102 u16 aspm_dis_mask = 0;
6103 u16 pdev_aspmc, parent_aspmc;
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006104
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006105 switch (state) {
6106 case PCIE_LINK_STATE_L0S:
6107 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6108 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6109 /* fall-through - can't have L1 without L0s */
6110 case PCIE_LINK_STATE_L1:
6111 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6112 break;
6113 default:
6114 return;
6115 }
6116
6117 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6118 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6119
6120 if (parent) {
6121 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6122 &parent_aspmc);
6123 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6124 }
6125
6126 /* Nothing to do if the ASPM states to be disabled already are */
6127 if (!(pdev_aspmc & aspm_dis_mask) &&
6128 (!parent || !(parent_aspmc & aspm_dis_mask)))
6129 return;
6130
6131 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6132 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6133 "L0s" : "",
6134 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6135 "L1" : "");
6136
6137#ifdef CONFIG_PCIEASPM
6138 pci_disable_link_state_locked(pdev, state);
6139
6140 /* Double-check ASPM control. If not disabled by the above, the
6141 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6142 * not enabled); override by writing PCI config space directly.
6143 */
6144 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6145 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6146
6147 if (!(aspm_dis_mask & pdev_aspmc))
6148 return;
6149#endif
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006150
Bruce Allane921eb12012-11-28 09:28:37 +00006151 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006152 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006153 */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006154 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
Bruce Allan6f461f62010-04-27 03:33:04 +00006155
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006156 if (parent)
6157 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6158 aspm_dis_mask);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006159}
6160
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006161#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006162static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006163{
6164 struct net_device *netdev = pci_get_drvdata(pdev);
6165 struct e1000_adapter *adapter = netdev_priv(netdev);
6166 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006167 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006168
Bruce Allan78cd29d2011-03-24 03:09:03 +00006169 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6170 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6171 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6172 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6173 if (aspm_disable_flag)
6174 e1000e_disable_aspm(pdev, aspm_disable_flag);
6175
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006176 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006177
Bruce Allan2fbe4522012-04-19 03:21:47 +00006178 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006179 e1000_resume_workarounds_pchlan(&adapter->hw);
6180
Auke Kokbc7f75f2007-09-17 12:30:59 -07006181 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006182
6183 /* report the system wakeup cause from S3/S4 */
6184 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6185 u16 phy_data;
6186
6187 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6188 if (phy_data) {
6189 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006190 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6191 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6192 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6193 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6194 phy_data & E1000_WUS_LNKC ?
6195 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006196 }
6197 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6198 } else {
6199 u32 wus = er32(WUS);
6200 if (wus) {
6201 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006202 wus & E1000_WUS_EX ? "Unicast Packet" :
6203 wus & E1000_WUS_MC ? "Multicast Packet" :
6204 wus & E1000_WUS_BC ? "Broadcast Packet" :
6205 wus & E1000_WUS_MAG ? "Magic Packet" :
6206 wus & E1000_WUS_LNKC ? "Link Status Change" :
6207 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006208 }
6209 ew32(WUS, ~0);
6210 }
6211
Auke Kokbc7f75f2007-09-17 12:30:59 -07006212 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006213
Bruce Allancd791612010-05-10 14:59:51 +00006214 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006215
Bruce Allane921eb12012-11-28 09:28:37 +00006216 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006217 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006218 * under the control of the driver.
6219 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006220 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006221 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006222
6223 return 0;
6224}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006225
David Ertman28002092014-02-14 07:16:41 +00006226static int e1000e_pm_thaw(struct device *dev)
6227{
6228 struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
6229 struct e1000_adapter *adapter = netdev_priv(netdev);
6230
6231 e1000e_set_interrupt_capability(adapter);
6232 if (netif_running(netdev)) {
6233 u32 err = e1000_request_irq(adapter);
6234
6235 if (err)
6236 return err;
6237
6238 e1000e_up(adapter);
6239 }
6240
6241 netif_device_attach(netdev);
6242
6243 return 0;
6244}
6245
Mika Westerberg38a529b2014-01-16 14:39:39 +02006246#ifdef CONFIG_PM_SLEEP
David Ertman28002092014-02-14 07:16:41 +00006247static int e1000e_pm_suspend(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006248{
6249 struct pci_dev *pdev = to_pci_dev(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006250
David Ertman28002092014-02-14 07:16:41 +00006251 e1000e_pm_freeze(dev);
6252
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006253 return __e1000_shutdown(pdev, false);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006254}
6255
David Ertman28002092014-02-14 07:16:41 +00006256static int e1000e_pm_resume(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006257{
6258 struct pci_dev *pdev = to_pci_dev(dev);
David Ertman28002092014-02-14 07:16:41 +00006259 int rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006260
David Ertman28002092014-02-14 07:16:41 +00006261 rc = __e1000_resume(pdev);
6262 if (rc)
6263 return rc;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006264
David Ertman28002092014-02-14 07:16:41 +00006265 return e1000e_pm_thaw(dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006266}
Mika Westerberg38a529b2014-01-16 14:39:39 +02006267#endif /* CONFIG_PM_SLEEP */
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006268
6269#ifdef CONFIG_PM_RUNTIME
David Ertman63eb48f2014-02-14 07:16:46 +00006270static int e1000e_pm_runtime_idle(struct device *dev)
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006271{
6272 struct pci_dev *pdev = to_pci_dev(dev);
6273 struct net_device *netdev = pci_get_drvdata(pdev);
6274 struct e1000_adapter *adapter = netdev_priv(netdev);
6275
David Ertman63eb48f2014-02-14 07:16:46 +00006276 if (!e1000e_has_link(adapter))
6277 pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006278
6279 return -EBUSY;
6280}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006281
David Ertman63eb48f2014-02-14 07:16:46 +00006282static int e1000e_pm_runtime_resume(struct device *dev)
6283{
6284 struct pci_dev *pdev = to_pci_dev(dev);
6285 struct net_device *netdev = pci_get_drvdata(pdev);
6286 struct e1000_adapter *adapter = netdev_priv(netdev);
6287 int rc;
6288
6289 rc = __e1000_resume(pdev);
6290 if (rc)
6291 return rc;
6292
6293 if (netdev->flags & IFF_UP)
6294 rc = e1000e_up(adapter);
6295
6296 return rc;
6297}
6298
6299static int e1000e_pm_runtime_suspend(struct device *dev)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006300{
6301 struct pci_dev *pdev = to_pci_dev(dev);
6302 struct net_device *netdev = pci_get_drvdata(pdev);
6303 struct e1000_adapter *adapter = netdev_priv(netdev);
6304
David Ertman63eb48f2014-02-14 07:16:46 +00006305 if (netdev->flags & IFF_UP) {
6306 int count = E1000_CHECK_RESET_COUNT;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006307
David Ertman63eb48f2014-02-14 07:16:46 +00006308 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
6309 usleep_range(10000, 20000);
6310
6311 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
6312
6313 /* Down the device without resetting the hardware */
6314 e1000e_down(adapter, false);
6315 }
6316
6317 if (__e1000_shutdown(pdev, true)) {
6318 e1000e_pm_runtime_resume(dev);
6319 return -EBUSY;
6320 }
6321
6322 return 0;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006323}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006324#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006325#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006326
6327static void e1000_shutdown(struct pci_dev *pdev)
6328{
David Ertman28002092014-02-14 07:16:41 +00006329 e1000e_pm_freeze(&pdev->dev);
6330
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006331 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006332}
6333
6334#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006335
Bruce Allan8bb62862013-01-16 08:46:49 +00006336static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006337{
6338 struct net_device *netdev = data;
6339 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006340
6341 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006342 int vector, msix_irq;
6343
Dongdong Deng147b2c82010-11-16 19:50:15 -08006344 vector = 0;
6345 msix_irq = adapter->msix_entries[vector].vector;
6346 disable_irq(msix_irq);
6347 e1000_intr_msix_rx(msix_irq, netdev);
6348 enable_irq(msix_irq);
6349
6350 vector++;
6351 msix_irq = adapter->msix_entries[vector].vector;
6352 disable_irq(msix_irq);
6353 e1000_intr_msix_tx(msix_irq, netdev);
6354 enable_irq(msix_irq);
6355
6356 vector++;
6357 msix_irq = adapter->msix_entries[vector].vector;
6358 disable_irq(msix_irq);
6359 e1000_msix_other(msix_irq, netdev);
6360 enable_irq(msix_irq);
6361 }
6362
6363 return IRQ_HANDLED;
6364}
6365
Bruce Allane921eb12012-11-28 09:28:37 +00006366/**
6367 * e1000_netpoll
6368 * @netdev: network interface device structure
6369 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006370 * Polling 'interrupt' - used by things like netconsole to send skbs
6371 * without having to re-enable interrupts. It's not called while
6372 * the interrupt routine is executing.
6373 */
6374static void e1000_netpoll(struct net_device *netdev)
6375{
6376 struct e1000_adapter *adapter = netdev_priv(netdev);
6377
Dongdong Deng147b2c82010-11-16 19:50:15 -08006378 switch (adapter->int_mode) {
6379 case E1000E_INT_MODE_MSIX:
6380 e1000_intr_msix(adapter->pdev->irq, netdev);
6381 break;
6382 case E1000E_INT_MODE_MSI:
6383 disable_irq(adapter->pdev->irq);
6384 e1000_intr_msi(adapter->pdev->irq, netdev);
6385 enable_irq(adapter->pdev->irq);
6386 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00006387 default: /* E1000E_INT_MODE_LEGACY */
Dongdong Deng147b2c82010-11-16 19:50:15 -08006388 disable_irq(adapter->pdev->irq);
6389 e1000_intr(adapter->pdev->irq, netdev);
6390 enable_irq(adapter->pdev->irq);
6391 break;
6392 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393}
6394#endif
6395
6396/**
6397 * e1000_io_error_detected - called when PCI error is detected
6398 * @pdev: Pointer to PCI device
6399 * @state: The current pci connection state
6400 *
6401 * This function is called after a PCI bus error affecting
6402 * this device has been detected.
6403 */
6404static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6405 pci_channel_state_t state)
6406{
6407 struct net_device *netdev = pci_get_drvdata(pdev);
6408 struct e1000_adapter *adapter = netdev_priv(netdev);
6409
6410 netif_device_detach(netdev);
6411
Mike Masonc93b5a72009-06-30 12:45:53 +00006412 if (state == pci_channel_io_perm_failure)
6413 return PCI_ERS_RESULT_DISCONNECT;
6414
Auke Kokbc7f75f2007-09-17 12:30:59 -07006415 if (netif_running(netdev))
David Ertman28002092014-02-14 07:16:41 +00006416 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006417 pci_disable_device(pdev);
6418
6419 /* Request a slot slot reset. */
6420 return PCI_ERS_RESULT_NEED_RESET;
6421}
6422
6423/**
6424 * e1000_io_slot_reset - called after the pci bus has been reset.
6425 * @pdev: Pointer to PCI device
6426 *
6427 * Restart the card from scratch, as if from a cold-boot. Implementation
David Ertman28002092014-02-14 07:16:41 +00006428 * resembles the first-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006429 */
6430static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6431{
6432 struct net_device *netdev = pci_get_drvdata(pdev);
6433 struct e1000_adapter *adapter = netdev_priv(netdev);
6434 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006435 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006436 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006437 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006438
Bruce Allan78cd29d2011-03-24 03:09:03 +00006439 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6440 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006441 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006442 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6443 if (aspm_disable_flag)
6444 e1000e_disable_aspm(pdev, aspm_disable_flag);
6445
Bruce Allanf0f422e2008-08-04 17:21:53 -07006446 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006447 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006448 dev_err(&pdev->dev,
6449 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006450 result = PCI_ERS_RESULT_DISCONNECT;
6451 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006452 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006453 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006454 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006455
6456 pci_enable_wake(pdev, PCI_D3hot, 0);
6457 pci_enable_wake(pdev, PCI_D3cold, 0);
6458
6459 e1000e_reset(adapter);
6460 ew32(WUS, ~0);
6461 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006462 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006463
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006464 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006465
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006466 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006467}
6468
6469/**
6470 * e1000_io_resume - called when traffic can start flowing again.
6471 * @pdev: Pointer to PCI device
6472 *
6473 * This callback is called when the error recovery driver tells us that
6474 * its OK to resume normal operation. Implementation resembles the
David Ertman28002092014-02-14 07:16:41 +00006475 * second-half of the e1000e_pm_resume routine.
Auke Kokbc7f75f2007-09-17 12:30:59 -07006476 */
6477static void e1000_io_resume(struct pci_dev *pdev)
6478{
6479 struct net_device *netdev = pci_get_drvdata(pdev);
6480 struct e1000_adapter *adapter = netdev_priv(netdev);
6481
Bruce Allancd791612010-05-10 14:59:51 +00006482 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006483
6484 if (netif_running(netdev)) {
6485 if (e1000e_up(adapter)) {
6486 dev_err(&pdev->dev,
6487 "can't bring device back up after reset\n");
6488 return;
6489 }
6490 }
6491
6492 netif_device_attach(netdev);
6493
Bruce Allane921eb12012-11-28 09:28:37 +00006494 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006495 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006496 * under the control of the driver.
6497 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006498 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006499 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006500}
6501
6502static void e1000_print_device_info(struct e1000_adapter *adapter)
6503{
6504 struct e1000_hw *hw = &adapter->hw;
6505 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006506 u32 ret_val;
6507 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006508
6509 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006510 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006511 /* bus width */
6512 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006513 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006514 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006515 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006516 e_info("Intel(R) PRO/%s Network Connection\n",
6517 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006518 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6519 E1000_PBANUM_LENGTH);
6520 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006521 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006522 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6523 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006524}
6525
Auke Kok10aa4c02008-08-04 17:21:20 -07006526static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6527{
6528 struct e1000_hw *hw = &adapter->hw;
6529 int ret_val;
6530 u16 buf = 0;
6531
6532 if (hw->mac.type != e1000_82573)
6533 return;
6534
6535 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006536 le16_to_cpus(&buf);
6537 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006538 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006539 dev_warn(&adapter->pdev->dev,
6540 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006541 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006542}
6543
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006544static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006545 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006546{
6547 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006548 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006549
6550 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6551 adapter->flags |= FLAG_TSO_FORCE;
6552
Patrick McHardyf6469682013-04-19 02:04:27 +00006553 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006554 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6555 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006556 return 0;
6557
Ben Greear01840392012-02-11 15:39:25 +00006558 if (changed & NETIF_F_RXFCS) {
6559 if (features & NETIF_F_RXFCS) {
6560 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6561 } else {
6562 /* We need to take it back to defaults, which might mean
6563 * stripping is still disabled at the adapter level.
6564 */
6565 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6566 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6567 else
6568 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6569 }
6570 }
6571
Bruce Allan70495a52012-01-11 01:26:50 +00006572 netdev->features = features;
6573
Bruce Allandc221292011-08-19 03:23:48 +00006574 if (netif_running(netdev))
6575 e1000e_reinit_locked(adapter);
6576 else
6577 e1000e_reset(adapter);
6578
6579 return 0;
6580}
6581
Stephen Hemminger651c2462008-11-19 21:57:48 -08006582static const struct net_device_ops e1000e_netdev_ops = {
6583 .ndo_open = e1000_open,
6584 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006585 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006586 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006587 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006588 .ndo_set_mac_address = e1000_set_mac,
6589 .ndo_change_mtu = e1000_change_mtu,
6590 .ndo_do_ioctl = e1000_ioctl,
6591 .ndo_tx_timeout = e1000_tx_timeout,
6592 .ndo_validate_addr = eth_validate_addr,
6593
Stephen Hemminger651c2462008-11-19 21:57:48 -08006594 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6595 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6596#ifdef CONFIG_NET_POLL_CONTROLLER
6597 .ndo_poll_controller = e1000_netpoll,
6598#endif
Bruce Allandc221292011-08-19 03:23:48 +00006599 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006600};
6601
Auke Kokbc7f75f2007-09-17 12:30:59 -07006602/**
6603 * e1000_probe - Device Initialization Routine
6604 * @pdev: PCI device information struct
6605 * @ent: entry in e1000_pci_tbl
6606 *
6607 * Returns 0 on success, negative on failure
6608 *
6609 * e1000_probe initializes an adapter identified by a pci_dev structure.
6610 * The OS initialization, configuring of the adapter private structure,
6611 * and a hardware reset occur.
6612 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006613static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006614{
6615 struct net_device *netdev;
6616 struct e1000_adapter *adapter;
6617 struct e1000_hw *hw;
6618 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006619 resource_size_t mmio_start, mmio_len;
6620 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006621 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006622 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006623 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006624 u16 eeprom_data = 0;
6625 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6626
Bruce Allan78cd29d2011-03-24 03:09:03 +00006627 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6628 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006629 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006630 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6631 if (aspm_disable_flag)
6632 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006633
Bruce Allanf0f422e2008-08-04 17:21:53 -07006634 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006635 if (err)
6636 return err;
6637
6638 pci_using_dac = 0;
Russell King718a39e2013-06-10 12:22:30 +01006639 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006640 if (!err) {
Russell King718a39e2013-06-10 12:22:30 +01006641 pci_using_dac = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006642 } else {
Russell King718a39e2013-06-10 12:22:30 +01006643 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006644 if (err) {
Russell King718a39e2013-06-10 12:22:30 +01006645 dev_err(&pdev->dev,
6646 "No usable DMA configuration, aborting\n");
6647 goto err_dma;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006648 }
6649 }
6650
Bruce Allan17e813e2013-02-20 04:06:01 +00006651 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6652 err = pci_request_selected_regions_exclusive(pdev, bars,
6653 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006654 if (err)
6655 goto err_pci_reg;
6656
Xiaotian Feng68eac462009-08-14 14:35:52 +00006657 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006658 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006659
Auke Kokbc7f75f2007-09-17 12:30:59 -07006660 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006661 /* PCI config space info */
6662 err = pci_save_state(pdev);
6663 if (err)
6664 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006665
6666 err = -ENOMEM;
6667 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6668 if (!netdev)
6669 goto err_alloc_etherdev;
6670
Auke Kokbc7f75f2007-09-17 12:30:59 -07006671 SET_NETDEV_DEV(netdev, &pdev->dev);
6672
Tom Herbertf85e4df2010-05-05 14:03:32 +00006673 netdev->irq = pdev->irq;
6674
Auke Kokbc7f75f2007-09-17 12:30:59 -07006675 pci_set_drvdata(pdev, netdev);
6676 adapter = netdev_priv(netdev);
6677 hw = &adapter->hw;
6678 adapter->netdev = netdev;
6679 adapter->pdev = pdev;
6680 adapter->ei = ei;
6681 adapter->pba = ei->pba;
6682 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006683 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006684 adapter->hw.adapter = adapter;
6685 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006686 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006687 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006688
6689 mmio_start = pci_resource_start(pdev, 0);
6690 mmio_len = pci_resource_len(pdev, 0);
6691
6692 err = -EIO;
6693 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6694 if (!adapter->hw.hw_addr)
6695 goto err_ioremap;
6696
6697 if ((adapter->flags & FLAG_HAS_FLASH) &&
6698 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6699 flash_start = pci_resource_start(pdev, 1);
6700 flash_len = pci_resource_len(pdev, 1);
6701 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6702 if (!adapter->hw.flash_address)
6703 goto err_flashmap;
6704 }
6705
Bruce Alland495bcb2013-03-20 07:23:11 +00006706 /* Set default EEE advertisement */
6707 if (adapter->flags2 & FLAG2_HAS_EEE)
6708 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
6709
Auke Kokbc7f75f2007-09-17 12:30:59 -07006710 /* construct the net_device struct */
Bruce Allane80bd1d2013-05-01 01:19:46 +00006711 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712 e1000e_set_ethtool_ops(netdev);
Bruce Allane80bd1d2013-05-01 01:19:46 +00006713 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006714 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006715 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006716
6717 netdev->mem_start = mmio_start;
6718 netdev->mem_end = mmio_start + mmio_len;
6719
6720 adapter->bd_number = cards_found++;
6721
Bruce Allan4662e822008-08-26 18:37:06 -07006722 e1000e_check_options(adapter);
6723
Auke Kokbc7f75f2007-09-17 12:30:59 -07006724 /* setup adapter struct */
6725 err = e1000_sw_init(adapter);
6726 if (err)
6727 goto err_sw_init;
6728
Auke Kokbc7f75f2007-09-17 12:30:59 -07006729 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6730 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6731 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6732
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006733 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006734 if (err)
6735 goto err_hw_init;
6736
Bruce Allan4a770352008-10-01 17:18:35 -07006737 if ((adapter->flags & FLAG_IS_ICH) &&
6738 (adapter->flags & FLAG_READ_ONLY_NVM))
6739 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6740
Auke Kokbc7f75f2007-09-17 12:30:59 -07006741 hw->mac.ops.get_bus_info(&adapter->hw);
6742
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006743 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006744
6745 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006746 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006747 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6748 adapter->hw.phy.disable_polarity_correction = 0;
6749 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6750 }
6751
Bruce Allan470a5422012-05-26 06:08:48 +00006752 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006753 dev_info(&pdev->dev,
6754 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006755
Bruce Allandc221292011-08-19 03:23:48 +00006756 /* Set initial default active device features */
6757 netdev->features = (NETIF_F_SG |
Patrick McHardyf6469682013-04-19 02:04:27 +00006758 NETIF_F_HW_VLAN_CTAG_RX |
6759 NETIF_F_HW_VLAN_CTAG_TX |
Bruce Allandc221292011-08-19 03:23:48 +00006760 NETIF_F_TSO |
6761 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006762 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006763 NETIF_F_RXCSUM |
6764 NETIF_F_HW_CSUM);
6765
6766 /* Set user-changeable features (subset of all device features) */
6767 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006768 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006769 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006770 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006771
6772 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardyf6469682013-04-19 02:04:27 +00006773 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006774
Bruce Allandc221292011-08-19 03:23:48 +00006775 netdev->vlan_features |= (NETIF_F_SG |
6776 NETIF_F_TSO |
6777 NETIF_F_TSO6 |
6778 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006779
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006780 netdev->priv_flags |= IFF_UNICAST_FLT;
6781
Yi Zou7b872a52010-09-22 17:57:58 +00006782 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006783 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006784 netdev->vlan_features |= NETIF_F_HIGHDMA;
6785 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006786
Auke Kokbc7f75f2007-09-17 12:30:59 -07006787 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6788 adapter->flags |= FLAG_MNG_PT_ENABLED;
6789
Bruce Allane921eb12012-11-28 09:28:37 +00006790 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006791 * put the device in a known good starting state
6792 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006793 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6794
Bruce Allane921eb12012-11-28 09:28:37 +00006795 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006796 * attempt. Let's give it a few tries
6797 */
6798 for (i = 0;; i++) {
6799 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6800 break;
6801 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006802 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006803 err = -EIO;
6804 goto err_eeprom;
6805 }
6806 }
6807
Auke Kok10aa4c02008-08-04 17:21:20 -07006808 e1000_eeprom_checks(adapter);
6809
Bruce Allan608f8a02010-01-13 02:04:58 +00006810 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006811 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006812 dev_err(&pdev->dev,
6813 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006814
6815 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006816
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006817 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006818 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006819 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006820 err = -EIO;
6821 goto err_eeprom;
6822 }
6823
6824 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006825 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006826 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006827
6828 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006829 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006830 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006831
6832 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6833 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006834 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6835 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006836 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006837
Auke Kokbc7f75f2007-09-17 12:30:59 -07006838 /* Initialize link parameters. User can change them with ethtool */
6839 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006840 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006841 adapter->hw.fc.requested_mode = e1000_fc_default;
6842 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006843 adapter->hw.phy.autoneg_advertised = 0x2f;
6844
Bruce Allane921eb12012-11-28 09:28:37 +00006845 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006846 * the EEPROM, enable the ACPI Magic Packet filter
6847 */
6848 if (adapter->flags & FLAG_APME_IN_WUC) {
6849 /* APME bit in EEPROM is mapped to WUC.APME */
6850 eeprom_data = er32(WUC);
6851 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006852 if ((hw->mac.type > e1000_ich10lan) &&
6853 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006854 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006855 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6856 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6857 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006858 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6859 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006860 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006861 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6862 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006863 }
6864
6865 /* fetch WoL from EEPROM */
6866 if (eeprom_data & eeprom_apme_mask)
6867 adapter->eeprom_wol |= E1000_WUFC_MAG;
6868
Bruce Allane921eb12012-11-28 09:28:37 +00006869 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006870 * where the eeprom may be wrong or the board simply won't support
6871 * wake on lan on a particular port
6872 */
6873 if (!(adapter->flags & FLAG_HAS_WOL))
6874 adapter->eeprom_wol = 0;
6875
6876 /* initialize the wol settings based on the eeprom settings */
6877 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006878
6879 /* make sure adapter isn't asleep if manageability is enabled */
6880 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
6881 (hw->mac.ops.check_mng_mode(hw)))
6882 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006883
Bruce Allan84527592008-11-21 17:00:22 -08006884 /* save off EEPROM version number */
6885 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6886
Auke Kokbc7f75f2007-09-17 12:30:59 -07006887 /* reset the hardware with the new settings */
6888 e1000e_reset(adapter);
6889
Bruce Allane921eb12012-11-28 09:28:37 +00006890 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006891 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006892 * under the control of the driver.
6893 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006894 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006895 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006896
Bruce Allanf2315bf2011-12-16 00:46:59 +00006897 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006898 err = register_netdev(netdev);
6899 if (err)
6900 goto err_register;
6901
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006902 /* carrier off reporting is important to ethtool even BEFORE open */
6903 netif_carrier_off(netdev);
6904
Bruce Alland89777b2013-01-19 01:09:58 +00006905 /* init PTP hardware clock */
6906 e1000e_ptp_init(adapter);
6907
Auke Kokbc7f75f2007-09-17 12:30:59 -07006908 e1000_print_device_info(adapter);
6909
Alan Sternf3ec4f82010-06-08 15:23:51 -04006910 if (pci_dev_run_wake(pdev))
6911 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006912
Auke Kokbc7f75f2007-09-17 12:30:59 -07006913 return 0;
6914
6915err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006916 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006917 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006918err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006919 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006920 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006921err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006922 kfree(adapter->tx_ring);
6923 kfree(adapter->rx_ring);
6924err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006925 if (adapter->hw.flash_address)
6926 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006927 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006928err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006929 iounmap(adapter->hw.hw_addr);
6930err_ioremap:
6931 free_netdev(netdev);
6932err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006933 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006934 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006935err_pci_reg:
6936err_dma:
6937 pci_disable_device(pdev);
6938 return err;
6939}
6940
6941/**
6942 * e1000_remove - Device Removal Routine
6943 * @pdev: PCI device information struct
6944 *
6945 * e1000_remove is called by the PCI subsystem to alert the driver
6946 * that it should release a PCI device. The could be caused by a
6947 * Hot-Plug event, or because the driver is going to be removed from
6948 * memory.
6949 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006950static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006951{
6952 struct net_device *netdev = pci_get_drvdata(pdev);
6953 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006954 bool down = test_bit(__E1000_DOWN, &adapter->state);
6955
Bruce Alland89777b2013-01-19 01:09:58 +00006956 e1000e_ptp_remove(adapter);
6957
Bruce Allane921eb12012-11-28 09:28:37 +00006958 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006959 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006960 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006961 if (!down)
6962 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006963 del_timer_sync(&adapter->watchdog_timer);
6964 del_timer_sync(&adapter->phy_info_timer);
6965
Bruce Allan41cec6f2009-11-20 23:28:56 +00006966 cancel_work_sync(&adapter->reset_task);
6967 cancel_work_sync(&adapter->watchdog_task);
6968 cancel_work_sync(&adapter->downshift_task);
6969 cancel_work_sync(&adapter->update_phy_task);
6970 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006971
Bruce Allanb67e1912012-12-27 08:32:33 +00006972 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6973 cancel_work_sync(&adapter->tx_hwtstamp_work);
6974 if (adapter->tx_hwtstamp_skb) {
6975 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6976 adapter->tx_hwtstamp_skb = NULL;
6977 }
6978 }
6979
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006980 /* Don't lie to e1000_close() down the road. */
6981 if (!down)
6982 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006983 unregister_netdev(netdev);
6984
Alan Sternf3ec4f82010-06-08 15:23:51 -04006985 if (pci_dev_run_wake(pdev))
6986 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006987
Bruce Allane921eb12012-11-28 09:28:37 +00006988 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006989 * would have already happened in close and is redundant.
6990 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006991 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006992
Bruce Allan4662e822008-08-26 18:37:06 -07006993 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006994 kfree(adapter->tx_ring);
6995 kfree(adapter->rx_ring);
6996
6997 iounmap(adapter->hw.hw_addr);
6998 if (adapter->hw.flash_address)
6999 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07007000 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00007001 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07007002
7003 free_netdev(netdev);
7004
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007005 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07007006 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00007007
Auke Kokbc7f75f2007-09-17 12:30:59 -07007008 pci_disable_device(pdev);
7009}
7010
7011/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007012static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007013 .error_detected = e1000_io_error_detected,
7014 .slot_reset = e1000_io_slot_reset,
7015 .resume = e1000_io_resume,
7016};
7017
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00007018static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07007019 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
7020 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
7021 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00007022 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
7023 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007024 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
7025 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07007026 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
7027 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
7028 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07007029
Auke Kokbc7f75f2007-09-17 12:30:59 -07007030 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
7031 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
7032 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
7033 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07007034
Auke Kokbc7f75f2007-09-17 12:30:59 -07007035 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
7036 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
7037 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07007038
Bruce Allan4662e822008-08-26 18:37:06 -07007039 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07007040 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00007041 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07007042
Auke Kokbc7f75f2007-09-17 12:30:59 -07007043 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
7044 board_80003es2lan },
7045 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
7046 board_80003es2lan },
7047 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
7048 board_80003es2lan },
7049 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
7050 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07007051
Auke Kokbc7f75f2007-09-17 12:30:59 -07007052 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
7053 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
7054 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
7055 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
7056 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
7057 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
7058 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00007059 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07007060
Auke Kokbc7f75f2007-09-17 12:30:59 -07007061 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
7062 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
7063 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
7064 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
7065 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07007066 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07007067 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
7068 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
7069 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
7070
7071 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7072 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7073 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007074
Bruce Allanf4187b52008-08-26 18:36:50 -07007075 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7076 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00007077 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07007078
Bruce Allana4f58f52009-06-02 11:29:18 +00007079 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7080 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7081 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7082 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7083
Bruce Alland3738bb2010-06-16 13:27:28 +00007084 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7085 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7086
Bruce Allan2fbe4522012-04-19 03:21:47 +00007087 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7088 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007089 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7090 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan91a3d822013-06-29 01:15:16 +00007091 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7092 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7093 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7094 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007095
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007096 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007097};
7098MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7099
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007100static const struct dev_pm_ops e1000_pm_ops = {
Kevin Hao72f72dc2014-03-18 00:26:49 -07007101#ifdef CONFIG_PM_SLEEP
David Ertman28002092014-02-14 07:16:41 +00007102 .suspend = e1000e_pm_suspend,
7103 .resume = e1000e_pm_resume,
7104 .freeze = e1000e_pm_freeze,
7105 .thaw = e1000e_pm_thaw,
7106 .poweroff = e1000e_pm_suspend,
7107 .restore = e1000e_pm_resume,
Kevin Hao72f72dc2014-03-18 00:26:49 -07007108#endif
David Ertman63eb48f2014-02-14 07:16:46 +00007109 SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
7110 e1000e_pm_runtime_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007111};
7112
Auke Kokbc7f75f2007-09-17 12:30:59 -07007113/* PCI Device API Driver */
7114static struct pci_driver e1000_driver = {
7115 .name = e1000e_driver_name,
7116 .id_table = e1000_pci_tbl,
7117 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007118 .remove = e1000_remove,
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007119 .driver = {
7120 .pm = &e1000_pm_ops,
7121 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007122 .shutdown = e1000_shutdown,
7123 .err_handler = &e1000_err_handler
7124};
7125
7126/**
7127 * e1000_init_module - Driver Registration Routine
7128 *
7129 * e1000_init_module is the first routine called when the driver is
7130 * loaded. All it does is register with the PCI subsystem.
7131 **/
7132static int __init e1000_init_module(void)
7133{
7134 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007135 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7136 e1000e_driver_version);
David Ertmane78b80b2014-02-04 01:56:06 +00007137 pr_info("Copyright(c) 1999 - 2014 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007138 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007139
Auke Kokbc7f75f2007-09-17 12:30:59 -07007140 return ret;
7141}
7142module_init(e1000_init_module);
7143
7144/**
7145 * e1000_exit_module - Driver Exit Cleanup Routine
7146 *
7147 * e1000_exit_module is called just before the driver is removed
7148 * from memory.
7149 **/
7150static void __exit e1000_exit_module(void)
7151{
7152 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007153}
7154module_exit(e1000_exit_module);
7155
Auke Kokbc7f75f2007-09-17 12:30:59 -07007156MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7157MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7158MODULE_LICENSE("GPL");
7159MODULE_VERSION(DRV_VERSION);
7160
Bruce Allan06c24b92012-02-23 03:13:13 +00007161/* netdev.c */