blob: eb01a55f60a6390a100d66197c19b682acfeea54 [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>
45#include <linux/mii.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
48#include <linux/cpu.h>
49#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020050#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000051#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000052#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040053#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070054
55#include "e1000.h"
56
Bruce Allanb3ccf262011-05-19 01:53:41 +000057#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000058
Bruce Allan9e019902013-01-12 07:28:54 +000059#define DRV_VERSION "2.2.14" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070060char e1000e_driver_name[] = "e1000e";
61const char e1000e_driver_version[] = DRV_VERSION;
62
stephen hemmingerb3f4d592012-03-13 06:04:20 +000063#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
64static int debug = -1;
65module_param(debug, int, 0);
66MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
67
Bruce Allan78cd29d2011-03-24 03:09:03 +000068static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
69
Auke Kokbc7f75f2007-09-17 12:30:59 -070070static const struct e1000_info *e1000_info_tbl[] = {
71 [board_82571] = &e1000_82571_info,
72 [board_82572] = &e1000_82572_info,
73 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070074 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000075 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070076 [board_80003es2lan] = &e1000_es2_info,
77 [board_ich8lan] = &e1000_ich8_info,
78 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070079 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000080 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000081 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000082 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070083};
84
Taku Izumi84f4ee92010-04-27 14:39:08 +000085struct e1000_reg_info {
86 u32 ofs;
87 char *name;
88};
89
Bruce Allanaf667a22010-12-31 06:10:01 +000090#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
91#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
92#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
93#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
94#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000095
Bruce Allanaf667a22010-12-31 06:10:01 +000096#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
97#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
98#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
99#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
100#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000101
102static const struct e1000_reg_info e1000_reg_info_tbl[] = {
103
104 /* General Registers */
105 {E1000_CTRL, "CTRL"},
106 {E1000_STATUS, "STATUS"},
107 {E1000_CTRL_EXT, "CTRL_EXT"},
108
109 /* Interrupt Registers */
110 {E1000_ICR, "ICR"},
111
Bruce Allanaf667a22010-12-31 06:10:01 +0000112 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000113 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000114 {E1000_RDLEN(0), "RDLEN"},
115 {E1000_RDH(0), "RDH"},
116 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000117 {E1000_RDTR, "RDTR"},
118 {E1000_RXDCTL(0), "RXDCTL"},
119 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000120 {E1000_RDBAL(0), "RDBAL"},
121 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000122 {E1000_RDFH, "RDFH"},
123 {E1000_RDFT, "RDFT"},
124 {E1000_RDFHS, "RDFHS"},
125 {E1000_RDFTS, "RDFTS"},
126 {E1000_RDFPC, "RDFPC"},
127
Bruce Allanaf667a22010-12-31 06:10:01 +0000128 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000129 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000130 {E1000_TDBAL(0), "TDBAL"},
131 {E1000_TDBAH(0), "TDBAH"},
132 {E1000_TDLEN(0), "TDLEN"},
133 {E1000_TDH(0), "TDH"},
134 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000135 {E1000_TIDV, "TIDV"},
136 {E1000_TXDCTL(0), "TXDCTL"},
137 {E1000_TADV, "TADV"},
138 {E1000_TARC(0), "TARC"},
139 {E1000_TDFH, "TDFH"},
140 {E1000_TDFT, "TDFT"},
141 {E1000_TDFHS, "TDFHS"},
142 {E1000_TDFTS, "TDFTS"},
143 {E1000_TDFPC, "TDFPC"},
144
145 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000146 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000147};
148
Bruce Allane921eb12012-11-28 09:28:37 +0000149/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000150 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000151 * @hw: pointer to the HW structure
152 * @reginfo: pointer to the register info table
153 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000154static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
155{
156 int n = 0;
157 char rname[16];
158 u32 regs[8];
159
160 switch (reginfo->ofs) {
161 case E1000_RXDCTL(0):
162 for (n = 0; n < 2; n++)
163 regs[n] = __er32(hw, E1000_RXDCTL(n));
164 break;
165 case E1000_TXDCTL(0):
166 for (n = 0; n < 2; n++)
167 regs[n] = __er32(hw, E1000_TXDCTL(n));
168 break;
169 case E1000_TARC(0):
170 for (n = 0; n < 2; n++)
171 regs[n] = __er32(hw, E1000_TARC(n));
172 break;
173 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000174 pr_info("%-15s %08x\n",
175 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000176 return;
177 }
178
179 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000180 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000181}
182
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000183static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
184 struct e1000_buffer *bi)
185{
186 int i;
187 struct e1000_ps_page *ps_page;
188
189 for (i = 0; i < adapter->rx_ps_pages; i++) {
190 ps_page = &bi->ps_pages[i];
191
192 if (ps_page->page) {
193 pr_info("packet dump for ps_page %d:\n", i);
194 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
195 16, 1, page_address(ps_page->page),
196 PAGE_SIZE, true);
197 }
198 }
199}
200
Bruce Allane921eb12012-11-28 09:28:37 +0000201/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000202 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000203 * @adapter: board private structure
204 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000205static void e1000e_dump(struct e1000_adapter *adapter)
206{
207 struct net_device *netdev = adapter->netdev;
208 struct e1000_hw *hw = &adapter->hw;
209 struct e1000_reg_info *reginfo;
210 struct e1000_ring *tx_ring = adapter->tx_ring;
211 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000212 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000213 __le64 a;
214 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000215 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000216 struct e1000_buffer *buffer_info;
217 struct e1000_ring *rx_ring = adapter->rx_ring;
218 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000219 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000220 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000221 __le64 a;
222 __le64 b;
223 __le64 c;
224 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000225 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000226 u32 staterr;
227 int i = 0;
228
229 if (!netif_msg_hw(adapter))
230 return;
231
232 /* Print netdevice Info */
233 if (netdev) {
234 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000235 pr_info("Device Name state trans_start last_rx\n");
236 pr_info("%-15s %016lX %016lX %016lX\n",
237 netdev->name, netdev->state, netdev->trans_start,
238 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000239 }
240
241 /* Print Registers */
242 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000243 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000244 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
245 reginfo->name; reginfo++) {
246 e1000_regdump(hw, reginfo);
247 }
248
Bruce Allanaf667a22010-12-31 06:10:01 +0000249 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000250 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000251 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000252
Bruce Allanaf667a22010-12-31 06:10:01 +0000253 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000254 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000255 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000256 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
257 0, tx_ring->next_to_use, tx_ring->next_to_clean,
258 (unsigned long long)buffer_info->dma,
259 buffer_info->length,
260 buffer_info->next_to_watch,
261 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000262
Bruce Allanaf667a22010-12-31 06:10:01 +0000263 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000264 if (!netif_msg_tx_done(adapter))
265 goto rx_ring_summary;
266
Bruce Allanaf667a22010-12-31 06:10:01 +0000267 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000268
269 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
270 *
271 * Legacy Transmit Descriptor
272 * +--------------------------------------------------------------+
273 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
274 * +--------------------------------------------------------------+
275 * 8 | Special | CSS | Status | CMD | CSO | Length |
276 * +--------------------------------------------------------------+
277 * 63 48 47 36 35 32 31 24 23 16 15 0
278 *
279 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
280 * 63 48 47 40 39 32 31 16 15 8 7 0
281 * +----------------------------------------------------------------+
282 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
283 * +----------------------------------------------------------------+
284 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
285 * +----------------------------------------------------------------+
286 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
287 *
288 * Extended Data Descriptor (DTYP=0x1)
289 * +----------------------------------------------------------------+
290 * 0 | Buffer Address [63:0] |
291 * +----------------------------------------------------------------+
292 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
293 * +----------------------------------------------------------------+
294 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
295 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000296 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
297 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
298 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000299 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000300 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000301 tx_desc = E1000_TX_DESC(*tx_ring, i);
302 buffer_info = &tx_ring->buffer_info[i];
303 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000304 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000305 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000306 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000307 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000309 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000311 next_desc = "";
312 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
313 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
314 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
315 i,
316 (unsigned long long)le64_to_cpu(u0->a),
317 (unsigned long long)le64_to_cpu(u0->b),
318 (unsigned long long)buffer_info->dma,
319 buffer_info->length, buffer_info->next_to_watch,
320 (unsigned long long)buffer_info->time_stamp,
321 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000322
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000323 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000324 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000325 16, 1, buffer_info->skb->data,
326 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000327 }
328
Bruce Allanaf667a22010-12-31 06:10:01 +0000329 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000330rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000331 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000332 pr_info("Queue [NTU] [NTC]\n");
333 pr_info(" %5d %5X %5X\n",
334 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000335
Bruce Allanaf667a22010-12-31 06:10:01 +0000336 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000337 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000338 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000339
Bruce Allanaf667a22010-12-31 06:10:01 +0000340 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000341 switch (adapter->rx_ps_pages) {
342 case 1:
343 case 2:
344 case 3:
345 /* [Extended] Packet Split Receive Descriptor Format
346 *
347 * +-----------------------------------------------------+
348 * 0 | Buffer Address 0 [63:0] |
349 * +-----------------------------------------------------+
350 * 8 | Buffer Address 1 [63:0] |
351 * +-----------------------------------------------------+
352 * 16 | Buffer Address 2 [63:0] |
353 * +-----------------------------------------------------+
354 * 24 | Buffer Address 3 [63:0] |
355 * +-----------------------------------------------------+
356 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000357 pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000358 /* [Extended] Receive Descriptor (Write-Back) Format
359 *
360 * 63 48 47 32 31 13 12 8 7 4 3 0
361 * +------------------------------------------------------+
362 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
363 * | Checksum | Ident | | Queue | | Type |
364 * +------------------------------------------------------+
365 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
366 * +------------------------------------------------------+
367 * 63 48 47 32 31 20 19 0
368 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000369 pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000370 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000371 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000372 buffer_info = &rx_ring->buffer_info[i];
373 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
374 u1 = (struct my_u1 *)rx_desc_ps;
375 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000376 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000377
378 if (i == rx_ring->next_to_use)
379 next_desc = " NTU";
380 else if (i == rx_ring->next_to_clean)
381 next_desc = " NTC";
382 else
383 next_desc = "";
384
Taku Izumi84f4ee92010-04-27 14:39:08 +0000385 if (staterr & E1000_RXD_STAT_DD) {
386 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000387 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
388 "RWB", i,
389 (unsigned long long)le64_to_cpu(u1->a),
390 (unsigned long long)le64_to_cpu(u1->b),
391 (unsigned long long)le64_to_cpu(u1->c),
392 (unsigned long long)le64_to_cpu(u1->d),
393 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000394 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000395 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
396 "R ", i,
397 (unsigned long long)le64_to_cpu(u1->a),
398 (unsigned long long)le64_to_cpu(u1->b),
399 (unsigned long long)le64_to_cpu(u1->c),
400 (unsigned long long)le64_to_cpu(u1->d),
401 (unsigned long long)buffer_info->dma,
402 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000403
404 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000405 e1000e_dump_ps_pages(adapter,
406 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000407 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000408 }
409 break;
410 default:
411 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000412 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000413 *
Bruce Allan5f450212011-07-22 06:21:46 +0000414 * +-----------------------------------------------------+
415 * 0 | Buffer Address [63:0] |
416 * +-----------------------------------------------------+
417 * 8 | Reserved |
418 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000419 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000420 pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000421 /* Extended Receive Descriptor (Write-Back) Format
422 *
423 * 63 48 47 32 31 24 23 4 3 0
424 * +------------------------------------------------------+
425 * | RSS Hash | | | |
426 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
427 * | Packet | IP | | | Type |
428 * | Checksum | Ident | | | |
429 * +------------------------------------------------------+
430 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
431 * +------------------------------------------------------+
432 * 63 48 47 32 31 20 19 0
433 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000434 pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
Bruce Allan5f450212011-07-22 06:21:46 +0000435
436 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000437 const char *next_desc;
438
Taku Izumi84f4ee92010-04-27 14:39:08 +0000439 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000440 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
441 u1 = (struct my_u1 *)rx_desc;
442 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000443
444 if (i == rx_ring->next_to_use)
445 next_desc = " NTU";
446 else if (i == rx_ring->next_to_clean)
447 next_desc = " NTC";
448 else
449 next_desc = "";
450
Bruce Allan5f450212011-07-22 06:21:46 +0000451 if (staterr & E1000_RXD_STAT_DD) {
452 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000453 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
454 "RWB", i,
455 (unsigned long long)le64_to_cpu(u1->a),
456 (unsigned long long)le64_to_cpu(u1->b),
457 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000458 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000459 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
460 "R ", i,
461 (unsigned long long)le64_to_cpu(u1->a),
462 (unsigned long long)le64_to_cpu(u1->b),
463 (unsigned long long)buffer_info->dma,
464 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000465
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000466 if (netif_msg_pktdata(adapter) &&
467 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000468 print_hex_dump(KERN_INFO, "",
469 DUMP_PREFIX_ADDRESS, 16,
470 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000471 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000472 adapter->rx_buffer_len,
473 true);
474 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000475 }
476 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000477}
478
Auke Kokbc7f75f2007-09-17 12:30:59 -0700479/**
480 * e1000_desc_unused - calculate if we have unused descriptors
481 **/
482static int e1000_desc_unused(struct e1000_ring *ring)
483{
484 if (ring->next_to_clean > ring->next_to_use)
485 return ring->next_to_clean - ring->next_to_use - 1;
486
487 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
488}
489
490/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000491 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
492 * @adapter: board private structure
493 * @hwtstamps: time stamp structure to update
494 * @systim: unsigned 64bit system time value.
495 *
496 * Convert the system time value stored in the RX/TXSTMP registers into a
497 * hwtstamp which can be used by the upper level time stamping functions.
498 *
499 * The 'systim_lock' spinlock is used to protect the consistency of the
500 * system time value. This is needed because reading the 64 bit time
501 * value involves reading two 32 bit registers. The first read latches the
502 * value.
503 **/
504static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
505 struct skb_shared_hwtstamps *hwtstamps,
506 u64 systim)
507{
508 u64 ns;
509 unsigned long flags;
510
511 spin_lock_irqsave(&adapter->systim_lock, flags);
512 ns = timecounter_cyc2time(&adapter->tc, systim);
513 spin_unlock_irqrestore(&adapter->systim_lock, flags);
514
515 memset(hwtstamps, 0, sizeof(*hwtstamps));
516 hwtstamps->hwtstamp = ns_to_ktime(ns);
517}
518
519/**
520 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
521 * @adapter: board private structure
522 * @status: descriptor extended error and status field
523 * @skb: particular skb to include time stamp
524 *
525 * If the time stamp is valid, convert it into the timecounter ns value
526 * and store that result into the shhwtstamps structure which is passed
527 * up the network stack.
528 **/
529static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
530 struct sk_buff *skb)
531{
532 struct e1000_hw *hw = &adapter->hw;
533 u64 rxstmp;
534
535 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
536 !(status & E1000_RXDEXT_STATERR_TST) ||
537 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
538 return;
539
540 /* The Rx time stamp registers contain the time stamp. No other
541 * received packet will be time stamped until the Rx time stamp
542 * registers are read. Because only one packet can be time stamped
543 * at a time, the register values must belong to this packet and
544 * therefore none of the other additional attributes need to be
545 * compared.
546 */
547 rxstmp = (u64)er32(RXSTMPL);
548 rxstmp |= (u64)er32(RXSTMPH) << 32;
549 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
550
551 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
552}
553
554/**
Bruce Allanad680762008-03-28 09:15:03 -0700555 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000557 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700558 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
559 * @skb: pointer to sk_buff to be indicated to stack
560 **/
561static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000562 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000563 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700564{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000565 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000566
567 e1000e_rx_hwtstamp(adapter, staterr, skb);
568
Auke Kokbc7f75f2007-09-17 12:30:59 -0700569 skb->protocol = eth_type_trans(skb, netdev);
570
Bruce Allanb67e1912012-12-27 08:32:33 +0000571 if (staterr & E1000_RXD_STAT_VP)
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000572 __vlan_hwaccel_put_tag(skb, tag);
573
574 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575}
576
577/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000578 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000579 * @adapter: board private structure
580 * @status_err: receive descriptor status and error fields
581 * @csum: receive descriptor csum field
582 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583 **/
584static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000585 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700586{
587 u16 status = (u16)status_err;
588 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700589
590 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591
Bruce Allanafd12932012-01-05 00:34:05 +0000592 /* Rx checksum disabled */
593 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
594 return;
595
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 /* Ignore Checksum bit is set */
597 if (status & E1000_RXD_STAT_IXSM)
598 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000599
Bruce Allan2e1706f2012-06-30 20:02:42 +0000600 /* TCP/UDP checksum error bit or IP checksum error bit is set */
601 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 /* let the stack verify checksum errors */
603 adapter->hw_csum_err++;
604 return;
605 }
606
607 /* TCP/UDP Checksum has not been calculated */
608 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
609 return;
610
611 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000612 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 adapter->hw_csum_good++;
614}
615
Bruce Allan55aa6982011-12-16 00:45:45 +0000616static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700617{
Bruce Allan55aa6982011-12-16 00:45:45 +0000618 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700619 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000620 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700621
Bruce Allanbdc125f2012-03-20 03:47:52 +0000622 writel(i, rx_ring->tail);
623
624 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700625 u32 rctl = er32(RCTL);
626 ew32(RCTL, rctl & ~E1000_RCTL_EN);
627 e_err("ME firmware caused invalid RDT - resetting\n");
628 schedule_work(&adapter->reset_task);
629 }
630}
631
Bruce Allan55aa6982011-12-16 00:45:45 +0000632static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700633{
Bruce Allan55aa6982011-12-16 00:45:45 +0000634 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700635 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000636 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700637
Bruce Allanbdc125f2012-03-20 03:47:52 +0000638 writel(i, tx_ring->tail);
639
640 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700641 u32 tctl = er32(TCTL);
642 ew32(TCTL, tctl & ~E1000_TCTL_EN);
643 e_err("ME firmware caused invalid TDT - resetting\n");
644 schedule_work(&adapter->reset_task);
645 }
646}
647
648/**
Bruce Allan5f450212011-07-22 06:21:46 +0000649 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000650 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000652static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000653 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654{
Bruce Allan55aa6982011-12-16 00:45:45 +0000655 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700656 struct net_device *netdev = adapter->netdev;
657 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000658 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659 struct e1000_buffer *buffer_info;
660 struct sk_buff *skb;
661 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000662 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700663
664 i = rx_ring->next_to_use;
665 buffer_info = &rx_ring->buffer_info[i];
666
667 while (cleaned_count--) {
668 skb = buffer_info->skb;
669 if (skb) {
670 skb_trim(skb, 0);
671 goto map_skb;
672 }
673
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000674 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700675 if (!skb) {
676 /* Better luck next round */
677 adapter->alloc_rx_buff_failed++;
678 break;
679 }
680
Auke Kokbc7f75f2007-09-17 12:30:59 -0700681 buffer_info->skb = skb;
682map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000683 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000685 DMA_FROM_DEVICE);
686 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000687 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688 adapter->rx_dma_failed++;
689 break;
690 }
691
Bruce Allan5f450212011-07-22 06:21:46 +0000692 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
693 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700694
Tom Herbert50849d72010-05-05 14:02:49 +0000695 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000696 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000697 * know there are new descriptors to fetch. (Only
698 * applicable for weak-ordered memory model archs,
699 * such as IA-64).
700 */
701 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700702 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000703 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700704 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000705 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000706 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707 i++;
708 if (i == rx_ring->count)
709 i = 0;
710 buffer_info = &rx_ring->buffer_info[i];
711 }
712
Tom Herbert50849d72010-05-05 14:02:49 +0000713 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714}
715
716/**
717 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000718 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000720static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000721 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700722{
Bruce Allan55aa6982011-12-16 00:45:45 +0000723 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700724 struct net_device *netdev = adapter->netdev;
725 struct pci_dev *pdev = adapter->pdev;
726 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700727 struct e1000_buffer *buffer_info;
728 struct e1000_ps_page *ps_page;
729 struct sk_buff *skb;
730 unsigned int i, j;
731
732 i = rx_ring->next_to_use;
733 buffer_info = &rx_ring->buffer_info[i];
734
735 while (cleaned_count--) {
736 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
737
738 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700739 ps_page = &buffer_info->ps_pages[j];
740 if (j >= adapter->rx_ps_pages) {
741 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000742 rx_desc->read.buffer_addr[j + 1] =
743 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700744 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700745 }
Auke Kok47f44e42007-10-25 13:57:44 -0700746 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000747 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700748 if (!ps_page->page) {
749 adapter->alloc_rx_buff_failed++;
750 goto no_buffers;
751 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000752 ps_page->dma = dma_map_page(&pdev->dev,
753 ps_page->page,
754 0, PAGE_SIZE,
755 DMA_FROM_DEVICE);
756 if (dma_mapping_error(&pdev->dev,
757 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700758 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000759 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700760 adapter->rx_dma_failed++;
761 goto no_buffers;
762 }
763 }
Bruce Allane921eb12012-11-28 09:28:37 +0000764 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700765 * didn't change because each write-back
766 * erases this info.
767 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000768 rx_desc->read.buffer_addr[j + 1] =
769 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700770 }
771
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000772 skb = __netdev_alloc_skb_ip_align(netdev,
773 adapter->rx_ps_bsize0,
774 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700775
776 if (!skb) {
777 adapter->alloc_rx_buff_failed++;
778 break;
779 }
780
Auke Kokbc7f75f2007-09-17 12:30:59 -0700781 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000782 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700783 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000784 DMA_FROM_DEVICE);
785 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000786 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700787 adapter->rx_dma_failed++;
788 /* cleanup skb */
789 dev_kfree_skb_any(skb);
790 buffer_info->skb = NULL;
791 break;
792 }
793
794 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
795
Tom Herbert50849d72010-05-05 14:02:49 +0000796 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000797 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000798 * know there are new descriptors to fetch. (Only
799 * applicable for weak-ordered memory model archs,
800 * such as IA-64).
801 */
802 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700803 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000804 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700805 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000806 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000807 }
808
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 i++;
810 if (i == rx_ring->count)
811 i = 0;
812 buffer_info = &rx_ring->buffer_info[i];
813 }
814
815no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000816 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700817}
818
819/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700820 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000821 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700822 * @cleaned_count: number of buffers to allocate this pass
823 **/
824
Bruce Allan55aa6982011-12-16 00:45:45 +0000825static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000826 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700827{
Bruce Allan55aa6982011-12-16 00:45:45 +0000828 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700829 struct net_device *netdev = adapter->netdev;
830 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000831 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700832 struct e1000_buffer *buffer_info;
833 struct sk_buff *skb;
834 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000835 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700836
837 i = rx_ring->next_to_use;
838 buffer_info = &rx_ring->buffer_info[i];
839
840 while (cleaned_count--) {
841 skb = buffer_info->skb;
842 if (skb) {
843 skb_trim(skb, 0);
844 goto check_page;
845 }
846
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000847 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700848 if (unlikely(!skb)) {
849 /* Better luck next round */
850 adapter->alloc_rx_buff_failed++;
851 break;
852 }
853
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700854 buffer_info->skb = skb;
855check_page:
856 /* allocate a new page if necessary */
857 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000858 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700859 if (unlikely(!buffer_info->page)) {
860 adapter->alloc_rx_buff_failed++;
861 break;
862 }
863 }
864
865 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000866 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700867 buffer_info->page, 0,
868 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000869 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700870
Bruce Allan5f450212011-07-22 06:21:46 +0000871 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
872 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700873
874 if (unlikely(++i == rx_ring->count))
875 i = 0;
876 buffer_info = &rx_ring->buffer_info[i];
877 }
878
879 if (likely(rx_ring->next_to_use != i)) {
880 rx_ring->next_to_use = i;
881 if (unlikely(i-- == 0))
882 i = (rx_ring->count - 1);
883
884 /* Force memory writes to complete before letting h/w
885 * know there are new descriptors to fetch. (Only
886 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000887 * such as IA-64).
888 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700889 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700890 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000891 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700892 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000893 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700894 }
895}
896
Bruce Allan70495a52012-01-11 01:26:50 +0000897static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
898 struct sk_buff *skb)
899{
900 if (netdev->features & NETIF_F_RXHASH)
901 skb->rxhash = le32_to_cpu(rss);
902}
903
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700904/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000905 * e1000_clean_rx_irq - Send received data up the network stack
906 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700907 *
908 * the return value indicates whether actual cleaning was done, there
909 * is no guarantee that everything was cleaned
910 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000911static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
912 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913{
Bruce Allan55aa6982011-12-16 00:45:45 +0000914 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700915 struct net_device *netdev = adapter->netdev;
916 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000917 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000918 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000920 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700921 unsigned int i;
922 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000923 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
925
926 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000927 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
928 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929 buffer_info = &rx_ring->buffer_info[i];
930
Bruce Allan5f450212011-07-22 06:21:46 +0000931 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933
934 if (*work_done >= work_to_do)
935 break;
936 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000937 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700938
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 skb = buffer_info->skb;
940 buffer_info->skb = NULL;
941
942 prefetch(skb->data - NET_IP_ALIGN);
943
944 i++;
945 if (i == rx_ring->count)
946 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000947 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700948 prefetch(next_rxd);
949
950 next_buffer = &rx_ring->buffer_info[i];
951
Rusty Russell3db1cd52011-12-19 13:56:45 +0000952 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700953 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000954 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955 buffer_info->dma,
956 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000957 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 buffer_info->dma = 0;
959
Bruce Allan5f450212011-07-22 06:21:46 +0000960 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961
Bruce Allane921eb12012-11-28 09:28:37 +0000962 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000963 * packet, if that's the case we need to toss it. In fact, we
964 * need to toss every packet with the EOP bit clear and the
965 * next frame that _does_ have the EOP bit set, as it is by
966 * definition only a frame fragment
967 */
Bruce Allan5f450212011-07-22 06:21:46 +0000968 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000969 adapter->flags2 |= FLAG2_IS_DISCARDING;
970
971 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700972 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000973 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700974 /* recycle */
975 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000976 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000977 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978 goto next_desc;
979 }
980
Ben Greearcf955e62012-02-11 15:39:51 +0000981 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
982 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983 /* recycle */
984 buffer_info->skb = skb;
985 goto next_desc;
986 }
987
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000988 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000989 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
990 /* If configured to store CRC, don't subtract FCS,
991 * but keep the FCS bytes out of the total_rx_bytes
992 * counter
993 */
994 if (netdev->features & NETIF_F_RXFCS)
995 total_rx_bytes -= 4;
996 else
997 length -= 4;
998 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000999
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 total_rx_bytes += length;
1001 total_rx_packets++;
1002
Bruce Allane921eb12012-11-28 09:28:37 +00001003 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -07001005 * of reassembly being done in the stack
1006 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007 if (length < copybreak) {
1008 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +00001009 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -07001011 skb_copy_to_linear_data_offset(new_skb,
1012 -NET_IP_ALIGN,
1013 (skb->data -
1014 NET_IP_ALIGN),
1015 (length +
1016 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001017 /* save the skb in buffer_info as good */
1018 buffer_info->skb = skb;
1019 skb = new_skb;
1020 }
1021 /* else just continue with the old one */
1022 }
1023 /* end copybreak code */
1024 skb_put(skb, length);
1025
1026 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001027 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028
Bruce Allan70495a52012-01-11 01:26:50 +00001029 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1030
Bruce Allan5f450212011-07-22 06:21:46 +00001031 e1000_receive_skb(adapter, netdev, skb, staterr,
1032 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033
1034next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001035 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
1037 /* return some buffers to hardware, one at a time is too slow */
1038 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001039 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001040 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041 cleaned_count = 0;
1042 }
1043
1044 /* use prefetched values */
1045 rx_desc = next_rxd;
1046 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001047
1048 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 }
1050 rx_ring->next_to_clean = i;
1051
1052 cleaned_count = e1000_desc_unused(rx_ring);
1053 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001054 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001057 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 return cleaned;
1059}
1060
Bruce Allan55aa6982011-12-16 00:45:45 +00001061static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1062 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063{
Bruce Allan55aa6982011-12-16 00:45:45 +00001064 struct e1000_adapter *adapter = tx_ring->adapter;
1065
Alexander Duyck03b13202009-12-02 16:45:31 +00001066 if (buffer_info->dma) {
1067 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001068 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1069 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001070 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001071 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1072 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001073 buffer_info->dma = 0;
1074 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 if (buffer_info->skb) {
1076 dev_kfree_skb_any(buffer_info->skb);
1077 buffer_info->skb = NULL;
1078 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001079 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080}
1081
Bruce Allan41cec6f2009-11-20 23:28:56 +00001082static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001083{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001084 struct e1000_adapter *adapter = container_of(work,
1085 struct e1000_adapter,
1086 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001087 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 struct e1000_ring *tx_ring = adapter->tx_ring;
1089 unsigned int i = tx_ring->next_to_clean;
1090 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1091 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001092 struct e1000_hw *hw = &adapter->hw;
1093 u16 phy_status, phy_1000t_status, phy_ext_status;
1094 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001096 if (test_bit(__E1000_DOWN, &adapter->state))
1097 return;
1098
Jeff Kirsher09357b02011-11-18 14:25:00 +00001099 if (!adapter->tx_hang_recheck &&
1100 (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001101 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001102 * flush pending descriptor writebacks to memory
1103 */
1104 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1105 /* execute the writes immediately */
1106 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001107 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001108 * the write is successful
1109 */
1110 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1111 /* execute the writes immediately */
1112 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001113 adapter->tx_hang_recheck = true;
1114 return;
1115 }
1116 /* Real hang detected */
1117 adapter->tx_hang_recheck = false;
1118 netif_stop_queue(netdev);
1119
Bruce Allan41cec6f2009-11-20 23:28:56 +00001120 e1e_rphy(hw, PHY_STATUS, &phy_status);
1121 e1e_rphy(hw, PHY_1000T_STATUS, &phy_1000t_status);
1122 e1e_rphy(hw, PHY_EXT_STATUS, &phy_ext_status);
1123
1124 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1125
1126 /* detected Hardware unit hang */
1127 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001128 " TDH <%x>\n"
1129 " TDT <%x>\n"
1130 " next_to_use <%x>\n"
1131 " next_to_clean <%x>\n"
1132 "buffer_info[next_to_clean]:\n"
1133 " time_stamp <%lx>\n"
1134 " next_to_watch <%x>\n"
1135 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001136 " next_to_watch.status <%x>\n"
1137 "MAC Status <%x>\n"
1138 "PHY Status <%x>\n"
1139 "PHY 1000BASE-T Status <%x>\n"
1140 "PHY Extended Status <%x>\n"
1141 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001142 readl(tx_ring->head),
1143 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001144 tx_ring->next_to_use,
1145 tx_ring->next_to_clean,
1146 tx_ring->buffer_info[eop].time_stamp,
1147 eop,
1148 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001149 eop_desc->upper.fields.status,
1150 er32(STATUS),
1151 phy_status,
1152 phy_1000t_status,
1153 phy_ext_status,
1154 pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001155
1156 /* Suggest workaround for known h/w issue */
1157 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1158 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159}
1160
1161/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001162 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1163 * @work: pointer to work struct
1164 *
1165 * This work function polls the TSYNCTXCTL valid bit to determine when a
1166 * timestamp has been taken for the current stored skb. The timestamp must
1167 * be for this skb because only one such packet is allowed in the queue.
1168 */
1169static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1170{
1171 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1172 tx_hwtstamp_work);
1173 struct e1000_hw *hw = &adapter->hw;
1174
1175 if (!adapter->tx_hwtstamp_skb)
1176 return;
1177
1178 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1179 struct skb_shared_hwtstamps shhwtstamps;
1180 u64 txstmp;
1181
1182 txstmp = er32(TXSTMPL);
1183 txstmp |= (u64)er32(TXSTMPH) << 32;
1184
1185 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1186
1187 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1188 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1189 adapter->tx_hwtstamp_skb = NULL;
1190 } else {
1191 /* reschedule to check later */
1192 schedule_work(&adapter->tx_hwtstamp_work);
1193 }
1194}
1195
1196/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001198 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 *
1200 * the return value indicates whether actual cleaning was done, there
1201 * is no guarantee that everything was cleaned
1202 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001203static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204{
Bruce Allan55aa6982011-12-16 00:45:45 +00001205 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 struct net_device *netdev = adapter->netdev;
1207 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 struct e1000_tx_desc *tx_desc, *eop_desc;
1209 struct e1000_buffer *buffer_info;
1210 unsigned int i, eop;
1211 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001212 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001213 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214
1215 i = tx_ring->next_to_clean;
1216 eop = tx_ring->buffer_info[i].next_to_watch;
1217 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1218
Alexander Duyck12d04a32009-03-25 22:05:03 +00001219 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1220 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001221 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001222 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001223 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 tx_desc = E1000_TX_DESC(*tx_ring, i);
1225 buffer_info = &tx_ring->buffer_info[i];
1226 cleaned = (i == eop);
1227
1228 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001229 total_tx_packets += buffer_info->segs;
1230 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001231 if (buffer_info->skb) {
1232 bytes_compl += buffer_info->skb->len;
1233 pkts_compl++;
1234 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001235 }
1236
Bruce Allan55aa6982011-12-16 00:45:45 +00001237 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001238 tx_desc->upper.data = 0;
1239
1240 i++;
1241 if (i == tx_ring->count)
1242 i = 0;
1243 }
1244
Terry Loftindac87612010-04-09 10:29:49 +00001245 if (i == tx_ring->next_to_use)
1246 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 eop = tx_ring->buffer_info[i].next_to_watch;
1248 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 }
1250
1251 tx_ring->next_to_clean = i;
1252
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001253 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1254
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001256 if (count && netif_carrier_ok(netdev) &&
1257 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258 /* Make sure that anybody stopping the queue after this
1259 * sees the new next_to_clean.
1260 */
1261 smp_mb();
1262
1263 if (netif_queue_stopped(netdev) &&
1264 !(test_bit(__E1000_DOWN, &adapter->state))) {
1265 netif_wake_queue(netdev);
1266 ++adapter->restart_queue;
1267 }
1268 }
1269
1270 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001271 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001272 * check with the clearing of time_stamp and movement of i
1273 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001274 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001275 if (tx_ring->buffer_info[i].time_stamp &&
1276 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001277 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001278 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001279 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001280 else
1281 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282 }
1283 adapter->total_tx_bytes += total_tx_bytes;
1284 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001285 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286}
1287
1288/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001289 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001290 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001291 *
1292 * the return value indicates whether actual cleaning was done, there
1293 * is no guarantee that everything was cleaned
1294 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001295static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1296 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297{
Bruce Allan55aa6982011-12-16 00:45:45 +00001298 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001299 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001300 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1301 struct net_device *netdev = adapter->netdev;
1302 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 struct e1000_buffer *buffer_info, *next_buffer;
1304 struct e1000_ps_page *ps_page;
1305 struct sk_buff *skb;
1306 unsigned int i, j;
1307 u32 length, staterr;
1308 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001309 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1311
1312 i = rx_ring->next_to_clean;
1313 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1314 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1315 buffer_info = &rx_ring->buffer_info[i];
1316
1317 while (staterr & E1000_RXD_STAT_DD) {
1318 if (*work_done >= work_to_do)
1319 break;
1320 (*work_done)++;
1321 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001322 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323
1324 /* in the packet split case this is header only */
1325 prefetch(skb->data - NET_IP_ALIGN);
1326
1327 i++;
1328 if (i == rx_ring->count)
1329 i = 0;
1330 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1331 prefetch(next_rxd);
1332
1333 next_buffer = &rx_ring->buffer_info[i];
1334
Rusty Russell3db1cd52011-12-19 13:56:45 +00001335 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001337 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001338 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339 buffer_info->dma = 0;
1340
Bruce Allanaf667a22010-12-31 06:10:01 +00001341 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001342 if (!(staterr & E1000_RXD_STAT_EOP))
1343 adapter->flags2 |= FLAG2_IS_DISCARDING;
1344
1345 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001346 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001348 if (staterr & E1000_RXD_STAT_EOP)
1349 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001350 goto next_desc;
1351 }
1352
Ben Greearcf955e62012-02-11 15:39:51 +00001353 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1354 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001355 dev_kfree_skb_irq(skb);
1356 goto next_desc;
1357 }
1358
1359 length = le16_to_cpu(rx_desc->wb.middle.length0);
1360
1361 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001362 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001363 dev_kfree_skb_irq(skb);
1364 goto next_desc;
1365 }
1366
1367 /* Good Receive */
1368 skb_put(skb, length);
1369
1370 {
Bruce Allane921eb12012-11-28 09:28:37 +00001371 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001372 * it more efficient than reusing j
1373 */
1374 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001375
Bruce Allane921eb12012-11-28 09:28:37 +00001376 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001377 * packet throughput, so unsplit small packets and
1378 * save the alloc/put only valid in softirq (napi)
1379 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001380 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001381 if (l1 && (l1 <= copybreak) &&
1382 ((length + l1) <= adapter->rx_ps_bsize0)) {
1383 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001384
Bruce Allan0e15df42012-01-31 06:37:11 +00001385 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001386
Bruce Allane921eb12012-11-28 09:28:37 +00001387 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001388 * kmap_atomic, so we can't hold the mapping
1389 * very long
1390 */
1391 dma_sync_single_for_cpu(&pdev->dev,
1392 ps_page->dma,
1393 PAGE_SIZE,
1394 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001395 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001396 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001397 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001398 dma_sync_single_for_device(&pdev->dev,
1399 ps_page->dma,
1400 PAGE_SIZE,
1401 DMA_FROM_DEVICE);
1402
1403 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001404 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1405 if (!(netdev->features & NETIF_F_RXFCS))
1406 l1 -= 4;
1407 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001408
1409 skb_put(skb, l1);
1410 goto copydone;
1411 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001412 }
1413
1414 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1415 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1416 if (!length)
1417 break;
1418
Auke Kok47f44e42007-10-25 13:57:44 -07001419 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001420 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1421 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001422 ps_page->dma = 0;
1423 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1424 ps_page->page = NULL;
1425 skb->len += length;
1426 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001427 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001428 }
1429
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001430 /* strip the ethernet crc, problem is we're using pages now so
1431 * this whole operation can get a little cpu intensive
1432 */
Ben Greear01840392012-02-11 15:39:25 +00001433 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1434 if (!(netdev->features & NETIF_F_RXFCS))
1435 pskb_trim(skb, skb->len - 4);
1436 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001437
Auke Kokbc7f75f2007-09-17 12:30:59 -07001438copydone:
1439 total_rx_bytes += skb->len;
1440 total_rx_packets++;
1441
Bruce Allan2e1706f2012-06-30 20:02:42 +00001442 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001443
Bruce Allan70495a52012-01-11 01:26:50 +00001444 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1445
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446 if (rx_desc->wb.upper.header_status &
1447 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1448 adapter->rx_hdr_split++;
1449
Bruce Allanb67e1912012-12-27 08:32:33 +00001450 e1000_receive_skb(adapter, netdev, skb, staterr,
1451 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452
1453next_desc:
1454 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1455 buffer_info->skb = NULL;
1456
1457 /* return some buffers to hardware, one at a time is too slow */
1458 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001459 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001460 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 cleaned_count = 0;
1462 }
1463
1464 /* use prefetched values */
1465 rx_desc = next_rxd;
1466 buffer_info = next_buffer;
1467
1468 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1469 }
1470 rx_ring->next_to_clean = i;
1471
1472 cleaned_count = e1000_desc_unused(rx_ring);
1473 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001474 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475
Auke Kokbc7f75f2007-09-17 12:30:59 -07001476 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001477 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001478 return cleaned;
1479}
1480
1481/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001482 * e1000_consume_page - helper function
1483 **/
1484static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1485 u16 length)
1486{
1487 bi->page = NULL;
1488 skb->len += length;
1489 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001490 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001491}
1492
1493/**
1494 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1495 * @adapter: board private structure
1496 *
1497 * the return value indicates whether actual cleaning was done, there
1498 * is no guarantee that everything was cleaned
1499 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001500static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1501 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001502{
Bruce Allan55aa6982011-12-16 00:45:45 +00001503 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001504 struct net_device *netdev = adapter->netdev;
1505 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001506 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001507 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001508 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001509 unsigned int i;
1510 int cleaned_count = 0;
1511 bool cleaned = false;
1512 unsigned int total_rx_bytes=0, total_rx_packets=0;
1513
1514 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001515 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1516 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001517 buffer_info = &rx_ring->buffer_info[i];
1518
Bruce Allan5f450212011-07-22 06:21:46 +00001519 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001520 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001521
1522 if (*work_done >= work_to_do)
1523 break;
1524 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001525 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001527 skb = buffer_info->skb;
1528 buffer_info->skb = NULL;
1529
1530 ++i;
1531 if (i == rx_ring->count)
1532 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001533 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001534 prefetch(next_rxd);
1535
1536 next_buffer = &rx_ring->buffer_info[i];
1537
1538 cleaned = true;
1539 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001540 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1541 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001542 buffer_info->dma = 0;
1543
Bruce Allan5f450212011-07-22 06:21:46 +00001544 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001545
1546 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001547 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001548 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1549 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001550 /* recycle both page and skb */
1551 buffer_info->skb = skb;
1552 /* an error means any chain goes out the window too */
1553 if (rx_ring->rx_skb_top)
1554 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1555 rx_ring->rx_skb_top = NULL;
1556 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001557 }
1558
Bruce Allanf0f1a172010-12-11 05:53:32 +00001559#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001560 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001561 /* this descriptor is only the beginning (or middle) */
1562 if (!rxtop) {
1563 /* this is the beginning of a chain */
1564 rxtop = skb;
1565 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1566 0, length);
1567 } else {
1568 /* this is the middle of a chain */
1569 skb_fill_page_desc(rxtop,
1570 skb_shinfo(rxtop)->nr_frags,
1571 buffer_info->page, 0, length);
1572 /* re-use the skb, only consumed the page */
1573 buffer_info->skb = skb;
1574 }
1575 e1000_consume_page(buffer_info, rxtop, length);
1576 goto next_desc;
1577 } else {
1578 if (rxtop) {
1579 /* end of the chain */
1580 skb_fill_page_desc(rxtop,
1581 skb_shinfo(rxtop)->nr_frags,
1582 buffer_info->page, 0, length);
1583 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001584 * page
1585 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001586 buffer_info->skb = skb;
1587 skb = rxtop;
1588 rxtop = NULL;
1589 e1000_consume_page(buffer_info, skb, length);
1590 } else {
1591 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001592 * copybreak to save the put_page/alloc_page
1593 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001594 if (length <= copybreak &&
1595 skb_tailroom(skb) >= length) {
1596 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001597 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001598 memcpy(skb_tail_pointer(skb), vaddr,
1599 length);
Cong Wang46790262011-11-25 23:14:23 +08001600 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001601 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001602 * buffer_info->page
1603 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001604 skb_put(skb, length);
1605 } else {
1606 skb_fill_page_desc(skb, 0,
1607 buffer_info->page, 0,
1608 length);
1609 e1000_consume_page(buffer_info, skb,
1610 length);
1611 }
1612 }
1613 }
1614
Bruce Allan2e1706f2012-06-30 20:02:42 +00001615 /* Receive Checksum Offload */
1616 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001617
Bruce Allan70495a52012-01-11 01:26:50 +00001618 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1619
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001620 /* probably a little skewed due to removing CRC */
1621 total_rx_bytes += skb->len;
1622 total_rx_packets++;
1623
1624 /* eth type trans needs skb->data to point to something */
1625 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001626 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001627 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001628 goto next_desc;
1629 }
1630
Bruce Allan5f450212011-07-22 06:21:46 +00001631 e1000_receive_skb(adapter, netdev, skb, staterr,
1632 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001633
1634next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001635 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001636
1637 /* return some buffers to hardware, one at a time is too slow */
1638 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001639 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001640 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001641 cleaned_count = 0;
1642 }
1643
1644 /* use prefetched values */
1645 rx_desc = next_rxd;
1646 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001647
1648 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001649 }
1650 rx_ring->next_to_clean = i;
1651
1652 cleaned_count = e1000_desc_unused(rx_ring);
1653 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001654 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001655
1656 adapter->total_rx_bytes += total_rx_bytes;
1657 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001658 return cleaned;
1659}
1660
1661/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001663 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001664 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001665static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666{
Bruce Allan55aa6982011-12-16 00:45:45 +00001667 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 struct e1000_buffer *buffer_info;
1669 struct e1000_ps_page *ps_page;
1670 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001671 unsigned int i, j;
1672
1673 /* Free all the Rx ring sk_buffs */
1674 for (i = 0; i < rx_ring->count; i++) {
1675 buffer_info = &rx_ring->buffer_info[i];
1676 if (buffer_info->dma) {
1677 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001678 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001679 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001680 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001681 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001682 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001683 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001684 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001686 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001688 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 buffer_info->dma = 0;
1690 }
1691
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001692 if (buffer_info->page) {
1693 put_page(buffer_info->page);
1694 buffer_info->page = NULL;
1695 }
1696
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 if (buffer_info->skb) {
1698 dev_kfree_skb(buffer_info->skb);
1699 buffer_info->skb = NULL;
1700 }
1701
1702 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001703 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001704 if (!ps_page->page)
1705 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001706 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1707 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 ps_page->dma = 0;
1709 put_page(ps_page->page);
1710 ps_page->page = NULL;
1711 }
1712 }
1713
1714 /* there also may be some cached data from a chained receive */
1715 if (rx_ring->rx_skb_top) {
1716 dev_kfree_skb(rx_ring->rx_skb_top);
1717 rx_ring->rx_skb_top = NULL;
1718 }
1719
Auke Kokbc7f75f2007-09-17 12:30:59 -07001720 /* Zero out the descriptor ring */
1721 memset(rx_ring->desc, 0, rx_ring->size);
1722
1723 rx_ring->next_to_clean = 0;
1724 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001725 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726
Bruce Allanc5083cf2011-12-16 00:45:40 +00001727 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001728 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1729 e1000e_update_rdt_wa(rx_ring, 0);
1730 else
1731 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732}
1733
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001734static void e1000e_downshift_workaround(struct work_struct *work)
1735{
1736 struct e1000_adapter *adapter = container_of(work,
1737 struct e1000_adapter, downshift_task);
1738
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001739 if (test_bit(__E1000_DOWN, &adapter->state))
1740 return;
1741
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001742 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1743}
1744
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745/**
1746 * e1000_intr_msi - Interrupt Handler
1747 * @irq: interrupt number
1748 * @data: pointer to a network interface device structure
1749 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001750static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751{
1752 struct net_device *netdev = data;
1753 struct e1000_adapter *adapter = netdev_priv(netdev);
1754 struct e1000_hw *hw = &adapter->hw;
1755 u32 icr = er32(ICR);
1756
Bruce Allane921eb12012-11-28 09:28:37 +00001757 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001758 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001759 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001760 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001761 * disconnect (LSC) before accessing any PHY registers
1762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1764 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001765 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766
Bruce Allane921eb12012-11-28 09:28:37 +00001767 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001768 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001769 * adapter in watchdog
1770 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 if (netif_carrier_ok(netdev) &&
1772 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1773 /* disable receives */
1774 u32 rctl = er32(RCTL);
1775 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001776 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001777 }
1778 /* guard against interrupt when we're going down */
1779 if (!test_bit(__E1000_DOWN, &adapter->state))
1780 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1781 }
1782
Bruce Allan94fb8482013-01-23 09:00:03 +00001783 /* Reset on uncorrectable ECC error */
1784 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1785 u32 pbeccsts = er32(PBECCSTS);
1786
1787 adapter->corr_errors +=
1788 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1789 adapter->uncorr_errors +=
1790 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1791 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1792
1793 /* Do the reset outside of interrupt context */
1794 schedule_work(&adapter->reset_task);
1795
1796 /* return immediately since reset is imminent */
1797 return IRQ_HANDLED;
1798 }
1799
Ben Hutchings288379f2009-01-19 16:43:59 -08001800 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001801 adapter->total_tx_bytes = 0;
1802 adapter->total_tx_packets = 0;
1803 adapter->total_rx_bytes = 0;
1804 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001805 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806 }
1807
1808 return IRQ_HANDLED;
1809}
1810
1811/**
1812 * e1000_intr - Interrupt Handler
1813 * @irq: interrupt number
1814 * @data: pointer to a network interface device structure
1815 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001816static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817{
1818 struct net_device *netdev = data;
1819 struct e1000_adapter *adapter = netdev_priv(netdev);
1820 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001822
Bruce Allana68ea772009-11-20 23:23:16 +00001823 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001824 return IRQ_NONE; /* Not our interrupt */
1825
Bruce Allane921eb12012-11-28 09:28:37 +00001826 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001827 * not set, then the adapter didn't send an interrupt
1828 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829 if (!(icr & E1000_ICR_INT_ASSERTED))
1830 return IRQ_NONE;
1831
Bruce Allane921eb12012-11-28 09:28:37 +00001832 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001833 * interrupts are masked. No need for the
1834 * IMC write
1835 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836
dave graham573cca82009-02-10 12:52:05 +00001837 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001838 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001839 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001840 * disconnect (LSC) before accessing any PHY registers
1841 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1843 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001844 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845
Bruce Allane921eb12012-11-28 09:28:37 +00001846 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847 * For packet buffer work-around on link down event;
1848 * disable receives here in the ISR and
1849 * reset adapter in watchdog
1850 */
1851 if (netif_carrier_ok(netdev) &&
1852 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1853 /* disable receives */
1854 rctl = er32(RCTL);
1855 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001856 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857 }
1858 /* guard against interrupt when we're going down */
1859 if (!test_bit(__E1000_DOWN, &adapter->state))
1860 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1861 }
1862
Bruce Allan94fb8482013-01-23 09:00:03 +00001863 /* Reset on uncorrectable ECC error */
1864 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1865 u32 pbeccsts = er32(PBECCSTS);
1866
1867 adapter->corr_errors +=
1868 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1869 adapter->uncorr_errors +=
1870 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1871 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1872
1873 /* Do the reset outside of interrupt context */
1874 schedule_work(&adapter->reset_task);
1875
1876 /* return immediately since reset is imminent */
1877 return IRQ_HANDLED;
1878 }
1879
Ben Hutchings288379f2009-01-19 16:43:59 -08001880 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881 adapter->total_tx_bytes = 0;
1882 adapter->total_tx_packets = 0;
1883 adapter->total_rx_bytes = 0;
1884 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001885 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001886 }
1887
1888 return IRQ_HANDLED;
1889}
1890
Bruce Allan8bb62862013-01-16 08:46:49 +00001891static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001892{
1893 struct net_device *netdev = data;
1894 struct e1000_adapter *adapter = netdev_priv(netdev);
1895 struct e1000_hw *hw = &adapter->hw;
1896 u32 icr = er32(ICR);
1897
1898 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001899 if (!test_bit(__E1000_DOWN, &adapter->state))
1900 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001901 return IRQ_NONE;
1902 }
1903
1904 if (icr & adapter->eiac_mask)
1905 ew32(ICS, (icr & adapter->eiac_mask));
1906
1907 if (icr & E1000_ICR_OTHER) {
1908 if (!(icr & E1000_ICR_LSC))
1909 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001910 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001911 /* guard against interrupt when we're going down */
1912 if (!test_bit(__E1000_DOWN, &adapter->state))
1913 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1914 }
1915
1916no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001917 if (!test_bit(__E1000_DOWN, &adapter->state))
1918 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001919
1920 return IRQ_HANDLED;
1921}
1922
Bruce Allan8bb62862013-01-16 08:46:49 +00001923static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001924{
1925 struct net_device *netdev = data;
1926 struct e1000_adapter *adapter = netdev_priv(netdev);
1927 struct e1000_hw *hw = &adapter->hw;
1928 struct e1000_ring *tx_ring = adapter->tx_ring;
1929
1930
1931 adapter->total_tx_bytes = 0;
1932 adapter->total_tx_packets = 0;
1933
Bruce Allan55aa6982011-12-16 00:45:45 +00001934 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001935 /* Ring was not completely cleaned, so fire another interrupt */
1936 ew32(ICS, tx_ring->ims_val);
1937
1938 return IRQ_HANDLED;
1939}
1940
Bruce Allan8bb62862013-01-16 08:46:49 +00001941static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001942{
1943 struct net_device *netdev = data;
1944 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001945 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001946
1947 /* Write the ITR value calculated at the end of the
1948 * previous interrupt.
1949 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001950 if (rx_ring->set_itr) {
1951 writel(1000000000 / (rx_ring->itr_val * 256),
1952 rx_ring->itr_register);
1953 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001954 }
1955
Ben Hutchings288379f2009-01-19 16:43:59 -08001956 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001957 adapter->total_rx_bytes = 0;
1958 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001959 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001960 }
1961 return IRQ_HANDLED;
1962}
1963
1964/**
1965 * e1000_configure_msix - Configure MSI-X hardware
1966 *
1967 * e1000_configure_msix sets up the hardware to properly
1968 * generate MSI-X interrupts.
1969 **/
1970static void e1000_configure_msix(struct e1000_adapter *adapter)
1971{
1972 struct e1000_hw *hw = &adapter->hw;
1973 struct e1000_ring *rx_ring = adapter->rx_ring;
1974 struct e1000_ring *tx_ring = adapter->tx_ring;
1975 int vector = 0;
1976 u32 ctrl_ext, ivar = 0;
1977
1978 adapter->eiac_mask = 0;
1979
1980 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1981 if (hw->mac.type == e1000_82574) {
1982 u32 rfctl = er32(RFCTL);
1983 rfctl |= E1000_RFCTL_ACK_DIS;
1984 ew32(RFCTL, rfctl);
1985 }
1986
1987#define E1000_IVAR_INT_ALLOC_VALID 0x8
1988 /* Configure Rx vector */
1989 rx_ring->ims_val = E1000_IMS_RXQ0;
1990 adapter->eiac_mask |= rx_ring->ims_val;
1991 if (rx_ring->itr_val)
1992 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001993 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001994 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001995 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001996 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1997
1998 /* Configure Tx vector */
1999 tx_ring->ims_val = E1000_IMS_TXQ0;
2000 vector++;
2001 if (tx_ring->itr_val)
2002 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002003 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002004 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002005 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002006 adapter->eiac_mask |= tx_ring->ims_val;
2007 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2008
2009 /* set vector for Other Causes, e.g. link changes */
2010 vector++;
2011 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2012 if (rx_ring->itr_val)
2013 writel(1000000000 / (rx_ring->itr_val * 256),
2014 hw->hw_addr + E1000_EITR_82574(vector));
2015 else
2016 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2017
2018 /* Cause Tx interrupts on every write back */
2019 ivar |= (1 << 31);
2020
2021 ew32(IVAR, ivar);
2022
2023 /* enable MSI-X PBA support */
2024 ctrl_ext = er32(CTRL_EXT);
2025 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2026
2027 /* Auto-Mask Other interrupts upon ICR read */
2028#define E1000_EIAC_MASK_82574 0x01F00000
2029 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2030 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2031 ew32(CTRL_EXT, ctrl_ext);
2032 e1e_flush();
2033}
2034
2035void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2036{
2037 if (adapter->msix_entries) {
2038 pci_disable_msix(adapter->pdev);
2039 kfree(adapter->msix_entries);
2040 adapter->msix_entries = NULL;
2041 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2042 pci_disable_msi(adapter->pdev);
2043 adapter->flags &= ~FLAG_MSI_ENABLED;
2044 }
Bruce Allan4662e822008-08-26 18:37:06 -07002045}
2046
2047/**
2048 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2049 *
2050 * Attempt to configure interrupts using the best available
2051 * capabilities of the hardware and kernel.
2052 **/
2053void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2054{
2055 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002056 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002057
2058 switch (adapter->int_mode) {
2059 case E1000E_INT_MODE_MSIX:
2060 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002061 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2062 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002063 sizeof(struct msix_entry),
2064 GFP_KERNEL);
2065 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002066 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002067 adapter->msix_entries[i].entry = i;
2068
2069 err = pci_enable_msix(adapter->pdev,
2070 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002071 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002072 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002073 return;
2074 }
2075 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002076 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002077 e1000e_reset_interrupt_capability(adapter);
2078 }
2079 adapter->int_mode = E1000E_INT_MODE_MSI;
2080 /* Fall through */
2081 case E1000E_INT_MODE_MSI:
2082 if (!pci_enable_msi(adapter->pdev)) {
2083 adapter->flags |= FLAG_MSI_ENABLED;
2084 } else {
2085 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002086 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002087 }
2088 /* Fall through */
2089 case E1000E_INT_MODE_LEGACY:
2090 /* Don't do anything; this is the system default */
2091 break;
2092 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002093
2094 /* store the number of vectors being used */
2095 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002096}
2097
2098/**
2099 * e1000_request_msix - Initialize MSI-X interrupts
2100 *
2101 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2102 * kernel.
2103 **/
2104static int e1000_request_msix(struct e1000_adapter *adapter)
2105{
2106 struct net_device *netdev = adapter->netdev;
2107 int err = 0, vector = 0;
2108
2109 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002110 snprintf(adapter->rx_ring->name,
2111 sizeof(adapter->rx_ring->name) - 1,
2112 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002113 else
2114 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2115 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002116 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002117 netdev);
2118 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002119 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002120 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2121 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002122 adapter->rx_ring->itr_val = adapter->itr;
2123 vector++;
2124
2125 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002126 snprintf(adapter->tx_ring->name,
2127 sizeof(adapter->tx_ring->name) - 1,
2128 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002129 else
2130 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2131 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002132 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002133 netdev);
2134 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002135 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002136 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2137 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002138 adapter->tx_ring->itr_val = adapter->itr;
2139 vector++;
2140
2141 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002142 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002143 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002144 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002145
2146 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002147
Bruce Allan4662e822008-08-26 18:37:06 -07002148 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002149}
2150
Bruce Allanf8d59f72008-08-08 18:36:11 -07002151/**
2152 * e1000_request_irq - initialize interrupts
2153 *
2154 * Attempts to configure interrupts using the best available
2155 * capabilities of the hardware and kernel.
2156 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157static int e1000_request_irq(struct e1000_adapter *adapter)
2158{
2159 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002160 int err;
2161
Bruce Allan4662e822008-08-26 18:37:06 -07002162 if (adapter->msix_entries) {
2163 err = e1000_request_msix(adapter);
2164 if (!err)
2165 return err;
2166 /* fall back to MSI */
2167 e1000e_reset_interrupt_capability(adapter);
2168 adapter->int_mode = E1000E_INT_MODE_MSI;
2169 e1000e_set_interrupt_capability(adapter);
2170 }
2171 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002172 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002173 netdev->name, netdev);
2174 if (!err)
2175 return err;
2176
2177 /* fall back to legacy interrupt */
2178 e1000e_reset_interrupt_capability(adapter);
2179 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180 }
2181
Joe Perchesa0607fd2009-11-18 23:29:17 -08002182 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002183 netdev->name, netdev);
2184 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002185 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002186
2187 return err;
2188}
2189
2190static void e1000_free_irq(struct e1000_adapter *adapter)
2191{
2192 struct net_device *netdev = adapter->netdev;
2193
Bruce Allan4662e822008-08-26 18:37:06 -07002194 if (adapter->msix_entries) {
2195 int vector = 0;
2196
2197 free_irq(adapter->msix_entries[vector].vector, netdev);
2198 vector++;
2199
2200 free_irq(adapter->msix_entries[vector].vector, netdev);
2201 vector++;
2202
2203 /* Other Causes interrupt vector */
2204 free_irq(adapter->msix_entries[vector].vector, netdev);
2205 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206 }
Bruce Allan4662e822008-08-26 18:37:06 -07002207
2208 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209}
2210
2211/**
2212 * e1000_irq_disable - Mask off interrupt generation on the NIC
2213 **/
2214static void e1000_irq_disable(struct e1000_adapter *adapter)
2215{
2216 struct e1000_hw *hw = &adapter->hw;
2217
Auke Kokbc7f75f2007-09-17 12:30:59 -07002218 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002219 if (adapter->msix_entries)
2220 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002222
2223 if (adapter->msix_entries) {
2224 int i;
2225 for (i = 0; i < adapter->num_vectors; i++)
2226 synchronize_irq(adapter->msix_entries[i].vector);
2227 } else {
2228 synchronize_irq(adapter->pdev->irq);
2229 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230}
2231
2232/**
2233 * e1000_irq_enable - Enable default interrupt generation settings
2234 **/
2235static void e1000_irq_enable(struct e1000_adapter *adapter)
2236{
2237 struct e1000_hw *hw = &adapter->hw;
2238
Bruce Allan4662e822008-08-26 18:37:06 -07002239 if (adapter->msix_entries) {
2240 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2241 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002242 } else if (hw->mac.type == e1000_pch_lpt) {
2243 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002244 } else {
2245 ew32(IMS, IMS_ENABLE_MASK);
2246 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002247 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248}
2249
2250/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002251 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002252 * @adapter: address of board private structure
2253 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002254 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 * For ASF and Pass Through versions of f/w this means that
2256 * the driver is loaded. For AMT version (only with 82573)
2257 * of the f/w this means that the network i/f is open.
2258 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002259void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002260{
2261 struct e1000_hw *hw = &adapter->hw;
2262 u32 ctrl_ext;
2263 u32 swsm;
2264
2265 /* Let firmware know the driver has taken over */
2266 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2267 swsm = er32(SWSM);
2268 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2269 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2270 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002271 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272 }
2273}
2274
2275/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002276 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277 * @adapter: address of board private structure
2278 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002279 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280 * For ASF and Pass Through versions of f/w this means that the
2281 * driver is no longer loaded. For AMT version (only with 82573) i
2282 * of the f/w this means that the network i/f is closed.
2283 *
2284 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002285void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002286{
2287 struct e1000_hw *hw = &adapter->hw;
2288 u32 ctrl_ext;
2289 u32 swsm;
2290
2291 /* Let firmware taken over control of h/w */
2292 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2293 swsm = er32(SWSM);
2294 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2295 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2296 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002297 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002298 }
2299}
2300
Auke Kokbc7f75f2007-09-17 12:30:59 -07002301/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002302 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303 **/
2304static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2305 struct e1000_ring *ring)
2306{
2307 struct pci_dev *pdev = adapter->pdev;
2308
2309 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2310 GFP_KERNEL);
2311 if (!ring->desc)
2312 return -ENOMEM;
2313
2314 return 0;
2315}
2316
2317/**
2318 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002319 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002320 *
2321 * Return 0 on success, negative on failure
2322 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002323int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324{
Bruce Allan55aa6982011-12-16 00:45:45 +00002325 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002326 int err = -ENOMEM, size;
2327
2328 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002329 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 if (!tx_ring->buffer_info)
2331 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332
2333 /* round up to nearest 4K */
2334 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2335 tx_ring->size = ALIGN(tx_ring->size, 4096);
2336
2337 err = e1000_alloc_ring_dma(adapter, tx_ring);
2338 if (err)
2339 goto err;
2340
2341 tx_ring->next_to_use = 0;
2342 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343
2344 return 0;
2345err:
2346 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002347 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002348 return err;
2349}
2350
2351/**
2352 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002353 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 *
2355 * Returns 0 on success, negative on failure
2356 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002357int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002358{
Bruce Allan55aa6982011-12-16 00:45:45 +00002359 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002360 struct e1000_buffer *buffer_info;
2361 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002362
2363 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002364 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365 if (!rx_ring->buffer_info)
2366 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367
Auke Kok47f44e42007-10-25 13:57:44 -07002368 for (i = 0; i < rx_ring->count; i++) {
2369 buffer_info = &rx_ring->buffer_info[i];
2370 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2371 sizeof(struct e1000_ps_page),
2372 GFP_KERNEL);
2373 if (!buffer_info->ps_pages)
2374 goto err_pages;
2375 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376
2377 desc_len = sizeof(union e1000_rx_desc_packet_split);
2378
2379 /* Round up to nearest 4K */
2380 rx_ring->size = rx_ring->count * desc_len;
2381 rx_ring->size = ALIGN(rx_ring->size, 4096);
2382
2383 err = e1000_alloc_ring_dma(adapter, rx_ring);
2384 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002385 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386
2387 rx_ring->next_to_clean = 0;
2388 rx_ring->next_to_use = 0;
2389 rx_ring->rx_skb_top = NULL;
2390
2391 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002392
2393err_pages:
2394 for (i = 0; i < rx_ring->count; i++) {
2395 buffer_info = &rx_ring->buffer_info[i];
2396 kfree(buffer_info->ps_pages);
2397 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398err:
2399 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002400 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002401 return err;
2402}
2403
2404/**
2405 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002406 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002407 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002408static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409{
Bruce Allan55aa6982011-12-16 00:45:45 +00002410 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411 struct e1000_buffer *buffer_info;
2412 unsigned long size;
2413 unsigned int i;
2414
2415 for (i = 0; i < tx_ring->count; i++) {
2416 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002417 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418 }
2419
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002420 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421 size = sizeof(struct e1000_buffer) * tx_ring->count;
2422 memset(tx_ring->buffer_info, 0, size);
2423
2424 memset(tx_ring->desc, 0, tx_ring->size);
2425
2426 tx_ring->next_to_use = 0;
2427 tx_ring->next_to_clean = 0;
2428
Bruce Allanc5083cf2011-12-16 00:45:40 +00002429 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002430 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2431 e1000e_update_tdt_wa(tx_ring, 0);
2432 else
2433 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434}
2435
2436/**
2437 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002438 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 *
2440 * Free all transmit software resources
2441 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002442void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443{
Bruce Allan55aa6982011-12-16 00:45:45 +00002444 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446
Bruce Allan55aa6982011-12-16 00:45:45 +00002447 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448
2449 vfree(tx_ring->buffer_info);
2450 tx_ring->buffer_info = NULL;
2451
2452 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2453 tx_ring->dma);
2454 tx_ring->desc = NULL;
2455}
2456
2457/**
2458 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002459 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 *
2461 * Free all receive software resources
2462 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002463void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464{
Bruce Allan55aa6982011-12-16 00:45:45 +00002465 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002466 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002467 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468
Bruce Allan55aa6982011-12-16 00:45:45 +00002469 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002471 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002472 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002473
Auke Kokbc7f75f2007-09-17 12:30:59 -07002474 vfree(rx_ring->buffer_info);
2475 rx_ring->buffer_info = NULL;
2476
Auke Kokbc7f75f2007-09-17 12:30:59 -07002477 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2478 rx_ring->dma);
2479 rx_ring->desc = NULL;
2480}
2481
2482/**
2483 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002484 * @adapter: pointer to adapter
2485 * @itr_setting: current adapter->itr
2486 * @packets: the number of packets during this measurement interval
2487 * @bytes: the number of bytes during this measurement interval
2488 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002489 * Stores a new ITR value based on packets and byte
2490 * counts during the last interrupt. The advantage of per interrupt
2491 * computation is faster updates and more accurate ITR for the current
2492 * traffic pattern. Constants in this function were computed
2493 * based on theoretical maximum wire speed and thresholds were set based
2494 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002495 * while increasing bulk throughput. This functionality is controlled
2496 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002497 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002498static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002499{
2500 unsigned int retval = itr_setting;
2501
2502 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002503 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504
2505 switch (itr_setting) {
2506 case lowest_latency:
2507 /* handle TSO and jumbo frames */
2508 if (bytes/packets > 8000)
2509 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002510 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002511 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002512 break;
2513 case low_latency: /* 50 usec aka 20000 ints/s */
2514 if (bytes > 10000) {
2515 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002516 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002518 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002520 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522 } else if (bytes/packets > 2000) {
2523 retval = bulk_latency;
2524 } else if (packets <= 2 && bytes < 512) {
2525 retval = lowest_latency;
2526 }
2527 break;
2528 case bulk_latency: /* 250 usec aka 4000 ints/s */
2529 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002530 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002531 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 } else if (bytes < 6000) {
2533 retval = low_latency;
2534 }
2535 break;
2536 }
2537
Auke Kokbc7f75f2007-09-17 12:30:59 -07002538 return retval;
2539}
2540
2541static void e1000_set_itr(struct e1000_adapter *adapter)
2542{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002543 u16 current_itr;
2544 u32 new_itr = adapter->itr;
2545
2546 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2547 if (adapter->link_speed != SPEED_1000) {
2548 current_itr = 0;
2549 new_itr = 4000;
2550 goto set_itr_now;
2551 }
2552
Bruce Allan828bac82010-09-29 21:39:37 +00002553 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2554 new_itr = 0;
2555 goto set_itr_now;
2556 }
2557
Bruce Allan8bb62862013-01-16 08:46:49 +00002558 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2559 adapter->total_tx_packets,
2560 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2562 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2563 adapter->tx_itr = low_latency;
2564
Bruce Allan8bb62862013-01-16 08:46:49 +00002565 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2566 adapter->total_rx_packets,
2567 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2569 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2570 adapter->rx_itr = low_latency;
2571
2572 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2573
2574 switch (current_itr) {
2575 /* counts and packets in update_itr are dependent on these numbers */
2576 case lowest_latency:
2577 new_itr = 70000;
2578 break;
2579 case low_latency:
2580 new_itr = 20000; /* aka hwitr = ~200 */
2581 break;
2582 case bulk_latency:
2583 new_itr = 4000;
2584 break;
2585 default:
2586 break;
2587 }
2588
2589set_itr_now:
2590 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002591 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002592 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002593 * increasing
2594 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002595 new_itr = new_itr > adapter->itr ?
2596 min(adapter->itr + (new_itr >> 2), new_itr) :
2597 new_itr;
2598 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002599 adapter->rx_ring->itr_val = new_itr;
2600 if (adapter->msix_entries)
2601 adapter->rx_ring->set_itr = 1;
2602 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002603 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002604 }
2605}
2606
2607/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002608 * e1000e_write_itr - write the ITR value to the appropriate registers
2609 * @adapter: address of board private structure
2610 * @itr: new ITR value to program
2611 *
2612 * e1000e_write_itr determines if the adapter is in MSI-X mode
2613 * and, if so, writes the EITR registers with the ITR value.
2614 * Otherwise, it writes the ITR value into the ITR register.
2615 **/
2616void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2617{
2618 struct e1000_hw *hw = &adapter->hw;
2619 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2620
2621 if (adapter->msix_entries) {
2622 int vector;
2623
2624 for (vector = 0; vector < adapter->num_vectors; vector++)
2625 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2626 } else {
2627 ew32(ITR, new_itr);
2628 }
2629}
2630
2631/**
Bruce Allan4662e822008-08-26 18:37:06 -07002632 * e1000_alloc_queues - Allocate memory for all rings
2633 * @adapter: board private structure to initialize
2634 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002635static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002636{
Bruce Allan55aa6982011-12-16 00:45:45 +00002637 int size = sizeof(struct e1000_ring);
2638
2639 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002640 if (!adapter->tx_ring)
2641 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002642 adapter->tx_ring->count = adapter->tx_ring_count;
2643 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002644
Bruce Allan55aa6982011-12-16 00:45:45 +00002645 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002646 if (!adapter->rx_ring)
2647 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002648 adapter->rx_ring->count = adapter->rx_ring_count;
2649 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002650
2651 return 0;
2652err:
2653 e_err("Unable to allocate memory for queues\n");
2654 kfree(adapter->rx_ring);
2655 kfree(adapter->tx_ring);
2656 return -ENOMEM;
2657}
2658
2659/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002660 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002661 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002662 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002664static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002665{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002666 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2667 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002668 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002670 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671
Wang Chen4cf16532008-11-12 23:38:14 -08002672 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673
Bruce Allanc58c8a72012-03-20 03:48:19 +00002674 if (!adapter->msix_entries ||
2675 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2676 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002677
Bruce Allanc58c8a72012-03-20 03:48:19 +00002678 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002679
Alexander Duyck12d04a32009-03-25 22:05:03 +00002680 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002681 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002682
Bruce Allanc58c8a72012-03-20 03:48:19 +00002683 /* If weight not fully consumed, exit the polling mode */
2684 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 if (adapter->itr_setting & 3)
2686 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002687 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002688 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2689 if (adapter->msix_entries)
2690 ew32(IMS, adapter->rx_ring->ims_val);
2691 else
2692 e1000_irq_enable(adapter);
2693 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 }
2695
2696 return work_done;
2697}
2698
Jiri Pirko8e586132011-12-08 19:52:37 -05002699static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700{
2701 struct e1000_adapter *adapter = netdev_priv(netdev);
2702 struct e1000_hw *hw = &adapter->hw;
2703 u32 vfta, index;
2704
2705 /* don't update vlan cookie if already programmed */
2706 if ((adapter->hw.mng_cookie.status &
2707 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2708 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002709 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002710
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002712 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2713 index = (vid >> 5) & 0x7F;
2714 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2715 vfta |= (1 << (vid & 0x1F));
2716 hw->mac.ops.write_vfta(hw, index, vfta);
2717 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002718
2719 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002720
2721 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002722}
2723
Jiri Pirko8e586132011-12-08 19:52:37 -05002724static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002725{
2726 struct e1000_adapter *adapter = netdev_priv(netdev);
2727 struct e1000_hw *hw = &adapter->hw;
2728 u32 vfta, index;
2729
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730 if ((adapter->hw.mng_cookie.status &
2731 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2732 (vid == adapter->mng_vlan_id)) {
2733 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002734 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002735 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002736 }
2737
2738 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002739 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2740 index = (vid >> 5) & 0x7F;
2741 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2742 vfta &= ~(1 << (vid & 0x1F));
2743 hw->mac.ops.write_vfta(hw, index, vfta);
2744 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002745
2746 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002747
2748 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002749}
2750
2751/**
2752 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2753 * @adapter: board private structure to initialize
2754 **/
2755static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2756{
2757 struct net_device *netdev = adapter->netdev;
2758 struct e1000_hw *hw = &adapter->hw;
2759 u32 rctl;
2760
2761 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2762 /* disable VLAN receive filtering */
2763 rctl = er32(RCTL);
2764 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2765 ew32(RCTL, rctl);
2766
2767 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2768 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2769 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2770 }
2771 }
2772}
2773
2774/**
2775 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2776 * @adapter: board private structure to initialize
2777 **/
2778static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2779{
2780 struct e1000_hw *hw = &adapter->hw;
2781 u32 rctl;
2782
2783 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2784 /* enable VLAN receive filtering */
2785 rctl = er32(RCTL);
2786 rctl |= E1000_RCTL_VFE;
2787 rctl &= ~E1000_RCTL_CFIEN;
2788 ew32(RCTL, rctl);
2789 }
2790}
2791
2792/**
2793 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2794 * @adapter: board private structure to initialize
2795 **/
2796static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2797{
2798 struct e1000_hw *hw = &adapter->hw;
2799 u32 ctrl;
2800
2801 /* disable VLAN tag insert/strip */
2802 ctrl = er32(CTRL);
2803 ctrl &= ~E1000_CTRL_VME;
2804 ew32(CTRL, ctrl);
2805}
2806
2807/**
2808 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2809 * @adapter: board private structure to initialize
2810 **/
2811static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2812{
2813 struct e1000_hw *hw = &adapter->hw;
2814 u32 ctrl;
2815
2816 /* enable VLAN tag insert/strip */
2817 ctrl = er32(CTRL);
2818 ctrl |= E1000_CTRL_VME;
2819 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002820}
2821
2822static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2823{
2824 struct net_device *netdev = adapter->netdev;
2825 u16 vid = adapter->hw.mng_cookie.vlan_id;
2826 u16 old_vid = adapter->mng_vlan_id;
2827
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002828 if (adapter->hw.mng_cookie.status &
2829 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2830 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 adapter->mng_vlan_id = vid;
2832 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002834 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2835 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836}
2837
2838static void e1000_restore_vlan(struct e1000_adapter *adapter)
2839{
2840 u16 vid;
2841
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002842 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002844 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002846}
2847
Bruce Allancd791612010-05-10 14:59:51 +00002848static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002849{
2850 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002851 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852
2853 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2854 return;
2855
2856 manc = er32(MANC);
2857
Bruce Allane921eb12012-11-28 09:28:37 +00002858 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002860 * the packets will be handled on SMBUS
2861 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002862 manc |= E1000_MANC_EN_MNG2HOST;
2863 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002864
2865 switch (hw->mac.type) {
2866 default:
2867 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2868 break;
2869 case e1000_82574:
2870 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002871 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002872 * if so, enable it.
2873 */
2874 for (i = 0, j = 0; i < 8; i++) {
2875 mdef = er32(MDEF(i));
2876
2877 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002878 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002879 continue;
2880
2881 /* Enable this decision filter in MANC2H */
2882 if (mdef)
2883 manc2h |= (1 << i);
2884
2885 j |= mdef;
2886 }
2887
2888 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2889 break;
2890
2891 /* Create new decision filter in an empty filter */
2892 for (i = 0, j = 0; i < 8; i++)
2893 if (er32(MDEF(i)) == 0) {
2894 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2895 E1000_MDEF_PORT_664));
2896 manc2h |= (1 << 1);
2897 j++;
2898 break;
2899 }
2900
2901 if (!j)
2902 e_warn("Unable to create IPMI pass-through filter\n");
2903 break;
2904 }
2905
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 ew32(MANC2H, manc2h);
2907 ew32(MANC, manc);
2908}
2909
2910/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002911 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002912 * @adapter: board private structure
2913 *
2914 * Configure the Tx unit of the MAC after a reset.
2915 **/
2916static void e1000_configure_tx(struct e1000_adapter *adapter)
2917{
2918 struct e1000_hw *hw = &adapter->hw;
2919 struct e1000_ring *tx_ring = adapter->tx_ring;
2920 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002921 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922
2923 /* Setup the HW Tx Head and Tail descriptor pointers */
2924 tdba = tx_ring->dma;
2925 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002926 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2927 ew32(TDBAH(0), (tdba >> 32));
2928 ew32(TDLEN(0), tdlen);
2929 ew32(TDH(0), 0);
2930 ew32(TDT(0), 0);
2931 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2932 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934 /* Set the Tx Interrupt Delay register */
2935 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002936 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937 ew32(TADV, adapter->tx_abs_int_delay);
2938
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002939 if (adapter->flags2 & FLAG2_DMA_BURST) {
2940 u32 txdctl = er32(TXDCTL(0));
2941 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2942 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002943 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002944 * hardware to use the bus more efficiently in bursts, depends
2945 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002946 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002947 * hthresh = 1 ==> prefetch when one or more available
2948 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2949 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002950 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002951 */
2952 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2953 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002954 }
Bruce Allan56032be2011-12-16 00:46:01 +00002955 /* erratum work around: set txdctl the same for both queues */
2956 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002957
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002959 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002960 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002961 * gigabit link later
2962 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002963#define SPEED_MODE_BIT (1 << 21)
2964 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002965 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 }
2967
2968 /* errata: program both queues to unweighted RR */
2969 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002970 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002972 ew32(TARC(0), tarc);
2973 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002975 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002976 }
2977
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 /* Setup Transmit Descriptor Settings for eop descriptor */
2979 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2980
2981 /* only set IDE if we are delaying interrupts using the timers */
2982 if (adapter->tx_int_delay)
2983 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2984
2985 /* enable Report Status bit */
2986 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2987
Bruce Allan57cde762012-02-22 09:02:58 +00002988 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989}
2990
2991/**
2992 * e1000_setup_rctl - configure the receive control registers
2993 * @adapter: Board private structure
2994 **/
2995#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2996 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2997static void e1000_setup_rctl(struct e1000_adapter *adapter)
2998{
2999 struct e1000_hw *hw = &adapter->hw;
3000 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001 u32 pages = 0;
3002
Bruce Allan2fbe4522012-04-19 03:21:47 +00003003 /* Workaround Si errata on PCHx - configure jumbo frame flow */
3004 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00003005 s32 ret_val;
3006
3007 if (adapter->netdev->mtu > ETH_DATA_LEN)
3008 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3009 else
3010 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00003011
3012 if (ret_val)
3013 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003014 }
3015
Auke Kokbc7f75f2007-09-17 12:30:59 -07003016 /* Program MC offset vector base */
3017 rctl = er32(RCTL);
3018 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3019 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3020 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3021 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3022
3023 /* Do not Store bad packets */
3024 rctl &= ~E1000_RCTL_SBP;
3025
3026 /* Enable Long Packet receive */
3027 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3028 rctl &= ~E1000_RCTL_LPE;
3029 else
3030 rctl |= E1000_RCTL_LPE;
3031
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003032 /* Some systems expect that the CRC is included in SMBUS traffic. The
3033 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3034 * host memory when this is enabled
3035 */
3036 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3037 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003038
Bruce Allana4f58f52009-06-02 11:29:18 +00003039 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3040 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3041 u16 phy_data;
3042
3043 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3044 phy_data &= 0xfff8;
3045 phy_data |= (1 << 2);
3046 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3047
3048 e1e_rphy(hw, 22, &phy_data);
3049 phy_data &= 0x0fff;
3050 phy_data |= (1 << 14);
3051 e1e_wphy(hw, 0x10, 0x2823);
3052 e1e_wphy(hw, 0x11, 0x0003);
3053 e1e_wphy(hw, 22, phy_data);
3054 }
3055
Auke Kokbc7f75f2007-09-17 12:30:59 -07003056 /* Setup buffer sizes */
3057 rctl &= ~E1000_RCTL_SZ_4096;
3058 rctl |= E1000_RCTL_BSEX;
3059 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 case 2048:
3061 default:
3062 rctl |= E1000_RCTL_SZ_2048;
3063 rctl &= ~E1000_RCTL_BSEX;
3064 break;
3065 case 4096:
3066 rctl |= E1000_RCTL_SZ_4096;
3067 break;
3068 case 8192:
3069 rctl |= E1000_RCTL_SZ_8192;
3070 break;
3071 case 16384:
3072 rctl |= E1000_RCTL_SZ_16384;
3073 break;
3074 }
3075
Bruce Allan5f450212011-07-22 06:21:46 +00003076 /* Enable Extended Status in all Receive Descriptors */
3077 rfctl = er32(RFCTL);
3078 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003079 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003080
Bruce Allane921eb12012-11-28 09:28:37 +00003081 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082 * header is placed in skb->data and the packet data is
3083 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3084 * In the case of a non-split, skb->data is linearly filled,
3085 * followed by the page buffers. Therefore, skb->data is
3086 * sized to hold the largest protocol header.
3087 *
3088 * allocations using alloc_page take too long for regular MTU
3089 * so only enable packet split for jumbo frames
3090 *
3091 * Using pages when the page size is greater than 16k wastes
3092 * a lot of memory, since we allocate 3 pages at all times
3093 * per packet.
3094 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003096 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003098 else
3099 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100
3101 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003102 u32 psrctl = 0;
3103
Auke Kok140a7482007-10-25 13:57:58 -07003104 /* Enable Packet split descriptors */
3105 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003106
3107 psrctl |= adapter->rx_ps_bsize0 >>
3108 E1000_PSRCTL_BSIZE0_SHIFT;
3109
3110 switch (adapter->rx_ps_pages) {
3111 case 3:
3112 psrctl |= PAGE_SIZE <<
3113 E1000_PSRCTL_BSIZE3_SHIFT;
3114 case 2:
3115 psrctl |= PAGE_SIZE <<
3116 E1000_PSRCTL_BSIZE2_SHIFT;
3117 case 1:
3118 psrctl |= PAGE_SIZE >>
3119 E1000_PSRCTL_BSIZE1_SHIFT;
3120 break;
3121 }
3122
3123 ew32(PSRCTL, psrctl);
3124 }
3125
Ben Greearcf955e62012-02-11 15:39:51 +00003126 /* This is useful for sniffing bad packets. */
3127 if (adapter->netdev->features & NETIF_F_RXALL) {
3128 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003129 * in e1000e_set_rx_mode
3130 */
Ben Greearcf955e62012-02-11 15:39:51 +00003131 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3132 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3133 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3134
3135 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3136 E1000_RCTL_DPF | /* Allow filtered pause */
3137 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3138 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3139 * and that breaks VLANs.
3140 */
3141 }
3142
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003144 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003145 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146}
3147
3148/**
3149 * e1000_configure_rx - Configure Receive Unit after Reset
3150 * @adapter: board private structure
3151 *
3152 * Configure the Rx unit of the MAC after a reset.
3153 **/
3154static void e1000_configure_rx(struct e1000_adapter *adapter)
3155{
3156 struct e1000_hw *hw = &adapter->hw;
3157 struct e1000_ring *rx_ring = adapter->rx_ring;
3158 u64 rdba;
3159 u32 rdlen, rctl, rxcsum, ctrl_ext;
3160
3161 if (adapter->rx_ps_pages) {
3162 /* this is a 32 byte descriptor */
3163 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003164 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 adapter->clean_rx = e1000_clean_rx_irq_ps;
3166 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003167 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003168 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003169 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3170 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003172 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 adapter->clean_rx = e1000_clean_rx_irq;
3174 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3175 }
3176
3177 /* disable receives while setting up the descriptors */
3178 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003179 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3180 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003182 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003183
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003184 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003185 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003186 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003187 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003188 * granularity = 01
3189 * wthresh = 04,
3190 * hthresh = 04,
3191 * pthresh = 0x20
3192 */
3193 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3194 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3195
Bruce Allane921eb12012-11-28 09:28:37 +00003196 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003197 * the value was not set by the user via module options
3198 */
3199 if (adapter->rx_int_delay == DEFAULT_RDTR)
3200 adapter->rx_int_delay = BURST_RDTR;
3201 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3202 adapter->rx_abs_int_delay = BURST_RADV;
3203 }
3204
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 /* set the Receive Delay Timer Register */
3206 ew32(RDTR, adapter->rx_int_delay);
3207
3208 /* irq moderation */
3209 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003210 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003211 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003212
3213 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214 /* Auto-Mask interrupts upon ICR access */
3215 ctrl_ext |= E1000_CTRL_EXT_IAME;
3216 ew32(IAM, 0xffffffff);
3217 ew32(CTRL_EXT, ctrl_ext);
3218 e1e_flush();
3219
Bruce Allane921eb12012-11-28 09:28:37 +00003220 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003221 * the Base and Length of the Rx Descriptor Ring
3222 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003224 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3225 ew32(RDBAH(0), (rdba >> 32));
3226 ew32(RDLEN(0), rdlen);
3227 ew32(RDH(0), 0);
3228 ew32(RDT(0), 0);
3229 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3230 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231
3232 /* Enable Receive Checksum Offload for TCP and UDP */
3233 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003234 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003235 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003236 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003238 ew32(RXCSUM, rxcsum);
3239
Bruce Allan3e35d992013-01-12 07:25:22 +00003240 /* With jumbo frames, excessive C-state transition latencies result
3241 * in dropped transactions.
3242 */
3243 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3244 u32 lat =
3245 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3246 adapter->max_frame_size) * 8 / 1000;
3247
3248 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003249 u32 rxdctl = er32(RXDCTL(0));
3250 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003251 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003252
3253 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3254 } else {
3255 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3256 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003257 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003258
3259 /* Enable Receives */
3260 ew32(RCTL, rctl);
3261}
3262
3263/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003264 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 * @netdev: network interface device structure
3266 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003267 * Writes multicast address list to the MTA hash table.
3268 * Returns: -ENOMEM on failure
3269 * 0 on no addresses written
3270 * X on writing X addresses to MTA
3271 */
3272static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003273{
3274 struct e1000_adapter *adapter = netdev_priv(netdev);
3275 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003276 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003277 u8 *mta_list;
3278 int i;
3279
3280 if (netdev_mc_empty(netdev)) {
3281 /* nothing to program, so clear mc list */
3282 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3283 return 0;
3284 }
3285
3286 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3287 if (!mta_list)
3288 return -ENOMEM;
3289
3290 /* update_mc_addr_list expects a packed array of only addresses. */
3291 i = 0;
3292 netdev_for_each_mc_addr(ha, netdev)
3293 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3294
3295 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3296 kfree(mta_list);
3297
3298 return netdev_mc_count(netdev);
3299}
3300
3301/**
3302 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3303 * @netdev: network interface device structure
3304 *
3305 * Writes unicast address list to the RAR table.
3306 * Returns: -ENOMEM on failure/insufficient address space
3307 * 0 on no addresses written
3308 * X on writing X addresses to the RAR table
3309 **/
3310static int e1000e_write_uc_addr_list(struct net_device *netdev)
3311{
3312 struct e1000_adapter *adapter = netdev_priv(netdev);
3313 struct e1000_hw *hw = &adapter->hw;
3314 unsigned int rar_entries = hw->mac.rar_entry_count;
3315 int count = 0;
3316
3317 /* save a rar entry for our hardware address */
3318 rar_entries--;
3319
3320 /* save a rar entry for the LAA workaround */
3321 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3322 rar_entries--;
3323
3324 /* return ENOMEM indicating insufficient memory for addresses */
3325 if (netdev_uc_count(netdev) > rar_entries)
3326 return -ENOMEM;
3327
3328 if (!netdev_uc_empty(netdev) && rar_entries) {
3329 struct netdev_hw_addr *ha;
3330
Bruce Allane921eb12012-11-28 09:28:37 +00003331 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003332 * combining
3333 */
3334 netdev_for_each_uc_addr(ha, netdev) {
3335 if (!rar_entries)
3336 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003337 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003338 count++;
3339 }
3340 }
3341
3342 /* zero out the remaining RAR entries not used above */
3343 for (; rar_entries > 0; rar_entries--) {
3344 ew32(RAH(rar_entries), 0);
3345 ew32(RAL(rar_entries), 0);
3346 }
3347 e1e_flush();
3348
3349 return count;
3350}
3351
3352/**
3353 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3354 * @netdev: network interface device structure
3355 *
3356 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3357 * address list or the network interface flags are updated. This routine is
3358 * responsible for configuring the hardware for proper unicast, multicast,
3359 * promiscuous mode, and all-multi behavior.
3360 **/
3361static void e1000e_set_rx_mode(struct net_device *netdev)
3362{
3363 struct e1000_adapter *adapter = netdev_priv(netdev);
3364 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003366
3367 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003368 rctl = er32(RCTL);
3369
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003370 /* clear the affected bits */
3371 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3372
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373 if (netdev->flags & IFF_PROMISC) {
3374 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003375 /* Do not hardware filter VLANs in promisc mode */
3376 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003377 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003378 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003379
Patrick McHardy746b9f02008-07-16 20:15:45 -07003380 if (netdev->flags & IFF_ALLMULTI) {
3381 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003382 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003383 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003384 * then we should just turn on promiscuous mode so
3385 * that we can at least receive multicast traffic
3386 */
3387 count = e1000e_write_mc_addr_list(netdev);
3388 if (count < 0)
3389 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003390 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003391 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003392 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003393 * sufficient space to store all the addresses then enable
3394 * unicast promiscuous mode
3395 */
3396 count = e1000e_write_uc_addr_list(netdev);
3397 if (count < 0)
3398 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003399 }
3400
3401 ew32(RCTL, rctl);
3402
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003403 if (netdev->features & NETIF_F_HW_VLAN_RX)
3404 e1000e_vlan_strip_enable(adapter);
3405 else
3406 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407}
3408
Bruce Allan70495a52012-01-11 01:26:50 +00003409static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3410{
3411 struct e1000_hw *hw = &adapter->hw;
3412 u32 mrqc, rxcsum;
3413 int i;
3414 static const u32 rsskey[10] = {
3415 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3416 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3417 };
3418
3419 /* Fill out hash function seed */
3420 for (i = 0; i < 10; i++)
3421 ew32(RSSRK(i), rsskey[i]);
3422
3423 /* Direct all traffic to queue 0 */
3424 for (i = 0; i < 32; i++)
3425 ew32(RETA(i), 0);
3426
Bruce Allane921eb12012-11-28 09:28:37 +00003427 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003428 * descriptor on writeback.
3429 */
3430 rxcsum = er32(RXCSUM);
3431 rxcsum |= E1000_RXCSUM_PCSD;
3432
3433 ew32(RXCSUM, rxcsum);
3434
3435 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3436 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3437 E1000_MRQC_RSS_FIELD_IPV6 |
3438 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3439 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3440
3441 ew32(MRQC, mrqc);
3442}
3443
Auke Kokbc7f75f2007-09-17 12:30:59 -07003444/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003445 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3446 * @adapter: board private structure
3447 * @timinca: pointer to returned time increment attributes
3448 *
3449 * Get attributes for incrementing the System Time Register SYSTIML/H at
3450 * the default base frequency, and set the cyclecounter shift value.
3451 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003452s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003453{
3454 struct e1000_hw *hw = &adapter->hw;
3455 u32 incvalue, incperiod, shift;
3456
3457 /* Make sure clock is enabled on I217 before checking the frequency */
3458 if ((hw->mac.type == e1000_pch_lpt) &&
3459 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3460 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3461 u32 fextnvm7 = er32(FEXTNVM7);
3462
3463 if (!(fextnvm7 & (1 << 0))) {
3464 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3465 e1e_flush();
3466 }
3467 }
3468
3469 switch (hw->mac.type) {
3470 case e1000_pch2lan:
3471 case e1000_pch_lpt:
3472 /* On I217, the clock frequency is 25MHz or 96MHz as
3473 * indicated by the System Clock Frequency Indication
3474 */
3475 if ((hw->mac.type != e1000_pch_lpt) ||
3476 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3477 /* Stable 96MHz frequency */
3478 incperiod = INCPERIOD_96MHz;
3479 incvalue = INCVALUE_96MHz;
3480 shift = INCVALUE_SHIFT_96MHz;
3481 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3482 break;
3483 }
3484 /* fall-through */
3485 case e1000_82574:
3486 case e1000_82583:
3487 /* Stable 25MHz frequency */
3488 incperiod = INCPERIOD_25MHz;
3489 incvalue = INCVALUE_25MHz;
3490 shift = INCVALUE_SHIFT_25MHz;
3491 adapter->cc.shift = shift;
3492 break;
3493 default:
3494 return -EINVAL;
3495 }
3496
3497 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3498 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3499
3500 return 0;
3501}
3502
3503/**
3504 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3505 * @adapter: board private structure
3506 *
3507 * Outgoing time stamping can be enabled and disabled. Play nice and
3508 * disable it when requested, although it shouldn't cause any overhead
3509 * when no packet needs it. At most one packet in the queue may be
3510 * marked for time stamping, otherwise it would be impossible to tell
3511 * for sure to which packet the hardware time stamp belongs.
3512 *
3513 * Incoming time stamping has to be configured via the hardware filters.
3514 * Not all combinations are supported, in particular event type has to be
3515 * specified. Matching the kind of event packet is not supported, with the
3516 * exception of "all V2 events regardless of level 2 or 4".
3517 **/
3518static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3519{
3520 struct e1000_hw *hw = &adapter->hw;
3521 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3522 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3523 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003524 u32 rxmtrl = 0;
3525 u16 rxudp = 0;
3526 bool is_l4 = false;
3527 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003528 u32 regval;
3529 s32 ret_val;
3530
3531 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3532 return -EINVAL;
3533
3534 /* flags reserved for future extensions - must be zero */
3535 if (config->flags)
3536 return -EINVAL;
3537
3538 switch (config->tx_type) {
3539 case HWTSTAMP_TX_OFF:
3540 tsync_tx_ctl = 0;
3541 break;
3542 case HWTSTAMP_TX_ON:
3543 break;
3544 default:
3545 return -ERANGE;
3546 }
3547
3548 switch (config->rx_filter) {
3549 case HWTSTAMP_FILTER_NONE:
3550 tsync_rx_ctl = 0;
3551 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003552 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3553 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3554 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3555 is_l4 = true;
3556 break;
3557 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3558 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3559 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3560 is_l4 = true;
3561 break;
3562 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3563 /* Also time stamps V2 L2 Path Delay Request/Response */
3564 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3565 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3566 is_l2 = true;
3567 break;
3568 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3569 /* Also time stamps V2 L2 Path Delay Request/Response. */
3570 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3571 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3572 is_l2 = true;
3573 break;
3574 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3575 /* Hardware cannot filter just V2 L4 Sync messages;
3576 * fall-through to V2 (both L2 and L4) Sync.
3577 */
3578 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3579 /* Also time stamps V2 Path Delay Request/Response. */
3580 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3581 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3582 is_l2 = true;
3583 is_l4 = true;
3584 break;
3585 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3586 /* Hardware cannot filter just V2 L4 Delay Request messages;
3587 * fall-through to V2 (both L2 and L4) Delay Request.
3588 */
3589 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3590 /* Also time stamps V2 Path Delay Request/Response. */
3591 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3592 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3593 is_l2 = true;
3594 is_l4 = true;
3595 break;
3596 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3597 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3598 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3599 * fall-through to all V2 (both L2 and L4) Events.
3600 */
3601 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3602 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3603 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3604 is_l2 = true;
3605 is_l4 = true;
3606 break;
3607 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3608 /* For V1, the hardware can only filter Sync messages or
3609 * Delay Request messages but not both so fall-through to
3610 * time stamp all packets.
3611 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003612 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003613 is_l2 = true;
3614 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003615 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3616 config->rx_filter = HWTSTAMP_FILTER_ALL;
3617 break;
3618 default:
3619 return -ERANGE;
3620 }
3621
3622 /* enable/disable Tx h/w time stamping */
3623 regval = er32(TSYNCTXCTL);
3624 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3625 regval |= tsync_tx_ctl;
3626 ew32(TSYNCTXCTL, regval);
3627 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3628 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3629 e_err("Timesync Tx Control register not set as expected\n");
3630 return -EAGAIN;
3631 }
3632
3633 /* enable/disable Rx h/w time stamping */
3634 regval = er32(TSYNCRXCTL);
3635 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3636 regval |= tsync_rx_ctl;
3637 ew32(TSYNCRXCTL, regval);
3638 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3639 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3640 (regval & (E1000_TSYNCRXCTL_ENABLED |
3641 E1000_TSYNCRXCTL_TYPE_MASK))) {
3642 e_err("Timesync Rx Control register not set as expected\n");
3643 return -EAGAIN;
3644 }
3645
Bruce Alland89777b2013-01-19 01:09:58 +00003646 /* L2: define ethertype filter for time stamped packets */
3647 if (is_l2)
3648 rxmtrl |= ETH_P_1588;
3649
3650 /* define which PTP packets get time stamped */
3651 ew32(RXMTRL, rxmtrl);
3652
3653 /* Filter by destination port */
3654 if (is_l4) {
3655 rxudp = PTP_EV_PORT;
3656 cpu_to_be16s(&rxudp);
3657 }
3658 ew32(RXUDP, rxudp);
3659
3660 e1e_flush();
3661
Bruce Allanb67e1912012-12-27 08:32:33 +00003662 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003663 er32(RXSTMPH);
3664 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003665
3666 /* Get and set the System Time Register SYSTIM base frequency */
3667 ret_val = e1000e_get_base_timinca(adapter, &regval);
3668 if (ret_val)
3669 return ret_val;
3670 ew32(TIMINCA, regval);
3671
3672 /* reset the ns time counter */
3673 timecounter_init(&adapter->tc, &adapter->cc,
3674 ktime_to_ns(ktime_get_real()));
3675
3676 return 0;
3677}
3678
3679/**
Bruce Allanad680762008-03-28 09:15:03 -07003680 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 * @adapter: private board structure
3682 **/
3683static void e1000_configure(struct e1000_adapter *adapter)
3684{
Bruce Allan55aa6982011-12-16 00:45:45 +00003685 struct e1000_ring *rx_ring = adapter->rx_ring;
3686
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003687 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
3689 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003690 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691
3692 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003693
3694 if (adapter->netdev->features & NETIF_F_RXHASH)
3695 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 e1000_setup_rctl(adapter);
3697 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003698 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699}
3700
3701/**
3702 * e1000e_power_up_phy - restore link in case the phy was powered down
3703 * @adapter: address of board private structure
3704 *
3705 * The phy may be powered down to save power and turn off link when the
3706 * driver is unloaded and wake on lan is not enabled (among others)
3707 * *** this routine MUST be followed by a call to e1000e_reset ***
3708 **/
3709void e1000e_power_up_phy(struct e1000_adapter *adapter)
3710{
Bruce Allan17f208d2009-12-01 15:47:22 +00003711 if (adapter->hw.phy.ops.power_up)
3712 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713
3714 adapter->hw.mac.ops.setup_link(&adapter->hw);
3715}
3716
3717/**
3718 * e1000_power_down_phy - Power down the PHY
3719 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003720 * Power down the PHY so no link is implied when interface is down.
3721 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722 */
3723static void e1000_power_down_phy(struct e1000_adapter *adapter)
3724{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003725 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003726 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727 return;
3728
Bruce Allan17f208d2009-12-01 15:47:22 +00003729 if (adapter->hw.phy.ops.power_down)
3730 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731}
3732
3733/**
3734 * e1000e_reset - bring the hardware into a known good state
3735 *
3736 * This function boots the hardware and enables some settings that
3737 * require a configuration cycle of the hardware - those cannot be
3738 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003739 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740 */
3741void e1000e_reset(struct e1000_adapter *adapter)
3742{
3743 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003744 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003745 struct e1000_hw *hw = &adapter->hw;
3746 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003747 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748 u16 hwm;
3749
Bruce Allanad680762008-03-28 09:15:03 -07003750 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003751 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003752
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003753 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003754 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 * large enough to accommodate two full transmit packets,
3756 * rounded up to the next 1KB and expressed in KB. Likewise,
3757 * the Rx FIFO should be large enough to accommodate at least
3758 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003759 * expressed in KB.
3760 */
Auke Kokdf762462007-10-25 13:57:53 -07003761 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003763 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003765 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003766 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003767 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003768 */
3769 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003770 sizeof(struct e1000_tx_desc) -
3771 ETH_FCS_LEN) * 2;
3772 min_tx_space = ALIGN(min_tx_space, 1024);
3773 min_tx_space >>= 10;
3774 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003775 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003776 min_rx_space = ALIGN(min_rx_space, 1024);
3777 min_rx_space >>= 10;
3778
Bruce Allane921eb12012-11-28 09:28:37 +00003779 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003780 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003781 * allocation, take space away from current Rx allocation
3782 */
Auke Kokdf762462007-10-25 13:57:53 -07003783 if ((tx_space < min_tx_space) &&
3784 ((min_tx_space - tx_space) < pba)) {
3785 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003786
Bruce Allane921eb12012-11-28 09:28:37 +00003787 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003788 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003789 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003790 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003791 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003792 }
Auke Kokdf762462007-10-25 13:57:53 -07003793
3794 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003795 }
3796
Bruce Allane921eb12012-11-28 09:28:37 +00003797 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003798 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003799 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003800 * (or the size used for early receive) above it in the Rx FIFO.
3801 * Set it to the lower of:
3802 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003803 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003804 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003805 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3806 fc->pause_time = 0xFFFF;
3807 else
3808 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003809 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003810 fc->current_mode = fc->requested_mode;
3811
3812 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003813 case e1000_ich9lan:
3814 case e1000_ich10lan:
3815 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3816 pba = 14;
3817 ew32(PBA, pba);
3818 fc->high_water = 0x2800;
3819 fc->low_water = fc->high_water - 8;
3820 break;
3821 }
3822 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003823 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003824 hwm = min(((pba << 10) * 9 / 10),
3825 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003826
3827 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3828 fc->low_water = fc->high_water - 8;
3829 break;
3830 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003831 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003832 * loads. If hangs persist, try disabling Tx flow control.
3833 */
3834 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3835 fc->high_water = 0x3500;
3836 fc->low_water = 0x1500;
3837 } else {
3838 fc->high_water = 0x5000;
3839 fc->low_water = 0x3000;
3840 }
Bruce Allana3055952010-05-10 15:02:12 +00003841 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003842 break;
3843 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003844 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003845 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003846
3847 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3848 fc->high_water = 0x05C20;
3849 fc->low_water = 0x05048;
3850 fc->pause_time = 0x0650;
3851 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003852 }
Bruce Allan347b5202012-12-08 00:35:35 +00003853
3854 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3855 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003856 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003857 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003858
Bruce Allane921eb12012-11-28 09:28:37 +00003859 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003860 * maximum size per Tx descriptor limited only to the transmit
3861 * allocation of the packet buffer minus 96 bytes with an upper
3862 * limit of 24KB due to receive synchronization limitations.
3863 */
3864 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3865 24 << 10);
3866
Bruce Allane921eb12012-11-28 09:28:37 +00003867 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003868 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003869 */
3870 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003871 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003872 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3873 dev_info(&adapter->pdev->dev,
3874 "Interrupt Throttle Rate turned off\n");
3875 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003876 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003877 }
3878 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3879 dev_info(&adapter->pdev->dev,
3880 "Interrupt Throttle Rate turned on\n");
3881 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3882 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003883 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003884 }
3885 }
3886
Auke Kokbc7f75f2007-09-17 12:30:59 -07003887 /* Allow time for pending master requests to run */
3888 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003889
Bruce Allane921eb12012-11-28 09:28:37 +00003890 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003891 * that the network interface is in control
3892 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003893 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003894 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003895
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896 ew32(WUC, 0);
3897
3898 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003899 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900
3901 e1000_update_mng_vlan(adapter);
3902
3903 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3904 ew32(VET, ETH_P_8021Q);
3905
3906 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003907
Bruce Allanb67e1912012-12-27 08:32:33 +00003908 /* initialize systim and reset the ns time counter */
3909 e1000e_config_hwtstamp(adapter);
3910
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003911 if (!netif_running(adapter->netdev) &&
3912 !test_bit(__E1000_TESTING, &adapter->state)) {
3913 e1000_power_down_phy(adapter);
3914 return;
3915 }
3916
Auke Kokbc7f75f2007-09-17 12:30:59 -07003917 e1000_get_phy_info(hw);
3918
Bruce Allan918d7192009-06-02 11:28:20 +00003919 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3920 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003922 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003924 * different we would do if it failed
3925 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003926 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3927 phy_data &= ~IGP02E1000_PM_SPD;
3928 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3929 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930}
3931
3932int e1000e_up(struct e1000_adapter *adapter)
3933{
3934 struct e1000_hw *hw = &adapter->hw;
3935
3936 /* hardware has been reset, we need to reload some things */
3937 e1000_configure(adapter);
3938
3939 clear_bit(__E1000_DOWN, &adapter->state);
3940
Bruce Allan4662e822008-08-26 18:37:06 -07003941 if (adapter->msix_entries)
3942 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003943 e1000_irq_enable(adapter);
3944
Bruce Allan400484f2011-05-13 07:20:03 +00003945 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003946
Auke Kokbc7f75f2007-09-17 12:30:59 -07003947 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003948 if (adapter->msix_entries)
3949 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3950 else
3951 ew32(ICS, E1000_ICS_LSC);
3952
Auke Kokbc7f75f2007-09-17 12:30:59 -07003953 return 0;
3954}
3955
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003956static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3957{
3958 struct e1000_hw *hw = &adapter->hw;
3959
3960 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3961 return;
3962
3963 /* flush pending descriptor writebacks to memory */
3964 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3965 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3966
3967 /* execute the writes immediately */
3968 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003969
Bruce Allane921eb12012-11-28 09:28:37 +00003970 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003971 * write is successful
3972 */
3973 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3974 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3975
3976 /* execute the writes immediately */
3977 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003978}
3979
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003980static void e1000e_update_stats(struct e1000_adapter *adapter);
3981
Auke Kokbc7f75f2007-09-17 12:30:59 -07003982void e1000e_down(struct e1000_adapter *adapter)
3983{
3984 struct net_device *netdev = adapter->netdev;
3985 struct e1000_hw *hw = &adapter->hw;
3986 u32 tctl, rctl;
3987
Bruce Allane921eb12012-11-28 09:28:37 +00003988 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003989 * reschedule our watchdog timer
3990 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003991 set_bit(__E1000_DOWN, &adapter->state);
3992
3993 /* disable receives in the hardware */
3994 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003995 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3996 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003997 /* flush and sleep below */
3998
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003999 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004000
4001 /* disable transmits in the hardware */
4002 tctl = er32(TCTL);
4003 tctl &= ~E1000_TCTL_EN;
4004 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004005
Auke Kokbc7f75f2007-09-17 12:30:59 -07004006 /* flush both disables and wait for them to finish */
4007 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004008 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010 e1000_irq_disable(adapter);
4011
4012 del_timer_sync(&adapter->watchdog_timer);
4013 del_timer_sync(&adapter->phy_info_timer);
4014
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004016
4017 spin_lock(&adapter->stats64_lock);
4018 e1000e_update_stats(adapter);
4019 spin_unlock(&adapter->stats64_lock);
4020
Bruce Allan400484f2011-05-13 07:20:03 +00004021 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004022 e1000_clean_tx_ring(adapter->tx_ring);
4023 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004024
Auke Kokbc7f75f2007-09-17 12:30:59 -07004025 adapter->link_speed = 0;
4026 adapter->link_duplex = 0;
4027
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004028 if (!pci_channel_offline(adapter->pdev))
4029 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004030
Bruce Allane921eb12012-11-28 09:28:37 +00004031 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004032 * pci_disable_device here.
4033 */
4034}
4035
4036void e1000e_reinit_locked(struct e1000_adapter *adapter)
4037{
4038 might_sleep();
4039 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004040 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004041 e1000e_down(adapter);
4042 e1000e_up(adapter);
4043 clear_bit(__E1000_RESETTING, &adapter->state);
4044}
4045
4046/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004047 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4048 * @cc: cyclecounter structure
4049 **/
4050static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4051{
4052 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4053 cc);
4054 struct e1000_hw *hw = &adapter->hw;
4055 cycle_t systim;
4056
4057 /* latch SYSTIMH on read of SYSTIML */
4058 systim = (cycle_t)er32(SYSTIML);
4059 systim |= (cycle_t)er32(SYSTIMH) << 32;
4060
4061 return systim;
4062}
4063
4064/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004065 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4066 * @adapter: board private structure to initialize
4067 *
4068 * e1000_sw_init initializes the Adapter private data structure.
4069 * Fields are initialized based on PCI device information and
4070 * OS network device settings (MTU size).
4071 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004072static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004073{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004074 struct net_device *netdev = adapter->netdev;
4075
4076 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4077 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004078 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4079 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004080 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4081 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004082
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004083 spin_lock_init(&adapter->stats64_lock);
4084
Bruce Allan4662e822008-08-26 18:37:06 -07004085 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086
Bruce Allan4662e822008-08-26 18:37:06 -07004087 if (e1000_alloc_queues(adapter))
4088 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004089
Bruce Allanb67e1912012-12-27 08:32:33 +00004090 /* Setup hardware time stamping cyclecounter */
4091 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4092 adapter->cc.read = e1000e_cyclecounter_read;
4093 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4094 adapter->cc.mult = 1;
4095 /* cc.shift set in e1000e_get_base_tininca() */
4096
4097 spin_lock_init(&adapter->systim_lock);
4098 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4099 }
4100
Auke Kokbc7f75f2007-09-17 12:30:59 -07004101 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102 e1000_irq_disable(adapter);
4103
Auke Kokbc7f75f2007-09-17 12:30:59 -07004104 set_bit(__E1000_DOWN, &adapter->state);
4105 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106}
4107
4108/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004109 * e1000_intr_msi_test - Interrupt Handler
4110 * @irq: interrupt number
4111 * @data: pointer to a network interface device structure
4112 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004113static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004114{
4115 struct net_device *netdev = data;
4116 struct e1000_adapter *adapter = netdev_priv(netdev);
4117 struct e1000_hw *hw = &adapter->hw;
4118 u32 icr = er32(ICR);
4119
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004120 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004121 if (icr & E1000_ICR_RXSEQ) {
4122 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004123 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004124 * interrupt is handled.
4125 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004126 wmb();
4127 }
4128
4129 return IRQ_HANDLED;
4130}
4131
4132/**
4133 * e1000_test_msi_interrupt - Returns 0 for successful test
4134 * @adapter: board private struct
4135 *
4136 * code flow taken from tg3.c
4137 **/
4138static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4139{
4140 struct net_device *netdev = adapter->netdev;
4141 struct e1000_hw *hw = &adapter->hw;
4142 int err;
4143
4144 /* poll_enable hasn't been called yet, so don't need disable */
4145 /* clear any pending events */
4146 er32(ICR);
4147
4148 /* free the real vector and request a test handler */
4149 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004150 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004151
4152 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004153 * MSI irq handler will unset this flag
4154 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004155 adapter->flags |= FLAG_MSI_TEST_FAILED;
4156
4157 err = pci_enable_msi(adapter->pdev);
4158 if (err)
4159 goto msi_test_failed;
4160
Joe Perchesa0607fd2009-11-18 23:29:17 -08004161 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004162 netdev->name, netdev);
4163 if (err) {
4164 pci_disable_msi(adapter->pdev);
4165 goto msi_test_failed;
4166 }
4167
Bruce Allane921eb12012-11-28 09:28:37 +00004168 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004169 * interrupt.
4170 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004171 wmb();
4172
4173 e1000_irq_enable(adapter);
4174
4175 /* fire an unusual interrupt on the test handler */
4176 ew32(ICS, E1000_ICS_RXSEQ);
4177 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004178 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004179
4180 e1000_irq_disable(adapter);
4181
Bruce Allanbc763292012-08-17 06:18:07 +00004182 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004183
4184 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004185 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004186 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004187 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004188 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004189 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004190
4191 free_irq(adapter->pdev->irq, netdev);
4192 pci_disable_msi(adapter->pdev);
4193
Bruce Allanf8d59f72008-08-08 18:36:11 -07004194msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004195 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004196 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004197}
4198
4199/**
4200 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4201 * @adapter: board private struct
4202 *
4203 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4204 **/
4205static int e1000_test_msi(struct e1000_adapter *adapter)
4206{
4207 int err;
4208 u16 pci_cmd;
4209
4210 if (!(adapter->flags & FLAG_MSI_ENABLED))
4211 return 0;
4212
4213 /* disable SERR in case the MSI write causes a master abort */
4214 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004215 if (pci_cmd & PCI_COMMAND_SERR)
4216 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4217 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004218
4219 err = e1000_test_msi_interrupt(adapter);
4220
Dean Nelson36f24072010-06-29 18:12:05 +00004221 /* re-enable SERR */
4222 if (pci_cmd & PCI_COMMAND_SERR) {
4223 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4224 pci_cmd |= PCI_COMMAND_SERR;
4225 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4226 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004227
Bruce Allanf8d59f72008-08-08 18:36:11 -07004228 return err;
4229}
4230
4231/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004232 * e1000_open - Called when a network interface is made active
4233 * @netdev: network interface device structure
4234 *
4235 * Returns 0 on success, negative value on failure
4236 *
4237 * The open entry point is called when a network interface is made
4238 * active by the system (IFF_UP). At this point all resources needed
4239 * for transmit and receive operations are allocated, the interrupt
4240 * handler is registered with the OS, the watchdog timer is started,
4241 * and the stack is notified that the interface is ready.
4242 **/
4243static int e1000_open(struct net_device *netdev)
4244{
4245 struct e1000_adapter *adapter = netdev_priv(netdev);
4246 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004247 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004248 int err;
4249
4250 /* disallow open during test */
4251 if (test_bit(__E1000_TESTING, &adapter->state))
4252 return -EBUSY;
4253
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004254 pm_runtime_get_sync(&pdev->dev);
4255
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004256 netif_carrier_off(netdev);
4257
Auke Kokbc7f75f2007-09-17 12:30:59 -07004258 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004259 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004260 if (err)
4261 goto err_setup_tx;
4262
4263 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004264 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004265 if (err)
4266 goto err_setup_rx;
4267
Bruce Allane921eb12012-11-28 09:28:37 +00004268 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004269 * interface is now open and reset the part to a known state.
4270 */
4271 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004272 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004273 e1000e_reset(adapter);
4274 }
4275
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 e1000e_power_up_phy(adapter);
4277
4278 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4279 if ((adapter->hw.mng_cookie.status &
4280 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4281 e1000_update_mng_vlan(adapter);
4282
Bruce Allan79d4e902011-12-16 00:46:27 +00004283 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004284 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4285 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004286
Bruce Allane921eb12012-11-28 09:28:37 +00004287 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004288 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4289 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004290 * clean_rx handler before we do so.
4291 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004292 e1000_configure(adapter);
4293
4294 err = e1000_request_irq(adapter);
4295 if (err)
4296 goto err_req_irq;
4297
Bruce Allane921eb12012-11-28 09:28:37 +00004298 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004299 * ignore e1000e MSI messages, which means we need to test our MSI
4300 * interrupt now
4301 */
Bruce Allan4662e822008-08-26 18:37:06 -07004302 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004303 err = e1000_test_msi(adapter);
4304 if (err) {
4305 e_err("Interrupt allocation failed\n");
4306 goto err_req_irq;
4307 }
4308 }
4309
Auke Kokbc7f75f2007-09-17 12:30:59 -07004310 /* From here on the code is the same as e1000e_up() */
4311 clear_bit(__E1000_DOWN, &adapter->state);
4312
4313 napi_enable(&adapter->napi);
4314
4315 e1000_irq_enable(adapter);
4316
Jeff Kirsher09357b02011-11-18 14:25:00 +00004317 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004318 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004319
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004320 adapter->idle_check = true;
4321 pm_runtime_put(&pdev->dev);
4322
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004324 if (adapter->msix_entries)
4325 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4326 else
4327 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328
4329 return 0;
4330
4331err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004332 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004333 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004334 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004335err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004336 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004337err_setup_tx:
4338 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004339 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004340
4341 return err;
4342}
4343
4344/**
4345 * e1000_close - Disables a network interface
4346 * @netdev: network interface device structure
4347 *
4348 * Returns 0, this is not allowed to fail
4349 *
4350 * The close entry point is called when an interface is de-activated
4351 * by the OS. The hardware is still under the drivers control, but
4352 * needs to be disabled. A global MAC reset is issued to stop the
4353 * hardware, and all transmit and receive resources are freed.
4354 **/
4355static int e1000_close(struct net_device *netdev)
4356{
4357 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004358 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004359 int count = E1000_CHECK_RESET_COUNT;
4360
4361 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4362 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004363
4364 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004365
4366 pm_runtime_get_sync(&pdev->dev);
4367
Bruce Allan5f4a7802011-11-29 08:09:19 +00004368 napi_disable(&adapter->napi);
4369
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004370 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4371 e1000e_down(adapter);
4372 e1000_free_irq(adapter);
4373 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004374 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375
Bruce Allan55aa6982011-12-16 00:45:45 +00004376 e1000e_free_tx_resources(adapter->tx_ring);
4377 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004378
Bruce Allane921eb12012-11-28 09:28:37 +00004379 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004380 * the same ID is registered on the host OS (let 8021q kill it)
4381 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004382 if (adapter->hw.mng_cookie.status &
4383 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004384 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4385
Bruce Allane921eb12012-11-28 09:28:37 +00004386 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004387 * interface is now closed
4388 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004389 if ((adapter->flags & FLAG_HAS_AMT) &&
4390 !test_bit(__E1000_TESTING, &adapter->state))
4391 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004392
Bruce Allan3e35d992013-01-12 07:25:22 +00004393 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004394
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004395 pm_runtime_put_sync(&pdev->dev);
4396
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397 return 0;
4398}
4399/**
4400 * e1000_set_mac - Change the Ethernet Address of the NIC
4401 * @netdev: network interface device structure
4402 * @p: pointer to an address structure
4403 *
4404 * Returns 0 on success, negative on failure
4405 **/
4406static int e1000_set_mac(struct net_device *netdev, void *p)
4407{
4408 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004409 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004410 struct sockaddr *addr = p;
4411
4412 if (!is_valid_ether_addr(addr->sa_data))
4413 return -EADDRNOTAVAIL;
4414
4415 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4416 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4417
Bruce Allan69e1e012012-04-14 03:28:50 +00004418 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004419
4420 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4421 /* activate the work around */
4422 e1000e_set_laa_state_82571(&adapter->hw, 1);
4423
Bruce Allane921eb12012-11-28 09:28:37 +00004424 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004425 * between the time RAR[0] gets clobbered and the time it
4426 * gets fixed (in e1000_watchdog), the actual LAA is in one
4427 * of the RARs and no incoming packets directed to this port
4428 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004429 * RAR[14]
4430 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004431 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4432 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433 }
4434
4435 return 0;
4436}
4437
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004438/**
4439 * e1000e_update_phy_task - work thread to update phy
4440 * @work: pointer to our work struct
4441 *
4442 * this worker thread exists because we must acquire a
4443 * semaphore to read the phy, which we could msleep while
4444 * waiting for it, and we can't msleep in a timer.
4445 **/
4446static void e1000e_update_phy_task(struct work_struct *work)
4447{
4448 struct e1000_adapter *adapter = container_of(work,
4449 struct e1000_adapter, 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{
4466 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 +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004633 adapter->stats.crcerrs + adapter->stats.algnerrc +
4634 adapter->stats.ruc + adapter->stats.roc +
4635 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004636 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004637 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004638 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4639 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4640 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004641
4642 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004643 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004644 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004645 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4646 netdev->stats.tx_window_errors = adapter->stats.latecol;
4647 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004648
4649 /* Tx Dropped needs to be maintained elsewhere */
4650
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651 /* Management Stats */
4652 adapter->stats.mgptc += er32(MGTPTC);
4653 adapter->stats.mgprc += er32(MGTPRC);
4654 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004655
4656 /* Correctable ECC Errors */
4657 if (hw->mac.type == e1000_pch_lpt) {
4658 u32 pbeccsts = er32(PBECCSTS);
4659 adapter->corr_errors +=
4660 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4661 adapter->uncorr_errors +=
4662 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4663 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4664 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004665}
4666
Bruce Allan7c257692008-04-23 11:09:00 -07004667/**
4668 * e1000_phy_read_status - Update the PHY register status snapshot
4669 * @adapter: board private structure
4670 **/
4671static void e1000_phy_read_status(struct e1000_adapter *adapter)
4672{
4673 struct e1000_hw *hw = &adapter->hw;
4674 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004675
4676 if ((er32(STATUS) & E1000_STATUS_LU) &&
4677 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004678 int ret_val;
4679
Bruce Allan7c257692008-04-23 11:09:00 -07004680 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4681 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4682 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4683 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4684 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4685 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4686 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4687 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4688 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004689 e_warn("Error reading PHY register\n");
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{
4800 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4801
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,
4811 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004812 struct net_device *netdev = adapter->netdev;
4813 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004814 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004815 struct e1000_ring *tx_ring = adapter->tx_ring;
4816 struct e1000_hw *hw = &adapter->hw;
4817 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004818
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004819 if (test_bit(__E1000_DOWN, &adapter->state))
4820 return;
4821
David S. Millerb405e8d2010-02-04 22:31:41 -08004822 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004823 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004824 /* Cancel scheduled suspend requests. */
4825 pm_runtime_resume(netdev->dev.parent);
4826
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004827 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004829 }
4830
4831 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4832 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4833 e1000_update_mng_vlan(adapter);
4834
Auke Kokbc7f75f2007-09-17 12:30:59 -07004835 if (link) {
4836 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004837 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004838
4839 /* Cancel scheduled suspend requests. */
4840 pm_runtime_resume(netdev->dev.parent);
4841
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004842 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004843 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844 mac->ops.get_link_up_info(&adapter->hw,
4845 &adapter->link_speed,
4846 &adapter->link_duplex);
4847 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004848 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004849 * if link has autonegotiated at 10/100 half
4850 */
4851 if ((hw->phy.type == e1000_phy_igp_3 ||
4852 hw->phy.type == e1000_phy_bm) &&
4853 (hw->mac.autoneg == true) &&
4854 (adapter->link_speed == SPEED_10 ||
4855 adapter->link_speed == SPEED_100) &&
4856 (adapter->link_duplex == HALF_DUPLEX)) {
4857 u16 autoneg_exp;
4858
4859 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4860
4861 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004862 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 -07004863 }
4864
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004865 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 adapter->tx_timeout_factor = 1;
4867 switch (adapter->link_speed) {
4868 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004869 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004870 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004871 break;
4872 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004873 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004874 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 break;
4876 }
4877
Bruce Allane921eb12012-11-28 09:28:37 +00004878 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004879 * link-up event
4880 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4882 !txb2b) {
4883 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004884 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004885 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004886 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887 }
4888
Bruce Allane921eb12012-11-28 09:28:37 +00004889 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004890 * some hardware issues
4891 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004892 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4893 switch (adapter->link_speed) {
4894 case SPEED_10:
4895 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004896 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 netdev->features &= ~NETIF_F_TSO;
4898 netdev->features &= ~NETIF_F_TSO6;
4899 break;
4900 case SPEED_1000:
4901 netdev->features |= NETIF_F_TSO;
4902 netdev->features |= NETIF_F_TSO6;
4903 break;
4904 default:
4905 /* oops */
4906 break;
4907 }
4908 }
4909
Bruce Allane921eb12012-11-28 09:28:37 +00004910 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004911 * after setting TARC(0)
4912 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913 tctl = er32(TCTL);
4914 tctl |= E1000_TCTL_EN;
4915 ew32(TCTL, tctl);
4916
Bruce Allane921eb12012-11-28 09:28:37 +00004917 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004918 * reporting link up.
4919 */
4920 if (phy->ops.cfg_on_link_up)
4921 phy->ops.cfg_on_link_up(hw);
4922
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924
4925 if (!test_bit(__E1000_DOWN, &adapter->state))
4926 mod_timer(&adapter->phy_info_timer,
4927 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 }
4929 } else {
4930 if (netif_carrier_ok(netdev)) {
4931 adapter->link_speed = 0;
4932 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004933 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004934 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004935 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004936 if (!test_bit(__E1000_DOWN, &adapter->state))
4937 mod_timer(&adapter->phy_info_timer,
4938 round_jiffies(jiffies + 2 * HZ));
4939
Bruce Allan12d43f72012-12-05 06:26:14 +00004940 /* The link is lost so the controller stops DMA.
4941 * If there is queued Tx work that cannot be done
4942 * or if on an 8000ES2LAN which requires a Rx packet
4943 * buffer work-around on link down event, reset the
4944 * controller to flush the Tx/Rx packet buffers.
4945 * (Do the reset outside of interrupt context).
4946 */
4947 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4948 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4949 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004950 else
4951 pm_schedule_suspend(netdev->dev.parent,
4952 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004953 }
4954 }
4955
4956link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004957 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958 e1000e_update_stats(adapter);
4959
4960 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4961 adapter->tpt_old = adapter->stats.tpt;
4962 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4963 adapter->colc_old = adapter->stats.colc;
4964
Bruce Allan7c257692008-04-23 11:09:00 -07004965 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4966 adapter->gorc_old = adapter->stats.gorc;
4967 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4968 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004969 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970
Bruce Allan12d43f72012-12-05 06:26:14 +00004971 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004972 schedule_work(&adapter->reset_task);
4973 /* return immediately since reset is imminent */
4974 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975 }
4976
Bruce Allan12d43f72012-12-05 06:26:14 +00004977 e1000e_update_adaptive(&adapter->hw);
4978
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004979 /* Simple mode for Interrupt Throttle Rate (ITR) */
4980 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004981 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004982 * Total asymmetrical Tx or Rx gets ITR=8000;
4983 * everyone else is between 2000-8000.
4984 */
4985 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4986 u32 dif = (adapter->gotc > adapter->gorc ?
4987 adapter->gotc - adapter->gorc :
4988 adapter->gorc - adapter->gotc) / 10000;
4989 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4990
Matthew Vick22a4cca2012-07-12 00:02:42 +00004991 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004992 }
4993
Bruce Allanad680762008-03-28 09:15:03 -07004994 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004995 if (adapter->msix_entries)
4996 ew32(ICS, adapter->rx_ring->ims_val);
4997 else
4998 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005000 /* flush pending descriptors to memory before detecting Tx hang */
5001 e1000e_flush_descriptors(adapter);
5002
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005004 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005
Bruce Allane921eb12012-11-28 09:28:37 +00005006 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005007 * reset from the other port. Set the appropriate LAA in RAR[0]
5008 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005010 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005011
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005012 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5013 e1000e_check_82574_phy_workaround(adapter);
5014
Bruce Allanb67e1912012-12-27 08:32:33 +00005015 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5016 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5017 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5018 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5019 er32(RXSTMPH);
5020 adapter->rx_hwtstamp_cleared++;
5021 } else {
5022 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5023 }
5024 }
5025
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026 /* Reset the timer */
5027 if (!test_bit(__E1000_DOWN, &adapter->state))
5028 mod_timer(&adapter->watchdog_timer,
5029 round_jiffies(jiffies + 2 * HZ));
5030}
5031
5032#define E1000_TX_FLAGS_CSUM 0x00000001
5033#define E1000_TX_FLAGS_VLAN 0x00000002
5034#define E1000_TX_FLAGS_TSO 0x00000004
5035#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005036#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005037#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005038#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5039#define E1000_TX_FLAGS_VLAN_SHIFT 16
5040
Bruce Allan55aa6982011-12-16 00:45:45 +00005041static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043 struct e1000_context_desc *context_desc;
5044 struct e1000_buffer *buffer_info;
5045 unsigned int i;
5046 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005047 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005049
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005050 if (!skb_is_gso(skb))
5051 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005053 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005054 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5055
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005056 if (err)
5057 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005058 }
5059
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005060 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5061 mss = skb_shinfo(skb)->gso_size;
5062 if (skb->protocol == htons(ETH_P_IP)) {
5063 struct iphdr *iph = ip_hdr(skb);
5064 iph->tot_len = 0;
5065 iph->check = 0;
5066 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5067 0, IPPROTO_TCP, 0);
5068 cmd_length = E1000_TXD_CMD_IP;
5069 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005070 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005071 ipv6_hdr(skb)->payload_len = 0;
5072 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5073 &ipv6_hdr(skb)->daddr,
5074 0, IPPROTO_TCP, 0);
5075 ipcse = 0;
5076 }
5077 ipcss = skb_network_offset(skb);
5078 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5079 tucss = skb_transport_offset(skb);
5080 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005081
5082 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5083 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5084
5085 i = tx_ring->next_to_use;
5086 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5087 buffer_info = &tx_ring->buffer_info[i];
5088
5089 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5090 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5091 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5092 context_desc->upper_setup.tcp_fields.tucss = tucss;
5093 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005094 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005095 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5096 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5097 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5098
5099 buffer_info->time_stamp = jiffies;
5100 buffer_info->next_to_watch = i;
5101
5102 i++;
5103 if (i == tx_ring->count)
5104 i = 0;
5105 tx_ring->next_to_use = i;
5106
5107 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005108}
5109
Bruce Allan55aa6982011-12-16 00:45:45 +00005110static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005111{
Bruce Allan55aa6982011-12-16 00:45:45 +00005112 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005113 struct e1000_context_desc *context_desc;
5114 struct e1000_buffer *buffer_info;
5115 unsigned int i;
5116 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005117 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005118 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005119
Dave Grahamaf807c82008-10-09 14:28:58 -07005120 if (skb->ip_summed != CHECKSUM_PARTIAL)
5121 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005122
Arthur Jones5f66f202009-03-19 01:13:08 +00005123 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5124 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5125 else
5126 protocol = skb->protocol;
5127
Arthur Jones3f518392009-03-20 15:56:35 -07005128 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005129 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005130 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5131 cmd_len |= E1000_TXD_CMD_TCP;
5132 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005133 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005134 /* XXX not handling all IPV6 headers */
5135 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5136 cmd_len |= E1000_TXD_CMD_TCP;
5137 break;
5138 default:
5139 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005140 e_warn("checksum_partial proto=%x!\n",
5141 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005142 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005143 }
5144
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005145 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005146
5147 i = tx_ring->next_to_use;
5148 buffer_info = &tx_ring->buffer_info[i];
5149 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5150
5151 context_desc->lower_setup.ip_config = 0;
5152 context_desc->upper_setup.tcp_fields.tucss = css;
5153 context_desc->upper_setup.tcp_fields.tucso =
5154 css + skb->csum_offset;
5155 context_desc->upper_setup.tcp_fields.tucse = 0;
5156 context_desc->tcp_seg_setup.data = 0;
5157 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5158
5159 buffer_info->time_stamp = jiffies;
5160 buffer_info->next_to_watch = i;
5161
5162 i++;
5163 if (i == tx_ring->count)
5164 i = 0;
5165 tx_ring->next_to_use = i;
5166
5167 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005168}
5169
Bruce Allan55aa6982011-12-16 00:45:45 +00005170static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5171 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005172 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005173{
Bruce Allan55aa6982011-12-16 00:45:45 +00005174 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005175 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005176 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005177 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005178 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005179 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005180
5181 i = tx_ring->next_to_use;
5182
5183 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005184 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005185 size = min(len, max_per_txd);
5186
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005189 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005190 buffer_info->dma = dma_map_single(&pdev->dev,
5191 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005192 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005193 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005194 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005195 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005196
5197 len -= size;
5198 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005199 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005200
5201 if (len) {
5202 i++;
5203 if (i == tx_ring->count)
5204 i = 0;
5205 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005206 }
5207
5208 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005209 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005210
5211 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005212 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005213 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214
5215 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005216 i++;
5217 if (i == tx_ring->count)
5218 i = 0;
5219
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220 buffer_info = &tx_ring->buffer_info[i];
5221 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005222
5223 buffer_info->length = size;
5224 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005226 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5227 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005228 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005229 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005230 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005231
5232 len -= size;
5233 offset += size;
5234 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005235 }
5236 }
5237
Bruce Allanaf667a22010-12-31 06:10:01 +00005238 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005239 /* multiply data chunks by size of headers */
5240 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5241
Auke Kokbc7f75f2007-09-17 12:30:59 -07005242 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005243 tx_ring->buffer_info[i].segs = segs;
5244 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005245 tx_ring->buffer_info[first].next_to_watch = i;
5246
5247 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005248
5249dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005250 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005251 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005252 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005253 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005254
5255 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005256 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005257 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005258 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005259 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005260 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005261 }
5262
5263 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005264}
5265
Bruce Allan55aa6982011-12-16 00:45:45 +00005266static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267{
Bruce Allan55aa6982011-12-16 00:45:45 +00005268 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005269 struct e1000_tx_desc *tx_desc = NULL;
5270 struct e1000_buffer *buffer_info;
5271 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5272 unsigned int i;
5273
5274 if (tx_flags & E1000_TX_FLAGS_TSO) {
5275 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5276 E1000_TXD_CMD_TSE;
5277 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5278
5279 if (tx_flags & E1000_TX_FLAGS_IPV4)
5280 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5281 }
5282
5283 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5284 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5285 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5286 }
5287
5288 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5289 txd_lower |= E1000_TXD_CMD_VLE;
5290 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5291 }
5292
Ben Greear943146d2012-02-11 15:39:40 +00005293 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5294 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5295
Bruce Allanb67e1912012-12-27 08:32:33 +00005296 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5297 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5298 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5299 }
5300
Auke Kokbc7f75f2007-09-17 12:30:59 -07005301 i = tx_ring->next_to_use;
5302
Bruce Allan36b973d2010-11-24 07:42:43 +00005303 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005304 buffer_info = &tx_ring->buffer_info[i];
5305 tx_desc = E1000_TX_DESC(*tx_ring, i);
5306 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5307 tx_desc->lower.data =
5308 cpu_to_le32(txd_lower | buffer_info->length);
5309 tx_desc->upper.data = cpu_to_le32(txd_upper);
5310
5311 i++;
5312 if (i == tx_ring->count)
5313 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005314 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005315
5316 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5317
Ben Greear943146d2012-02-11 15:39:40 +00005318 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5319 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5320 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5321
Bruce Allane921eb12012-11-28 09:28:37 +00005322 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005323 * know there are new descriptors to fetch. (Only
5324 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005325 * such as IA-64).
5326 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005327 wmb();
5328
5329 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005330
5331 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005332 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005333 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005334 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005335
Bruce Allane921eb12012-11-28 09:28:37 +00005336 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005337 * at a time, it synchronizes IO on IA64/Altix systems
5338 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005339 mmiowb();
5340}
5341
5342#define MINIMUM_DHCP_PACKET_SIZE 282
5343static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5344 struct sk_buff *skb)
5345{
5346 struct e1000_hw *hw = &adapter->hw;
5347 u16 length, offset;
5348
Bruce Alland60923c2012-12-05 06:26:56 +00005349 if (vlan_tx_tag_present(skb) &&
5350 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5351 (adapter->hw.mng_cookie.status &
5352 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5353 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005354
5355 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5356 return 0;
5357
5358 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5359 return 0;
5360
5361 {
5362 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5363 struct udphdr *udp;
5364
5365 if (ip->protocol != IPPROTO_UDP)
5366 return 0;
5367
5368 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5369 if (ntohs(udp->dest) != 67)
5370 return 0;
5371
5372 offset = (u8 *)udp + 8 - skb->data;
5373 length = skb->len - offset;
5374 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5375 }
5376
5377 return 0;
5378}
5379
Bruce Allan55aa6982011-12-16 00:45:45 +00005380static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381{
Bruce Allan55aa6982011-12-16 00:45:45 +00005382 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005383
Bruce Allan55aa6982011-12-16 00:45:45 +00005384 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005385 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005387 * but since that doesn't exist yet, just open code it.
5388 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005389 smp_mb();
5390
Bruce Allane921eb12012-11-28 09:28:37 +00005391 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005392 * made room available.
5393 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005394 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005395 return -EBUSY;
5396
5397 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005398 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005399 ++adapter->restart_queue;
5400 return 0;
5401}
5402
Bruce Allan55aa6982011-12-16 00:45:45 +00005403static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404{
Bruce Alland821a4c2012-08-24 20:38:11 +00005405 BUG_ON(size > tx_ring->count);
5406
Bruce Allan55aa6982011-12-16 00:45:45 +00005407 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005409 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005410}
5411
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005412static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5413 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005414{
5415 struct e1000_adapter *adapter = netdev_priv(netdev);
5416 struct e1000_ring *tx_ring = adapter->tx_ring;
5417 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005418 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005419 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005420 unsigned int nr_frags;
5421 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422 int count = 0;
5423 int tso;
5424 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425
5426 if (test_bit(__E1000_DOWN, &adapter->state)) {
5427 dev_kfree_skb_any(skb);
5428 return NETDEV_TX_OK;
5429 }
5430
5431 if (skb->len <= 0) {
5432 dev_kfree_skb_any(skb);
5433 return NETDEV_TX_OK;
5434 }
5435
Bruce Allane921eb12012-11-28 09:28:37 +00005436 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005437 * pad skb in order to meet this minimum size requirement
5438 */
5439 if (unlikely(skb->len < 17)) {
5440 if (skb_pad(skb, 17 - skb->len))
5441 return NETDEV_TX_OK;
5442 skb->len = 17;
5443 skb_set_tail_pointer(skb, 17);
5444 }
5445
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447 if (mss) {
5448 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449
Bruce Allane921eb12012-11-28 09:28:37 +00005450 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005451 * points to just header, pull a few bytes of payload from
5452 * frags into skb->data
5453 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005455 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005456 * avoiding it could save a lot of cycles
5457 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005458 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459 unsigned int pull_size;
5460
Bruce Allana2a5b322012-01-31 06:37:17 +00005461 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005463 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005464 dev_kfree_skb_any(skb);
5465 return NETDEV_TX_OK;
5466 }
Eric Dumazete743d312010-04-14 15:59:40 -07005467 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468 }
5469 }
5470
5471 /* reserve a descriptor for the offload context */
5472 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5473 count++;
5474 count++;
5475
Bruce Alland821a4c2012-08-24 20:38:11 +00005476 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005477
5478 nr_frags = skb_shinfo(skb)->nr_frags;
5479 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005480 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5481 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005482
5483 if (adapter->hw.mac.tx_pkt_filtering)
5484 e1000_transfer_dhcp_info(adapter, skb);
5485
Bruce Allane921eb12012-11-28 09:28:37 +00005486 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005487 * head, otherwise try next time
5488 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005489 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005491
Jesse Grosseab6d182010-10-20 13:56:03 +00005492 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005493 tx_flags |= E1000_TX_FLAGS_VLAN;
5494 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5495 }
5496
5497 first = tx_ring->next_to_use;
5498
Bruce Allan55aa6982011-12-16 00:45:45 +00005499 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005500 if (tso < 0) {
5501 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502 return NETDEV_TX_OK;
5503 }
5504
5505 if (tso)
5506 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005507 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005508 tx_flags |= E1000_TX_FLAGS_CSUM;
5509
Bruce Allane921eb12012-11-28 09:28:37 +00005510 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005511 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005512 * no longer assume, we must.
5513 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005514 if (skb->protocol == htons(ETH_P_IP))
5515 tx_flags |= E1000_TX_FLAGS_IPV4;
5516
Ben Greear943146d2012-02-11 15:39:40 +00005517 if (unlikely(skb->no_fcs))
5518 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5519
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005520 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005521 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5522 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005523 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005524 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5525 !adapter->tx_hwtstamp_skb)) {
5526 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5527 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5528 adapter->tx_hwtstamp_skb = skb_get(skb);
5529 schedule_work(&adapter->tx_hwtstamp_work);
5530 } else {
5531 skb_tx_timestamp(skb);
5532 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005533
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005534 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005535 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005536 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005537 e1000_maybe_stop_tx(tx_ring,
5538 (MAX_SKB_FRAGS *
5539 DIV_ROUND_UP(PAGE_SIZE,
5540 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005541 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005542 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005543 tx_ring->buffer_info[first].time_stamp = 0;
5544 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545 }
5546
Auke Kokbc7f75f2007-09-17 12:30:59 -07005547 return NETDEV_TX_OK;
5548}
5549
5550/**
5551 * e1000_tx_timeout - Respond to a Tx Hang
5552 * @netdev: network interface device structure
5553 **/
5554static void e1000_tx_timeout(struct net_device *netdev)
5555{
5556 struct e1000_adapter *adapter = netdev_priv(netdev);
5557
5558 /* Do the reset outside of interrupt context */
5559 adapter->tx_timeout_count++;
5560 schedule_work(&adapter->reset_task);
5561}
5562
5563static void e1000_reset_task(struct work_struct *work)
5564{
5565 struct e1000_adapter *adapter;
5566 adapter = container_of(work, struct e1000_adapter, reset_task);
5567
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005568 /* don't run the task if already down */
5569 if (test_bit(__E1000_DOWN, &adapter->state))
5570 return;
5571
Bruce Allan12d43f72012-12-05 06:26:14 +00005572 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005573 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005574 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005575 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005576 e1000e_reinit_locked(adapter);
5577}
5578
5579/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005580 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005581 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005582 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005583 *
5584 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005585 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005586struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5587 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005588{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005589 struct e1000_adapter *adapter = netdev_priv(netdev);
5590
5591 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5592 spin_lock(&adapter->stats64_lock);
5593 e1000e_update_stats(adapter);
5594 /* Fill out the OS statistics structure */
5595 stats->rx_bytes = adapter->stats.gorc;
5596 stats->rx_packets = adapter->stats.gprc;
5597 stats->tx_bytes = adapter->stats.gotc;
5598 stats->tx_packets = adapter->stats.gptc;
5599 stats->multicast = adapter->stats.mprc;
5600 stats->collisions = adapter->stats.colc;
5601
5602 /* Rx Errors */
5603
Bruce Allane921eb12012-11-28 09:28:37 +00005604 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005605 * our own version based on RUC and ROC
5606 */
5607 stats->rx_errors = adapter->stats.rxerrc +
5608 adapter->stats.crcerrs + adapter->stats.algnerrc +
5609 adapter->stats.ruc + adapter->stats.roc +
5610 adapter->stats.cexterr;
5611 stats->rx_length_errors = adapter->stats.ruc +
5612 adapter->stats.roc;
5613 stats->rx_crc_errors = adapter->stats.crcerrs;
5614 stats->rx_frame_errors = adapter->stats.algnerrc;
5615 stats->rx_missed_errors = adapter->stats.mpc;
5616
5617 /* Tx Errors */
5618 stats->tx_errors = adapter->stats.ecol +
5619 adapter->stats.latecol;
5620 stats->tx_aborted_errors = adapter->stats.ecol;
5621 stats->tx_window_errors = adapter->stats.latecol;
5622 stats->tx_carrier_errors = adapter->stats.tncrs;
5623
5624 /* Tx Dropped needs to be maintained elsewhere */
5625
5626 spin_unlock(&adapter->stats64_lock);
5627 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005628}
5629
5630/**
5631 * e1000_change_mtu - Change the Maximum Transfer Unit
5632 * @netdev: network interface device structure
5633 * @new_mtu: new value for maximum frame size
5634 *
5635 * Returns 0 on success, negative on failure
5636 **/
5637static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5638{
5639 struct e1000_adapter *adapter = netdev_priv(netdev);
5640 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5641
Bruce Allan2adc55c2009-06-02 11:28:58 +00005642 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005643 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5644 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5645 e_err("Jumbo Frames not supported.\n");
5646 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005647 }
5648
Bruce Allan2adc55c2009-06-02 11:28:58 +00005649 /* Supported frame sizes */
5650 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5651 (max_frame > adapter->max_hw_frame_size)) {
5652 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005653 return -EINVAL;
5654 }
5655
Bruce Allan2fbe4522012-04-19 03:21:47 +00005656 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5657 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005658 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5659 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005660 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005661 return -EINVAL;
5662 }
5663
Auke Kokbc7f75f2007-09-17 12:30:59 -07005664 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005665 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005666 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005667 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005668 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5669 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005670 if (netif_running(netdev))
5671 e1000e_down(adapter);
5672
Bruce Allane921eb12012-11-28 09:28:37 +00005673 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005674 * means we reserve 2 more, this pushes us to allocate from the next
5675 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005676 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005677 * However with the new *_jumbo_rx* routines, jumbo receives will use
5678 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005679 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005680
Jesse Brandeburg99261462010-01-22 22:56:16 +00005681 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005682 adapter->rx_buffer_len = 2048;
5683 else
5684 adapter->rx_buffer_len = 4096;
5685
5686 /* adjust allocation if LPE protects us, and we aren't using SBP */
5687 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5688 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5689 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005690 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691
Auke Kokbc7f75f2007-09-17 12:30:59 -07005692 if (netif_running(netdev))
5693 e1000e_up(adapter);
5694 else
5695 e1000e_reset(adapter);
5696
5697 clear_bit(__E1000_RESETTING, &adapter->state);
5698
5699 return 0;
5700}
5701
5702static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5703 int cmd)
5704{
5705 struct e1000_adapter *adapter = netdev_priv(netdev);
5706 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005707
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005708 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005709 return -EOPNOTSUPP;
5710
5711 switch (cmd) {
5712 case SIOCGMIIPHY:
5713 data->phy_id = adapter->hw.phy.addr;
5714 break;
5715 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005716 e1000_phy_read_status(adapter);
5717
Bruce Allan7c257692008-04-23 11:09:00 -07005718 switch (data->reg_num & 0x1F) {
5719 case MII_BMCR:
5720 data->val_out = adapter->phy_regs.bmcr;
5721 break;
5722 case MII_BMSR:
5723 data->val_out = adapter->phy_regs.bmsr;
5724 break;
5725 case MII_PHYSID1:
5726 data->val_out = (adapter->hw.phy.id >> 16);
5727 break;
5728 case MII_PHYSID2:
5729 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5730 break;
5731 case MII_ADVERTISE:
5732 data->val_out = adapter->phy_regs.advertise;
5733 break;
5734 case MII_LPA:
5735 data->val_out = adapter->phy_regs.lpa;
5736 break;
5737 case MII_EXPANSION:
5738 data->val_out = adapter->phy_regs.expansion;
5739 break;
5740 case MII_CTRL1000:
5741 data->val_out = adapter->phy_regs.ctrl1000;
5742 break;
5743 case MII_STAT1000:
5744 data->val_out = adapter->phy_regs.stat1000;
5745 break;
5746 case MII_ESTATUS:
5747 data->val_out = adapter->phy_regs.estatus;
5748 break;
5749 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005750 return -EIO;
5751 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005752 break;
5753 case SIOCSMIIREG:
5754 default:
5755 return -EOPNOTSUPP;
5756 }
5757 return 0;
5758}
5759
Bruce Allanb67e1912012-12-27 08:32:33 +00005760/**
5761 * e1000e_hwtstamp_ioctl - control hardware time stamping
5762 * @netdev: network interface device structure
5763 * @ifreq: interface request
5764 *
5765 * Outgoing time stamping can be enabled and disabled. Play nice and
5766 * disable it when requested, although it shouldn't cause any overhead
5767 * when no packet needs it. At most one packet in the queue may be
5768 * marked for time stamping, otherwise it would be impossible to tell
5769 * for sure to which packet the hardware time stamp belongs.
5770 *
5771 * Incoming time stamping has to be configured via the hardware filters.
5772 * Not all combinations are supported, in particular event type has to be
5773 * specified. Matching the kind of event packet is not supported, with the
5774 * exception of "all V2 events regardless of level 2 or 4".
5775 **/
5776static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5777{
5778 struct e1000_adapter *adapter = netdev_priv(netdev);
5779 struct hwtstamp_config config;
5780 int ret_val;
5781
5782 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5783 return -EFAULT;
5784
5785 adapter->hwtstamp_config = config;
5786
5787 ret_val = e1000e_config_hwtstamp(adapter);
5788 if (ret_val)
5789 return ret_val;
5790
5791 config = adapter->hwtstamp_config;
5792
Bruce Alland89777b2013-01-19 01:09:58 +00005793 switch (config.rx_filter) {
5794 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5795 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5796 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5797 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5798 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5799 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5800 /* With V2 type filters which specify a Sync or Delay Request,
5801 * Path Delay Request/Response messages are also time stamped
5802 * by hardware so notify the caller the requested packets plus
5803 * some others are time stamped.
5804 */
5805 config.rx_filter = HWTSTAMP_FILTER_SOME;
5806 break;
5807 default:
5808 break;
5809 }
5810
Bruce Allanb67e1912012-12-27 08:32:33 +00005811 return copy_to_user(ifr->ifr_data, &config,
5812 sizeof(config)) ? -EFAULT : 0;
5813}
5814
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5816{
5817 switch (cmd) {
5818 case SIOCGMIIPHY:
5819 case SIOCGMIIREG:
5820 case SIOCSMIIREG:
5821 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005822 case SIOCSHWTSTAMP:
5823 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005824 default:
5825 return -EOPNOTSUPP;
5826 }
5827}
5828
Bruce Allana4f58f52009-06-02 11:29:18 +00005829static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5830{
5831 struct e1000_hw *hw = &adapter->hw;
5832 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005833 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005834 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005835
5836 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005837 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005838
Bruce Allan2b6b1682011-05-13 07:20:09 +00005839 retval = hw->phy.ops.acquire(hw);
5840 if (retval) {
5841 e_err("Could not acquire PHY\n");
5842 return retval;
5843 }
5844
5845 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5846 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5847 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005848 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005849
5850 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005851 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5852 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005853 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5854 (u16)(mac_reg & 0xFFFF));
5855 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5856 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005857 }
5858
5859 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005860 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005861 mac_reg = er32(RCTL);
5862 if (mac_reg & E1000_RCTL_UPE)
5863 phy_reg |= BM_RCTL_UPE;
5864 if (mac_reg & E1000_RCTL_MPE)
5865 phy_reg |= BM_RCTL_MPE;
5866 phy_reg &= ~(BM_RCTL_MO_MASK);
5867 if (mac_reg & E1000_RCTL_MO_3)
5868 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5869 << BM_RCTL_MO_SHIFT);
5870 if (mac_reg & E1000_RCTL_BAM)
5871 phy_reg |= BM_RCTL_BAM;
5872 if (mac_reg & E1000_RCTL_PMCF)
5873 phy_reg |= BM_RCTL_PMCF;
5874 mac_reg = er32(CTRL);
5875 if (mac_reg & E1000_CTRL_RFCE)
5876 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005877 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005878
5879 /* enable PHY wakeup in MAC register */
5880 ew32(WUFC, wufc);
5881 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5882
5883 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005884 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5885 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005886
5887 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005888 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5889 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005890 if (retval)
5891 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005892release:
Bruce Allan94d81862009-11-20 23:25:26 +00005893 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005894
5895 return retval;
5896}
5897
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005898static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5899 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005900{
5901 struct net_device *netdev = pci_get_drvdata(pdev);
5902 struct e1000_adapter *adapter = netdev_priv(netdev);
5903 struct e1000_hw *hw = &adapter->hw;
5904 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005905 /* Runtime suspend should only enable wakeup for link changes */
5906 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 int retval = 0;
5908
5909 netif_device_detach(netdev);
5910
5911 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005912 int count = E1000_CHECK_RESET_COUNT;
5913
5914 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5915 usleep_range(10000, 20000);
5916
Auke Kokbc7f75f2007-09-17 12:30:59 -07005917 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5918 e1000e_down(adapter);
5919 e1000_free_irq(adapter);
5920 }
Bruce Allan4662e822008-08-26 18:37:06 -07005921 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005922
5923 retval = pci_save_state(pdev);
5924 if (retval)
5925 return retval;
5926
5927 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);
5943 /* advertise wake from D3Cold */
5944 #define E1000_CTRL_ADVD3WUC 0x00100000
5945 /* phy power management enable */
5946 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005947 ctrl |= E1000_CTRL_ADVD3WUC;
5948 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5949 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005950 ew32(CTRL, ctrl);
5951
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005952 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5953 adapter->hw.phy.media_type ==
5954 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 /* keep the laser running in D3 */
5956 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005957 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005958 ew32(CTRL_EXT, ctrl_ext);
5959 }
5960
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005961 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005962 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005963
Auke Kokbc7f75f2007-09-17 12:30:59 -07005964 /* Allow time for pending master requests to run */
5965 e1000e_disable_pcie_master(&adapter->hw);
5966
Bruce Allan82776a42009-08-14 14:35:33 +00005967 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005968 /* enable wakeup by the PHY */
5969 retval = e1000_init_phy_wakeup(adapter, wufc);
5970 if (retval)
5971 return retval;
5972 } else {
5973 /* enable wakeup by the MAC */
5974 ew32(WUFC, wufc);
5975 ew32(WUC, E1000_WUC_PME_EN);
5976 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005977 } else {
5978 ew32(WUC, 0);
5979 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980 }
5981
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005982 *enable_wake = !!wufc;
5983
Auke Kokbc7f75f2007-09-17 12:30:59 -07005984 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005985 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5986 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005987 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005988
5989 if (adapter->hw.phy.type == e1000_phy_igp_3)
5990 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5991
Bruce Allane921eb12012-11-28 09:28:37 +00005992 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005993 * would have already happened in close and is redundant.
5994 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005995 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005996
5997 pci_disable_device(pdev);
5998
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005999 return 0;
6000}
6001
6002static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
6003{
6004 if (sleep && wake) {
6005 pci_prepare_to_sleep(pdev);
6006 return;
6007 }
6008
6009 pci_wake_from_d3(pdev, wake);
6010 pci_set_power_state(pdev, PCI_D3hot);
6011}
6012
6013static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
6014 bool wake)
6015{
6016 struct net_device *netdev = pci_get_drvdata(pdev);
6017 struct e1000_adapter *adapter = netdev_priv(netdev);
6018
Bruce Allane921eb12012-11-28 09:28:37 +00006019 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006020 * correctable error when the MAC transitions from D0 to D3. To
6021 * prevent this we need to mask off the correctable errors on the
6022 * downstream port of the pci-e switch.
6023 */
6024 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6025 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006026 u16 devctl;
6027
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006028 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6029 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6030 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006031
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006032 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006033
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006034 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006035 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006036 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006037 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038}
6039
Bruce Allan6f461f62010-04-27 03:33:04 +00006040#ifdef CONFIG_PCIEASPM
6041static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6042{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006043 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006044}
6045#else
6046static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006047{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006048 u16 aspm_ctl = 0;
6049
6050 if (state & PCIE_LINK_STATE_L0S)
6051 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6052 if (state & PCIE_LINK_STATE_L1)
6053 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6054
Bruce Allane921eb12012-11-28 09:28:37 +00006055 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006056 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006057 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006058 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006059
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006060 if (pdev->bus->self)
6061 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006062 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006063}
6064#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006065static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006066{
6067 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6068 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6069 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6070
6071 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006072}
6073
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006074#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006075static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006076{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006077 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006078}
6079
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006080static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006081{
6082 struct net_device *netdev = pci_get_drvdata(pdev);
6083 struct e1000_adapter *adapter = netdev_priv(netdev);
6084 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006085 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086 u32 err;
6087
Bruce Allan78cd29d2011-03-24 03:09:03 +00006088 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6089 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6090 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6091 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6092 if (aspm_disable_flag)
6093 e1000e_disable_aspm(pdev, aspm_disable_flag);
6094
Auke Kokbc7f75f2007-09-17 12:30:59 -07006095 pci_set_power_state(pdev, PCI_D0);
6096 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006097 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006098
Bruce Allan4662e822008-08-26 18:37:06 -07006099 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100 if (netif_running(netdev)) {
6101 err = e1000_request_irq(adapter);
6102 if (err)
6103 return err;
6104 }
6105
Bruce Allan2fbe4522012-04-19 03:21:47 +00006106 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006107 e1000_resume_workarounds_pchlan(&adapter->hw);
6108
Auke Kokbc7f75f2007-09-17 12:30:59 -07006109 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006110
6111 /* report the system wakeup cause from S3/S4 */
6112 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6113 u16 phy_data;
6114
6115 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6116 if (phy_data) {
6117 e_info("PHY Wakeup cause - %s\n",
6118 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6119 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6120 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6121 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006122 phy_data & E1000_WUS_LNKC ?
6123 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006124 }
6125 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6126 } else {
6127 u32 wus = er32(WUS);
6128 if (wus) {
6129 e_info("MAC Wakeup cause - %s\n",
6130 wus & E1000_WUS_EX ? "Unicast Packet" :
6131 wus & E1000_WUS_MC ? "Multicast Packet" :
6132 wus & E1000_WUS_BC ? "Broadcast Packet" :
6133 wus & E1000_WUS_MAG ? "Magic Packet" :
6134 wus & E1000_WUS_LNKC ? "Link Status Change" :
6135 "other");
6136 }
6137 ew32(WUS, ~0);
6138 }
6139
Auke Kokbc7f75f2007-09-17 12:30:59 -07006140 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141
Bruce Allancd791612010-05-10 14:59:51 +00006142 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006143
6144 if (netif_running(netdev))
6145 e1000e_up(adapter);
6146
6147 netif_device_attach(netdev);
6148
Bruce Allane921eb12012-11-28 09:28:37 +00006149 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006150 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006151 * under the control of the driver.
6152 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006153 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006154 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155
6156 return 0;
6157}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006158
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006159#ifdef CONFIG_PM_SLEEP
6160static int e1000_suspend(struct device *dev)
6161{
6162 struct pci_dev *pdev = to_pci_dev(dev);
6163 int retval;
6164 bool wake;
6165
6166 retval = __e1000_shutdown(pdev, &wake, false);
6167 if (!retval)
6168 e1000_complete_shutdown(pdev, true, wake);
6169
6170 return retval;
6171}
6172
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006173static int e1000_resume(struct device *dev)
6174{
6175 struct pci_dev *pdev = to_pci_dev(dev);
6176 struct net_device *netdev = pci_get_drvdata(pdev);
6177 struct e1000_adapter *adapter = netdev_priv(netdev);
6178
6179 if (e1000e_pm_ready(adapter))
6180 adapter->idle_check = true;
6181
6182 return __e1000_resume(pdev);
6183}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006184#endif /* CONFIG_PM_SLEEP */
6185
6186#ifdef CONFIG_PM_RUNTIME
6187static int e1000_runtime_suspend(struct device *dev)
6188{
6189 struct pci_dev *pdev = to_pci_dev(dev);
6190 struct net_device *netdev = pci_get_drvdata(pdev);
6191 struct e1000_adapter *adapter = netdev_priv(netdev);
6192
6193 if (e1000e_pm_ready(adapter)) {
6194 bool wake;
6195
6196 __e1000_shutdown(pdev, &wake, true);
6197 }
6198
6199 return 0;
6200}
6201
6202static int e1000_idle(struct device *dev)
6203{
6204 struct pci_dev *pdev = to_pci_dev(dev);
6205 struct net_device *netdev = pci_get_drvdata(pdev);
6206 struct e1000_adapter *adapter = netdev_priv(netdev);
6207
6208 if (!e1000e_pm_ready(adapter))
6209 return 0;
6210
6211 if (adapter->idle_check) {
6212 adapter->idle_check = false;
6213 if (!e1000e_has_link(adapter))
6214 pm_schedule_suspend(dev, MSEC_PER_SEC);
6215 }
6216
6217 return -EBUSY;
6218}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006219
6220static int e1000_runtime_resume(struct device *dev)
6221{
6222 struct pci_dev *pdev = to_pci_dev(dev);
6223 struct net_device *netdev = pci_get_drvdata(pdev);
6224 struct e1000_adapter *adapter = netdev_priv(netdev);
6225
6226 if (!e1000e_pm_ready(adapter))
6227 return 0;
6228
6229 adapter->idle_check = !dev->power.runtime_auto;
6230 return __e1000_resume(pdev);
6231}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006232#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006233#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234
6235static void e1000_shutdown(struct pci_dev *pdev)
6236{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006237 bool wake = false;
6238
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006239 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006240
6241 if (system_state == SYSTEM_POWER_OFF)
6242 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006243}
6244
6245#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006246
Bruce Allan8bb62862013-01-16 08:46:49 +00006247static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006248{
6249 struct net_device *netdev = data;
6250 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006251
6252 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006253 int vector, msix_irq;
6254
Dongdong Deng147b2c82010-11-16 19:50:15 -08006255 vector = 0;
6256 msix_irq = adapter->msix_entries[vector].vector;
6257 disable_irq(msix_irq);
6258 e1000_intr_msix_rx(msix_irq, netdev);
6259 enable_irq(msix_irq);
6260
6261 vector++;
6262 msix_irq = adapter->msix_entries[vector].vector;
6263 disable_irq(msix_irq);
6264 e1000_intr_msix_tx(msix_irq, netdev);
6265 enable_irq(msix_irq);
6266
6267 vector++;
6268 msix_irq = adapter->msix_entries[vector].vector;
6269 disable_irq(msix_irq);
6270 e1000_msix_other(msix_irq, netdev);
6271 enable_irq(msix_irq);
6272 }
6273
6274 return IRQ_HANDLED;
6275}
6276
Bruce Allane921eb12012-11-28 09:28:37 +00006277/**
6278 * e1000_netpoll
6279 * @netdev: network interface device structure
6280 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006281 * Polling 'interrupt' - used by things like netconsole to send skbs
6282 * without having to re-enable interrupts. It's not called while
6283 * the interrupt routine is executing.
6284 */
6285static void e1000_netpoll(struct net_device *netdev)
6286{
6287 struct e1000_adapter *adapter = netdev_priv(netdev);
6288
Dongdong Deng147b2c82010-11-16 19:50:15 -08006289 switch (adapter->int_mode) {
6290 case E1000E_INT_MODE_MSIX:
6291 e1000_intr_msix(adapter->pdev->irq, netdev);
6292 break;
6293 case E1000E_INT_MODE_MSI:
6294 disable_irq(adapter->pdev->irq);
6295 e1000_intr_msi(adapter->pdev->irq, netdev);
6296 enable_irq(adapter->pdev->irq);
6297 break;
6298 default: /* E1000E_INT_MODE_LEGACY */
6299 disable_irq(adapter->pdev->irq);
6300 e1000_intr(adapter->pdev->irq, netdev);
6301 enable_irq(adapter->pdev->irq);
6302 break;
6303 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006304}
6305#endif
6306
6307/**
6308 * e1000_io_error_detected - called when PCI error is detected
6309 * @pdev: Pointer to PCI device
6310 * @state: The current pci connection state
6311 *
6312 * This function is called after a PCI bus error affecting
6313 * this device has been detected.
6314 */
6315static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6316 pci_channel_state_t state)
6317{
6318 struct net_device *netdev = pci_get_drvdata(pdev);
6319 struct e1000_adapter *adapter = netdev_priv(netdev);
6320
6321 netif_device_detach(netdev);
6322
Mike Masonc93b5a72009-06-30 12:45:53 +00006323 if (state == pci_channel_io_perm_failure)
6324 return PCI_ERS_RESULT_DISCONNECT;
6325
Auke Kokbc7f75f2007-09-17 12:30:59 -07006326 if (netif_running(netdev))
6327 e1000e_down(adapter);
6328 pci_disable_device(pdev);
6329
6330 /* Request a slot slot reset. */
6331 return PCI_ERS_RESULT_NEED_RESET;
6332}
6333
6334/**
6335 * e1000_io_slot_reset - called after the pci bus has been reset.
6336 * @pdev: Pointer to PCI device
6337 *
6338 * Restart the card from scratch, as if from a cold-boot. Implementation
6339 * resembles the first-half of the e1000_resume routine.
6340 */
6341static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6342{
6343 struct net_device *netdev = pci_get_drvdata(pdev);
6344 struct e1000_adapter *adapter = netdev_priv(netdev);
6345 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006346 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006347 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006348 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006349
Bruce Allan78cd29d2011-03-24 03:09:03 +00006350 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6351 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006352 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006353 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6354 if (aspm_disable_flag)
6355 e1000e_disable_aspm(pdev, aspm_disable_flag);
6356
Bruce Allanf0f422e2008-08-04 17:21:53 -07006357 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006358 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006359 dev_err(&pdev->dev,
6360 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006361 result = PCI_ERS_RESULT_DISCONNECT;
6362 } else {
6363 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006364 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006365 pci_restore_state(pdev);
6366
6367 pci_enable_wake(pdev, PCI_D3hot, 0);
6368 pci_enable_wake(pdev, PCI_D3cold, 0);
6369
6370 e1000e_reset(adapter);
6371 ew32(WUS, ~0);
6372 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006373 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006374
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006375 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006376
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006377 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006378}
6379
6380/**
6381 * e1000_io_resume - called when traffic can start flowing again.
6382 * @pdev: Pointer to PCI device
6383 *
6384 * This callback is called when the error recovery driver tells us that
6385 * its OK to resume normal operation. Implementation resembles the
6386 * second-half of the e1000_resume routine.
6387 */
6388static void e1000_io_resume(struct pci_dev *pdev)
6389{
6390 struct net_device *netdev = pci_get_drvdata(pdev);
6391 struct e1000_adapter *adapter = netdev_priv(netdev);
6392
Bruce Allancd791612010-05-10 14:59:51 +00006393 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006394
6395 if (netif_running(netdev)) {
6396 if (e1000e_up(adapter)) {
6397 dev_err(&pdev->dev,
6398 "can't bring device back up after reset\n");
6399 return;
6400 }
6401 }
6402
6403 netif_device_attach(netdev);
6404
Bruce Allane921eb12012-11-28 09:28:37 +00006405 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006406 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006407 * under the control of the driver.
6408 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006409 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006410 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006411
6412}
6413
6414static void e1000_print_device_info(struct e1000_adapter *adapter)
6415{
6416 struct e1000_hw *hw = &adapter->hw;
6417 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006418 u32 ret_val;
6419 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006420
6421 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006422 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006423 /* bus width */
6424 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6425 "Width x1"),
6426 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006427 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006428 e_info("Intel(R) PRO/%s Network Connection\n",
6429 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006430 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6431 E1000_PBANUM_LENGTH);
6432 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006433 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006434 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6435 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006436}
6437
Auke Kok10aa4c02008-08-04 17:21:20 -07006438static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6439{
6440 struct e1000_hw *hw = &adapter->hw;
6441 int ret_val;
6442 u16 buf = 0;
6443
6444 if (hw->mac.type != e1000_82573)
6445 return;
6446
6447 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006448 le16_to_cpus(&buf);
6449 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006450 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006451 dev_warn(&adapter->pdev->dev,
6452 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006453 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006454}
6455
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006456static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006457 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006458{
6459 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006460 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006461
6462 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6463 adapter->flags |= FLAG_TSO_FORCE;
6464
6465 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006466 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6467 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006468 return 0;
6469
Ben Greear01840392012-02-11 15:39:25 +00006470 if (changed & NETIF_F_RXFCS) {
6471 if (features & NETIF_F_RXFCS) {
6472 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6473 } else {
6474 /* We need to take it back to defaults, which might mean
6475 * stripping is still disabled at the adapter level.
6476 */
6477 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6478 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6479 else
6480 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6481 }
6482 }
6483
Bruce Allan70495a52012-01-11 01:26:50 +00006484 netdev->features = features;
6485
Bruce Allandc221292011-08-19 03:23:48 +00006486 if (netif_running(netdev))
6487 e1000e_reinit_locked(adapter);
6488 else
6489 e1000e_reset(adapter);
6490
6491 return 0;
6492}
6493
Stephen Hemminger651c2462008-11-19 21:57:48 -08006494static const struct net_device_ops e1000e_netdev_ops = {
6495 .ndo_open = e1000_open,
6496 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006497 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006498 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006499 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006500 .ndo_set_mac_address = e1000_set_mac,
6501 .ndo_change_mtu = e1000_change_mtu,
6502 .ndo_do_ioctl = e1000_ioctl,
6503 .ndo_tx_timeout = e1000_tx_timeout,
6504 .ndo_validate_addr = eth_validate_addr,
6505
Stephen Hemminger651c2462008-11-19 21:57:48 -08006506 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6507 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6508#ifdef CONFIG_NET_POLL_CONTROLLER
6509 .ndo_poll_controller = e1000_netpoll,
6510#endif
Bruce Allandc221292011-08-19 03:23:48 +00006511 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006512};
6513
Auke Kokbc7f75f2007-09-17 12:30:59 -07006514/**
6515 * e1000_probe - Device Initialization Routine
6516 * @pdev: PCI device information struct
6517 * @ent: entry in e1000_pci_tbl
6518 *
6519 * Returns 0 on success, negative on failure
6520 *
6521 * e1000_probe initializes an adapter identified by a pci_dev structure.
6522 * The OS initialization, configuring of the adapter private structure,
6523 * and a hardware reset occur.
6524 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006525static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006526{
6527 struct net_device *netdev;
6528 struct e1000_adapter *adapter;
6529 struct e1000_hw *hw;
6530 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006531 resource_size_t mmio_start, mmio_len;
6532 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006533 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006534 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006535 int i, err, pci_using_dac;
6536 u16 eeprom_data = 0;
6537 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6538
Bruce Allan78cd29d2011-03-24 03:09:03 +00006539 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6540 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006541 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006542 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6543 if (aspm_disable_flag)
6544 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006545
Bruce Allanf0f422e2008-08-04 17:21:53 -07006546 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006547 if (err)
6548 return err;
6549
6550 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006551 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006552 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006553 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006554 if (!err)
6555 pci_using_dac = 1;
6556 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006557 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006558 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006559 err = dma_set_coherent_mask(&pdev->dev,
6560 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006561 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006562 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006563 goto err_dma;
6564 }
6565 }
6566 }
6567
Arjan van de Vene8de1482008-10-22 19:55:31 -07006568 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allan55c5f552013-01-12 07:28:24 +00006569 pci_select_bars(pdev, IORESOURCE_MEM),
6570 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006571 if (err)
6572 goto err_pci_reg;
6573
Xiaotian Feng68eac462009-08-14 14:35:52 +00006574 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006575 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006576
Auke Kokbc7f75f2007-09-17 12:30:59 -07006577 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006578 /* PCI config space info */
6579 err = pci_save_state(pdev);
6580 if (err)
6581 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006582
6583 err = -ENOMEM;
6584 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6585 if (!netdev)
6586 goto err_alloc_etherdev;
6587
Auke Kokbc7f75f2007-09-17 12:30:59 -07006588 SET_NETDEV_DEV(netdev, &pdev->dev);
6589
Tom Herbertf85e4df2010-05-05 14:03:32 +00006590 netdev->irq = pdev->irq;
6591
Auke Kokbc7f75f2007-09-17 12:30:59 -07006592 pci_set_drvdata(pdev, netdev);
6593 adapter = netdev_priv(netdev);
6594 hw = &adapter->hw;
6595 adapter->netdev = netdev;
6596 adapter->pdev = pdev;
6597 adapter->ei = ei;
6598 adapter->pba = ei->pba;
6599 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006600 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006601 adapter->hw.adapter = adapter;
6602 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006603 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006604 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006605
6606 mmio_start = pci_resource_start(pdev, 0);
6607 mmio_len = pci_resource_len(pdev, 0);
6608
6609 err = -EIO;
6610 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6611 if (!adapter->hw.hw_addr)
6612 goto err_ioremap;
6613
6614 if ((adapter->flags & FLAG_HAS_FLASH) &&
6615 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6616 flash_start = pci_resource_start(pdev, 1);
6617 flash_len = pci_resource_len(pdev, 1);
6618 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6619 if (!adapter->hw.flash_address)
6620 goto err_flashmap;
6621 }
6622
6623 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006624 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006625 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006626 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006627 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006628 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006629
6630 netdev->mem_start = mmio_start;
6631 netdev->mem_end = mmio_start + mmio_len;
6632
6633 adapter->bd_number = cards_found++;
6634
Bruce Allan4662e822008-08-26 18:37:06 -07006635 e1000e_check_options(adapter);
6636
Auke Kokbc7f75f2007-09-17 12:30:59 -07006637 /* setup adapter struct */
6638 err = e1000_sw_init(adapter);
6639 if (err)
6640 goto err_sw_init;
6641
Auke Kokbc7f75f2007-09-17 12:30:59 -07006642 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6643 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6644 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6645
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006646 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006647 if (err)
6648 goto err_hw_init;
6649
Bruce Allan4a770352008-10-01 17:18:35 -07006650 if ((adapter->flags & FLAG_IS_ICH) &&
6651 (adapter->flags & FLAG_READ_ONLY_NVM))
6652 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6653
Auke Kokbc7f75f2007-09-17 12:30:59 -07006654 hw->mac.ops.get_bus_info(&adapter->hw);
6655
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006656 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006657
6658 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006659 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006660 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6661 adapter->hw.phy.disable_polarity_correction = 0;
6662 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6663 }
6664
Bruce Allan470a5422012-05-26 06:08:48 +00006665 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006666 dev_info(&pdev->dev,
6667 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006668
Bruce Allandc221292011-08-19 03:23:48 +00006669 /* Set initial default active device features */
6670 netdev->features = (NETIF_F_SG |
6671 NETIF_F_HW_VLAN_RX |
6672 NETIF_F_HW_VLAN_TX |
6673 NETIF_F_TSO |
6674 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006675 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006676 NETIF_F_RXCSUM |
6677 NETIF_F_HW_CSUM);
6678
6679 /* Set user-changeable features (subset of all device features) */
6680 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006681 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006682 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006683 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006684
6685 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6686 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6687
Bruce Allandc221292011-08-19 03:23:48 +00006688 netdev->vlan_features |= (NETIF_F_SG |
6689 NETIF_F_TSO |
6690 NETIF_F_TSO6 |
6691 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006692
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006693 netdev->priv_flags |= IFF_UNICAST_FLT;
6694
Yi Zou7b872a52010-09-22 17:57:58 +00006695 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006696 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006697 netdev->vlan_features |= NETIF_F_HIGHDMA;
6698 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006699
Auke Kokbc7f75f2007-09-17 12:30:59 -07006700 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6701 adapter->flags |= FLAG_MNG_PT_ENABLED;
6702
Bruce Allane921eb12012-11-28 09:28:37 +00006703 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006704 * put the device in a known good starting state
6705 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006706 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6707
Bruce Allane921eb12012-11-28 09:28:37 +00006708 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006709 * attempt. Let's give it a few tries
6710 */
6711 for (i = 0;; i++) {
6712 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6713 break;
6714 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006715 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006716 err = -EIO;
6717 goto err_eeprom;
6718 }
6719 }
6720
Auke Kok10aa4c02008-08-04 17:21:20 -07006721 e1000_eeprom_checks(adapter);
6722
Bruce Allan608f8a02010-01-13 02:04:58 +00006723 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006724 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006725 dev_err(&pdev->dev,
6726 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006727
6728 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006729
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006730 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006731 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006732 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006733 err = -EIO;
6734 goto err_eeprom;
6735 }
6736
6737 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006738 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006739 adapter->watchdog_timer.data = (unsigned long) adapter;
6740
6741 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006742 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006743 adapter->phy_info_timer.data = (unsigned long) adapter;
6744
6745 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6746 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006747 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6748 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006749 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006750
Auke Kokbc7f75f2007-09-17 12:30:59 -07006751 /* Initialize link parameters. User can change them with ethtool */
6752 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006753 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006754 adapter->hw.fc.requested_mode = e1000_fc_default;
6755 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006756 adapter->hw.phy.autoneg_advertised = 0x2f;
6757
6758 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006759 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6760 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006761
Bruce Allane921eb12012-11-28 09:28:37 +00006762 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006763 * the EEPROM, enable the ACPI Magic Packet filter
6764 */
6765 if (adapter->flags & FLAG_APME_IN_WUC) {
6766 /* APME bit in EEPROM is mapped to WUC.APME */
6767 eeprom_data = er32(WUC);
6768 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006769 if ((hw->mac.type > e1000_ich10lan) &&
6770 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006771 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006772 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6773 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6774 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006775 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6776 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006777 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006778 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6779 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006780 }
6781
6782 /* fetch WoL from EEPROM */
6783 if (eeprom_data & eeprom_apme_mask)
6784 adapter->eeprom_wol |= E1000_WUFC_MAG;
6785
Bruce Allane921eb12012-11-28 09:28:37 +00006786 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006787 * where the eeprom may be wrong or the board simply won't support
6788 * wake on lan on a particular port
6789 */
6790 if (!(adapter->flags & FLAG_HAS_WOL))
6791 adapter->eeprom_wol = 0;
6792
6793 /* initialize the wol settings based on the eeprom settings */
6794 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006795 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006796
Bruce Allan84527592008-11-21 17:00:22 -08006797 /* save off EEPROM version number */
6798 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6799
Auke Kokbc7f75f2007-09-17 12:30:59 -07006800 /* reset the hardware with the new settings */
6801 e1000e_reset(adapter);
6802
Bruce Allane921eb12012-11-28 09:28:37 +00006803 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006804 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006805 * under the control of the driver.
6806 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006807 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006808 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809
Bruce Allanf2315bf2011-12-16 00:46:59 +00006810 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006811 err = register_netdev(netdev);
6812 if (err)
6813 goto err_register;
6814
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006815 /* carrier off reporting is important to ethtool even BEFORE open */
6816 netif_carrier_off(netdev);
6817
Bruce Alland89777b2013-01-19 01:09:58 +00006818 /* init PTP hardware clock */
6819 e1000e_ptp_init(adapter);
6820
Auke Kokbc7f75f2007-09-17 12:30:59 -07006821 e1000_print_device_info(adapter);
6822
Alan Sternf3ec4f82010-06-08 15:23:51 -04006823 if (pci_dev_run_wake(pdev))
6824 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006825
Auke Kokbc7f75f2007-09-17 12:30:59 -07006826 return 0;
6827
6828err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006829 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006830 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006831err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006832 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006833 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006834err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006835 kfree(adapter->tx_ring);
6836 kfree(adapter->rx_ring);
6837err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006838 if (adapter->hw.flash_address)
6839 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006840 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006841err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006842 iounmap(adapter->hw.hw_addr);
6843err_ioremap:
6844 free_netdev(netdev);
6845err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006846 pci_release_selected_regions(pdev,
6847 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006848err_pci_reg:
6849err_dma:
6850 pci_disable_device(pdev);
6851 return err;
6852}
6853
6854/**
6855 * e1000_remove - Device Removal Routine
6856 * @pdev: PCI device information struct
6857 *
6858 * e1000_remove is called by the PCI subsystem to alert the driver
6859 * that it should release a PCI device. The could be caused by a
6860 * Hot-Plug event, or because the driver is going to be removed from
6861 * memory.
6862 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006863static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006864{
6865 struct net_device *netdev = pci_get_drvdata(pdev);
6866 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006867 bool down = test_bit(__E1000_DOWN, &adapter->state);
6868
Bruce Alland89777b2013-01-19 01:09:58 +00006869 e1000e_ptp_remove(adapter);
6870
Bruce Allane921eb12012-11-28 09:28:37 +00006871 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006872 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006873 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006874 if (!down)
6875 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006876 del_timer_sync(&adapter->watchdog_timer);
6877 del_timer_sync(&adapter->phy_info_timer);
6878
Bruce Allan41cec6f2009-11-20 23:28:56 +00006879 cancel_work_sync(&adapter->reset_task);
6880 cancel_work_sync(&adapter->watchdog_task);
6881 cancel_work_sync(&adapter->downshift_task);
6882 cancel_work_sync(&adapter->update_phy_task);
6883 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006884
Bruce Allanb67e1912012-12-27 08:32:33 +00006885 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6886 cancel_work_sync(&adapter->tx_hwtstamp_work);
6887 if (adapter->tx_hwtstamp_skb) {
6888 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6889 adapter->tx_hwtstamp_skb = NULL;
6890 }
6891 }
6892
Bruce Allan17f208d2009-12-01 15:47:22 +00006893 if (!(netdev->flags & IFF_UP))
6894 e1000_power_down_phy(adapter);
6895
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006896 /* Don't lie to e1000_close() down the road. */
6897 if (!down)
6898 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006899 unregister_netdev(netdev);
6900
Alan Sternf3ec4f82010-06-08 15:23:51 -04006901 if (pci_dev_run_wake(pdev))
6902 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006903
Bruce Allane921eb12012-11-28 09:28:37 +00006904 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006905 * would have already happened in close and is redundant.
6906 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006907 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006908
Bruce Allan4662e822008-08-26 18:37:06 -07006909 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006910 kfree(adapter->tx_ring);
6911 kfree(adapter->rx_ring);
6912
6913 iounmap(adapter->hw.hw_addr);
6914 if (adapter->hw.flash_address)
6915 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006916 pci_release_selected_regions(pdev,
6917 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006918
6919 free_netdev(netdev);
6920
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006921 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006922 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006923
Auke Kokbc7f75f2007-09-17 12:30:59 -07006924 pci_disable_device(pdev);
6925}
6926
6927/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006928static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006929 .error_detected = e1000_io_error_detected,
6930 .slot_reset = e1000_io_slot_reset,
6931 .resume = e1000_io_resume,
6932};
6933
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006934static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6936 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006944
Auke Kokbc7f75f2007-09-17 12:30:59 -07006945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006949
Auke Kokbc7f75f2007-09-17 12:30:59 -07006950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006953
Bruce Allan4662e822008-08-26 18:37:06 -07006954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006957
Auke Kokbc7f75f2007-09-17 12:30:59 -07006958 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6959 board_80003es2lan },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6961 board_80003es2lan },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6963 board_80003es2lan },
6964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6965 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006966
Auke Kokbc7f75f2007-09-17 12:30:59 -07006967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006975
Auke Kokbc7f75f2007-09-17 12:30:59 -07006976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6980 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6984 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6985
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006989
Bruce Allanf4187b52008-08-26 18:36:50 -07006990 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006992 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006993
Bruce Allana4f58f52009-06-02 11:29:18 +00006994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6998
Bruce Alland3738bb2010-06-16 13:27:28 +00006999 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7000 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7001
Bruce Allan2fbe4522012-04-19 03:21:47 +00007002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7003 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007004 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7005 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007006
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007007 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007008};
7009MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7010
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007011#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007012static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007013 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
7014 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
7015 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007016};
David S. Millere50208a2010-03-16 23:36:24 -07007017#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007018
Auke Kokbc7f75f2007-09-17 12:30:59 -07007019/* PCI Device API Driver */
7020static struct pci_driver e1000_driver = {
7021 .name = e1000e_driver_name,
7022 .id_table = e1000_pci_tbl,
7023 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007024 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007025#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007026 .driver = {
7027 .pm = &e1000_pm_ops,
7028 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007029#endif
7030 .shutdown = e1000_shutdown,
7031 .err_handler = &e1000_err_handler
7032};
7033
7034/**
7035 * e1000_init_module - Driver Registration Routine
7036 *
7037 * e1000_init_module is the first routine called when the driver is
7038 * loaded. All it does is register with the PCI subsystem.
7039 **/
7040static int __init e1000_init_module(void)
7041{
7042 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007043 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7044 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007045 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007046 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007047
Auke Kokbc7f75f2007-09-17 12:30:59 -07007048 return ret;
7049}
7050module_init(e1000_init_module);
7051
7052/**
7053 * e1000_exit_module - Driver Exit Cleanup Routine
7054 *
7055 * e1000_exit_module is called just before the driver is removed
7056 * from memory.
7057 **/
7058static void __exit e1000_exit_module(void)
7059{
7060 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007061}
7062module_exit(e1000_exit_module);
7063
7064
7065MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7066MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7067MODULE_LICENSE("GPL");
7068MODULE_VERSION(DRV_VERSION);
7069
Bruce Allan06c24b92012-02-23 03:13:13 +00007070/* netdev.c */