blob: 0459fe3a06bde9d47d2c1aa89639b9beb4bc273c [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070045#include <linux/ethtool.h>
46#include <linux/if_vlan.h>
47#include <linux/cpu.h>
48#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020049#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000050#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000051#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040052#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070053
54#include "e1000.h"
55
Bruce Allanb3ccf262011-05-19 01:53:41 +000056#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000057
Bruce Allan9e019902013-01-12 07:28:54 +000058#define DRV_VERSION "2.2.14" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070059char e1000e_driver_name[] = "e1000e";
60const char e1000e_driver_version[] = DRV_VERSION;
61
stephen hemmingerb3f4d592012-03-13 06:04:20 +000062#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
63static int debug = -1;
64module_param(debug, int, 0);
65MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
66
Bruce Allan78cd29d2011-03-24 03:09:03 +000067static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
68
Auke Kokbc7f75f2007-09-17 12:30:59 -070069static const struct e1000_info *e1000_info_tbl[] = {
70 [board_82571] = &e1000_82571_info,
71 [board_82572] = &e1000_82572_info,
72 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070073 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000074 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070075 [board_80003es2lan] = &e1000_es2_info,
76 [board_ich8lan] = &e1000_ich8_info,
77 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070078 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000079 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000080 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000081 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070082};
83
Taku Izumi84f4ee92010-04-27 14:39:08 +000084struct e1000_reg_info {
85 u32 ofs;
86 char *name;
87};
88
Taku Izumi84f4ee92010-04-27 14:39:08 +000089static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000090 /* General Registers */
91 {E1000_CTRL, "CTRL"},
92 {E1000_STATUS, "STATUS"},
93 {E1000_CTRL_EXT, "CTRL_EXT"},
94
95 /* Interrupt Registers */
96 {E1000_ICR, "ICR"},
97
Bruce Allanaf667a22010-12-31 06:10:01 +000098 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000099 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000100 {E1000_RDLEN(0), "RDLEN"},
101 {E1000_RDH(0), "RDH"},
102 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000103 {E1000_RDTR, "RDTR"},
104 {E1000_RXDCTL(0), "RXDCTL"},
105 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000106 {E1000_RDBAL(0), "RDBAL"},
107 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000108 {E1000_RDFH, "RDFH"},
109 {E1000_RDFT, "RDFT"},
110 {E1000_RDFHS, "RDFHS"},
111 {E1000_RDFTS, "RDFTS"},
112 {E1000_RDFPC, "RDFPC"},
113
Bruce Allanaf667a22010-12-31 06:10:01 +0000114 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000115 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000116 {E1000_TDBAL(0), "TDBAL"},
117 {E1000_TDBAH(0), "TDBAH"},
118 {E1000_TDLEN(0), "TDLEN"},
119 {E1000_TDH(0), "TDH"},
120 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000121 {E1000_TIDV, "TIDV"},
122 {E1000_TXDCTL(0), "TXDCTL"},
123 {E1000_TADV, "TADV"},
124 {E1000_TARC(0), "TARC"},
125 {E1000_TDFH, "TDFH"},
126 {E1000_TDFT, "TDFT"},
127 {E1000_TDFHS, "TDFHS"},
128 {E1000_TDFTS, "TDFTS"},
129 {E1000_TDFPC, "TDFPC"},
130
131 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000132 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000133};
134
Bruce Allane921eb12012-11-28 09:28:37 +0000135/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000136 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000137 * @hw: pointer to the HW structure
138 * @reginfo: pointer to the register info table
139 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000140static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
141{
142 int n = 0;
143 char rname[16];
144 u32 regs[8];
145
146 switch (reginfo->ofs) {
147 case E1000_RXDCTL(0):
148 for (n = 0; n < 2; n++)
149 regs[n] = __er32(hw, E1000_RXDCTL(n));
150 break;
151 case E1000_TXDCTL(0):
152 for (n = 0; n < 2; n++)
153 regs[n] = __er32(hw, E1000_TXDCTL(n));
154 break;
155 case E1000_TARC(0):
156 for (n = 0; n < 2; n++)
157 regs[n] = __er32(hw, E1000_TARC(n));
158 break;
159 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000160 pr_info("%-15s %08x\n",
161 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000162 return;
163 }
164
165 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000166 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000167}
168
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000169static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
170 struct e1000_buffer *bi)
171{
172 int i;
173 struct e1000_ps_page *ps_page;
174
175 for (i = 0; i < adapter->rx_ps_pages; i++) {
176 ps_page = &bi->ps_pages[i];
177
178 if (ps_page->page) {
179 pr_info("packet dump for ps_page %d:\n", i);
180 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
181 16, 1, page_address(ps_page->page),
182 PAGE_SIZE, true);
183 }
184 }
185}
186
Bruce Allane921eb12012-11-28 09:28:37 +0000187/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000188 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000189 * @adapter: board private structure
190 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000191static void e1000e_dump(struct e1000_adapter *adapter)
192{
193 struct net_device *netdev = adapter->netdev;
194 struct e1000_hw *hw = &adapter->hw;
195 struct e1000_reg_info *reginfo;
196 struct e1000_ring *tx_ring = adapter->tx_ring;
197 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000198 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000199 __le64 a;
200 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000201 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000202 struct e1000_buffer *buffer_info;
203 struct e1000_ring *rx_ring = adapter->rx_ring;
204 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000205 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000206 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000207 __le64 a;
208 __le64 b;
209 __le64 c;
210 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000211 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 u32 staterr;
213 int i = 0;
214
215 if (!netif_msg_hw(adapter))
216 return;
217
218 /* Print netdevice Info */
219 if (netdev) {
220 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000221 pr_info("Device Name state trans_start last_rx\n");
Bruce Allane5fe2542013-02-20 04:06:27 +0000222 pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
223 netdev->state, netdev->trans_start, netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000224 }
225
226 /* Print Registers */
227 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000228 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000229 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
230 reginfo->name; reginfo++) {
231 e1000_regdump(hw, reginfo);
232 }
233
Bruce Allanaf667a22010-12-31 06:10:01 +0000234 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000235 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000236 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000237
Bruce Allanaf667a22010-12-31 06:10:01 +0000238 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000239 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000240 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000241 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
242 0, tx_ring->next_to_use, tx_ring->next_to_clean,
243 (unsigned long long)buffer_info->dma,
244 buffer_info->length,
245 buffer_info->next_to_watch,
246 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000247
Bruce Allanaf667a22010-12-31 06:10:01 +0000248 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000249 if (!netif_msg_tx_done(adapter))
250 goto rx_ring_summary;
251
Bruce Allanaf667a22010-12-31 06:10:01 +0000252 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000253
254 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
255 *
256 * Legacy Transmit Descriptor
257 * +--------------------------------------------------------------+
258 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
259 * +--------------------------------------------------------------+
260 * 8 | Special | CSS | Status | CMD | CSO | Length |
261 * +--------------------------------------------------------------+
262 * 63 48 47 36 35 32 31 24 23 16 15 0
263 *
264 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
265 * 63 48 47 40 39 32 31 16 15 8 7 0
266 * +----------------------------------------------------------------+
267 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
268 * +----------------------------------------------------------------+
269 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
270 * +----------------------------------------------------------------+
271 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
272 *
273 * Extended Data Descriptor (DTYP=0x1)
274 * +----------------------------------------------------------------+
275 * 0 | Buffer Address [63:0] |
276 * +----------------------------------------------------------------+
277 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
278 * +----------------------------------------------------------------+
279 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
280 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000281 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
282 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
283 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 +0000284 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000285 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000286 tx_desc = E1000_TX_DESC(*tx_ring, i);
287 buffer_info = &tx_ring->buffer_info[i];
288 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000289 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000290 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000291 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000292 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000293 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000294 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000295 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000296 next_desc = "";
297 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
298 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
299 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
300 i,
301 (unsigned long long)le64_to_cpu(u0->a),
302 (unsigned long long)le64_to_cpu(u0->b),
303 (unsigned long long)buffer_info->dma,
304 buffer_info->length, buffer_info->next_to_watch,
305 (unsigned long long)buffer_info->time_stamp,
306 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000307
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000308 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000310 16, 1, buffer_info->skb->data,
311 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000312 }
313
Bruce Allanaf667a22010-12-31 06:10:01 +0000314 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000315rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000316 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000317 pr_info("Queue [NTU] [NTC]\n");
318 pr_info(" %5d %5X %5X\n",
319 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000320
Bruce Allanaf667a22010-12-31 06:10:01 +0000321 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000322 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000323 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324
Bruce Allanaf667a22010-12-31 06:10:01 +0000325 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000326 switch (adapter->rx_ps_pages) {
327 case 1:
328 case 2:
329 case 3:
330 /* [Extended] Packet Split Receive Descriptor Format
331 *
332 * +-----------------------------------------------------+
333 * 0 | Buffer Address 0 [63:0] |
334 * +-----------------------------------------------------+
335 * 8 | Buffer Address 1 [63:0] |
336 * +-----------------------------------------------------+
337 * 16 | Buffer Address 2 [63:0] |
338 * +-----------------------------------------------------+
339 * 24 | Buffer Address 3 [63:0] |
340 * +-----------------------------------------------------+
341 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000342 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 +0000343 /* [Extended] Receive Descriptor (Write-Back) Format
344 *
345 * 63 48 47 32 31 13 12 8 7 4 3 0
346 * +------------------------------------------------------+
347 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
348 * | Checksum | Ident | | Queue | | Type |
349 * +------------------------------------------------------+
350 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
351 * +------------------------------------------------------+
352 * 63 48 47 32 31 20 19 0
353 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000354 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 +0000355 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000356 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000357 buffer_info = &rx_ring->buffer_info[i];
358 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
359 u1 = (struct my_u1 *)rx_desc_ps;
360 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000361 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000362
363 if (i == rx_ring->next_to_use)
364 next_desc = " NTU";
365 else if (i == rx_ring->next_to_clean)
366 next_desc = " NTC";
367 else
368 next_desc = "";
369
Taku Izumi84f4ee92010-04-27 14:39:08 +0000370 if (staterr & E1000_RXD_STAT_DD) {
371 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000372 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
373 "RWB", i,
374 (unsigned long long)le64_to_cpu(u1->a),
375 (unsigned long long)le64_to_cpu(u1->b),
376 (unsigned long long)le64_to_cpu(u1->c),
377 (unsigned long long)le64_to_cpu(u1->d),
378 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000379 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000380 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
381 "R ", i,
382 (unsigned long long)le64_to_cpu(u1->a),
383 (unsigned long long)le64_to_cpu(u1->b),
384 (unsigned long long)le64_to_cpu(u1->c),
385 (unsigned long long)le64_to_cpu(u1->d),
386 (unsigned long long)buffer_info->dma,
387 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000388
389 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000390 e1000e_dump_ps_pages(adapter,
391 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000392 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000393 }
394 break;
395 default:
396 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000397 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000398 *
Bruce Allan5f450212011-07-22 06:21:46 +0000399 * +-----------------------------------------------------+
400 * 0 | Buffer Address [63:0] |
401 * +-----------------------------------------------------+
402 * 8 | Reserved |
403 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000404 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000405 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 +0000406 /* Extended Receive Descriptor (Write-Back) Format
407 *
408 * 63 48 47 32 31 24 23 4 3 0
409 * +------------------------------------------------------+
410 * | RSS Hash | | | |
411 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
412 * | Packet | IP | | | Type |
413 * | Checksum | Ident | | | |
414 * +------------------------------------------------------+
415 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
416 * +------------------------------------------------------+
417 * 63 48 47 32 31 20 19 0
418 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000419 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 +0000420
421 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000422 const char *next_desc;
423
Taku Izumi84f4ee92010-04-27 14:39:08 +0000424 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000425 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
426 u1 = (struct my_u1 *)rx_desc;
427 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000428
429 if (i == rx_ring->next_to_use)
430 next_desc = " NTU";
431 else if (i == rx_ring->next_to_clean)
432 next_desc = " NTC";
433 else
434 next_desc = "";
435
Bruce Allan5f450212011-07-22 06:21:46 +0000436 if (staterr & E1000_RXD_STAT_DD) {
437 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000438 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
439 "RWB", i,
440 (unsigned long long)le64_to_cpu(u1->a),
441 (unsigned long long)le64_to_cpu(u1->b),
442 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000443 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000444 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
445 "R ", i,
446 (unsigned long long)le64_to_cpu(u1->a),
447 (unsigned long long)le64_to_cpu(u1->b),
448 (unsigned long long)buffer_info->dma,
449 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000450
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000451 if (netif_msg_pktdata(adapter) &&
452 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000453 print_hex_dump(KERN_INFO, "",
454 DUMP_PREFIX_ADDRESS, 16,
455 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000456 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000457 adapter->rx_buffer_len,
458 true);
459 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000460 }
461 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000462}
463
Auke Kokbc7f75f2007-09-17 12:30:59 -0700464/**
465 * e1000_desc_unused - calculate if we have unused descriptors
466 **/
467static int e1000_desc_unused(struct e1000_ring *ring)
468{
469 if (ring->next_to_clean > ring->next_to_use)
470 return ring->next_to_clean - ring->next_to_use - 1;
471
472 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
473}
474
475/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000476 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
477 * @adapter: board private structure
478 * @hwtstamps: time stamp structure to update
479 * @systim: unsigned 64bit system time value.
480 *
481 * Convert the system time value stored in the RX/TXSTMP registers into a
482 * hwtstamp which can be used by the upper level time stamping functions.
483 *
484 * The 'systim_lock' spinlock is used to protect the consistency of the
485 * system time value. This is needed because reading the 64 bit time
486 * value involves reading two 32 bit registers. The first read latches the
487 * value.
488 **/
489static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
490 struct skb_shared_hwtstamps *hwtstamps,
491 u64 systim)
492{
493 u64 ns;
494 unsigned long flags;
495
496 spin_lock_irqsave(&adapter->systim_lock, flags);
497 ns = timecounter_cyc2time(&adapter->tc, systim);
498 spin_unlock_irqrestore(&adapter->systim_lock, flags);
499
500 memset(hwtstamps, 0, sizeof(*hwtstamps));
501 hwtstamps->hwtstamp = ns_to_ktime(ns);
502}
503
504/**
505 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
506 * @adapter: board private structure
507 * @status: descriptor extended error and status field
508 * @skb: particular skb to include time stamp
509 *
510 * If the time stamp is valid, convert it into the timecounter ns value
511 * and store that result into the shhwtstamps structure which is passed
512 * up the network stack.
513 **/
514static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
515 struct sk_buff *skb)
516{
517 struct e1000_hw *hw = &adapter->hw;
518 u64 rxstmp;
519
520 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
521 !(status & E1000_RXDEXT_STATERR_TST) ||
522 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
523 return;
524
525 /* The Rx time stamp registers contain the time stamp. No other
526 * received packet will be time stamped until the Rx time stamp
527 * registers are read. Because only one packet can be time stamped
528 * at a time, the register values must belong to this packet and
529 * therefore none of the other additional attributes need to be
530 * compared.
531 */
532 rxstmp = (u64)er32(RXSTMPL);
533 rxstmp |= (u64)er32(RXSTMPH) << 32;
534 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
535
536 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
537}
538
539/**
Bruce Allanad680762008-03-28 09:15:03 -0700540 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700541 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000542 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700543 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
544 * @skb: pointer to sk_buff to be indicated to stack
545 **/
546static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000547 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000548 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700549{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000550 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000551
552 e1000e_rx_hwtstamp(adapter, staterr, skb);
553
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554 skb->protocol = eth_type_trans(skb, netdev);
555
Bruce Allanb67e1912012-12-27 08:32:33 +0000556 if (staterr & E1000_RXD_STAT_VP)
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000557 __vlan_hwaccel_put_tag(skb, tag);
558
559 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700560}
561
562/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000563 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000564 * @adapter: board private structure
565 * @status_err: receive descriptor status and error fields
566 * @csum: receive descriptor csum field
567 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700568 **/
569static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000570 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700571{
572 u16 status = (u16)status_err;
573 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700574
575 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700576
Bruce Allanafd12932012-01-05 00:34:05 +0000577 /* Rx checksum disabled */
578 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
579 return;
580
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581 /* Ignore Checksum bit is set */
582 if (status & E1000_RXD_STAT_IXSM)
583 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000584
Bruce Allan2e1706f2012-06-30 20:02:42 +0000585 /* TCP/UDP checksum error bit or IP checksum error bit is set */
586 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587 /* let the stack verify checksum errors */
588 adapter->hw_csum_err++;
589 return;
590 }
591
592 /* TCP/UDP Checksum has not been calculated */
593 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
594 return;
595
596 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000597 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700598 adapter->hw_csum_good++;
599}
600
Bruce Allan55aa6982011-12-16 00:45:45 +0000601static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700602{
Bruce Allan55aa6982011-12-16 00:45:45 +0000603 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700604 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000605 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700606
Bruce Allanbdc125f2012-03-20 03:47:52 +0000607 writel(i, rx_ring->tail);
608
609 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700610 u32 rctl = er32(RCTL);
611 ew32(RCTL, rctl & ~E1000_RCTL_EN);
612 e_err("ME firmware caused invalid RDT - resetting\n");
613 schedule_work(&adapter->reset_task);
614 }
615}
616
Bruce Allan55aa6982011-12-16 00:45:45 +0000617static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700618{
Bruce Allan55aa6982011-12-16 00:45:45 +0000619 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700620 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000621 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700622
Bruce Allanbdc125f2012-03-20 03:47:52 +0000623 writel(i, tx_ring->tail);
624
625 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700626 u32 tctl = er32(TCTL);
627 ew32(TCTL, tctl & ~E1000_TCTL_EN);
628 e_err("ME firmware caused invalid TDT - resetting\n");
629 schedule_work(&adapter->reset_task);
630 }
631}
632
633/**
Bruce Allan5f450212011-07-22 06:21:46 +0000634 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000635 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700636 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000637static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000638 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639{
Bruce Allan55aa6982011-12-16 00:45:45 +0000640 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 struct net_device *netdev = adapter->netdev;
642 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000643 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 struct e1000_buffer *buffer_info;
645 struct sk_buff *skb;
646 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000647 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648
649 i = rx_ring->next_to_use;
650 buffer_info = &rx_ring->buffer_info[i];
651
652 while (cleaned_count--) {
653 skb = buffer_info->skb;
654 if (skb) {
655 skb_trim(skb, 0);
656 goto map_skb;
657 }
658
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000659 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 if (!skb) {
661 /* Better luck next round */
662 adapter->alloc_rx_buff_failed++;
663 break;
664 }
665
Auke Kokbc7f75f2007-09-17 12:30:59 -0700666 buffer_info->skb = skb;
667map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000668 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700669 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000670 DMA_FROM_DEVICE);
671 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000672 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673 adapter->rx_dma_failed++;
674 break;
675 }
676
Bruce Allan5f450212011-07-22 06:21:46 +0000677 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
678 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700679
Tom Herbert50849d72010-05-05 14:02:49 +0000680 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000681 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000682 * know there are new descriptors to fetch. (Only
683 * applicable for weak-ordered memory model archs,
684 * such as IA-64).
685 */
686 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700687 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000688 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700689 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000690 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000691 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692 i++;
693 if (i == rx_ring->count)
694 i = 0;
695 buffer_info = &rx_ring->buffer_info[i];
696 }
697
Tom Herbert50849d72010-05-05 14:02:49 +0000698 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699}
700
701/**
702 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000703 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000705static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000706 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707{
Bruce Allan55aa6982011-12-16 00:45:45 +0000708 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700709 struct net_device *netdev = adapter->netdev;
710 struct pci_dev *pdev = adapter->pdev;
711 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700712 struct e1000_buffer *buffer_info;
713 struct e1000_ps_page *ps_page;
714 struct sk_buff *skb;
715 unsigned int i, j;
716
717 i = rx_ring->next_to_use;
718 buffer_info = &rx_ring->buffer_info[i];
719
720 while (cleaned_count--) {
721 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
722
723 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700724 ps_page = &buffer_info->ps_pages[j];
725 if (j >= adapter->rx_ps_pages) {
726 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000727 rx_desc->read.buffer_addr[j + 1] =
728 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700729 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700730 }
Auke Kok47f44e42007-10-25 13:57:44 -0700731 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000732 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700733 if (!ps_page->page) {
734 adapter->alloc_rx_buff_failed++;
735 goto no_buffers;
736 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000737 ps_page->dma = dma_map_page(&pdev->dev,
738 ps_page->page,
739 0, PAGE_SIZE,
740 DMA_FROM_DEVICE);
741 if (dma_mapping_error(&pdev->dev,
742 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700743 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000744 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700745 adapter->rx_dma_failed++;
746 goto no_buffers;
747 }
748 }
Bruce Allane921eb12012-11-28 09:28:37 +0000749 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700750 * didn't change because each write-back
751 * erases this info.
752 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000753 rx_desc->read.buffer_addr[j + 1] =
754 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700755 }
756
Bruce Allane5fe2542013-02-20 04:06:27 +0000757 skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000758 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759
760 if (!skb) {
761 adapter->alloc_rx_buff_failed++;
762 break;
763 }
764
Auke Kokbc7f75f2007-09-17 12:30:59 -0700765 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000766 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000768 DMA_FROM_DEVICE);
769 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000770 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 adapter->rx_dma_failed++;
772 /* cleanup skb */
773 dev_kfree_skb_any(skb);
774 buffer_info->skb = NULL;
775 break;
776 }
777
778 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
779
Tom Herbert50849d72010-05-05 14:02:49 +0000780 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000781 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000782 * know there are new descriptors to fetch. (Only
783 * applicable for weak-ordered memory model archs,
784 * such as IA-64).
785 */
786 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700787 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000788 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700789 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000790 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000791 }
792
Auke Kokbc7f75f2007-09-17 12:30:59 -0700793 i++;
794 if (i == rx_ring->count)
795 i = 0;
796 buffer_info = &rx_ring->buffer_info[i];
797 }
798
799no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000800 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801}
802
803/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700804 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000805 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700806 * @cleaned_count: number of buffers to allocate this pass
807 **/
808
Bruce Allan55aa6982011-12-16 00:45:45 +0000809static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000810 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700811{
Bruce Allan55aa6982011-12-16 00:45:45 +0000812 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700813 struct net_device *netdev = adapter->netdev;
814 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000815 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700816 struct e1000_buffer *buffer_info;
817 struct sk_buff *skb;
818 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000819 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700820
821 i = rx_ring->next_to_use;
822 buffer_info = &rx_ring->buffer_info[i];
823
824 while (cleaned_count--) {
825 skb = buffer_info->skb;
826 if (skb) {
827 skb_trim(skb, 0);
828 goto check_page;
829 }
830
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000831 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700832 if (unlikely(!skb)) {
833 /* Better luck next round */
834 adapter->alloc_rx_buff_failed++;
835 break;
836 }
837
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700838 buffer_info->skb = skb;
839check_page:
840 /* allocate a new page if necessary */
841 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000842 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700843 if (unlikely(!buffer_info->page)) {
844 adapter->alloc_rx_buff_failed++;
845 break;
846 }
847 }
848
849 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000850 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000851 buffer_info->page, 0,
852 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000853 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700854
Bruce Allan5f450212011-07-22 06:21:46 +0000855 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
856 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700857
858 if (unlikely(++i == rx_ring->count))
859 i = 0;
860 buffer_info = &rx_ring->buffer_info[i];
861 }
862
863 if (likely(rx_ring->next_to_use != i)) {
864 rx_ring->next_to_use = i;
865 if (unlikely(i-- == 0))
866 i = (rx_ring->count - 1);
867
868 /* Force memory writes to complete before letting h/w
869 * know there are new descriptors to fetch. (Only
870 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000871 * such as IA-64).
872 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700873 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700874 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000875 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700876 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000877 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700878 }
879}
880
Bruce Allan70495a52012-01-11 01:26:50 +0000881static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
882 struct sk_buff *skb)
883{
884 if (netdev->features & NETIF_F_RXHASH)
885 skb->rxhash = le32_to_cpu(rss);
886}
887
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700888/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000889 * e1000_clean_rx_irq - Send received data up the network stack
890 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700891 *
892 * the return value indicates whether actual cleaning was done, there
893 * is no guarantee that everything was cleaned
894 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000895static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
896 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700897{
Bruce Allan55aa6982011-12-16 00:45:45 +0000898 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 struct net_device *netdev = adapter->netdev;
900 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000901 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000902 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000904 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 unsigned int i;
906 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000907 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
909
910 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000911 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
912 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 buffer_info = &rx_ring->buffer_info[i];
914
Bruce Allan5f450212011-07-22 06:21:46 +0000915 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700917
918 if (*work_done >= work_to_do)
919 break;
920 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000921 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922
Auke Kokbc7f75f2007-09-17 12:30:59 -0700923 skb = buffer_info->skb;
924 buffer_info->skb = NULL;
925
926 prefetch(skb->data - NET_IP_ALIGN);
927
928 i++;
929 if (i == rx_ring->count)
930 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000931 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 prefetch(next_rxd);
933
934 next_buffer = &rx_ring->buffer_info[i];
935
Rusty Russell3db1cd52011-12-19 13:56:45 +0000936 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937 cleaned_count++;
Bruce Allane5fe2542013-02-20 04:06:27 +0000938 dma_unmap_single(&pdev->dev, buffer_info->dma,
939 adapter->rx_buffer_len, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 buffer_info->dma = 0;
941
Bruce Allan5f450212011-07-22 06:21:46 +0000942 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943
Bruce Allane921eb12012-11-28 09:28:37 +0000944 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000945 * packet, if that's the case we need to toss it. In fact, we
946 * need to toss every packet with the EOP bit clear and the
947 * next frame that _does_ have the EOP bit set, as it is by
948 * definition only a frame fragment
949 */
Bruce Allan5f450212011-07-22 06:21:46 +0000950 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000951 adapter->flags2 |= FLAG2_IS_DISCARDING;
952
953 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000955 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700956 /* recycle */
957 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000958 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000959 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960 goto next_desc;
961 }
962
Ben Greearcf955e62012-02-11 15:39:51 +0000963 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
964 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965 /* recycle */
966 buffer_info->skb = skb;
967 goto next_desc;
968 }
969
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000970 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000971 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
972 /* If configured to store CRC, don't subtract FCS,
973 * but keep the FCS bytes out of the total_rx_bytes
974 * counter
975 */
976 if (netdev->features & NETIF_F_RXFCS)
977 total_rx_bytes -= 4;
978 else
979 length -= 4;
980 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000981
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 total_rx_bytes += length;
983 total_rx_packets++;
984
Bruce Allane921eb12012-11-28 09:28:37 +0000985 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700987 * of reassembly being done in the stack
988 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989 if (length < copybreak) {
990 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000991 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700992 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700993 skb_copy_to_linear_data_offset(new_skb,
994 -NET_IP_ALIGN,
995 (skb->data -
996 NET_IP_ALIGN),
997 (length +
998 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 /* save the skb in buffer_info as good */
1000 buffer_info->skb = skb;
1001 skb = new_skb;
1002 }
1003 /* else just continue with the old one */
1004 }
1005 /* end copybreak code */
1006 skb_put(skb, length);
1007
1008 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001009 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010
Bruce Allan70495a52012-01-11 01:26:50 +00001011 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1012
Bruce Allan5f450212011-07-22 06:21:46 +00001013 e1000_receive_skb(adapter, netdev, skb, staterr,
1014 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001015
1016next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001017 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018
1019 /* return some buffers to hardware, one at a time is too slow */
1020 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001021 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001022 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 cleaned_count = 0;
1024 }
1025
1026 /* use prefetched values */
1027 rx_desc = next_rxd;
1028 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001029
1030 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031 }
1032 rx_ring->next_to_clean = i;
1033
1034 cleaned_count = e1000_desc_unused(rx_ring);
1035 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001036 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001039 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 return cleaned;
1041}
1042
Bruce Allan55aa6982011-12-16 00:45:45 +00001043static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1044 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001045{
Bruce Allan55aa6982011-12-16 00:45:45 +00001046 struct e1000_adapter *adapter = tx_ring->adapter;
1047
Alexander Duyck03b13202009-12-02 16:45:31 +00001048 if (buffer_info->dma) {
1049 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001050 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1051 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001052 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001053 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1054 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001055 buffer_info->dma = 0;
1056 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 if (buffer_info->skb) {
1058 dev_kfree_skb_any(buffer_info->skb);
1059 buffer_info->skb = NULL;
1060 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001061 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062}
1063
Bruce Allan41cec6f2009-11-20 23:28:56 +00001064static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001066 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001067 struct e1000_adapter,
1068 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001069 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001070 struct e1000_ring *tx_ring = adapter->tx_ring;
1071 unsigned int i = tx_ring->next_to_clean;
1072 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1073 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001074 struct e1000_hw *hw = &adapter->hw;
1075 u16 phy_status, phy_1000t_status, phy_ext_status;
1076 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001077
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001078 if (test_bit(__E1000_DOWN, &adapter->state))
1079 return;
1080
Bruce Allane5fe2542013-02-20 04:06:27 +00001081 if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001082 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001083 * flush pending descriptor writebacks to memory
1084 */
1085 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1086 /* execute the writes immediately */
1087 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001088 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001089 * the write is successful
1090 */
1091 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1092 /* execute the writes immediately */
1093 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001094 adapter->tx_hang_recheck = true;
1095 return;
1096 }
1097 /* Real hang detected */
1098 adapter->tx_hang_recheck = false;
1099 netif_stop_queue(netdev);
1100
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001101 e1e_rphy(hw, MII_BMSR, &phy_status);
1102 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1103 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001104
1105 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1106
1107 /* detected Hardware unit hang */
1108 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001109 " TDH <%x>\n"
1110 " TDT <%x>\n"
1111 " next_to_use <%x>\n"
1112 " next_to_clean <%x>\n"
1113 "buffer_info[next_to_clean]:\n"
1114 " time_stamp <%lx>\n"
1115 " next_to_watch <%x>\n"
1116 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001117 " next_to_watch.status <%x>\n"
1118 "MAC Status <%x>\n"
1119 "PHY Status <%x>\n"
1120 "PHY 1000BASE-T Status <%x>\n"
1121 "PHY Extended Status <%x>\n"
1122 "PCI Status <%x>\n",
Bruce Allane5fe2542013-02-20 04:06:27 +00001123 readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
1124 tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
1125 eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
1126 phy_status, phy_1000t_status, phy_ext_status, pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001127
1128 /* Suggest workaround for known h/w issue */
1129 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1130 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131}
1132
1133/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001134 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1135 * @work: pointer to work struct
1136 *
1137 * This work function polls the TSYNCTXCTL valid bit to determine when a
1138 * timestamp has been taken for the current stored skb. The timestamp must
1139 * be for this skb because only one such packet is allowed in the queue.
1140 */
1141static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1142{
1143 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1144 tx_hwtstamp_work);
1145 struct e1000_hw *hw = &adapter->hw;
1146
1147 if (!adapter->tx_hwtstamp_skb)
1148 return;
1149
1150 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1151 struct skb_shared_hwtstamps shhwtstamps;
1152 u64 txstmp;
1153
1154 txstmp = er32(TXSTMPL);
1155 txstmp |= (u64)er32(TXSTMPH) << 32;
1156
1157 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1158
1159 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1160 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1161 adapter->tx_hwtstamp_skb = NULL;
1162 } else {
1163 /* reschedule to check later */
1164 schedule_work(&adapter->tx_hwtstamp_work);
1165 }
1166}
1167
1168/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001170 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 *
1172 * the return value indicates whether actual cleaning was done, there
1173 * is no guarantee that everything was cleaned
1174 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001175static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176{
Bruce Allan55aa6982011-12-16 00:45:45 +00001177 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 struct net_device *netdev = adapter->netdev;
1179 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 struct e1000_tx_desc *tx_desc, *eop_desc;
1181 struct e1000_buffer *buffer_info;
1182 unsigned int i, eop;
1183 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001185 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186
1187 i = tx_ring->next_to_clean;
1188 eop = tx_ring->buffer_info[i].next_to_watch;
1189 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1190
Alexander Duyck12d04a32009-03-25 22:05:03 +00001191 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1192 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001193 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001194 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001195 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 tx_desc = E1000_TX_DESC(*tx_ring, i);
1197 buffer_info = &tx_ring->buffer_info[i];
1198 cleaned = (i == eop);
1199
1200 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001201 total_tx_packets += buffer_info->segs;
1202 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001203 if (buffer_info->skb) {
1204 bytes_compl += buffer_info->skb->len;
1205 pkts_compl++;
1206 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 }
1208
Bruce Allan55aa6982011-12-16 00:45:45 +00001209 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 tx_desc->upper.data = 0;
1211
1212 i++;
1213 if (i == tx_ring->count)
1214 i = 0;
1215 }
1216
Terry Loftindac87612010-04-09 10:29:49 +00001217 if (i == tx_ring->next_to_use)
1218 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219 eop = tx_ring->buffer_info[i].next_to_watch;
1220 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221 }
1222
1223 tx_ring->next_to_clean = i;
1224
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001225 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1226
Auke Kokbc7f75f2007-09-17 12:30:59 -07001227#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001228 if (count && netif_carrier_ok(netdev) &&
1229 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 /* Make sure that anybody stopping the queue after this
1231 * sees the new next_to_clean.
1232 */
1233 smp_mb();
1234
1235 if (netif_queue_stopped(netdev) &&
1236 !(test_bit(__E1000_DOWN, &adapter->state))) {
1237 netif_wake_queue(netdev);
1238 ++adapter->restart_queue;
1239 }
1240 }
1241
1242 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001243 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001244 * check with the clearing of time_stamp and movement of i
1245 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001246 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001247 if (tx_ring->buffer_info[i].time_stamp &&
1248 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001249 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001250 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001251 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001252 else
1253 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254 }
1255 adapter->total_tx_bytes += total_tx_bytes;
1256 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001257 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258}
1259
1260/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001262 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001263 *
1264 * the return value indicates whether actual cleaning was done, there
1265 * is no guarantee that everything was cleaned
1266 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001267static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1268 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001269{
Bruce Allan55aa6982011-12-16 00:45:45 +00001270 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001271 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1273 struct net_device *netdev = adapter->netdev;
1274 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 struct e1000_buffer *buffer_info, *next_buffer;
1276 struct e1000_ps_page *ps_page;
1277 struct sk_buff *skb;
1278 unsigned int i, j;
1279 u32 length, staterr;
1280 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001281 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1283
1284 i = rx_ring->next_to_clean;
1285 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1286 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1287 buffer_info = &rx_ring->buffer_info[i];
1288
1289 while (staterr & E1000_RXD_STAT_DD) {
1290 if (*work_done >= work_to_do)
1291 break;
1292 (*work_done)++;
1293 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001294 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295
1296 /* in the packet split case this is header only */
1297 prefetch(skb->data - NET_IP_ALIGN);
1298
1299 i++;
1300 if (i == rx_ring->count)
1301 i = 0;
1302 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1303 prefetch(next_rxd);
1304
1305 next_buffer = &rx_ring->buffer_info[i];
1306
Rusty Russell3db1cd52011-12-19 13:56:45 +00001307 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001308 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001309 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001310 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311 buffer_info->dma = 0;
1312
Bruce Allanaf667a22010-12-31 06:10:01 +00001313 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001314 if (!(staterr & E1000_RXD_STAT_EOP))
1315 adapter->flags2 |= FLAG2_IS_DISCARDING;
1316
1317 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001318 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001320 if (staterr & E1000_RXD_STAT_EOP)
1321 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 goto next_desc;
1323 }
1324
Ben Greearcf955e62012-02-11 15:39:51 +00001325 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1326 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001327 dev_kfree_skb_irq(skb);
1328 goto next_desc;
1329 }
1330
1331 length = le16_to_cpu(rx_desc->wb.middle.length0);
1332
1333 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001334 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335 dev_kfree_skb_irq(skb);
1336 goto next_desc;
1337 }
1338
1339 /* Good Receive */
1340 skb_put(skb, length);
1341
1342 {
Bruce Allane921eb12012-11-28 09:28:37 +00001343 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001344 * it more efficient than reusing j
1345 */
1346 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347
Bruce Allane921eb12012-11-28 09:28:37 +00001348 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001349 * packet throughput, so unsplit small packets and
1350 * save the alloc/put only valid in softirq (napi)
1351 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001352 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001353 if (l1 && (l1 <= copybreak) &&
1354 ((length + l1) <= adapter->rx_ps_bsize0)) {
1355 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001356
Bruce Allan0e15df42012-01-31 06:37:11 +00001357 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001358
Bruce Allane921eb12012-11-28 09:28:37 +00001359 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001360 * kmap_atomic, so we can't hold the mapping
1361 * very long
1362 */
1363 dma_sync_single_for_cpu(&pdev->dev,
1364 ps_page->dma,
1365 PAGE_SIZE,
1366 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001367 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001368 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001369 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001370 dma_sync_single_for_device(&pdev->dev,
1371 ps_page->dma,
1372 PAGE_SIZE,
1373 DMA_FROM_DEVICE);
1374
1375 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001376 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1377 if (!(netdev->features & NETIF_F_RXFCS))
1378 l1 -= 4;
1379 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001380
1381 skb_put(skb, l1);
1382 goto copydone;
1383 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001384 }
1385
1386 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1387 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1388 if (!length)
1389 break;
1390
Auke Kok47f44e42007-10-25 13:57:44 -07001391 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001392 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1393 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001394 ps_page->dma = 0;
1395 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1396 ps_page->page = NULL;
1397 skb->len += length;
1398 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001399 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001400 }
1401
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001402 /* strip the ethernet crc, problem is we're using pages now so
1403 * this whole operation can get a little cpu intensive
1404 */
Ben Greear01840392012-02-11 15:39:25 +00001405 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1406 if (!(netdev->features & NETIF_F_RXFCS))
1407 pskb_trim(skb, skb->len - 4);
1408 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001409
Auke Kokbc7f75f2007-09-17 12:30:59 -07001410copydone:
1411 total_rx_bytes += skb->len;
1412 total_rx_packets++;
1413
Bruce Allan2e1706f2012-06-30 20:02:42 +00001414 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001415
Bruce Allan70495a52012-01-11 01:26:50 +00001416 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1417
Auke Kokbc7f75f2007-09-17 12:30:59 -07001418 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001419 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001420 adapter->rx_hdr_split++;
1421
Bruce Allanb67e1912012-12-27 08:32:33 +00001422 e1000_receive_skb(adapter, netdev, skb, staterr,
1423 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001424
1425next_desc:
1426 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1427 buffer_info->skb = NULL;
1428
1429 /* return some buffers to hardware, one at a time is too slow */
1430 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001431 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001432 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001433 cleaned_count = 0;
1434 }
1435
1436 /* use prefetched values */
1437 rx_desc = next_rxd;
1438 buffer_info = next_buffer;
1439
1440 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1441 }
1442 rx_ring->next_to_clean = i;
1443
1444 cleaned_count = e1000_desc_unused(rx_ring);
1445 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001446 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447
Auke Kokbc7f75f2007-09-17 12:30:59 -07001448 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001449 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001450 return cleaned;
1451}
1452
1453/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001454 * e1000_consume_page - helper function
1455 **/
1456static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001457 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001458{
1459 bi->page = NULL;
1460 skb->len += length;
1461 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001462 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001463}
1464
1465/**
1466 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1467 * @adapter: board private structure
1468 *
1469 * the return value indicates whether actual cleaning was done, there
1470 * is no guarantee that everything was cleaned
1471 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001472static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1473 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001474{
Bruce Allan55aa6982011-12-16 00:45:45 +00001475 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001476 struct net_device *netdev = adapter->netdev;
1477 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001478 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001479 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001480 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001481 unsigned int i;
1482 int cleaned_count = 0;
1483 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001484 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001485 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001486
1487 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001488 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1489 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490 buffer_info = &rx_ring->buffer_info[i];
1491
Bruce Allan5f450212011-07-22 06:21:46 +00001492 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001493 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001494
1495 if (*work_done >= work_to_do)
1496 break;
1497 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001498 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001499
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001500 skb = buffer_info->skb;
1501 buffer_info->skb = NULL;
1502
1503 ++i;
1504 if (i == rx_ring->count)
1505 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001506 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001507 prefetch(next_rxd);
1508
1509 next_buffer = &rx_ring->buffer_info[i];
1510
1511 cleaned = true;
1512 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001513 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1514 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001515 buffer_info->dma = 0;
1516
Bruce Allan5f450212011-07-22 06:21:46 +00001517 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001518
1519 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001520 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001521 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1522 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001523 /* recycle both page and skb */
1524 buffer_info->skb = skb;
1525 /* an error means any chain goes out the window too */
1526 if (rx_ring->rx_skb_top)
1527 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1528 rx_ring->rx_skb_top = NULL;
1529 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001530 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001531#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001532 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001533 /* this descriptor is only the beginning (or middle) */
1534 if (!rxtop) {
1535 /* this is the beginning of a chain */
1536 rxtop = skb;
1537 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001538 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001539 } else {
1540 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001541 shinfo = skb_shinfo(rxtop);
1542 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1543 buffer_info->page, 0,
1544 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545 /* re-use the skb, only consumed the page */
1546 buffer_info->skb = skb;
1547 }
1548 e1000_consume_page(buffer_info, rxtop, length);
1549 goto next_desc;
1550 } else {
1551 if (rxtop) {
1552 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001553 shinfo = skb_shinfo(rxtop);
1554 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1555 buffer_info->page, 0,
1556 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001557 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001558 * page
1559 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001560 buffer_info->skb = skb;
1561 skb = rxtop;
1562 rxtop = NULL;
1563 e1000_consume_page(buffer_info, skb, length);
1564 } else {
1565 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001566 * copybreak to save the put_page/alloc_page
1567 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001568 if (length <= copybreak &&
1569 skb_tailroom(skb) >= length) {
1570 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001571 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001572 memcpy(skb_tail_pointer(skb), vaddr,
1573 length);
Cong Wang46790262011-11-25 23:14:23 +08001574 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001575 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001576 * buffer_info->page
1577 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001578 skb_put(skb, length);
1579 } else {
1580 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001581 buffer_info->page, 0,
1582 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001583 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001584 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001585 }
1586 }
1587 }
1588
Bruce Allan2e1706f2012-06-30 20:02:42 +00001589 /* Receive Checksum Offload */
1590 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001591
Bruce Allan70495a52012-01-11 01:26:50 +00001592 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1593
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001594 /* probably a little skewed due to removing CRC */
1595 total_rx_bytes += skb->len;
1596 total_rx_packets++;
1597
1598 /* eth type trans needs skb->data to point to something */
1599 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001600 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001601 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001602 goto next_desc;
1603 }
1604
Bruce Allan5f450212011-07-22 06:21:46 +00001605 e1000_receive_skb(adapter, netdev, skb, staterr,
1606 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001607
1608next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001609 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001610
1611 /* return some buffers to hardware, one at a time is too slow */
1612 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001613 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001614 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001615 cleaned_count = 0;
1616 }
1617
1618 /* use prefetched values */
1619 rx_desc = next_rxd;
1620 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001621
1622 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001623 }
1624 rx_ring->next_to_clean = i;
1625
1626 cleaned_count = e1000_desc_unused(rx_ring);
1627 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001628 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001629
1630 adapter->total_rx_bytes += total_rx_bytes;
1631 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001632 return cleaned;
1633}
1634
1635/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001637 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001639static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640{
Bruce Allan55aa6982011-12-16 00:45:45 +00001641 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642 struct e1000_buffer *buffer_info;
1643 struct e1000_ps_page *ps_page;
1644 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 unsigned int i, j;
1646
1647 /* Free all the Rx ring sk_buffs */
1648 for (i = 0; i < rx_ring->count; i++) {
1649 buffer_info = &rx_ring->buffer_info[i];
1650 if (buffer_info->dma) {
1651 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001652 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001654 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001655 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001656 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001657 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001659 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001661 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662 buffer_info->dma = 0;
1663 }
1664
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001665 if (buffer_info->page) {
1666 put_page(buffer_info->page);
1667 buffer_info->page = NULL;
1668 }
1669
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670 if (buffer_info->skb) {
1671 dev_kfree_skb(buffer_info->skb);
1672 buffer_info->skb = NULL;
1673 }
1674
1675 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001676 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677 if (!ps_page->page)
1678 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001679 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1680 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 ps_page->dma = 0;
1682 put_page(ps_page->page);
1683 ps_page->page = NULL;
1684 }
1685 }
1686
1687 /* there also may be some cached data from a chained receive */
1688 if (rx_ring->rx_skb_top) {
1689 dev_kfree_skb(rx_ring->rx_skb_top);
1690 rx_ring->rx_skb_top = NULL;
1691 }
1692
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693 /* Zero out the descriptor ring */
1694 memset(rx_ring->desc, 0, rx_ring->size);
1695
1696 rx_ring->next_to_clean = 0;
1697 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001698 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699
Bruce Allanc5083cf2011-12-16 00:45:40 +00001700 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001701 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1702 e1000e_update_rdt_wa(rx_ring, 0);
1703 else
1704 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705}
1706
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001707static void e1000e_downshift_workaround(struct work_struct *work)
1708{
1709 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001710 struct e1000_adapter,
1711 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001712
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001713 if (test_bit(__E1000_DOWN, &adapter->state))
1714 return;
1715
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001716 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1717}
1718
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719/**
1720 * e1000_intr_msi - Interrupt Handler
1721 * @irq: interrupt number
1722 * @data: pointer to a network interface device structure
1723 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001724static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725{
1726 struct net_device *netdev = data;
1727 struct e1000_adapter *adapter = netdev_priv(netdev);
1728 struct e1000_hw *hw = &adapter->hw;
1729 u32 icr = er32(ICR);
1730
Bruce Allane921eb12012-11-28 09:28:37 +00001731 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001732 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001733 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001734 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001735 * disconnect (LSC) before accessing any PHY registers
1736 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1738 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001739 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740
Bruce Allane921eb12012-11-28 09:28:37 +00001741 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001743 * adapter in watchdog
1744 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745 if (netif_carrier_ok(netdev) &&
1746 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1747 /* disable receives */
1748 u32 rctl = er32(RCTL);
1749 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001750 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751 }
1752 /* guard against interrupt when we're going down */
1753 if (!test_bit(__E1000_DOWN, &adapter->state))
1754 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1755 }
1756
Bruce Allan94fb8482013-01-23 09:00:03 +00001757 /* Reset on uncorrectable ECC error */
1758 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1759 u32 pbeccsts = er32(PBECCSTS);
1760
1761 adapter->corr_errors +=
1762 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1763 adapter->uncorr_errors +=
1764 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1765 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1766
1767 /* Do the reset outside of interrupt context */
1768 schedule_work(&adapter->reset_task);
1769
1770 /* return immediately since reset is imminent */
1771 return IRQ_HANDLED;
1772 }
1773
Ben Hutchings288379f2009-01-19 16:43:59 -08001774 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001775 adapter->total_tx_bytes = 0;
1776 adapter->total_tx_packets = 0;
1777 adapter->total_rx_bytes = 0;
1778 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001779 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780 }
1781
1782 return IRQ_HANDLED;
1783}
1784
1785/**
1786 * e1000_intr - Interrupt Handler
1787 * @irq: interrupt number
1788 * @data: pointer to a network interface device structure
1789 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001790static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791{
1792 struct net_device *netdev = data;
1793 struct e1000_adapter *adapter = netdev_priv(netdev);
1794 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001796
Bruce Allana68ea772009-11-20 23:23:16 +00001797 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798 return IRQ_NONE; /* Not our interrupt */
1799
Bruce Allane921eb12012-11-28 09:28:37 +00001800 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001801 * not set, then the adapter didn't send an interrupt
1802 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803 if (!(icr & E1000_ICR_INT_ASSERTED))
1804 return IRQ_NONE;
1805
Bruce Allane921eb12012-11-28 09:28:37 +00001806 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001807 * interrupts are masked. No need for the
1808 * IMC write
1809 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810
dave graham573cca82009-02-10 12:52:05 +00001811 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001812 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001813 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001814 * disconnect (LSC) before accessing any PHY registers
1815 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1817 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001818 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819
Bruce Allane921eb12012-11-28 09:28:37 +00001820 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821 * For packet buffer work-around on link down event;
1822 * disable receives here in the ISR and
1823 * reset adapter in watchdog
1824 */
1825 if (netif_carrier_ok(netdev) &&
1826 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1827 /* disable receives */
1828 rctl = er32(RCTL);
1829 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001830 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831 }
1832 /* guard against interrupt when we're going down */
1833 if (!test_bit(__E1000_DOWN, &adapter->state))
1834 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1835 }
1836
Bruce Allan94fb8482013-01-23 09:00:03 +00001837 /* Reset on uncorrectable ECC error */
1838 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1839 u32 pbeccsts = er32(PBECCSTS);
1840
1841 adapter->corr_errors +=
1842 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1843 adapter->uncorr_errors +=
1844 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1845 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1846
1847 /* Do the reset outside of interrupt context */
1848 schedule_work(&adapter->reset_task);
1849
1850 /* return immediately since reset is imminent */
1851 return IRQ_HANDLED;
1852 }
1853
Ben Hutchings288379f2009-01-19 16:43:59 -08001854 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001855 adapter->total_tx_bytes = 0;
1856 adapter->total_tx_packets = 0;
1857 adapter->total_rx_bytes = 0;
1858 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001859 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001860 }
1861
1862 return IRQ_HANDLED;
1863}
1864
Bruce Allan8bb62862013-01-16 08:46:49 +00001865static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001866{
1867 struct net_device *netdev = data;
1868 struct e1000_adapter *adapter = netdev_priv(netdev);
1869 struct e1000_hw *hw = &adapter->hw;
1870 u32 icr = er32(ICR);
1871
1872 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001873 if (!test_bit(__E1000_DOWN, &adapter->state))
1874 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001875 return IRQ_NONE;
1876 }
1877
1878 if (icr & adapter->eiac_mask)
1879 ew32(ICS, (icr & adapter->eiac_mask));
1880
1881 if (icr & E1000_ICR_OTHER) {
1882 if (!(icr & E1000_ICR_LSC))
1883 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001884 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001885 /* guard against interrupt when we're going down */
1886 if (!test_bit(__E1000_DOWN, &adapter->state))
1887 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1888 }
1889
1890no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001891 if (!test_bit(__E1000_DOWN, &adapter->state))
1892 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001893
1894 return IRQ_HANDLED;
1895}
1896
Bruce Allan8bb62862013-01-16 08:46:49 +00001897static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001898{
1899 struct net_device *netdev = data;
1900 struct e1000_adapter *adapter = netdev_priv(netdev);
1901 struct e1000_hw *hw = &adapter->hw;
1902 struct e1000_ring *tx_ring = adapter->tx_ring;
1903
Bruce Allan4662e822008-08-26 18:37:06 -07001904 adapter->total_tx_bytes = 0;
1905 adapter->total_tx_packets = 0;
1906
Bruce Allan55aa6982011-12-16 00:45:45 +00001907 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001908 /* Ring was not completely cleaned, so fire another interrupt */
1909 ew32(ICS, tx_ring->ims_val);
1910
1911 return IRQ_HANDLED;
1912}
1913
Bruce Allan8bb62862013-01-16 08:46:49 +00001914static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001915{
1916 struct net_device *netdev = data;
1917 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001918 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001919
1920 /* Write the ITR value calculated at the end of the
1921 * previous interrupt.
1922 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001923 if (rx_ring->set_itr) {
1924 writel(1000000000 / (rx_ring->itr_val * 256),
1925 rx_ring->itr_register);
1926 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001927 }
1928
Ben Hutchings288379f2009-01-19 16:43:59 -08001929 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001930 adapter->total_rx_bytes = 0;
1931 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001932 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001933 }
1934 return IRQ_HANDLED;
1935}
1936
1937/**
1938 * e1000_configure_msix - Configure MSI-X hardware
1939 *
1940 * e1000_configure_msix sets up the hardware to properly
1941 * generate MSI-X interrupts.
1942 **/
1943static void e1000_configure_msix(struct e1000_adapter *adapter)
1944{
1945 struct e1000_hw *hw = &adapter->hw;
1946 struct e1000_ring *rx_ring = adapter->rx_ring;
1947 struct e1000_ring *tx_ring = adapter->tx_ring;
1948 int vector = 0;
1949 u32 ctrl_ext, ivar = 0;
1950
1951 adapter->eiac_mask = 0;
1952
1953 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1954 if (hw->mac.type == e1000_82574) {
1955 u32 rfctl = er32(RFCTL);
1956 rfctl |= E1000_RFCTL_ACK_DIS;
1957 ew32(RFCTL, rfctl);
1958 }
1959
Bruce Allan4662e822008-08-26 18:37:06 -07001960 /* Configure Rx vector */
1961 rx_ring->ims_val = E1000_IMS_RXQ0;
1962 adapter->eiac_mask |= rx_ring->ims_val;
1963 if (rx_ring->itr_val)
1964 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001965 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001966 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001967 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001968 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1969
1970 /* Configure Tx vector */
1971 tx_ring->ims_val = E1000_IMS_TXQ0;
1972 vector++;
1973 if (tx_ring->itr_val)
1974 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001975 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001976 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001977 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001978 adapter->eiac_mask |= tx_ring->ims_val;
1979 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1980
1981 /* set vector for Other Causes, e.g. link changes */
1982 vector++;
1983 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1984 if (rx_ring->itr_val)
1985 writel(1000000000 / (rx_ring->itr_val * 256),
1986 hw->hw_addr + E1000_EITR_82574(vector));
1987 else
1988 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1989
1990 /* Cause Tx interrupts on every write back */
1991 ivar |= (1 << 31);
1992
1993 ew32(IVAR, ivar);
1994
1995 /* enable MSI-X PBA support */
1996 ctrl_ext = er32(CTRL_EXT);
1997 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1998
1999 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07002000 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2001 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2002 ew32(CTRL_EXT, ctrl_ext);
2003 e1e_flush();
2004}
2005
2006void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2007{
2008 if (adapter->msix_entries) {
2009 pci_disable_msix(adapter->pdev);
2010 kfree(adapter->msix_entries);
2011 adapter->msix_entries = NULL;
2012 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2013 pci_disable_msi(adapter->pdev);
2014 adapter->flags &= ~FLAG_MSI_ENABLED;
2015 }
Bruce Allan4662e822008-08-26 18:37:06 -07002016}
2017
2018/**
2019 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2020 *
2021 * Attempt to configure interrupts using the best available
2022 * capabilities of the hardware and kernel.
2023 **/
2024void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2025{
2026 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002027 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002028
2029 switch (adapter->int_mode) {
2030 case E1000E_INT_MODE_MSIX:
2031 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002032 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2033 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002034 sizeof(struct
2035 msix_entry),
2036 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002037 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002038 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002039 adapter->msix_entries[i].entry = i;
2040
2041 err = pci_enable_msix(adapter->pdev,
2042 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002043 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002044 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002045 return;
2046 }
2047 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002048 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002049 e1000e_reset_interrupt_capability(adapter);
2050 }
2051 adapter->int_mode = E1000E_INT_MODE_MSI;
2052 /* Fall through */
2053 case E1000E_INT_MODE_MSI:
2054 if (!pci_enable_msi(adapter->pdev)) {
2055 adapter->flags |= FLAG_MSI_ENABLED;
2056 } else {
2057 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002058 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002059 }
2060 /* Fall through */
2061 case E1000E_INT_MODE_LEGACY:
2062 /* Don't do anything; this is the system default */
2063 break;
2064 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002065
2066 /* store the number of vectors being used */
2067 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002068}
2069
2070/**
2071 * e1000_request_msix - Initialize MSI-X interrupts
2072 *
2073 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2074 * kernel.
2075 **/
2076static int e1000_request_msix(struct e1000_adapter *adapter)
2077{
2078 struct net_device *netdev = adapter->netdev;
2079 int err = 0, vector = 0;
2080
2081 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002082 snprintf(adapter->rx_ring->name,
2083 sizeof(adapter->rx_ring->name) - 1,
2084 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002085 else
2086 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2087 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002088 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002089 netdev);
2090 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002091 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002092 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2093 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002094 adapter->rx_ring->itr_val = adapter->itr;
2095 vector++;
2096
2097 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002098 snprintf(adapter->tx_ring->name,
2099 sizeof(adapter->tx_ring->name) - 1,
2100 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002101 else
2102 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2103 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002104 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002105 netdev);
2106 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002107 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002108 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2109 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002110 adapter->tx_ring->itr_val = adapter->itr;
2111 vector++;
2112
2113 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002114 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002115 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002116 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002117
2118 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002119
Bruce Allan4662e822008-08-26 18:37:06 -07002120 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002121}
2122
Bruce Allanf8d59f72008-08-08 18:36:11 -07002123/**
2124 * e1000_request_irq - initialize interrupts
2125 *
2126 * Attempts to configure interrupts using the best available
2127 * capabilities of the hardware and kernel.
2128 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002129static int e1000_request_irq(struct e1000_adapter *adapter)
2130{
2131 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002132 int err;
2133
Bruce Allan4662e822008-08-26 18:37:06 -07002134 if (adapter->msix_entries) {
2135 err = e1000_request_msix(adapter);
2136 if (!err)
2137 return err;
2138 /* fall back to MSI */
2139 e1000e_reset_interrupt_capability(adapter);
2140 adapter->int_mode = E1000E_INT_MODE_MSI;
2141 e1000e_set_interrupt_capability(adapter);
2142 }
2143 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002144 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002145 netdev->name, netdev);
2146 if (!err)
2147 return err;
2148
2149 /* fall back to legacy interrupt */
2150 e1000e_reset_interrupt_capability(adapter);
2151 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002152 }
2153
Joe Perchesa0607fd2009-11-18 23:29:17 -08002154 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002155 netdev->name, netdev);
2156 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002157 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002158
2159 return err;
2160}
2161
2162static void e1000_free_irq(struct e1000_adapter *adapter)
2163{
2164 struct net_device *netdev = adapter->netdev;
2165
Bruce Allan4662e822008-08-26 18:37:06 -07002166 if (adapter->msix_entries) {
2167 int vector = 0;
2168
2169 free_irq(adapter->msix_entries[vector].vector, netdev);
2170 vector++;
2171
2172 free_irq(adapter->msix_entries[vector].vector, netdev);
2173 vector++;
2174
2175 /* Other Causes interrupt vector */
2176 free_irq(adapter->msix_entries[vector].vector, netdev);
2177 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002178 }
Bruce Allan4662e822008-08-26 18:37:06 -07002179
2180 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002181}
2182
2183/**
2184 * e1000_irq_disable - Mask off interrupt generation on the NIC
2185 **/
2186static void e1000_irq_disable(struct e1000_adapter *adapter)
2187{
2188 struct e1000_hw *hw = &adapter->hw;
2189
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002191 if (adapter->msix_entries)
2192 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002194
2195 if (adapter->msix_entries) {
2196 int i;
2197 for (i = 0; i < adapter->num_vectors; i++)
2198 synchronize_irq(adapter->msix_entries[i].vector);
2199 } else {
2200 synchronize_irq(adapter->pdev->irq);
2201 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202}
2203
2204/**
2205 * e1000_irq_enable - Enable default interrupt generation settings
2206 **/
2207static void e1000_irq_enable(struct e1000_adapter *adapter)
2208{
2209 struct e1000_hw *hw = &adapter->hw;
2210
Bruce Allan4662e822008-08-26 18:37:06 -07002211 if (adapter->msix_entries) {
2212 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2213 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002214 } else if (hw->mac.type == e1000_pch_lpt) {
2215 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002216 } else {
2217 ew32(IMS, IMS_ENABLE_MASK);
2218 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002219 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220}
2221
2222/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002223 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002224 * @adapter: address of board private structure
2225 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002226 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227 * For ASF and Pass Through versions of f/w this means that
2228 * the driver is loaded. For AMT version (only with 82573)
2229 * of the f/w this means that the network i/f is open.
2230 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002231void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232{
2233 struct e1000_hw *hw = &adapter->hw;
2234 u32 ctrl_ext;
2235 u32 swsm;
2236
2237 /* Let firmware know the driver has taken over */
2238 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2239 swsm = er32(SWSM);
2240 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2241 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2242 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002243 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 }
2245}
2246
2247/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002248 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249 * @adapter: address of board private structure
2250 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002251 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 * For ASF and Pass Through versions of f/w this means that the
2253 * driver is no longer loaded. For AMT version (only with 82573) i
2254 * of the f/w this means that the network i/f is closed.
2255 *
2256 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002257void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258{
2259 struct e1000_hw *hw = &adapter->hw;
2260 u32 ctrl_ext;
2261 u32 swsm;
2262
2263 /* Let firmware taken over control of h/w */
2264 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2265 swsm = er32(SWSM);
2266 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2267 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2268 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002269 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 }
2271}
2272
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002274 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002275 **/
2276static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2277 struct e1000_ring *ring)
2278{
2279 struct pci_dev *pdev = adapter->pdev;
2280
2281 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2282 GFP_KERNEL);
2283 if (!ring->desc)
2284 return -ENOMEM;
2285
2286 return 0;
2287}
2288
2289/**
2290 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002291 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002292 *
2293 * Return 0 on success, negative on failure
2294 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002295int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002296{
Bruce Allan55aa6982011-12-16 00:45:45 +00002297 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002298 int err = -ENOMEM, size;
2299
2300 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002301 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302 if (!tx_ring->buffer_info)
2303 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002304
2305 /* round up to nearest 4K */
2306 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2307 tx_ring->size = ALIGN(tx_ring->size, 4096);
2308
2309 err = e1000_alloc_ring_dma(adapter, tx_ring);
2310 if (err)
2311 goto err;
2312
2313 tx_ring->next_to_use = 0;
2314 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002315
2316 return 0;
2317err:
2318 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002319 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002320 return err;
2321}
2322
2323/**
2324 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002325 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002326 *
2327 * Returns 0 on success, negative on failure
2328 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002329int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330{
Bruce Allan55aa6982011-12-16 00:45:45 +00002331 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002332 struct e1000_buffer *buffer_info;
2333 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334
2335 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002336 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337 if (!rx_ring->buffer_info)
2338 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339
Auke Kok47f44e42007-10-25 13:57:44 -07002340 for (i = 0; i < rx_ring->count; i++) {
2341 buffer_info = &rx_ring->buffer_info[i];
2342 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2343 sizeof(struct e1000_ps_page),
2344 GFP_KERNEL);
2345 if (!buffer_info->ps_pages)
2346 goto err_pages;
2347 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002348
2349 desc_len = sizeof(union e1000_rx_desc_packet_split);
2350
2351 /* Round up to nearest 4K */
2352 rx_ring->size = rx_ring->count * desc_len;
2353 rx_ring->size = ALIGN(rx_ring->size, 4096);
2354
2355 err = e1000_alloc_ring_dma(adapter, rx_ring);
2356 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002357 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002358
2359 rx_ring->next_to_clean = 0;
2360 rx_ring->next_to_use = 0;
2361 rx_ring->rx_skb_top = NULL;
2362
2363 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002364
2365err_pages:
2366 for (i = 0; i < rx_ring->count; i++) {
2367 buffer_info = &rx_ring->buffer_info[i];
2368 kfree(buffer_info->ps_pages);
2369 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370err:
2371 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002372 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 return err;
2374}
2375
2376/**
2377 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002378 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002379 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002380static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002381{
Bruce Allan55aa6982011-12-16 00:45:45 +00002382 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 struct e1000_buffer *buffer_info;
2384 unsigned long size;
2385 unsigned int i;
2386
2387 for (i = 0; i < tx_ring->count; i++) {
2388 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002389 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 }
2391
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002392 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 size = sizeof(struct e1000_buffer) * tx_ring->count;
2394 memset(tx_ring->buffer_info, 0, size);
2395
2396 memset(tx_ring->desc, 0, tx_ring->size);
2397
2398 tx_ring->next_to_use = 0;
2399 tx_ring->next_to_clean = 0;
2400
Bruce Allanc5083cf2011-12-16 00:45:40 +00002401 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002402 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2403 e1000e_update_tdt_wa(tx_ring, 0);
2404 else
2405 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406}
2407
2408/**
2409 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002410 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411 *
2412 * Free all transmit software resources
2413 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002414void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002415{
Bruce Allan55aa6982011-12-16 00:45:45 +00002416 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418
Bruce Allan55aa6982011-12-16 00:45:45 +00002419 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420
2421 vfree(tx_ring->buffer_info);
2422 tx_ring->buffer_info = NULL;
2423
2424 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2425 tx_ring->dma);
2426 tx_ring->desc = NULL;
2427}
2428
2429/**
2430 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002431 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432 *
2433 * Free all receive software resources
2434 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002435void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002436{
Bruce Allan55aa6982011-12-16 00:45:45 +00002437 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002438 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002439 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440
Bruce Allan55aa6982011-12-16 00:45:45 +00002441 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002443 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002444 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002445
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 vfree(rx_ring->buffer_info);
2447 rx_ring->buffer_info = NULL;
2448
Auke Kokbc7f75f2007-09-17 12:30:59 -07002449 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2450 rx_ring->dma);
2451 rx_ring->desc = NULL;
2452}
2453
2454/**
2455 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002456 * @adapter: pointer to adapter
2457 * @itr_setting: current adapter->itr
2458 * @packets: the number of packets during this measurement interval
2459 * @bytes: the number of bytes during this measurement interval
2460 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 * Stores a new ITR value based on packets and byte
2462 * counts during the last interrupt. The advantage of per interrupt
2463 * computation is faster updates and more accurate ITR for the current
2464 * traffic pattern. Constants in this function were computed
2465 * based on theoretical maximum wire speed and thresholds were set based
2466 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002467 * while increasing bulk throughput. This functionality is controlled
2468 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002469 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002470static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471{
2472 unsigned int retval = itr_setting;
2473
2474 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002475 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476
2477 switch (itr_setting) {
2478 case lowest_latency:
2479 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002480 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002481 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002482 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 break;
2485 case low_latency: /* 50 usec aka 20000 ints/s */
2486 if (bytes > 10000) {
2487 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002488 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002489 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002490 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002491 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002492 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002493 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002494 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495 retval = bulk_latency;
2496 } else if (packets <= 2 && bytes < 512) {
2497 retval = lowest_latency;
2498 }
2499 break;
2500 case bulk_latency: /* 250 usec aka 4000 ints/s */
2501 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002502 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 } else if (bytes < 6000) {
2505 retval = low_latency;
2506 }
2507 break;
2508 }
2509
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 return retval;
2511}
2512
2513static void e1000_set_itr(struct e1000_adapter *adapter)
2514{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 u16 current_itr;
2516 u32 new_itr = adapter->itr;
2517
2518 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2519 if (adapter->link_speed != SPEED_1000) {
2520 current_itr = 0;
2521 new_itr = 4000;
2522 goto set_itr_now;
2523 }
2524
Bruce Allan828bac82010-09-29 21:39:37 +00002525 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2526 new_itr = 0;
2527 goto set_itr_now;
2528 }
2529
Bruce Allan8bb62862013-01-16 08:46:49 +00002530 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2531 adapter->total_tx_packets,
2532 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2534 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2535 adapter->tx_itr = low_latency;
2536
Bruce Allan8bb62862013-01-16 08:46:49 +00002537 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2538 adapter->total_rx_packets,
2539 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002540 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2541 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2542 adapter->rx_itr = low_latency;
2543
2544 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2545
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002547 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548 case lowest_latency:
2549 new_itr = 70000;
2550 break;
2551 case low_latency:
2552 new_itr = 20000; /* aka hwitr = ~200 */
2553 break;
2554 case bulk_latency:
2555 new_itr = 4000;
2556 break;
2557 default:
2558 break;
2559 }
2560
2561set_itr_now:
2562 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002563 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002565 * increasing
2566 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002567 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002568 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002569 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002570 adapter->rx_ring->itr_val = new_itr;
2571 if (adapter->msix_entries)
2572 adapter->rx_ring->set_itr = 1;
2573 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002574 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002575 }
2576}
2577
2578/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002579 * e1000e_write_itr - write the ITR value to the appropriate registers
2580 * @adapter: address of board private structure
2581 * @itr: new ITR value to program
2582 *
2583 * e1000e_write_itr determines if the adapter is in MSI-X mode
2584 * and, if so, writes the EITR registers with the ITR value.
2585 * Otherwise, it writes the ITR value into the ITR register.
2586 **/
2587void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2588{
2589 struct e1000_hw *hw = &adapter->hw;
2590 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2591
2592 if (adapter->msix_entries) {
2593 int vector;
2594
2595 for (vector = 0; vector < adapter->num_vectors; vector++)
2596 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2597 } else {
2598 ew32(ITR, new_itr);
2599 }
2600}
2601
2602/**
Bruce Allan4662e822008-08-26 18:37:06 -07002603 * e1000_alloc_queues - Allocate memory for all rings
2604 * @adapter: board private structure to initialize
2605 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002606static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002607{
Bruce Allan55aa6982011-12-16 00:45:45 +00002608 int size = sizeof(struct e1000_ring);
2609
2610 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002611 if (!adapter->tx_ring)
2612 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002613 adapter->tx_ring->count = adapter->tx_ring_count;
2614 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002615
Bruce Allan55aa6982011-12-16 00:45:45 +00002616 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002617 if (!adapter->rx_ring)
2618 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002619 adapter->rx_ring->count = adapter->rx_ring_count;
2620 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002621
2622 return 0;
2623err:
2624 e_err("Unable to allocate memory for queues\n");
2625 kfree(adapter->rx_ring);
2626 kfree(adapter->tx_ring);
2627 return -ENOMEM;
2628}
2629
2630/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002631 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002632 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002633 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002634 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002635static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002636{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002637 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2638 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002639 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002640 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002641 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002642
Wang Chen4cf16532008-11-12 23:38:14 -08002643 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644
Bruce Allanc58c8a72012-03-20 03:48:19 +00002645 if (!adapter->msix_entries ||
2646 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2647 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002648
Bruce Allanc58c8a72012-03-20 03:48:19 +00002649 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002650
Alexander Duyck12d04a32009-03-25 22:05:03 +00002651 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002652 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002653
Bruce Allanc58c8a72012-03-20 03:48:19 +00002654 /* If weight not fully consumed, exit the polling mode */
2655 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656 if (adapter->itr_setting & 3)
2657 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002658 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002659 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2660 if (adapter->msix_entries)
2661 ew32(IMS, adapter->rx_ring->ims_val);
2662 else
2663 e1000_irq_enable(adapter);
2664 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002665 }
2666
2667 return work_done;
2668}
2669
Jiri Pirko8e586132011-12-08 19:52:37 -05002670static int e1000_vlan_rx_add_vid(struct net_device *netdev, 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
Jiri Pirko8e586132011-12-08 19:52:37 -05002695static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696{
2697 struct e1000_adapter *adapter = netdev_priv(netdev);
2698 struct e1000_hw *hw = &adapter->hw;
2699 u32 vfta, index;
2700
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701 if ((adapter->hw.mng_cookie.status &
2702 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2703 (vid == adapter->mng_vlan_id)) {
2704 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002705 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002706 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002707 }
2708
2709 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002710 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2711 index = (vid >> 5) & 0x7F;
2712 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2713 vfta &= ~(1 << (vid & 0x1F));
2714 hw->mac.ops.write_vfta(hw, index, vfta);
2715 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002716
2717 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002718
2719 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002720}
2721
2722/**
2723 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2724 * @adapter: board private structure to initialize
2725 **/
2726static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2727{
2728 struct net_device *netdev = adapter->netdev;
2729 struct e1000_hw *hw = &adapter->hw;
2730 u32 rctl;
2731
2732 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2733 /* disable VLAN receive filtering */
2734 rctl = er32(RCTL);
2735 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2736 ew32(RCTL, rctl);
2737
2738 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2739 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2740 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2741 }
2742 }
2743}
2744
2745/**
2746 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2747 * @adapter: board private structure to initialize
2748 **/
2749static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2750{
2751 struct e1000_hw *hw = &adapter->hw;
2752 u32 rctl;
2753
2754 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2755 /* enable VLAN receive filtering */
2756 rctl = er32(RCTL);
2757 rctl |= E1000_RCTL_VFE;
2758 rctl &= ~E1000_RCTL_CFIEN;
2759 ew32(RCTL, rctl);
2760 }
2761}
2762
2763/**
2764 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2765 * @adapter: board private structure to initialize
2766 **/
2767static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2768{
2769 struct e1000_hw *hw = &adapter->hw;
2770 u32 ctrl;
2771
2772 /* disable VLAN tag insert/strip */
2773 ctrl = er32(CTRL);
2774 ctrl &= ~E1000_CTRL_VME;
2775 ew32(CTRL, ctrl);
2776}
2777
2778/**
2779 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2780 * @adapter: board private structure to initialize
2781 **/
2782static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2783{
2784 struct e1000_hw *hw = &adapter->hw;
2785 u32 ctrl;
2786
2787 /* enable VLAN tag insert/strip */
2788 ctrl = er32(CTRL);
2789 ctrl |= E1000_CTRL_VME;
2790 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791}
2792
2793static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2794{
2795 struct net_device *netdev = adapter->netdev;
2796 u16 vid = adapter->hw.mng_cookie.vlan_id;
2797 u16 old_vid = adapter->mng_vlan_id;
2798
Bruce Allane5fe2542013-02-20 04:06:27 +00002799 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002800 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 adapter->mng_vlan_id = vid;
2802 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002804 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2805 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806}
2807
2808static void e1000_restore_vlan(struct e1000_adapter *adapter)
2809{
2810 u16 vid;
2811
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002812 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002814 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Bruce Allanf0ff4392013-02-20 04:05:39 +00002815 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002816}
2817
Bruce Allancd791612010-05-10 14:59:51 +00002818static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819{
2820 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002821 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822
2823 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2824 return;
2825
2826 manc = er32(MANC);
2827
Bruce Allane921eb12012-11-28 09:28:37 +00002828 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002830 * the packets will be handled on SMBUS
2831 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 manc |= E1000_MANC_EN_MNG2HOST;
2833 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002834
2835 switch (hw->mac.type) {
2836 default:
2837 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2838 break;
2839 case e1000_82574:
2840 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002841 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002842 * if so, enable it.
2843 */
2844 for (i = 0, j = 0; i < 8; i++) {
2845 mdef = er32(MDEF(i));
2846
2847 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002848 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002849 continue;
2850
2851 /* Enable this decision filter in MANC2H */
2852 if (mdef)
2853 manc2h |= (1 << i);
2854
2855 j |= mdef;
2856 }
2857
2858 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2859 break;
2860
2861 /* Create new decision filter in an empty filter */
2862 for (i = 0, j = 0; i < 8; i++)
2863 if (er32(MDEF(i)) == 0) {
2864 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2865 E1000_MDEF_PORT_664));
2866 manc2h |= (1 << 1);
2867 j++;
2868 break;
2869 }
2870
2871 if (!j)
2872 e_warn("Unable to create IPMI pass-through filter\n");
2873 break;
2874 }
2875
Auke Kokbc7f75f2007-09-17 12:30:59 -07002876 ew32(MANC2H, manc2h);
2877 ew32(MANC, manc);
2878}
2879
2880/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002881 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002882 * @adapter: board private structure
2883 *
2884 * Configure the Tx unit of the MAC after a reset.
2885 **/
2886static void e1000_configure_tx(struct e1000_adapter *adapter)
2887{
2888 struct e1000_hw *hw = &adapter->hw;
2889 struct e1000_ring *tx_ring = adapter->tx_ring;
2890 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002891 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002892
2893 /* Setup the HW Tx Head and Tail descriptor pointers */
2894 tdba = tx_ring->dma;
2895 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002896 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2897 ew32(TDBAH(0), (tdba >> 32));
2898 ew32(TDLEN(0), tdlen);
2899 ew32(TDH(0), 0);
2900 ew32(TDT(0), 0);
2901 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2902 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904 /* Set the Tx Interrupt Delay register */
2905 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002906 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002907 ew32(TADV, adapter->tx_abs_int_delay);
2908
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002909 if (adapter->flags2 & FLAG2_DMA_BURST) {
2910 u32 txdctl = er32(TXDCTL(0));
2911 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2912 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002913 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002914 * hardware to use the bus more efficiently in bursts, depends
2915 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002916 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002917 * hthresh = 1 ==> prefetch when one or more available
2918 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2919 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002920 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002921 */
2922 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2923 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002924 }
Bruce Allan56032be2011-12-16 00:46:01 +00002925 /* erratum work around: set txdctl the same for both queues */
2926 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002927
Auke Kokbc7f75f2007-09-17 12:30:59 -07002928 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002929 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002930 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002931 * gigabit link later
2932 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933#define SPEED_MODE_BIT (1 << 21)
2934 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002935 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002936 }
2937
2938 /* errata: program both queues to unweighted RR */
2939 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002940 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002942 ew32(TARC(0), tarc);
2943 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002945 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 }
2947
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 /* Setup Transmit Descriptor Settings for eop descriptor */
2949 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2950
2951 /* only set IDE if we are delaying interrupts using the timers */
2952 if (adapter->tx_int_delay)
2953 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2954
2955 /* enable Report Status bit */
2956 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2957
Bruce Allan57cde762012-02-22 09:02:58 +00002958 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002959}
2960
2961/**
2962 * e1000_setup_rctl - configure the receive control registers
2963 * @adapter: Board private structure
2964 **/
2965#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2966 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2967static void e1000_setup_rctl(struct e1000_adapter *adapter)
2968{
2969 struct e1000_hw *hw = &adapter->hw;
2970 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971 u32 pages = 0;
2972
Bruce Allan2fbe4522012-04-19 03:21:47 +00002973 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2974 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002975 s32 ret_val;
2976
2977 if (adapter->netdev->mtu > ETH_DATA_LEN)
2978 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2979 else
2980 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002981
2982 if (ret_val)
2983 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002984 }
2985
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 /* Program MC offset vector base */
2987 rctl = er32(RCTL);
2988 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2989 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002990 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2991 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992
2993 /* Do not Store bad packets */
2994 rctl &= ~E1000_RCTL_SBP;
2995
2996 /* Enable Long Packet receive */
2997 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2998 rctl &= ~E1000_RCTL_LPE;
2999 else
3000 rctl |= E1000_RCTL_LPE;
3001
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003002 /* Some systems expect that the CRC is included in SMBUS traffic. The
3003 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3004 * host memory when this is enabled
3005 */
3006 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3007 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003008
Bruce Allana4f58f52009-06-02 11:29:18 +00003009 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3010 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3011 u16 phy_data;
3012
3013 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3014 phy_data &= 0xfff8;
3015 phy_data |= (1 << 2);
3016 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3017
3018 e1e_rphy(hw, 22, &phy_data);
3019 phy_data &= 0x0fff;
3020 phy_data |= (1 << 14);
3021 e1e_wphy(hw, 0x10, 0x2823);
3022 e1e_wphy(hw, 0x11, 0x0003);
3023 e1e_wphy(hw, 22, phy_data);
3024 }
3025
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 /* Setup buffer sizes */
3027 rctl &= ~E1000_RCTL_SZ_4096;
3028 rctl |= E1000_RCTL_BSEX;
3029 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003030 case 2048:
3031 default:
3032 rctl |= E1000_RCTL_SZ_2048;
3033 rctl &= ~E1000_RCTL_BSEX;
3034 break;
3035 case 4096:
3036 rctl |= E1000_RCTL_SZ_4096;
3037 break;
3038 case 8192:
3039 rctl |= E1000_RCTL_SZ_8192;
3040 break;
3041 case 16384:
3042 rctl |= E1000_RCTL_SZ_16384;
3043 break;
3044 }
3045
Bruce Allan5f450212011-07-22 06:21:46 +00003046 /* Enable Extended Status in all Receive Descriptors */
3047 rfctl = er32(RFCTL);
3048 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003049 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003050
Bruce Allane921eb12012-11-28 09:28:37 +00003051 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003052 * header is placed in skb->data and the packet data is
3053 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3054 * In the case of a non-split, skb->data is linearly filled,
3055 * followed by the page buffers. Therefore, skb->data is
3056 * sized to hold the largest protocol header.
3057 *
3058 * allocations using alloc_page take too long for regular MTU
3059 * so only enable packet split for jumbo frames
3060 *
3061 * Using pages when the page size is greater than 16k wastes
3062 * a lot of memory, since we allocate 3 pages at all times
3063 * per packet.
3064 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003066 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003068 else
3069 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070
3071 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003072 u32 psrctl = 0;
3073
Auke Kok140a7482007-10-25 13:57:58 -07003074 /* Enable Packet split descriptors */
3075 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076
Bruce Allane5fe2542013-02-20 04:06:27 +00003077 psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078
3079 switch (adapter->rx_ps_pages) {
3080 case 3:
Bruce Allane5fe2542013-02-20 04:06:27 +00003081 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
3082 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 case 2:
Bruce Allane5fe2542013-02-20 04:06:27 +00003084 psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
3085 /* fall-through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003086 case 1:
Bruce Allane5fe2542013-02-20 04:06:27 +00003087 psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 break;
3089 }
3090
3091 ew32(PSRCTL, psrctl);
3092 }
3093
Ben Greearcf955e62012-02-11 15:39:51 +00003094 /* This is useful for sniffing bad packets. */
3095 if (adapter->netdev->features & NETIF_F_RXALL) {
3096 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003097 * in e1000e_set_rx_mode
3098 */
Ben Greearcf955e62012-02-11 15:39:51 +00003099 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3100 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3101 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3102
3103 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3104 E1000_RCTL_DPF | /* Allow filtered pause */
3105 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3106 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3107 * and that breaks VLANs.
3108 */
3109 }
3110
Auke Kokbc7f75f2007-09-17 12:30:59 -07003111 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003112 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003113 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114}
3115
3116/**
3117 * e1000_configure_rx - Configure Receive Unit after Reset
3118 * @adapter: board private structure
3119 *
3120 * Configure the Rx unit of the MAC after a reset.
3121 **/
3122static void e1000_configure_rx(struct e1000_adapter *adapter)
3123{
3124 struct e1000_hw *hw = &adapter->hw;
3125 struct e1000_ring *rx_ring = adapter->rx_ring;
3126 u64 rdba;
3127 u32 rdlen, rctl, rxcsum, ctrl_ext;
3128
3129 if (adapter->rx_ps_pages) {
3130 /* this is a 32 byte descriptor */
3131 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003132 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133 adapter->clean_rx = e1000_clean_rx_irq_ps;
3134 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003135 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003136 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003137 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3138 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003140 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003141 adapter->clean_rx = e1000_clean_rx_irq;
3142 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3143 }
3144
3145 /* disable receives while setting up the descriptors */
3146 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003147 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3148 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003149 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003150 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003152 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003153 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003154 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003155 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003156 * granularity = 01
3157 * wthresh = 04,
3158 * hthresh = 04,
3159 * pthresh = 0x20
3160 */
3161 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3162 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3163
Bruce Allane921eb12012-11-28 09:28:37 +00003164 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003165 * the value was not set by the user via module options
3166 */
3167 if (adapter->rx_int_delay == DEFAULT_RDTR)
3168 adapter->rx_int_delay = BURST_RDTR;
3169 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3170 adapter->rx_abs_int_delay = BURST_RADV;
3171 }
3172
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 /* set the Receive Delay Timer Register */
3174 ew32(RDTR, adapter->rx_int_delay);
3175
3176 /* irq moderation */
3177 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003178 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003179 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180
3181 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003182 /* Auto-Mask interrupts upon ICR access */
3183 ctrl_ext |= E1000_CTRL_EXT_IAME;
3184 ew32(IAM, 0xffffffff);
3185 ew32(CTRL_EXT, ctrl_ext);
3186 e1e_flush();
3187
Bruce Allane921eb12012-11-28 09:28:37 +00003188 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003189 * the Base and Length of the Rx Descriptor Ring
3190 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003192 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3193 ew32(RDBAH(0), (rdba >> 32));
3194 ew32(RDLEN(0), rdlen);
3195 ew32(RDH(0), 0);
3196 ew32(RDT(0), 0);
3197 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3198 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003199
3200 /* Enable Receive Checksum Offload for TCP and UDP */
3201 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003202 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003203 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003204 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 ew32(RXCSUM, rxcsum);
3207
Bruce Allan3e35d992013-01-12 07:25:22 +00003208 /* With jumbo frames, excessive C-state transition latencies result
3209 * in dropped transactions.
3210 */
3211 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3212 u32 lat =
3213 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3214 adapter->max_frame_size) * 8 / 1000;
3215
3216 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003217 u32 rxdctl = er32(RXDCTL(0));
3218 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003219 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003220
3221 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3222 } else {
3223 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3224 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003225 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226
3227 /* Enable Receives */
3228 ew32(RCTL, rctl);
3229}
3230
3231/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003232 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003233 * @netdev: network interface device structure
3234 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003235 * Writes multicast address list to the MTA hash table.
3236 * Returns: -ENOMEM on failure
3237 * 0 on no addresses written
3238 * X on writing X addresses to MTA
3239 */
3240static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241{
3242 struct e1000_adapter *adapter = netdev_priv(netdev);
3243 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003244 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003245 u8 *mta_list;
3246 int i;
3247
3248 if (netdev_mc_empty(netdev)) {
3249 /* nothing to program, so clear mc list */
3250 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3251 return 0;
3252 }
3253
3254 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3255 if (!mta_list)
3256 return -ENOMEM;
3257
3258 /* update_mc_addr_list expects a packed array of only addresses. */
3259 i = 0;
3260 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003261 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003262
3263 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3264 kfree(mta_list);
3265
3266 return netdev_mc_count(netdev);
3267}
3268
3269/**
3270 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3271 * @netdev: network interface device structure
3272 *
3273 * Writes unicast address list to the RAR table.
3274 * Returns: -ENOMEM on failure/insufficient address space
3275 * 0 on no addresses written
3276 * X on writing X addresses to the RAR table
3277 **/
3278static int e1000e_write_uc_addr_list(struct net_device *netdev)
3279{
3280 struct e1000_adapter *adapter = netdev_priv(netdev);
3281 struct e1000_hw *hw = &adapter->hw;
3282 unsigned int rar_entries = hw->mac.rar_entry_count;
3283 int count = 0;
3284
3285 /* save a rar entry for our hardware address */
3286 rar_entries--;
3287
3288 /* save a rar entry for the LAA workaround */
3289 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3290 rar_entries--;
3291
3292 /* return ENOMEM indicating insufficient memory for addresses */
3293 if (netdev_uc_count(netdev) > rar_entries)
3294 return -ENOMEM;
3295
3296 if (!netdev_uc_empty(netdev) && rar_entries) {
3297 struct netdev_hw_addr *ha;
3298
Bruce Allane921eb12012-11-28 09:28:37 +00003299 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003300 * combining
3301 */
3302 netdev_for_each_uc_addr(ha, netdev) {
3303 if (!rar_entries)
3304 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003305 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003306 count++;
3307 }
3308 }
3309
3310 /* zero out the remaining RAR entries not used above */
3311 for (; rar_entries > 0; rar_entries--) {
3312 ew32(RAH(rar_entries), 0);
3313 ew32(RAL(rar_entries), 0);
3314 }
3315 e1e_flush();
3316
3317 return count;
3318}
3319
3320/**
3321 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3322 * @netdev: network interface device structure
3323 *
3324 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3325 * address list or the network interface flags are updated. This routine is
3326 * responsible for configuring the hardware for proper unicast, multicast,
3327 * promiscuous mode, and all-multi behavior.
3328 **/
3329static void e1000e_set_rx_mode(struct net_device *netdev)
3330{
3331 struct e1000_adapter *adapter = netdev_priv(netdev);
3332 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334
3335 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336 rctl = er32(RCTL);
3337
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003338 /* clear the affected bits */
3339 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3340
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341 if (netdev->flags & IFF_PROMISC) {
3342 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003343 /* Do not hardware filter VLANs in promisc mode */
3344 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003346 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003347
Patrick McHardy746b9f02008-07-16 20:15:45 -07003348 if (netdev->flags & IFF_ALLMULTI) {
3349 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003350 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003351 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003352 * then we should just turn on promiscuous mode so
3353 * that we can at least receive multicast traffic
3354 */
3355 count = e1000e_write_mc_addr_list(netdev);
3356 if (count < 0)
3357 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003358 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003359 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003360 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003361 * sufficient space to store all the addresses then enable
3362 * unicast promiscuous mode
3363 */
3364 count = e1000e_write_uc_addr_list(netdev);
3365 if (count < 0)
3366 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 }
3368
3369 ew32(RCTL, rctl);
3370
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003371 if (netdev->features & NETIF_F_HW_VLAN_RX)
3372 e1000e_vlan_strip_enable(adapter);
3373 else
3374 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375}
3376
Bruce Allan70495a52012-01-11 01:26:50 +00003377static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3378{
3379 struct e1000_hw *hw = &adapter->hw;
3380 u32 mrqc, rxcsum;
3381 int i;
3382 static const u32 rsskey[10] = {
3383 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3384 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3385 };
3386
3387 /* Fill out hash function seed */
3388 for (i = 0; i < 10; i++)
3389 ew32(RSSRK(i), rsskey[i]);
3390
3391 /* Direct all traffic to queue 0 */
3392 for (i = 0; i < 32; i++)
3393 ew32(RETA(i), 0);
3394
Bruce Allane921eb12012-11-28 09:28:37 +00003395 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003396 * descriptor on writeback.
3397 */
3398 rxcsum = er32(RXCSUM);
3399 rxcsum |= E1000_RXCSUM_PCSD;
3400
3401 ew32(RXCSUM, rxcsum);
3402
3403 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3404 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3405 E1000_MRQC_RSS_FIELD_IPV6 |
3406 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3407 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3408
3409 ew32(MRQC, mrqc);
3410}
3411
Auke Kokbc7f75f2007-09-17 12:30:59 -07003412/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003413 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3414 * @adapter: board private structure
3415 * @timinca: pointer to returned time increment attributes
3416 *
3417 * Get attributes for incrementing the System Time Register SYSTIML/H at
3418 * the default base frequency, and set the cyclecounter shift value.
3419 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003420s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003421{
3422 struct e1000_hw *hw = &adapter->hw;
3423 u32 incvalue, incperiod, shift;
3424
3425 /* Make sure clock is enabled on I217 before checking the frequency */
3426 if ((hw->mac.type == e1000_pch_lpt) &&
3427 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3428 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3429 u32 fextnvm7 = er32(FEXTNVM7);
3430
3431 if (!(fextnvm7 & (1 << 0))) {
3432 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3433 e1e_flush();
3434 }
3435 }
3436
3437 switch (hw->mac.type) {
3438 case e1000_pch2lan:
3439 case e1000_pch_lpt:
3440 /* On I217, the clock frequency is 25MHz or 96MHz as
3441 * indicated by the System Clock Frequency Indication
3442 */
3443 if ((hw->mac.type != e1000_pch_lpt) ||
3444 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3445 /* Stable 96MHz frequency */
3446 incperiod = INCPERIOD_96MHz;
3447 incvalue = INCVALUE_96MHz;
3448 shift = INCVALUE_SHIFT_96MHz;
3449 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3450 break;
3451 }
3452 /* fall-through */
3453 case e1000_82574:
3454 case e1000_82583:
3455 /* Stable 25MHz frequency */
3456 incperiod = INCPERIOD_25MHz;
3457 incvalue = INCVALUE_25MHz;
3458 shift = INCVALUE_SHIFT_25MHz;
3459 adapter->cc.shift = shift;
3460 break;
3461 default:
3462 return -EINVAL;
3463 }
3464
3465 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3466 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3467
3468 return 0;
3469}
3470
3471/**
3472 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3473 * @adapter: board private structure
3474 *
3475 * Outgoing time stamping can be enabled and disabled. Play nice and
3476 * disable it when requested, although it shouldn't cause any overhead
3477 * when no packet needs it. At most one packet in the queue may be
3478 * marked for time stamping, otherwise it would be impossible to tell
3479 * for sure to which packet the hardware time stamp belongs.
3480 *
3481 * Incoming time stamping has to be configured via the hardware filters.
3482 * Not all combinations are supported, in particular event type has to be
3483 * specified. Matching the kind of event packet is not supported, with the
3484 * exception of "all V2 events regardless of level 2 or 4".
3485 **/
3486static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3487{
3488 struct e1000_hw *hw = &adapter->hw;
3489 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3490 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3491 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003492 u32 rxmtrl = 0;
3493 u16 rxudp = 0;
3494 bool is_l4 = false;
3495 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003496 u32 regval;
3497 s32 ret_val;
3498
3499 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3500 return -EINVAL;
3501
3502 /* flags reserved for future extensions - must be zero */
3503 if (config->flags)
3504 return -EINVAL;
3505
3506 switch (config->tx_type) {
3507 case HWTSTAMP_TX_OFF:
3508 tsync_tx_ctl = 0;
3509 break;
3510 case HWTSTAMP_TX_ON:
3511 break;
3512 default:
3513 return -ERANGE;
3514 }
3515
3516 switch (config->rx_filter) {
3517 case HWTSTAMP_FILTER_NONE:
3518 tsync_rx_ctl = 0;
3519 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003520 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3521 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3522 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3523 is_l4 = true;
3524 break;
3525 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3526 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3527 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3528 is_l4 = true;
3529 break;
3530 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3531 /* Also time stamps V2 L2 Path Delay Request/Response */
3532 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3533 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3534 is_l2 = true;
3535 break;
3536 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3537 /* Also time stamps V2 L2 Path Delay Request/Response. */
3538 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3539 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3540 is_l2 = true;
3541 break;
3542 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3543 /* Hardware cannot filter just V2 L4 Sync messages;
3544 * fall-through to V2 (both L2 and L4) Sync.
3545 */
3546 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3547 /* Also time stamps V2 Path Delay Request/Response. */
3548 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3549 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3550 is_l2 = true;
3551 is_l4 = true;
3552 break;
3553 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3554 /* Hardware cannot filter just V2 L4 Delay Request messages;
3555 * fall-through to V2 (both L2 and L4) Delay Request.
3556 */
3557 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3558 /* Also time stamps V2 Path Delay Request/Response. */
3559 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3560 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3561 is_l2 = true;
3562 is_l4 = true;
3563 break;
3564 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3565 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3566 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3567 * fall-through to all V2 (both L2 and L4) Events.
3568 */
3569 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3570 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3571 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3572 is_l2 = true;
3573 is_l4 = true;
3574 break;
3575 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3576 /* For V1, the hardware can only filter Sync messages or
3577 * Delay Request messages but not both so fall-through to
3578 * time stamp all packets.
3579 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003580 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003581 is_l2 = true;
3582 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003583 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3584 config->rx_filter = HWTSTAMP_FILTER_ALL;
3585 break;
3586 default:
3587 return -ERANGE;
3588 }
3589
3590 /* enable/disable Tx h/w time stamping */
3591 regval = er32(TSYNCTXCTL);
3592 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3593 regval |= tsync_tx_ctl;
3594 ew32(TSYNCTXCTL, regval);
3595 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3596 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3597 e_err("Timesync Tx Control register not set as expected\n");
3598 return -EAGAIN;
3599 }
3600
3601 /* enable/disable Rx h/w time stamping */
3602 regval = er32(TSYNCRXCTL);
3603 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3604 regval |= tsync_rx_ctl;
3605 ew32(TSYNCRXCTL, regval);
3606 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3607 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3608 (regval & (E1000_TSYNCRXCTL_ENABLED |
3609 E1000_TSYNCRXCTL_TYPE_MASK))) {
3610 e_err("Timesync Rx Control register not set as expected\n");
3611 return -EAGAIN;
3612 }
3613
Bruce Alland89777b2013-01-19 01:09:58 +00003614 /* L2: define ethertype filter for time stamped packets */
3615 if (is_l2)
3616 rxmtrl |= ETH_P_1588;
3617
3618 /* define which PTP packets get time stamped */
3619 ew32(RXMTRL, rxmtrl);
3620
3621 /* Filter by destination port */
3622 if (is_l4) {
3623 rxudp = PTP_EV_PORT;
3624 cpu_to_be16s(&rxudp);
3625 }
3626 ew32(RXUDP, rxudp);
3627
3628 e1e_flush();
3629
Bruce Allanb67e1912012-12-27 08:32:33 +00003630 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003631 er32(RXSTMPH);
3632 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003633
3634 /* Get and set the System Time Register SYSTIM base frequency */
3635 ret_val = e1000e_get_base_timinca(adapter, &regval);
3636 if (ret_val)
3637 return ret_val;
3638 ew32(TIMINCA, regval);
3639
3640 /* reset the ns time counter */
3641 timecounter_init(&adapter->tc, &adapter->cc,
3642 ktime_to_ns(ktime_get_real()));
3643
3644 return 0;
3645}
3646
3647/**
Bruce Allanad680762008-03-28 09:15:03 -07003648 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649 * @adapter: private board structure
3650 **/
3651static void e1000_configure(struct e1000_adapter *adapter)
3652{
Bruce Allan55aa6982011-12-16 00:45:45 +00003653 struct e1000_ring *rx_ring = adapter->rx_ring;
3654
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003655 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656
3657 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003658 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003659
3660 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003661
3662 if (adapter->netdev->features & NETIF_F_RXHASH)
3663 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664 e1000_setup_rctl(adapter);
3665 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003666 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003667}
3668
3669/**
3670 * e1000e_power_up_phy - restore link in case the phy was powered down
3671 * @adapter: address of board private structure
3672 *
3673 * The phy may be powered down to save power and turn off link when the
3674 * driver is unloaded and wake on lan is not enabled (among others)
3675 * *** this routine MUST be followed by a call to e1000e_reset ***
3676 **/
3677void e1000e_power_up_phy(struct e1000_adapter *adapter)
3678{
Bruce Allan17f208d2009-12-01 15:47:22 +00003679 if (adapter->hw.phy.ops.power_up)
3680 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681
3682 adapter->hw.mac.ops.setup_link(&adapter->hw);
3683}
3684
3685/**
3686 * e1000_power_down_phy - Power down the PHY
3687 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003688 * Power down the PHY so no link is implied when interface is down.
3689 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690 */
3691static void e1000_power_down_phy(struct e1000_adapter *adapter)
3692{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003694 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695 return;
3696
Bruce Allan17f208d2009-12-01 15:47:22 +00003697 if (adapter->hw.phy.ops.power_down)
3698 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699}
3700
3701/**
3702 * e1000e_reset - bring the hardware into a known good state
3703 *
3704 * This function boots the hardware and enables some settings that
3705 * require a configuration cycle of the hardware - those cannot be
3706 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003707 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003708 */
3709void e1000e_reset(struct e1000_adapter *adapter)
3710{
3711 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003712 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 struct e1000_hw *hw = &adapter->hw;
3714 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003715 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003716 u16 hwm;
3717
Bruce Allanad680762008-03-28 09:15:03 -07003718 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003719 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003720
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003721 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003722 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003723 * large enough to accommodate two full transmit packets,
3724 * rounded up to the next 1KB and expressed in KB. Likewise,
3725 * the Rx FIFO should be large enough to accommodate at least
3726 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003727 * expressed in KB.
3728 */
Auke Kokdf762462007-10-25 13:57:53 -07003729 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003731 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003732 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003733 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003734 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003735 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003736 */
3737 min_tx_space = (adapter->max_frame_size +
Bruce Allane5fe2542013-02-20 04:06:27 +00003738 sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 min_tx_space = ALIGN(min_tx_space, 1024);
3740 min_tx_space >>= 10;
3741 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003742 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 min_rx_space = ALIGN(min_rx_space, 1024);
3744 min_rx_space >>= 10;
3745
Bruce Allane921eb12012-11-28 09:28:37 +00003746 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003747 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003748 * allocation, take space away from current Rx allocation
3749 */
Auke Kokdf762462007-10-25 13:57:53 -07003750 if ((tx_space < min_tx_space) &&
3751 ((min_tx_space - tx_space) < pba)) {
3752 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753
Bruce Allane921eb12012-11-28 09:28:37 +00003754 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003755 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003756 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003757 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003758 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 }
Auke Kokdf762462007-10-25 13:57:53 -07003760
3761 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762 }
3763
Bruce Allane921eb12012-11-28 09:28:37 +00003764 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003765 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003766 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767 * (or the size used for early receive) above it in the Rx FIFO.
3768 * Set it to the lower of:
3769 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003770 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003771 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003772 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3773 fc->pause_time = 0xFFFF;
3774 else
3775 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003776 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003777 fc->current_mode = fc->requested_mode;
3778
3779 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003780 case e1000_ich9lan:
3781 case e1000_ich10lan:
3782 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3783 pba = 14;
3784 ew32(PBA, pba);
3785 fc->high_water = 0x2800;
3786 fc->low_water = fc->high_water - 8;
3787 break;
3788 }
3789 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003790 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003791 hwm = min(((pba << 10) * 9 / 10),
3792 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003793
3794 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3795 fc->low_water = fc->high_water - 8;
3796 break;
3797 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003798 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003799 * loads. If hangs persist, try disabling Tx flow control.
3800 */
3801 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3802 fc->high_water = 0x3500;
3803 fc->low_water = 0x1500;
3804 } else {
3805 fc->high_water = 0x5000;
3806 fc->low_water = 0x3000;
3807 }
Bruce Allana3055952010-05-10 15:02:12 +00003808 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003809 break;
3810 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003811 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003812 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003813
3814 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3815 fc->high_water = 0x05C20;
3816 fc->low_water = 0x05048;
3817 fc->pause_time = 0x0650;
3818 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003819 }
Bruce Allan347b5202012-12-08 00:35:35 +00003820
3821 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3822 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003823 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003824 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003825
Bruce Allane921eb12012-11-28 09:28:37 +00003826 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003827 * maximum size per Tx descriptor limited only to the transmit
3828 * allocation of the packet buffer minus 96 bytes with an upper
3829 * limit of 24KB due to receive synchronization limitations.
3830 */
3831 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3832 24 << 10);
3833
Bruce Allane921eb12012-11-28 09:28:37 +00003834 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003835 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003836 */
3837 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003838 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003839 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3840 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003841 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003842 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003843 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003844 }
3845 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3846 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003847 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003848 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3849 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003850 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003851 }
3852 }
3853
Auke Kokbc7f75f2007-09-17 12:30:59 -07003854 /* Allow time for pending master requests to run */
3855 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003856
Bruce Allane921eb12012-11-28 09:28:37 +00003857 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003858 * that the network interface is in control
3859 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003860 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003861 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003862
Auke Kokbc7f75f2007-09-17 12:30:59 -07003863 ew32(WUC, 0);
3864
3865 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003866 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003867
3868 e1000_update_mng_vlan(adapter);
3869
3870 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3871 ew32(VET, ETH_P_8021Q);
3872
3873 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003874
Bruce Allanb67e1912012-12-27 08:32:33 +00003875 /* initialize systim and reset the ns time counter */
3876 e1000e_config_hwtstamp(adapter);
3877
Bruce Alland495bcb2013-03-20 07:23:11 +00003878 /* Set EEE advertisement as appropriate */
3879 if (adapter->flags2 & FLAG2_HAS_EEE) {
3880 s32 ret_val;
3881 u16 adv_addr;
3882
3883 switch (hw->phy.type) {
3884 case e1000_phy_82579:
3885 adv_addr = I82579_EEE_ADVERTISEMENT;
3886 break;
3887 case e1000_phy_i217:
3888 adv_addr = I217_EEE_ADVERTISEMENT;
3889 break;
3890 default:
3891 dev_err(&adapter->pdev->dev,
3892 "Invalid PHY type setting EEE advertisement\n");
3893 return;
3894 }
3895
3896 ret_val = hw->phy.ops.acquire(hw);
3897 if (ret_val) {
3898 dev_err(&adapter->pdev->dev,
3899 "EEE advertisement - unable to acquire PHY\n");
3900 return;
3901 }
3902
3903 e1000_write_emi_reg_locked(hw, adv_addr,
3904 hw->dev_spec.ich8lan.eee_disable ?
3905 0 : adapter->eee_advert);
3906
3907 hw->phy.ops.release(hw);
3908 }
3909
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003910 if (!netif_running(adapter->netdev) &&
3911 !test_bit(__E1000_TESTING, &adapter->state)) {
3912 e1000_power_down_phy(adapter);
3913 return;
3914 }
3915
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916 e1000_get_phy_info(hw);
3917
Bruce Allan918d7192009-06-02 11:28:20 +00003918 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3919 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003920 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003921 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003923 * different we would do if it failed
3924 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3926 phy_data &= ~IGP02E1000_PM_SPD;
3927 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3928 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003929}
3930
3931int e1000e_up(struct e1000_adapter *adapter)
3932{
3933 struct e1000_hw *hw = &adapter->hw;
3934
3935 /* hardware has been reset, we need to reload some things */
3936 e1000_configure(adapter);
3937
3938 clear_bit(__E1000_DOWN, &adapter->state);
3939
Bruce Allan4662e822008-08-26 18:37:06 -07003940 if (adapter->msix_entries)
3941 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942 e1000_irq_enable(adapter);
3943
Bruce Allan400484f2011-05-13 07:20:03 +00003944 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003945
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003947 if (adapter->msix_entries)
3948 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3949 else
3950 ew32(ICS, E1000_ICS_LSC);
3951
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 return 0;
3953}
3954
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003955static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3956{
3957 struct e1000_hw *hw = &adapter->hw;
3958
3959 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3960 return;
3961
3962 /* flush pending descriptor writebacks to memory */
3963 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3964 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3965
3966 /* execute the writes immediately */
3967 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003968
Bruce Allane921eb12012-11-28 09:28:37 +00003969 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003970 * write is successful
3971 */
3972 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3973 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3974
3975 /* execute the writes immediately */
3976 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003977}
3978
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003979static void e1000e_update_stats(struct e1000_adapter *adapter);
3980
Auke Kokbc7f75f2007-09-17 12:30:59 -07003981void e1000e_down(struct e1000_adapter *adapter)
3982{
3983 struct net_device *netdev = adapter->netdev;
3984 struct e1000_hw *hw = &adapter->hw;
3985 u32 tctl, rctl;
3986
Bruce Allane921eb12012-11-28 09:28:37 +00003987 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003988 * reschedule our watchdog timer
3989 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 set_bit(__E1000_DOWN, &adapter->state);
3991
3992 /* disable receives in the hardware */
3993 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003994 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3995 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 /* flush and sleep below */
3997
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003998 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999
4000 /* disable transmits in the hardware */
4001 tctl = er32(TCTL);
4002 tctl &= ~E1000_TCTL_EN;
4003 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004004
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 /* flush both disables and wait for them to finish */
4006 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004007 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 e1000_irq_disable(adapter);
4010
4011 del_timer_sync(&adapter->watchdog_timer);
4012 del_timer_sync(&adapter->phy_info_timer);
4013
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004015
4016 spin_lock(&adapter->stats64_lock);
4017 e1000e_update_stats(adapter);
4018 spin_unlock(&adapter->stats64_lock);
4019
Bruce Allan400484f2011-05-13 07:20:03 +00004020 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004021 e1000_clean_tx_ring(adapter->tx_ring);
4022 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004023
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 adapter->link_speed = 0;
4025 adapter->link_duplex = 0;
4026
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004027 if (!pci_channel_offline(adapter->pdev))
4028 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004029
Bruce Allane921eb12012-11-28 09:28:37 +00004030 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004031 * pci_disable_device here.
4032 */
4033}
4034
4035void e1000e_reinit_locked(struct e1000_adapter *adapter)
4036{
4037 might_sleep();
4038 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004039 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040 e1000e_down(adapter);
4041 e1000e_up(adapter);
4042 clear_bit(__E1000_RESETTING, &adapter->state);
4043}
4044
4045/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004046 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4047 * @cc: cyclecounter structure
4048 **/
4049static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4050{
4051 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4052 cc);
4053 struct e1000_hw *hw = &adapter->hw;
4054 cycle_t systim;
4055
4056 /* latch SYSTIMH on read of SYSTIML */
4057 systim = (cycle_t)er32(SYSTIML);
4058 systim |= (cycle_t)er32(SYSTIMH) << 32;
4059
4060 return systim;
4061}
4062
4063/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4065 * @adapter: board private structure to initialize
4066 *
4067 * e1000_sw_init initializes the Adapter private data structure.
4068 * Fields are initialized based on PCI device information and
4069 * OS network device settings (MTU size).
4070 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004071static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004073 struct net_device *netdev = adapter->netdev;
4074
4075 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4076 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004077 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4078 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004079 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4080 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004082 spin_lock_init(&adapter->stats64_lock);
4083
Bruce Allan4662e822008-08-26 18:37:06 -07004084 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085
Bruce Allan4662e822008-08-26 18:37:06 -07004086 if (e1000_alloc_queues(adapter))
4087 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088
Bruce Allanb67e1912012-12-27 08:32:33 +00004089 /* Setup hardware time stamping cyclecounter */
4090 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4091 adapter->cc.read = e1000e_cyclecounter_read;
4092 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4093 adapter->cc.mult = 1;
4094 /* cc.shift set in e1000e_get_base_tininca() */
4095
4096 spin_lock_init(&adapter->systim_lock);
4097 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4098 }
4099
Auke Kokbc7f75f2007-09-17 12:30:59 -07004100 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004101 e1000_irq_disable(adapter);
4102
Auke Kokbc7f75f2007-09-17 12:30:59 -07004103 set_bit(__E1000_DOWN, &adapter->state);
4104 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004105}
4106
4107/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004108 * e1000_intr_msi_test - Interrupt Handler
4109 * @irq: interrupt number
4110 * @data: pointer to a network interface device structure
4111 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004112static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004113{
4114 struct net_device *netdev = data;
4115 struct e1000_adapter *adapter = netdev_priv(netdev);
4116 struct e1000_hw *hw = &adapter->hw;
4117 u32 icr = er32(ICR);
4118
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004119 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004120 if (icr & E1000_ICR_RXSEQ) {
4121 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004122 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004123 * interrupt is handled.
4124 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004125 wmb();
4126 }
4127
4128 return IRQ_HANDLED;
4129}
4130
4131/**
4132 * e1000_test_msi_interrupt - Returns 0 for successful test
4133 * @adapter: board private struct
4134 *
4135 * code flow taken from tg3.c
4136 **/
4137static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4138{
4139 struct net_device *netdev = adapter->netdev;
4140 struct e1000_hw *hw = &adapter->hw;
4141 int err;
4142
4143 /* poll_enable hasn't been called yet, so don't need disable */
4144 /* clear any pending events */
4145 er32(ICR);
4146
4147 /* free the real vector and request a test handler */
4148 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004149 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004150
4151 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004152 * MSI irq handler will unset this flag
4153 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004154 adapter->flags |= FLAG_MSI_TEST_FAILED;
4155
4156 err = pci_enable_msi(adapter->pdev);
4157 if (err)
4158 goto msi_test_failed;
4159
Joe Perchesa0607fd2009-11-18 23:29:17 -08004160 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004161 netdev->name, netdev);
4162 if (err) {
4163 pci_disable_msi(adapter->pdev);
4164 goto msi_test_failed;
4165 }
4166
Bruce Allane921eb12012-11-28 09:28:37 +00004167 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004168 * interrupt.
4169 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004170 wmb();
4171
4172 e1000_irq_enable(adapter);
4173
4174 /* fire an unusual interrupt on the test handler */
4175 ew32(ICS, E1000_ICS_RXSEQ);
4176 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004177 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004178
4179 e1000_irq_disable(adapter);
4180
Bruce Allanbc763292012-08-17 06:18:07 +00004181 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004182
4183 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004184 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004185 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004186 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004187 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004188 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004189
4190 free_irq(adapter->pdev->irq, netdev);
4191 pci_disable_msi(adapter->pdev);
4192
Bruce Allanf8d59f72008-08-08 18:36:11 -07004193msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004194 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004195 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004196}
4197
4198/**
4199 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4200 * @adapter: board private struct
4201 *
4202 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4203 **/
4204static int e1000_test_msi(struct e1000_adapter *adapter)
4205{
4206 int err;
4207 u16 pci_cmd;
4208
4209 if (!(adapter->flags & FLAG_MSI_ENABLED))
4210 return 0;
4211
4212 /* disable SERR in case the MSI write causes a master abort */
4213 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004214 if (pci_cmd & PCI_COMMAND_SERR)
4215 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4216 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004217
4218 err = e1000_test_msi_interrupt(adapter);
4219
Dean Nelson36f24072010-06-29 18:12:05 +00004220 /* re-enable SERR */
4221 if (pci_cmd & PCI_COMMAND_SERR) {
4222 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4223 pci_cmd |= PCI_COMMAND_SERR;
4224 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4225 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004226
Bruce Allanf8d59f72008-08-08 18:36:11 -07004227 return err;
4228}
4229
4230/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231 * e1000_open - Called when a network interface is made active
4232 * @netdev: network interface device structure
4233 *
4234 * Returns 0 on success, negative value on failure
4235 *
4236 * The open entry point is called when a network interface is made
4237 * active by the system (IFF_UP). At this point all resources needed
4238 * for transmit and receive operations are allocated, the interrupt
4239 * handler is registered with the OS, the watchdog timer is started,
4240 * and the stack is notified that the interface is ready.
4241 **/
4242static int e1000_open(struct net_device *netdev)
4243{
4244 struct e1000_adapter *adapter = netdev_priv(netdev);
4245 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004246 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004247 int err;
4248
4249 /* disallow open during test */
4250 if (test_bit(__E1000_TESTING, &adapter->state))
4251 return -EBUSY;
4252
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004253 pm_runtime_get_sync(&pdev->dev);
4254
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004255 netif_carrier_off(netdev);
4256
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004258 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 if (err)
4260 goto err_setup_tx;
4261
4262 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004263 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 if (err)
4265 goto err_setup_rx;
4266
Bruce Allane921eb12012-11-28 09:28:37 +00004267 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004268 * interface is now open and reset the part to a known state.
4269 */
4270 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004271 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004272 e1000e_reset(adapter);
4273 }
4274
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 e1000e_power_up_phy(adapter);
4276
4277 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Bruce Allane5fe2542013-02-20 04:06:27 +00004278 if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004279 e1000_update_mng_vlan(adapter);
4280
Bruce Allan79d4e902011-12-16 00:46:27 +00004281 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004282 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4283 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004284
Bruce Allane921eb12012-11-28 09:28:37 +00004285 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004286 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4287 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004288 * clean_rx handler before we do so.
4289 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290 e1000_configure(adapter);
4291
4292 err = e1000_request_irq(adapter);
4293 if (err)
4294 goto err_req_irq;
4295
Bruce Allane921eb12012-11-28 09:28:37 +00004296 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004297 * ignore e1000e MSI messages, which means we need to test our MSI
4298 * interrupt now
4299 */
Bruce Allan4662e822008-08-26 18:37:06 -07004300 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004301 err = e1000_test_msi(adapter);
4302 if (err) {
4303 e_err("Interrupt allocation failed\n");
4304 goto err_req_irq;
4305 }
4306 }
4307
Auke Kokbc7f75f2007-09-17 12:30:59 -07004308 /* From here on the code is the same as e1000e_up() */
4309 clear_bit(__E1000_DOWN, &adapter->state);
4310
4311 napi_enable(&adapter->napi);
4312
4313 e1000_irq_enable(adapter);
4314
Jeff Kirsher09357b02011-11-18 14:25:00 +00004315 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004316 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004317
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004318 adapter->idle_check = true;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00004319 hw->mac.get_link_status = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004320 pm_runtime_put(&pdev->dev);
4321
Auke Kokbc7f75f2007-09-17 12:30:59 -07004322 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004323 if (adapter->msix_entries)
4324 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4325 else
4326 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004327
4328 return 0;
4329
4330err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004331 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004332 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004333 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004334err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004335 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336err_setup_tx:
4337 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004338 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004339
4340 return err;
4341}
4342
4343/**
4344 * e1000_close - Disables a network interface
4345 * @netdev: network interface device structure
4346 *
4347 * Returns 0, this is not allowed to fail
4348 *
4349 * The close entry point is called when an interface is de-activated
4350 * by the OS. The hardware is still under the drivers control, but
4351 * needs to be disabled. A global MAC reset is issued to stop the
4352 * hardware, and all transmit and receive resources are freed.
4353 **/
4354static int e1000_close(struct net_device *netdev)
4355{
4356 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004357 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004358 int count = E1000_CHECK_RESET_COUNT;
4359
4360 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4361 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004362
4363 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004364
4365 pm_runtime_get_sync(&pdev->dev);
4366
Bruce Allan5f4a7802011-11-29 08:09:19 +00004367 napi_disable(&adapter->napi);
4368
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004369 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4370 e1000e_down(adapter);
4371 e1000_free_irq(adapter);
4372 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004373 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004374
Bruce Allan55aa6982011-12-16 00:45:45 +00004375 e1000e_free_tx_resources(adapter->tx_ring);
4376 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004377
Bruce Allane921eb12012-11-28 09:28:37 +00004378 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004379 * the same ID is registered on the host OS (let 8021q kill it)
4380 */
Bruce Allane5fe2542013-02-20 04:06:27 +00004381 if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4383
Bruce Allane921eb12012-11-28 09:28:37 +00004384 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004385 * interface is now closed
4386 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004387 if ((adapter->flags & FLAG_HAS_AMT) &&
4388 !test_bit(__E1000_TESTING, &adapter->state))
4389 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004390
Bruce Allan3e35d992013-01-12 07:25:22 +00004391 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004392
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004393 pm_runtime_put_sync(&pdev->dev);
4394
Auke Kokbc7f75f2007-09-17 12:30:59 -07004395 return 0;
4396}
Bruce Allanfc830b72013-02-20 04:06:11 +00004397
Auke Kokbc7f75f2007-09-17 12:30:59 -07004398/**
4399 * e1000_set_mac - Change the Ethernet Address of the NIC
4400 * @netdev: network interface device structure
4401 * @p: pointer to an address structure
4402 *
4403 * Returns 0 on success, negative on failure
4404 **/
4405static int e1000_set_mac(struct net_device *netdev, void *p)
4406{
4407 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004408 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004409 struct sockaddr *addr = p;
4410
4411 if (!is_valid_ether_addr(addr->sa_data))
4412 return -EADDRNOTAVAIL;
4413
4414 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4415 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4416
Bruce Allan69e1e012012-04-14 03:28:50 +00004417 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418
4419 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4420 /* activate the work around */
4421 e1000e_set_laa_state_82571(&adapter->hw, 1);
4422
Bruce Allane921eb12012-11-28 09:28:37 +00004423 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 * between the time RAR[0] gets clobbered and the time it
4425 * gets fixed (in e1000_watchdog), the actual LAA is in one
4426 * of the RARs and no incoming packets directed to this port
4427 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004428 * RAR[14]
4429 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004430 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4431 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432 }
4433
4434 return 0;
4435}
4436
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004437/**
4438 * e1000e_update_phy_task - work thread to update phy
4439 * @work: pointer to our work struct
4440 *
4441 * this worker thread exists because we must acquire a
4442 * semaphore to read the phy, which we could msleep while
4443 * waiting for it, and we can't msleep in a timer.
4444 **/
4445static void e1000e_update_phy_task(struct work_struct *work)
4446{
4447 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004448 struct e1000_adapter,
4449 update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004450
4451 if (test_bit(__E1000_DOWN, &adapter->state))
4452 return;
4453
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004454 e1000_get_phy_info(&adapter->hw);
4455}
4456
Bruce Allane921eb12012-11-28 09:28:37 +00004457/**
4458 * e1000_update_phy_info - timre call-back to update PHY info
4459 * @data: pointer to adapter cast into an unsigned long
4460 *
Bruce Allanad680762008-03-28 09:15:03 -07004461 * Need to wait a few seconds after link up to get diagnostic information from
4462 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004463 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004464static void e1000_update_phy_info(unsigned long data)
4465{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004466 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004467
4468 if (test_bit(__E1000_DOWN, &adapter->state))
4469 return;
4470
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004471 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004472}
4473
4474/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004475 * e1000e_update_phy_stats - Update the PHY statistics counters
4476 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004477 *
4478 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004479 **/
4480static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4481{
4482 struct e1000_hw *hw = &adapter->hw;
4483 s32 ret_val;
4484 u16 phy_data;
4485
4486 ret_val = hw->phy.ops.acquire(hw);
4487 if (ret_val)
4488 return;
4489
Bruce Allane921eb12012-11-28 09:28:37 +00004490 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004491 * If not, set to the page with the PHY status registers.
4492 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004493 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004494 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4495 &phy_data);
4496 if (ret_val)
4497 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004498 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4499 ret_val = hw->phy.ops.set_page(hw,
4500 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004501 if (ret_val)
4502 goto release;
4503 }
4504
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004505 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004506 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4507 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004508 if (!ret_val)
4509 adapter->stats.scc += phy_data;
4510
4511 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004512 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4513 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004514 if (!ret_val)
4515 adapter->stats.ecol += phy_data;
4516
4517 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004518 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4519 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004520 if (!ret_val)
4521 adapter->stats.mcc += phy_data;
4522
4523 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004524 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4525 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004526 if (!ret_val)
4527 adapter->stats.latecol += phy_data;
4528
4529 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004530 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4531 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004532 if (!ret_val)
4533 hw->mac.collision_delta = phy_data;
4534
4535 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004536 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4537 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004538 if (!ret_val)
4539 adapter->stats.dc += phy_data;
4540
4541 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004542 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4543 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004544 if (!ret_val)
4545 adapter->stats.tncrs += phy_data;
4546
4547release:
4548 hw->phy.ops.release(hw);
4549}
4550
4551/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552 * e1000e_update_stats - Update the board statistics counters
4553 * @adapter: board private structure
4554 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004555static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004557 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558 struct e1000_hw *hw = &adapter->hw;
4559 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560
Bruce Allane921eb12012-11-28 09:28:37 +00004561 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562 * connection is down.
4563 */
4564 if (adapter->link_speed == 0)
4565 return;
4566 if (pci_channel_offline(pdev))
4567 return;
4568
Auke Kokbc7f75f2007-09-17 12:30:59 -07004569 adapter->stats.crcerrs += er32(CRCERRS);
4570 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004571 adapter->stats.gorc += er32(GORCL);
4572 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 adapter->stats.bprc += er32(BPRC);
4574 adapter->stats.mprc += er32(MPRC);
4575 adapter->stats.roc += er32(ROC);
4576
Auke Kokbc7f75f2007-09-17 12:30:59 -07004577 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004578
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004579 /* Half-duplex statistics */
4580 if (adapter->link_duplex == HALF_DUPLEX) {
4581 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4582 e1000e_update_phy_stats(adapter);
4583 } else {
4584 adapter->stats.scc += er32(SCC);
4585 adapter->stats.ecol += er32(ECOL);
4586 adapter->stats.mcc += er32(MCC);
4587 adapter->stats.latecol += er32(LATECOL);
4588 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004589
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004590 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004591
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004592 if ((hw->mac.type != e1000_82574) &&
4593 (hw->mac.type != e1000_82583))
4594 adapter->stats.tncrs += er32(TNCRS);
4595 }
4596 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004597 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004598
Auke Kokbc7f75f2007-09-17 12:30:59 -07004599 adapter->stats.xonrxc += er32(XONRXC);
4600 adapter->stats.xontxc += er32(XONTXC);
4601 adapter->stats.xoffrxc += er32(XOFFRXC);
4602 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004603 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004604 adapter->stats.gotc += er32(GOTCL);
4605 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 adapter->stats.rnbc += er32(RNBC);
4607 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608
4609 adapter->stats.mptc += er32(MPTC);
4610 adapter->stats.bptc += er32(BPTC);
4611
4612 /* used for adaptive IFS */
4613
4614 hw->mac.tx_packet_delta = er32(TPT);
4615 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004616
4617 adapter->stats.algnerrc += er32(ALGNERRC);
4618 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004619 adapter->stats.cexterr += er32(CEXTERR);
4620 adapter->stats.tsctc += er32(TSCTC);
4621 adapter->stats.tsctfc += er32(TSCTFC);
4622
Auke Kokbc7f75f2007-09-17 12:30:59 -07004623 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004624 netdev->stats.multicast = adapter->stats.mprc;
4625 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004626
4627 /* Rx Errors */
4628
Bruce Allane921eb12012-11-28 09:28:37 +00004629 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004630 * our own version based on RUC and ROC
4631 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004632 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004633 adapter->stats.crcerrs + adapter->stats.algnerrc +
4634 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004635 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004636 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004637 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4638 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4639 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004640
4641 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004642 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004643 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4644 netdev->stats.tx_window_errors = adapter->stats.latecol;
4645 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004646
4647 /* Tx Dropped needs to be maintained elsewhere */
4648
Auke Kokbc7f75f2007-09-17 12:30:59 -07004649 /* Management Stats */
4650 adapter->stats.mgptc += er32(MGTPTC);
4651 adapter->stats.mgprc += er32(MGTPRC);
4652 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004653
4654 /* Correctable ECC Errors */
4655 if (hw->mac.type == e1000_pch_lpt) {
4656 u32 pbeccsts = er32(PBECCSTS);
4657 adapter->corr_errors +=
4658 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4659 adapter->uncorr_errors +=
4660 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4661 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4662 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663}
4664
Bruce Allan7c257692008-04-23 11:09:00 -07004665/**
4666 * e1000_phy_read_status - Update the PHY register status snapshot
4667 * @adapter: board private structure
4668 **/
4669static void e1000_phy_read_status(struct e1000_adapter *adapter)
4670{
4671 struct e1000_hw *hw = &adapter->hw;
4672 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004673
4674 if ((er32(STATUS) & E1000_STATUS_LU) &&
4675 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004676 int ret_val;
4677
Konstantin Khlebnikove60b22c2013-03-05 09:43:09 +00004678 pm_runtime_get_sync(&adapter->pdev->dev);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004679 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4680 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4681 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4682 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4683 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4684 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4685 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4686 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004687 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004688 e_warn("Error reading PHY register\n");
Konstantin Khlebnikove60b22c2013-03-05 09:43:09 +00004689 pm_runtime_put_sync(&adapter->pdev->dev);
Bruce Allan7c257692008-04-23 11:09:00 -07004690 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004691 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004692 * Set values to typical power-on defaults
4693 */
4694 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4695 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4696 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4697 BMSR_ERCAP);
4698 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4699 ADVERTISE_ALL | ADVERTISE_CSMA);
4700 phy->lpa = 0;
4701 phy->expansion = EXPANSION_ENABLENPAGE;
4702 phy->ctrl1000 = ADVERTISE_1000FULL;
4703 phy->stat1000 = 0;
4704 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4705 }
Bruce Allan7c257692008-04-23 11:09:00 -07004706}
4707
Auke Kokbc7f75f2007-09-17 12:30:59 -07004708static void e1000_print_link_info(struct e1000_adapter *adapter)
4709{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004710 struct e1000_hw *hw = &adapter->hw;
4711 u32 ctrl = er32(CTRL);
4712
Bruce Allan8f12fe82008-11-21 16:54:43 -08004713 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004714 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4715 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004716 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4717 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4718 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4719 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004720}
4721
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004722static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004723{
4724 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004725 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004726 s32 ret_val = 0;
4727
Bruce Allane921eb12012-11-28 09:28:37 +00004728 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004729 * Rx sequence error interrupt. get_link_status will stay
4730 * false until the check_for_link establishes link
4731 * for copper adapters ONLY
4732 */
4733 switch (hw->phy.media_type) {
4734 case e1000_media_type_copper:
4735 if (hw->mac.get_link_status) {
4736 ret_val = hw->mac.ops.check_for_link(hw);
4737 link_active = !hw->mac.get_link_status;
4738 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004739 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004740 }
4741 break;
4742 case e1000_media_type_fiber:
4743 ret_val = hw->mac.ops.check_for_link(hw);
4744 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4745 break;
4746 case e1000_media_type_internal_serdes:
4747 ret_val = hw->mac.ops.check_for_link(hw);
4748 link_active = adapter->hw.mac.serdes_has_link;
4749 break;
4750 default:
4751 case e1000_media_type_unknown:
4752 break;
4753 }
4754
4755 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4756 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4757 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004758 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004759 }
4760
4761 return link_active;
4762}
4763
4764static void e1000e_enable_receives(struct e1000_adapter *adapter)
4765{
4766 /* make sure the receive unit is started */
4767 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004768 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004769 struct e1000_hw *hw = &adapter->hw;
4770 u32 rctl = er32(RCTL);
4771 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004772 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004773 }
4774}
4775
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004776static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4777{
4778 struct e1000_hw *hw = &adapter->hw;
4779
Bruce Allane921eb12012-11-28 09:28:37 +00004780 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004781 * for hung state and reset, if two calls return true
4782 */
4783 if (e1000_check_phy_82574(hw))
4784 adapter->phy_hang_count++;
4785 else
4786 adapter->phy_hang_count = 0;
4787
4788 if (adapter->phy_hang_count > 1) {
4789 adapter->phy_hang_count = 0;
4790 schedule_work(&adapter->reset_task);
4791 }
4792}
4793
Auke Kokbc7f75f2007-09-17 12:30:59 -07004794/**
4795 * e1000_watchdog - Timer Call-back
4796 * @data: pointer to adapter cast into an unsigned long
4797 **/
4798static void e1000_watchdog(unsigned long data)
4799{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004800 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004801
4802 /* Do the rest outside of interrupt context */
4803 schedule_work(&adapter->watchdog_task);
4804
4805 /* TODO: make this use queue_delayed_work() */
4806}
4807
4808static void e1000_watchdog_task(struct work_struct *work)
4809{
4810 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004811 struct e1000_adapter,
4812 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813 struct net_device *netdev = adapter->netdev;
4814 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004815 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816 struct e1000_ring *tx_ring = adapter->tx_ring;
4817 struct e1000_hw *hw = &adapter->hw;
4818 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004819
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004820 if (test_bit(__E1000_DOWN, &adapter->state))
4821 return;
4822
David S. Millerb405e8d2010-02-04 22:31:41 -08004823 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004824 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004825 /* Cancel scheduled suspend requests. */
4826 pm_runtime_resume(netdev->dev.parent);
4827
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004828 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004829 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004830 }
4831
4832 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4833 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4834 e1000_update_mng_vlan(adapter);
4835
Auke Kokbc7f75f2007-09-17 12:30:59 -07004836 if (link) {
4837 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004838 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004839
4840 /* Cancel scheduled suspend requests. */
4841 pm_runtime_resume(netdev->dev.parent);
4842
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004843 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004844 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004846 &adapter->link_speed,
4847 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004848 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004849
4850 /* check if SmartSpeed worked */
4851 e1000e_check_downshift(hw);
4852 if (phy->speed_downgraded)
4853 netdev_warn(netdev,
4854 "Link Speed was downgraded by SmartSpeed\n");
4855
Bruce Allane921eb12012-11-28 09:28:37 +00004856 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004857 * if link has autonegotiated at 10/100 half
4858 */
4859 if ((hw->phy.type == e1000_phy_igp_3 ||
4860 hw->phy.type == e1000_phy_bm) &&
4861 (hw->mac.autoneg == true) &&
4862 (adapter->link_speed == SPEED_10 ||
4863 adapter->link_speed == SPEED_100) &&
4864 (adapter->link_duplex == HALF_DUPLEX)) {
4865 u16 autoneg_exp;
4866
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004867 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004868
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004869 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004870 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 -07004871 }
4872
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004873 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 adapter->tx_timeout_factor = 1;
4875 switch (adapter->link_speed) {
4876 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004877 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004878 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004879 break;
4880 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004881 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004882 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004883 break;
4884 }
4885
Bruce Allane921eb12012-11-28 09:28:37 +00004886 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004887 * link-up event
4888 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004889 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4890 !txb2b) {
4891 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004892 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004893 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004894 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004895 }
4896
Bruce Allane921eb12012-11-28 09:28:37 +00004897 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004898 * some hardware issues
4899 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4901 switch (adapter->link_speed) {
4902 case SPEED_10:
4903 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004904 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004905 netdev->features &= ~NETIF_F_TSO;
4906 netdev->features &= ~NETIF_F_TSO6;
4907 break;
4908 case SPEED_1000:
4909 netdev->features |= NETIF_F_TSO;
4910 netdev->features |= NETIF_F_TSO6;
4911 break;
4912 default:
4913 /* oops */
4914 break;
4915 }
4916 }
4917
Bruce Allane921eb12012-11-28 09:28:37 +00004918 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004919 * after setting TARC(0)
4920 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004921 tctl = er32(TCTL);
4922 tctl |= E1000_TCTL_EN;
4923 ew32(TCTL, tctl);
4924
Bruce Allane921eb12012-11-28 09:28:37 +00004925 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004926 * reporting link up.
4927 */
4928 if (phy->ops.cfg_on_link_up)
4929 phy->ops.cfg_on_link_up(hw);
4930
Auke Kokbc7f75f2007-09-17 12:30:59 -07004931 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932
4933 if (!test_bit(__E1000_DOWN, &adapter->state))
4934 mod_timer(&adapter->phy_info_timer,
4935 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004936 }
4937 } else {
4938 if (netif_carrier_ok(netdev)) {
4939 adapter->link_speed = 0;
4940 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004941 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004942 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004943 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004944 if (!test_bit(__E1000_DOWN, &adapter->state))
4945 mod_timer(&adapter->phy_info_timer,
4946 round_jiffies(jiffies + 2 * HZ));
4947
Bruce Allan12d43f72012-12-05 06:26:14 +00004948 /* The link is lost so the controller stops DMA.
4949 * If there is queued Tx work that cannot be done
4950 * or if on an 8000ES2LAN which requires a Rx packet
4951 * buffer work-around on link down event, reset the
4952 * controller to flush the Tx/Rx packet buffers.
4953 * (Do the reset outside of interrupt context).
4954 */
4955 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4956 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4957 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004958 else
4959 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004960 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004961 }
4962 }
4963
4964link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004965 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004966 e1000e_update_stats(adapter);
4967
4968 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4969 adapter->tpt_old = adapter->stats.tpt;
4970 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4971 adapter->colc_old = adapter->stats.colc;
4972
Bruce Allan7c257692008-04-23 11:09:00 -07004973 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4974 adapter->gorc_old = adapter->stats.gorc;
4975 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4976 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004977 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004978
Bruce Allan12d43f72012-12-05 06:26:14 +00004979 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004980 schedule_work(&adapter->reset_task);
4981 /* return immediately since reset is imminent */
4982 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983 }
4984
Bruce Allan12d43f72012-12-05 06:26:14 +00004985 e1000e_update_adaptive(&adapter->hw);
4986
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004987 /* Simple mode for Interrupt Throttle Rate (ITR) */
4988 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004989 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004990 * Total asymmetrical Tx or Rx gets ITR=8000;
4991 * everyone else is between 2000-8000.
4992 */
4993 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4994 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00004995 adapter->gotc - adapter->gorc :
4996 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004997 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4998
Matthew Vick22a4cca2012-07-12 00:02:42 +00004999 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00005000 }
5001
Bruce Allanad680762008-03-28 09:15:03 -07005002 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005003 if (adapter->msix_entries)
5004 ew32(ICS, adapter->rx_ring->ims_val);
5005 else
5006 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005007
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005008 /* flush pending descriptors to memory before detecting Tx hang */
5009 e1000e_flush_descriptors(adapter);
5010
Auke Kokbc7f75f2007-09-17 12:30:59 -07005011 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005012 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005013
Bruce Allane921eb12012-11-28 09:28:37 +00005014 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005015 * reset from the other port. Set the appropriate LAA in RAR[0]
5016 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005017 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005018 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005019
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005020 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5021 e1000e_check_82574_phy_workaround(adapter);
5022
Bruce Allanb67e1912012-12-27 08:32:33 +00005023 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5024 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5025 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5026 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5027 er32(RXSTMPH);
5028 adapter->rx_hwtstamp_cleared++;
5029 } else {
5030 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5031 }
5032 }
5033
Auke Kokbc7f75f2007-09-17 12:30:59 -07005034 /* Reset the timer */
5035 if (!test_bit(__E1000_DOWN, &adapter->state))
5036 mod_timer(&adapter->watchdog_timer,
5037 round_jiffies(jiffies + 2 * HZ));
5038}
5039
5040#define E1000_TX_FLAGS_CSUM 0x00000001
5041#define E1000_TX_FLAGS_VLAN 0x00000002
5042#define E1000_TX_FLAGS_TSO 0x00000004
5043#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005044#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005045#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5047#define E1000_TX_FLAGS_VLAN_SHIFT 16
5048
Bruce Allan55aa6982011-12-16 00:45:45 +00005049static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005051 struct e1000_context_desc *context_desc;
5052 struct e1000_buffer *buffer_info;
5053 unsigned int i;
5054 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005055 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005056 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005058 if (!skb_is_gso(skb))
5059 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005061 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005062 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5063
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005064 if (err)
5065 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005066 }
5067
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005068 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5069 mss = skb_shinfo(skb)->gso_size;
5070 if (skb->protocol == htons(ETH_P_IP)) {
5071 struct iphdr *iph = ip_hdr(skb);
5072 iph->tot_len = 0;
5073 iph->check = 0;
5074 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005075 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005076 cmd_length = E1000_TXD_CMD_IP;
5077 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005078 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005079 ipv6_hdr(skb)->payload_len = 0;
5080 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005081 &ipv6_hdr(skb)->daddr,
5082 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005083 ipcse = 0;
5084 }
5085 ipcss = skb_network_offset(skb);
5086 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5087 tucss = skb_transport_offset(skb);
5088 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005089
5090 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005091 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005092
5093 i = tx_ring->next_to_use;
5094 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5095 buffer_info = &tx_ring->buffer_info[i];
5096
5097 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5098 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5099 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5100 context_desc->upper_setup.tcp_fields.tucss = tucss;
5101 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005102 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005103 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5104 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5105 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5106
5107 buffer_info->time_stamp = jiffies;
5108 buffer_info->next_to_watch = i;
5109
5110 i++;
5111 if (i == tx_ring->count)
5112 i = 0;
5113 tx_ring->next_to_use = i;
5114
5115 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005116}
5117
Bruce Allan55aa6982011-12-16 00:45:45 +00005118static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005119{
Bruce Allan55aa6982011-12-16 00:45:45 +00005120 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005121 struct e1000_context_desc *context_desc;
5122 struct e1000_buffer *buffer_info;
5123 unsigned int i;
5124 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005125 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005126 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005127
Dave Grahamaf807c82008-10-09 14:28:58 -07005128 if (skb->ip_summed != CHECKSUM_PARTIAL)
5129 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005130
Arthur Jones5f66f202009-03-19 01:13:08 +00005131 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5132 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5133 else
5134 protocol = skb->protocol;
5135
Arthur Jones3f518392009-03-20 15:56:35 -07005136 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005137 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005138 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5139 cmd_len |= E1000_TXD_CMD_TCP;
5140 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005141 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005142 /* XXX not handling all IPV6 headers */
5143 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5144 cmd_len |= E1000_TXD_CMD_TCP;
5145 break;
5146 default:
5147 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005148 e_warn("checksum_partial proto=%x!\n",
5149 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005150 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005151 }
5152
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005153 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005154
5155 i = tx_ring->next_to_use;
5156 buffer_info = &tx_ring->buffer_info[i];
5157 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5158
5159 context_desc->lower_setup.ip_config = 0;
5160 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005161 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005162 context_desc->upper_setup.tcp_fields.tucse = 0;
5163 context_desc->tcp_seg_setup.data = 0;
5164 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5165
5166 buffer_info->time_stamp = jiffies;
5167 buffer_info->next_to_watch = i;
5168
5169 i++;
5170 if (i == tx_ring->count)
5171 i = 0;
5172 tx_ring->next_to_use = i;
5173
5174 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005175}
5176
Bruce Allan55aa6982011-12-16 00:45:45 +00005177static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5178 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005179 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005180{
Bruce Allan55aa6982011-12-16 00:45:45 +00005181 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005182 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005183 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005184 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005185 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005186 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187
5188 i = tx_ring->next_to_use;
5189
5190 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005191 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005192 size = min(len, max_per_txd);
5193
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005195 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005196 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005197 buffer_info->dma = dma_map_single(&pdev->dev,
5198 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005199 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005200 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005201 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005202 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005203
5204 len -= size;
5205 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005206 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005207
5208 if (len) {
5209 i++;
5210 if (i == tx_ring->count)
5211 i = 0;
5212 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 }
5214
5215 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005216 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005217
5218 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005219 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005220 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005221
5222 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005223 i++;
5224 if (i == tx_ring->count)
5225 i = 0;
5226
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227 buffer_info = &tx_ring->buffer_info[i];
5228 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229
5230 buffer_info->length = size;
5231 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005232 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005233 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005234 offset, size,
5235 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005236 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005237 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005238 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239
5240 len -= size;
5241 offset += size;
5242 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005243 }
5244 }
5245
Bruce Allanaf667a22010-12-31 06:10:01 +00005246 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005247 /* multiply data chunks by size of headers */
5248 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5249
Auke Kokbc7f75f2007-09-17 12:30:59 -07005250 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005251 tx_ring->buffer_info[i].segs = segs;
5252 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005253 tx_ring->buffer_info[first].next_to_watch = i;
5254
5255 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005256
5257dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005258 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005259 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005260 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005261 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005262
5263 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005264 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005265 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005266 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005267 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005268 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005269 }
5270
5271 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272}
5273
Bruce Allan55aa6982011-12-16 00:45:45 +00005274static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005275{
Bruce Allan55aa6982011-12-16 00:45:45 +00005276 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005277 struct e1000_tx_desc *tx_desc = NULL;
5278 struct e1000_buffer *buffer_info;
5279 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5280 unsigned int i;
5281
5282 if (tx_flags & E1000_TX_FLAGS_TSO) {
5283 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005284 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005285 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5286
5287 if (tx_flags & E1000_TX_FLAGS_IPV4)
5288 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5289 }
5290
5291 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5292 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5293 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5294 }
5295
5296 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5297 txd_lower |= E1000_TXD_CMD_VLE;
5298 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5299 }
5300
Ben Greear943146d2012-02-11 15:39:40 +00005301 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5302 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5303
Bruce Allanb67e1912012-12-27 08:32:33 +00005304 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5305 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5306 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5307 }
5308
Auke Kokbc7f75f2007-09-17 12:30:59 -07005309 i = tx_ring->next_to_use;
5310
Bruce Allan36b973d2010-11-24 07:42:43 +00005311 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005312 buffer_info = &tx_ring->buffer_info[i];
5313 tx_desc = E1000_TX_DESC(*tx_ring, i);
5314 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005315 tx_desc->lower.data = cpu_to_le32(txd_lower |
5316 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005317 tx_desc->upper.data = cpu_to_le32(txd_upper);
5318
5319 i++;
5320 if (i == tx_ring->count)
5321 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005322 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323
5324 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5325
Ben Greear943146d2012-02-11 15:39:40 +00005326 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5327 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5328 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5329
Bruce Allane921eb12012-11-28 09:28:37 +00005330 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005331 * know there are new descriptors to fetch. (Only
5332 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005333 * such as IA-64).
5334 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005335 wmb();
5336
5337 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005338
5339 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005340 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005341 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005342 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005343
Bruce Allane921eb12012-11-28 09:28:37 +00005344 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005345 * at a time, it synchronizes IO on IA64/Altix systems
5346 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005347 mmiowb();
5348}
5349
5350#define MINIMUM_DHCP_PACKET_SIZE 282
5351static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5352 struct sk_buff *skb)
5353{
5354 struct e1000_hw *hw = &adapter->hw;
5355 u16 length, offset;
5356
Bruce Alland60923c2012-12-05 06:26:56 +00005357 if (vlan_tx_tag_present(skb) &&
5358 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5359 (adapter->hw.mng_cookie.status &
5360 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5361 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005362
5363 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5364 return 0;
5365
Bruce Allan53aa82d2013-02-20 04:06:06 +00005366 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005367 return 0;
5368
5369 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005370 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005371 struct udphdr *udp;
5372
5373 if (ip->protocol != IPPROTO_UDP)
5374 return 0;
5375
5376 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5377 if (ntohs(udp->dest) != 67)
5378 return 0;
5379
5380 offset = (u8 *)udp + 8 - skb->data;
5381 length = skb->len - offset;
5382 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5383 }
5384
5385 return 0;
5386}
5387
Bruce Allan55aa6982011-12-16 00:45:45 +00005388static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005389{
Bruce Allan55aa6982011-12-16 00:45:45 +00005390 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005391
Bruce Allan55aa6982011-12-16 00:45:45 +00005392 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005393 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005394 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005395 * but since that doesn't exist yet, just open code it.
5396 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005397 smp_mb();
5398
Bruce Allane921eb12012-11-28 09:28:37 +00005399 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005400 * made room available.
5401 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005402 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403 return -EBUSY;
5404
5405 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005406 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005407 ++adapter->restart_queue;
5408 return 0;
5409}
5410
Bruce Allan55aa6982011-12-16 00:45:45 +00005411static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005412{
Bruce Alland821a4c2012-08-24 20:38:11 +00005413 BUG_ON(size > tx_ring->count);
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 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005417 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005418}
5419
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005420static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5421 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422{
5423 struct e1000_adapter *adapter = netdev_priv(netdev);
5424 struct e1000_ring *tx_ring = adapter->tx_ring;
5425 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005426 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005427 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005428 unsigned int nr_frags;
5429 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430 int count = 0;
5431 int tso;
5432 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005433
5434 if (test_bit(__E1000_DOWN, &adapter->state)) {
5435 dev_kfree_skb_any(skb);
5436 return NETDEV_TX_OK;
5437 }
5438
5439 if (skb->len <= 0) {
5440 dev_kfree_skb_any(skb);
5441 return NETDEV_TX_OK;
5442 }
5443
Bruce Allane921eb12012-11-28 09:28:37 +00005444 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005445 * pad skb in order to meet this minimum size requirement
5446 */
5447 if (unlikely(skb->len < 17)) {
5448 if (skb_pad(skb, 17 - skb->len))
5449 return NETDEV_TX_OK;
5450 skb->len = 17;
5451 skb_set_tail_pointer(skb, 17);
5452 }
5453
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005455 if (mss) {
5456 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005457
Bruce Allane921eb12012-11-28 09:28:37 +00005458 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005459 * points to just header, pull a few bytes of payload from
5460 * frags into skb->data
5461 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005463 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005464 * avoiding it could save a lot of cycles
5465 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005466 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467 unsigned int pull_size;
5468
Bruce Allana2a5b322012-01-31 06:37:17 +00005469 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005470 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005471 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472 dev_kfree_skb_any(skb);
5473 return NETDEV_TX_OK;
5474 }
Eric Dumazete743d312010-04-14 15:59:40 -07005475 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005476 }
5477 }
5478
5479 /* reserve a descriptor for the offload context */
5480 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5481 count++;
5482 count++;
5483
Bruce Alland821a4c2012-08-24 20:38:11 +00005484 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005485
5486 nr_frags = skb_shinfo(skb)->nr_frags;
5487 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005488 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5489 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490
5491 if (adapter->hw.mac.tx_pkt_filtering)
5492 e1000_transfer_dhcp_info(adapter, skb);
5493
Bruce Allane921eb12012-11-28 09:28:37 +00005494 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005495 * head, otherwise try next time
5496 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005497 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005498 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005499
Jesse Grosseab6d182010-10-20 13:56:03 +00005500 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005501 tx_flags |= E1000_TX_FLAGS_VLAN;
5502 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5503 }
5504
5505 first = tx_ring->next_to_use;
5506
Bruce Allan55aa6982011-12-16 00:45:45 +00005507 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005508 if (tso < 0) {
5509 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005510 return NETDEV_TX_OK;
5511 }
5512
5513 if (tso)
5514 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005515 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005516 tx_flags |= E1000_TX_FLAGS_CSUM;
5517
Bruce Allane921eb12012-11-28 09:28:37 +00005518 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005519 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005520 * no longer assume, we must.
5521 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005522 if (skb->protocol == htons(ETH_P_IP))
5523 tx_flags |= E1000_TX_FLAGS_IPV4;
5524
Ben Greear943146d2012-02-11 15:39:40 +00005525 if (unlikely(skb->no_fcs))
5526 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5527
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005528 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005529 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5530 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005531 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005532 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5533 !adapter->tx_hwtstamp_skb)) {
5534 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5535 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5536 adapter->tx_hwtstamp_skb = skb_get(skb);
5537 schedule_work(&adapter->tx_hwtstamp_work);
5538 } else {
5539 skb_tx_timestamp(skb);
5540 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005541
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005542 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005543 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005544 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005545 e1000_maybe_stop_tx(tx_ring,
5546 (MAX_SKB_FRAGS *
5547 DIV_ROUND_UP(PAGE_SIZE,
5548 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005549 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005550 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005551 tx_ring->buffer_info[first].time_stamp = 0;
5552 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005553 }
5554
Auke Kokbc7f75f2007-09-17 12:30:59 -07005555 return NETDEV_TX_OK;
5556}
5557
5558/**
5559 * e1000_tx_timeout - Respond to a Tx Hang
5560 * @netdev: network interface device structure
5561 **/
5562static void e1000_tx_timeout(struct net_device *netdev)
5563{
5564 struct e1000_adapter *adapter = netdev_priv(netdev);
5565
5566 /* Do the reset outside of interrupt context */
5567 adapter->tx_timeout_count++;
5568 schedule_work(&adapter->reset_task);
5569}
5570
5571static void e1000_reset_task(struct work_struct *work)
5572{
5573 struct e1000_adapter *adapter;
5574 adapter = container_of(work, struct e1000_adapter, reset_task);
5575
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005576 /* don't run the task if already down */
5577 if (test_bit(__E1000_DOWN, &adapter->state))
5578 return;
5579
Bruce Allan12d43f72012-12-05 06:26:14 +00005580 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005581 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005582 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005583 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005584 e1000e_reinit_locked(adapter);
5585}
5586
5587/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005588 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005589 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005590 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005591 *
5592 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005593 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005594struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005595 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005596{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005597 struct e1000_adapter *adapter = netdev_priv(netdev);
5598
5599 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5600 spin_lock(&adapter->stats64_lock);
5601 e1000e_update_stats(adapter);
5602 /* Fill out the OS statistics structure */
5603 stats->rx_bytes = adapter->stats.gorc;
5604 stats->rx_packets = adapter->stats.gprc;
5605 stats->tx_bytes = adapter->stats.gotc;
5606 stats->tx_packets = adapter->stats.gptc;
5607 stats->multicast = adapter->stats.mprc;
5608 stats->collisions = adapter->stats.colc;
5609
5610 /* Rx Errors */
5611
Bruce Allane921eb12012-11-28 09:28:37 +00005612 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005613 * our own version based on RUC and ROC
5614 */
5615 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005616 adapter->stats.crcerrs + adapter->stats.algnerrc +
5617 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5618 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005619 stats->rx_crc_errors = adapter->stats.crcerrs;
5620 stats->rx_frame_errors = adapter->stats.algnerrc;
5621 stats->rx_missed_errors = adapter->stats.mpc;
5622
5623 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005624 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005625 stats->tx_aborted_errors = adapter->stats.ecol;
5626 stats->tx_window_errors = adapter->stats.latecol;
5627 stats->tx_carrier_errors = adapter->stats.tncrs;
5628
5629 /* Tx Dropped needs to be maintained elsewhere */
5630
5631 spin_unlock(&adapter->stats64_lock);
5632 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005633}
5634
5635/**
5636 * e1000_change_mtu - Change the Maximum Transfer Unit
5637 * @netdev: network interface device structure
5638 * @new_mtu: new value for maximum frame size
5639 *
5640 * Returns 0 on success, negative on failure
5641 **/
5642static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5643{
5644 struct e1000_adapter *adapter = netdev_priv(netdev);
5645 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5646
Bruce Allan2adc55c2009-06-02 11:28:58 +00005647 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005648 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5649 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5650 e_err("Jumbo Frames not supported.\n");
5651 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005652 }
5653
Bruce Allan2adc55c2009-06-02 11:28:58 +00005654 /* Supported frame sizes */
5655 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5656 (max_frame > adapter->max_hw_frame_size)) {
5657 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658 return -EINVAL;
5659 }
5660
Bruce Allan2fbe4522012-04-19 03:21:47 +00005661 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5662 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005663 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5664 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005665 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005666 return -EINVAL;
5667 }
5668
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005670 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005671 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005672 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005673 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5674 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675 if (netif_running(netdev))
5676 e1000e_down(adapter);
5677
Bruce Allane921eb12012-11-28 09:28:37 +00005678 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679 * means we reserve 2 more, this pushes us to allocate from the next
5680 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005681 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005682 * However with the new *_jumbo_rx* routines, jumbo receives will use
5683 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005684 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005685
Jesse Brandeburg99261462010-01-22 22:56:16 +00005686 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005687 adapter->rx_buffer_len = 2048;
5688 else
5689 adapter->rx_buffer_len = 4096;
5690
5691 /* adjust allocation if LPE protects us, and we aren't using SBP */
5692 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005693 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005694 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005695 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696
Auke Kokbc7f75f2007-09-17 12:30:59 -07005697 if (netif_running(netdev))
5698 e1000e_up(adapter);
5699 else
5700 e1000e_reset(adapter);
5701
5702 clear_bit(__E1000_RESETTING, &adapter->state);
5703
5704 return 0;
5705}
5706
5707static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5708 int cmd)
5709{
5710 struct e1000_adapter *adapter = netdev_priv(netdev);
5711 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005712
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005713 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714 return -EOPNOTSUPP;
5715
5716 switch (cmd) {
5717 case SIOCGMIIPHY:
5718 data->phy_id = adapter->hw.phy.addr;
5719 break;
5720 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005721 e1000_phy_read_status(adapter);
5722
Bruce Allan7c257692008-04-23 11:09:00 -07005723 switch (data->reg_num & 0x1F) {
5724 case MII_BMCR:
5725 data->val_out = adapter->phy_regs.bmcr;
5726 break;
5727 case MII_BMSR:
5728 data->val_out = adapter->phy_regs.bmsr;
5729 break;
5730 case MII_PHYSID1:
5731 data->val_out = (adapter->hw.phy.id >> 16);
5732 break;
5733 case MII_PHYSID2:
5734 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5735 break;
5736 case MII_ADVERTISE:
5737 data->val_out = adapter->phy_regs.advertise;
5738 break;
5739 case MII_LPA:
5740 data->val_out = adapter->phy_regs.lpa;
5741 break;
5742 case MII_EXPANSION:
5743 data->val_out = adapter->phy_regs.expansion;
5744 break;
5745 case MII_CTRL1000:
5746 data->val_out = adapter->phy_regs.ctrl1000;
5747 break;
5748 case MII_STAT1000:
5749 data->val_out = adapter->phy_regs.stat1000;
5750 break;
5751 case MII_ESTATUS:
5752 data->val_out = adapter->phy_regs.estatus;
5753 break;
5754 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755 return -EIO;
5756 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757 break;
5758 case SIOCSMIIREG:
5759 default:
5760 return -EOPNOTSUPP;
5761 }
5762 return 0;
5763}
5764
Bruce Allanb67e1912012-12-27 08:32:33 +00005765/**
5766 * e1000e_hwtstamp_ioctl - control hardware time stamping
5767 * @netdev: network interface device structure
5768 * @ifreq: interface request
5769 *
5770 * Outgoing time stamping can be enabled and disabled. Play nice and
5771 * disable it when requested, although it shouldn't cause any overhead
5772 * when no packet needs it. At most one packet in the queue may be
5773 * marked for time stamping, otherwise it would be impossible to tell
5774 * for sure to which packet the hardware time stamp belongs.
5775 *
5776 * Incoming time stamping has to be configured via the hardware filters.
5777 * Not all combinations are supported, in particular event type has to be
5778 * specified. Matching the kind of event packet is not supported, with the
5779 * exception of "all V2 events regardless of level 2 or 4".
5780 **/
5781static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5782{
5783 struct e1000_adapter *adapter = netdev_priv(netdev);
5784 struct hwtstamp_config config;
5785 int ret_val;
5786
5787 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5788 return -EFAULT;
5789
5790 adapter->hwtstamp_config = config;
5791
5792 ret_val = e1000e_config_hwtstamp(adapter);
5793 if (ret_val)
5794 return ret_val;
5795
5796 config = adapter->hwtstamp_config;
5797
Bruce Alland89777b2013-01-19 01:09:58 +00005798 switch (config.rx_filter) {
5799 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5800 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5801 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5802 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5803 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5804 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5805 /* With V2 type filters which specify a Sync or Delay Request,
5806 * Path Delay Request/Response messages are also time stamped
5807 * by hardware so notify the caller the requested packets plus
5808 * some others are time stamped.
5809 */
5810 config.rx_filter = HWTSTAMP_FILTER_SOME;
5811 break;
5812 default:
5813 break;
5814 }
5815
Bruce Allanb67e1912012-12-27 08:32:33 +00005816 return copy_to_user(ifr->ifr_data, &config,
5817 sizeof(config)) ? -EFAULT : 0;
5818}
5819
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5821{
5822 switch (cmd) {
5823 case SIOCGMIIPHY:
5824 case SIOCGMIIREG:
5825 case SIOCSMIIREG:
5826 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005827 case SIOCSHWTSTAMP:
5828 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005829 default:
5830 return -EOPNOTSUPP;
5831 }
5832}
5833
Bruce Allana4f58f52009-06-02 11:29:18 +00005834static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5835{
5836 struct e1000_hw *hw = &adapter->hw;
5837 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005838 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005839 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005840
5841 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005842 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005843
Bruce Allan2b6b1682011-05-13 07:20:09 +00005844 retval = hw->phy.ops.acquire(hw);
5845 if (retval) {
5846 e_err("Could not acquire PHY\n");
5847 return retval;
5848 }
5849
5850 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5851 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5852 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005853 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005854
5855 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005856 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5857 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005858 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5859 (u16)(mac_reg & 0xFFFF));
5860 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5861 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005862 }
5863
5864 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005865 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005866 mac_reg = er32(RCTL);
5867 if (mac_reg & E1000_RCTL_UPE)
5868 phy_reg |= BM_RCTL_UPE;
5869 if (mac_reg & E1000_RCTL_MPE)
5870 phy_reg |= BM_RCTL_MPE;
5871 phy_reg &= ~(BM_RCTL_MO_MASK);
5872 if (mac_reg & E1000_RCTL_MO_3)
5873 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005874 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005875 if (mac_reg & E1000_RCTL_BAM)
5876 phy_reg |= BM_RCTL_BAM;
5877 if (mac_reg & E1000_RCTL_PMCF)
5878 phy_reg |= BM_RCTL_PMCF;
5879 mac_reg = er32(CTRL);
5880 if (mac_reg & E1000_CTRL_RFCE)
5881 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005882 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005883
5884 /* enable PHY wakeup in MAC register */
5885 ew32(WUFC, wufc);
5886 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5887
5888 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005889 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5890 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005891
5892 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005893 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5894 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005895 if (retval)
5896 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005897release:
Bruce Allan94d81862009-11-20 23:25:26 +00005898 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005899
5900 return retval;
5901}
5902
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00005903static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005904{
5905 struct net_device *netdev = pci_get_drvdata(pdev);
5906 struct e1000_adapter *adapter = netdev_priv(netdev);
5907 struct e1000_hw *hw = &adapter->hw;
5908 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005909 /* Runtime suspend should only enable wakeup for link changes */
5910 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005911 int retval = 0;
5912
5913 netif_device_detach(netdev);
5914
5915 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005916 int count = E1000_CHECK_RESET_COUNT;
5917
5918 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5919 usleep_range(10000, 20000);
5920
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5922 e1000e_down(adapter);
5923 e1000_free_irq(adapter);
5924 }
Bruce Allan4662e822008-08-26 18:37:06 -07005925 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005926
Auke Kokbc7f75f2007-09-17 12:30:59 -07005927 status = er32(STATUS);
5928 if (status & E1000_STATUS_LU)
5929 wufc &= ~E1000_WUFC_LNKC;
5930
5931 if (wufc) {
5932 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005933 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934
5935 /* turn on all-multi mode if wake on multicast is enabled */
5936 if (wufc & E1000_WUFC_MC) {
5937 rctl = er32(RCTL);
5938 rctl |= E1000_RCTL_MPE;
5939 ew32(RCTL, rctl);
5940 }
5941
5942 ctrl = er32(CTRL);
Bruce Allana4f58f52009-06-02 11:29:18 +00005943 ctrl |= E1000_CTRL_ADVD3WUC;
5944 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5945 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005946 ew32(CTRL, ctrl);
5947
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005948 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5949 adapter->hw.phy.media_type ==
5950 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005951 /* keep the laser running in D3 */
5952 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005953 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005954 ew32(CTRL_EXT, ctrl_ext);
5955 }
5956
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005957 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005958 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005959
Auke Kokbc7f75f2007-09-17 12:30:59 -07005960 /* Allow time for pending master requests to run */
5961 e1000e_disable_pcie_master(&adapter->hw);
5962
Bruce Allan82776a42009-08-14 14:35:33 +00005963 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005964 /* enable wakeup by the PHY */
5965 retval = e1000_init_phy_wakeup(adapter, wufc);
5966 if (retval)
5967 return retval;
5968 } else {
5969 /* enable wakeup by the MAC */
5970 ew32(WUFC, wufc);
5971 ew32(WUC, E1000_WUC_PME_EN);
5972 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005973 } else {
5974 ew32(WUC, 0);
5975 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005976 }
5977
Auke Kokbc7f75f2007-09-17 12:30:59 -07005978 if (adapter->hw.phy.type == e1000_phy_igp_3)
5979 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5980
Bruce Allane921eb12012-11-28 09:28:37 +00005981 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005982 * would have already happened in close and is redundant.
5983 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005984 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005985
Bruce Allane921eb12012-11-28 09:28:37 +00005986 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005987 * correctable error when the MAC transitions from D0 to D3. To
5988 * prevent this we need to mask off the correctable errors on the
5989 * downstream port of the pci-e switch.
5990 */
5991 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5992 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005993 u16 devctl;
5994
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005995 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
5996 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
5997 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005998
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00005999 pci_save_state(pdev);
6000 pci_prepare_to_sleep(pdev);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006001
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006002 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006003 }
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006004
6005 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006006}
6007
Bruce Allan6f461f62010-04-27 03:33:04 +00006008#ifdef CONFIG_PCIEASPM
6009static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6010{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006011 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006012}
6013#else
6014static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006015{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006016 u16 aspm_ctl = 0;
6017
6018 if (state & PCIE_LINK_STATE_L0S)
6019 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6020 if (state & PCIE_LINK_STATE_L1)
6021 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6022
Bruce Allane921eb12012-11-28 09:28:37 +00006023 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006024 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006025 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006026 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006027
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006028 if (pdev->bus->self)
6029 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006030 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006031}
6032#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006033static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006034{
6035 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6036 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6037 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6038
6039 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006040}
6041
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006042#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006043static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006044{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006045 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006046}
6047
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006048static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006049{
6050 struct net_device *netdev = pci_get_drvdata(pdev);
6051 struct e1000_adapter *adapter = netdev_priv(netdev);
6052 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006053 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006054 u32 err;
6055
Bruce Allan78cd29d2011-03-24 03:09:03 +00006056 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6057 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6058 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6059 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6060 if (aspm_disable_flag)
6061 e1000e_disable_aspm(pdev, aspm_disable_flag);
6062
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006063 pci_set_master(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006064
Bruce Allan4662e822008-08-26 18:37:06 -07006065 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006066 if (netif_running(netdev)) {
6067 err = e1000_request_irq(adapter);
6068 if (err)
6069 return err;
6070 }
6071
Bruce Allan2fbe4522012-04-19 03:21:47 +00006072 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006073 e1000_resume_workarounds_pchlan(&adapter->hw);
6074
Auke Kokbc7f75f2007-09-17 12:30:59 -07006075 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006076
6077 /* report the system wakeup cause from S3/S4 */
6078 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6079 u16 phy_data;
6080
6081 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6082 if (phy_data) {
6083 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006084 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6085 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6086 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6087 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6088 phy_data & E1000_WUS_LNKC ?
6089 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006090 }
6091 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6092 } else {
6093 u32 wus = er32(WUS);
6094 if (wus) {
6095 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006096 wus & E1000_WUS_EX ? "Unicast Packet" :
6097 wus & E1000_WUS_MC ? "Multicast Packet" :
6098 wus & E1000_WUS_BC ? "Broadcast Packet" :
6099 wus & E1000_WUS_MAG ? "Magic Packet" :
6100 wus & E1000_WUS_LNKC ? "Link Status Change" :
6101 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006102 }
6103 ew32(WUS, ~0);
6104 }
6105
Auke Kokbc7f75f2007-09-17 12:30:59 -07006106 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006107
Bruce Allancd791612010-05-10 14:59:51 +00006108 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109
6110 if (netif_running(netdev))
6111 e1000e_up(adapter);
6112
6113 netif_device_attach(netdev);
6114
Bruce Allane921eb12012-11-28 09:28:37 +00006115 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006116 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006117 * under the control of the driver.
6118 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006119 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006120 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006121
6122 return 0;
6123}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006124
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006125#ifdef CONFIG_PM_SLEEP
6126static int e1000_suspend(struct device *dev)
6127{
6128 struct pci_dev *pdev = to_pci_dev(dev);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006129
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006130 return __e1000_shutdown(pdev, false);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006131}
6132
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006133static int e1000_resume(struct device *dev)
6134{
6135 struct pci_dev *pdev = to_pci_dev(dev);
6136 struct net_device *netdev = pci_get_drvdata(pdev);
6137 struct e1000_adapter *adapter = netdev_priv(netdev);
6138
6139 if (e1000e_pm_ready(adapter))
6140 adapter->idle_check = true;
6141
6142 return __e1000_resume(pdev);
6143}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006144#endif /* CONFIG_PM_SLEEP */
6145
6146#ifdef CONFIG_PM_RUNTIME
6147static int e1000_runtime_suspend(struct device *dev)
6148{
6149 struct pci_dev *pdev = to_pci_dev(dev);
6150 struct net_device *netdev = pci_get_drvdata(pdev);
6151 struct e1000_adapter *adapter = netdev_priv(netdev);
6152
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006153 if (!e1000e_pm_ready(adapter))
6154 return 0;
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006155
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006156 return __e1000_shutdown(pdev, true);
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006157}
6158
6159static int e1000_idle(struct device *dev)
6160{
6161 struct pci_dev *pdev = to_pci_dev(dev);
6162 struct net_device *netdev = pci_get_drvdata(pdev);
6163 struct e1000_adapter *adapter = netdev_priv(netdev);
6164
6165 if (!e1000e_pm_ready(adapter))
6166 return 0;
6167
6168 if (adapter->idle_check) {
6169 adapter->idle_check = false;
6170 if (!e1000e_has_link(adapter))
6171 pm_schedule_suspend(dev, MSEC_PER_SEC);
6172 }
6173
6174 return -EBUSY;
6175}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006176
6177static int e1000_runtime_resume(struct device *dev)
6178{
6179 struct pci_dev *pdev = to_pci_dev(dev);
6180 struct net_device *netdev = pci_get_drvdata(pdev);
6181 struct e1000_adapter *adapter = netdev_priv(netdev);
6182
6183 if (!e1000e_pm_ready(adapter))
6184 return 0;
6185
6186 adapter->idle_check = !dev->power.runtime_auto;
6187 return __e1000_resume(pdev);
6188}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006189#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006190#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191
6192static void e1000_shutdown(struct pci_dev *pdev)
6193{
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006194 __e1000_shutdown(pdev, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006195}
6196
6197#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006198
Bruce Allan8bb62862013-01-16 08:46:49 +00006199static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006200{
6201 struct net_device *netdev = data;
6202 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006203
6204 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006205 int vector, msix_irq;
6206
Dongdong Deng147b2c82010-11-16 19:50:15 -08006207 vector = 0;
6208 msix_irq = adapter->msix_entries[vector].vector;
6209 disable_irq(msix_irq);
6210 e1000_intr_msix_rx(msix_irq, netdev);
6211 enable_irq(msix_irq);
6212
6213 vector++;
6214 msix_irq = adapter->msix_entries[vector].vector;
6215 disable_irq(msix_irq);
6216 e1000_intr_msix_tx(msix_irq, netdev);
6217 enable_irq(msix_irq);
6218
6219 vector++;
6220 msix_irq = adapter->msix_entries[vector].vector;
6221 disable_irq(msix_irq);
6222 e1000_msix_other(msix_irq, netdev);
6223 enable_irq(msix_irq);
6224 }
6225
6226 return IRQ_HANDLED;
6227}
6228
Bruce Allane921eb12012-11-28 09:28:37 +00006229/**
6230 * e1000_netpoll
6231 * @netdev: network interface device structure
6232 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233 * Polling 'interrupt' - used by things like netconsole to send skbs
6234 * without having to re-enable interrupts. It's not called while
6235 * the interrupt routine is executing.
6236 */
6237static void e1000_netpoll(struct net_device *netdev)
6238{
6239 struct e1000_adapter *adapter = netdev_priv(netdev);
6240
Dongdong Deng147b2c82010-11-16 19:50:15 -08006241 switch (adapter->int_mode) {
6242 case E1000E_INT_MODE_MSIX:
6243 e1000_intr_msix(adapter->pdev->irq, netdev);
6244 break;
6245 case E1000E_INT_MODE_MSI:
6246 disable_irq(adapter->pdev->irq);
6247 e1000_intr_msi(adapter->pdev->irq, netdev);
6248 enable_irq(adapter->pdev->irq);
6249 break;
6250 default: /* E1000E_INT_MODE_LEGACY */
6251 disable_irq(adapter->pdev->irq);
6252 e1000_intr(adapter->pdev->irq, netdev);
6253 enable_irq(adapter->pdev->irq);
6254 break;
6255 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006256}
6257#endif
6258
6259/**
6260 * e1000_io_error_detected - called when PCI error is detected
6261 * @pdev: Pointer to PCI device
6262 * @state: The current pci connection state
6263 *
6264 * This function is called after a PCI bus error affecting
6265 * this device has been detected.
6266 */
6267static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6268 pci_channel_state_t state)
6269{
6270 struct net_device *netdev = pci_get_drvdata(pdev);
6271 struct e1000_adapter *adapter = netdev_priv(netdev);
6272
6273 netif_device_detach(netdev);
6274
Mike Masonc93b5a72009-06-30 12:45:53 +00006275 if (state == pci_channel_io_perm_failure)
6276 return PCI_ERS_RESULT_DISCONNECT;
6277
Auke Kokbc7f75f2007-09-17 12:30:59 -07006278 if (netif_running(netdev))
6279 e1000e_down(adapter);
6280 pci_disable_device(pdev);
6281
6282 /* Request a slot slot reset. */
6283 return PCI_ERS_RESULT_NEED_RESET;
6284}
6285
6286/**
6287 * e1000_io_slot_reset - called after the pci bus has been reset.
6288 * @pdev: Pointer to PCI device
6289 *
6290 * Restart the card from scratch, as if from a cold-boot. Implementation
6291 * resembles the first-half of the e1000_resume routine.
6292 */
6293static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6294{
6295 struct net_device *netdev = pci_get_drvdata(pdev);
6296 struct e1000_adapter *adapter = netdev_priv(netdev);
6297 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006298 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006299 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006300 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006301
Bruce Allan78cd29d2011-03-24 03:09:03 +00006302 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6303 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006304 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006305 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6306 if (aspm_disable_flag)
6307 e1000e_disable_aspm(pdev, aspm_disable_flag);
6308
Bruce Allanf0f422e2008-08-04 17:21:53 -07006309 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006310 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006311 dev_err(&pdev->dev,
6312 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006313 result = PCI_ERS_RESULT_DISCONNECT;
6314 } else {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006315 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006316 pci_restore_state(pdev);
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006317 pci_set_master(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006318
6319 pci_enable_wake(pdev, PCI_D3hot, 0);
6320 pci_enable_wake(pdev, PCI_D3cold, 0);
6321
6322 e1000e_reset(adapter);
6323 ew32(WUS, ~0);
6324 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006325 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006326
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006327 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006328
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006329 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006330}
6331
6332/**
6333 * e1000_io_resume - called when traffic can start flowing again.
6334 * @pdev: Pointer to PCI device
6335 *
6336 * This callback is called when the error recovery driver tells us that
6337 * its OK to resume normal operation. Implementation resembles the
6338 * second-half of the e1000_resume routine.
6339 */
6340static void e1000_io_resume(struct pci_dev *pdev)
6341{
6342 struct net_device *netdev = pci_get_drvdata(pdev);
6343 struct e1000_adapter *adapter = netdev_priv(netdev);
6344
Bruce Allancd791612010-05-10 14:59:51 +00006345 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006346
6347 if (netif_running(netdev)) {
6348 if (e1000e_up(adapter)) {
6349 dev_err(&pdev->dev,
6350 "can't bring device back up after reset\n");
6351 return;
6352 }
6353 }
6354
6355 netif_device_attach(netdev);
6356
Bruce Allane921eb12012-11-28 09:28:37 +00006357 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006358 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006359 * under the control of the driver.
6360 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006361 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006362 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006363}
6364
6365static void e1000_print_device_info(struct e1000_adapter *adapter)
6366{
6367 struct e1000_hw *hw = &adapter->hw;
6368 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006369 u32 ret_val;
6370 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006371
6372 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006373 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006374 /* bus width */
6375 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006376 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006377 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006378 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006379 e_info("Intel(R) PRO/%s Network Connection\n",
6380 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006381 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6382 E1000_PBANUM_LENGTH);
6383 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006384 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006385 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6386 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006387}
6388
Auke Kok10aa4c02008-08-04 17:21:20 -07006389static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6390{
6391 struct e1000_hw *hw = &adapter->hw;
6392 int ret_val;
6393 u16 buf = 0;
6394
6395 if (hw->mac.type != e1000_82573)
6396 return;
6397
6398 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006399 le16_to_cpus(&buf);
6400 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006401 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006402 dev_warn(&adapter->pdev->dev,
6403 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006404 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006405}
6406
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006407static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006408 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006409{
6410 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006411 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006412
6413 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6414 adapter->flags |= FLAG_TSO_FORCE;
6415
6416 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006417 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6418 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006419 return 0;
6420
Ben Greear01840392012-02-11 15:39:25 +00006421 if (changed & NETIF_F_RXFCS) {
6422 if (features & NETIF_F_RXFCS) {
6423 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6424 } else {
6425 /* We need to take it back to defaults, which might mean
6426 * stripping is still disabled at the adapter level.
6427 */
6428 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6429 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6430 else
6431 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6432 }
6433 }
6434
Bruce Allan70495a52012-01-11 01:26:50 +00006435 netdev->features = features;
6436
Bruce Allandc221292011-08-19 03:23:48 +00006437 if (netif_running(netdev))
6438 e1000e_reinit_locked(adapter);
6439 else
6440 e1000e_reset(adapter);
6441
6442 return 0;
6443}
6444
Stephen Hemminger651c2462008-11-19 21:57:48 -08006445static const struct net_device_ops e1000e_netdev_ops = {
6446 .ndo_open = e1000_open,
6447 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006448 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006449 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006450 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006451 .ndo_set_mac_address = e1000_set_mac,
6452 .ndo_change_mtu = e1000_change_mtu,
6453 .ndo_do_ioctl = e1000_ioctl,
6454 .ndo_tx_timeout = e1000_tx_timeout,
6455 .ndo_validate_addr = eth_validate_addr,
6456
Stephen Hemminger651c2462008-11-19 21:57:48 -08006457 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6458 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6459#ifdef CONFIG_NET_POLL_CONTROLLER
6460 .ndo_poll_controller = e1000_netpoll,
6461#endif
Bruce Allandc221292011-08-19 03:23:48 +00006462 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006463};
6464
Auke Kokbc7f75f2007-09-17 12:30:59 -07006465/**
6466 * e1000_probe - Device Initialization Routine
6467 * @pdev: PCI device information struct
6468 * @ent: entry in e1000_pci_tbl
6469 *
6470 * Returns 0 on success, negative on failure
6471 *
6472 * e1000_probe initializes an adapter identified by a pci_dev structure.
6473 * The OS initialization, configuring of the adapter private structure,
6474 * and a hardware reset occur.
6475 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006476static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006477{
6478 struct net_device *netdev;
6479 struct e1000_adapter *adapter;
6480 struct e1000_hw *hw;
6481 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006482 resource_size_t mmio_start, mmio_len;
6483 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006484 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006485 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006486 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006487 u16 eeprom_data = 0;
6488 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6489
Bruce Allan78cd29d2011-03-24 03:09:03 +00006490 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6491 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006492 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006493 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6494 if (aspm_disable_flag)
6495 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006496
Bruce Allanf0f422e2008-08-04 17:21:53 -07006497 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006498 if (err)
6499 return err;
6500
6501 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006502 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006503 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006504 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006505 if (!err)
6506 pci_using_dac = 1;
6507 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006508 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006509 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006510 err = dma_set_coherent_mask(&pdev->dev,
6511 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006512 if (err) {
Bruce Allanf0ff4392013-02-20 04:05:39 +00006513 dev_err(&pdev->dev,
6514 "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006515 goto err_dma;
6516 }
6517 }
6518 }
6519
Bruce Allan17e813e2013-02-20 04:06:01 +00006520 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6521 err = pci_request_selected_regions_exclusive(pdev, bars,
6522 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006523 if (err)
6524 goto err_pci_reg;
6525
Xiaotian Feng68eac462009-08-14 14:35:52 +00006526 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006527 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006528
Auke Kokbc7f75f2007-09-17 12:30:59 -07006529 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006530 /* PCI config space info */
6531 err = pci_save_state(pdev);
6532 if (err)
6533 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534
6535 err = -ENOMEM;
6536 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6537 if (!netdev)
6538 goto err_alloc_etherdev;
6539
Auke Kokbc7f75f2007-09-17 12:30:59 -07006540 SET_NETDEV_DEV(netdev, &pdev->dev);
6541
Tom Herbertf85e4df2010-05-05 14:03:32 +00006542 netdev->irq = pdev->irq;
6543
Auke Kokbc7f75f2007-09-17 12:30:59 -07006544 pci_set_drvdata(pdev, netdev);
6545 adapter = netdev_priv(netdev);
6546 hw = &adapter->hw;
6547 adapter->netdev = netdev;
6548 adapter->pdev = pdev;
6549 adapter->ei = ei;
6550 adapter->pba = ei->pba;
6551 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006552 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006553 adapter->hw.adapter = adapter;
6554 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006555 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006556 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006557
6558 mmio_start = pci_resource_start(pdev, 0);
6559 mmio_len = pci_resource_len(pdev, 0);
6560
6561 err = -EIO;
6562 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6563 if (!adapter->hw.hw_addr)
6564 goto err_ioremap;
6565
6566 if ((adapter->flags & FLAG_HAS_FLASH) &&
6567 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6568 flash_start = pci_resource_start(pdev, 1);
6569 flash_len = pci_resource_len(pdev, 1);
6570 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6571 if (!adapter->hw.flash_address)
6572 goto err_flashmap;
6573 }
6574
Bruce Alland495bcb2013-03-20 07:23:11 +00006575 /* Set default EEE advertisement */
6576 if (adapter->flags2 & FLAG2_HAS_EEE)
6577 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
6578
Auke Kokbc7f75f2007-09-17 12:30:59 -07006579 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006580 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006581 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006582 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006583 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006584 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006585
6586 netdev->mem_start = mmio_start;
6587 netdev->mem_end = mmio_start + mmio_len;
6588
6589 adapter->bd_number = cards_found++;
6590
Bruce Allan4662e822008-08-26 18:37:06 -07006591 e1000e_check_options(adapter);
6592
Auke Kokbc7f75f2007-09-17 12:30:59 -07006593 /* setup adapter struct */
6594 err = e1000_sw_init(adapter);
6595 if (err)
6596 goto err_sw_init;
6597
Auke Kokbc7f75f2007-09-17 12:30:59 -07006598 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6599 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6600 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6601
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006602 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006603 if (err)
6604 goto err_hw_init;
6605
Bruce Allan4a770352008-10-01 17:18:35 -07006606 if ((adapter->flags & FLAG_IS_ICH) &&
6607 (adapter->flags & FLAG_READ_ONLY_NVM))
6608 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6609
Auke Kokbc7f75f2007-09-17 12:30:59 -07006610 hw->mac.ops.get_bus_info(&adapter->hw);
6611
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006612 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006613
6614 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006615 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006616 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6617 adapter->hw.phy.disable_polarity_correction = 0;
6618 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6619 }
6620
Bruce Allan470a5422012-05-26 06:08:48 +00006621 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006622 dev_info(&pdev->dev,
6623 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006624
Bruce Allandc221292011-08-19 03:23:48 +00006625 /* Set initial default active device features */
6626 netdev->features = (NETIF_F_SG |
6627 NETIF_F_HW_VLAN_RX |
6628 NETIF_F_HW_VLAN_TX |
6629 NETIF_F_TSO |
6630 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006631 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006632 NETIF_F_RXCSUM |
6633 NETIF_F_HW_CSUM);
6634
6635 /* Set user-changeable features (subset of all device features) */
6636 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006637 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006638 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006639 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006640
6641 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6642 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6643
Bruce Allandc221292011-08-19 03:23:48 +00006644 netdev->vlan_features |= (NETIF_F_SG |
6645 NETIF_F_TSO |
6646 NETIF_F_TSO6 |
6647 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006648
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006649 netdev->priv_flags |= IFF_UNICAST_FLT;
6650
Yi Zou7b872a52010-09-22 17:57:58 +00006651 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006652 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006653 netdev->vlan_features |= NETIF_F_HIGHDMA;
6654 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006655
Auke Kokbc7f75f2007-09-17 12:30:59 -07006656 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6657 adapter->flags |= FLAG_MNG_PT_ENABLED;
6658
Bruce Allane921eb12012-11-28 09:28:37 +00006659 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006660 * put the device in a known good starting state
6661 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006662 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6663
Bruce Allane921eb12012-11-28 09:28:37 +00006664 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006665 * attempt. Let's give it a few tries
6666 */
6667 for (i = 0;; i++) {
6668 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6669 break;
6670 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006671 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006672 err = -EIO;
6673 goto err_eeprom;
6674 }
6675 }
6676
Auke Kok10aa4c02008-08-04 17:21:20 -07006677 e1000_eeprom_checks(adapter);
6678
Bruce Allan608f8a02010-01-13 02:04:58 +00006679 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006680 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006681 dev_err(&pdev->dev,
6682 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006683
6684 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006685
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006686 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006687 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006688 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006689 err = -EIO;
6690 goto err_eeprom;
6691 }
6692
6693 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006694 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006695 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006696
6697 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006698 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006699 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006700
6701 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6702 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006703 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6704 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006705 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006706
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 /* Initialize link parameters. User can change them with ethtool */
6708 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006709 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006710 adapter->hw.fc.requested_mode = e1000_fc_default;
6711 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712 adapter->hw.phy.autoneg_advertised = 0x2f;
6713
6714 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006715 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6716 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006717
Bruce Allane921eb12012-11-28 09:28:37 +00006718 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006719 * the EEPROM, enable the ACPI Magic Packet filter
6720 */
6721 if (adapter->flags & FLAG_APME_IN_WUC) {
6722 /* APME bit in EEPROM is mapped to WUC.APME */
6723 eeprom_data = er32(WUC);
6724 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006725 if ((hw->mac.type > e1000_ich10lan) &&
6726 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006727 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006728 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6729 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6730 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006731 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6732 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006733 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006734 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6735 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006736 }
6737
6738 /* fetch WoL from EEPROM */
6739 if (eeprom_data & eeprom_apme_mask)
6740 adapter->eeprom_wol |= E1000_WUFC_MAG;
6741
Bruce Allane921eb12012-11-28 09:28:37 +00006742 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006743 * where the eeprom may be wrong or the board simply won't support
6744 * wake on lan on a particular port
6745 */
6746 if (!(adapter->flags & FLAG_HAS_WOL))
6747 adapter->eeprom_wol = 0;
6748
6749 /* initialize the wol settings based on the eeprom settings */
6750 adapter->wol = adapter->eeprom_wol;
Konstantin Khlebnikov66148ba2013-03-05 09:43:04 +00006751
6752 /* make sure adapter isn't asleep if manageability is enabled */
6753 if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
6754 (hw->mac.ops.check_mng_mode(hw)))
6755 device_wakeup_enable(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006756
Bruce Allan84527592008-11-21 17:00:22 -08006757 /* save off EEPROM version number */
6758 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6759
Auke Kokbc7f75f2007-09-17 12:30:59 -07006760 /* reset the hardware with the new settings */
6761 e1000e_reset(adapter);
6762
Bruce Allane921eb12012-11-28 09:28:37 +00006763 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006764 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006765 * under the control of the driver.
6766 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006767 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006768 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006769
Bruce Allanf2315bf2011-12-16 00:46:59 +00006770 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006771 err = register_netdev(netdev);
6772 if (err)
6773 goto err_register;
6774
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006775 /* carrier off reporting is important to ethtool even BEFORE open */
6776 netif_carrier_off(netdev);
6777
Bruce Alland89777b2013-01-19 01:09:58 +00006778 /* init PTP hardware clock */
6779 e1000e_ptp_init(adapter);
6780
Auke Kokbc7f75f2007-09-17 12:30:59 -07006781 e1000_print_device_info(adapter);
6782
Alan Sternf3ec4f82010-06-08 15:23:51 -04006783 if (pci_dev_run_wake(pdev))
6784 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006785
Auke Kokbc7f75f2007-09-17 12:30:59 -07006786 return 0;
6787
6788err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006789 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006790 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006791err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006792 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006793 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006794err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006795 kfree(adapter->tx_ring);
6796 kfree(adapter->rx_ring);
6797err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006798 if (adapter->hw.flash_address)
6799 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006800 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006801err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006802 iounmap(adapter->hw.hw_addr);
6803err_ioremap:
6804 free_netdev(netdev);
6805err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006806 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006807 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006808err_pci_reg:
6809err_dma:
6810 pci_disable_device(pdev);
6811 return err;
6812}
6813
6814/**
6815 * e1000_remove - Device Removal Routine
6816 * @pdev: PCI device information struct
6817 *
6818 * e1000_remove is called by the PCI subsystem to alert the driver
6819 * that it should release a PCI device. The could be caused by a
6820 * Hot-Plug event, or because the driver is going to be removed from
6821 * memory.
6822 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006823static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006824{
6825 struct net_device *netdev = pci_get_drvdata(pdev);
6826 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006827 bool down = test_bit(__E1000_DOWN, &adapter->state);
6828
Bruce Alland89777b2013-01-19 01:09:58 +00006829 e1000e_ptp_remove(adapter);
6830
Bruce Allane921eb12012-11-28 09:28:37 +00006831 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006832 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006833 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006834 if (!down)
6835 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006836 del_timer_sync(&adapter->watchdog_timer);
6837 del_timer_sync(&adapter->phy_info_timer);
6838
Bruce Allan41cec6f2009-11-20 23:28:56 +00006839 cancel_work_sync(&adapter->reset_task);
6840 cancel_work_sync(&adapter->watchdog_task);
6841 cancel_work_sync(&adapter->downshift_task);
6842 cancel_work_sync(&adapter->update_phy_task);
6843 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006844
Bruce Allanb67e1912012-12-27 08:32:33 +00006845 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6846 cancel_work_sync(&adapter->tx_hwtstamp_work);
6847 if (adapter->tx_hwtstamp_skb) {
6848 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6849 adapter->tx_hwtstamp_skb = NULL;
6850 }
6851 }
6852
Bruce Allan17f208d2009-12-01 15:47:22 +00006853 if (!(netdev->flags & IFF_UP))
6854 e1000_power_down_phy(adapter);
6855
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006856 /* Don't lie to e1000_close() down the road. */
6857 if (!down)
6858 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006859 unregister_netdev(netdev);
6860
Alan Sternf3ec4f82010-06-08 15:23:51 -04006861 if (pci_dev_run_wake(pdev))
6862 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006863
Bruce Allane921eb12012-11-28 09:28:37 +00006864 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006865 * would have already happened in close and is redundant.
6866 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006867 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006868
Bruce Allan4662e822008-08-26 18:37:06 -07006869 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006870 kfree(adapter->tx_ring);
6871 kfree(adapter->rx_ring);
6872
6873 iounmap(adapter->hw.hw_addr);
6874 if (adapter->hw.flash_address)
6875 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006876 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006877 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006878
6879 free_netdev(netdev);
6880
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006881 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006882 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006883
Auke Kokbc7f75f2007-09-17 12:30:59 -07006884 pci_disable_device(pdev);
6885}
6886
6887/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006888static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006889 .error_detected = e1000_io_error_detected,
6890 .slot_reset = e1000_io_slot_reset,
6891 .resume = e1000_io_resume,
6892};
6893
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006894static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006895 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6896 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6897 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00006898 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
6899 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006900 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6901 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006902 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6903 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6904 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006905
Auke Kokbc7f75f2007-09-17 12:30:59 -07006906 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6907 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6908 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6909 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006910
Auke Kokbc7f75f2007-09-17 12:30:59 -07006911 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6912 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6913 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006914
Bruce Allan4662e822008-08-26 18:37:06 -07006915 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006916 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006917 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006918
Auke Kokbc7f75f2007-09-17 12:30:59 -07006919 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6920 board_80003es2lan },
6921 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6922 board_80003es2lan },
6923 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6924 board_80003es2lan },
6925 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6926 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006927
Auke Kokbc7f75f2007-09-17 12:30:59 -07006928 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6929 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6930 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6931 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6932 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006936
Auke Kokbc7f75f2007-09-17 12:30:59 -07006937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6946
6947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006950
Bruce Allanf4187b52008-08-26 18:36:50 -07006951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006954
Bruce Allana4f58f52009-06-02 11:29:18 +00006955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6958 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6959
Bruce Alland3738bb2010-06-16 13:27:28 +00006960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6962
Bruce Allan2fbe4522012-04-19 03:21:47 +00006963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006967
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006968 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006969};
6970MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6971
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006972#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006973static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006974 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
Bruce Allan17e813e2013-02-20 04:06:01 +00006975 SET_RUNTIME_PM_OPS(e1000_runtime_suspend, e1000_runtime_resume,
6976 e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006977};
David S. Millere50208a2010-03-16 23:36:24 -07006978#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006979
Auke Kokbc7f75f2007-09-17 12:30:59 -07006980/* PCI Device API Driver */
6981static struct pci_driver e1000_driver = {
6982 .name = e1000e_driver_name,
6983 .id_table = e1000_pci_tbl,
6984 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006985 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006986#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006987 .driver = {
6988 .pm = &e1000_pm_ops,
6989 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006990#endif
6991 .shutdown = e1000_shutdown,
6992 .err_handler = &e1000_err_handler
6993};
6994
6995/**
6996 * e1000_init_module - Driver Registration Routine
6997 *
6998 * e1000_init_module is the first routine called when the driver is
6999 * loaded. All it does is register with the PCI subsystem.
7000 **/
7001static int __init e1000_init_module(void)
7002{
7003 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007004 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7005 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007006 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007007 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007008
Auke Kokbc7f75f2007-09-17 12:30:59 -07007009 return ret;
7010}
7011module_init(e1000_init_module);
7012
7013/**
7014 * e1000_exit_module - Driver Exit Cleanup Routine
7015 *
7016 * e1000_exit_module is called just before the driver is removed
7017 * from memory.
7018 **/
7019static void __exit e1000_exit_module(void)
7020{
7021 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007022}
7023module_exit(e1000_exit_module);
7024
7025
7026MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7027MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7028MODULE_LICENSE("GPL");
7029MODULE_VERSION(DRV_VERSION);
7030
Bruce Allan06c24b92012-02-23 03:13:13 +00007031/* netdev.c */