blob: a69388cba175464420a902680cac19ad4106f69e [file] [log] [blame]
David Ertmane78b80b2014-02-04 01:56:06 +00001/* Intel PRO/1000 Linux driver
2 * Copyright(c) 1999 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * Linux NICS <linux.nics@intel.com>
18 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
20 */
Auke Kokbc7f75f2007-09-17 12:30:59 -070021
Bruce Allan8544b9f2010-03-24 12:55:30 +000022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Auke Kokbc7f75f2007-09-17 12:30:59 -070024#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/vmalloc.h>
29#include <linux/pagemap.h>
30#include <linux/delay.h>
31#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#include <linux/tcp.h>
34#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <net/checksum.h>
37#include <net/ip6_checksum.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070038#include <linux/ethtool.h>
39#include <linux/if_vlan.h>
40#include <linux/cpu.h>
41#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020042#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000043#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000044#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040045#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070046
47#include "e1000.h"
48
Bruce Allanb3ccf262011-05-19 01:53:41 +000049#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000050
Bruce Allan8defe712013-03-06 09:03:13 +000051#define DRV_VERSION "2.3.2" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070052char e1000e_driver_name[] = "e1000e";
53const char e1000e_driver_version[] = DRV_VERSION;
54
stephen hemmingerb3f4d592012-03-13 06:04:20 +000055#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
56static int debug = -1;
57module_param(debug, int, 0);
58MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
59
Auke Kokbc7f75f2007-09-17 12:30:59 -070060static const struct e1000_info *e1000_info_tbl[] = {
61 [board_82571] = &e1000_82571_info,
62 [board_82572] = &e1000_82572_info,
63 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070064 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000065 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 [board_80003es2lan] = &e1000_es2_info,
67 [board_ich8lan] = &e1000_ich8_info,
68 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070069 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000070 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000071 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000072 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070073};
74
Taku Izumi84f4ee92010-04-27 14:39:08 +000075struct e1000_reg_info {
76 u32 ofs;
77 char *name;
78};
79
Taku Izumi84f4ee92010-04-27 14:39:08 +000080static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000081 /* General Registers */
82 {E1000_CTRL, "CTRL"},
83 {E1000_STATUS, "STATUS"},
84 {E1000_CTRL_EXT, "CTRL_EXT"},
85
86 /* Interrupt Registers */
87 {E1000_ICR, "ICR"},
88
Bruce Allanaf667a22010-12-31 06:10:01 +000089 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000090 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +000091 {E1000_RDLEN(0), "RDLEN"},
92 {E1000_RDH(0), "RDH"},
93 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000094 {E1000_RDTR, "RDTR"},
95 {E1000_RXDCTL(0), "RXDCTL"},
96 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +000097 {E1000_RDBAL(0), "RDBAL"},
98 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +000099 {E1000_RDFH, "RDFH"},
100 {E1000_RDFT, "RDFT"},
101 {E1000_RDFHS, "RDFHS"},
102 {E1000_RDFTS, "RDFTS"},
103 {E1000_RDFPC, "RDFPC"},
104
Bruce Allanaf667a22010-12-31 06:10:01 +0000105 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000106 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000107 {E1000_TDBAL(0), "TDBAL"},
108 {E1000_TDBAH(0), "TDBAH"},
109 {E1000_TDLEN(0), "TDLEN"},
110 {E1000_TDH(0), "TDH"},
111 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000112 {E1000_TIDV, "TIDV"},
113 {E1000_TXDCTL(0), "TXDCTL"},
114 {E1000_TADV, "TADV"},
115 {E1000_TARC(0), "TARC"},
116 {E1000_TDFH, "TDFH"},
117 {E1000_TDFT, "TDFT"},
118 {E1000_TDFHS, "TDFHS"},
119 {E1000_TDFTS, "TDFTS"},
120 {E1000_TDFPC, "TDFPC"},
121
122 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000123 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000124};
125
Bruce Allane921eb12012-11-28 09:28:37 +0000126/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000127 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000128 * @hw: pointer to the HW structure
129 * @reginfo: pointer to the register info table
130 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000131static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
132{
133 int n = 0;
134 char rname[16];
135 u32 regs[8];
136
137 switch (reginfo->ofs) {
138 case E1000_RXDCTL(0):
139 for (n = 0; n < 2; n++)
140 regs[n] = __er32(hw, E1000_RXDCTL(n));
141 break;
142 case E1000_TXDCTL(0):
143 for (n = 0; n < 2; n++)
144 regs[n] = __er32(hw, E1000_TXDCTL(n));
145 break;
146 case E1000_TARC(0):
147 for (n = 0; n < 2; n++)
148 regs[n] = __er32(hw, E1000_TARC(n));
149 break;
150 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000151 pr_info("%-15s %08x\n",
152 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000153 return;
154 }
155
156 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000157 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000158}
159
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000160static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
161 struct e1000_buffer *bi)
162{
163 int i;
164 struct e1000_ps_page *ps_page;
165
166 for (i = 0; i < adapter->rx_ps_pages; i++) {
167 ps_page = &bi->ps_pages[i];
168
169 if (ps_page->page) {
170 pr_info("packet dump for ps_page %d:\n", i);
171 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
172 16, 1, page_address(ps_page->page),
173 PAGE_SIZE, true);
174 }
175 }
176}
177
Bruce Allane921eb12012-11-28 09:28:37 +0000178/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000179 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000180 * @adapter: board private structure
181 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000182static void e1000e_dump(struct e1000_adapter *adapter)
183{
184 struct net_device *netdev = adapter->netdev;
185 struct e1000_hw *hw = &adapter->hw;
186 struct e1000_reg_info *reginfo;
187 struct e1000_ring *tx_ring = adapter->tx_ring;
188 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000189 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000190 __le64 a;
191 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000192 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000193 struct e1000_buffer *buffer_info;
194 struct e1000_ring *rx_ring = adapter->rx_ring;
195 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000196 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000197 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000198 __le64 a;
199 __le64 b;
200 __le64 c;
201 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000202 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000203 u32 staterr;
204 int i = 0;
205
206 if (!netif_msg_hw(adapter))
207 return;
208
209 /* Print netdevice Info */
210 if (netdev) {
211 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000212 pr_info("Device Name state trans_start last_rx\n");
Bruce Allane5fe2542013-02-20 04:06:27 +0000213 pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
214 netdev->state, netdev->trans_start, netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000215 }
216
217 /* Print Registers */
218 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000219 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000220 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
221 reginfo->name; reginfo++) {
222 e1000_regdump(hw, reginfo);
223 }
224
Bruce Allanaf667a22010-12-31 06:10:01 +0000225 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000227 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000228
Bruce Allanaf667a22010-12-31 06:10:01 +0000229 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000230 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000231 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000232 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
233 0, tx_ring->next_to_use, tx_ring->next_to_clean,
234 (unsigned long long)buffer_info->dma,
235 buffer_info->length,
236 buffer_info->next_to_watch,
237 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238
Bruce Allanaf667a22010-12-31 06:10:01 +0000239 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240 if (!netif_msg_tx_done(adapter))
241 goto rx_ring_summary;
242
Bruce Allanaf667a22010-12-31 06:10:01 +0000243 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244
245 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
246 *
247 * Legacy Transmit Descriptor
248 * +--------------------------------------------------------------+
249 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
250 * +--------------------------------------------------------------+
251 * 8 | Special | CSS | Status | CMD | CSO | Length |
252 * +--------------------------------------------------------------+
253 * 63 48 47 36 35 32 31 24 23 16 15 0
254 *
255 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
256 * 63 48 47 40 39 32 31 16 15 8 7 0
257 * +----------------------------------------------------------------+
258 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
259 * +----------------------------------------------------------------+
260 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
261 * +----------------------------------------------------------------+
262 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
263 *
264 * Extended Data Descriptor (DTYP=0x1)
265 * +----------------------------------------------------------------+
266 * 0 | Buffer Address [63:0] |
267 * +----------------------------------------------------------------+
268 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
269 * +----------------------------------------------------------------+
270 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
271 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000272 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
273 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
274 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000275 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000276 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000277 tx_desc = E1000_TX_DESC(*tx_ring, i);
278 buffer_info = &tx_ring->buffer_info[i];
279 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000280 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000281 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000282 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000283 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000284 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000285 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000286 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000287 next_desc = "";
288 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
289 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
290 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
291 i,
292 (unsigned long long)le64_to_cpu(u0->a),
293 (unsigned long long)le64_to_cpu(u0->b),
294 (unsigned long long)buffer_info->dma,
295 buffer_info->length, buffer_info->next_to_watch,
296 (unsigned long long)buffer_info->time_stamp,
297 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000298
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000299 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000300 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000301 16, 1, buffer_info->skb->data,
302 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000303 }
304
Bruce Allanaf667a22010-12-31 06:10:01 +0000305 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000307 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000308 pr_info("Queue [NTU] [NTC]\n");
309 pr_info(" %5d %5X %5X\n",
310 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000311
Bruce Allanaf667a22010-12-31 06:10:01 +0000312 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000314 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315
Bruce Allanaf667a22010-12-31 06:10:01 +0000316 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000317 switch (adapter->rx_ps_pages) {
318 case 1:
319 case 2:
320 case 3:
321 /* [Extended] Packet Split Receive Descriptor Format
322 *
323 * +-----------------------------------------------------+
324 * 0 | Buffer Address 0 [63:0] |
325 * +-----------------------------------------------------+
326 * 8 | Buffer Address 1 [63:0] |
327 * +-----------------------------------------------------+
328 * 16 | Buffer Address 2 [63:0] |
329 * +-----------------------------------------------------+
330 * 24 | Buffer Address 3 [63:0] |
331 * +-----------------------------------------------------+
332 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000333 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000334 /* [Extended] Receive Descriptor (Write-Back) Format
335 *
336 * 63 48 47 32 31 13 12 8 7 4 3 0
337 * +------------------------------------------------------+
338 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
339 * | Checksum | Ident | | Queue | | Type |
340 * +------------------------------------------------------+
341 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
342 * +------------------------------------------------------+
343 * 63 48 47 32 31 20 19 0
344 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000345 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000346 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000347 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000348 buffer_info = &rx_ring->buffer_info[i];
349 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
350 u1 = (struct my_u1 *)rx_desc_ps;
351 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000352 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000353
354 if (i == rx_ring->next_to_use)
355 next_desc = " NTU";
356 else if (i == rx_ring->next_to_clean)
357 next_desc = " NTC";
358 else
359 next_desc = "";
360
Taku Izumi84f4ee92010-04-27 14:39:08 +0000361 if (staterr & E1000_RXD_STAT_DD) {
362 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000363 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
364 "RWB", i,
365 (unsigned long long)le64_to_cpu(u1->a),
366 (unsigned long long)le64_to_cpu(u1->b),
367 (unsigned long long)le64_to_cpu(u1->c),
368 (unsigned long long)le64_to_cpu(u1->d),
369 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000370 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000371 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
372 "R ", i,
373 (unsigned long long)le64_to_cpu(u1->a),
374 (unsigned long long)le64_to_cpu(u1->b),
375 (unsigned long long)le64_to_cpu(u1->c),
376 (unsigned long long)le64_to_cpu(u1->d),
377 (unsigned long long)buffer_info->dma,
378 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000379
380 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000381 e1000e_dump_ps_pages(adapter,
382 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000383 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000384 }
385 break;
386 default:
387 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000388 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000389 *
Bruce Allan5f450212011-07-22 06:21:46 +0000390 * +-----------------------------------------------------+
391 * 0 | Buffer Address [63:0] |
392 * +-----------------------------------------------------+
393 * 8 | Reserved |
394 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000395 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000396 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000397 /* Extended Receive Descriptor (Write-Back) Format
398 *
399 * 63 48 47 32 31 24 23 4 3 0
400 * +------------------------------------------------------+
401 * | RSS Hash | | | |
402 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
403 * | Packet | IP | | | Type |
404 * | Checksum | Ident | | | |
405 * +------------------------------------------------------+
406 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
407 * +------------------------------------------------------+
408 * 63 48 47 32 31 20 19 0
409 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000410 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000411
412 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000413 const char *next_desc;
414
Taku Izumi84f4ee92010-04-27 14:39:08 +0000415 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000416 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
417 u1 = (struct my_u1 *)rx_desc;
418 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000419
420 if (i == rx_ring->next_to_use)
421 next_desc = " NTU";
422 else if (i == rx_ring->next_to_clean)
423 next_desc = " NTC";
424 else
425 next_desc = "";
426
Bruce Allan5f450212011-07-22 06:21:46 +0000427 if (staterr & E1000_RXD_STAT_DD) {
428 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000429 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
430 "RWB", i,
431 (unsigned long long)le64_to_cpu(u1->a),
432 (unsigned long long)le64_to_cpu(u1->b),
433 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000434 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000435 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
436 "R ", i,
437 (unsigned long long)le64_to_cpu(u1->a),
438 (unsigned long long)le64_to_cpu(u1->b),
439 (unsigned long long)buffer_info->dma,
440 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000441
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000442 if (netif_msg_pktdata(adapter) &&
443 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000444 print_hex_dump(KERN_INFO, "",
445 DUMP_PREFIX_ADDRESS, 16,
446 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000447 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000448 adapter->rx_buffer_len,
449 true);
450 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000451 }
452 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000453}
454
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455/**
456 * e1000_desc_unused - calculate if we have unused descriptors
457 **/
458static int e1000_desc_unused(struct e1000_ring *ring)
459{
460 if (ring->next_to_clean > ring->next_to_use)
461 return ring->next_to_clean - ring->next_to_use - 1;
462
463 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
464}
465
466/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000467 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
468 * @adapter: board private structure
469 * @hwtstamps: time stamp structure to update
470 * @systim: unsigned 64bit system time value.
471 *
472 * Convert the system time value stored in the RX/TXSTMP registers into a
473 * hwtstamp which can be used by the upper level time stamping functions.
474 *
475 * The 'systim_lock' spinlock is used to protect the consistency of the
476 * system time value. This is needed because reading the 64 bit time
477 * value involves reading two 32 bit registers. The first read latches the
478 * value.
479 **/
480static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
481 struct skb_shared_hwtstamps *hwtstamps,
482 u64 systim)
483{
484 u64 ns;
485 unsigned long flags;
486
487 spin_lock_irqsave(&adapter->systim_lock, flags);
488 ns = timecounter_cyc2time(&adapter->tc, systim);
489 spin_unlock_irqrestore(&adapter->systim_lock, flags);
490
491 memset(hwtstamps, 0, sizeof(*hwtstamps));
492 hwtstamps->hwtstamp = ns_to_ktime(ns);
493}
494
495/**
496 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
497 * @adapter: board private structure
498 * @status: descriptor extended error and status field
499 * @skb: particular skb to include time stamp
500 *
501 * If the time stamp is valid, convert it into the timecounter ns value
502 * and store that result into the shhwtstamps structure which is passed
503 * up the network stack.
504 **/
505static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
506 struct sk_buff *skb)
507{
508 struct e1000_hw *hw = &adapter->hw;
509 u64 rxstmp;
510
511 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
512 !(status & E1000_RXDEXT_STATERR_TST) ||
513 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
514 return;
515
516 /* The Rx time stamp registers contain the time stamp. No other
517 * received packet will be time stamped until the Rx time stamp
518 * registers are read. Because only one packet can be time stamped
519 * at a time, the register values must belong to this packet and
520 * therefore none of the other additional attributes need to be
521 * compared.
522 */
523 rxstmp = (u64)er32(RXSTMPL);
524 rxstmp |= (u64)er32(RXSTMPH) << 32;
525 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
526
527 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
528}
529
530/**
Bruce Allanad680762008-03-28 09:15:03 -0700531 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000533 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
535 * @skb: pointer to sk_buff to be indicated to stack
536 **/
537static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000538 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000539 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000541 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000542
543 e1000e_rx_hwtstamp(adapter, staterr, skb);
544
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545 skb->protocol = eth_type_trans(skb, netdev);
546
Bruce Allanb67e1912012-12-27 08:32:33 +0000547 if (staterr & E1000_RXD_STAT_VP)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000548 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000549
550 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700551}
552
553/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000554 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000555 * @adapter: board private structure
556 * @status_err: receive descriptor status and error fields
557 * @csum: receive descriptor csum field
558 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 **/
560static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000561 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562{
563 u16 status = (u16)status_err;
564 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700565
566 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700567
Bruce Allanafd12932012-01-05 00:34:05 +0000568 /* Rx checksum disabled */
569 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
570 return;
571
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572 /* Ignore Checksum bit is set */
573 if (status & E1000_RXD_STAT_IXSM)
574 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000575
Bruce Allan2e1706f2012-06-30 20:02:42 +0000576 /* TCP/UDP checksum error bit or IP checksum error bit is set */
577 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 /* let the stack verify checksum errors */
579 adapter->hw_csum_err++;
580 return;
581 }
582
583 /* TCP/UDP Checksum has not been calculated */
584 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
585 return;
586
587 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000588 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700589 adapter->hw_csum_good++;
590}
591
Bruce Allan55aa6982011-12-16 00:45:45 +0000592static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700593{
Bruce Allan55aa6982011-12-16 00:45:45 +0000594 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700595 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000596 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700597
Bruce Allanbdc125f2012-03-20 03:47:52 +0000598 writel(i, rx_ring->tail);
599
600 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700601 u32 rctl = er32(RCTL);
602 ew32(RCTL, rctl & ~E1000_RCTL_EN);
603 e_err("ME firmware caused invalid RDT - resetting\n");
604 schedule_work(&adapter->reset_task);
605 }
606}
607
Bruce Allan55aa6982011-12-16 00:45:45 +0000608static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700609{
Bruce Allan55aa6982011-12-16 00:45:45 +0000610 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700611 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000612 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700613
Bruce Allanbdc125f2012-03-20 03:47:52 +0000614 writel(i, tx_ring->tail);
615
616 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700617 u32 tctl = er32(TCTL);
618 ew32(TCTL, tctl & ~E1000_TCTL_EN);
619 e_err("ME firmware caused invalid TDT - resetting\n");
620 schedule_work(&adapter->reset_task);
621 }
622}
623
624/**
Bruce Allan5f450212011-07-22 06:21:46 +0000625 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000626 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000628static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000629 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630{
Bruce Allan55aa6982011-12-16 00:45:45 +0000631 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700632 struct net_device *netdev = adapter->netdev;
633 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000634 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 struct e1000_buffer *buffer_info;
636 struct sk_buff *skb;
637 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000638 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639
640 i = rx_ring->next_to_use;
641 buffer_info = &rx_ring->buffer_info[i];
642
643 while (cleaned_count--) {
644 skb = buffer_info->skb;
645 if (skb) {
646 skb_trim(skb, 0);
647 goto map_skb;
648 }
649
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000650 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 if (!skb) {
652 /* Better luck next round */
653 adapter->alloc_rx_buff_failed++;
654 break;
655 }
656
Auke Kokbc7f75f2007-09-17 12:30:59 -0700657 buffer_info->skb = skb;
658map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000659 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000661 DMA_FROM_DEVICE);
662 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000663 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700664 adapter->rx_dma_failed++;
665 break;
666 }
667
Bruce Allan5f450212011-07-22 06:21:46 +0000668 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
669 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670
Tom Herbert50849d72010-05-05 14:02:49 +0000671 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000672 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000673 * know there are new descriptors to fetch. (Only
674 * applicable for weak-ordered memory model archs,
675 * such as IA-64).
676 */
677 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700678 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000679 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700680 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000681 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000682 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683 i++;
684 if (i == rx_ring->count)
685 i = 0;
686 buffer_info = &rx_ring->buffer_info[i];
687 }
688
Tom Herbert50849d72010-05-05 14:02:49 +0000689 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700690}
691
692/**
693 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000694 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700695 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000696static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000697 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698{
Bruce Allan55aa6982011-12-16 00:45:45 +0000699 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700700 struct net_device *netdev = adapter->netdev;
701 struct pci_dev *pdev = adapter->pdev;
702 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703 struct e1000_buffer *buffer_info;
704 struct e1000_ps_page *ps_page;
705 struct sk_buff *skb;
706 unsigned int i, j;
707
708 i = rx_ring->next_to_use;
709 buffer_info = &rx_ring->buffer_info[i];
710
711 while (cleaned_count--) {
712 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
713
714 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700715 ps_page = &buffer_info->ps_pages[j];
716 if (j >= adapter->rx_ps_pages) {
717 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000718 rx_desc->read.buffer_addr[j + 1] =
719 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700720 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700721 }
Auke Kok47f44e42007-10-25 13:57:44 -0700722 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000723 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700724 if (!ps_page->page) {
725 adapter->alloc_rx_buff_failed++;
726 goto no_buffers;
727 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000728 ps_page->dma = dma_map_page(&pdev->dev,
729 ps_page->page,
730 0, PAGE_SIZE,
731 DMA_FROM_DEVICE);
732 if (dma_mapping_error(&pdev->dev,
733 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700734 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000735 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700736 adapter->rx_dma_failed++;
737 goto no_buffers;
738 }
739 }
Bruce Allane921eb12012-11-28 09:28:37 +0000740 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700741 * didn't change because each write-back
742 * erases this info.
743 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000744 rx_desc->read.buffer_addr[j + 1] =
745 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700746 }
747
Bruce Allane5fe2542013-02-20 04:06:27 +0000748 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000749 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700750
751 if (!skb) {
752 adapter->alloc_rx_buff_failed++;
753 break;
754 }
755
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000757 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000759 DMA_FROM_DEVICE);
760 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000761 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 adapter->rx_dma_failed++;
763 /* cleanup skb */
764 dev_kfree_skb_any(skb);
765 buffer_info->skb = NULL;
766 break;
767 }
768
769 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
770
Tom Herbert50849d72010-05-05 14:02:49 +0000771 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000772 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000773 * know there are new descriptors to fetch. (Only
774 * applicable for weak-ordered memory model archs,
775 * such as IA-64).
776 */
777 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700778 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000779 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700780 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000781 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000782 }
783
Auke Kokbc7f75f2007-09-17 12:30:59 -0700784 i++;
785 if (i == rx_ring->count)
786 i = 0;
787 buffer_info = &rx_ring->buffer_info[i];
788 }
789
790no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000791 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792}
793
794/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700795 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000796 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700797 * @cleaned_count: number of buffers to allocate this pass
798 **/
799
Bruce Allan55aa6982011-12-16 00:45:45 +0000800static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000801 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700802{
Bruce Allan55aa6982011-12-16 00:45:45 +0000803 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700804 struct net_device *netdev = adapter->netdev;
805 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000806 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700807 struct e1000_buffer *buffer_info;
808 struct sk_buff *skb;
809 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000810 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700811
812 i = rx_ring->next_to_use;
813 buffer_info = &rx_ring->buffer_info[i];
814
815 while (cleaned_count--) {
816 skb = buffer_info->skb;
817 if (skb) {
818 skb_trim(skb, 0);
819 goto check_page;
820 }
821
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000822 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700823 if (unlikely(!skb)) {
824 /* Better luck next round */
825 adapter->alloc_rx_buff_failed++;
826 break;
827 }
828
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700829 buffer_info->skb = skb;
830check_page:
831 /* allocate a new page if necessary */
832 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000833 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700834 if (unlikely(!buffer_info->page)) {
835 adapter->alloc_rx_buff_failed++;
836 break;
837 }
838 }
839
Christoph Paasch37287fae2013-03-20 08:59:46 +0000840 if (!buffer_info->dma) {
Nick Nunley0be3f552010-04-27 13:09:05 +0000841 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000842 buffer_info->page, 0,
843 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000844 DMA_FROM_DEVICE);
Christoph Paasch37287fae2013-03-20 08:59:46 +0000845 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
846 adapter->alloc_rx_buff_failed++;
847 break;
848 }
849 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700850
Bruce Allan5f450212011-07-22 06:21:46 +0000851 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
852 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700853
854 if (unlikely(++i == rx_ring->count))
855 i = 0;
856 buffer_info = &rx_ring->buffer_info[i];
857 }
858
859 if (likely(rx_ring->next_to_use != i)) {
860 rx_ring->next_to_use = i;
861 if (unlikely(i-- == 0))
862 i = (rx_ring->count - 1);
863
864 /* Force memory writes to complete before letting h/w
865 * know there are new descriptors to fetch. (Only
866 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000867 * such as IA-64).
868 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700869 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700870 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000871 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700872 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000873 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700874 }
875}
876
Bruce Allan70495a52012-01-11 01:26:50 +0000877static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
878 struct sk_buff *skb)
879{
880 if (netdev->features & NETIF_F_RXHASH)
881 skb->rxhash = le32_to_cpu(rss);
882}
883
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700884/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000885 * e1000_clean_rx_irq - Send received data up the network stack
886 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 *
888 * the return value indicates whether actual cleaning was done, there
889 * is no guarantee that everything was cleaned
890 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000891static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
892 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700893{
Bruce Allan55aa6982011-12-16 00:45:45 +0000894 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895 struct net_device *netdev = adapter->netdev;
896 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000897 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000898 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000900 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 unsigned int i;
902 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000903 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700904 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
905
906 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000907 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
908 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909 buffer_info = &rx_ring->buffer_info[i];
910
Bruce Allan5f450212011-07-22 06:21:46 +0000911 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913
914 if (*work_done >= work_to_do)
915 break;
916 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000917 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919 skb = buffer_info->skb;
920 buffer_info->skb = NULL;
921
922 prefetch(skb->data - NET_IP_ALIGN);
923
924 i++;
925 if (i == rx_ring->count)
926 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000927 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928 prefetch(next_rxd);
929
930 next_buffer = &rx_ring->buffer_info[i];
931
Rusty Russell3db1cd52011-12-19 13:56:45 +0000932 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 cleaned_count++;
Bruce Allane5fe2542013-02-20 04:06:27 +0000934 dma_unmap_single(&pdev->dev, buffer_info->dma,
935 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 buffer_info->dma = 0;
937
Bruce Allan5f450212011-07-22 06:21:46 +0000938 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939
Bruce Allane921eb12012-11-28 09:28:37 +0000940 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000941 * packet, if that's the case we need to toss it. In fact, we
942 * need to toss every packet with the EOP bit clear and the
943 * next frame that _does_ have the EOP bit set, as it is by
944 * definition only a frame fragment
945 */
Bruce Allan5f450212011-07-22 06:21:46 +0000946 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000947 adapter->flags2 |= FLAG2_IS_DISCARDING;
948
949 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000951 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 /* recycle */
953 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000954 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000955 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700956 goto next_desc;
957 }
958
Ben Greearcf955e62012-02-11 15:39:51 +0000959 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
960 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 /* recycle */
962 buffer_info->skb = skb;
963 goto next_desc;
964 }
965
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000966 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000967 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
968 /* If configured to store CRC, don't subtract FCS,
969 * but keep the FCS bytes out of the total_rx_bytes
970 * counter
971 */
972 if (netdev->features & NETIF_F_RXFCS)
973 total_rx_bytes -= 4;
974 else
975 length -= 4;
976 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000977
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978 total_rx_bytes += length;
979 total_rx_packets++;
980
Bruce Allane921eb12012-11-28 09:28:37 +0000981 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700983 * of reassembly being done in the stack
984 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700985 if (length < copybreak) {
986 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000987 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700989 skb_copy_to_linear_data_offset(new_skb,
990 -NET_IP_ALIGN,
991 (skb->data -
992 NET_IP_ALIGN),
993 (length +
994 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700995 /* save the skb in buffer_info as good */
996 buffer_info->skb = skb;
997 skb = new_skb;
998 }
999 /* else just continue with the old one */
1000 }
1001 /* end copybreak code */
1002 skb_put(skb, length);
1003
1004 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001005 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006
Bruce Allan70495a52012-01-11 01:26:50 +00001007 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1008
Bruce Allan5f450212011-07-22 06:21:46 +00001009 e1000_receive_skb(adapter, netdev, skb, staterr,
1010 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011
1012next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001013 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014
1015 /* return some buffers to hardware, one at a time is too slow */
1016 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001017 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001018 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 cleaned_count = 0;
1020 }
1021
1022 /* use prefetched values */
1023 rx_desc = next_rxd;
1024 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001025
1026 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 }
1028 rx_ring->next_to_clean = i;
1029
1030 cleaned_count = e1000_desc_unused(rx_ring);
1031 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001032 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033
Auke Kokbc7f75f2007-09-17 12:30:59 -07001034 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001035 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036 return cleaned;
1037}
1038
Bruce Allan55aa6982011-12-16 00:45:45 +00001039static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1040 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041{
Bruce Allan55aa6982011-12-16 00:45:45 +00001042 struct e1000_adapter *adapter = tx_ring->adapter;
1043
Alexander Duyck03b13202009-12-02 16:45:31 +00001044 if (buffer_info->dma) {
1045 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001046 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1047 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001048 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001049 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1050 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001051 buffer_info->dma = 0;
1052 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053 if (buffer_info->skb) {
1054 dev_kfree_skb_any(buffer_info->skb);
1055 buffer_info->skb = NULL;
1056 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001057 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058}
1059
Bruce Allan41cec6f2009-11-20 23:28:56 +00001060static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001062 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001063 struct e1000_adapter,
1064 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001065 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066 struct e1000_ring *tx_ring = adapter->tx_ring;
1067 unsigned int i = tx_ring->next_to_clean;
1068 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1069 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001070 struct e1000_hw *hw = &adapter->hw;
1071 u16 phy_status, phy_1000t_status, phy_ext_status;
1072 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001074 if (test_bit(__E1000_DOWN, &adapter->state))
1075 return;
1076
Bruce Allane5fe2542013-02-20 04:06:27 +00001077 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001078 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001079 * flush pending descriptor writebacks to memory
1080 */
1081 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1082 /* execute the writes immediately */
1083 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001084 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001085 * the write is successful
1086 */
1087 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1088 /* execute the writes immediately */
1089 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001090 adapter->tx_hang_recheck = true;
1091 return;
1092 }
1093 /* Real hang detected */
1094 adapter->tx_hang_recheck = false;
1095 netif_stop_queue(netdev);
1096
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001097 e1e_rphy(hw, MII_BMSR, &phy_status);
1098 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1099 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001100
1101 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1102
1103 /* detected Hardware unit hang */
1104 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001105 " TDH <%x>\n"
1106 " TDT <%x>\n"
1107 " next_to_use <%x>\n"
1108 " next_to_clean <%x>\n"
1109 "buffer_info[next_to_clean]:\n"
1110 " time_stamp <%lx>\n"
1111 " next_to_watch <%x>\n"
1112 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001113 " next_to_watch.status <%x>\n"
1114 "MAC Status <%x>\n"
1115 "PHY Status <%x>\n"
1116 "PHY 1000BASE-T Status <%x>\n"
1117 "PHY Extended Status <%x>\n"
1118 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001119 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1120 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1121 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1122 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001123
1124 /* Suggest workaround for known h/w issue */
1125 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1126 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127}
1128
1129/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001130 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1131 * @work: pointer to work struct
1132 *
1133 * This work function polls the TSYNCTXCTL valid bit to determine when a
1134 * timestamp has been taken for the current stored skb. The timestamp must
1135 * be for this skb because only one such packet is allowed in the queue.
1136 */
1137static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1138{
1139 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1140 tx_hwtstamp_work);
1141 struct e1000_hw *hw = &adapter->hw;
1142
1143 if (!adapter->tx_hwtstamp_skb)
1144 return;
1145
1146 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1147 struct skb_shared_hwtstamps shhwtstamps;
1148 u64 txstmp;
1149
1150 txstmp = er32(TXSTMPL);
1151 txstmp |= (u64)er32(TXSTMPH) << 32;
1152
1153 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1154
1155 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1156 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1157 adapter->tx_hwtstamp_skb = NULL;
1158 } else {
1159 /* reschedule to check later */
1160 schedule_work(&adapter->tx_hwtstamp_work);
1161 }
1162}
1163
1164/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001166 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 *
1168 * the return value indicates whether actual cleaning was done, there
1169 * is no guarantee that everything was cleaned
1170 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001171static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172{
Bruce Allan55aa6982011-12-16 00:45:45 +00001173 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 struct net_device *netdev = adapter->netdev;
1175 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 struct e1000_tx_desc *tx_desc, *eop_desc;
1177 struct e1000_buffer *buffer_info;
1178 unsigned int i, eop;
1179 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001181 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182
1183 i = tx_ring->next_to_clean;
1184 eop = tx_ring->buffer_info[i].next_to_watch;
1185 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1186
Alexander Duyck12d04a32009-03-25 22:05:03 +00001187 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1188 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001189 bool cleaned = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001190 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001191 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 tx_desc = E1000_TX_DESC(*tx_ring, i);
1193 buffer_info = &tx_ring->buffer_info[i];
1194 cleaned = (i == eop);
1195
1196 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001197 total_tx_packets += buffer_info->segs;
1198 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001199 if (buffer_info->skb) {
1200 bytes_compl += buffer_info->skb->len;
1201 pkts_compl++;
1202 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 }
1204
Bruce Allan55aa6982011-12-16 00:45:45 +00001205 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 tx_desc->upper.data = 0;
1207
1208 i++;
1209 if (i == tx_ring->count)
1210 i = 0;
1211 }
1212
Terry Loftindac87612010-04-09 10:29:49 +00001213 if (i == tx_ring->next_to_use)
1214 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001215 eop = tx_ring->buffer_info[i].next_to_watch;
1216 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 }
1218
1219 tx_ring->next_to_clean = i;
1220
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001221 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1222
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001224 if (count && netif_carrier_ok(netdev) &&
1225 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001226 /* Make sure that anybody stopping the queue after this
1227 * sees the new next_to_clean.
1228 */
1229 smp_mb();
1230
1231 if (netif_queue_stopped(netdev) &&
1232 !(test_bit(__E1000_DOWN, &adapter->state))) {
1233 netif_wake_queue(netdev);
1234 ++adapter->restart_queue;
1235 }
1236 }
1237
1238 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001239 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001240 * check with the clearing of time_stamp and movement of i
1241 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001242 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001243 if (tx_ring->buffer_info[i].time_stamp &&
1244 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001245 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001246 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001247 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001248 else
1249 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 }
1251 adapter->total_tx_bytes += total_tx_bytes;
1252 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001253 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254}
1255
1256/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001258 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259 *
1260 * the return value indicates whether actual cleaning was done, there
1261 * is no guarantee that everything was cleaned
1262 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001263static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1264 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265{
Bruce Allan55aa6982011-12-16 00:45:45 +00001266 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001267 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1269 struct net_device *netdev = adapter->netdev;
1270 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271 struct e1000_buffer *buffer_info, *next_buffer;
1272 struct e1000_ps_page *ps_page;
1273 struct sk_buff *skb;
1274 unsigned int i, j;
1275 u32 length, staterr;
1276 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001277 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1279
1280 i = rx_ring->next_to_clean;
1281 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1282 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1283 buffer_info = &rx_ring->buffer_info[i];
1284
1285 while (staterr & E1000_RXD_STAT_DD) {
1286 if (*work_done >= work_to_do)
1287 break;
1288 (*work_done)++;
1289 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001290 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001291
1292 /* in the packet split case this is header only */
1293 prefetch(skb->data - NET_IP_ALIGN);
1294
1295 i++;
1296 if (i == rx_ring->count)
1297 i = 0;
1298 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1299 prefetch(next_rxd);
1300
1301 next_buffer = &rx_ring->buffer_info[i];
1302
Rusty Russell3db1cd52011-12-19 13:56:45 +00001303 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001305 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001306 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 buffer_info->dma = 0;
1308
Bruce Allanaf667a22010-12-31 06:10:01 +00001309 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001310 if (!(staterr & E1000_RXD_STAT_EOP))
1311 adapter->flags2 |= FLAG2_IS_DISCARDING;
1312
1313 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001314 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001315 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001316 if (staterr & E1000_RXD_STAT_EOP)
1317 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001318 goto next_desc;
1319 }
1320
Ben Greearcf955e62012-02-11 15:39:51 +00001321 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1322 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 dev_kfree_skb_irq(skb);
1324 goto next_desc;
1325 }
1326
1327 length = le16_to_cpu(rx_desc->wb.middle.length0);
1328
1329 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001330 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 dev_kfree_skb_irq(skb);
1332 goto next_desc;
1333 }
1334
1335 /* Good Receive */
1336 skb_put(skb, length);
1337
1338 {
Bruce Allane921eb12012-11-28 09:28:37 +00001339 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001340 * it more efficient than reusing j
1341 */
1342 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001343
Bruce Allane921eb12012-11-28 09:28:37 +00001344 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001345 * packet throughput, so unsplit small packets and
1346 * save the alloc/put only valid in softirq (napi)
1347 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001348 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001349 if (l1 && (l1 <= copybreak) &&
1350 ((length + l1) <= adapter->rx_ps_bsize0)) {
1351 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001352
Bruce Allan0e15df42012-01-31 06:37:11 +00001353 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001354
Bruce Allane921eb12012-11-28 09:28:37 +00001355 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001356 * kmap_atomic, so we can't hold the mapping
1357 * very long
1358 */
1359 dma_sync_single_for_cpu(&pdev->dev,
1360 ps_page->dma,
1361 PAGE_SIZE,
1362 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001363 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001364 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001365 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001366 dma_sync_single_for_device(&pdev->dev,
1367 ps_page->dma,
1368 PAGE_SIZE,
1369 DMA_FROM_DEVICE);
1370
1371 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001372 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1373 if (!(netdev->features & NETIF_F_RXFCS))
1374 l1 -= 4;
1375 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001376
1377 skb_put(skb, l1);
1378 goto copydone;
Bruce Allane80bd1d2013-05-01 01:19:46 +00001379 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001380 }
1381
1382 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1383 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1384 if (!length)
1385 break;
1386
Auke Kok47f44e42007-10-25 13:57:44 -07001387 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001388 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1389 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390 ps_page->dma = 0;
1391 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1392 ps_page->page = NULL;
1393 skb->len += length;
1394 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001395 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001396 }
1397
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001398 /* strip the ethernet crc, problem is we're using pages now so
1399 * this whole operation can get a little cpu intensive
1400 */
Ben Greear01840392012-02-11 15:39:25 +00001401 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1402 if (!(netdev->features & NETIF_F_RXFCS))
1403 pskb_trim(skb, skb->len - 4);
1404 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001405
Auke Kokbc7f75f2007-09-17 12:30:59 -07001406copydone:
1407 total_rx_bytes += skb->len;
1408 total_rx_packets++;
1409
Bruce Allan2e1706f2012-06-30 20:02:42 +00001410 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001411
Bruce Allan70495a52012-01-11 01:26:50 +00001412 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1413
Auke Kokbc7f75f2007-09-17 12:30:59 -07001414 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001415 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 adapter->rx_hdr_split++;
1417
Bruce Allanb67e1912012-12-27 08:32:33 +00001418 e1000_receive_skb(adapter, netdev, skb, staterr,
1419 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001420
1421next_desc:
1422 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1423 buffer_info->skb = NULL;
1424
1425 /* return some buffers to hardware, one at a time is too slow */
1426 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001427 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001428 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001429 cleaned_count = 0;
1430 }
1431
1432 /* use prefetched values */
1433 rx_desc = next_rxd;
1434 buffer_info = next_buffer;
1435
1436 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1437 }
1438 rx_ring->next_to_clean = i;
1439
1440 cleaned_count = e1000_desc_unused(rx_ring);
1441 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001442 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001443
Auke Kokbc7f75f2007-09-17 12:30:59 -07001444 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001445 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446 return cleaned;
1447}
1448
1449/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001450 * e1000_consume_page - helper function
1451 **/
1452static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001453 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454{
1455 bi->page = NULL;
1456 skb->len += length;
1457 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001458 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001459}
1460
1461/**
1462 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1463 * @adapter: board private structure
1464 *
1465 * the return value indicates whether actual cleaning was done, there
1466 * is no guarantee that everything was cleaned
1467 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001468static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1469 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001470{
Bruce Allan55aa6982011-12-16 00:45:45 +00001471 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001472 struct net_device *netdev = adapter->netdev;
1473 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001474 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001475 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001476 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001477 unsigned int i;
1478 int cleaned_count = 0;
1479 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001480 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001481 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001482
1483 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001484 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1485 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001486 buffer_info = &rx_ring->buffer_info[i];
1487
Bruce Allan5f450212011-07-22 06:21:46 +00001488 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001489 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490
1491 if (*work_done >= work_to_do)
1492 break;
1493 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001494 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001495
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001496 skb = buffer_info->skb;
1497 buffer_info->skb = NULL;
1498
1499 ++i;
1500 if (i == rx_ring->count)
1501 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001502 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 prefetch(next_rxd);
1504
1505 next_buffer = &rx_ring->buffer_info[i];
1506
1507 cleaned = true;
1508 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001509 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1510 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001511 buffer_info->dma = 0;
1512
Bruce Allan5f450212011-07-22 06:21:46 +00001513 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001514
1515 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001516 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001517 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1518 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001519 /* recycle both page and skb */
1520 buffer_info->skb = skb;
1521 /* an error means any chain goes out the window too */
1522 if (rx_ring->rx_skb_top)
1523 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1524 rx_ring->rx_skb_top = NULL;
1525 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001527#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001528 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529 /* this descriptor is only the beginning (or middle) */
1530 if (!rxtop) {
1531 /* this is the beginning of a chain */
1532 rxtop = skb;
1533 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001534 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001535 } else {
1536 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001537 shinfo = skb_shinfo(rxtop);
1538 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1539 buffer_info->page, 0,
1540 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001541 /* re-use the skb, only consumed the page */
1542 buffer_info->skb = skb;
1543 }
1544 e1000_consume_page(buffer_info, rxtop, length);
1545 goto next_desc;
1546 } else {
1547 if (rxtop) {
1548 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001549 shinfo = skb_shinfo(rxtop);
1550 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1551 buffer_info->page, 0,
1552 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001553 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001554 * page
1555 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001556 buffer_info->skb = skb;
1557 skb = rxtop;
1558 rxtop = NULL;
1559 e1000_consume_page(buffer_info, skb, length);
1560 } else {
1561 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001562 * copybreak to save the put_page/alloc_page
1563 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001564 if (length <= copybreak &&
1565 skb_tailroom(skb) >= length) {
1566 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001567 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001568 memcpy(skb_tail_pointer(skb), vaddr,
1569 length);
Cong Wang46790262011-11-25 23:14:23 +08001570 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001571 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001572 * buffer_info->page
1573 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001574 skb_put(skb, length);
1575 } else {
1576 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001577 buffer_info->page, 0,
1578 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001579 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001580 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001581 }
1582 }
1583 }
1584
Bruce Allan2e1706f2012-06-30 20:02:42 +00001585 /* Receive Checksum Offload */
1586 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001587
Bruce Allan70495a52012-01-11 01:26:50 +00001588 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1589
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001590 /* probably a little skewed due to removing CRC */
1591 total_rx_bytes += skb->len;
1592 total_rx_packets++;
1593
1594 /* eth type trans needs skb->data to point to something */
1595 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001596 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001597 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001598 goto next_desc;
1599 }
1600
Bruce Allan5f450212011-07-22 06:21:46 +00001601 e1000_receive_skb(adapter, netdev, skb, staterr,
1602 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001603
1604next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001605 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001606
1607 /* return some buffers to hardware, one at a time is too slow */
1608 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001609 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001610 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001611 cleaned_count = 0;
1612 }
1613
1614 /* use prefetched values */
1615 rx_desc = next_rxd;
1616 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001617
1618 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001619 }
1620 rx_ring->next_to_clean = i;
1621
1622 cleaned_count = e1000_desc_unused(rx_ring);
1623 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001624 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001625
1626 adapter->total_rx_bytes += total_rx_bytes;
1627 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001628 return cleaned;
1629}
1630
1631/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001633 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001635static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636{
Bruce Allan55aa6982011-12-16 00:45:45 +00001637 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 struct e1000_buffer *buffer_info;
1639 struct e1000_ps_page *ps_page;
1640 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 unsigned int i, j;
1642
1643 /* Free all the Rx ring sk_buffs */
1644 for (i = 0; i < rx_ring->count; i++) {
1645 buffer_info = &rx_ring->buffer_info[i];
1646 if (buffer_info->dma) {
1647 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001648 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001650 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001651 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001652 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001653 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001655 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001657 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 buffer_info->dma = 0;
1659 }
1660
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001661 if (buffer_info->page) {
1662 put_page(buffer_info->page);
1663 buffer_info->page = NULL;
1664 }
1665
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 if (buffer_info->skb) {
1667 dev_kfree_skb(buffer_info->skb);
1668 buffer_info->skb = NULL;
1669 }
1670
1671 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001672 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001673 if (!ps_page->page)
1674 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001675 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1676 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677 ps_page->dma = 0;
1678 put_page(ps_page->page);
1679 ps_page->page = NULL;
1680 }
1681 }
1682
1683 /* there also may be some cached data from a chained receive */
1684 if (rx_ring->rx_skb_top) {
1685 dev_kfree_skb(rx_ring->rx_skb_top);
1686 rx_ring->rx_skb_top = NULL;
1687 }
1688
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 /* Zero out the descriptor ring */
1690 memset(rx_ring->desc, 0, rx_ring->size);
1691
1692 rx_ring->next_to_clean = 0;
1693 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001694 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695
Bruce Allanc5083cf2011-12-16 00:45:40 +00001696 writel(0, rx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00001697 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00001698 e1000e_update_rdt_wa(rx_ring, 0);
1699 else
1700 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701}
1702
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001703static void e1000e_downshift_workaround(struct work_struct *work)
1704{
1705 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001706 struct e1000_adapter,
1707 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001708
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001709 if (test_bit(__E1000_DOWN, &adapter->state))
1710 return;
1711
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001712 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1713}
1714
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715/**
1716 * e1000_intr_msi - Interrupt Handler
1717 * @irq: interrupt number
1718 * @data: pointer to a network interface device structure
1719 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001720static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721{
1722 struct net_device *netdev = data;
1723 struct e1000_adapter *adapter = netdev_priv(netdev);
1724 struct e1000_hw *hw = &adapter->hw;
1725 u32 icr = er32(ICR);
1726
Bruce Allane921eb12012-11-28 09:28:37 +00001727 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001728 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001729 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001730 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001731 * disconnect (LSC) before accessing any PHY registers
1732 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1734 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001735 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736
Bruce Allane921eb12012-11-28 09:28:37 +00001737 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001739 * adapter in watchdog
1740 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if (netif_carrier_ok(netdev) &&
1742 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1743 /* disable receives */
1744 u32 rctl = er32(RCTL);
1745 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001746 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001747 }
1748 /* guard against interrupt when we're going down */
1749 if (!test_bit(__E1000_DOWN, &adapter->state))
1750 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1751 }
1752
Bruce Allan94fb8482013-01-23 09:00:03 +00001753 /* Reset on uncorrectable ECC error */
1754 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1755 u32 pbeccsts = er32(PBECCSTS);
1756
1757 adapter->corr_errors +=
1758 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1759 adapter->uncorr_errors +=
1760 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1761 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1762
1763 /* Do the reset outside of interrupt context */
1764 schedule_work(&adapter->reset_task);
1765
1766 /* return immediately since reset is imminent */
1767 return IRQ_HANDLED;
1768 }
1769
Ben Hutchings288379f2009-01-19 16:43:59 -08001770 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 adapter->total_tx_bytes = 0;
1772 adapter->total_tx_packets = 0;
1773 adapter->total_rx_bytes = 0;
1774 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001775 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 }
1777
1778 return IRQ_HANDLED;
1779}
1780
1781/**
1782 * e1000_intr - Interrupt Handler
1783 * @irq: interrupt number
1784 * @data: pointer to a network interface device structure
1785 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001786static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787{
1788 struct net_device *netdev = data;
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1790 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001792
Bruce Allana68ea772009-11-20 23:23:16 +00001793 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Bruce Allane80bd1d2013-05-01 01:19:46 +00001794 return IRQ_NONE; /* Not our interrupt */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795
Bruce Allane921eb12012-11-28 09:28:37 +00001796 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001797 * not set, then the adapter didn't send an interrupt
1798 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799 if (!(icr & E1000_ICR_INT_ASSERTED))
1800 return IRQ_NONE;
1801
Bruce Allane921eb12012-11-28 09:28:37 +00001802 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001803 * interrupts are masked. No need for the
1804 * IMC write
1805 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806
dave graham573cca82009-02-10 12:52:05 +00001807 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001808 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001809 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001810 * disconnect (LSC) before accessing any PHY registers
1811 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1813 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001814 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815
Bruce Allane921eb12012-11-28 09:28:37 +00001816 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 * For packet buffer work-around on link down event;
1818 * disable receives here in the ISR and
1819 * reset adapter in watchdog
1820 */
1821 if (netif_carrier_ok(netdev) &&
1822 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1823 /* disable receives */
1824 rctl = er32(RCTL);
1825 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001826 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001827 }
1828 /* guard against interrupt when we're going down */
1829 if (!test_bit(__E1000_DOWN, &adapter->state))
1830 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1831 }
1832
Bruce Allan94fb8482013-01-23 09:00:03 +00001833 /* Reset on uncorrectable ECC error */
1834 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1835 u32 pbeccsts = er32(PBECCSTS);
1836
1837 adapter->corr_errors +=
1838 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1839 adapter->uncorr_errors +=
1840 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1841 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1842
1843 /* Do the reset outside of interrupt context */
1844 schedule_work(&adapter->reset_task);
1845
1846 /* return immediately since reset is imminent */
1847 return IRQ_HANDLED;
1848 }
1849
Ben Hutchings288379f2009-01-19 16:43:59 -08001850 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851 adapter->total_tx_bytes = 0;
1852 adapter->total_tx_packets = 0;
1853 adapter->total_rx_bytes = 0;
1854 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001855 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 }
1857
1858 return IRQ_HANDLED;
1859}
1860
Bruce Allan8bb62862013-01-16 08:46:49 +00001861static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001862{
1863 struct net_device *netdev = data;
1864 struct e1000_adapter *adapter = netdev_priv(netdev);
1865 struct e1000_hw *hw = &adapter->hw;
1866 u32 icr = er32(ICR);
1867
1868 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001869 if (!test_bit(__E1000_DOWN, &adapter->state))
1870 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001871 return IRQ_NONE;
1872 }
1873
1874 if (icr & adapter->eiac_mask)
1875 ew32(ICS, (icr & adapter->eiac_mask));
1876
1877 if (icr & E1000_ICR_OTHER) {
1878 if (!(icr & E1000_ICR_LSC))
1879 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001880 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001881 /* guard against interrupt when we're going down */
1882 if (!test_bit(__E1000_DOWN, &adapter->state))
1883 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1884 }
1885
1886no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001887 if (!test_bit(__E1000_DOWN, &adapter->state))
1888 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001889
1890 return IRQ_HANDLED;
1891}
1892
Bruce Allan8bb62862013-01-16 08:46:49 +00001893static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001894{
1895 struct net_device *netdev = data;
1896 struct e1000_adapter *adapter = netdev_priv(netdev);
1897 struct e1000_hw *hw = &adapter->hw;
1898 struct e1000_ring *tx_ring = adapter->tx_ring;
1899
Bruce Allan4662e822008-08-26 18:37:06 -07001900 adapter->total_tx_bytes = 0;
1901 adapter->total_tx_packets = 0;
1902
Bruce Allan55aa6982011-12-16 00:45:45 +00001903 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001904 /* Ring was not completely cleaned, so fire another interrupt */
1905 ew32(ICS, tx_ring->ims_val);
1906
1907 return IRQ_HANDLED;
1908}
1909
Bruce Allan8bb62862013-01-16 08:46:49 +00001910static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001911{
1912 struct net_device *netdev = data;
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001914 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001915
1916 /* Write the ITR value calculated at the end of the
1917 * previous interrupt.
1918 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001919 if (rx_ring->set_itr) {
1920 writel(1000000000 / (rx_ring->itr_val * 256),
1921 rx_ring->itr_register);
1922 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001923 }
1924
Ben Hutchings288379f2009-01-19 16:43:59 -08001925 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001926 adapter->total_rx_bytes = 0;
1927 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001928 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001929 }
1930 return IRQ_HANDLED;
1931}
1932
1933/**
1934 * e1000_configure_msix - Configure MSI-X hardware
1935 *
1936 * e1000_configure_msix sets up the hardware to properly
1937 * generate MSI-X interrupts.
1938 **/
1939static void e1000_configure_msix(struct e1000_adapter *adapter)
1940{
1941 struct e1000_hw *hw = &adapter->hw;
1942 struct e1000_ring *rx_ring = adapter->rx_ring;
1943 struct e1000_ring *tx_ring = adapter->tx_ring;
1944 int vector = 0;
1945 u32 ctrl_ext, ivar = 0;
1946
1947 adapter->eiac_mask = 0;
1948
1949 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1950 if (hw->mac.type == e1000_82574) {
1951 u32 rfctl = er32(RFCTL);
1952 rfctl |= E1000_RFCTL_ACK_DIS;
1953 ew32(RFCTL, rfctl);
1954 }
1955
Bruce Allan4662e822008-08-26 18:37:06 -07001956 /* Configure Rx vector */
1957 rx_ring->ims_val = E1000_IMS_RXQ0;
1958 adapter->eiac_mask |= rx_ring->ims_val;
1959 if (rx_ring->itr_val)
1960 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001961 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001962 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001963 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001964 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1965
1966 /* Configure Tx vector */
1967 tx_ring->ims_val = E1000_IMS_TXQ0;
1968 vector++;
1969 if (tx_ring->itr_val)
1970 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001971 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001972 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001973 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001974 adapter->eiac_mask |= tx_ring->ims_val;
1975 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1976
1977 /* set vector for Other Causes, e.g. link changes */
1978 vector++;
1979 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1980 if (rx_ring->itr_val)
1981 writel(1000000000 / (rx_ring->itr_val * 256),
1982 hw->hw_addr + E1000_EITR_82574(vector));
1983 else
1984 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1985
1986 /* Cause Tx interrupts on every write back */
1987 ivar |= (1 << 31);
1988
1989 ew32(IVAR, ivar);
1990
1991 /* enable MSI-X PBA support */
1992 ctrl_ext = er32(CTRL_EXT);
1993 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1994
1995 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07001996 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1997 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1998 ew32(CTRL_EXT, ctrl_ext);
1999 e1e_flush();
2000}
2001
2002void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2003{
2004 if (adapter->msix_entries) {
2005 pci_disable_msix(adapter->pdev);
2006 kfree(adapter->msix_entries);
2007 adapter->msix_entries = NULL;
2008 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2009 pci_disable_msi(adapter->pdev);
2010 adapter->flags &= ~FLAG_MSI_ENABLED;
2011 }
Bruce Allan4662e822008-08-26 18:37:06 -07002012}
2013
2014/**
2015 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2016 *
2017 * Attempt to configure interrupts using the best available
2018 * capabilities of the hardware and kernel.
2019 **/
2020void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2021{
2022 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002023 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002024
2025 switch (adapter->int_mode) {
2026 case E1000E_INT_MODE_MSIX:
2027 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002028 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2029 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002030 sizeof(struct
2031 msix_entry),
2032 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002033 if (adapter->msix_entries) {
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002034 struct e1000_adapter *a = adapter;
2035
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002036 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002037 adapter->msix_entries[i].entry = i;
2038
Alexander Gordeev0cc7c952014-02-18 11:11:41 +01002039 err = pci_enable_msix_range(a->pdev,
2040 a->msix_entries,
2041 a->num_vectors,
2042 a->num_vectors);
2043 if (err > 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002044 return;
2045 }
2046 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002047 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002048 e1000e_reset_interrupt_capability(adapter);
2049 }
2050 adapter->int_mode = E1000E_INT_MODE_MSI;
2051 /* Fall through */
2052 case E1000E_INT_MODE_MSI:
2053 if (!pci_enable_msi(adapter->pdev)) {
2054 adapter->flags |= FLAG_MSI_ENABLED;
2055 } else {
2056 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002057 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002058 }
2059 /* Fall through */
2060 case E1000E_INT_MODE_LEGACY:
2061 /* Don't do anything; this is the system default */
2062 break;
2063 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002064
2065 /* store the number of vectors being used */
2066 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002067}
2068
2069/**
2070 * e1000_request_msix - Initialize MSI-X interrupts
2071 *
2072 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2073 * kernel.
2074 **/
2075static int e1000_request_msix(struct e1000_adapter *adapter)
2076{
2077 struct net_device *netdev = adapter->netdev;
2078 int err = 0, vector = 0;
2079
2080 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002081 snprintf(adapter->rx_ring->name,
2082 sizeof(adapter->rx_ring->name) - 1,
2083 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002084 else
2085 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2086 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002087 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002088 netdev);
2089 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002090 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002091 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2092 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002093 adapter->rx_ring->itr_val = adapter->itr;
2094 vector++;
2095
2096 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002097 snprintf(adapter->tx_ring->name,
2098 sizeof(adapter->tx_ring->name) - 1,
2099 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002100 else
2101 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2102 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002103 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002104 netdev);
2105 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002106 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002107 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2108 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002109 adapter->tx_ring->itr_val = adapter->itr;
2110 vector++;
2111
2112 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002113 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002114 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002115 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002116
2117 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002118
Bruce Allan4662e822008-08-26 18:37:06 -07002119 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002120}
2121
Bruce Allanf8d59f72008-08-08 18:36:11 -07002122/**
2123 * e1000_request_irq - initialize interrupts
2124 *
2125 * Attempts to configure interrupts using the best available
2126 * capabilities of the hardware and kernel.
2127 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128static int e1000_request_irq(struct e1000_adapter *adapter)
2129{
2130 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002131 int err;
2132
Bruce Allan4662e822008-08-26 18:37:06 -07002133 if (adapter->msix_entries) {
2134 err = e1000_request_msix(adapter);
2135 if (!err)
2136 return err;
2137 /* fall back to MSI */
2138 e1000e_reset_interrupt_capability(adapter);
2139 adapter->int_mode = E1000E_INT_MODE_MSI;
2140 e1000e_set_interrupt_capability(adapter);
2141 }
2142 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002143 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002144 netdev->name, netdev);
2145 if (!err)
2146 return err;
2147
2148 /* fall back to legacy interrupt */
2149 e1000e_reset_interrupt_capability(adapter);
2150 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002151 }
2152
Joe Perchesa0607fd2009-11-18 23:29:17 -08002153 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002154 netdev->name, netdev);
2155 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002156 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157
2158 return err;
2159}
2160
2161static void e1000_free_irq(struct e1000_adapter *adapter)
2162{
2163 struct net_device *netdev = adapter->netdev;
2164
Bruce Allan4662e822008-08-26 18:37:06 -07002165 if (adapter->msix_entries) {
2166 int vector = 0;
2167
2168 free_irq(adapter->msix_entries[vector].vector, netdev);
2169 vector++;
2170
2171 free_irq(adapter->msix_entries[vector].vector, netdev);
2172 vector++;
2173
2174 /* Other Causes interrupt vector */
2175 free_irq(adapter->msix_entries[vector].vector, netdev);
2176 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002177 }
Bruce Allan4662e822008-08-26 18:37:06 -07002178
2179 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180}
2181
2182/**
2183 * e1000_irq_disable - Mask off interrupt generation on the NIC
2184 **/
2185static void e1000_irq_disable(struct e1000_adapter *adapter)
2186{
2187 struct e1000_hw *hw = &adapter->hw;
2188
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002190 if (adapter->msix_entries)
2191 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002192 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002193
2194 if (adapter->msix_entries) {
2195 int i;
2196 for (i = 0; i < adapter->num_vectors; i++)
2197 synchronize_irq(adapter->msix_entries[i].vector);
2198 } else {
2199 synchronize_irq(adapter->pdev->irq);
2200 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002201}
2202
2203/**
2204 * e1000_irq_enable - Enable default interrupt generation settings
2205 **/
2206static void e1000_irq_enable(struct e1000_adapter *adapter)
2207{
2208 struct e1000_hw *hw = &adapter->hw;
2209
Bruce Allan4662e822008-08-26 18:37:06 -07002210 if (adapter->msix_entries) {
2211 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2212 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002213 } else if (hw->mac.type == e1000_pch_lpt) {
2214 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002215 } else {
2216 ew32(IMS, IMS_ENABLE_MASK);
2217 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002218 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219}
2220
2221/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002222 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223 * @adapter: address of board private structure
2224 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002225 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 * For ASF and Pass Through versions of f/w this means that
2227 * the driver is loaded. For AMT version (only with 82573)
2228 * of the f/w this means that the network i/f is open.
2229 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002230void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231{
2232 struct e1000_hw *hw = &adapter->hw;
2233 u32 ctrl_ext;
2234 u32 swsm;
2235
2236 /* Let firmware know the driver has taken over */
2237 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2238 swsm = er32(SWSM);
2239 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2240 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2241 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002242 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243 }
2244}
2245
2246/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002247 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248 * @adapter: address of board private structure
2249 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002250 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 * For ASF and Pass Through versions of f/w this means that the
2252 * driver is no longer loaded. For AMT version (only with 82573) i
2253 * of the f/w this means that the network i/f is closed.
2254 *
2255 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002256void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002257{
2258 struct e1000_hw *hw = &adapter->hw;
2259 u32 ctrl_ext;
2260 u32 swsm;
2261
2262 /* Let firmware taken over control of h/w */
2263 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2264 swsm = er32(SWSM);
2265 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2266 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2267 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002268 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 }
2270}
2271
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002273 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 **/
2275static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2276 struct e1000_ring *ring)
2277{
2278 struct pci_dev *pdev = adapter->pdev;
2279
2280 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2281 GFP_KERNEL);
2282 if (!ring->desc)
2283 return -ENOMEM;
2284
2285 return 0;
2286}
2287
2288/**
2289 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002290 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291 *
2292 * Return 0 on success, negative on failure
2293 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002294int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002295{
Bruce Allan55aa6982011-12-16 00:45:45 +00002296 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 int err = -ENOMEM, size;
2298
2299 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002300 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002301 if (!tx_ring->buffer_info)
2302 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303
2304 /* round up to nearest 4K */
2305 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2306 tx_ring->size = ALIGN(tx_ring->size, 4096);
2307
2308 err = e1000_alloc_ring_dma(adapter, tx_ring);
2309 if (err)
2310 goto err;
2311
2312 tx_ring->next_to_use = 0;
2313 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314
2315 return 0;
2316err:
2317 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002318 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 return err;
2320}
2321
2322/**
2323 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002324 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 *
2326 * Returns 0 on success, negative on failure
2327 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002328int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329{
Bruce Allan55aa6982011-12-16 00:45:45 +00002330 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002331 struct e1000_buffer *buffer_info;
2332 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333
2334 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002335 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 if (!rx_ring->buffer_info)
2337 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338
Auke Kok47f44e42007-10-25 13:57:44 -07002339 for (i = 0; i < rx_ring->count; i++) {
2340 buffer_info = &rx_ring->buffer_info[i];
2341 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2342 sizeof(struct e1000_ps_page),
2343 GFP_KERNEL);
2344 if (!buffer_info->ps_pages)
2345 goto err_pages;
2346 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347
2348 desc_len = sizeof(union e1000_rx_desc_packet_split);
2349
2350 /* Round up to nearest 4K */
2351 rx_ring->size = rx_ring->count * desc_len;
2352 rx_ring->size = ALIGN(rx_ring->size, 4096);
2353
2354 err = e1000_alloc_ring_dma(adapter, rx_ring);
2355 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002356 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357
2358 rx_ring->next_to_clean = 0;
2359 rx_ring->next_to_use = 0;
2360 rx_ring->rx_skb_top = NULL;
2361
2362 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002363
2364err_pages:
2365 for (i = 0; i < rx_ring->count; i++) {
2366 buffer_info = &rx_ring->buffer_info[i];
2367 kfree(buffer_info->ps_pages);
2368 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369err:
2370 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002371 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 return err;
2373}
2374
2375/**
2376 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002377 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002379static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380{
Bruce Allan55aa6982011-12-16 00:45:45 +00002381 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 struct e1000_buffer *buffer_info;
2383 unsigned long size;
2384 unsigned int i;
2385
2386 for (i = 0; i < tx_ring->count; i++) {
2387 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002388 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 }
2390
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002391 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 size = sizeof(struct e1000_buffer) * tx_ring->count;
2393 memset(tx_ring->buffer_info, 0, size);
2394
2395 memset(tx_ring->desc, 0, tx_ring->size);
2396
2397 tx_ring->next_to_use = 0;
2398 tx_ring->next_to_clean = 0;
2399
Bruce Allanc5083cf2011-12-16 00:45:40 +00002400 writel(0, tx_ring->head);
David Ertmanb485dba2014-01-22 00:21:41 +00002401 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allanbdc125f2012-03-20 03:47:52 +00002402 e1000e_update_tdt_wa(tx_ring, 0);
2403 else
2404 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405}
2406
2407/**
2408 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002409 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 *
2411 * Free all transmit software resources
2412 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002413void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414{
Bruce Allan55aa6982011-12-16 00:45:45 +00002415 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417
Bruce Allan55aa6982011-12-16 00:45:45 +00002418 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419
2420 vfree(tx_ring->buffer_info);
2421 tx_ring->buffer_info = NULL;
2422
2423 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2424 tx_ring->dma);
2425 tx_ring->desc = NULL;
2426}
2427
2428/**
2429 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002430 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 *
2432 * Free all receive software resources
2433 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002434void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435{
Bruce Allan55aa6982011-12-16 00:45:45 +00002436 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002438 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439
Bruce Allan55aa6982011-12-16 00:45:45 +00002440 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002442 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002443 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002444
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445 vfree(rx_ring->buffer_info);
2446 rx_ring->buffer_info = NULL;
2447
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2449 rx_ring->dma);
2450 rx_ring->desc = NULL;
2451}
2452
2453/**
2454 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002455 * @adapter: pointer to adapter
2456 * @itr_setting: current adapter->itr
2457 * @packets: the number of packets during this measurement interval
2458 * @bytes: the number of bytes during this measurement interval
2459 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 * Stores a new ITR value based on packets and byte
2461 * counts during the last interrupt. The advantage of per interrupt
2462 * computation is faster updates and more accurate ITR for the current
2463 * traffic pattern. Constants in this function were computed
2464 * based on theoretical maximum wire speed and thresholds were set based
2465 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002466 * while increasing bulk throughput. This functionality is controlled
2467 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002469static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470{
2471 unsigned int retval = itr_setting;
2472
2473 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002474 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475
2476 switch (itr_setting) {
2477 case lowest_latency:
2478 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002479 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002480 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002481 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002482 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002484 case low_latency: /* 50 usec aka 20000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 if (bytes > 10000) {
2486 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002487 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002489 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002491 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002493 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002494 retval = bulk_latency;
2495 } else if (packets <= 2 && bytes < 512) {
2496 retval = lowest_latency;
2497 }
2498 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00002499 case bulk_latency: /* 250 usec aka 4000 ints/s */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002501 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 } else if (bytes < 6000) {
2504 retval = low_latency;
2505 }
2506 break;
2507 }
2508
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 return retval;
2510}
2511
2512static void e1000_set_itr(struct e1000_adapter *adapter)
2513{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 u16 current_itr;
2515 u32 new_itr = adapter->itr;
2516
2517 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2518 if (adapter->link_speed != SPEED_1000) {
2519 current_itr = 0;
2520 new_itr = 4000;
2521 goto set_itr_now;
2522 }
2523
Bruce Allan828bac82010-09-29 21:39:37 +00002524 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2525 new_itr = 0;
2526 goto set_itr_now;
2527 }
2528
Bruce Allan8bb62862013-01-16 08:46:49 +00002529 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2530 adapter->total_tx_packets,
2531 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2533 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2534 adapter->tx_itr = low_latency;
2535
Bruce Allan8bb62862013-01-16 08:46:49 +00002536 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2537 adapter->total_rx_packets,
2538 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2540 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2541 adapter->rx_itr = low_latency;
2542
2543 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2544
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002546 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 case lowest_latency:
2548 new_itr = 70000;
2549 break;
2550 case low_latency:
Bruce Allane80bd1d2013-05-01 01:19:46 +00002551 new_itr = 20000; /* aka hwitr = ~200 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552 break;
2553 case bulk_latency:
2554 new_itr = 4000;
2555 break;
2556 default:
2557 break;
2558 }
2559
2560set_itr_now:
2561 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002562 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002564 * increasing
2565 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002567 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002569 adapter->rx_ring->itr_val = new_itr;
2570 if (adapter->msix_entries)
2571 adapter->rx_ring->set_itr = 1;
2572 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002573 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 }
2575}
2576
2577/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002578 * e1000e_write_itr - write the ITR value to the appropriate registers
2579 * @adapter: address of board private structure
2580 * @itr: new ITR value to program
2581 *
2582 * e1000e_write_itr determines if the adapter is in MSI-X mode
2583 * and, if so, writes the EITR registers with the ITR value.
2584 * Otherwise, it writes the ITR value into the ITR register.
2585 **/
2586void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2587{
2588 struct e1000_hw *hw = &adapter->hw;
2589 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2590
2591 if (adapter->msix_entries) {
2592 int vector;
2593
2594 for (vector = 0; vector < adapter->num_vectors; vector++)
2595 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2596 } else {
2597 ew32(ITR, new_itr);
2598 }
2599}
2600
2601/**
Bruce Allan4662e822008-08-26 18:37:06 -07002602 * e1000_alloc_queues - Allocate memory for all rings
2603 * @adapter: board private structure to initialize
2604 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002605static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002606{
Bruce Allan55aa6982011-12-16 00:45:45 +00002607 int size = sizeof(struct e1000_ring);
2608
2609 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002610 if (!adapter->tx_ring)
2611 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002612 adapter->tx_ring->count = adapter->tx_ring_count;
2613 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002614
Bruce Allan55aa6982011-12-16 00:45:45 +00002615 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002616 if (!adapter->rx_ring)
2617 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002618 adapter->rx_ring->count = adapter->rx_ring_count;
2619 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002620
2621 return 0;
2622err:
2623 e_err("Unable to allocate memory for queues\n");
2624 kfree(adapter->rx_ring);
2625 kfree(adapter->tx_ring);
2626 return -ENOMEM;
2627}
2628
2629/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002630 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002631 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002632 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002633 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002634static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002635{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002636 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2637 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002638 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002639 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002640 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641
Wang Chen4cf16532008-11-12 23:38:14 -08002642 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002643
Bruce Allanc58c8a72012-03-20 03:48:19 +00002644 if (!adapter->msix_entries ||
2645 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2646 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002647
Bruce Allanc58c8a72012-03-20 03:48:19 +00002648 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649
Alexander Duyck12d04a32009-03-25 22:05:03 +00002650 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002651 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002652
Bruce Allanc58c8a72012-03-20 03:48:19 +00002653 /* If weight not fully consumed, exit the polling mode */
2654 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 if (adapter->itr_setting & 3)
2656 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002657 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002658 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2659 if (adapter->msix_entries)
2660 ew32(IMS, adapter->rx_ring->ims_val);
2661 else
2662 e1000_irq_enable(adapter);
2663 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664 }
2665
2666 return work_done;
2667}
2668
Patrick McHardy80d5c362013-04-19 02:04:28 +00002669static int e1000_vlan_rx_add_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002670 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671{
2672 struct e1000_adapter *adapter = netdev_priv(netdev);
2673 struct e1000_hw *hw = &adapter->hw;
2674 u32 vfta, index;
2675
2676 /* don't update vlan cookie if already programmed */
2677 if ((adapter->hw.mng_cookie.status &
2678 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2679 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002680 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002681
Auke Kokbc7f75f2007-09-17 12:30:59 -07002682 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002683 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2684 index = (vid >> 5) & 0x7F;
2685 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2686 vfta |= (1 << (vid & 0x1F));
2687 hw->mac.ops.write_vfta(hw, index, vfta);
2688 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002689
2690 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002691
2692 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002693}
2694
Patrick McHardy80d5c362013-04-19 02:04:28 +00002695static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
Bruce Allan603cdca2013-05-01 03:48:11 +00002696 __always_unused __be16 proto, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697{
2698 struct e1000_adapter *adapter = netdev_priv(netdev);
2699 struct e1000_hw *hw = &adapter->hw;
2700 u32 vfta, index;
2701
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 if ((adapter->hw.mng_cookie.status &
2703 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2704 (vid == adapter->mng_vlan_id)) {
2705 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002706 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002707 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708 }
2709
2710 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002711 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2712 index = (vid >> 5) & 0x7F;
2713 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2714 vfta &= ~(1 << (vid & 0x1F));
2715 hw->mac.ops.write_vfta(hw, index, vfta);
2716 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002717
2718 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002719
2720 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002721}
2722
2723/**
2724 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2725 * @adapter: board private structure to initialize
2726 **/
2727static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2728{
2729 struct net_device *netdev = adapter->netdev;
2730 struct e1000_hw *hw = &adapter->hw;
2731 u32 rctl;
2732
2733 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2734 /* disable VLAN receive filtering */
2735 rctl = er32(RCTL);
2736 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2737 ew32(RCTL, rctl);
2738
2739 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002740 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
2741 adapter->mng_vlan_id);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002742 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2743 }
2744 }
2745}
2746
2747/**
2748 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2749 * @adapter: board private structure to initialize
2750 **/
2751static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2752{
2753 struct e1000_hw *hw = &adapter->hw;
2754 u32 rctl;
2755
2756 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2757 /* enable VLAN receive filtering */
2758 rctl = er32(RCTL);
2759 rctl |= E1000_RCTL_VFE;
2760 rctl &= ~E1000_RCTL_CFIEN;
2761 ew32(RCTL, rctl);
2762 }
2763}
2764
2765/**
2766 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2767 * @adapter: board private structure to initialize
2768 **/
2769static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2770{
2771 struct e1000_hw *hw = &adapter->hw;
2772 u32 ctrl;
2773
2774 /* disable VLAN tag insert/strip */
2775 ctrl = er32(CTRL);
2776 ctrl &= ~E1000_CTRL_VME;
2777 ew32(CTRL, ctrl);
2778}
2779
2780/**
2781 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2782 * @adapter: board private structure to initialize
2783 **/
2784static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2785{
2786 struct e1000_hw *hw = &adapter->hw;
2787 u32 ctrl;
2788
2789 /* enable VLAN tag insert/strip */
2790 ctrl = er32(CTRL);
2791 ctrl |= E1000_CTRL_VME;
2792 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793}
2794
2795static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2796{
2797 struct net_device *netdev = adapter->netdev;
2798 u16 vid = adapter->hw.mng_cookie.vlan_id;
2799 u16 old_vid = adapter->mng_vlan_id;
2800
Bruce Allane5fe2542013-02-20 04:06:27 +00002801 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Patrick McHardy80d5c362013-04-19 02:04:28 +00002802 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803 adapter->mng_vlan_id = vid;
2804 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002806 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
Patrick McHardy80d5c362013-04-19 02:04:28 +00002807 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002808}
2809
2810static void e1000_restore_vlan(struct e1000_adapter *adapter)
2811{
2812 u16 vid;
2813
Patrick McHardy80d5c362013-04-19 02:04:28 +00002814 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002816 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00002817 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818}
2819
Bruce Allancd791612010-05-10 14:59:51 +00002820static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821{
2822 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002823 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824
2825 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2826 return;
2827
2828 manc = er32(MANC);
2829
Bruce Allane921eb12012-11-28 09:28:37 +00002830 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002832 * the packets will be handled on SMBUS
2833 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834 manc |= E1000_MANC_EN_MNG2HOST;
2835 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002836
2837 switch (hw->mac.type) {
2838 default:
2839 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2840 break;
2841 case e1000_82574:
2842 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002843 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002844 * if so, enable it.
2845 */
2846 for (i = 0, j = 0; i < 8; i++) {
2847 mdef = er32(MDEF(i));
2848
2849 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002850 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002851 continue;
2852
2853 /* Enable this decision filter in MANC2H */
2854 if (mdef)
2855 manc2h |= (1 << i);
2856
2857 j |= mdef;
2858 }
2859
2860 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2861 break;
2862
2863 /* Create new decision filter in an empty filter */
2864 for (i = 0, j = 0; i < 8; i++)
2865 if (er32(MDEF(i)) == 0) {
2866 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2867 E1000_MDEF_PORT_664));
2868 manc2h |= (1 << 1);
2869 j++;
2870 break;
2871 }
2872
2873 if (!j)
2874 e_warn("Unable to create IPMI pass-through filter\n");
2875 break;
2876 }
2877
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878 ew32(MANC2H, manc2h);
2879 ew32(MANC, manc);
2880}
2881
2882/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002883 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002884 * @adapter: board private structure
2885 *
2886 * Configure the Tx unit of the MAC after a reset.
2887 **/
2888static void e1000_configure_tx(struct e1000_adapter *adapter)
2889{
2890 struct e1000_hw *hw = &adapter->hw;
2891 struct e1000_ring *tx_ring = adapter->tx_ring;
2892 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002893 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894
2895 /* Setup the HW Tx Head and Tail descriptor pointers */
2896 tdba = tx_ring->dma;
2897 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002898 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2899 ew32(TDBAH(0), (tdba >> 32));
2900 ew32(TDLEN(0), tdlen);
2901 ew32(TDH(0), 0);
2902 ew32(TDT(0), 0);
2903 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2904 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 /* Set the Tx Interrupt Delay register */
2907 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002908 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909 ew32(TADV, adapter->tx_abs_int_delay);
2910
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002911 if (adapter->flags2 & FLAG2_DMA_BURST) {
2912 u32 txdctl = er32(TXDCTL(0));
2913 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2914 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002915 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002916 * hardware to use the bus more efficiently in bursts, depends
2917 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002918 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002919 * hthresh = 1 ==> prefetch when one or more available
2920 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2921 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002922 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002923 */
2924 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2925 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002926 }
Bruce Allan56032be2011-12-16 00:46:01 +00002927 /* erratum work around: set txdctl the same for both queues */
2928 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002929
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002931 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002932 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002933 * gigabit link later
2934 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935#define SPEED_MODE_BIT (1 << 21)
2936 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002937 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 }
2939
2940 /* errata: program both queues to unweighted RR */
2941 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002942 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002944 ew32(TARC(0), tarc);
2945 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002947 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 }
2949
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 /* Setup Transmit Descriptor Settings for eop descriptor */
2951 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2952
2953 /* only set IDE if we are delaying interrupts using the timers */
2954 if (adapter->tx_int_delay)
2955 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2956
2957 /* enable Report Status bit */
2958 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2959
Bruce Allan57cde762012-02-22 09:02:58 +00002960 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961}
2962
2963/**
2964 * e1000_setup_rctl - configure the receive control registers
2965 * @adapter: Board private structure
2966 **/
2967#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2968 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2969static void e1000_setup_rctl(struct e1000_adapter *adapter)
2970{
2971 struct e1000_hw *hw = &adapter->hw;
2972 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002973 u32 pages = 0;
2974
Bruce Allan2fbe4522012-04-19 03:21:47 +00002975 /* Workaround Si errata on PCHx - configure jumbo frame flow */
Bruce Allanda1e2042013-06-21 09:07:02 +00002976 if ((hw->mac.type >= e1000_pch2lan) &&
2977 (adapter->netdev->mtu > ETH_DATA_LEN) &&
2978 e1000_lv_jumbo_workaround_ich8lan(hw, true))
2979 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002980
Auke Kokbc7f75f2007-09-17 12:30:59 -07002981 /* Program MC offset vector base */
2982 rctl = er32(RCTL);
2983 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2984 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002985 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2986 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987
2988 /* Do not Store bad packets */
2989 rctl &= ~E1000_RCTL_SBP;
2990
2991 /* Enable Long Packet receive */
2992 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2993 rctl &= ~E1000_RCTL_LPE;
2994 else
2995 rctl |= E1000_RCTL_LPE;
2996
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00002997 /* Some systems expect that the CRC is included in SMBUS traffic. The
2998 * hardware strips the CRC before sending to both SMBUS (BMC) and to
2999 * host memory when this is enabled
3000 */
3001 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3002 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003003
Bruce Allana4f58f52009-06-02 11:29:18 +00003004 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3005 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3006 u16 phy_data;
3007
3008 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3009 phy_data &= 0xfff8;
3010 phy_data |= (1 << 2);
3011 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3012
3013 e1e_rphy(hw, 22, &phy_data);
3014 phy_data &= 0x0fff;
3015 phy_data |= (1 << 14);
3016 e1e_wphy(hw, 0x10, 0x2823);
3017 e1e_wphy(hw, 0x11, 0x0003);
3018 e1e_wphy(hw, 22, phy_data);
3019 }
3020
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021 /* Setup buffer sizes */
3022 rctl &= ~E1000_RCTL_SZ_4096;
3023 rctl |= E1000_RCTL_BSEX;
3024 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025 case 2048:
3026 default:
3027 rctl |= E1000_RCTL_SZ_2048;
3028 rctl &= ~E1000_RCTL_BSEX;
3029 break;
3030 case 4096:
3031 rctl |= E1000_RCTL_SZ_4096;
3032 break;
3033 case 8192:
3034 rctl |= E1000_RCTL_SZ_8192;
3035 break;
3036 case 16384:
3037 rctl |= E1000_RCTL_SZ_16384;
3038 break;
3039 }
3040
Bruce Allan5f450212011-07-22 06:21:46 +00003041 /* Enable Extended Status in all Receive Descriptors */
3042 rfctl = er32(RFCTL);
3043 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003044 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003045
Bruce Allane921eb12012-11-28 09:28:37 +00003046 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 * header is placed in skb->data and the packet data is
3048 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3049 * In the case of a non-split, skb->data is linearly filled,
3050 * followed by the page buffers. Therefore, skb->data is
3051 * sized to hold the largest protocol header.
3052 *
3053 * allocations using alloc_page take too long for regular MTU
3054 * so only enable packet split for jumbo frames
3055 *
3056 * Using pages when the page size is greater than 16k wastes
3057 * a lot of memory, since we allocate 3 pages at all times
3058 * per packet.
3059 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003061 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003062 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003063 else
3064 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065
3066 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003067 u32 psrctl = 0;
3068
Auke Kok140a7482007-10-25 13:57:58 -07003069 /* Enable Packet split descriptors */
3070 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003071
Bruce Allane5fe2542013-02-20 04:06:27 +00003072 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003073
3074 switch (adapter->rx_ps_pages) {
3075 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003076 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3077 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003079 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3080 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003082 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 break;
3084 }
3085
3086 ew32(PSRCTL, psrctl);
3087 }
3088
Ben Greearcf955e62012-02-11 15:39:51 +00003089 /* This is useful for sniffing bad packets. */
3090 if (adapter->netdev->features & NETIF_F_RXALL) {
3091 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003092 * in e1000e_set_rx_mode
3093 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003094 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3095 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3096 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
Ben Greearcf955e62012-02-11 15:39:51 +00003097
Bruce Allane80bd1d2013-05-01 01:19:46 +00003098 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3099 E1000_RCTL_DPF | /* Allow filtered pause */
3100 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
Ben Greearcf955e62012-02-11 15:39:51 +00003101 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3102 * and that breaks VLANs.
3103 */
3104 }
3105
Auke Kokbc7f75f2007-09-17 12:30:59 -07003106 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003107 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003108 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109}
3110
3111/**
3112 * e1000_configure_rx - Configure Receive Unit after Reset
3113 * @adapter: board private structure
3114 *
3115 * Configure the Rx unit of the MAC after a reset.
3116 **/
3117static void e1000_configure_rx(struct e1000_adapter *adapter)
3118{
3119 struct e1000_hw *hw = &adapter->hw;
3120 struct e1000_ring *rx_ring = adapter->rx_ring;
3121 u64 rdba;
3122 u32 rdlen, rctl, rxcsum, ctrl_ext;
3123
3124 if (adapter->rx_ps_pages) {
3125 /* this is a 32 byte descriptor */
3126 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003127 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 adapter->clean_rx = e1000_clean_rx_irq_ps;
3129 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003130 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003131 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003132 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3133 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003134 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003135 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003136 adapter->clean_rx = e1000_clean_rx_irq;
3137 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3138 }
3139
3140 /* disable receives while setting up the descriptors */
3141 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003142 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3143 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003145 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003147 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003148 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003149 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003150 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003151 * granularity = 01
3152 * wthresh = 04,
3153 * hthresh = 04,
3154 * pthresh = 0x20
3155 */
3156 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3157 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3158
Bruce Allane921eb12012-11-28 09:28:37 +00003159 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003160 * the value was not set by the user via module options
3161 */
3162 if (adapter->rx_int_delay == DEFAULT_RDTR)
3163 adapter->rx_int_delay = BURST_RDTR;
3164 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3165 adapter->rx_abs_int_delay = BURST_RADV;
3166 }
3167
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 /* set the Receive Delay Timer Register */
3169 ew32(RDTR, adapter->rx_int_delay);
3170
3171 /* irq moderation */
3172 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003173 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003174 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003175
3176 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003177 /* Auto-Mask interrupts upon ICR access */
3178 ctrl_ext |= E1000_CTRL_EXT_IAME;
3179 ew32(IAM, 0xffffffff);
3180 ew32(CTRL_EXT, ctrl_ext);
3181 e1e_flush();
3182
Bruce Allane921eb12012-11-28 09:28:37 +00003183 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003184 * the Base and Length of the Rx Descriptor Ring
3185 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003186 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003187 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3188 ew32(RDBAH(0), (rdba >> 32));
3189 ew32(RDLEN(0), rdlen);
3190 ew32(RDH(0), 0);
3191 ew32(RDT(0), 0);
3192 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3193 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003194
3195 /* Enable Receive Checksum Offload for TCP and UDP */
3196 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003197 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003199 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003200 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 ew32(RXCSUM, rxcsum);
3202
Bruce Allan3e35d992013-01-12 07:25:22 +00003203 /* With jumbo frames, excessive C-state transition latencies result
3204 * in dropped transactions.
3205 */
3206 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3207 u32 lat =
3208 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3209 adapter->max_frame_size) * 8 / 1000;
3210
3211 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003212 u32 rxdctl = er32(RXDCTL(0));
3213 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003214 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003215
3216 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3217 } else {
3218 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3219 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003220 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221
3222 /* Enable Receives */
3223 ew32(RCTL, rctl);
3224}
3225
3226/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003227 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 * @netdev: network interface device structure
3229 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003230 * Writes multicast address list to the MTA hash table.
3231 * Returns: -ENOMEM on failure
3232 * 0 on no addresses written
3233 * X on writing X addresses to MTA
3234 */
3235static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236{
3237 struct e1000_adapter *adapter = netdev_priv(netdev);
3238 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003239 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003240 u8 *mta_list;
3241 int i;
3242
3243 if (netdev_mc_empty(netdev)) {
3244 /* nothing to program, so clear mc list */
3245 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3246 return 0;
3247 }
3248
3249 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3250 if (!mta_list)
3251 return -ENOMEM;
3252
3253 /* update_mc_addr_list expects a packed array of only addresses. */
3254 i = 0;
3255 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003256 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003257
3258 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3259 kfree(mta_list);
3260
3261 return netdev_mc_count(netdev);
3262}
3263
3264/**
3265 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3266 * @netdev: network interface device structure
3267 *
3268 * Writes unicast address list to the RAR table.
3269 * Returns: -ENOMEM on failure/insufficient address space
3270 * 0 on no addresses written
3271 * X on writing X addresses to the RAR table
3272 **/
3273static int e1000e_write_uc_addr_list(struct net_device *netdev)
3274{
3275 struct e1000_adapter *adapter = netdev_priv(netdev);
3276 struct e1000_hw *hw = &adapter->hw;
3277 unsigned int rar_entries = hw->mac.rar_entry_count;
3278 int count = 0;
3279
3280 /* save a rar entry for our hardware address */
3281 rar_entries--;
3282
3283 /* save a rar entry for the LAA workaround */
3284 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3285 rar_entries--;
3286
3287 /* return ENOMEM indicating insufficient memory for addresses */
3288 if (netdev_uc_count(netdev) > rar_entries)
3289 return -ENOMEM;
3290
3291 if (!netdev_uc_empty(netdev) && rar_entries) {
3292 struct netdev_hw_addr *ha;
3293
Bruce Allane921eb12012-11-28 09:28:37 +00003294 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003295 * combining
3296 */
3297 netdev_for_each_uc_addr(ha, netdev) {
3298 if (!rar_entries)
3299 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003300 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003301 count++;
3302 }
3303 }
3304
3305 /* zero out the remaining RAR entries not used above */
3306 for (; rar_entries > 0; rar_entries--) {
3307 ew32(RAH(rar_entries), 0);
3308 ew32(RAL(rar_entries), 0);
3309 }
3310 e1e_flush();
3311
3312 return count;
3313}
3314
3315/**
3316 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3317 * @netdev: network interface device structure
3318 *
3319 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3320 * address list or the network interface flags are updated. This routine is
3321 * responsible for configuring the hardware for proper unicast, multicast,
3322 * promiscuous mode, and all-multi behavior.
3323 **/
3324static void e1000e_set_rx_mode(struct net_device *netdev)
3325{
3326 struct e1000_adapter *adapter = netdev_priv(netdev);
3327 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003328 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329
3330 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331 rctl = er32(RCTL);
3332
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003333 /* clear the affected bits */
3334 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3335
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336 if (netdev->flags & IFF_PROMISC) {
3337 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003338 /* Do not hardware filter VLANs in promisc mode */
3339 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003341 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003342
Patrick McHardy746b9f02008-07-16 20:15:45 -07003343 if (netdev->flags & IFF_ALLMULTI) {
3344 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003345 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003346 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003347 * then we should just turn on promiscuous mode so
3348 * that we can at least receive multicast traffic
3349 */
3350 count = e1000e_write_mc_addr_list(netdev);
3351 if (count < 0)
3352 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003353 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003354 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003355 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003356 * sufficient space to store all the addresses then enable
3357 * unicast promiscuous mode
3358 */
3359 count = e1000e_write_uc_addr_list(netdev);
3360 if (count < 0)
3361 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003362 }
3363
3364 ew32(RCTL, rctl);
3365
Patrick McHardyf6469682013-04-19 02:04:27 +00003366 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003367 e1000e_vlan_strip_enable(adapter);
3368 else
3369 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003370}
3371
Bruce Allan70495a52012-01-11 01:26:50 +00003372static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3373{
3374 struct e1000_hw *hw = &adapter->hw;
3375 u32 mrqc, rxcsum;
3376 int i;
3377 static const u32 rsskey[10] = {
3378 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3379 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3380 };
3381
3382 /* Fill out hash function seed */
3383 for (i = 0; i < 10; i++)
3384 ew32(RSSRK(i), rsskey[i]);
3385
3386 /* Direct all traffic to queue 0 */
3387 for (i = 0; i < 32; i++)
3388 ew32(RETA(i), 0);
3389
Bruce Allane921eb12012-11-28 09:28:37 +00003390 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003391 * descriptor on writeback.
3392 */
3393 rxcsum = er32(RXCSUM);
3394 rxcsum |= E1000_RXCSUM_PCSD;
3395
3396 ew32(RXCSUM, rxcsum);
3397
3398 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3399 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3400 E1000_MRQC_RSS_FIELD_IPV6 |
3401 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3402 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3403
3404 ew32(MRQC, mrqc);
3405}
3406
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003408 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3409 * @adapter: board private structure
3410 * @timinca: pointer to returned time increment attributes
3411 *
3412 * Get attributes for incrementing the System Time Register SYSTIML/H at
3413 * the default base frequency, and set the cyclecounter shift value.
3414 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003415s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003416{
3417 struct e1000_hw *hw = &adapter->hw;
3418 u32 incvalue, incperiod, shift;
3419
3420 /* Make sure clock is enabled on I217 before checking the frequency */
3421 if ((hw->mac.type == e1000_pch_lpt) &&
3422 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3423 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3424 u32 fextnvm7 = er32(FEXTNVM7);
3425
3426 if (!(fextnvm7 & (1 << 0))) {
3427 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3428 e1e_flush();
3429 }
3430 }
3431
3432 switch (hw->mac.type) {
3433 case e1000_pch2lan:
3434 case e1000_pch_lpt:
3435 /* On I217, the clock frequency is 25MHz or 96MHz as
3436 * indicated by the System Clock Frequency Indication
3437 */
3438 if ((hw->mac.type != e1000_pch_lpt) ||
3439 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3440 /* Stable 96MHz frequency */
3441 incperiod = INCPERIOD_96MHz;
3442 incvalue = INCVALUE_96MHz;
3443 shift = INCVALUE_SHIFT_96MHz;
3444 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3445 break;
3446 }
3447 /* fall-through */
3448 case e1000_82574:
3449 case e1000_82583:
3450 /* Stable 25MHz frequency */
3451 incperiod = INCPERIOD_25MHz;
3452 incvalue = INCVALUE_25MHz;
3453 shift = INCVALUE_SHIFT_25MHz;
3454 adapter->cc.shift = shift;
3455 break;
3456 default:
3457 return -EINVAL;
3458 }
3459
3460 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3461 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3462
3463 return 0;
3464}
3465
3466/**
3467 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3468 * @adapter: board private structure
3469 *
3470 * Outgoing time stamping can be enabled and disabled. Play nice and
3471 * disable it when requested, although it shouldn't cause any overhead
3472 * when no packet needs it. At most one packet in the queue may be
3473 * marked for time stamping, otherwise it would be impossible to tell
3474 * for sure to which packet the hardware time stamp belongs.
3475 *
3476 * Incoming time stamping has to be configured via the hardware filters.
3477 * Not all combinations are supported, in particular event type has to be
3478 * specified. Matching the kind of event packet is not supported, with the
3479 * exception of "all V2 events regardless of level 2 or 4".
3480 **/
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003481static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
3482 struct hwtstamp_config *config)
Bruce Allanb67e1912012-12-27 08:32:33 +00003483{
3484 struct e1000_hw *hw = &adapter->hw;
Bruce Allanb67e1912012-12-27 08:32:33 +00003485 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3486 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003487 u32 rxmtrl = 0;
3488 u16 rxudp = 0;
3489 bool is_l4 = false;
3490 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003491 u32 regval;
3492 s32 ret_val;
3493
3494 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3495 return -EINVAL;
3496
3497 /* flags reserved for future extensions - must be zero */
3498 if (config->flags)
3499 return -EINVAL;
3500
3501 switch (config->tx_type) {
3502 case HWTSTAMP_TX_OFF:
3503 tsync_tx_ctl = 0;
3504 break;
3505 case HWTSTAMP_TX_ON:
3506 break;
3507 default:
3508 return -ERANGE;
3509 }
3510
3511 switch (config->rx_filter) {
3512 case HWTSTAMP_FILTER_NONE:
3513 tsync_rx_ctl = 0;
3514 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003515 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3516 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3517 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3518 is_l4 = true;
3519 break;
3520 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3521 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3522 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3523 is_l4 = true;
3524 break;
3525 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3526 /* Also time stamps V2 L2 Path Delay Request/Response */
3527 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3528 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3529 is_l2 = true;
3530 break;
3531 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3532 /* Also time stamps V2 L2 Path Delay Request/Response. */
3533 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3534 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3535 is_l2 = true;
3536 break;
3537 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3538 /* Hardware cannot filter just V2 L4 Sync messages;
3539 * fall-through to V2 (both L2 and L4) Sync.
3540 */
3541 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3542 /* Also time stamps V2 Path Delay Request/Response. */
3543 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3544 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3545 is_l2 = true;
3546 is_l4 = true;
3547 break;
3548 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3549 /* Hardware cannot filter just V2 L4 Delay Request messages;
3550 * fall-through to V2 (both L2 and L4) Delay Request.
3551 */
3552 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3553 /* Also time stamps V2 Path Delay Request/Response. */
3554 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3555 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3556 is_l2 = true;
3557 is_l4 = true;
3558 break;
3559 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3560 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3561 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3562 * fall-through to all V2 (both L2 and L4) Events.
3563 */
3564 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3565 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3566 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3567 is_l2 = true;
3568 is_l4 = true;
3569 break;
3570 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3571 /* For V1, the hardware can only filter Sync messages or
3572 * Delay Request messages but not both so fall-through to
3573 * time stamp all packets.
3574 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003575 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003576 is_l2 = true;
3577 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003578 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3579 config->rx_filter = HWTSTAMP_FILTER_ALL;
3580 break;
3581 default:
3582 return -ERANGE;
3583 }
3584
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003585 adapter->hwtstamp_config = *config;
3586
Bruce Allanb67e1912012-12-27 08:32:33 +00003587 /* enable/disable Tx h/w time stamping */
3588 regval = er32(TSYNCTXCTL);
3589 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3590 regval |= tsync_tx_ctl;
3591 ew32(TSYNCTXCTL, regval);
3592 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3593 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3594 e_err("Timesync Tx Control register not set as expected\n");
3595 return -EAGAIN;
3596 }
3597
3598 /* enable/disable Rx h/w time stamping */
3599 regval = er32(TSYNCRXCTL);
3600 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3601 regval |= tsync_rx_ctl;
3602 ew32(TSYNCRXCTL, regval);
3603 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3604 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3605 (regval & (E1000_TSYNCRXCTL_ENABLED |
3606 E1000_TSYNCRXCTL_TYPE_MASK))) {
3607 e_err("Timesync Rx Control register not set as expected\n");
3608 return -EAGAIN;
3609 }
3610
Bruce Alland89777b2013-01-19 01:09:58 +00003611 /* L2: define ethertype filter for time stamped packets */
3612 if (is_l2)
3613 rxmtrl |= ETH_P_1588;
3614
3615 /* define which PTP packets get time stamped */
3616 ew32(RXMTRL, rxmtrl);
3617
3618 /* Filter by destination port */
3619 if (is_l4) {
3620 rxudp = PTP_EV_PORT;
3621 cpu_to_be16s(&rxudp);
3622 }
3623 ew32(RXUDP, rxudp);
3624
3625 e1e_flush();
3626
Bruce Allanb67e1912012-12-27 08:32:33 +00003627 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003628 er32(RXSTMPH);
3629 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003630
3631 /* Get and set the System Time Register SYSTIM base frequency */
3632 ret_val = e1000e_get_base_timinca(adapter, &regval);
3633 if (ret_val)
3634 return ret_val;
3635 ew32(TIMINCA, regval);
3636
3637 /* reset the ns time counter */
3638 timecounter_init(&adapter->tc, &adapter->cc,
3639 ktime_to_ns(ktime_get_real()));
3640
3641 return 0;
3642}
3643
3644/**
Bruce Allanad680762008-03-28 09:15:03 -07003645 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 * @adapter: private board structure
3647 **/
3648static void e1000_configure(struct e1000_adapter *adapter)
3649{
Bruce Allan55aa6982011-12-16 00:45:45 +00003650 struct e1000_ring *rx_ring = adapter->rx_ring;
3651
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003652 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003653
3654 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003655 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656
3657 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003658
3659 if (adapter->netdev->features & NETIF_F_RXHASH)
3660 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003661 e1000_setup_rctl(adapter);
3662 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003663 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664}
3665
3666/**
3667 * e1000e_power_up_phy - restore link in case the phy was powered down
3668 * @adapter: address of board private structure
3669 *
3670 * The phy may be powered down to save power and turn off link when the
3671 * driver is unloaded and wake on lan is not enabled (among others)
3672 * *** this routine MUST be followed by a call to e1000e_reset ***
3673 **/
3674void e1000e_power_up_phy(struct e1000_adapter *adapter)
3675{
Bruce Allan17f208d2009-12-01 15:47:22 +00003676 if (adapter->hw.phy.ops.power_up)
3677 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003678
3679 adapter->hw.mac.ops.setup_link(&adapter->hw);
3680}
3681
3682/**
3683 * e1000_power_down_phy - Power down the PHY
3684 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003685 * Power down the PHY so no link is implied when interface is down.
3686 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687 */
3688static void e1000_power_down_phy(struct e1000_adapter *adapter)
3689{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003691 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003692 return;
3693
Bruce Allan17f208d2009-12-01 15:47:22 +00003694 if (adapter->hw.phy.ops.power_down)
3695 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696}
3697
3698/**
3699 * e1000e_reset - bring the hardware into a known good state
3700 *
3701 * This function boots the hardware and enables some settings that
3702 * require a configuration cycle of the hardware - those cannot be
3703 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003704 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003705 */
3706void e1000e_reset(struct e1000_adapter *adapter)
3707{
3708 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003709 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 struct e1000_hw *hw = &adapter->hw;
3711 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003712 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 u16 hwm;
3714
Bruce Allanad680762008-03-28 09:15:03 -07003715 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003716 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003717
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003718 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003719 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 * large enough to accommodate two full transmit packets,
3721 * rounded up to the next 1KB and expressed in KB. Likewise,
3722 * the Rx FIFO should be large enough to accommodate at least
3723 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003724 * expressed in KB.
3725 */
Auke Kokdf762462007-10-25 13:57:53 -07003726 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003728 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003729 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003730 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003731 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003732 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003733 */
3734 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00003735 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736 min_tx_space = ALIGN(min_tx_space, 1024);
3737 min_tx_space >>= 10;
3738 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003739 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740 min_rx_space = ALIGN(min_rx_space, 1024);
3741 min_rx_space >>= 10;
3742
Bruce Allane921eb12012-11-28 09:28:37 +00003743 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003745 * allocation, take space away from current Rx allocation
3746 */
Auke Kokdf762462007-10-25 13:57:53 -07003747 if ((tx_space < min_tx_space) &&
3748 ((min_tx_space - tx_space) < pba)) {
3749 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750
Bruce Allane921eb12012-11-28 09:28:37 +00003751 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003752 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003753 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003754 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003755 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756 }
Auke Kokdf762462007-10-25 13:57:53 -07003757
3758 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 }
3760
Bruce Allane921eb12012-11-28 09:28:37 +00003761 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003762 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003763 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 * (or the size used for early receive) above it in the Rx FIFO.
3765 * Set it to the lower of:
3766 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003767 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003768 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003769 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3770 fc->pause_time = 0xFFFF;
3771 else
3772 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003773 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003774 fc->current_mode = fc->requested_mode;
3775
3776 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003777 case e1000_ich9lan:
3778 case e1000_ich10lan:
3779 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3780 pba = 14;
3781 ew32(PBA, pba);
3782 fc->high_water = 0x2800;
3783 fc->low_water = fc->high_water - 8;
3784 break;
3785 }
3786 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003787 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003788 hwm = min(((pba << 10) * 9 / 10),
3789 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003790
Bruce Allane80bd1d2013-05-01 01:19:46 +00003791 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
Bruce Alland3738bb2010-06-16 13:27:28 +00003792 fc->low_water = fc->high_water - 8;
3793 break;
3794 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003795 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003796 * loads. If hangs persist, try disabling Tx flow control.
3797 */
3798 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3799 fc->high_water = 0x3500;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003800 fc->low_water = 0x1500;
Bruce Allan38eb3942009-11-19 12:34:20 +00003801 } else {
3802 fc->high_water = 0x5000;
Bruce Allane80bd1d2013-05-01 01:19:46 +00003803 fc->low_water = 0x3000;
Bruce Allan38eb3942009-11-19 12:34:20 +00003804 }
Bruce Allana3055952010-05-10 15:02:12 +00003805 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003806 break;
3807 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003808 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003809 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003810
3811 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3812 fc->high_water = 0x05C20;
3813 fc->low_water = 0x05048;
3814 fc->pause_time = 0x0650;
3815 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003816 }
Bruce Allan347b5202012-12-08 00:35:35 +00003817
Bruce Allance345e02013-06-21 09:07:07 +00003818 pba = 14;
3819 ew32(PBA, pba);
Bruce Allan347b5202012-12-08 00:35:35 +00003820 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3821 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003822 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003823 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003824
Bruce Allane921eb12012-11-28 09:28:37 +00003825 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003826 * maximum size per Tx descriptor limited only to the transmit
3827 * allocation of the packet buffer minus 96 bytes with an upper
3828 * limit of 24KB due to receive synchronization limitations.
3829 */
3830 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3831 24 << 10);
3832
Bruce Allane921eb12012-11-28 09:28:37 +00003833 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003834 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003835 */
3836 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003837 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003838 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3839 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003840 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003841 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003842 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003843 }
3844 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3845 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003846 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003847 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3848 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003849 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003850 }
3851 }
3852
Auke Kokbc7f75f2007-09-17 12:30:59 -07003853 /* Allow time for pending master requests to run */
3854 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003855
Bruce Allane921eb12012-11-28 09:28:37 +00003856 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003857 * that the network interface is in control
3858 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003859 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003860 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003861
Auke Kokbc7f75f2007-09-17 12:30:59 -07003862 ew32(WUC, 0);
3863
3864 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003865 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003866
3867 e1000_update_mng_vlan(adapter);
3868
3869 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3870 ew32(VET, ETH_P_8021Q);
3871
3872 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003873
Bruce Allanb67e1912012-12-27 08:32:33 +00003874 /* initialize systim and reset the ns time counter */
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00003875 e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
Bruce Allanb67e1912012-12-27 08:32:33 +00003876
Bruce Alland495bcb2013-03-20 07:23:11 +00003877 /* Set EEE advertisement as appropriate */
3878 if (adapter->flags2 & FLAG2_HAS_EEE) {
3879 s32 ret_val;
3880 u16 adv_addr;
3881
3882 switch (hw->phy.type) {
3883 case e1000_phy_82579:
3884 adv_addr = I82579_EEE_ADVERTISEMENT;
3885 break;
3886 case e1000_phy_i217:
3887 adv_addr = I217_EEE_ADVERTISEMENT;
3888 break;
3889 default:
3890 dev_err(&adapter->pdev->dev,
3891 "Invalid PHY type setting EEE advertisement\n");
3892 return;
3893 }
3894
3895 ret_val = hw->phy.ops.acquire(hw);
3896 if (ret_val) {
3897 dev_err(&adapter->pdev->dev,
3898 "EEE advertisement - unable to acquire PHY\n");
3899 return;
3900 }
3901
3902 e1000_write_emi_reg_locked(hw, adv_addr,
3903 hw->dev_spec.ich8lan.eee_disable ?
3904 0 : adapter->eee_advert);
3905
3906 hw->phy.ops.release(hw);
3907 }
3908
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003909 if (!netif_running(adapter->netdev) &&
3910 !test_bit(__E1000_TESTING, &adapter->state)) {
3911 e1000_power_down_phy(adapter);
3912 return;
3913 }
3914
Auke Kokbc7f75f2007-09-17 12:30:59 -07003915 e1000_get_phy_info(hw);
3916
Bruce Allan918d7192009-06-02 11:28:20 +00003917 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3918 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003919 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003920 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003922 * different we would do if it failed
3923 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003924 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3925 phy_data &= ~IGP02E1000_PM_SPD;
3926 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3927 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003928}
3929
3930int e1000e_up(struct e1000_adapter *adapter)
3931{
3932 struct e1000_hw *hw = &adapter->hw;
3933
3934 /* hardware has been reset, we need to reload some things */
3935 e1000_configure(adapter);
3936
3937 clear_bit(__E1000_DOWN, &adapter->state);
3938
Bruce Allan4662e822008-08-26 18:37:06 -07003939 if (adapter->msix_entries)
3940 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 e1000_irq_enable(adapter);
3942
Bruce Allan400484f2011-05-13 07:20:03 +00003943 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003944
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003946 if (adapter->msix_entries)
3947 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3948 else
3949 ew32(ICS, E1000_ICS_LSC);
3950
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951 return 0;
3952}
3953
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003954static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3955{
3956 struct e1000_hw *hw = &adapter->hw;
3957
3958 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3959 return;
3960
3961 /* flush pending descriptor writebacks to memory */
3962 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3963 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3964
3965 /* execute the writes immediately */
3966 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003967
Bruce Allane921eb12012-11-28 09:28:37 +00003968 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003969 * write is successful
3970 */
3971 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3972 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3973
3974 /* execute the writes immediately */
3975 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003976}
3977
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003978static void e1000e_update_stats(struct e1000_adapter *adapter);
3979
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980void e1000e_down(struct e1000_adapter *adapter)
3981{
3982 struct net_device *netdev = adapter->netdev;
3983 struct e1000_hw *hw = &adapter->hw;
3984 u32 tctl, rctl;
3985
Bruce Allane921eb12012-11-28 09:28:37 +00003986 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003987 * reschedule our watchdog timer
3988 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 set_bit(__E1000_DOWN, &adapter->state);
3990
3991 /* disable receives in the hardware */
3992 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003993 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3994 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995 /* flush and sleep below */
3996
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003997 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998
3999 /* disable transmits in the hardware */
4000 tctl = er32(TCTL);
4001 tctl &= ~E1000_TCTL_EN;
4002 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004003
Auke Kokbc7f75f2007-09-17 12:30:59 -07004004 /* flush both disables and wait for them to finish */
4005 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004006 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004007
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 e1000_irq_disable(adapter);
4009
Bruce Allana3b87a42013-04-20 05:37:29 +00004010 napi_synchronize(&adapter->napi);
4011
Auke Kokbc7f75f2007-09-17 12:30:59 -07004012 del_timer_sync(&adapter->watchdog_timer);
4013 del_timer_sync(&adapter->phy_info_timer);
4014
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004016
4017 spin_lock(&adapter->stats64_lock);
4018 e1000e_update_stats(adapter);
4019 spin_unlock(&adapter->stats64_lock);
4020
Bruce Allan400484f2011-05-13 07:20:03 +00004021 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004022 e1000_clean_tx_ring(adapter->tx_ring);
4023 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004024
Auke Kokbc7f75f2007-09-17 12:30:59 -07004025 adapter->link_speed = 0;
4026 adapter->link_duplex = 0;
4027
Bruce Allanda1e2042013-06-21 09:07:02 +00004028 /* Disable Si errata workaround on PCHx for jumbo frame flow */
4029 if ((hw->mac.type >= e1000_pch2lan) &&
4030 (adapter->netdev->mtu > ETH_DATA_LEN) &&
4031 e1000_lv_jumbo_workaround_ich8lan(hw, false))
4032 e_dbg("failed to disable jumbo frame workaround mode\n");
4033
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004034 if (!pci_channel_offline(adapter->pdev))
4035 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004036
Bruce Allane921eb12012-11-28 09:28:37 +00004037 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 * pci_disable_device here.
4039 */
4040}
4041
4042void e1000e_reinit_locked(struct e1000_adapter *adapter)
4043{
4044 might_sleep();
4045 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004046 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047 e1000e_down(adapter);
4048 e1000e_up(adapter);
4049 clear_bit(__E1000_RESETTING, &adapter->state);
4050}
4051
4052/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004053 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4054 * @cc: cyclecounter structure
4055 **/
4056static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4057{
4058 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4059 cc);
4060 struct e1000_hw *hw = &adapter->hw;
4061 cycle_t systim;
4062
4063 /* latch SYSTIMH on read of SYSTIML */
4064 systim = (cycle_t)er32(SYSTIML);
4065 systim |= (cycle_t)er32(SYSTIMH) << 32;
4066
4067 return systim;
4068}
4069
4070/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4072 * @adapter: board private structure to initialize
4073 *
4074 * e1000_sw_init initializes the Adapter private data structure.
4075 * Fields are initialized based on PCI device information and
4076 * OS network device settings (MTU size).
4077 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004078static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004079{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004080 struct net_device *netdev = adapter->netdev;
4081
4082 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4083 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004084 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4085 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004086 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4087 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004089 spin_lock_init(&adapter->stats64_lock);
4090
Bruce Allan4662e822008-08-26 18:37:06 -07004091 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092
Bruce Allan4662e822008-08-26 18:37:06 -07004093 if (e1000_alloc_queues(adapter))
4094 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004095
Bruce Allanb67e1912012-12-27 08:32:33 +00004096 /* Setup hardware time stamping cyclecounter */
4097 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4098 adapter->cc.read = e1000e_cyclecounter_read;
4099 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4100 adapter->cc.mult = 1;
4101 /* cc.shift set in e1000e_get_base_tininca() */
4102
4103 spin_lock_init(&adapter->systim_lock);
4104 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4105 }
4106
Auke Kokbc7f75f2007-09-17 12:30:59 -07004107 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004108 e1000_irq_disable(adapter);
4109
Auke Kokbc7f75f2007-09-17 12:30:59 -07004110 set_bit(__E1000_DOWN, &adapter->state);
4111 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004112}
4113
4114/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004115 * e1000_intr_msi_test - Interrupt Handler
4116 * @irq: interrupt number
4117 * @data: pointer to a network interface device structure
4118 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004119static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004120{
4121 struct net_device *netdev = data;
4122 struct e1000_adapter *adapter = netdev_priv(netdev);
4123 struct e1000_hw *hw = &adapter->hw;
4124 u32 icr = er32(ICR);
4125
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004126 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004127 if (icr & E1000_ICR_RXSEQ) {
4128 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004129 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004130 * interrupt is handled.
4131 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004132 wmb();
4133 }
4134
4135 return IRQ_HANDLED;
4136}
4137
4138/**
4139 * e1000_test_msi_interrupt - Returns 0 for successful test
4140 * @adapter: board private struct
4141 *
4142 * code flow taken from tg3.c
4143 **/
4144static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4145{
4146 struct net_device *netdev = adapter->netdev;
4147 struct e1000_hw *hw = &adapter->hw;
4148 int err;
4149
4150 /* poll_enable hasn't been called yet, so don't need disable */
4151 /* clear any pending events */
4152 er32(ICR);
4153
4154 /* free the real vector and request a test handler */
4155 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004156 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004157
4158 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004159 * MSI irq handler will unset this flag
4160 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004161 adapter->flags |= FLAG_MSI_TEST_FAILED;
4162
4163 err = pci_enable_msi(adapter->pdev);
4164 if (err)
4165 goto msi_test_failed;
4166
Joe Perchesa0607fd2009-11-18 23:29:17 -08004167 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004168 netdev->name, netdev);
4169 if (err) {
4170 pci_disable_msi(adapter->pdev);
4171 goto msi_test_failed;
4172 }
4173
Bruce Allane921eb12012-11-28 09:28:37 +00004174 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004175 * interrupt.
4176 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004177 wmb();
4178
4179 e1000_irq_enable(adapter);
4180
4181 /* fire an unusual interrupt on the test handler */
4182 ew32(ICS, E1000_ICS_RXSEQ);
4183 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004184 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004185
4186 e1000_irq_disable(adapter);
4187
Bruce Allanbc763292012-08-17 06:18:07 +00004188 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004189
4190 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004191 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004192 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004193 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004194 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004195 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004196
4197 free_irq(adapter->pdev->irq, netdev);
4198 pci_disable_msi(adapter->pdev);
4199
Bruce Allanf8d59f72008-08-08 18:36:11 -07004200msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004201 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004202 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004203}
4204
4205/**
4206 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4207 * @adapter: board private struct
4208 *
4209 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4210 **/
4211static int e1000_test_msi(struct e1000_adapter *adapter)
4212{
4213 int err;
4214 u16 pci_cmd;
4215
4216 if (!(adapter->flags & FLAG_MSI_ENABLED))
4217 return 0;
4218
4219 /* disable SERR in case the MSI write causes a master abort */
4220 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004221 if (pci_cmd & PCI_COMMAND_SERR)
4222 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4223 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004224
4225 err = e1000_test_msi_interrupt(adapter);
4226
Dean Nelson36f24072010-06-29 18:12:05 +00004227 /* re-enable SERR */
4228 if (pci_cmd & PCI_COMMAND_SERR) {
4229 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4230 pci_cmd |= PCI_COMMAND_SERR;
4231 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4232 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004233
Bruce Allanf8d59f72008-08-08 18:36:11 -07004234 return err;
4235}
4236
4237/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004238 * e1000_open - Called when a network interface is made active
4239 * @netdev: network interface device structure
4240 *
4241 * Returns 0 on success, negative value on failure
4242 *
4243 * The open entry point is called when a network interface is made
4244 * active by the system (IFF_UP). At this point all resources needed
4245 * for transmit and receive operations are allocated, the interrupt
4246 * handler is registered with the OS, the watchdog timer is started,
4247 * and the stack is notified that the interface is ready.
4248 **/
4249static int e1000_open(struct net_device *netdev)
4250{
4251 struct e1000_adapter *adapter = netdev_priv(netdev);
4252 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004253 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 int err;
4255
4256 /* disallow open during test */
4257 if (test_bit(__E1000_TESTING, &adapter->state))
4258 return -EBUSY;
4259
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004260 pm_runtime_get_sync(&pdev->dev);
4261
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004262 netif_carrier_off(netdev);
4263
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004265 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004266 if (err)
4267 goto err_setup_tx;
4268
4269 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004270 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004271 if (err)
4272 goto err_setup_rx;
4273
Bruce Allane921eb12012-11-28 09:28:37 +00004274 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004275 * interface is now open and reset the part to a known state.
4276 */
4277 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004278 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004279 e1000e_reset(adapter);
4280 }
4281
Auke Kokbc7f75f2007-09-17 12:30:59 -07004282 e1000e_power_up_phy(adapter);
4283
4284 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004285 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004286 e1000_update_mng_vlan(adapter);
4287
Bruce Allan79d4e902011-12-16 00:46:27 +00004288 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004289 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4290 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004291
Bruce Allane921eb12012-11-28 09:28:37 +00004292 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004293 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4294 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004295 * clean_rx handler before we do so.
4296 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297 e1000_configure(adapter);
4298
4299 err = e1000_request_irq(adapter);
4300 if (err)
4301 goto err_req_irq;
4302
Bruce Allane921eb12012-11-28 09:28:37 +00004303 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004304 * ignore e1000e MSI messages, which means we need to test our MSI
4305 * interrupt now
4306 */
Bruce Allan4662e822008-08-26 18:37:06 -07004307 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004308 err = e1000_test_msi(adapter);
4309 if (err) {
4310 e_err("Interrupt allocation failed\n");
4311 goto err_req_irq;
4312 }
4313 }
4314
Auke Kokbc7f75f2007-09-17 12:30:59 -07004315 /* From here on the code is the same as e1000e_up() */
4316 clear_bit(__E1000_DOWN, &adapter->state);
4317
4318 napi_enable(&adapter->napi);
4319
4320 e1000_irq_enable(adapter);
4321
Jeff Kirsher09357b02011-11-18 14:25:00 +00004322 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004323 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004324
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004325 adapter->idle_check = true;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004326 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004327 pm_runtime_put(&pdev->dev);
4328
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004330 if (adapter->msix_entries)
4331 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4332 else
4333 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004334
4335 return 0;
4336
4337err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004338 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004339 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004340 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004341err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004342 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004343err_setup_tx:
4344 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004345 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004346
4347 return err;
4348}
4349
4350/**
4351 * e1000_close - Disables a network interface
4352 * @netdev: network interface device structure
4353 *
4354 * Returns 0, this is not allowed to fail
4355 *
4356 * The close entry point is called when an interface is de-activated
4357 * by the OS. The hardware is still under the drivers control, but
4358 * needs to be disabled. A global MAC reset is issued to stop the
4359 * hardware, and all transmit and receive resources are freed.
4360 **/
4361static int e1000_close(struct net_device *netdev)
4362{
4363 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004364 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004365 int count = E1000_CHECK_RESET_COUNT;
4366
4367 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4368 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004369
4370 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004371
4372 pm_runtime_get_sync(&pdev->dev);
4373
4374 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4375 e1000e_down(adapter);
4376 e1000_free_irq(adapter);
4377 }
Bruce Allana3b87a42013-04-20 05:37:29 +00004378
4379 napi_disable(&adapter->napi);
4380
Auke Kokbc7f75f2007-09-17 12:30:59 -07004381 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382
Bruce Allan55aa6982011-12-16 00:45:45 +00004383 e1000e_free_tx_resources(adapter->tx_ring);
4384 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004385
Bruce Allane921eb12012-11-28 09:28:37 +00004386 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004387 * the same ID is registered on the host OS (let 8021q kill it)
4388 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004389 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004390 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
4391 adapter->mng_vlan_id);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004392
Bruce Allane921eb12012-11-28 09:28:37 +00004393 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004394 * interface is now closed
4395 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004396 if ((adapter->flags & FLAG_HAS_AMT) &&
4397 !test_bit(__E1000_TESTING, &adapter->state))
4398 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004399
Bruce Allan3e35d992013-01-12 07:25:22 +00004400 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004401
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004402 pm_runtime_put_sync(&pdev->dev);
4403
Auke Kokbc7f75f2007-09-17 12:30:59 -07004404 return 0;
4405}
Bruce Allanfc830b72013-02-20 04:06:11 +00004406
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407/**
4408 * e1000_set_mac - Change the Ethernet Address of the NIC
4409 * @netdev: network interface device structure
4410 * @p: pointer to an address structure
4411 *
4412 * Returns 0 on success, negative on failure
4413 **/
4414static int e1000_set_mac(struct net_device *netdev, void *p)
4415{
4416 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004417 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418 struct sockaddr *addr = p;
4419
4420 if (!is_valid_ether_addr(addr->sa_data))
4421 return -EADDRNOTAVAIL;
4422
4423 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4424 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4425
Bruce Allan69e1e012012-04-14 03:28:50 +00004426 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004427
4428 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4429 /* activate the work around */
4430 e1000e_set_laa_state_82571(&adapter->hw, 1);
4431
Bruce Allane921eb12012-11-28 09:28:37 +00004432 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433 * between the time RAR[0] gets clobbered and the time it
4434 * gets fixed (in e1000_watchdog), the actual LAA is in one
4435 * of the RARs and no incoming packets directed to this port
4436 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004437 * RAR[14]
4438 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004439 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4440 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441 }
4442
4443 return 0;
4444}
4445
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004446/**
4447 * e1000e_update_phy_task - work thread to update phy
4448 * @work: pointer to our work struct
4449 *
4450 * this worker thread exists because we must acquire a
4451 * semaphore to read the phy, which we could msleep while
4452 * waiting for it, and we can't msleep in a timer.
4453 **/
4454static void e1000e_update_phy_task(struct work_struct *work)
4455{
4456 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004457 struct e1000_adapter,
4458 update_phy_task);
David Ertmana03206e2014-01-24 23:07:48 +00004459 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004460
4461 if (test_bit(__E1000_DOWN, &adapter->state))
4462 return;
4463
David Ertmana03206e2014-01-24 23:07:48 +00004464 e1000_get_phy_info(hw);
4465
4466 /* Enable EEE on 82579 after link up */
4467 if (hw->phy.type == e1000_phy_82579)
4468 e1000_set_eee_pchlan(hw);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004469}
4470
Bruce Allane921eb12012-11-28 09:28:37 +00004471/**
4472 * e1000_update_phy_info - timre call-back to update PHY info
4473 * @data: pointer to adapter cast into an unsigned long
4474 *
Bruce Allanad680762008-03-28 09:15:03 -07004475 * Need to wait a few seconds after link up to get diagnostic information from
4476 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004477 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004478static void e1000_update_phy_info(unsigned long data)
4479{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004480 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004481
4482 if (test_bit(__E1000_DOWN, &adapter->state))
4483 return;
4484
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004485 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004486}
4487
4488/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004489 * e1000e_update_phy_stats - Update the PHY statistics counters
4490 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004491 *
4492 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004493 **/
4494static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4495{
4496 struct e1000_hw *hw = &adapter->hw;
4497 s32 ret_val;
4498 u16 phy_data;
4499
4500 ret_val = hw->phy.ops.acquire(hw);
4501 if (ret_val)
4502 return;
4503
Bruce Allane921eb12012-11-28 09:28:37 +00004504 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004505 * If not, set to the page with the PHY status registers.
4506 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004507 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004508 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4509 &phy_data);
4510 if (ret_val)
4511 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004512 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4513 ret_val = hw->phy.ops.set_page(hw,
4514 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004515 if (ret_val)
4516 goto release;
4517 }
4518
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004519 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004520 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4521 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004522 if (!ret_val)
4523 adapter->stats.scc += phy_data;
4524
4525 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004526 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4527 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004528 if (!ret_val)
4529 adapter->stats.ecol += phy_data;
4530
4531 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004532 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4533 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004534 if (!ret_val)
4535 adapter->stats.mcc += phy_data;
4536
4537 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004538 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4539 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004540 if (!ret_val)
4541 adapter->stats.latecol += phy_data;
4542
4543 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004544 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4545 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004546 if (!ret_val)
4547 hw->mac.collision_delta = phy_data;
4548
4549 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004550 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4551 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004552 if (!ret_val)
4553 adapter->stats.dc += phy_data;
4554
4555 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004556 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4557 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004558 if (!ret_val)
4559 adapter->stats.tncrs += phy_data;
4560
4561release:
4562 hw->phy.ops.release(hw);
4563}
4564
4565/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566 * e1000e_update_stats - Update the board statistics counters
4567 * @adapter: board private structure
4568 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004569static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004571 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572 struct e1000_hw *hw = &adapter->hw;
4573 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574
Bruce Allane921eb12012-11-28 09:28:37 +00004575 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 * connection is down.
4577 */
4578 if (adapter->link_speed == 0)
4579 return;
4580 if (pci_channel_offline(pdev))
4581 return;
4582
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583 adapter->stats.crcerrs += er32(CRCERRS);
4584 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004585 adapter->stats.gorc += er32(GORCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004586 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004587 adapter->stats.bprc += er32(BPRC);
4588 adapter->stats.mprc += er32(MPRC);
4589 adapter->stats.roc += er32(ROC);
4590
Auke Kokbc7f75f2007-09-17 12:30:59 -07004591 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004592
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004593 /* Half-duplex statistics */
4594 if (adapter->link_duplex == HALF_DUPLEX) {
4595 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4596 e1000e_update_phy_stats(adapter);
4597 } else {
4598 adapter->stats.scc += er32(SCC);
4599 adapter->stats.ecol += er32(ECOL);
4600 adapter->stats.mcc += er32(MCC);
4601 adapter->stats.latecol += er32(LATECOL);
4602 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004603
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004604 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004605
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004606 if ((hw->mac.type != e1000_82574) &&
4607 (hw->mac.type != e1000_82583))
4608 adapter->stats.tncrs += er32(TNCRS);
4609 }
4610 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004611 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004612
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613 adapter->stats.xonrxc += er32(XONRXC);
4614 adapter->stats.xontxc += er32(XONTXC);
4615 adapter->stats.xoffrxc += er32(XOFFRXC);
4616 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004617 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004618 adapter->stats.gotc += er32(GOTCL);
Bruce Allane80bd1d2013-05-01 01:19:46 +00004619 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620 adapter->stats.rnbc += er32(RNBC);
4621 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004622
4623 adapter->stats.mptc += er32(MPTC);
4624 adapter->stats.bptc += er32(BPTC);
4625
4626 /* used for adaptive IFS */
4627
4628 hw->mac.tx_packet_delta = er32(TPT);
4629 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004630
4631 adapter->stats.algnerrc += er32(ALGNERRC);
4632 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004633 adapter->stats.cexterr += er32(CEXTERR);
4634 adapter->stats.tsctc += er32(TSCTC);
4635 adapter->stats.tsctfc += er32(TSCTFC);
4636
Auke Kokbc7f75f2007-09-17 12:30:59 -07004637 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004638 netdev->stats.multicast = adapter->stats.mprc;
4639 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004640
4641 /* Rx Errors */
4642
Bruce Allane921eb12012-11-28 09:28:37 +00004643 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004644 * our own version based on RUC and ROC
4645 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004646 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004647 adapter->stats.crcerrs + adapter->stats.algnerrc +
4648 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004649 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004650 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004651 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4652 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4653 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004654
4655 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004656 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004657 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4658 netdev->stats.tx_window_errors = adapter->stats.latecol;
4659 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004660
4661 /* Tx Dropped needs to be maintained elsewhere */
4662
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663 /* Management Stats */
4664 adapter->stats.mgptc += er32(MGTPTC);
4665 adapter->stats.mgprc += er32(MGTPRC);
4666 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004667
4668 /* Correctable ECC Errors */
4669 if (hw->mac.type == e1000_pch_lpt) {
4670 u32 pbeccsts = er32(PBECCSTS);
4671 adapter->corr_errors +=
4672 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4673 adapter->uncorr_errors +=
4674 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4675 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4676 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677}
4678
Bruce Allan7c257692008-04-23 11:09:00 -07004679/**
4680 * e1000_phy_read_status - Update the PHY register status snapshot
4681 * @adapter: board private structure
4682 **/
4683static void e1000_phy_read_status(struct e1000_adapter *adapter)
4684{
4685 struct e1000_hw *hw = &adapter->hw;
4686 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004687
Bruce Allan97390ab2013-06-29 07:42:25 +00004688 if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
4689 (er32(STATUS) & E1000_STATUS_LU) &&
Bruce Allan7c257692008-04-23 11:09:00 -07004690 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004691 int ret_val;
4692
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004693 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4694 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4695 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4696 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4697 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4698 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4699 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4700 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004701 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004702 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004703 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004704 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004705 * Set values to typical power-on defaults
4706 */
4707 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4708 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4709 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4710 BMSR_ERCAP);
4711 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4712 ADVERTISE_ALL | ADVERTISE_CSMA);
4713 phy->lpa = 0;
4714 phy->expansion = EXPANSION_ENABLENPAGE;
4715 phy->ctrl1000 = ADVERTISE_1000FULL;
4716 phy->stat1000 = 0;
4717 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4718 }
Bruce Allan7c257692008-04-23 11:09:00 -07004719}
4720
Auke Kokbc7f75f2007-09-17 12:30:59 -07004721static void e1000_print_link_info(struct e1000_adapter *adapter)
4722{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723 struct e1000_hw *hw = &adapter->hw;
4724 u32 ctrl = er32(CTRL);
4725
Bruce Allan8f12fe82008-11-21 16:54:43 -08004726 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004727 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4728 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004729 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4730 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4731 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4732 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004733}
4734
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004735static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004736{
4737 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004738 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004739 s32 ret_val = 0;
4740
Bruce Allane921eb12012-11-28 09:28:37 +00004741 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004742 * Rx sequence error interrupt. get_link_status will stay
4743 * false until the check_for_link establishes link
4744 * for copper adapters ONLY
4745 */
4746 switch (hw->phy.media_type) {
4747 case e1000_media_type_copper:
4748 if (hw->mac.get_link_status) {
4749 ret_val = hw->mac.ops.check_for_link(hw);
4750 link_active = !hw->mac.get_link_status;
4751 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004752 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004753 }
4754 break;
4755 case e1000_media_type_fiber:
4756 ret_val = hw->mac.ops.check_for_link(hw);
4757 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4758 break;
4759 case e1000_media_type_internal_serdes:
4760 ret_val = hw->mac.ops.check_for_link(hw);
4761 link_active = adapter->hw.mac.serdes_has_link;
4762 break;
4763 default:
4764 case e1000_media_type_unknown:
4765 break;
4766 }
4767
4768 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4769 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4770 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004771 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004772 }
4773
4774 return link_active;
4775}
4776
4777static void e1000e_enable_receives(struct e1000_adapter *adapter)
4778{
4779 /* make sure the receive unit is started */
4780 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004781 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004782 struct e1000_hw *hw = &adapter->hw;
4783 u32 rctl = er32(RCTL);
4784 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004785 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004786 }
4787}
4788
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004789static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4790{
4791 struct e1000_hw *hw = &adapter->hw;
4792
Bruce Allane921eb12012-11-28 09:28:37 +00004793 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004794 * for hung state and reset, if two calls return true
4795 */
4796 if (e1000_check_phy_82574(hw))
4797 adapter->phy_hang_count++;
4798 else
4799 adapter->phy_hang_count = 0;
4800
4801 if (adapter->phy_hang_count > 1) {
4802 adapter->phy_hang_count = 0;
4803 schedule_work(&adapter->reset_task);
4804 }
4805}
4806
Auke Kokbc7f75f2007-09-17 12:30:59 -07004807/**
4808 * e1000_watchdog - Timer Call-back
4809 * @data: pointer to adapter cast into an unsigned long
4810 **/
4811static void e1000_watchdog(unsigned long data)
4812{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004813 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004814
4815 /* Do the rest outside of interrupt context */
4816 schedule_work(&adapter->watchdog_task);
4817
4818 /* TODO: make this use queue_delayed_work() */
4819}
4820
4821static void e1000_watchdog_task(struct work_struct *work)
4822{
4823 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004824 struct e1000_adapter,
4825 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004826 struct net_device *netdev = adapter->netdev;
4827 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004828 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004829 struct e1000_ring *tx_ring = adapter->tx_ring;
4830 struct e1000_hw *hw = &adapter->hw;
4831 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004833 if (test_bit(__E1000_DOWN, &adapter->state))
4834 return;
4835
David S. Millerb405e8d2010-02-04 22:31:41 -08004836 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004837 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004838 /* Cancel scheduled suspend requests. */
4839 pm_runtime_resume(netdev->dev.parent);
4840
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004841 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004843 }
4844
4845 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4846 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4847 e1000_update_mng_vlan(adapter);
4848
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 if (link) {
4850 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004851 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004852
4853 /* Cancel scheduled suspend requests. */
4854 pm_runtime_resume(netdev->dev.parent);
4855
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004856 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004857 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004858 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004859 &adapter->link_speed,
4860 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004861 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004862
4863 /* check if SmartSpeed worked */
4864 e1000e_check_downshift(hw);
4865 if (phy->speed_downgraded)
4866 netdev_warn(netdev,
4867 "Link Speed was downgraded by SmartSpeed\n");
4868
Bruce Allane921eb12012-11-28 09:28:37 +00004869 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004870 * if link has autonegotiated at 10/100 half
4871 */
4872 if ((hw->phy.type == e1000_phy_igp_3 ||
4873 hw->phy.type == e1000_phy_bm) &&
David Ertman138953b2013-08-30 05:45:25 +00004874 hw->mac.autoneg &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004875 (adapter->link_speed == SPEED_10 ||
4876 adapter->link_speed == SPEED_100) &&
4877 (adapter->link_duplex == HALF_DUPLEX)) {
4878 u16 autoneg_exp;
4879
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004880 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004881
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004882 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004883 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 -07004884 }
4885
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004886 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887 adapter->tx_timeout_factor = 1;
4888 switch (adapter->link_speed) {
4889 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004890 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004891 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004892 break;
4893 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004894 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004895 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896 break;
4897 }
4898
Bruce Allane921eb12012-11-28 09:28:37 +00004899 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004900 * link-up event
4901 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4903 !txb2b) {
4904 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004905 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004906 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004907 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004908 }
4909
Bruce Allane921eb12012-11-28 09:28:37 +00004910 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004911 * some hardware issues
4912 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4914 switch (adapter->link_speed) {
4915 case SPEED_10:
4916 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004917 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918 netdev->features &= ~NETIF_F_TSO;
4919 netdev->features &= ~NETIF_F_TSO6;
4920 break;
4921 case SPEED_1000:
4922 netdev->features |= NETIF_F_TSO;
4923 netdev->features |= NETIF_F_TSO6;
4924 break;
4925 default:
4926 /* oops */
4927 break;
4928 }
4929 }
4930
Bruce Allane921eb12012-11-28 09:28:37 +00004931 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004932 * after setting TARC(0)
4933 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004934 tctl = er32(TCTL);
4935 tctl |= E1000_TCTL_EN;
4936 ew32(TCTL, tctl);
4937
Bruce Allane921eb12012-11-28 09:28:37 +00004938 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004939 * reporting link up.
4940 */
4941 if (phy->ops.cfg_on_link_up)
4942 phy->ops.cfg_on_link_up(hw);
4943
Auke Kokbc7f75f2007-09-17 12:30:59 -07004944 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004945
4946 if (!test_bit(__E1000_DOWN, &adapter->state))
4947 mod_timer(&adapter->phy_info_timer,
4948 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004949 }
4950 } else {
4951 if (netif_carrier_ok(netdev)) {
4952 adapter->link_speed = 0;
4953 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004954 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004955 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 if (!test_bit(__E1000_DOWN, &adapter->state))
4958 mod_timer(&adapter->phy_info_timer,
4959 round_jiffies(jiffies + 2 * HZ));
4960
Bruce Allan12d43f72012-12-05 06:26:14 +00004961 /* The link is lost so the controller stops DMA.
4962 * If there is queued Tx work that cannot be done
4963 * or if on an 8000ES2LAN which requires a Rx packet
4964 * buffer work-around on link down event, reset the
4965 * controller to flush the Tx/Rx packet buffers.
4966 * (Do the reset outside of interrupt context).
4967 */
4968 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4969 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4970 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004971 else
4972 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004973 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 }
4975 }
4976
4977link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004978 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004979 e1000e_update_stats(adapter);
4980
4981 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4982 adapter->tpt_old = adapter->stats.tpt;
4983 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4984 adapter->colc_old = adapter->stats.colc;
4985
Bruce Allan7c257692008-04-23 11:09:00 -07004986 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4987 adapter->gorc_old = adapter->stats.gorc;
4988 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4989 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004990 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991
Bruce Allan12d43f72012-12-05 06:26:14 +00004992 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004993 schedule_work(&adapter->reset_task);
4994 /* return immediately since reset is imminent */
4995 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004996 }
4997
Bruce Allan12d43f72012-12-05 06:26:14 +00004998 e1000e_update_adaptive(&adapter->hw);
4999
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005000 /* Simple mode for Interrupt Throttle Rate (ITR) */
5001 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00005002 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005003 * Total asymmetrical Tx or Rx gets ITR=8000;
5004 * everyone else is between 2000-8000.
5005 */
5006 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
5007 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00005008 adapter->gotc - adapter->gorc :
5009 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005010 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
5011
Matthew Vick22a4cca2012-07-12 00:02:42 +00005012 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005013 }
5014
Bruce Allanad680762008-03-28 09:15:03 -07005015 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005016 if (adapter->msix_entries)
5017 ew32(ICS, adapter->rx_ring->ims_val);
5018 else
5019 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005020
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005021 /* flush pending descriptors to memory before detecting Tx hang */
5022 e1000e_flush_descriptors(adapter);
5023
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005025 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026
Bruce Allane921eb12012-11-28 09:28:37 +00005027 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005028 * reset from the other port. Set the appropriate LAA in RAR[0]
5029 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005030 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005031 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005032
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005033 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5034 e1000e_check_82574_phy_workaround(adapter);
5035
Bruce Allanb67e1912012-12-27 08:32:33 +00005036 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5037 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5038 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5039 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5040 er32(RXSTMPH);
5041 adapter->rx_hwtstamp_cleared++;
5042 } else {
5043 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5044 }
5045 }
5046
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 /* Reset the timer */
5048 if (!test_bit(__E1000_DOWN, &adapter->state))
5049 mod_timer(&adapter->watchdog_timer,
5050 round_jiffies(jiffies + 2 * HZ));
5051}
5052
5053#define E1000_TX_FLAGS_CSUM 0x00000001
5054#define E1000_TX_FLAGS_VLAN 0x00000002
5055#define E1000_TX_FLAGS_TSO 0x00000004
5056#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005057#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005058#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5060#define E1000_TX_FLAGS_VLAN_SHIFT 16
5061
Bruce Allan55aa6982011-12-16 00:45:45 +00005062static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005064 struct e1000_context_desc *context_desc;
5065 struct e1000_buffer *buffer_info;
5066 unsigned int i;
5067 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005068 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005071 if (!skb_is_gso(skb))
5072 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005073
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005074 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005075 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5076
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005077 if (err)
5078 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079 }
5080
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005081 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5082 mss = skb_shinfo(skb)->gso_size;
5083 if (skb->protocol == htons(ETH_P_IP)) {
5084 struct iphdr *iph = ip_hdr(skb);
5085 iph->tot_len = 0;
5086 iph->check = 0;
5087 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005088 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005089 cmd_length = E1000_TXD_CMD_IP;
5090 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005091 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005092 ipv6_hdr(skb)->payload_len = 0;
5093 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005094 &ipv6_hdr(skb)->daddr,
5095 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005096 ipcse = 0;
5097 }
5098 ipcss = skb_network_offset(skb);
5099 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5100 tucss = skb_transport_offset(skb);
5101 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005102
5103 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005104 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005105
5106 i = tx_ring->next_to_use;
5107 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5108 buffer_info = &tx_ring->buffer_info[i];
5109
Bruce Allane80bd1d2013-05-01 01:19:46 +00005110 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5111 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5112 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005113 context_desc->upper_setup.tcp_fields.tucss = tucss;
5114 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005115 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allane80bd1d2013-05-01 01:19:46 +00005116 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005117 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5118 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5119
5120 buffer_info->time_stamp = jiffies;
5121 buffer_info->next_to_watch = i;
5122
5123 i++;
5124 if (i == tx_ring->count)
5125 i = 0;
5126 tx_ring->next_to_use = i;
5127
5128 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005129}
5130
Bruce Allan55aa6982011-12-16 00:45:45 +00005131static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005132{
Bruce Allan55aa6982011-12-16 00:45:45 +00005133 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005134 struct e1000_context_desc *context_desc;
5135 struct e1000_buffer *buffer_info;
5136 unsigned int i;
5137 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005138 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005139 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005140
Dave Grahamaf807c82008-10-09 14:28:58 -07005141 if (skb->ip_summed != CHECKSUM_PARTIAL)
5142 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005143
Arthur Jones5f66f202009-03-19 01:13:08 +00005144 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5145 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5146 else
5147 protocol = skb->protocol;
5148
Arthur Jones3f518392009-03-20 15:56:35 -07005149 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005150 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005151 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5152 cmd_len |= E1000_TXD_CMD_TCP;
5153 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005154 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005155 /* XXX not handling all IPV6 headers */
5156 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5157 cmd_len |= E1000_TXD_CMD_TCP;
5158 break;
5159 default:
5160 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005161 e_warn("checksum_partial proto=%x!\n",
5162 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005163 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005164 }
5165
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005166 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005167
5168 i = tx_ring->next_to_use;
5169 buffer_info = &tx_ring->buffer_info[i];
5170 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5171
5172 context_desc->lower_setup.ip_config = 0;
5173 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005174 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005175 context_desc->upper_setup.tcp_fields.tucse = 0;
5176 context_desc->tcp_seg_setup.data = 0;
5177 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5178
5179 buffer_info->time_stamp = jiffies;
5180 buffer_info->next_to_watch = i;
5181
5182 i++;
5183 if (i == tx_ring->count)
5184 i = 0;
5185 tx_ring->next_to_use = i;
5186
5187 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188}
5189
Bruce Allan55aa6982011-12-16 00:45:45 +00005190static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5191 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005192 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193{
Bruce Allan55aa6982011-12-16 00:45:45 +00005194 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005195 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005196 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005197 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005198 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005199 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005200
5201 i = tx_ring->next_to_use;
5202
5203 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005204 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005205 size = min(len, max_per_txd);
5206
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005208 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005209 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005210 buffer_info->dma = dma_map_single(&pdev->dev,
5211 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005212 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005213 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005214 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005215 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005216
5217 len -= size;
5218 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005219 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005220
5221 if (len) {
5222 i++;
5223 if (i == tx_ring->count)
5224 i = 0;
5225 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226 }
5227
5228 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005229 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230
5231 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005232 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005233 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005234
5235 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005236 i++;
5237 if (i == tx_ring->count)
5238 i = 0;
5239
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240 buffer_info = &tx_ring->buffer_info[i];
5241 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005242
5243 buffer_info->length = size;
5244 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005245 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005246 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005247 offset, size,
5248 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005249 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005250 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005251 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005252
5253 len -= size;
5254 offset += size;
5255 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 }
5257 }
5258
Bruce Allanaf667a22010-12-31 06:10:01 +00005259 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005260 /* multiply data chunks by size of headers */
5261 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5262
Auke Kokbc7f75f2007-09-17 12:30:59 -07005263 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005264 tx_ring->buffer_info[i].segs = segs;
5265 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005266 tx_ring->buffer_info[first].next_to_watch = i;
5267
5268 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005269
5270dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005271 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005272 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005273 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005274 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005275
5276 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005277 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005278 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005279 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005280 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005281 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005282 }
5283
5284 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005285}
5286
Bruce Allan55aa6982011-12-16 00:45:45 +00005287static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005288{
Bruce Allan55aa6982011-12-16 00:45:45 +00005289 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005290 struct e1000_tx_desc *tx_desc = NULL;
5291 struct e1000_buffer *buffer_info;
5292 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5293 unsigned int i;
5294
5295 if (tx_flags & E1000_TX_FLAGS_TSO) {
5296 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005297 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005298 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5299
5300 if (tx_flags & E1000_TX_FLAGS_IPV4)
5301 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5302 }
5303
5304 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5305 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5306 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5307 }
5308
5309 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5310 txd_lower |= E1000_TXD_CMD_VLE;
5311 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5312 }
5313
Ben Greear943146d2012-02-11 15:39:40 +00005314 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5315 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5316
Bruce Allanb67e1912012-12-27 08:32:33 +00005317 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5318 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5319 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5320 }
5321
Auke Kokbc7f75f2007-09-17 12:30:59 -07005322 i = tx_ring->next_to_use;
5323
Bruce Allan36b973d2010-11-24 07:42:43 +00005324 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005325 buffer_info = &tx_ring->buffer_info[i];
5326 tx_desc = E1000_TX_DESC(*tx_ring, i);
5327 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005328 tx_desc->lower.data = cpu_to_le32(txd_lower |
5329 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005330 tx_desc->upper.data = cpu_to_le32(txd_upper);
5331
5332 i++;
5333 if (i == tx_ring->count)
5334 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005335 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005336
5337 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5338
Ben Greear943146d2012-02-11 15:39:40 +00005339 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5340 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5341 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5342
Bruce Allane921eb12012-11-28 09:28:37 +00005343 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005344 * know there are new descriptors to fetch. (Only
5345 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005346 * such as IA-64).
5347 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005348 wmb();
5349
5350 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005351
5352 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005353 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005354 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005355 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005356
Bruce Allane921eb12012-11-28 09:28:37 +00005357 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005358 * at a time, it synchronizes IO on IA64/Altix systems
5359 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005360 mmiowb();
5361}
5362
5363#define MINIMUM_DHCP_PACKET_SIZE 282
5364static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5365 struct sk_buff *skb)
5366{
Bruce Allane80bd1d2013-05-01 01:19:46 +00005367 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368 u16 length, offset;
5369
Bruce Alland60923c2012-12-05 06:26:56 +00005370 if (vlan_tx_tag_present(skb) &&
5371 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5372 (adapter->hw.mng_cookie.status &
5373 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5374 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375
5376 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5377 return 0;
5378
Bruce Allan53aa82d2013-02-20 04:06:06 +00005379 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005380 return 0;
5381
5382 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005383 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005384 struct udphdr *udp;
5385
5386 if (ip->protocol != IPPROTO_UDP)
5387 return 0;
5388
5389 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5390 if (ntohs(udp->dest) != 67)
5391 return 0;
5392
5393 offset = (u8 *)udp + 8 - skb->data;
5394 length = skb->len - offset;
5395 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5396 }
5397
5398 return 0;
5399}
5400
Bruce Allan55aa6982011-12-16 00:45:45 +00005401static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005402{
Bruce Allan55aa6982011-12-16 00:45:45 +00005403 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404
Bruce Allan55aa6982011-12-16 00:45:45 +00005405 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005406 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005407 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005408 * but since that doesn't exist yet, just open code it.
5409 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005410 smp_mb();
5411
Bruce Allane921eb12012-11-28 09:28:37 +00005412 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005413 * made room available.
5414 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005415 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005416 return -EBUSY;
5417
5418 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005419 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420 ++adapter->restart_queue;
5421 return 0;
5422}
5423
Bruce Allan55aa6982011-12-16 00:45:45 +00005424static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425{
Bruce Alland821a4c2012-08-24 20:38:11 +00005426 BUG_ON(size > tx_ring->count);
5427
Bruce Allan55aa6982011-12-16 00:45:45 +00005428 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005429 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005430 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005431}
5432
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005433static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5434 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005435{
5436 struct e1000_adapter *adapter = netdev_priv(netdev);
5437 struct e1000_ring *tx_ring = adapter->tx_ring;
5438 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005439 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005440 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005441 unsigned int nr_frags;
5442 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005443 int count = 0;
5444 int tso;
5445 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446
5447 if (test_bit(__E1000_DOWN, &adapter->state)) {
5448 dev_kfree_skb_any(skb);
5449 return NETDEV_TX_OK;
5450 }
5451
5452 if (skb->len <= 0) {
5453 dev_kfree_skb_any(skb);
5454 return NETDEV_TX_OK;
5455 }
5456
Bruce Allane921eb12012-11-28 09:28:37 +00005457 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005458 * pad skb in order to meet this minimum size requirement
5459 */
5460 if (unlikely(skb->len < 17)) {
5461 if (skb_pad(skb, 17 - skb->len))
5462 return NETDEV_TX_OK;
5463 skb->len = 17;
5464 skb_set_tail_pointer(skb, 17);
5465 }
5466
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468 if (mss) {
5469 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005470
Bruce Allane921eb12012-11-28 09:28:37 +00005471 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005472 * points to just header, pull a few bytes of payload from
5473 * frags into skb->data
5474 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005475 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005476 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005477 * avoiding it could save a lot of cycles
5478 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005479 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480 unsigned int pull_size;
5481
Bruce Allana2a5b322012-01-31 06:37:17 +00005482 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005483 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005484 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005485 dev_kfree_skb_any(skb);
5486 return NETDEV_TX_OK;
5487 }
Eric Dumazete743d312010-04-14 15:59:40 -07005488 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489 }
5490 }
5491
5492 /* reserve a descriptor for the offload context */
5493 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5494 count++;
5495 count++;
5496
Bruce Alland821a4c2012-08-24 20:38:11 +00005497 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005498
5499 nr_frags = skb_shinfo(skb)->nr_frags;
5500 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005501 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5502 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005503
5504 if (adapter->hw.mac.tx_pkt_filtering)
5505 e1000_transfer_dhcp_info(adapter, skb);
5506
Bruce Allane921eb12012-11-28 09:28:37 +00005507 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005508 * head, otherwise try next time
5509 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005510 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005511 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005512
Jesse Grosseab6d182010-10-20 13:56:03 +00005513 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005514 tx_flags |= E1000_TX_FLAGS_VLAN;
5515 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5516 }
5517
5518 first = tx_ring->next_to_use;
5519
Bruce Allan55aa6982011-12-16 00:45:45 +00005520 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005521 if (tso < 0) {
5522 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005523 return NETDEV_TX_OK;
5524 }
5525
5526 if (tso)
5527 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005528 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005529 tx_flags |= E1000_TX_FLAGS_CSUM;
5530
Bruce Allane921eb12012-11-28 09:28:37 +00005531 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005532 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005533 * no longer assume, we must.
5534 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005535 if (skb->protocol == htons(ETH_P_IP))
5536 tx_flags |= E1000_TX_FLAGS_IPV4;
5537
Ben Greear943146d2012-02-11 15:39:40 +00005538 if (unlikely(skb->no_fcs))
5539 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5540
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005541 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005542 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5543 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005544 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005545 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5546 !adapter->tx_hwtstamp_skb)) {
5547 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5548 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5549 adapter->tx_hwtstamp_skb = skb_get(skb);
5550 schedule_work(&adapter->tx_hwtstamp_work);
5551 } else {
5552 skb_tx_timestamp(skb);
5553 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005554
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005555 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005556 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005557 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005558 e1000_maybe_stop_tx(tx_ring,
5559 (MAX_SKB_FRAGS *
5560 DIV_ROUND_UP(PAGE_SIZE,
5561 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005562 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005563 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005564 tx_ring->buffer_info[first].time_stamp = 0;
5565 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005566 }
5567
Auke Kokbc7f75f2007-09-17 12:30:59 -07005568 return NETDEV_TX_OK;
5569}
5570
5571/**
5572 * e1000_tx_timeout - Respond to a Tx Hang
5573 * @netdev: network interface device structure
5574 **/
5575static void e1000_tx_timeout(struct net_device *netdev)
5576{
5577 struct e1000_adapter *adapter = netdev_priv(netdev);
5578
5579 /* Do the reset outside of interrupt context */
5580 adapter->tx_timeout_count++;
5581 schedule_work(&adapter->reset_task);
5582}
5583
5584static void e1000_reset_task(struct work_struct *work)
5585{
5586 struct e1000_adapter *adapter;
5587 adapter = container_of(work, struct e1000_adapter, reset_task);
5588
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005589 /* don't run the task if already down */
5590 if (test_bit(__E1000_DOWN, &adapter->state))
5591 return;
5592
Bruce Allan12d43f72012-12-05 06:26:14 +00005593 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005594 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005595 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005596 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005597 e1000e_reinit_locked(adapter);
5598}
5599
5600/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005601 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005602 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005603 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005604 *
5605 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005606 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005607struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005608 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005609{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005610 struct e1000_adapter *adapter = netdev_priv(netdev);
5611
5612 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5613 spin_lock(&adapter->stats64_lock);
5614 e1000e_update_stats(adapter);
5615 /* Fill out the OS statistics structure */
5616 stats->rx_bytes = adapter->stats.gorc;
5617 stats->rx_packets = adapter->stats.gprc;
5618 stats->tx_bytes = adapter->stats.gotc;
5619 stats->tx_packets = adapter->stats.gptc;
5620 stats->multicast = adapter->stats.mprc;
5621 stats->collisions = adapter->stats.colc;
5622
5623 /* Rx Errors */
5624
Bruce Allane921eb12012-11-28 09:28:37 +00005625 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005626 * our own version based on RUC and ROC
5627 */
5628 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005629 adapter->stats.crcerrs + adapter->stats.algnerrc +
5630 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5631 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005632 stats->rx_crc_errors = adapter->stats.crcerrs;
5633 stats->rx_frame_errors = adapter->stats.algnerrc;
5634 stats->rx_missed_errors = adapter->stats.mpc;
5635
5636 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005637 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005638 stats->tx_aborted_errors = adapter->stats.ecol;
5639 stats->tx_window_errors = adapter->stats.latecol;
5640 stats->tx_carrier_errors = adapter->stats.tncrs;
5641
5642 /* Tx Dropped needs to be maintained elsewhere */
5643
5644 spin_unlock(&adapter->stats64_lock);
5645 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005646}
5647
5648/**
5649 * e1000_change_mtu - Change the Maximum Transfer Unit
5650 * @netdev: network interface device structure
5651 * @new_mtu: new value for maximum frame size
5652 *
5653 * Returns 0 on success, negative on failure
5654 **/
5655static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5656{
5657 struct e1000_adapter *adapter = netdev_priv(netdev);
5658 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5659
Bruce Allan2adc55c2009-06-02 11:28:58 +00005660 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005661 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5662 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5663 e_err("Jumbo Frames not supported.\n");
5664 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005665 }
5666
Bruce Allan2adc55c2009-06-02 11:28:58 +00005667 /* Supported frame sizes */
5668 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5669 (max_frame > adapter->max_hw_frame_size)) {
5670 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005671 return -EINVAL;
5672 }
5673
Bruce Allan2fbe4522012-04-19 03:21:47 +00005674 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5675 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005676 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5677 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005678 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005679 return -EINVAL;
5680 }
5681
Auke Kokbc7f75f2007-09-17 12:30:59 -07005682 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005683 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005684 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005685 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005686 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5687 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005688 if (netif_running(netdev))
5689 e1000e_down(adapter);
5690
Bruce Allane921eb12012-11-28 09:28:37 +00005691 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005692 * means we reserve 2 more, this pushes us to allocate from the next
5693 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005694 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005695 * However with the new *_jumbo_rx* routines, jumbo receives will use
5696 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005697 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005698
Jesse Brandeburg99261462010-01-22 22:56:16 +00005699 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005700 adapter->rx_buffer_len = 2048;
5701 else
5702 adapter->rx_buffer_len = 4096;
5703
5704 /* adjust allocation if LPE protects us, and we aren't using SBP */
5705 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005706 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005707 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005708 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005709
Auke Kokbc7f75f2007-09-17 12:30:59 -07005710 if (netif_running(netdev))
5711 e1000e_up(adapter);
5712 else
5713 e1000e_reset(adapter);
5714
5715 clear_bit(__E1000_RESETTING, &adapter->state);
5716
5717 return 0;
5718}
5719
5720static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5721 int cmd)
5722{
5723 struct e1000_adapter *adapter = netdev_priv(netdev);
5724 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005725
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005726 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005727 return -EOPNOTSUPP;
5728
5729 switch (cmd) {
5730 case SIOCGMIIPHY:
5731 data->phy_id = adapter->hw.phy.addr;
5732 break;
5733 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005734 e1000_phy_read_status(adapter);
5735
Bruce Allan7c257692008-04-23 11:09:00 -07005736 switch (data->reg_num & 0x1F) {
5737 case MII_BMCR:
5738 data->val_out = adapter->phy_regs.bmcr;
5739 break;
5740 case MII_BMSR:
5741 data->val_out = adapter->phy_regs.bmsr;
5742 break;
5743 case MII_PHYSID1:
5744 data->val_out = (adapter->hw.phy.id >> 16);
5745 break;
5746 case MII_PHYSID2:
5747 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5748 break;
5749 case MII_ADVERTISE:
5750 data->val_out = adapter->phy_regs.advertise;
5751 break;
5752 case MII_LPA:
5753 data->val_out = adapter->phy_regs.lpa;
5754 break;
5755 case MII_EXPANSION:
5756 data->val_out = adapter->phy_regs.expansion;
5757 break;
5758 case MII_CTRL1000:
5759 data->val_out = adapter->phy_regs.ctrl1000;
5760 break;
5761 case MII_STAT1000:
5762 data->val_out = adapter->phy_regs.stat1000;
5763 break;
5764 case MII_ESTATUS:
5765 data->val_out = adapter->phy_regs.estatus;
5766 break;
5767 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005768 return -EIO;
5769 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005770 break;
5771 case SIOCSMIIREG:
5772 default:
5773 return -EOPNOTSUPP;
5774 }
5775 return 0;
5776}
5777
Bruce Allanb67e1912012-12-27 08:32:33 +00005778/**
5779 * e1000e_hwtstamp_ioctl - control hardware time stamping
5780 * @netdev: network interface device structure
5781 * @ifreq: interface request
5782 *
5783 * Outgoing time stamping can be enabled and disabled. Play nice and
5784 * disable it when requested, although it shouldn't cause any overhead
5785 * when no packet needs it. At most one packet in the queue may be
5786 * marked for time stamping, otherwise it would be impossible to tell
5787 * for sure to which packet the hardware time stamp belongs.
5788 *
5789 * Incoming time stamping has to be configured via the hardware filters.
5790 * Not all combinations are supported, in particular event type has to be
5791 * specified. Matching the kind of event packet is not supported, with the
5792 * exception of "all V2 events regardless of level 2 or 4".
5793 **/
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005794static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Bruce Allanb67e1912012-12-27 08:32:33 +00005795{
5796 struct e1000_adapter *adapter = netdev_priv(netdev);
5797 struct hwtstamp_config config;
5798 int ret_val;
5799
5800 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5801 return -EFAULT;
5802
Ben Hutchings62d7e3a2013-11-14 00:41:38 +00005803 ret_val = e1000e_config_hwtstamp(adapter, &config);
Bruce Allanb67e1912012-12-27 08:32:33 +00005804 if (ret_val)
5805 return ret_val;
5806
Bruce Alland89777b2013-01-19 01:09:58 +00005807 switch (config.rx_filter) {
5808 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5809 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5810 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5811 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5812 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5813 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5814 /* With V2 type filters which specify a Sync or Delay Request,
5815 * Path Delay Request/Response messages are also time stamped
5816 * by hardware so notify the caller the requested packets plus
5817 * some others are time stamped.
5818 */
5819 config.rx_filter = HWTSTAMP_FILTER_SOME;
5820 break;
5821 default:
5822 break;
5823 }
5824
Bruce Allanb67e1912012-12-27 08:32:33 +00005825 return copy_to_user(ifr->ifr_data, &config,
5826 sizeof(config)) ? -EFAULT : 0;
5827}
5828
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005829static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
5830{
5831 struct e1000_adapter *adapter = netdev_priv(netdev);
5832
5833 return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
5834 sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
5835}
5836
Auke Kokbc7f75f2007-09-17 12:30:59 -07005837static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5838{
5839 switch (cmd) {
5840 case SIOCGMIIPHY:
5841 case SIOCGMIIREG:
5842 case SIOCSMIIREG:
5843 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005844 case SIOCSHWTSTAMP:
Ben Hutchings4e8cff62013-11-18 23:07:16 +00005845 return e1000e_hwtstamp_set(netdev, ifr);
5846 case SIOCGHWTSTAMP:
5847 return e1000e_hwtstamp_get(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005848 default:
5849 return -EOPNOTSUPP;
5850 }
5851}
5852
Bruce Allana4f58f52009-06-02 11:29:18 +00005853static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5854{
5855 struct e1000_hw *hw = &adapter->hw;
5856 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005857 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005858 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005859
5860 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005861 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005862
Bruce Allan2b6b1682011-05-13 07:20:09 +00005863 retval = hw->phy.ops.acquire(hw);
5864 if (retval) {
5865 e_err("Could not acquire PHY\n");
5866 return retval;
5867 }
5868
5869 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5870 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5871 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005872 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005873
5874 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005875 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5876 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005877 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5878 (u16)(mac_reg & 0xFFFF));
5879 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5880 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005881 }
5882
5883 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005884 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005885 mac_reg = er32(RCTL);
5886 if (mac_reg & E1000_RCTL_UPE)
5887 phy_reg |= BM_RCTL_UPE;
5888 if (mac_reg & E1000_RCTL_MPE)
5889 phy_reg |= BM_RCTL_MPE;
5890 phy_reg &= ~(BM_RCTL_MO_MASK);
5891 if (mac_reg & E1000_RCTL_MO_3)
5892 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005893 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005894 if (mac_reg & E1000_RCTL_BAM)
5895 phy_reg |= BM_RCTL_BAM;
5896 if (mac_reg & E1000_RCTL_PMCF)
5897 phy_reg |= BM_RCTL_PMCF;
5898 mac_reg = er32(CTRL);
5899 if (mac_reg & E1000_CTRL_RFCE)
5900 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005901 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005902
5903 /* enable PHY wakeup in MAC register */
5904 ew32(WUFC, wufc);
5905 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5906
5907 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005908 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5909 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005910
5911 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005912 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5913 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005914 if (retval)
5915 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005916release:
Bruce Allan94d81862009-11-20 23:25:26 +00005917 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005918
5919 return retval;
5920}
5921
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00005922static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005923{
5924 struct net_device *netdev = pci_get_drvdata(pdev);
5925 struct e1000_adapter *adapter = netdev_priv(netdev);
5926 struct e1000_hw *hw = &adapter->hw;
5927 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005928 /* Runtime suspend should only enable wakeup for link changes */
5929 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005930 int retval = 0;
5931
5932 netif_device_detach(netdev);
5933
5934 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005935 int count = E1000_CHECK_RESET_COUNT;
5936
5937 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5938 usleep_range(10000, 20000);
5939
Auke Kokbc7f75f2007-09-17 12:30:59 -07005940 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5941 e1000e_down(adapter);
5942 e1000_free_irq(adapter);
5943 }
Bruce Allan4662e822008-08-26 18:37:06 -07005944 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005945
Auke Kokbc7f75f2007-09-17 12:30:59 -07005946 status = er32(STATUS);
5947 if (status & E1000_STATUS_LU)
5948 wufc &= ~E1000_WUFC_LNKC;
5949
5950 if (wufc) {
5951 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005952 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005953
5954 /* turn on all-multi mode if wake on multicast is enabled */
5955 if (wufc & E1000_WUFC_MC) {
5956 rctl = er32(RCTL);
5957 rctl |= E1000_RCTL_MPE;
5958 ew32(RCTL, rctl);
5959 }
5960
5961 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00005962 ctrl |= E1000_CTRL_ADVD3WUC;
5963 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5964 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005965 ew32(CTRL, ctrl);
5966
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005967 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5968 adapter->hw.phy.media_type ==
5969 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005970 /* keep the laser running in D3 */
5971 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005972 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005973 ew32(CTRL_EXT, ctrl_ext);
5974 }
5975
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005976 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005977 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005978
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 /* Allow time for pending master requests to run */
5980 e1000e_disable_pcie_master(&adapter->hw);
5981
Bruce Allan82776a42009-08-14 14:35:33 +00005982 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005983 /* enable wakeup by the PHY */
5984 retval = e1000_init_phy_wakeup(adapter, wufc);
5985 if (retval)
5986 return retval;
5987 } else {
5988 /* enable wakeup by the MAC */
5989 ew32(WUFC, wufc);
5990 ew32(WUC, E1000_WUC_PME_EN);
5991 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005992 } else {
5993 ew32(WUC, 0);
5994 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995 }
5996
Auke Kokbc7f75f2007-09-17 12:30:59 -07005997 if (adapter->hw.phy.type == e1000_phy_igp_3)
5998 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5999
Bruce Allane921eb12012-11-28 09:28:37 +00006000 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006001 * would have already happened in close and is redundant.
6002 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006003 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006004
Dean Nelson24b41c92013-06-13 03:55:44 +00006005 pci_clear_master(pdev);
6006
Bruce Allane921eb12012-11-28 09:28:37 +00006007 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006008 * correctable error when the MAC transitions from D0 to D3. To
6009 * prevent this we need to mask off the correctable errors on the
6010 * downstream port of the pci-e switch.
Li Zhange8c254c2013-08-13 18:42:58 +00006011 *
6012 * We don't have the associated upstream bridge while assigning
6013 * the PCI device into guest. For example, the KVM on power is
6014 * one of the cases.
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006015 */
6016 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6017 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006018 u16 devctl;
6019
Li Zhange8c254c2013-08-13 18:42:58 +00006020 if (!us_dev)
6021 return 0;
6022
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006023 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6024 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6025 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006026
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006027 pci_save_state(pdev);
6028 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006029
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006030 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006031 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006032
6033 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006034}
6035
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006036/**
6037 * e1000e_disable_aspm - Disable ASPM states
6038 * @pdev: pointer to PCI device struct
6039 * @state: bit-mask of ASPM states to disable
6040 *
6041 * Some devices *must* have certain ASPM states disabled per hardware errata.
6042 **/
6043static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006044{
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006045 struct pci_dev *parent = pdev->bus->self;
6046 u16 aspm_dis_mask = 0;
6047 u16 pdev_aspmc, parent_aspmc;
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006048
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006049 switch (state) {
6050 case PCIE_LINK_STATE_L0S:
6051 case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
6052 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
6053 /* fall-through - can't have L1 without L0s */
6054 case PCIE_LINK_STATE_L1:
6055 aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
6056 break;
6057 default:
6058 return;
6059 }
6060
6061 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6062 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6063
6064 if (parent) {
6065 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
6066 &parent_aspmc);
6067 parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6068 }
6069
6070 /* Nothing to do if the ASPM states to be disabled already are */
6071 if (!(pdev_aspmc & aspm_dis_mask) &&
6072 (!parent || !(parent_aspmc & aspm_dis_mask)))
6073 return;
6074
6075 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6076 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
6077 "L0s" : "",
6078 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
6079 "L1" : "");
6080
6081#ifdef CONFIG_PCIEASPM
6082 pci_disable_link_state_locked(pdev, state);
6083
6084 /* Double-check ASPM control. If not disabled by the above, the
6085 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
6086 * not enabled); override by writing PCI config space directly.
6087 */
6088 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
6089 pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
6090
6091 if (!(aspm_dis_mask & pdev_aspmc))
6092 return;
6093#endif
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006094
Bruce Allane921eb12012-11-28 09:28:37 +00006095 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006096 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006097 */
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006098 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
Bruce Allan6f461f62010-04-27 03:33:04 +00006099
Carolyn Wyborny13129d92013-08-03 01:53:54 +00006100 if (parent)
6101 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
6102 aspm_dis_mask);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006103}
6104
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006105#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006106static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006107{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006108 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006109}
6110
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006111static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006112{
6113 struct net_device *netdev = pci_get_drvdata(pdev);
6114 struct e1000_adapter *adapter = netdev_priv(netdev);
6115 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006116 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006117 u32 err;
6118
Bruce Allan78cd29d2011-03-24 03:09:03 +00006119 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6120 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6121 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6122 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6123 if (aspm_disable_flag)
6124 e1000e_disable_aspm(pdev, aspm_disable_flag);
6125
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006126 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006127
Bruce Allan4662e822008-08-26 18:37:06 -07006128 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006129 if (netif_running(netdev)) {
6130 err = e1000_request_irq(adapter);
6131 if (err)
6132 return err;
6133 }
6134
Bruce Allan2fbe4522012-04-19 03:21:47 +00006135 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006136 e1000_resume_workarounds_pchlan(&adapter->hw);
6137
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006139
6140 /* report the system wakeup cause from S3/S4 */
6141 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6142 u16 phy_data;
6143
6144 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6145 if (phy_data) {
6146 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006147 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6148 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6149 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6150 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6151 phy_data & E1000_WUS_LNKC ?
6152 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006153 }
6154 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6155 } else {
6156 u32 wus = er32(WUS);
6157 if (wus) {
6158 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006159 wus & E1000_WUS_EX ? "Unicast Packet" :
6160 wus & E1000_WUS_MC ? "Multicast Packet" :
6161 wus & E1000_WUS_BC ? "Broadcast Packet" :
6162 wus & E1000_WUS_MAG ? "Magic Packet" :
6163 wus & E1000_WUS_LNKC ? "Link Status Change" :
6164 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006165 }
6166 ew32(WUS, ~0);
6167 }
6168
Auke Kokbc7f75f2007-09-17 12:30:59 -07006169 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006170
Bruce Allancd791612010-05-10 14:59:51 +00006171 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006172
6173 if (netif_running(netdev))
6174 e1000e_up(adapter);
6175
6176 netif_device_attach(netdev);
6177
Bruce Allane921eb12012-11-28 09:28:37 +00006178 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006179 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006180 * under the control of the driver.
6181 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006182 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006183 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006184
6185 return 0;
6186}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006187
Mika Westerberg38a529b2014-01-16 14:39:39 +02006188#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006189static int e1000_suspend(struct device *dev)
6190{
6191 struct pci_dev *pdev = to_pci_dev(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006192
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006193 return __e1000_shutdown(pdev, false);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006194}
6195
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006196static int e1000_resume(struct device *dev)
6197{
6198 struct pci_dev *pdev = to_pci_dev(dev);
6199 struct net_device *netdev = pci_get_drvdata(pdev);
6200 struct e1000_adapter *adapter = netdev_priv(netdev);
6201
6202 if (e1000e_pm_ready(adapter))
6203 adapter->idle_check = true;
6204
6205 return __e1000_resume(pdev);
6206}
Mika Westerberg38a529b2014-01-16 14:39:39 +02006207#endif /* CONFIG_PM_SLEEP */
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006208
6209#ifdef CONFIG_PM_RUNTIME
6210static int e1000_runtime_suspend(struct device *dev)
6211{
6212 struct pci_dev *pdev = to_pci_dev(dev);
6213 struct net_device *netdev = pci_get_drvdata(pdev);
6214 struct e1000_adapter *adapter = netdev_priv(netdev);
6215
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006216 if (!e1000e_pm_ready(adapter))
6217 return 0;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006218
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006219 return __e1000_shutdown(pdev, true);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006220}
6221
6222static int e1000_idle(struct device *dev)
6223{
6224 struct pci_dev *pdev = to_pci_dev(dev);
6225 struct net_device *netdev = pci_get_drvdata(pdev);
6226 struct e1000_adapter *adapter = netdev_priv(netdev);
6227
6228 if (!e1000e_pm_ready(adapter))
6229 return 0;
6230
6231 if (adapter->idle_check) {
6232 adapter->idle_check = false;
6233 if (!e1000e_has_link(adapter))
6234 pm_schedule_suspend(dev, MSEC_PER_SEC);
6235 }
6236
6237 return -EBUSY;
6238}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006239
6240static int e1000_runtime_resume(struct device *dev)
6241{
6242 struct pci_dev *pdev = to_pci_dev(dev);
6243 struct net_device *netdev = pci_get_drvdata(pdev);
6244 struct e1000_adapter *adapter = netdev_priv(netdev);
6245
6246 if (!e1000e_pm_ready(adapter))
6247 return 0;
6248
6249 adapter->idle_check = !dev->power.runtime_auto;
6250 return __e1000_resume(pdev);
6251}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006252#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006253#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006254
6255static void e1000_shutdown(struct pci_dev *pdev)
6256{
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006257 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006258}
6259
6260#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006261
Bruce Allan8bb62862013-01-16 08:46:49 +00006262static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006263{
6264 struct net_device *netdev = data;
6265 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006266
6267 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006268 int vector, msix_irq;
6269
Dongdong Deng147b2c82010-11-16 19:50:15 -08006270 vector = 0;
6271 msix_irq = adapter->msix_entries[vector].vector;
6272 disable_irq(msix_irq);
6273 e1000_intr_msix_rx(msix_irq, netdev);
6274 enable_irq(msix_irq);
6275
6276 vector++;
6277 msix_irq = adapter->msix_entries[vector].vector;
6278 disable_irq(msix_irq);
6279 e1000_intr_msix_tx(msix_irq, netdev);
6280 enable_irq(msix_irq);
6281
6282 vector++;
6283 msix_irq = adapter->msix_entries[vector].vector;
6284 disable_irq(msix_irq);
6285 e1000_msix_other(msix_irq, netdev);
6286 enable_irq(msix_irq);
6287 }
6288
6289 return IRQ_HANDLED;
6290}
6291
Bruce Allane921eb12012-11-28 09:28:37 +00006292/**
6293 * e1000_netpoll
6294 * @netdev: network interface device structure
6295 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006296 * Polling 'interrupt' - used by things like netconsole to send skbs
6297 * without having to re-enable interrupts. It's not called while
6298 * the interrupt routine is executing.
6299 */
6300static void e1000_netpoll(struct net_device *netdev)
6301{
6302 struct e1000_adapter *adapter = netdev_priv(netdev);
6303
Dongdong Deng147b2c82010-11-16 19:50:15 -08006304 switch (adapter->int_mode) {
6305 case E1000E_INT_MODE_MSIX:
6306 e1000_intr_msix(adapter->pdev->irq, netdev);
6307 break;
6308 case E1000E_INT_MODE_MSI:
6309 disable_irq(adapter->pdev->irq);
6310 e1000_intr_msi(adapter->pdev->irq, netdev);
6311 enable_irq(adapter->pdev->irq);
6312 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +00006313 default: /* E1000E_INT_MODE_LEGACY */
Dongdong Deng147b2c82010-11-16 19:50:15 -08006314 disable_irq(adapter->pdev->irq);
6315 e1000_intr(adapter->pdev->irq, netdev);
6316 enable_irq(adapter->pdev->irq);
6317 break;
6318 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006319}
6320#endif
6321
6322/**
6323 * e1000_io_error_detected - called when PCI error is detected
6324 * @pdev: Pointer to PCI device
6325 * @state: The current pci connection state
6326 *
6327 * This function is called after a PCI bus error affecting
6328 * this device has been detected.
6329 */
6330static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6331 pci_channel_state_t state)
6332{
6333 struct net_device *netdev = pci_get_drvdata(pdev);
6334 struct e1000_adapter *adapter = netdev_priv(netdev);
6335
6336 netif_device_detach(netdev);
6337
Mike Masonc93b5a72009-06-30 12:45:53 +00006338 if (state == pci_channel_io_perm_failure)
6339 return PCI_ERS_RESULT_DISCONNECT;
6340
Auke Kokbc7f75f2007-09-17 12:30:59 -07006341 if (netif_running(netdev))
6342 e1000e_down(adapter);
6343 pci_disable_device(pdev);
6344
6345 /* Request a slot slot reset. */
6346 return PCI_ERS_RESULT_NEED_RESET;
6347}
6348
6349/**
6350 * e1000_io_slot_reset - called after the pci bus has been reset.
6351 * @pdev: Pointer to PCI device
6352 *
6353 * Restart the card from scratch, as if from a cold-boot. Implementation
6354 * resembles the first-half of the e1000_resume routine.
6355 */
6356static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6357{
6358 struct net_device *netdev = pci_get_drvdata(pdev);
6359 struct e1000_adapter *adapter = netdev_priv(netdev);
6360 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006361 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006362 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006363 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364
Bruce Allan78cd29d2011-03-24 03:09:03 +00006365 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6366 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006367 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006368 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6369 if (aspm_disable_flag)
6370 e1000e_disable_aspm(pdev, aspm_disable_flag);
6371
Bruce Allanf0f422e2008-08-04 17:21:53 -07006372 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006373 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006374 dev_err(&pdev->dev,
6375 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006376 result = PCI_ERS_RESULT_DISCONNECT;
6377 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006378 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006379 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006380 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006381
6382 pci_enable_wake(pdev, PCI_D3hot, 0);
6383 pci_enable_wake(pdev, PCI_D3cold, 0);
6384
6385 e1000e_reset(adapter);
6386 ew32(WUS, ~0);
6387 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006388 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006389
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006390 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006391
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006392 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393}
6394
6395/**
6396 * e1000_io_resume - called when traffic can start flowing again.
6397 * @pdev: Pointer to PCI device
6398 *
6399 * This callback is called when the error recovery driver tells us that
6400 * its OK to resume normal operation. Implementation resembles the
6401 * second-half of the e1000_resume routine.
6402 */
6403static void e1000_io_resume(struct pci_dev *pdev)
6404{
6405 struct net_device *netdev = pci_get_drvdata(pdev);
6406 struct e1000_adapter *adapter = netdev_priv(netdev);
6407
Bruce Allancd791612010-05-10 14:59:51 +00006408 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006409
6410 if (netif_running(netdev)) {
6411 if (e1000e_up(adapter)) {
6412 dev_err(&pdev->dev,
6413 "can't bring device back up after reset\n");
6414 return;
6415 }
6416 }
6417
6418 netif_device_attach(netdev);
6419
Bruce Allane921eb12012-11-28 09:28:37 +00006420 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006421 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006422 * under the control of the driver.
6423 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006424 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006425 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006426}
6427
6428static void e1000_print_device_info(struct e1000_adapter *adapter)
6429{
6430 struct e1000_hw *hw = &adapter->hw;
6431 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006432 u32 ret_val;
6433 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006434
6435 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006436 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006437 /* bus width */
6438 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006439 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006440 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006441 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006442 e_info("Intel(R) PRO/%s Network Connection\n",
6443 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006444 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6445 E1000_PBANUM_LENGTH);
6446 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006447 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006448 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6449 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006450}
6451
Auke Kok10aa4c02008-08-04 17:21:20 -07006452static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6453{
6454 struct e1000_hw *hw = &adapter->hw;
6455 int ret_val;
6456 u16 buf = 0;
6457
6458 if (hw->mac.type != e1000_82573)
6459 return;
6460
6461 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006462 le16_to_cpus(&buf);
6463 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006464 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006465 dev_warn(&adapter->pdev->dev,
6466 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006467 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006468}
6469
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006470static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006471 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006472{
6473 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006474 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006475
6476 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6477 adapter->flags |= FLAG_TSO_FORCE;
6478
Patrick McHardyf6469682013-04-19 02:04:27 +00006479 if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006480 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6481 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006482 return 0;
6483
Ben Greear01840392012-02-11 15:39:25 +00006484 if (changed & NETIF_F_RXFCS) {
6485 if (features & NETIF_F_RXFCS) {
6486 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6487 } else {
6488 /* We need to take it back to defaults, which might mean
6489 * stripping is still disabled at the adapter level.
6490 */
6491 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6492 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6493 else
6494 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6495 }
6496 }
6497
Bruce Allan70495a52012-01-11 01:26:50 +00006498 netdev->features = features;
6499
Bruce Allandc221292011-08-19 03:23:48 +00006500 if (netif_running(netdev))
6501 e1000e_reinit_locked(adapter);
6502 else
6503 e1000e_reset(adapter);
6504
6505 return 0;
6506}
6507
Stephen Hemminger651c2462008-11-19 21:57:48 -08006508static const struct net_device_ops e1000e_netdev_ops = {
6509 .ndo_open = e1000_open,
6510 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006511 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006512 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006513 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006514 .ndo_set_mac_address = e1000_set_mac,
6515 .ndo_change_mtu = e1000_change_mtu,
6516 .ndo_do_ioctl = e1000_ioctl,
6517 .ndo_tx_timeout = e1000_tx_timeout,
6518 .ndo_validate_addr = eth_validate_addr,
6519
Stephen Hemminger651c2462008-11-19 21:57:48 -08006520 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6521 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6522#ifdef CONFIG_NET_POLL_CONTROLLER
6523 .ndo_poll_controller = e1000_netpoll,
6524#endif
Bruce Allandc221292011-08-19 03:23:48 +00006525 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006526};
6527
Auke Kokbc7f75f2007-09-17 12:30:59 -07006528/**
6529 * e1000_probe - Device Initialization Routine
6530 * @pdev: PCI device information struct
6531 * @ent: entry in e1000_pci_tbl
6532 *
6533 * Returns 0 on success, negative on failure
6534 *
6535 * e1000_probe initializes an adapter identified by a pci_dev structure.
6536 * The OS initialization, configuring of the adapter private structure,
6537 * and a hardware reset occur.
6538 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006539static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006540{
6541 struct net_device *netdev;
6542 struct e1000_adapter *adapter;
6543 struct e1000_hw *hw;
6544 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006545 resource_size_t mmio_start, mmio_len;
6546 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006547 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006548 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006549 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006550 u16 eeprom_data = 0;
6551 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6552
Bruce Allan78cd29d2011-03-24 03:09:03 +00006553 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6554 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006555 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006556 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6557 if (aspm_disable_flag)
6558 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006559
Bruce Allanf0f422e2008-08-04 17:21:53 -07006560 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006561 if (err)
6562 return err;
6563
6564 pci_using_dac = 0;
Russell King718a39e2013-06-10 12:22:30 +01006565 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006566 if (!err) {
Russell King718a39e2013-06-10 12:22:30 +01006567 pci_using_dac = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006568 } else {
Russell King718a39e2013-06-10 12:22:30 +01006569 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006570 if (err) {
Russell King718a39e2013-06-10 12:22:30 +01006571 dev_err(&pdev->dev,
6572 "No usable DMA configuration, aborting\n");
6573 goto err_dma;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006574 }
6575 }
6576
Bruce Allan17e813e2013-02-20 04:06:01 +00006577 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6578 err = pci_request_selected_regions_exclusive(pdev, bars,
6579 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006580 if (err)
6581 goto err_pci_reg;
6582
Xiaotian Feng68eac462009-08-14 14:35:52 +00006583 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006584 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006585
Auke Kokbc7f75f2007-09-17 12:30:59 -07006586 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006587 /* PCI config space info */
6588 err = pci_save_state(pdev);
6589 if (err)
6590 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006591
6592 err = -ENOMEM;
6593 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6594 if (!netdev)
6595 goto err_alloc_etherdev;
6596
Auke Kokbc7f75f2007-09-17 12:30:59 -07006597 SET_NETDEV_DEV(netdev, &pdev->dev);
6598
Tom Herbertf85e4df2010-05-05 14:03:32 +00006599 netdev->irq = pdev->irq;
6600
Auke Kokbc7f75f2007-09-17 12:30:59 -07006601 pci_set_drvdata(pdev, netdev);
6602 adapter = netdev_priv(netdev);
6603 hw = &adapter->hw;
6604 adapter->netdev = netdev;
6605 adapter->pdev = pdev;
6606 adapter->ei = ei;
6607 adapter->pba = ei->pba;
6608 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006609 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006610 adapter->hw.adapter = adapter;
6611 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006612 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006613 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006614
6615 mmio_start = pci_resource_start(pdev, 0);
6616 mmio_len = pci_resource_len(pdev, 0);
6617
6618 err = -EIO;
6619 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6620 if (!adapter->hw.hw_addr)
6621 goto err_ioremap;
6622
6623 if ((adapter->flags & FLAG_HAS_FLASH) &&
6624 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6625 flash_start = pci_resource_start(pdev, 1);
6626 flash_len = pci_resource_len(pdev, 1);
6627 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6628 if (!adapter->hw.flash_address)
6629 goto err_flashmap;
6630 }
6631
Bruce Alland495bcb2013-03-20 07:23:11 +00006632 /* Set default EEE advertisement */
6633 if (adapter->flags2 & FLAG2_HAS_EEE)
6634 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
6635
Auke Kokbc7f75f2007-09-17 12:30:59 -07006636 /* construct the net_device struct */
Bruce Allane80bd1d2013-05-01 01:19:46 +00006637 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006638 e1000e_set_ethtool_ops(netdev);
Bruce Allane80bd1d2013-05-01 01:19:46 +00006639 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006640 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006641 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006642
6643 netdev->mem_start = mmio_start;
6644 netdev->mem_end = mmio_start + mmio_len;
6645
6646 adapter->bd_number = cards_found++;
6647
Bruce Allan4662e822008-08-26 18:37:06 -07006648 e1000e_check_options(adapter);
6649
Auke Kokbc7f75f2007-09-17 12:30:59 -07006650 /* setup adapter struct */
6651 err = e1000_sw_init(adapter);
6652 if (err)
6653 goto err_sw_init;
6654
Auke Kokbc7f75f2007-09-17 12:30:59 -07006655 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6656 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6657 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6658
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006659 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006660 if (err)
6661 goto err_hw_init;
6662
Bruce Allan4a770352008-10-01 17:18:35 -07006663 if ((adapter->flags & FLAG_IS_ICH) &&
6664 (adapter->flags & FLAG_READ_ONLY_NVM))
6665 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6666
Auke Kokbc7f75f2007-09-17 12:30:59 -07006667 hw->mac.ops.get_bus_info(&adapter->hw);
6668
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006669 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006670
6671 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006672 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006673 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6674 adapter->hw.phy.disable_polarity_correction = 0;
6675 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6676 }
6677
Bruce Allan470a5422012-05-26 06:08:48 +00006678 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006679 dev_info(&pdev->dev,
6680 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006681
Bruce Allandc221292011-08-19 03:23:48 +00006682 /* Set initial default active device features */
6683 netdev->features = (NETIF_F_SG |
Patrick McHardyf6469682013-04-19 02:04:27 +00006684 NETIF_F_HW_VLAN_CTAG_RX |
6685 NETIF_F_HW_VLAN_CTAG_TX |
Bruce Allandc221292011-08-19 03:23:48 +00006686 NETIF_F_TSO |
6687 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006688 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006689 NETIF_F_RXCSUM |
6690 NETIF_F_HW_CSUM);
6691
6692 /* Set user-changeable features (subset of all device features) */
6693 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006694 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006695 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006696 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006697
6698 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
Patrick McHardyf6469682013-04-19 02:04:27 +00006699 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006700
Bruce Allandc221292011-08-19 03:23:48 +00006701 netdev->vlan_features |= (NETIF_F_SG |
6702 NETIF_F_TSO |
6703 NETIF_F_TSO6 |
6704 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006705
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006706 netdev->priv_flags |= IFF_UNICAST_FLT;
6707
Yi Zou7b872a52010-09-22 17:57:58 +00006708 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006709 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006710 netdev->vlan_features |= NETIF_F_HIGHDMA;
6711 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712
Auke Kokbc7f75f2007-09-17 12:30:59 -07006713 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6714 adapter->flags |= FLAG_MNG_PT_ENABLED;
6715
Bruce Allane921eb12012-11-28 09:28:37 +00006716 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006717 * put the device in a known good starting state
6718 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006719 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6720
Bruce Allane921eb12012-11-28 09:28:37 +00006721 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006722 * attempt. Let's give it a few tries
6723 */
6724 for (i = 0;; i++) {
6725 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6726 break;
6727 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006728 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006729 err = -EIO;
6730 goto err_eeprom;
6731 }
6732 }
6733
Auke Kok10aa4c02008-08-04 17:21:20 -07006734 e1000_eeprom_checks(adapter);
6735
Bruce Allan608f8a02010-01-13 02:04:58 +00006736 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006737 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006738 dev_err(&pdev->dev,
6739 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006740
6741 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006742
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006743 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006744 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006745 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006746 err = -EIO;
6747 goto err_eeprom;
6748 }
6749
6750 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006751 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006752 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006753
6754 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006755 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006756 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006757
6758 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6759 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006760 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6761 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006762 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006763
Auke Kokbc7f75f2007-09-17 12:30:59 -07006764 /* Initialize link parameters. User can change them with ethtool */
6765 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006766 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006767 adapter->hw.fc.requested_mode = e1000_fc_default;
6768 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006769 adapter->hw.phy.autoneg_advertised = 0x2f;
6770
Bruce Allane921eb12012-11-28 09:28:37 +00006771 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006772 * the EEPROM, enable the ACPI Magic Packet filter
6773 */
6774 if (adapter->flags & FLAG_APME_IN_WUC) {
6775 /* APME bit in EEPROM is mapped to WUC.APME */
6776 eeprom_data = er32(WUC);
6777 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006778 if ((hw->mac.type > e1000_ich10lan) &&
6779 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006780 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006781 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6782 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6783 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006784 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6785 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006786 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006787 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6788 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006789 }
6790
6791 /* fetch WoL from EEPROM */
6792 if (eeprom_data & eeprom_apme_mask)
6793 adapter->eeprom_wol |= E1000_WUFC_MAG;
6794
Bruce Allane921eb12012-11-28 09:28:37 +00006795 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006796 * where the eeprom may be wrong or the board simply won't support
6797 * wake on lan on a particular port
6798 */
6799 if (!(adapter->flags & FLAG_HAS_WOL))
6800 adapter->eeprom_wol = 0;
6801
6802 /* initialize the wol settings based on the eeprom settings */
6803 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006804
6805 /* make sure adapter isn't asleep if manageability is enabled */
6806 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
6807 (hw->mac.ops.check_mng_mode(hw)))
6808 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809
Bruce Allan84527592008-11-21 17:00:22 -08006810 /* save off EEPROM version number */
6811 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6812
Auke Kokbc7f75f2007-09-17 12:30:59 -07006813 /* reset the hardware with the new settings */
6814 e1000e_reset(adapter);
6815
Bruce Allane921eb12012-11-28 09:28:37 +00006816 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006817 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006818 * under the control of the driver.
6819 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006820 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006821 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006822
Bruce Allanf2315bf2011-12-16 00:46:59 +00006823 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006824 err = register_netdev(netdev);
6825 if (err)
6826 goto err_register;
6827
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006828 /* carrier off reporting is important to ethtool even BEFORE open */
6829 netif_carrier_off(netdev);
6830
Bruce Alland89777b2013-01-19 01:09:58 +00006831 /* init PTP hardware clock */
6832 e1000e_ptp_init(adapter);
6833
Auke Kokbc7f75f2007-09-17 12:30:59 -07006834 e1000_print_device_info(adapter);
6835
Alan Sternf3ec4f82010-06-08 15:23:51 -04006836 if (pci_dev_run_wake(pdev))
6837 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006838
Auke Kokbc7f75f2007-09-17 12:30:59 -07006839 return 0;
6840
6841err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006842 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006843 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006844err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006845 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006846 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006847err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006848 kfree(adapter->tx_ring);
6849 kfree(adapter->rx_ring);
6850err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006851 if (adapter->hw.flash_address)
6852 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006853 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006854err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006855 iounmap(adapter->hw.hw_addr);
6856err_ioremap:
6857 free_netdev(netdev);
6858err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006859 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006860 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006861err_pci_reg:
6862err_dma:
6863 pci_disable_device(pdev);
6864 return err;
6865}
6866
6867/**
6868 * e1000_remove - Device Removal Routine
6869 * @pdev: PCI device information struct
6870 *
6871 * e1000_remove is called by the PCI subsystem to alert the driver
6872 * that it should release a PCI device. The could be caused by a
6873 * Hot-Plug event, or because the driver is going to be removed from
6874 * memory.
6875 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006876static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006877{
6878 struct net_device *netdev = pci_get_drvdata(pdev);
6879 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006880 bool down = test_bit(__E1000_DOWN, &adapter->state);
6881
Bruce Alland89777b2013-01-19 01:09:58 +00006882 e1000e_ptp_remove(adapter);
6883
Bruce Allane921eb12012-11-28 09:28:37 +00006884 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006885 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006886 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006887 if (!down)
6888 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006889 del_timer_sync(&adapter->watchdog_timer);
6890 del_timer_sync(&adapter->phy_info_timer);
6891
Bruce Allan41cec6f2009-11-20 23:28:56 +00006892 cancel_work_sync(&adapter->reset_task);
6893 cancel_work_sync(&adapter->watchdog_task);
6894 cancel_work_sync(&adapter->downshift_task);
6895 cancel_work_sync(&adapter->update_phy_task);
6896 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006897
Bruce Allanb67e1912012-12-27 08:32:33 +00006898 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6899 cancel_work_sync(&adapter->tx_hwtstamp_work);
6900 if (adapter->tx_hwtstamp_skb) {
6901 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6902 adapter->tx_hwtstamp_skb = NULL;
6903 }
6904 }
6905
Bruce Allan17f208d2009-12-01 15:47:22 +00006906 if (!(netdev->flags & IFF_UP))
6907 e1000_power_down_phy(adapter);
6908
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006909 /* Don't lie to e1000_close() down the road. */
6910 if (!down)
6911 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006912 unregister_netdev(netdev);
6913
Alan Sternf3ec4f82010-06-08 15:23:51 -04006914 if (pci_dev_run_wake(pdev))
6915 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006916
Bruce Allane921eb12012-11-28 09:28:37 +00006917 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006918 * would have already happened in close and is redundant.
6919 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006920 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006921
Bruce Allan4662e822008-08-26 18:37:06 -07006922 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006923 kfree(adapter->tx_ring);
6924 kfree(adapter->rx_ring);
6925
6926 iounmap(adapter->hw.hw_addr);
6927 if (adapter->hw.flash_address)
6928 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006929 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006930 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006931
6932 free_netdev(netdev);
6933
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006934 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006935 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006936
Auke Kokbc7f75f2007-09-17 12:30:59 -07006937 pci_disable_device(pdev);
6938}
6939
6940/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006941static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006942 .error_detected = e1000_io_error_detected,
6943 .slot_reset = e1000_io_slot_reset,
6944 .resume = e1000_io_resume,
6945};
6946
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006947static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00006951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
6952 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006958
Auke Kokbc7f75f2007-09-17 12:30:59 -07006959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006963
Auke Kokbc7f75f2007-09-17 12:30:59 -07006964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006967
Bruce Allan4662e822008-08-26 18:37:06 -07006968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006971
Auke Kokbc7f75f2007-09-17 12:30:59 -07006972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6973 board_80003es2lan },
6974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6975 board_80003es2lan },
6976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6977 board_80003es2lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6979 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006980
Auke Kokbc7f75f2007-09-17 12:30:59 -07006981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6984 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006989
Auke Kokbc7f75f2007-09-17 12:30:59 -07006990 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6992 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6993 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6998 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6999
7000 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
7001 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
7002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007003
Bruce Allanf4187b52008-08-26 18:36:50 -07007004 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
7005 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00007006 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07007007
Bruce Allana4f58f52009-06-02 11:29:18 +00007008 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7009 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7010 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7011 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7012
Bruce Alland3738bb2010-06-16 13:27:28 +00007013 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7014 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7015
Bruce Allan2fbe4522012-04-19 03:21:47 +00007016 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7017 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007018 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7019 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan91a3d822013-06-29 01:15:16 +00007020 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
7021 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
7022 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
7023 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007024
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007025 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007026};
7027MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7028
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007029static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007030 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
Bruce Allan17e813e2013-02-20 04:06:01 +00007031 SET_RUNTIME_PM_OPS(e1000_runtime_suspend, e1000_runtime_resume,
7032 e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007033};
7034
Auke Kokbc7f75f2007-09-17 12:30:59 -07007035/* PCI Device API Driver */
7036static struct pci_driver e1000_driver = {
7037 .name = e1000e_driver_name,
7038 .id_table = e1000_pci_tbl,
7039 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007040 .remove = e1000_remove,
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007041 .driver = {
7042 .pm = &e1000_pm_ops,
7043 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007044 .shutdown = e1000_shutdown,
7045 .err_handler = &e1000_err_handler
7046};
7047
7048/**
7049 * e1000_init_module - Driver Registration Routine
7050 *
7051 * e1000_init_module is the first routine called when the driver is
7052 * loaded. All it does is register with the PCI subsystem.
7053 **/
7054static int __init e1000_init_module(void)
7055{
7056 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007057 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7058 e1000e_driver_version);
David Ertmane78b80b2014-02-04 01:56:06 +00007059 pr_info("Copyright(c) 1999 - 2014 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007060 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007061
Auke Kokbc7f75f2007-09-17 12:30:59 -07007062 return ret;
7063}
7064module_init(e1000_init_module);
7065
7066/**
7067 * e1000_exit_module - Driver Exit Cleanup Routine
7068 *
7069 * e1000_exit_module is called just before the driver is removed
7070 * from memory.
7071 **/
7072static void __exit e1000_exit_module(void)
7073{
7074 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007075}
7076module_exit(e1000_exit_module);
7077
Auke Kokbc7f75f2007-09-17 12:30:59 -07007078MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7079MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7080MODULE_LICENSE("GPL");
7081MODULE_VERSION(DRV_VERSION);
7082
Bruce Allan06c24b92012-02-23 03:13:13 +00007083/* netdev.c */