blob: 46a38a4d8da58384bce368aa4dd4569731772571 [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 Allan076d8072012-08-17 06:18:23 +000059#define DRV_VERSION "2.1.4" 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 **/
1750static irqreturn_t e1000_intr_msi(int irq, void *data)
1751{
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 **/
1816static irqreturn_t e1000_intr(int irq, void *data)
1817{
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 Allan4662e822008-08-26 18:37:06 -07001891static irqreturn_t e1000_msix_other(int irq, void *data)
1892{
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
1923
1924static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1925{
1926 struct net_device *netdev = data;
1927 struct e1000_adapter *adapter = netdev_priv(netdev);
1928 struct e1000_hw *hw = &adapter->hw;
1929 struct e1000_ring *tx_ring = adapter->tx_ring;
1930
1931
1932 adapter->total_tx_bytes = 0;
1933 adapter->total_tx_packets = 0;
1934
Bruce Allan55aa6982011-12-16 00:45:45 +00001935 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001936 /* Ring was not completely cleaned, so fire another interrupt */
1937 ew32(ICS, tx_ring->ims_val);
1938
1939 return IRQ_HANDLED;
1940}
1941
1942static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1943{
1944 struct net_device *netdev = data;
1945 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001946 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001947
1948 /* Write the ITR value calculated at the end of the
1949 * previous interrupt.
1950 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001951 if (rx_ring->set_itr) {
1952 writel(1000000000 / (rx_ring->itr_val * 256),
1953 rx_ring->itr_register);
1954 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001955 }
1956
Ben Hutchings288379f2009-01-19 16:43:59 -08001957 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001958 adapter->total_rx_bytes = 0;
1959 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001960 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001961 }
1962 return IRQ_HANDLED;
1963}
1964
1965/**
1966 * e1000_configure_msix - Configure MSI-X hardware
1967 *
1968 * e1000_configure_msix sets up the hardware to properly
1969 * generate MSI-X interrupts.
1970 **/
1971static void e1000_configure_msix(struct e1000_adapter *adapter)
1972{
1973 struct e1000_hw *hw = &adapter->hw;
1974 struct e1000_ring *rx_ring = adapter->rx_ring;
1975 struct e1000_ring *tx_ring = adapter->tx_ring;
1976 int vector = 0;
1977 u32 ctrl_ext, ivar = 0;
1978
1979 adapter->eiac_mask = 0;
1980
1981 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1982 if (hw->mac.type == e1000_82574) {
1983 u32 rfctl = er32(RFCTL);
1984 rfctl |= E1000_RFCTL_ACK_DIS;
1985 ew32(RFCTL, rfctl);
1986 }
1987
1988#define E1000_IVAR_INT_ALLOC_VALID 0x8
1989 /* Configure Rx vector */
1990 rx_ring->ims_val = E1000_IMS_RXQ0;
1991 adapter->eiac_mask |= rx_ring->ims_val;
1992 if (rx_ring->itr_val)
1993 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001994 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001995 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001996 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001997 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1998
1999 /* Configure Tx vector */
2000 tx_ring->ims_val = E1000_IMS_TXQ0;
2001 vector++;
2002 if (tx_ring->itr_val)
2003 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002004 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002005 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002006 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002007 adapter->eiac_mask |= tx_ring->ims_val;
2008 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2009
2010 /* set vector for Other Causes, e.g. link changes */
2011 vector++;
2012 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2013 if (rx_ring->itr_val)
2014 writel(1000000000 / (rx_ring->itr_val * 256),
2015 hw->hw_addr + E1000_EITR_82574(vector));
2016 else
2017 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2018
2019 /* Cause Tx interrupts on every write back */
2020 ivar |= (1 << 31);
2021
2022 ew32(IVAR, ivar);
2023
2024 /* enable MSI-X PBA support */
2025 ctrl_ext = er32(CTRL_EXT);
2026 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2027
2028 /* Auto-Mask Other interrupts upon ICR read */
2029#define E1000_EIAC_MASK_82574 0x01F00000
2030 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2031 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2032 ew32(CTRL_EXT, ctrl_ext);
2033 e1e_flush();
2034}
2035
2036void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2037{
2038 if (adapter->msix_entries) {
2039 pci_disable_msix(adapter->pdev);
2040 kfree(adapter->msix_entries);
2041 adapter->msix_entries = NULL;
2042 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2043 pci_disable_msi(adapter->pdev);
2044 adapter->flags &= ~FLAG_MSI_ENABLED;
2045 }
Bruce Allan4662e822008-08-26 18:37:06 -07002046}
2047
2048/**
2049 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2050 *
2051 * Attempt to configure interrupts using the best available
2052 * capabilities of the hardware and kernel.
2053 **/
2054void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2055{
2056 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002057 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002058
2059 switch (adapter->int_mode) {
2060 case E1000E_INT_MODE_MSIX:
2061 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002062 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2063 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002064 sizeof(struct msix_entry),
2065 GFP_KERNEL);
2066 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002067 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002068 adapter->msix_entries[i].entry = i;
2069
2070 err = pci_enable_msix(adapter->pdev,
2071 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002072 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002073 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002074 return;
2075 }
2076 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002077 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002078 e1000e_reset_interrupt_capability(adapter);
2079 }
2080 adapter->int_mode = E1000E_INT_MODE_MSI;
2081 /* Fall through */
2082 case E1000E_INT_MODE_MSI:
2083 if (!pci_enable_msi(adapter->pdev)) {
2084 adapter->flags |= FLAG_MSI_ENABLED;
2085 } else {
2086 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002087 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002088 }
2089 /* Fall through */
2090 case E1000E_INT_MODE_LEGACY:
2091 /* Don't do anything; this is the system default */
2092 break;
2093 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002094
2095 /* store the number of vectors being used */
2096 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002097}
2098
2099/**
2100 * e1000_request_msix - Initialize MSI-X interrupts
2101 *
2102 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2103 * kernel.
2104 **/
2105static int e1000_request_msix(struct e1000_adapter *adapter)
2106{
2107 struct net_device *netdev = adapter->netdev;
2108 int err = 0, vector = 0;
2109
2110 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002111 snprintf(adapter->rx_ring->name,
2112 sizeof(adapter->rx_ring->name) - 1,
2113 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002114 else
2115 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2116 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002117 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002118 netdev);
2119 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002120 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002121 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2122 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002123 adapter->rx_ring->itr_val = adapter->itr;
2124 vector++;
2125
2126 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002127 snprintf(adapter->tx_ring->name,
2128 sizeof(adapter->tx_ring->name) - 1,
2129 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002130 else
2131 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2132 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002133 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002134 netdev);
2135 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002136 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002137 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2138 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002139 adapter->tx_ring->itr_val = adapter->itr;
2140 vector++;
2141
2142 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002143 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002144 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002145 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002146
2147 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002148
Bruce Allan4662e822008-08-26 18:37:06 -07002149 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002150}
2151
Bruce Allanf8d59f72008-08-08 18:36:11 -07002152/**
2153 * e1000_request_irq - initialize interrupts
2154 *
2155 * Attempts to configure interrupts using the best available
2156 * capabilities of the hardware and kernel.
2157 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002158static int e1000_request_irq(struct e1000_adapter *adapter)
2159{
2160 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002161 int err;
2162
Bruce Allan4662e822008-08-26 18:37:06 -07002163 if (adapter->msix_entries) {
2164 err = e1000_request_msix(adapter);
2165 if (!err)
2166 return err;
2167 /* fall back to MSI */
2168 e1000e_reset_interrupt_capability(adapter);
2169 adapter->int_mode = E1000E_INT_MODE_MSI;
2170 e1000e_set_interrupt_capability(adapter);
2171 }
2172 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002173 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002174 netdev->name, netdev);
2175 if (!err)
2176 return err;
2177
2178 /* fall back to legacy interrupt */
2179 e1000e_reset_interrupt_capability(adapter);
2180 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002181 }
2182
Joe Perchesa0607fd2009-11-18 23:29:17 -08002183 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002184 netdev->name, netdev);
2185 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002186 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187
2188 return err;
2189}
2190
2191static void e1000_free_irq(struct e1000_adapter *adapter)
2192{
2193 struct net_device *netdev = adapter->netdev;
2194
Bruce Allan4662e822008-08-26 18:37:06 -07002195 if (adapter->msix_entries) {
2196 int vector = 0;
2197
2198 free_irq(adapter->msix_entries[vector].vector, netdev);
2199 vector++;
2200
2201 free_irq(adapter->msix_entries[vector].vector, netdev);
2202 vector++;
2203
2204 /* Other Causes interrupt vector */
2205 free_irq(adapter->msix_entries[vector].vector, netdev);
2206 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207 }
Bruce Allan4662e822008-08-26 18:37:06 -07002208
2209 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210}
2211
2212/**
2213 * e1000_irq_disable - Mask off interrupt generation on the NIC
2214 **/
2215static void e1000_irq_disable(struct e1000_adapter *adapter)
2216{
2217 struct e1000_hw *hw = &adapter->hw;
2218
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002220 if (adapter->msix_entries)
2221 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002222 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002223
2224 if (adapter->msix_entries) {
2225 int i;
2226 for (i = 0; i < adapter->num_vectors; i++)
2227 synchronize_irq(adapter->msix_entries[i].vector);
2228 } else {
2229 synchronize_irq(adapter->pdev->irq);
2230 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231}
2232
2233/**
2234 * e1000_irq_enable - Enable default interrupt generation settings
2235 **/
2236static void e1000_irq_enable(struct e1000_adapter *adapter)
2237{
2238 struct e1000_hw *hw = &adapter->hw;
2239
Bruce Allan4662e822008-08-26 18:37:06 -07002240 if (adapter->msix_entries) {
2241 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2242 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002243 } else if (hw->mac.type == e1000_pch_lpt) {
2244 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002245 } else {
2246 ew32(IMS, IMS_ENABLE_MASK);
2247 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002248 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249}
2250
2251/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002252 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 * @adapter: address of board private structure
2254 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002255 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002256 * For ASF and Pass Through versions of f/w this means that
2257 * the driver is loaded. For AMT version (only with 82573)
2258 * of the f/w this means that the network i/f is open.
2259 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002260void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261{
2262 struct e1000_hw *hw = &adapter->hw;
2263 u32 ctrl_ext;
2264 u32 swsm;
2265
2266 /* Let firmware know the driver has taken over */
2267 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2268 swsm = er32(SWSM);
2269 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2270 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2271 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002272 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273 }
2274}
2275
2276/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002277 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002278 * @adapter: address of board private structure
2279 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002280 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002281 * For ASF and Pass Through versions of f/w this means that the
2282 * driver is no longer loaded. For AMT version (only with 82573) i
2283 * of the f/w this means that the network i/f is closed.
2284 *
2285 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002286void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002287{
2288 struct e1000_hw *hw = &adapter->hw;
2289 u32 ctrl_ext;
2290 u32 swsm;
2291
2292 /* Let firmware taken over control of h/w */
2293 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2294 swsm = er32(SWSM);
2295 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2296 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2297 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002298 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002299 }
2300}
2301
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002303 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002304 **/
2305static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2306 struct e1000_ring *ring)
2307{
2308 struct pci_dev *pdev = adapter->pdev;
2309
2310 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2311 GFP_KERNEL);
2312 if (!ring->desc)
2313 return -ENOMEM;
2314
2315 return 0;
2316}
2317
2318/**
2319 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002320 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321 *
2322 * Return 0 on success, negative on failure
2323 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002324int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325{
Bruce Allan55aa6982011-12-16 00:45:45 +00002326 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327 int err = -ENOMEM, size;
2328
2329 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002330 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002331 if (!tx_ring->buffer_info)
2332 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333
2334 /* round up to nearest 4K */
2335 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2336 tx_ring->size = ALIGN(tx_ring->size, 4096);
2337
2338 err = e1000_alloc_ring_dma(adapter, tx_ring);
2339 if (err)
2340 goto err;
2341
2342 tx_ring->next_to_use = 0;
2343 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344
2345 return 0;
2346err:
2347 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002348 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002349 return err;
2350}
2351
2352/**
2353 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002354 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002355 *
2356 * Returns 0 on success, negative on failure
2357 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002358int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359{
Bruce Allan55aa6982011-12-16 00:45:45 +00002360 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002361 struct e1000_buffer *buffer_info;
2362 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363
2364 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002365 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 if (!rx_ring->buffer_info)
2367 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368
Auke Kok47f44e42007-10-25 13:57:44 -07002369 for (i = 0; i < rx_ring->count; i++) {
2370 buffer_info = &rx_ring->buffer_info[i];
2371 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2372 sizeof(struct e1000_ps_page),
2373 GFP_KERNEL);
2374 if (!buffer_info->ps_pages)
2375 goto err_pages;
2376 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377
2378 desc_len = sizeof(union e1000_rx_desc_packet_split);
2379
2380 /* Round up to nearest 4K */
2381 rx_ring->size = rx_ring->count * desc_len;
2382 rx_ring->size = ALIGN(rx_ring->size, 4096);
2383
2384 err = e1000_alloc_ring_dma(adapter, rx_ring);
2385 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002386 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387
2388 rx_ring->next_to_clean = 0;
2389 rx_ring->next_to_use = 0;
2390 rx_ring->rx_skb_top = NULL;
2391
2392 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002393
2394err_pages:
2395 for (i = 0; i < rx_ring->count; i++) {
2396 buffer_info = &rx_ring->buffer_info[i];
2397 kfree(buffer_info->ps_pages);
2398 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399err:
2400 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002401 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 return err;
2403}
2404
2405/**
2406 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002407 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002408 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002409static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410{
Bruce Allan55aa6982011-12-16 00:45:45 +00002411 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002412 struct e1000_buffer *buffer_info;
2413 unsigned long size;
2414 unsigned int i;
2415
2416 for (i = 0; i < tx_ring->count; i++) {
2417 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002418 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419 }
2420
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002421 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422 size = sizeof(struct e1000_buffer) * tx_ring->count;
2423 memset(tx_ring->buffer_info, 0, size);
2424
2425 memset(tx_ring->desc, 0, tx_ring->size);
2426
2427 tx_ring->next_to_use = 0;
2428 tx_ring->next_to_clean = 0;
2429
Bruce Allanc5083cf2011-12-16 00:45:40 +00002430 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002431 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2432 e1000e_update_tdt_wa(tx_ring, 0);
2433 else
2434 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435}
2436
2437/**
2438 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002439 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440 *
2441 * Free all transmit software resources
2442 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002443void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444{
Bruce Allan55aa6982011-12-16 00:45:45 +00002445 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447
Bruce Allan55aa6982011-12-16 00:45:45 +00002448 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002449
2450 vfree(tx_ring->buffer_info);
2451 tx_ring->buffer_info = NULL;
2452
2453 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2454 tx_ring->dma);
2455 tx_ring->desc = NULL;
2456}
2457
2458/**
2459 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002460 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 *
2462 * Free all receive software resources
2463 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002464void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465{
Bruce Allan55aa6982011-12-16 00:45:45 +00002466 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002468 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002469
Bruce Allan55aa6982011-12-16 00:45:45 +00002470 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002472 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002473 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002474
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475 vfree(rx_ring->buffer_info);
2476 rx_ring->buffer_info = NULL;
2477
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2479 rx_ring->dma);
2480 rx_ring->desc = NULL;
2481}
2482
2483/**
2484 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002485 * @adapter: pointer to adapter
2486 * @itr_setting: current adapter->itr
2487 * @packets: the number of packets during this measurement interval
2488 * @bytes: the number of bytes during this measurement interval
2489 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002490 * Stores a new ITR value based on packets and byte
2491 * counts during the last interrupt. The advantage of per interrupt
2492 * computation is faster updates and more accurate ITR for the current
2493 * traffic pattern. Constants in this function were computed
2494 * based on theoretical maximum wire speed and thresholds were set based
2495 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002496 * while increasing bulk throughput. This functionality is controlled
2497 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 **/
2499static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2500 u16 itr_setting, int packets,
2501 int bytes)
2502{
2503 unsigned int retval = itr_setting;
2504
2505 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002506 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507
2508 switch (itr_setting) {
2509 case lowest_latency:
2510 /* handle TSO and jumbo frames */
2511 if (bytes/packets > 8000)
2512 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002513 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 break;
2516 case low_latency: /* 50 usec aka 20000 ints/s */
2517 if (bytes > 10000) {
2518 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002519 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002521 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002523 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002525 } else if (bytes/packets > 2000) {
2526 retval = bulk_latency;
2527 } else if (packets <= 2 && bytes < 512) {
2528 retval = lowest_latency;
2529 }
2530 break;
2531 case bulk_latency: /* 250 usec aka 4000 ints/s */
2532 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002533 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002534 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 } else if (bytes < 6000) {
2536 retval = low_latency;
2537 }
2538 break;
2539 }
2540
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 return retval;
2542}
2543
2544static void e1000_set_itr(struct e1000_adapter *adapter)
2545{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546 u16 current_itr;
2547 u32 new_itr = adapter->itr;
2548
2549 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2550 if (adapter->link_speed != SPEED_1000) {
2551 current_itr = 0;
2552 new_itr = 4000;
2553 goto set_itr_now;
2554 }
2555
Bruce Allan828bac82010-09-29 21:39:37 +00002556 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2557 new_itr = 0;
2558 goto set_itr_now;
2559 }
2560
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 adapter->tx_itr = e1000_update_itr(adapter,
2562 adapter->tx_itr,
2563 adapter->total_tx_packets,
2564 adapter->total_tx_bytes);
2565 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2566 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2567 adapter->tx_itr = low_latency;
2568
2569 adapter->rx_itr = e1000_update_itr(adapter,
2570 adapter->rx_itr,
2571 adapter->total_rx_packets,
2572 adapter->total_rx_bytes);
2573 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2574 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2575 adapter->rx_itr = low_latency;
2576
2577 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2578
2579 switch (current_itr) {
2580 /* counts and packets in update_itr are dependent on these numbers */
2581 case lowest_latency:
2582 new_itr = 70000;
2583 break;
2584 case low_latency:
2585 new_itr = 20000; /* aka hwitr = ~200 */
2586 break;
2587 case bulk_latency:
2588 new_itr = 4000;
2589 break;
2590 default:
2591 break;
2592 }
2593
2594set_itr_now:
2595 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002596 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002597 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002598 * increasing
2599 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002600 new_itr = new_itr > adapter->itr ?
2601 min(adapter->itr + (new_itr >> 2), new_itr) :
2602 new_itr;
2603 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002604 adapter->rx_ring->itr_val = new_itr;
2605 if (adapter->msix_entries)
2606 adapter->rx_ring->set_itr = 1;
2607 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002608 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002609 }
2610}
2611
2612/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002613 * e1000e_write_itr - write the ITR value to the appropriate registers
2614 * @adapter: address of board private structure
2615 * @itr: new ITR value to program
2616 *
2617 * e1000e_write_itr determines if the adapter is in MSI-X mode
2618 * and, if so, writes the EITR registers with the ITR value.
2619 * Otherwise, it writes the ITR value into the ITR register.
2620 **/
2621void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2622{
2623 struct e1000_hw *hw = &adapter->hw;
2624 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2625
2626 if (adapter->msix_entries) {
2627 int vector;
2628
2629 for (vector = 0; vector < adapter->num_vectors; vector++)
2630 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2631 } else {
2632 ew32(ITR, new_itr);
2633 }
2634}
2635
2636/**
Bruce Allan4662e822008-08-26 18:37:06 -07002637 * e1000_alloc_queues - Allocate memory for all rings
2638 * @adapter: board private structure to initialize
2639 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002640static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002641{
Bruce Allan55aa6982011-12-16 00:45:45 +00002642 int size = sizeof(struct e1000_ring);
2643
2644 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002645 if (!adapter->tx_ring)
2646 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002647 adapter->tx_ring->count = adapter->tx_ring_count;
2648 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002649
Bruce Allan55aa6982011-12-16 00:45:45 +00002650 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002651 if (!adapter->rx_ring)
2652 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002653 adapter->rx_ring->count = adapter->rx_ring_count;
2654 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002655
2656 return 0;
2657err:
2658 e_err("Unable to allocate memory for queues\n");
2659 kfree(adapter->rx_ring);
2660 kfree(adapter->tx_ring);
2661 return -ENOMEM;
2662}
2663
2664/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002665 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002666 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002667 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002668 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002669static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002671 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2672 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002673 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002674 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002675 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002676
Wang Chen4cf16532008-11-12 23:38:14 -08002677 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678
Bruce Allanc58c8a72012-03-20 03:48:19 +00002679 if (!adapter->msix_entries ||
2680 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2681 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002682
Bruce Allanc58c8a72012-03-20 03:48:19 +00002683 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684
Alexander Duyck12d04a32009-03-25 22:05:03 +00002685 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002686 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002687
Bruce Allanc58c8a72012-03-20 03:48:19 +00002688 /* If weight not fully consumed, exit the polling mode */
2689 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690 if (adapter->itr_setting & 3)
2691 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002692 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002693 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2694 if (adapter->msix_entries)
2695 ew32(IMS, adapter->rx_ring->ims_val);
2696 else
2697 e1000_irq_enable(adapter);
2698 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699 }
2700
2701 return work_done;
2702}
2703
Jiri Pirko8e586132011-12-08 19:52:37 -05002704static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705{
2706 struct e1000_adapter *adapter = netdev_priv(netdev);
2707 struct e1000_hw *hw = &adapter->hw;
2708 u32 vfta, index;
2709
2710 /* don't update vlan cookie if already programmed */
2711 if ((adapter->hw.mng_cookie.status &
2712 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2713 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002714 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002715
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002717 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2718 index = (vid >> 5) & 0x7F;
2719 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2720 vfta |= (1 << (vid & 0x1F));
2721 hw->mac.ops.write_vfta(hw, index, vfta);
2722 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002723
2724 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002725
2726 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002727}
2728
Jiri Pirko8e586132011-12-08 19:52:37 -05002729static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730{
2731 struct e1000_adapter *adapter = netdev_priv(netdev);
2732 struct e1000_hw *hw = &adapter->hw;
2733 u32 vfta, index;
2734
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 if ((adapter->hw.mng_cookie.status &
2736 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2737 (vid == adapter->mng_vlan_id)) {
2738 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002739 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002740 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002741 }
2742
2743 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002744 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2745 index = (vid >> 5) & 0x7F;
2746 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2747 vfta &= ~(1 << (vid & 0x1F));
2748 hw->mac.ops.write_vfta(hw, index, vfta);
2749 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002750
2751 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002752
2753 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002754}
2755
2756/**
2757 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2758 * @adapter: board private structure to initialize
2759 **/
2760static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2761{
2762 struct net_device *netdev = adapter->netdev;
2763 struct e1000_hw *hw = &adapter->hw;
2764 u32 rctl;
2765
2766 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2767 /* disable VLAN receive filtering */
2768 rctl = er32(RCTL);
2769 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2770 ew32(RCTL, rctl);
2771
2772 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2773 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2774 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2775 }
2776 }
2777}
2778
2779/**
2780 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2781 * @adapter: board private structure to initialize
2782 **/
2783static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2784{
2785 struct e1000_hw *hw = &adapter->hw;
2786 u32 rctl;
2787
2788 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2789 /* enable VLAN receive filtering */
2790 rctl = er32(RCTL);
2791 rctl |= E1000_RCTL_VFE;
2792 rctl &= ~E1000_RCTL_CFIEN;
2793 ew32(RCTL, rctl);
2794 }
2795}
2796
2797/**
2798 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2799 * @adapter: board private structure to initialize
2800 **/
2801static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2802{
2803 struct e1000_hw *hw = &adapter->hw;
2804 u32 ctrl;
2805
2806 /* disable VLAN tag insert/strip */
2807 ctrl = er32(CTRL);
2808 ctrl &= ~E1000_CTRL_VME;
2809 ew32(CTRL, ctrl);
2810}
2811
2812/**
2813 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2814 * @adapter: board private structure to initialize
2815 **/
2816static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2817{
2818 struct e1000_hw *hw = &adapter->hw;
2819 u32 ctrl;
2820
2821 /* enable VLAN tag insert/strip */
2822 ctrl = er32(CTRL);
2823 ctrl |= E1000_CTRL_VME;
2824 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825}
2826
2827static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2828{
2829 struct net_device *netdev = adapter->netdev;
2830 u16 vid = adapter->hw.mng_cookie.vlan_id;
2831 u16 old_vid = adapter->mng_vlan_id;
2832
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002833 if (adapter->hw.mng_cookie.status &
2834 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2835 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836 adapter->mng_vlan_id = vid;
2837 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002839 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2840 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841}
2842
2843static void e1000_restore_vlan(struct e1000_adapter *adapter)
2844{
2845 u16 vid;
2846
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002847 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002849 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002851}
2852
Bruce Allancd791612010-05-10 14:59:51 +00002853static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002854{
2855 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002856 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002857
2858 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2859 return;
2860
2861 manc = er32(MANC);
2862
Bruce Allane921eb12012-11-28 09:28:37 +00002863 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002864 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002865 * the packets will be handled on SMBUS
2866 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 manc |= E1000_MANC_EN_MNG2HOST;
2868 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002869
2870 switch (hw->mac.type) {
2871 default:
2872 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2873 break;
2874 case e1000_82574:
2875 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002876 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002877 * if so, enable it.
2878 */
2879 for (i = 0, j = 0; i < 8; i++) {
2880 mdef = er32(MDEF(i));
2881
2882 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002883 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002884 continue;
2885
2886 /* Enable this decision filter in MANC2H */
2887 if (mdef)
2888 manc2h |= (1 << i);
2889
2890 j |= mdef;
2891 }
2892
2893 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2894 break;
2895
2896 /* Create new decision filter in an empty filter */
2897 for (i = 0, j = 0; i < 8; i++)
2898 if (er32(MDEF(i)) == 0) {
2899 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2900 E1000_MDEF_PORT_664));
2901 manc2h |= (1 << 1);
2902 j++;
2903 break;
2904 }
2905
2906 if (!j)
2907 e_warn("Unable to create IPMI pass-through filter\n");
2908 break;
2909 }
2910
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 ew32(MANC2H, manc2h);
2912 ew32(MANC, manc);
2913}
2914
2915/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002916 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 * @adapter: board private structure
2918 *
2919 * Configure the Tx unit of the MAC after a reset.
2920 **/
2921static void e1000_configure_tx(struct e1000_adapter *adapter)
2922{
2923 struct e1000_hw *hw = &adapter->hw;
2924 struct e1000_ring *tx_ring = adapter->tx_ring;
2925 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002926 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927
2928 /* Setup the HW Tx Head and Tail descriptor pointers */
2929 tdba = tx_ring->dma;
2930 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002931 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2932 ew32(TDBAH(0), (tdba >> 32));
2933 ew32(TDLEN(0), tdlen);
2934 ew32(TDH(0), 0);
2935 ew32(TDT(0), 0);
2936 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2937 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939 /* Set the Tx Interrupt Delay register */
2940 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002941 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002942 ew32(TADV, adapter->tx_abs_int_delay);
2943
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002944 if (adapter->flags2 & FLAG2_DMA_BURST) {
2945 u32 txdctl = er32(TXDCTL(0));
2946 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2947 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002948 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002949 * hardware to use the bus more efficiently in bursts, depends
2950 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002951 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002952 * hthresh = 1 ==> prefetch when one or more available
2953 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2954 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002955 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002956 */
2957 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2958 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002959 }
Bruce Allan56032be2011-12-16 00:46:01 +00002960 /* erratum work around: set txdctl the same for both queues */
2961 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002962
Auke Kokbc7f75f2007-09-17 12:30:59 -07002963 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002964 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002965 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002966 * gigabit link later
2967 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002968#define SPEED_MODE_BIT (1 << 21)
2969 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002970 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002971 }
2972
2973 /* errata: program both queues to unweighted RR */
2974 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002975 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002976 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002977 ew32(TARC(0), tarc);
2978 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002979 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002980 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002981 }
2982
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983 /* Setup Transmit Descriptor Settings for eop descriptor */
2984 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2985
2986 /* only set IDE if we are delaying interrupts using the timers */
2987 if (adapter->tx_int_delay)
2988 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2989
2990 /* enable Report Status bit */
2991 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2992
Bruce Allan57cde762012-02-22 09:02:58 +00002993 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002994}
2995
2996/**
2997 * e1000_setup_rctl - configure the receive control registers
2998 * @adapter: Board private structure
2999 **/
3000#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
3001 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
3002static void e1000_setup_rctl(struct e1000_adapter *adapter)
3003{
3004 struct e1000_hw *hw = &adapter->hw;
3005 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003006 u32 pages = 0;
3007
Bruce Allan2fbe4522012-04-19 03:21:47 +00003008 /* Workaround Si errata on PCHx - configure jumbo frame flow */
3009 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00003010 s32 ret_val;
3011
3012 if (adapter->netdev->mtu > ETH_DATA_LEN)
3013 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3014 else
3015 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00003016
3017 if (ret_val)
3018 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003019 }
3020
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021 /* Program MC offset vector base */
3022 rctl = er32(RCTL);
3023 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3024 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3025 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3026 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3027
3028 /* Do not Store bad packets */
3029 rctl &= ~E1000_RCTL_SBP;
3030
3031 /* Enable Long Packet receive */
3032 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3033 rctl &= ~E1000_RCTL_LPE;
3034 else
3035 rctl |= E1000_RCTL_LPE;
3036
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003037 /* Some systems expect that the CRC is included in SMBUS traffic. The
3038 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3039 * host memory when this is enabled
3040 */
3041 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3042 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003043
Bruce Allana4f58f52009-06-02 11:29:18 +00003044 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3045 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3046 u16 phy_data;
3047
3048 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3049 phy_data &= 0xfff8;
3050 phy_data |= (1 << 2);
3051 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3052
3053 e1e_rphy(hw, 22, &phy_data);
3054 phy_data &= 0x0fff;
3055 phy_data |= (1 << 14);
3056 e1e_wphy(hw, 0x10, 0x2823);
3057 e1e_wphy(hw, 0x11, 0x0003);
3058 e1e_wphy(hw, 22, phy_data);
3059 }
3060
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 /* Setup buffer sizes */
3062 rctl &= ~E1000_RCTL_SZ_4096;
3063 rctl |= E1000_RCTL_BSEX;
3064 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 case 2048:
3066 default:
3067 rctl |= E1000_RCTL_SZ_2048;
3068 rctl &= ~E1000_RCTL_BSEX;
3069 break;
3070 case 4096:
3071 rctl |= E1000_RCTL_SZ_4096;
3072 break;
3073 case 8192:
3074 rctl |= E1000_RCTL_SZ_8192;
3075 break;
3076 case 16384:
3077 rctl |= E1000_RCTL_SZ_16384;
3078 break;
3079 }
3080
Bruce Allan5f450212011-07-22 06:21:46 +00003081 /* Enable Extended Status in all Receive Descriptors */
3082 rfctl = er32(RFCTL);
3083 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003084 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003085
Bruce Allane921eb12012-11-28 09:28:37 +00003086 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087 * header is placed in skb->data and the packet data is
3088 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3089 * In the case of a non-split, skb->data is linearly filled,
3090 * followed by the page buffers. Therefore, skb->data is
3091 * sized to hold the largest protocol header.
3092 *
3093 * allocations using alloc_page take too long for regular MTU
3094 * so only enable packet split for jumbo frames
3095 *
3096 * Using pages when the page size is greater than 16k wastes
3097 * a lot of memory, since we allocate 3 pages at all times
3098 * per packet.
3099 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003101 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003102 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003103 else
3104 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105
3106 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003107 u32 psrctl = 0;
3108
Auke Kok140a7482007-10-25 13:57:58 -07003109 /* Enable Packet split descriptors */
3110 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003111
3112 psrctl |= adapter->rx_ps_bsize0 >>
3113 E1000_PSRCTL_BSIZE0_SHIFT;
3114
3115 switch (adapter->rx_ps_pages) {
3116 case 3:
3117 psrctl |= PAGE_SIZE <<
3118 E1000_PSRCTL_BSIZE3_SHIFT;
3119 case 2:
3120 psrctl |= PAGE_SIZE <<
3121 E1000_PSRCTL_BSIZE2_SHIFT;
3122 case 1:
3123 psrctl |= PAGE_SIZE >>
3124 E1000_PSRCTL_BSIZE1_SHIFT;
3125 break;
3126 }
3127
3128 ew32(PSRCTL, psrctl);
3129 }
3130
Ben Greearcf955e62012-02-11 15:39:51 +00003131 /* This is useful for sniffing bad packets. */
3132 if (adapter->netdev->features & NETIF_F_RXALL) {
3133 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003134 * in e1000e_set_rx_mode
3135 */
Ben Greearcf955e62012-02-11 15:39:51 +00003136 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3137 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3138 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3139
3140 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3141 E1000_RCTL_DPF | /* Allow filtered pause */
3142 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3143 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3144 * and that breaks VLANs.
3145 */
3146 }
3147
Auke Kokbc7f75f2007-09-17 12:30:59 -07003148 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003149 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003150 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151}
3152
3153/**
3154 * e1000_configure_rx - Configure Receive Unit after Reset
3155 * @adapter: board private structure
3156 *
3157 * Configure the Rx unit of the MAC after a reset.
3158 **/
3159static void e1000_configure_rx(struct e1000_adapter *adapter)
3160{
3161 struct e1000_hw *hw = &adapter->hw;
3162 struct e1000_ring *rx_ring = adapter->rx_ring;
3163 u64 rdba;
3164 u32 rdlen, rctl, rxcsum, ctrl_ext;
3165
3166 if (adapter->rx_ps_pages) {
3167 /* this is a 32 byte descriptor */
3168 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003169 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003170 adapter->clean_rx = e1000_clean_rx_irq_ps;
3171 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003172 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003173 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003174 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3175 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003176 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003177 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178 adapter->clean_rx = e1000_clean_rx_irq;
3179 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3180 }
3181
3182 /* disable receives while setting up the descriptors */
3183 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003184 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3185 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003186 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003187 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003189 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003190 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003191 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003192 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003193 * granularity = 01
3194 * wthresh = 04,
3195 * hthresh = 04,
3196 * pthresh = 0x20
3197 */
3198 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3199 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3200
Bruce Allane921eb12012-11-28 09:28:37 +00003201 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003202 * the value was not set by the user via module options
3203 */
3204 if (adapter->rx_int_delay == DEFAULT_RDTR)
3205 adapter->rx_int_delay = BURST_RDTR;
3206 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3207 adapter->rx_abs_int_delay = BURST_RADV;
3208 }
3209
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 /* set the Receive Delay Timer Register */
3211 ew32(RDTR, adapter->rx_int_delay);
3212
3213 /* irq moderation */
3214 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003215 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003216 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003217
3218 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003219 /* Auto-Mask interrupts upon ICR access */
3220 ctrl_ext |= E1000_CTRL_EXT_IAME;
3221 ew32(IAM, 0xffffffff);
3222 ew32(CTRL_EXT, ctrl_ext);
3223 e1e_flush();
3224
Bruce Allane921eb12012-11-28 09:28:37 +00003225 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003226 * the Base and Length of the Rx Descriptor Ring
3227 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003229 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3230 ew32(RDBAH(0), (rdba >> 32));
3231 ew32(RDLEN(0), rdlen);
3232 ew32(RDH(0), 0);
3233 ew32(RDT(0), 0);
3234 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3235 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236
3237 /* Enable Receive Checksum Offload for TCP and UDP */
3238 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003239 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003240 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003241 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003242 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 ew32(RXCSUM, rxcsum);
3244
Bruce Allan3e35d992013-01-12 07:25:22 +00003245 /* With jumbo frames, excessive C-state transition latencies result
3246 * in dropped transactions.
3247 */
3248 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3249 u32 lat =
3250 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3251 adapter->max_frame_size) * 8 / 1000;
3252
3253 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003254 u32 rxdctl = er32(RXDCTL(0));
3255 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003256 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003257
3258 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3259 } else {
3260 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3261 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003262 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263
3264 /* Enable Receives */
3265 ew32(RCTL, rctl);
3266}
3267
3268/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003269 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270 * @netdev: network interface device structure
3271 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003272 * Writes multicast address list to the MTA hash table.
3273 * Returns: -ENOMEM on failure
3274 * 0 on no addresses written
3275 * X on writing X addresses to MTA
3276 */
3277static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278{
3279 struct e1000_adapter *adapter = netdev_priv(netdev);
3280 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003281 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003282 u8 *mta_list;
3283 int i;
3284
3285 if (netdev_mc_empty(netdev)) {
3286 /* nothing to program, so clear mc list */
3287 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3288 return 0;
3289 }
3290
3291 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3292 if (!mta_list)
3293 return -ENOMEM;
3294
3295 /* update_mc_addr_list expects a packed array of only addresses. */
3296 i = 0;
3297 netdev_for_each_mc_addr(ha, netdev)
3298 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3299
3300 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3301 kfree(mta_list);
3302
3303 return netdev_mc_count(netdev);
3304}
3305
3306/**
3307 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3308 * @netdev: network interface device structure
3309 *
3310 * Writes unicast address list to the RAR table.
3311 * Returns: -ENOMEM on failure/insufficient address space
3312 * 0 on no addresses written
3313 * X on writing X addresses to the RAR table
3314 **/
3315static int e1000e_write_uc_addr_list(struct net_device *netdev)
3316{
3317 struct e1000_adapter *adapter = netdev_priv(netdev);
3318 struct e1000_hw *hw = &adapter->hw;
3319 unsigned int rar_entries = hw->mac.rar_entry_count;
3320 int count = 0;
3321
3322 /* save a rar entry for our hardware address */
3323 rar_entries--;
3324
3325 /* save a rar entry for the LAA workaround */
3326 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3327 rar_entries--;
3328
3329 /* return ENOMEM indicating insufficient memory for addresses */
3330 if (netdev_uc_count(netdev) > rar_entries)
3331 return -ENOMEM;
3332
3333 if (!netdev_uc_empty(netdev) && rar_entries) {
3334 struct netdev_hw_addr *ha;
3335
Bruce Allane921eb12012-11-28 09:28:37 +00003336 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003337 * combining
3338 */
3339 netdev_for_each_uc_addr(ha, netdev) {
3340 if (!rar_entries)
3341 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003342 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003343 count++;
3344 }
3345 }
3346
3347 /* zero out the remaining RAR entries not used above */
3348 for (; rar_entries > 0; rar_entries--) {
3349 ew32(RAH(rar_entries), 0);
3350 ew32(RAL(rar_entries), 0);
3351 }
3352 e1e_flush();
3353
3354 return count;
3355}
3356
3357/**
3358 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3359 * @netdev: network interface device structure
3360 *
3361 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3362 * address list or the network interface flags are updated. This routine is
3363 * responsible for configuring the hardware for proper unicast, multicast,
3364 * promiscuous mode, and all-multi behavior.
3365 **/
3366static void e1000e_set_rx_mode(struct net_device *netdev)
3367{
3368 struct e1000_adapter *adapter = netdev_priv(netdev);
3369 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003370 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371
3372 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373 rctl = er32(RCTL);
3374
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003375 /* clear the affected bits */
3376 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3377
Auke Kokbc7f75f2007-09-17 12:30:59 -07003378 if (netdev->flags & IFF_PROMISC) {
3379 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003380 /* Do not hardware filter VLANs in promisc mode */
3381 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003383 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003384
Patrick McHardy746b9f02008-07-16 20:15:45 -07003385 if (netdev->flags & IFF_ALLMULTI) {
3386 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003387 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003388 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003389 * then we should just turn on promiscuous mode so
3390 * that we can at least receive multicast traffic
3391 */
3392 count = e1000e_write_mc_addr_list(netdev);
3393 if (count < 0)
3394 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003395 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003396 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003397 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003398 * sufficient space to store all the addresses then enable
3399 * unicast promiscuous mode
3400 */
3401 count = e1000e_write_uc_addr_list(netdev);
3402 if (count < 0)
3403 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003404 }
3405
3406 ew32(RCTL, rctl);
3407
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003408 if (netdev->features & NETIF_F_HW_VLAN_RX)
3409 e1000e_vlan_strip_enable(adapter);
3410 else
3411 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003412}
3413
Bruce Allan70495a52012-01-11 01:26:50 +00003414static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3415{
3416 struct e1000_hw *hw = &adapter->hw;
3417 u32 mrqc, rxcsum;
3418 int i;
3419 static const u32 rsskey[10] = {
3420 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3421 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3422 };
3423
3424 /* Fill out hash function seed */
3425 for (i = 0; i < 10; i++)
3426 ew32(RSSRK(i), rsskey[i]);
3427
3428 /* Direct all traffic to queue 0 */
3429 for (i = 0; i < 32; i++)
3430 ew32(RETA(i), 0);
3431
Bruce Allane921eb12012-11-28 09:28:37 +00003432 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003433 * descriptor on writeback.
3434 */
3435 rxcsum = er32(RXCSUM);
3436 rxcsum |= E1000_RXCSUM_PCSD;
3437
3438 ew32(RXCSUM, rxcsum);
3439
3440 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3441 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3442 E1000_MRQC_RSS_FIELD_IPV6 |
3443 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3444 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3445
3446 ew32(MRQC, mrqc);
3447}
3448
Auke Kokbc7f75f2007-09-17 12:30:59 -07003449/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003450 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3451 * @adapter: board private structure
3452 * @timinca: pointer to returned time increment attributes
3453 *
3454 * Get attributes for incrementing the System Time Register SYSTIML/H at
3455 * the default base frequency, and set the cyclecounter shift value.
3456 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003457s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003458{
3459 struct e1000_hw *hw = &adapter->hw;
3460 u32 incvalue, incperiod, shift;
3461
3462 /* Make sure clock is enabled on I217 before checking the frequency */
3463 if ((hw->mac.type == e1000_pch_lpt) &&
3464 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3465 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3466 u32 fextnvm7 = er32(FEXTNVM7);
3467
3468 if (!(fextnvm7 & (1 << 0))) {
3469 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3470 e1e_flush();
3471 }
3472 }
3473
3474 switch (hw->mac.type) {
3475 case e1000_pch2lan:
3476 case e1000_pch_lpt:
3477 /* On I217, the clock frequency is 25MHz or 96MHz as
3478 * indicated by the System Clock Frequency Indication
3479 */
3480 if ((hw->mac.type != e1000_pch_lpt) ||
3481 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3482 /* Stable 96MHz frequency */
3483 incperiod = INCPERIOD_96MHz;
3484 incvalue = INCVALUE_96MHz;
3485 shift = INCVALUE_SHIFT_96MHz;
3486 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3487 break;
3488 }
3489 /* fall-through */
3490 case e1000_82574:
3491 case e1000_82583:
3492 /* Stable 25MHz frequency */
3493 incperiod = INCPERIOD_25MHz;
3494 incvalue = INCVALUE_25MHz;
3495 shift = INCVALUE_SHIFT_25MHz;
3496 adapter->cc.shift = shift;
3497 break;
3498 default:
3499 return -EINVAL;
3500 }
3501
3502 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3503 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3504
3505 return 0;
3506}
3507
3508/**
3509 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3510 * @adapter: board private structure
3511 *
3512 * Outgoing time stamping can be enabled and disabled. Play nice and
3513 * disable it when requested, although it shouldn't cause any overhead
3514 * when no packet needs it. At most one packet in the queue may be
3515 * marked for time stamping, otherwise it would be impossible to tell
3516 * for sure to which packet the hardware time stamp belongs.
3517 *
3518 * Incoming time stamping has to be configured via the hardware filters.
3519 * Not all combinations are supported, in particular event type has to be
3520 * specified. Matching the kind of event packet is not supported, with the
3521 * exception of "all V2 events regardless of level 2 or 4".
3522 **/
3523static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3524{
3525 struct e1000_hw *hw = &adapter->hw;
3526 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3527 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3528 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003529 u32 rxmtrl = 0;
3530 u16 rxudp = 0;
3531 bool is_l4 = false;
3532 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003533 u32 regval;
3534 s32 ret_val;
3535
3536 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3537 return -EINVAL;
3538
3539 /* flags reserved for future extensions - must be zero */
3540 if (config->flags)
3541 return -EINVAL;
3542
3543 switch (config->tx_type) {
3544 case HWTSTAMP_TX_OFF:
3545 tsync_tx_ctl = 0;
3546 break;
3547 case HWTSTAMP_TX_ON:
3548 break;
3549 default:
3550 return -ERANGE;
3551 }
3552
3553 switch (config->rx_filter) {
3554 case HWTSTAMP_FILTER_NONE:
3555 tsync_rx_ctl = 0;
3556 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003557 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3558 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3559 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3560 is_l4 = true;
3561 break;
3562 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3563 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3564 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3565 is_l4 = true;
3566 break;
3567 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3568 /* Also time stamps V2 L2 Path Delay Request/Response */
3569 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3570 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3571 is_l2 = true;
3572 break;
3573 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3574 /* Also time stamps V2 L2 Path Delay Request/Response. */
3575 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3576 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3577 is_l2 = true;
3578 break;
3579 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3580 /* Hardware cannot filter just V2 L4 Sync messages;
3581 * fall-through to V2 (both L2 and L4) Sync.
3582 */
3583 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3584 /* Also time stamps V2 Path Delay Request/Response. */
3585 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3586 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3587 is_l2 = true;
3588 is_l4 = true;
3589 break;
3590 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3591 /* Hardware cannot filter just V2 L4 Delay Request messages;
3592 * fall-through to V2 (both L2 and L4) Delay Request.
3593 */
3594 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3595 /* Also time stamps V2 Path Delay Request/Response. */
3596 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3597 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3598 is_l2 = true;
3599 is_l4 = true;
3600 break;
3601 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3602 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3603 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3604 * fall-through to all V2 (both L2 and L4) Events.
3605 */
3606 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3607 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3608 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3609 is_l2 = true;
3610 is_l4 = true;
3611 break;
3612 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3613 /* For V1, the hardware can only filter Sync messages or
3614 * Delay Request messages but not both so fall-through to
3615 * time stamp all packets.
3616 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003617 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003618 is_l2 = true;
3619 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003620 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3621 config->rx_filter = HWTSTAMP_FILTER_ALL;
3622 break;
3623 default:
3624 return -ERANGE;
3625 }
3626
3627 /* enable/disable Tx h/w time stamping */
3628 regval = er32(TSYNCTXCTL);
3629 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3630 regval |= tsync_tx_ctl;
3631 ew32(TSYNCTXCTL, regval);
3632 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3633 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3634 e_err("Timesync Tx Control register not set as expected\n");
3635 return -EAGAIN;
3636 }
3637
3638 /* enable/disable Rx h/w time stamping */
3639 regval = er32(TSYNCRXCTL);
3640 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3641 regval |= tsync_rx_ctl;
3642 ew32(TSYNCRXCTL, regval);
3643 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3644 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3645 (regval & (E1000_TSYNCRXCTL_ENABLED |
3646 E1000_TSYNCRXCTL_TYPE_MASK))) {
3647 e_err("Timesync Rx Control register not set as expected\n");
3648 return -EAGAIN;
3649 }
3650
Bruce Alland89777b2013-01-19 01:09:58 +00003651 /* L2: define ethertype filter for time stamped packets */
3652 if (is_l2)
3653 rxmtrl |= ETH_P_1588;
3654
3655 /* define which PTP packets get time stamped */
3656 ew32(RXMTRL, rxmtrl);
3657
3658 /* Filter by destination port */
3659 if (is_l4) {
3660 rxudp = PTP_EV_PORT;
3661 cpu_to_be16s(&rxudp);
3662 }
3663 ew32(RXUDP, rxudp);
3664
3665 e1e_flush();
3666
Bruce Allanb67e1912012-12-27 08:32:33 +00003667 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003668 er32(RXSTMPH);
3669 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003670
3671 /* Get and set the System Time Register SYSTIM base frequency */
3672 ret_val = e1000e_get_base_timinca(adapter, &regval);
3673 if (ret_val)
3674 return ret_val;
3675 ew32(TIMINCA, regval);
3676
3677 /* reset the ns time counter */
3678 timecounter_init(&adapter->tc, &adapter->cc,
3679 ktime_to_ns(ktime_get_real()));
3680
3681 return 0;
3682}
3683
3684/**
Bruce Allanad680762008-03-28 09:15:03 -07003685 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 * @adapter: private board structure
3687 **/
3688static void e1000_configure(struct e1000_adapter *adapter)
3689{
Bruce Allan55aa6982011-12-16 00:45:45 +00003690 struct e1000_ring *rx_ring = adapter->rx_ring;
3691
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003692 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693
3694 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003695 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696
3697 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003698
3699 if (adapter->netdev->features & NETIF_F_RXHASH)
3700 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701 e1000_setup_rctl(adapter);
3702 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003703 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003704}
3705
3706/**
3707 * e1000e_power_up_phy - restore link in case the phy was powered down
3708 * @adapter: address of board private structure
3709 *
3710 * The phy may be powered down to save power and turn off link when the
3711 * driver is unloaded and wake on lan is not enabled (among others)
3712 * *** this routine MUST be followed by a call to e1000e_reset ***
3713 **/
3714void e1000e_power_up_phy(struct e1000_adapter *adapter)
3715{
Bruce Allan17f208d2009-12-01 15:47:22 +00003716 if (adapter->hw.phy.ops.power_up)
3717 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003718
3719 adapter->hw.mac.ops.setup_link(&adapter->hw);
3720}
3721
3722/**
3723 * e1000_power_down_phy - Power down the PHY
3724 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003725 * Power down the PHY so no link is implied when interface is down.
3726 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727 */
3728static void e1000_power_down_phy(struct e1000_adapter *adapter)
3729{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003731 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003732 return;
3733
Bruce Allan17f208d2009-12-01 15:47:22 +00003734 if (adapter->hw.phy.ops.power_down)
3735 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736}
3737
3738/**
3739 * e1000e_reset - bring the hardware into a known good state
3740 *
3741 * This function boots the hardware and enables some settings that
3742 * require a configuration cycle of the hardware - those cannot be
3743 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003744 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003745 */
3746void e1000e_reset(struct e1000_adapter *adapter)
3747{
3748 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003749 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750 struct e1000_hw *hw = &adapter->hw;
3751 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003752 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753 u16 hwm;
3754
Bruce Allanad680762008-03-28 09:15:03 -07003755 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003756 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003757
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003758 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003759 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760 * large enough to accommodate two full transmit packets,
3761 * rounded up to the next 1KB and expressed in KB. Likewise,
3762 * the Rx FIFO should be large enough to accommodate at least
3763 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003764 * expressed in KB.
3765 */
Auke Kokdf762462007-10-25 13:57:53 -07003766 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003768 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003770 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003771 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003772 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003773 */
3774 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775 sizeof(struct e1000_tx_desc) -
3776 ETH_FCS_LEN) * 2;
3777 min_tx_space = ALIGN(min_tx_space, 1024);
3778 min_tx_space >>= 10;
3779 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003780 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781 min_rx_space = ALIGN(min_rx_space, 1024);
3782 min_rx_space >>= 10;
3783
Bruce Allane921eb12012-11-28 09:28:37 +00003784 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003786 * allocation, take space away from current Rx allocation
3787 */
Auke Kokdf762462007-10-25 13:57:53 -07003788 if ((tx_space < min_tx_space) &&
3789 ((min_tx_space - tx_space) < pba)) {
3790 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791
Bruce Allane921eb12012-11-28 09:28:37 +00003792 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003793 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003794 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003795 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003796 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003797 }
Auke Kokdf762462007-10-25 13:57:53 -07003798
3799 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003800 }
3801
Bruce Allane921eb12012-11-28 09:28:37 +00003802 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003803 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003804 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003805 * (or the size used for early receive) above it in the Rx FIFO.
3806 * Set it to the lower of:
3807 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003808 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003809 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003810 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3811 fc->pause_time = 0xFFFF;
3812 else
3813 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003814 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003815 fc->current_mode = fc->requested_mode;
3816
3817 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003818 case e1000_ich9lan:
3819 case e1000_ich10lan:
3820 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3821 pba = 14;
3822 ew32(PBA, pba);
3823 fc->high_water = 0x2800;
3824 fc->low_water = fc->high_water - 8;
3825 break;
3826 }
3827 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003828 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003829 hwm = min(((pba << 10) * 9 / 10),
3830 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003831
3832 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3833 fc->low_water = fc->high_water - 8;
3834 break;
3835 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003836 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003837 * loads. If hangs persist, try disabling Tx flow control.
3838 */
3839 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3840 fc->high_water = 0x3500;
3841 fc->low_water = 0x1500;
3842 } else {
3843 fc->high_water = 0x5000;
3844 fc->low_water = 0x3000;
3845 }
Bruce Allana3055952010-05-10 15:02:12 +00003846 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003847 break;
3848 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003849 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003850 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003851
3852 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3853 fc->high_water = 0x05C20;
3854 fc->low_water = 0x05048;
3855 fc->pause_time = 0x0650;
3856 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003857 }
Bruce Allan347b5202012-12-08 00:35:35 +00003858
3859 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3860 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003861 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003862 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003863
Bruce Allane921eb12012-11-28 09:28:37 +00003864 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003865 * maximum size per Tx descriptor limited only to the transmit
3866 * allocation of the packet buffer minus 96 bytes with an upper
3867 * limit of 24KB due to receive synchronization limitations.
3868 */
3869 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3870 24 << 10);
3871
Bruce Allane921eb12012-11-28 09:28:37 +00003872 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003873 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003874 */
3875 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003876 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003877 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3878 dev_info(&adapter->pdev->dev,
3879 "Interrupt Throttle Rate turned off\n");
3880 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003881 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003882 }
3883 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3884 dev_info(&adapter->pdev->dev,
3885 "Interrupt Throttle Rate turned on\n");
3886 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3887 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003888 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003889 }
3890 }
3891
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 /* Allow time for pending master requests to run */
3893 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003894
Bruce Allane921eb12012-11-28 09:28:37 +00003895 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003896 * that the network interface is in control
3897 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003898 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003899 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003900
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901 ew32(WUC, 0);
3902
3903 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003904 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003905
3906 e1000_update_mng_vlan(adapter);
3907
3908 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3909 ew32(VET, ETH_P_8021Q);
3910
3911 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003912
Bruce Allanb67e1912012-12-27 08:32:33 +00003913 /* initialize systim and reset the ns time counter */
3914 e1000e_config_hwtstamp(adapter);
3915
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003916 if (!netif_running(adapter->netdev) &&
3917 !test_bit(__E1000_TESTING, &adapter->state)) {
3918 e1000_power_down_phy(adapter);
3919 return;
3920 }
3921
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 e1000_get_phy_info(hw);
3923
Bruce Allan918d7192009-06-02 11:28:20 +00003924 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3925 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003926 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003927 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003928 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003929 * different we would do if it failed
3930 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3932 phy_data &= ~IGP02E1000_PM_SPD;
3933 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3934 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935}
3936
3937int e1000e_up(struct e1000_adapter *adapter)
3938{
3939 struct e1000_hw *hw = &adapter->hw;
3940
3941 /* hardware has been reset, we need to reload some things */
3942 e1000_configure(adapter);
3943
3944 clear_bit(__E1000_DOWN, &adapter->state);
3945
Bruce Allan4662e822008-08-26 18:37:06 -07003946 if (adapter->msix_entries)
3947 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003948 e1000_irq_enable(adapter);
3949
Bruce Allan400484f2011-05-13 07:20:03 +00003950 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003951
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003953 if (adapter->msix_entries)
3954 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3955 else
3956 ew32(ICS, E1000_ICS_LSC);
3957
Auke Kokbc7f75f2007-09-17 12:30:59 -07003958 return 0;
3959}
3960
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003961static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3962{
3963 struct e1000_hw *hw = &adapter->hw;
3964
3965 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3966 return;
3967
3968 /* flush pending descriptor writebacks to memory */
3969 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3970 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3971
3972 /* execute the writes immediately */
3973 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003974
Bruce Allane921eb12012-11-28 09:28:37 +00003975 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003976 * write is successful
3977 */
3978 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3979 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3980
3981 /* execute the writes immediately */
3982 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003983}
3984
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003985static void e1000e_update_stats(struct e1000_adapter *adapter);
3986
Auke Kokbc7f75f2007-09-17 12:30:59 -07003987void e1000e_down(struct e1000_adapter *adapter)
3988{
3989 struct net_device *netdev = adapter->netdev;
3990 struct e1000_hw *hw = &adapter->hw;
3991 u32 tctl, rctl;
3992
Bruce Allane921eb12012-11-28 09:28:37 +00003993 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003994 * reschedule our watchdog timer
3995 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 set_bit(__E1000_DOWN, &adapter->state);
3997
3998 /* disable receives in the hardware */
3999 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07004000 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
4001 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004002 /* flush and sleep below */
4003
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004004 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005
4006 /* disable transmits in the hardware */
4007 tctl = er32(TCTL);
4008 tctl &= ~E1000_TCTL_EN;
4009 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004010
Auke Kokbc7f75f2007-09-17 12:30:59 -07004011 /* flush both disables and wait for them to finish */
4012 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004013 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015 e1000_irq_disable(adapter);
4016
4017 del_timer_sync(&adapter->watchdog_timer);
4018 del_timer_sync(&adapter->phy_info_timer);
4019
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004021
4022 spin_lock(&adapter->stats64_lock);
4023 e1000e_update_stats(adapter);
4024 spin_unlock(&adapter->stats64_lock);
4025
Bruce Allan400484f2011-05-13 07:20:03 +00004026 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004027 e1000_clean_tx_ring(adapter->tx_ring);
4028 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004029
Auke Kokbc7f75f2007-09-17 12:30:59 -07004030 adapter->link_speed = 0;
4031 adapter->link_duplex = 0;
4032
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004033 if (!pci_channel_offline(adapter->pdev))
4034 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004035
Bruce Allane921eb12012-11-28 09:28:37 +00004036 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004037 * pci_disable_device here.
4038 */
4039}
4040
4041void e1000e_reinit_locked(struct e1000_adapter *adapter)
4042{
4043 might_sleep();
4044 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004045 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004046 e1000e_down(adapter);
4047 e1000e_up(adapter);
4048 clear_bit(__E1000_RESETTING, &adapter->state);
4049}
4050
4051/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004052 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4053 * @cc: cyclecounter structure
4054 **/
4055static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4056{
4057 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4058 cc);
4059 struct e1000_hw *hw = &adapter->hw;
4060 cycle_t systim;
4061
4062 /* latch SYSTIMH on read of SYSTIML */
4063 systim = (cycle_t)er32(SYSTIML);
4064 systim |= (cycle_t)er32(SYSTIMH) << 32;
4065
4066 return systim;
4067}
4068
4069/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4071 * @adapter: board private structure to initialize
4072 *
4073 * e1000_sw_init initializes the Adapter private data structure.
4074 * Fields are initialized based on PCI device information and
4075 * OS network device settings (MTU size).
4076 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004077static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004079 struct net_device *netdev = adapter->netdev;
4080
4081 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4082 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004083 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4084 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004085 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4086 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004088 spin_lock_init(&adapter->stats64_lock);
4089
Bruce Allan4662e822008-08-26 18:37:06 -07004090 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004091
Bruce Allan4662e822008-08-26 18:37:06 -07004092 if (e1000_alloc_queues(adapter))
4093 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004094
Bruce Allanb67e1912012-12-27 08:32:33 +00004095 /* Setup hardware time stamping cyclecounter */
4096 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4097 adapter->cc.read = e1000e_cyclecounter_read;
4098 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4099 adapter->cc.mult = 1;
4100 /* cc.shift set in e1000e_get_base_tininca() */
4101
4102 spin_lock_init(&adapter->systim_lock);
4103 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4104 }
4105
Auke Kokbc7f75f2007-09-17 12:30:59 -07004106 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004107 e1000_irq_disable(adapter);
4108
Auke Kokbc7f75f2007-09-17 12:30:59 -07004109 set_bit(__E1000_DOWN, &adapter->state);
4110 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004111}
4112
4113/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004114 * e1000_intr_msi_test - Interrupt Handler
4115 * @irq: interrupt number
4116 * @data: pointer to a network interface device structure
4117 **/
4118static irqreturn_t e1000_intr_msi_test(int irq, void *data)
4119{
4120 struct net_device *netdev = data;
4121 struct e1000_adapter *adapter = netdev_priv(netdev);
4122 struct e1000_hw *hw = &adapter->hw;
4123 u32 icr = er32(ICR);
4124
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004125 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004126 if (icr & E1000_ICR_RXSEQ) {
4127 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004128 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004129 * interrupt is handled.
4130 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004131 wmb();
4132 }
4133
4134 return IRQ_HANDLED;
4135}
4136
4137/**
4138 * e1000_test_msi_interrupt - Returns 0 for successful test
4139 * @adapter: board private struct
4140 *
4141 * code flow taken from tg3.c
4142 **/
4143static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4144{
4145 struct net_device *netdev = adapter->netdev;
4146 struct e1000_hw *hw = &adapter->hw;
4147 int err;
4148
4149 /* poll_enable hasn't been called yet, so don't need disable */
4150 /* clear any pending events */
4151 er32(ICR);
4152
4153 /* free the real vector and request a test handler */
4154 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004155 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004156
4157 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004158 * MSI irq handler will unset this flag
4159 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004160 adapter->flags |= FLAG_MSI_TEST_FAILED;
4161
4162 err = pci_enable_msi(adapter->pdev);
4163 if (err)
4164 goto msi_test_failed;
4165
Joe Perchesa0607fd2009-11-18 23:29:17 -08004166 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004167 netdev->name, netdev);
4168 if (err) {
4169 pci_disable_msi(adapter->pdev);
4170 goto msi_test_failed;
4171 }
4172
Bruce Allane921eb12012-11-28 09:28:37 +00004173 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004174 * interrupt.
4175 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004176 wmb();
4177
4178 e1000_irq_enable(adapter);
4179
4180 /* fire an unusual interrupt on the test handler */
4181 ew32(ICS, E1000_ICS_RXSEQ);
4182 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004183 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004184
4185 e1000_irq_disable(adapter);
4186
Bruce Allanbc763292012-08-17 06:18:07 +00004187 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004188
4189 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004190 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004191 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004192 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004193 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004194 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004195
4196 free_irq(adapter->pdev->irq, netdev);
4197 pci_disable_msi(adapter->pdev);
4198
Bruce Allanf8d59f72008-08-08 18:36:11 -07004199msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004200 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004201 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004202}
4203
4204/**
4205 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4206 * @adapter: board private struct
4207 *
4208 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4209 **/
4210static int e1000_test_msi(struct e1000_adapter *adapter)
4211{
4212 int err;
4213 u16 pci_cmd;
4214
4215 if (!(adapter->flags & FLAG_MSI_ENABLED))
4216 return 0;
4217
4218 /* disable SERR in case the MSI write causes a master abort */
4219 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004220 if (pci_cmd & PCI_COMMAND_SERR)
4221 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4222 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004223
4224 err = e1000_test_msi_interrupt(adapter);
4225
Dean Nelson36f24072010-06-29 18:12:05 +00004226 /* re-enable SERR */
4227 if (pci_cmd & PCI_COMMAND_SERR) {
4228 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4229 pci_cmd |= PCI_COMMAND_SERR;
4230 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4231 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004232
Bruce Allanf8d59f72008-08-08 18:36:11 -07004233 return err;
4234}
4235
4236/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004237 * e1000_open - Called when a network interface is made active
4238 * @netdev: network interface device structure
4239 *
4240 * Returns 0 on success, negative value on failure
4241 *
4242 * The open entry point is called when a network interface is made
4243 * active by the system (IFF_UP). At this point all resources needed
4244 * for transmit and receive operations are allocated, the interrupt
4245 * handler is registered with the OS, the watchdog timer is started,
4246 * and the stack is notified that the interface is ready.
4247 **/
4248static int e1000_open(struct net_device *netdev)
4249{
4250 struct e1000_adapter *adapter = netdev_priv(netdev);
4251 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004252 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004253 int err;
4254
4255 /* disallow open during test */
4256 if (test_bit(__E1000_TESTING, &adapter->state))
4257 return -EBUSY;
4258
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004259 pm_runtime_get_sync(&pdev->dev);
4260
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004261 netif_carrier_off(netdev);
4262
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004264 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004265 if (err)
4266 goto err_setup_tx;
4267
4268 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004269 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004270 if (err)
4271 goto err_setup_rx;
4272
Bruce Allane921eb12012-11-28 09:28:37 +00004273 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004274 * interface is now open and reset the part to a known state.
4275 */
4276 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004277 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004278 e1000e_reset(adapter);
4279 }
4280
Auke Kokbc7f75f2007-09-17 12:30:59 -07004281 e1000e_power_up_phy(adapter);
4282
4283 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4284 if ((adapter->hw.mng_cookie.status &
4285 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4286 e1000_update_mng_vlan(adapter);
4287
Bruce Allan79d4e902011-12-16 00:46:27 +00004288 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004289 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4290 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004291
Bruce Allane921eb12012-11-28 09:28:37 +00004292 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004293 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4294 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004295 * clean_rx handler before we do so.
4296 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004297 e1000_configure(adapter);
4298
4299 err = e1000_request_irq(adapter);
4300 if (err)
4301 goto err_req_irq;
4302
Bruce Allane921eb12012-11-28 09:28:37 +00004303 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004304 * ignore e1000e MSI messages, which means we need to test our MSI
4305 * interrupt now
4306 */
Bruce Allan4662e822008-08-26 18:37:06 -07004307 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004308 err = e1000_test_msi(adapter);
4309 if (err) {
4310 e_err("Interrupt allocation failed\n");
4311 goto err_req_irq;
4312 }
4313 }
4314
Auke Kokbc7f75f2007-09-17 12:30:59 -07004315 /* From here on the code is the same as e1000e_up() */
4316 clear_bit(__E1000_DOWN, &adapter->state);
4317
4318 napi_enable(&adapter->napi);
4319
4320 e1000_irq_enable(adapter);
4321
Jeff Kirsher09357b02011-11-18 14:25:00 +00004322 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004323 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004324
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004325 adapter->idle_check = true;
4326 pm_runtime_put(&pdev->dev);
4327
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004329 if (adapter->msix_entries)
4330 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4331 else
4332 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004333
4334 return 0;
4335
4336err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004337 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004339 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004340err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004341 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004342err_setup_tx:
4343 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004344 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004345
4346 return err;
4347}
4348
4349/**
4350 * e1000_close - Disables a network interface
4351 * @netdev: network interface device structure
4352 *
4353 * Returns 0, this is not allowed to fail
4354 *
4355 * The close entry point is called when an interface is de-activated
4356 * by the OS. The hardware is still under the drivers control, but
4357 * needs to be disabled. A global MAC reset is issued to stop the
4358 * hardware, and all transmit and receive resources are freed.
4359 **/
4360static int e1000_close(struct net_device *netdev)
4361{
4362 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004363 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004364 int count = E1000_CHECK_RESET_COUNT;
4365
4366 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4367 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004368
4369 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004370
4371 pm_runtime_get_sync(&pdev->dev);
4372
Bruce Allan5f4a7802011-11-29 08:09:19 +00004373 napi_disable(&adapter->napi);
4374
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004375 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4376 e1000e_down(adapter);
4377 e1000_free_irq(adapter);
4378 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004379 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004380
Bruce Allan55aa6982011-12-16 00:45:45 +00004381 e1000e_free_tx_resources(adapter->tx_ring);
4382 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383
Bruce Allane921eb12012-11-28 09:28:37 +00004384 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004385 * the same ID is registered on the host OS (let 8021q kill it)
4386 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004387 if (adapter->hw.mng_cookie.status &
4388 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004389 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4390
Bruce Allane921eb12012-11-28 09:28:37 +00004391 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004392 * interface is now closed
4393 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004394 if ((adapter->flags & FLAG_HAS_AMT) &&
4395 !test_bit(__E1000_TESTING, &adapter->state))
4396 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397
Bruce Allan3e35d992013-01-12 07:25:22 +00004398 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004399
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004400 pm_runtime_put_sync(&pdev->dev);
4401
Auke Kokbc7f75f2007-09-17 12:30:59 -07004402 return 0;
4403}
4404/**
4405 * e1000_set_mac - Change the Ethernet Address of the NIC
4406 * @netdev: network interface device structure
4407 * @p: pointer to an address structure
4408 *
4409 * Returns 0 on success, negative on failure
4410 **/
4411static int e1000_set_mac(struct net_device *netdev, void *p)
4412{
4413 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004414 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004415 struct sockaddr *addr = p;
4416
4417 if (!is_valid_ether_addr(addr->sa_data))
4418 return -EADDRNOTAVAIL;
4419
4420 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4421 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4422
Bruce Allan69e1e012012-04-14 03:28:50 +00004423 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424
4425 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4426 /* activate the work around */
4427 e1000e_set_laa_state_82571(&adapter->hw, 1);
4428
Bruce Allane921eb12012-11-28 09:28:37 +00004429 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004430 * between the time RAR[0] gets clobbered and the time it
4431 * gets fixed (in e1000_watchdog), the actual LAA is in one
4432 * of the RARs and no incoming packets directed to this port
4433 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004434 * RAR[14]
4435 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004436 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4437 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004438 }
4439
4440 return 0;
4441}
4442
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004443/**
4444 * e1000e_update_phy_task - work thread to update phy
4445 * @work: pointer to our work struct
4446 *
4447 * this worker thread exists because we must acquire a
4448 * semaphore to read the phy, which we could msleep while
4449 * waiting for it, and we can't msleep in a timer.
4450 **/
4451static void e1000e_update_phy_task(struct work_struct *work)
4452{
4453 struct e1000_adapter *adapter = container_of(work,
4454 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004455
4456 if (test_bit(__E1000_DOWN, &adapter->state))
4457 return;
4458
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004459 e1000_get_phy_info(&adapter->hw);
4460}
4461
Bruce Allane921eb12012-11-28 09:28:37 +00004462/**
4463 * e1000_update_phy_info - timre call-back to update PHY info
4464 * @data: pointer to adapter cast into an unsigned long
4465 *
Bruce Allanad680762008-03-28 09:15:03 -07004466 * Need to wait a few seconds after link up to get diagnostic information from
4467 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004468 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004469static void e1000_update_phy_info(unsigned long data)
4470{
4471 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004472
4473 if (test_bit(__E1000_DOWN, &adapter->state))
4474 return;
4475
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004476 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004477}
4478
4479/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004480 * e1000e_update_phy_stats - Update the PHY statistics counters
4481 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004482 *
4483 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004484 **/
4485static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4486{
4487 struct e1000_hw *hw = &adapter->hw;
4488 s32 ret_val;
4489 u16 phy_data;
4490
4491 ret_val = hw->phy.ops.acquire(hw);
4492 if (ret_val)
4493 return;
4494
Bruce Allane921eb12012-11-28 09:28:37 +00004495 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004496 * If not, set to the page with the PHY status registers.
4497 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004498 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004499 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4500 &phy_data);
4501 if (ret_val)
4502 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004503 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4504 ret_val = hw->phy.ops.set_page(hw,
4505 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004506 if (ret_val)
4507 goto release;
4508 }
4509
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004510 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004511 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4512 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004513 if (!ret_val)
4514 adapter->stats.scc += phy_data;
4515
4516 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004517 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4518 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004519 if (!ret_val)
4520 adapter->stats.ecol += phy_data;
4521
4522 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004523 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4524 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004525 if (!ret_val)
4526 adapter->stats.mcc += phy_data;
4527
4528 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004529 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4530 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004531 if (!ret_val)
4532 adapter->stats.latecol += phy_data;
4533
4534 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004535 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4536 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004537 if (!ret_val)
4538 hw->mac.collision_delta = phy_data;
4539
4540 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004541 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4542 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004543 if (!ret_val)
4544 adapter->stats.dc += phy_data;
4545
4546 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004547 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4548 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004549 if (!ret_val)
4550 adapter->stats.tncrs += phy_data;
4551
4552release:
4553 hw->phy.ops.release(hw);
4554}
4555
4556/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 * e1000e_update_stats - Update the board statistics counters
4558 * @adapter: board private structure
4559 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004560static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004561{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004562 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 struct e1000_hw *hw = &adapter->hw;
4564 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565
Bruce Allane921eb12012-11-28 09:28:37 +00004566 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004567 * connection is down.
4568 */
4569 if (adapter->link_speed == 0)
4570 return;
4571 if (pci_channel_offline(pdev))
4572 return;
4573
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 adapter->stats.crcerrs += er32(CRCERRS);
4575 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004576 adapter->stats.gorc += er32(GORCL);
4577 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004578 adapter->stats.bprc += er32(BPRC);
4579 adapter->stats.mprc += er32(MPRC);
4580 adapter->stats.roc += er32(ROC);
4581
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004583
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004584 /* Half-duplex statistics */
4585 if (adapter->link_duplex == HALF_DUPLEX) {
4586 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4587 e1000e_update_phy_stats(adapter);
4588 } else {
4589 adapter->stats.scc += er32(SCC);
4590 adapter->stats.ecol += er32(ECOL);
4591 adapter->stats.mcc += er32(MCC);
4592 adapter->stats.latecol += er32(LATECOL);
4593 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004594
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004595 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004596
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004597 if ((hw->mac.type != e1000_82574) &&
4598 (hw->mac.type != e1000_82583))
4599 adapter->stats.tncrs += er32(TNCRS);
4600 }
4601 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004602 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004603
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604 adapter->stats.xonrxc += er32(XONRXC);
4605 adapter->stats.xontxc += er32(XONTXC);
4606 adapter->stats.xoffrxc += er32(XOFFRXC);
4607 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004609 adapter->stats.gotc += er32(GOTCL);
4610 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 adapter->stats.rnbc += er32(RNBC);
4612 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004613
4614 adapter->stats.mptc += er32(MPTC);
4615 adapter->stats.bptc += er32(BPTC);
4616
4617 /* used for adaptive IFS */
4618
4619 hw->mac.tx_packet_delta = er32(TPT);
4620 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004621
4622 adapter->stats.algnerrc += er32(ALGNERRC);
4623 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624 adapter->stats.cexterr += er32(CEXTERR);
4625 adapter->stats.tsctc += er32(TSCTC);
4626 adapter->stats.tsctfc += er32(TSCTFC);
4627
Auke Kokbc7f75f2007-09-17 12:30:59 -07004628 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004629 netdev->stats.multicast = adapter->stats.mprc;
4630 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631
4632 /* Rx Errors */
4633
Bruce Allane921eb12012-11-28 09:28:37 +00004634 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004635 * our own version based on RUC and ROC
4636 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004637 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004638 adapter->stats.crcerrs + adapter->stats.algnerrc +
4639 adapter->stats.ruc + adapter->stats.roc +
4640 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004641 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004643 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4644 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4645 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004646
4647 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004648 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004649 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004650 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4651 netdev->stats.tx_window_errors = adapter->stats.latecol;
4652 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653
4654 /* Tx Dropped needs to be maintained elsewhere */
4655
Auke Kokbc7f75f2007-09-17 12:30:59 -07004656 /* Management Stats */
4657 adapter->stats.mgptc += er32(MGTPTC);
4658 adapter->stats.mgprc += er32(MGTPRC);
4659 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004660
4661 /* Correctable ECC Errors */
4662 if (hw->mac.type == e1000_pch_lpt) {
4663 u32 pbeccsts = er32(PBECCSTS);
4664 adapter->corr_errors +=
4665 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4666 adapter->uncorr_errors +=
4667 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4668 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4669 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004670}
4671
Bruce Allan7c257692008-04-23 11:09:00 -07004672/**
4673 * e1000_phy_read_status - Update the PHY register status snapshot
4674 * @adapter: board private structure
4675 **/
4676static void e1000_phy_read_status(struct e1000_adapter *adapter)
4677{
4678 struct e1000_hw *hw = &adapter->hw;
4679 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004680
4681 if ((er32(STATUS) & E1000_STATUS_LU) &&
4682 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004683 int ret_val;
4684
Bruce Allan7c257692008-04-23 11:09:00 -07004685 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4686 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4687 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4688 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4689 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4690 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4691 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4692 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4693 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004694 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004695 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004696 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004697 * Set values to typical power-on defaults
4698 */
4699 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4700 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4701 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4702 BMSR_ERCAP);
4703 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4704 ADVERTISE_ALL | ADVERTISE_CSMA);
4705 phy->lpa = 0;
4706 phy->expansion = EXPANSION_ENABLENPAGE;
4707 phy->ctrl1000 = ADVERTISE_1000FULL;
4708 phy->stat1000 = 0;
4709 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4710 }
Bruce Allan7c257692008-04-23 11:09:00 -07004711}
4712
Auke Kokbc7f75f2007-09-17 12:30:59 -07004713static void e1000_print_link_info(struct e1000_adapter *adapter)
4714{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004715 struct e1000_hw *hw = &adapter->hw;
4716 u32 ctrl = er32(CTRL);
4717
Bruce Allan8f12fe82008-11-21 16:54:43 -08004718 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004719 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4720 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004721 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4722 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4723 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4724 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004725}
4726
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004727static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004728{
4729 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004730 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004731 s32 ret_val = 0;
4732
Bruce Allane921eb12012-11-28 09:28:37 +00004733 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004734 * Rx sequence error interrupt. get_link_status will stay
4735 * false until the check_for_link establishes link
4736 * for copper adapters ONLY
4737 */
4738 switch (hw->phy.media_type) {
4739 case e1000_media_type_copper:
4740 if (hw->mac.get_link_status) {
4741 ret_val = hw->mac.ops.check_for_link(hw);
4742 link_active = !hw->mac.get_link_status;
4743 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004744 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004745 }
4746 break;
4747 case e1000_media_type_fiber:
4748 ret_val = hw->mac.ops.check_for_link(hw);
4749 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4750 break;
4751 case e1000_media_type_internal_serdes:
4752 ret_val = hw->mac.ops.check_for_link(hw);
4753 link_active = adapter->hw.mac.serdes_has_link;
4754 break;
4755 default:
4756 case e1000_media_type_unknown:
4757 break;
4758 }
4759
4760 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4761 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4762 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004763 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004764 }
4765
4766 return link_active;
4767}
4768
4769static void e1000e_enable_receives(struct e1000_adapter *adapter)
4770{
4771 /* make sure the receive unit is started */
4772 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004773 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004774 struct e1000_hw *hw = &adapter->hw;
4775 u32 rctl = er32(RCTL);
4776 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004777 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004778 }
4779}
4780
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004781static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4782{
4783 struct e1000_hw *hw = &adapter->hw;
4784
Bruce Allane921eb12012-11-28 09:28:37 +00004785 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004786 * for hung state and reset, if two calls return true
4787 */
4788 if (e1000_check_phy_82574(hw))
4789 adapter->phy_hang_count++;
4790 else
4791 adapter->phy_hang_count = 0;
4792
4793 if (adapter->phy_hang_count > 1) {
4794 adapter->phy_hang_count = 0;
4795 schedule_work(&adapter->reset_task);
4796 }
4797}
4798
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799/**
4800 * e1000_watchdog - Timer Call-back
4801 * @data: pointer to adapter cast into an unsigned long
4802 **/
4803static void e1000_watchdog(unsigned long data)
4804{
4805 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4806
4807 /* Do the rest outside of interrupt context */
4808 schedule_work(&adapter->watchdog_task);
4809
4810 /* TODO: make this use queue_delayed_work() */
4811}
4812
4813static void e1000_watchdog_task(struct work_struct *work)
4814{
4815 struct e1000_adapter *adapter = container_of(work,
4816 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817 struct net_device *netdev = adapter->netdev;
4818 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004819 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004820 struct e1000_ring *tx_ring = adapter->tx_ring;
4821 struct e1000_hw *hw = &adapter->hw;
4822 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004823
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004824 if (test_bit(__E1000_DOWN, &adapter->state))
4825 return;
4826
David S. Millerb405e8d2010-02-04 22:31:41 -08004827 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004828 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004829 /* Cancel scheduled suspend requests. */
4830 pm_runtime_resume(netdev->dev.parent);
4831
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004832 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834 }
4835
4836 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4837 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4838 e1000_update_mng_vlan(adapter);
4839
Auke Kokbc7f75f2007-09-17 12:30:59 -07004840 if (link) {
4841 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004842 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004843
4844 /* Cancel scheduled suspend requests. */
4845 pm_runtime_resume(netdev->dev.parent);
4846
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004847 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004848 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 mac->ops.get_link_up_info(&adapter->hw,
4850 &adapter->link_speed,
4851 &adapter->link_duplex);
4852 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004853 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004854 * if link has autonegotiated at 10/100 half
4855 */
4856 if ((hw->phy.type == e1000_phy_igp_3 ||
4857 hw->phy.type == e1000_phy_bm) &&
4858 (hw->mac.autoneg == true) &&
4859 (adapter->link_speed == SPEED_10 ||
4860 adapter->link_speed == SPEED_100) &&
4861 (adapter->link_duplex == HALF_DUPLEX)) {
4862 u16 autoneg_exp;
4863
4864 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4865
4866 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004867 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 -07004868 }
4869
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004870 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004871 adapter->tx_timeout_factor = 1;
4872 switch (adapter->link_speed) {
4873 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004874 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004875 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876 break;
4877 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004878 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004879 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880 break;
4881 }
4882
Bruce Allane921eb12012-11-28 09:28:37 +00004883 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004884 * link-up event
4885 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4887 !txb2b) {
4888 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004889 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004890 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004891 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004892 }
4893
Bruce Allane921eb12012-11-28 09:28:37 +00004894 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004895 * some hardware issues
4896 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004897 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4898 switch (adapter->link_speed) {
4899 case SPEED_10:
4900 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004901 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004902 netdev->features &= ~NETIF_F_TSO;
4903 netdev->features &= ~NETIF_F_TSO6;
4904 break;
4905 case SPEED_1000:
4906 netdev->features |= NETIF_F_TSO;
4907 netdev->features |= NETIF_F_TSO6;
4908 break;
4909 default:
4910 /* oops */
4911 break;
4912 }
4913 }
4914
Bruce Allane921eb12012-11-28 09:28:37 +00004915 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004916 * after setting TARC(0)
4917 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918 tctl = er32(TCTL);
4919 tctl |= E1000_TCTL_EN;
4920 ew32(TCTL, tctl);
4921
Bruce Allane921eb12012-11-28 09:28:37 +00004922 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004923 * reporting link up.
4924 */
4925 if (phy->ops.cfg_on_link_up)
4926 phy->ops.cfg_on_link_up(hw);
4927
Auke Kokbc7f75f2007-09-17 12:30:59 -07004928 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004929
4930 if (!test_bit(__E1000_DOWN, &adapter->state))
4931 mod_timer(&adapter->phy_info_timer,
4932 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933 }
4934 } else {
4935 if (netif_carrier_ok(netdev)) {
4936 adapter->link_speed = 0;
4937 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004938 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004939 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004940 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004941 if (!test_bit(__E1000_DOWN, &adapter->state))
4942 mod_timer(&adapter->phy_info_timer,
4943 round_jiffies(jiffies + 2 * HZ));
4944
Bruce Allan12d43f72012-12-05 06:26:14 +00004945 /* The link is lost so the controller stops DMA.
4946 * If there is queued Tx work that cannot be done
4947 * or if on an 8000ES2LAN which requires a Rx packet
4948 * buffer work-around on link down event, reset the
4949 * controller to flush the Tx/Rx packet buffers.
4950 * (Do the reset outside of interrupt context).
4951 */
4952 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4953 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4954 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004955 else
4956 pm_schedule_suspend(netdev->dev.parent,
4957 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958 }
4959 }
4960
4961link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004962 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004963 e1000e_update_stats(adapter);
4964
4965 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4966 adapter->tpt_old = adapter->stats.tpt;
4967 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4968 adapter->colc_old = adapter->stats.colc;
4969
Bruce Allan7c257692008-04-23 11:09:00 -07004970 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4971 adapter->gorc_old = adapter->stats.gorc;
4972 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4973 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004974 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004975
Bruce Allan12d43f72012-12-05 06:26:14 +00004976 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004977 schedule_work(&adapter->reset_task);
4978 /* return immediately since reset is imminent */
4979 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980 }
4981
Bruce Allan12d43f72012-12-05 06:26:14 +00004982 e1000e_update_adaptive(&adapter->hw);
4983
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004984 /* Simple mode for Interrupt Throttle Rate (ITR) */
4985 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004986 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004987 * Total asymmetrical Tx or Rx gets ITR=8000;
4988 * everyone else is between 2000-8000.
4989 */
4990 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4991 u32 dif = (adapter->gotc > adapter->gorc ?
4992 adapter->gotc - adapter->gorc :
4993 adapter->gorc - adapter->gotc) / 10000;
4994 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4995
Matthew Vick22a4cca2012-07-12 00:02:42 +00004996 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004997 }
4998
Bruce Allanad680762008-03-28 09:15:03 -07004999 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07005000 if (adapter->msix_entries)
5001 ew32(ICS, adapter->rx_ring->ims_val);
5002 else
5003 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00005005 /* flush pending descriptors to memory before detecting Tx hang */
5006 e1000e_flush_descriptors(adapter);
5007
Auke Kokbc7f75f2007-09-17 12:30:59 -07005008 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005009 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010
Bruce Allane921eb12012-11-28 09:28:37 +00005011 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005012 * reset from the other port. Set the appropriate LAA in RAR[0]
5013 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005015 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005017 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5018 e1000e_check_82574_phy_workaround(adapter);
5019
Bruce Allanb67e1912012-12-27 08:32:33 +00005020 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5021 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5022 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5023 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5024 er32(RXSTMPH);
5025 adapter->rx_hwtstamp_cleared++;
5026 } else {
5027 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5028 }
5029 }
5030
Auke Kokbc7f75f2007-09-17 12:30:59 -07005031 /* Reset the timer */
5032 if (!test_bit(__E1000_DOWN, &adapter->state))
5033 mod_timer(&adapter->watchdog_timer,
5034 round_jiffies(jiffies + 2 * HZ));
5035}
5036
5037#define E1000_TX_FLAGS_CSUM 0x00000001
5038#define E1000_TX_FLAGS_VLAN 0x00000002
5039#define E1000_TX_FLAGS_TSO 0x00000004
5040#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005041#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005042#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5044#define E1000_TX_FLAGS_VLAN_SHIFT 16
5045
Bruce Allan55aa6982011-12-16 00:45:45 +00005046static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048 struct e1000_context_desc *context_desc;
5049 struct e1000_buffer *buffer_info;
5050 unsigned int i;
5051 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005052 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005053 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005054
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005055 if (!skb_is_gso(skb))
5056 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005058 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005059 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5060
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005061 if (err)
5062 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063 }
5064
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005065 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5066 mss = skb_shinfo(skb)->gso_size;
5067 if (skb->protocol == htons(ETH_P_IP)) {
5068 struct iphdr *iph = ip_hdr(skb);
5069 iph->tot_len = 0;
5070 iph->check = 0;
5071 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5072 0, IPPROTO_TCP, 0);
5073 cmd_length = E1000_TXD_CMD_IP;
5074 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005075 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005076 ipv6_hdr(skb)->payload_len = 0;
5077 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5078 &ipv6_hdr(skb)->daddr,
5079 0, IPPROTO_TCP, 0);
5080 ipcse = 0;
5081 }
5082 ipcss = skb_network_offset(skb);
5083 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5084 tucss = skb_transport_offset(skb);
5085 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005086
5087 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5088 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5089
5090 i = tx_ring->next_to_use;
5091 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5092 buffer_info = &tx_ring->buffer_info[i];
5093
5094 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5095 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5096 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5097 context_desc->upper_setup.tcp_fields.tucss = tucss;
5098 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005099 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005100 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5101 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5102 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5103
5104 buffer_info->time_stamp = jiffies;
5105 buffer_info->next_to_watch = i;
5106
5107 i++;
5108 if (i == tx_ring->count)
5109 i = 0;
5110 tx_ring->next_to_use = i;
5111
5112 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005113}
5114
Bruce Allan55aa6982011-12-16 00:45:45 +00005115static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005116{
Bruce Allan55aa6982011-12-16 00:45:45 +00005117 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005118 struct e1000_context_desc *context_desc;
5119 struct e1000_buffer *buffer_info;
5120 unsigned int i;
5121 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005122 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005123 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005124
Dave Grahamaf807c82008-10-09 14:28:58 -07005125 if (skb->ip_summed != CHECKSUM_PARTIAL)
5126 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005127
Arthur Jones5f66f202009-03-19 01:13:08 +00005128 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5129 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5130 else
5131 protocol = skb->protocol;
5132
Arthur Jones3f518392009-03-20 15:56:35 -07005133 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005134 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005135 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5136 cmd_len |= E1000_TXD_CMD_TCP;
5137 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005138 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005139 /* XXX not handling all IPV6 headers */
5140 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5141 cmd_len |= E1000_TXD_CMD_TCP;
5142 break;
5143 default:
5144 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005145 e_warn("checksum_partial proto=%x!\n",
5146 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005147 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005148 }
5149
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005150 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005151
5152 i = tx_ring->next_to_use;
5153 buffer_info = &tx_ring->buffer_info[i];
5154 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5155
5156 context_desc->lower_setup.ip_config = 0;
5157 context_desc->upper_setup.tcp_fields.tucss = css;
5158 context_desc->upper_setup.tcp_fields.tucso =
5159 css + skb->csum_offset;
5160 context_desc->upper_setup.tcp_fields.tucse = 0;
5161 context_desc->tcp_seg_setup.data = 0;
5162 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5163
5164 buffer_info->time_stamp = jiffies;
5165 buffer_info->next_to_watch = i;
5166
5167 i++;
5168 if (i == tx_ring->count)
5169 i = 0;
5170 tx_ring->next_to_use = i;
5171
5172 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005173}
5174
Bruce Allan55aa6982011-12-16 00:45:45 +00005175static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5176 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005177 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005178{
Bruce Allan55aa6982011-12-16 00:45:45 +00005179 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005180 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005181 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005182 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005183 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005184 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005185
5186 i = tx_ring->next_to_use;
5187
5188 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005189 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005190 size = min(len, max_per_txd);
5191
Auke Kokbc7f75f2007-09-17 12:30:59 -07005192 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005195 buffer_info->dma = dma_map_single(&pdev->dev,
5196 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005197 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005198 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005199 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005200 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005201
5202 len -= size;
5203 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005204 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005205
5206 if (len) {
5207 i++;
5208 if (i == tx_ring->count)
5209 i = 0;
5210 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005211 }
5212
5213 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005214 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005215
5216 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005217 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005218 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219
5220 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005221 i++;
5222 if (i == tx_ring->count)
5223 i = 0;
5224
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225 buffer_info = &tx_ring->buffer_info[i];
5226 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005227
5228 buffer_info->length = size;
5229 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005231 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5232 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005233 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005234 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005235 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005236
5237 len -= size;
5238 offset += size;
5239 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240 }
5241 }
5242
Bruce Allanaf667a22010-12-31 06:10:01 +00005243 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005244 /* multiply data chunks by size of headers */
5245 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5246
Auke Kokbc7f75f2007-09-17 12:30:59 -07005247 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005248 tx_ring->buffer_info[i].segs = segs;
5249 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005250 tx_ring->buffer_info[first].next_to_watch = i;
5251
5252 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005253
5254dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005255 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005256 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005257 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005258 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005259
5260 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005261 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005262 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005263 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005264 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005265 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005266 }
5267
5268 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005269}
5270
Bruce Allan55aa6982011-12-16 00:45:45 +00005271static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272{
Bruce Allan55aa6982011-12-16 00:45:45 +00005273 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005274 struct e1000_tx_desc *tx_desc = NULL;
5275 struct e1000_buffer *buffer_info;
5276 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5277 unsigned int i;
5278
5279 if (tx_flags & E1000_TX_FLAGS_TSO) {
5280 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5281 E1000_TXD_CMD_TSE;
5282 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5283
5284 if (tx_flags & E1000_TX_FLAGS_IPV4)
5285 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5286 }
5287
5288 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5289 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5290 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5291 }
5292
5293 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5294 txd_lower |= E1000_TXD_CMD_VLE;
5295 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5296 }
5297
Ben Greear943146d2012-02-11 15:39:40 +00005298 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5299 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5300
Bruce Allanb67e1912012-12-27 08:32:33 +00005301 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5302 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5303 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5304 }
5305
Auke Kokbc7f75f2007-09-17 12:30:59 -07005306 i = tx_ring->next_to_use;
5307
Bruce Allan36b973d2010-11-24 07:42:43 +00005308 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005309 buffer_info = &tx_ring->buffer_info[i];
5310 tx_desc = E1000_TX_DESC(*tx_ring, i);
5311 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5312 tx_desc->lower.data =
5313 cpu_to_le32(txd_lower | buffer_info->length);
5314 tx_desc->upper.data = cpu_to_le32(txd_upper);
5315
5316 i++;
5317 if (i == tx_ring->count)
5318 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005319 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005320
5321 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5322
Ben Greear943146d2012-02-11 15:39:40 +00005323 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5324 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5325 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5326
Bruce Allane921eb12012-11-28 09:28:37 +00005327 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005328 * know there are new descriptors to fetch. (Only
5329 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005330 * such as IA-64).
5331 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005332 wmb();
5333
5334 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005335
5336 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005337 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005338 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005339 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005340
Bruce Allane921eb12012-11-28 09:28:37 +00005341 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005342 * at a time, it synchronizes IO on IA64/Altix systems
5343 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005344 mmiowb();
5345}
5346
5347#define MINIMUM_DHCP_PACKET_SIZE 282
5348static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5349 struct sk_buff *skb)
5350{
5351 struct e1000_hw *hw = &adapter->hw;
5352 u16 length, offset;
5353
Bruce Alland60923c2012-12-05 06:26:56 +00005354 if (vlan_tx_tag_present(skb) &&
5355 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5356 (adapter->hw.mng_cookie.status &
5357 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5358 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005359
5360 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5361 return 0;
5362
5363 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5364 return 0;
5365
5366 {
5367 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5368 struct udphdr *udp;
5369
5370 if (ip->protocol != IPPROTO_UDP)
5371 return 0;
5372
5373 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5374 if (ntohs(udp->dest) != 67)
5375 return 0;
5376
5377 offset = (u8 *)udp + 8 - skb->data;
5378 length = skb->len - offset;
5379 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5380 }
5381
5382 return 0;
5383}
5384
Bruce Allan55aa6982011-12-16 00:45:45 +00005385static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386{
Bruce Allan55aa6982011-12-16 00:45:45 +00005387 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005388
Bruce Allan55aa6982011-12-16 00:45:45 +00005389 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005390 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005391 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005392 * but since that doesn't exist yet, just open code it.
5393 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005394 smp_mb();
5395
Bruce Allane921eb12012-11-28 09:28:37 +00005396 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005397 * made room available.
5398 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005399 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005400 return -EBUSY;
5401
5402 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005403 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404 ++adapter->restart_queue;
5405 return 0;
5406}
5407
Bruce Allan55aa6982011-12-16 00:45:45 +00005408static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005409{
Bruce Alland821a4c2012-08-24 20:38:11 +00005410 BUG_ON(size > tx_ring->count);
5411
Bruce Allan55aa6982011-12-16 00:45:45 +00005412 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005413 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005414 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005415}
5416
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005417static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5418 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419{
5420 struct e1000_adapter *adapter = netdev_priv(netdev);
5421 struct e1000_ring *tx_ring = adapter->tx_ring;
5422 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005423 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005424 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005425 unsigned int nr_frags;
5426 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005427 int count = 0;
5428 int tso;
5429 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005430
5431 if (test_bit(__E1000_DOWN, &adapter->state)) {
5432 dev_kfree_skb_any(skb);
5433 return NETDEV_TX_OK;
5434 }
5435
5436 if (skb->len <= 0) {
5437 dev_kfree_skb_any(skb);
5438 return NETDEV_TX_OK;
5439 }
5440
Bruce Allane921eb12012-11-28 09:28:37 +00005441 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005442 * pad skb in order to meet this minimum size requirement
5443 */
5444 if (unlikely(skb->len < 17)) {
5445 if (skb_pad(skb, 17 - skb->len))
5446 return NETDEV_TX_OK;
5447 skb->len = 17;
5448 skb_set_tail_pointer(skb, 17);
5449 }
5450
Auke Kokbc7f75f2007-09-17 12:30:59 -07005451 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005452 if (mss) {
5453 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454
Bruce Allane921eb12012-11-28 09:28:37 +00005455 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005456 * points to just header, pull a few bytes of payload from
5457 * frags into skb->data
5458 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005460 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005461 * avoiding it could save a lot of cycles
5462 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005463 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005464 unsigned int pull_size;
5465
Bruce Allana2a5b322012-01-31 06:37:17 +00005466 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005468 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005469 dev_kfree_skb_any(skb);
5470 return NETDEV_TX_OK;
5471 }
Eric Dumazete743d312010-04-14 15:59:40 -07005472 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005473 }
5474 }
5475
5476 /* reserve a descriptor for the offload context */
5477 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5478 count++;
5479 count++;
5480
Bruce Alland821a4c2012-08-24 20:38:11 +00005481 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005482
5483 nr_frags = skb_shinfo(skb)->nr_frags;
5484 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005485 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5486 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005487
5488 if (adapter->hw.mac.tx_pkt_filtering)
5489 e1000_transfer_dhcp_info(adapter, skb);
5490
Bruce Allane921eb12012-11-28 09:28:37 +00005491 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005492 * head, otherwise try next time
5493 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005494 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005495 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005496
Jesse Grosseab6d182010-10-20 13:56:03 +00005497 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005498 tx_flags |= E1000_TX_FLAGS_VLAN;
5499 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5500 }
5501
5502 first = tx_ring->next_to_use;
5503
Bruce Allan55aa6982011-12-16 00:45:45 +00005504 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005505 if (tso < 0) {
5506 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005507 return NETDEV_TX_OK;
5508 }
5509
5510 if (tso)
5511 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005512 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005513 tx_flags |= E1000_TX_FLAGS_CSUM;
5514
Bruce Allane921eb12012-11-28 09:28:37 +00005515 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005516 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005517 * no longer assume, we must.
5518 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005519 if (skb->protocol == htons(ETH_P_IP))
5520 tx_flags |= E1000_TX_FLAGS_IPV4;
5521
Ben Greear943146d2012-02-11 15:39:40 +00005522 if (unlikely(skb->no_fcs))
5523 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5524
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005525 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005526 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5527 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005528 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005529 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5530 !adapter->tx_hwtstamp_skb)) {
5531 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5532 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5533 adapter->tx_hwtstamp_skb = skb_get(skb);
5534 schedule_work(&adapter->tx_hwtstamp_work);
5535 } else {
5536 skb_tx_timestamp(skb);
5537 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005538
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005539 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005540 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005541 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005542 e1000_maybe_stop_tx(tx_ring,
5543 (MAX_SKB_FRAGS *
5544 DIV_ROUND_UP(PAGE_SIZE,
5545 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005546 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005547 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005548 tx_ring->buffer_info[first].time_stamp = 0;
5549 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005550 }
5551
Auke Kokbc7f75f2007-09-17 12:30:59 -07005552 return NETDEV_TX_OK;
5553}
5554
5555/**
5556 * e1000_tx_timeout - Respond to a Tx Hang
5557 * @netdev: network interface device structure
5558 **/
5559static void e1000_tx_timeout(struct net_device *netdev)
5560{
5561 struct e1000_adapter *adapter = netdev_priv(netdev);
5562
5563 /* Do the reset outside of interrupt context */
5564 adapter->tx_timeout_count++;
5565 schedule_work(&adapter->reset_task);
5566}
5567
5568static void e1000_reset_task(struct work_struct *work)
5569{
5570 struct e1000_adapter *adapter;
5571 adapter = container_of(work, struct e1000_adapter, reset_task);
5572
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005573 /* don't run the task if already down */
5574 if (test_bit(__E1000_DOWN, &adapter->state))
5575 return;
5576
Bruce Allan12d43f72012-12-05 06:26:14 +00005577 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005578 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005579 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005580 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005581 e1000e_reinit_locked(adapter);
5582}
5583
5584/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005585 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005586 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005587 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005588 *
5589 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005590 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005591struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5592 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005593{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005594 struct e1000_adapter *adapter = netdev_priv(netdev);
5595
5596 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5597 spin_lock(&adapter->stats64_lock);
5598 e1000e_update_stats(adapter);
5599 /* Fill out the OS statistics structure */
5600 stats->rx_bytes = adapter->stats.gorc;
5601 stats->rx_packets = adapter->stats.gprc;
5602 stats->tx_bytes = adapter->stats.gotc;
5603 stats->tx_packets = adapter->stats.gptc;
5604 stats->multicast = adapter->stats.mprc;
5605 stats->collisions = adapter->stats.colc;
5606
5607 /* Rx Errors */
5608
Bruce Allane921eb12012-11-28 09:28:37 +00005609 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005610 * our own version based on RUC and ROC
5611 */
5612 stats->rx_errors = adapter->stats.rxerrc +
5613 adapter->stats.crcerrs + adapter->stats.algnerrc +
5614 adapter->stats.ruc + adapter->stats.roc +
5615 adapter->stats.cexterr;
5616 stats->rx_length_errors = adapter->stats.ruc +
5617 adapter->stats.roc;
5618 stats->rx_crc_errors = adapter->stats.crcerrs;
5619 stats->rx_frame_errors = adapter->stats.algnerrc;
5620 stats->rx_missed_errors = adapter->stats.mpc;
5621
5622 /* Tx Errors */
5623 stats->tx_errors = adapter->stats.ecol +
5624 adapter->stats.latecol;
5625 stats->tx_aborted_errors = adapter->stats.ecol;
5626 stats->tx_window_errors = adapter->stats.latecol;
5627 stats->tx_carrier_errors = adapter->stats.tncrs;
5628
5629 /* Tx Dropped needs to be maintained elsewhere */
5630
5631 spin_unlock(&adapter->stats64_lock);
5632 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005633}
5634
5635/**
5636 * e1000_change_mtu - Change the Maximum Transfer Unit
5637 * @netdev: network interface device structure
5638 * @new_mtu: new value for maximum frame size
5639 *
5640 * Returns 0 on success, negative on failure
5641 **/
5642static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5643{
5644 struct e1000_adapter *adapter = netdev_priv(netdev);
5645 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5646
Bruce Allan2adc55c2009-06-02 11:28:58 +00005647 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005648 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5649 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5650 e_err("Jumbo Frames not supported.\n");
5651 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005652 }
5653
Bruce Allan2adc55c2009-06-02 11:28:58 +00005654 /* Supported frame sizes */
5655 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5656 (max_frame > adapter->max_hw_frame_size)) {
5657 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658 return -EINVAL;
5659 }
5660
Bruce Allan2fbe4522012-04-19 03:21:47 +00005661 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5662 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005663 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5664 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005665 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005666 return -EINVAL;
5667 }
5668
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005670 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005671 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005672 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005673 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5674 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675 if (netif_running(netdev))
5676 e1000e_down(adapter);
5677
Bruce Allane921eb12012-11-28 09:28:37 +00005678 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679 * means we reserve 2 more, this pushes us to allocate from the next
5680 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005681 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005682 * However with the new *_jumbo_rx* routines, jumbo receives will use
5683 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005684 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005685
Jesse Brandeburg99261462010-01-22 22:56:16 +00005686 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005687 adapter->rx_buffer_len = 2048;
5688 else
5689 adapter->rx_buffer_len = 4096;
5690
5691 /* adjust allocation if LPE protects us, and we aren't using SBP */
5692 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5693 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5694 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005695 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005696
Auke Kokbc7f75f2007-09-17 12:30:59 -07005697 if (netif_running(netdev))
5698 e1000e_up(adapter);
5699 else
5700 e1000e_reset(adapter);
5701
5702 clear_bit(__E1000_RESETTING, &adapter->state);
5703
5704 return 0;
5705}
5706
5707static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5708 int cmd)
5709{
5710 struct e1000_adapter *adapter = netdev_priv(netdev);
5711 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005712
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005713 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005714 return -EOPNOTSUPP;
5715
5716 switch (cmd) {
5717 case SIOCGMIIPHY:
5718 data->phy_id = adapter->hw.phy.addr;
5719 break;
5720 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005721 e1000_phy_read_status(adapter);
5722
Bruce Allan7c257692008-04-23 11:09:00 -07005723 switch (data->reg_num & 0x1F) {
5724 case MII_BMCR:
5725 data->val_out = adapter->phy_regs.bmcr;
5726 break;
5727 case MII_BMSR:
5728 data->val_out = adapter->phy_regs.bmsr;
5729 break;
5730 case MII_PHYSID1:
5731 data->val_out = (adapter->hw.phy.id >> 16);
5732 break;
5733 case MII_PHYSID2:
5734 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5735 break;
5736 case MII_ADVERTISE:
5737 data->val_out = adapter->phy_regs.advertise;
5738 break;
5739 case MII_LPA:
5740 data->val_out = adapter->phy_regs.lpa;
5741 break;
5742 case MII_EXPANSION:
5743 data->val_out = adapter->phy_regs.expansion;
5744 break;
5745 case MII_CTRL1000:
5746 data->val_out = adapter->phy_regs.ctrl1000;
5747 break;
5748 case MII_STAT1000:
5749 data->val_out = adapter->phy_regs.stat1000;
5750 break;
5751 case MII_ESTATUS:
5752 data->val_out = adapter->phy_regs.estatus;
5753 break;
5754 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005755 return -EIO;
5756 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757 break;
5758 case SIOCSMIIREG:
5759 default:
5760 return -EOPNOTSUPP;
5761 }
5762 return 0;
5763}
5764
Bruce Allanb67e1912012-12-27 08:32:33 +00005765/**
5766 * e1000e_hwtstamp_ioctl - control hardware time stamping
5767 * @netdev: network interface device structure
5768 * @ifreq: interface request
5769 *
5770 * Outgoing time stamping can be enabled and disabled. Play nice and
5771 * disable it when requested, although it shouldn't cause any overhead
5772 * when no packet needs it. At most one packet in the queue may be
5773 * marked for time stamping, otherwise it would be impossible to tell
5774 * for sure to which packet the hardware time stamp belongs.
5775 *
5776 * Incoming time stamping has to be configured via the hardware filters.
5777 * Not all combinations are supported, in particular event type has to be
5778 * specified. Matching the kind of event packet is not supported, with the
5779 * exception of "all V2 events regardless of level 2 or 4".
5780 **/
5781static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5782{
5783 struct e1000_adapter *adapter = netdev_priv(netdev);
5784 struct hwtstamp_config config;
5785 int ret_val;
5786
5787 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5788 return -EFAULT;
5789
5790 adapter->hwtstamp_config = config;
5791
5792 ret_val = e1000e_config_hwtstamp(adapter);
5793 if (ret_val)
5794 return ret_val;
5795
5796 config = adapter->hwtstamp_config;
5797
Bruce Alland89777b2013-01-19 01:09:58 +00005798 switch (config.rx_filter) {
5799 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5800 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5801 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5802 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5803 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5804 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5805 /* With V2 type filters which specify a Sync or Delay Request,
5806 * Path Delay Request/Response messages are also time stamped
5807 * by hardware so notify the caller the requested packets plus
5808 * some others are time stamped.
5809 */
5810 config.rx_filter = HWTSTAMP_FILTER_SOME;
5811 break;
5812 default:
5813 break;
5814 }
5815
Bruce Allanb67e1912012-12-27 08:32:33 +00005816 return copy_to_user(ifr->ifr_data, &config,
5817 sizeof(config)) ? -EFAULT : 0;
5818}
5819
Auke Kokbc7f75f2007-09-17 12:30:59 -07005820static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5821{
5822 switch (cmd) {
5823 case SIOCGMIIPHY:
5824 case SIOCGMIIREG:
5825 case SIOCSMIIREG:
5826 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005827 case SIOCSHWTSTAMP:
5828 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005829 default:
5830 return -EOPNOTSUPP;
5831 }
5832}
5833
Bruce Allana4f58f52009-06-02 11:29:18 +00005834static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5835{
5836 struct e1000_hw *hw = &adapter->hw;
5837 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005838 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005839 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005840
5841 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005842 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005843
Bruce Allan2b6b1682011-05-13 07:20:09 +00005844 retval = hw->phy.ops.acquire(hw);
5845 if (retval) {
5846 e_err("Could not acquire PHY\n");
5847 return retval;
5848 }
5849
5850 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5851 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5852 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005853 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005854
5855 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005856 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5857 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005858 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5859 (u16)(mac_reg & 0xFFFF));
5860 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5861 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005862 }
5863
5864 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005865 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005866 mac_reg = er32(RCTL);
5867 if (mac_reg & E1000_RCTL_UPE)
5868 phy_reg |= BM_RCTL_UPE;
5869 if (mac_reg & E1000_RCTL_MPE)
5870 phy_reg |= BM_RCTL_MPE;
5871 phy_reg &= ~(BM_RCTL_MO_MASK);
5872 if (mac_reg & E1000_RCTL_MO_3)
5873 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5874 << BM_RCTL_MO_SHIFT);
5875 if (mac_reg & E1000_RCTL_BAM)
5876 phy_reg |= BM_RCTL_BAM;
5877 if (mac_reg & E1000_RCTL_PMCF)
5878 phy_reg |= BM_RCTL_PMCF;
5879 mac_reg = er32(CTRL);
5880 if (mac_reg & E1000_CTRL_RFCE)
5881 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005882 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005883
5884 /* enable PHY wakeup in MAC register */
5885 ew32(WUFC, wufc);
5886 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5887
5888 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005889 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5890 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005891
5892 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005893 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5894 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005895 if (retval)
5896 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005897release:
Bruce Allan94d81862009-11-20 23:25:26 +00005898 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005899
5900 return retval;
5901}
5902
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005903static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5904 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005905{
5906 struct net_device *netdev = pci_get_drvdata(pdev);
5907 struct e1000_adapter *adapter = netdev_priv(netdev);
5908 struct e1000_hw *hw = &adapter->hw;
5909 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005910 /* Runtime suspend should only enable wakeup for link changes */
5911 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912 int retval = 0;
5913
5914 netif_device_detach(netdev);
5915
5916 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005917 int count = E1000_CHECK_RESET_COUNT;
5918
5919 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5920 usleep_range(10000, 20000);
5921
Auke Kokbc7f75f2007-09-17 12:30:59 -07005922 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5923 e1000e_down(adapter);
5924 e1000_free_irq(adapter);
5925 }
Bruce Allan4662e822008-08-26 18:37:06 -07005926 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005927
5928 retval = pci_save_state(pdev);
5929 if (retval)
5930 return retval;
5931
5932 status = er32(STATUS);
5933 if (status & E1000_STATUS_LU)
5934 wufc &= ~E1000_WUFC_LNKC;
5935
5936 if (wufc) {
5937 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005938 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939
5940 /* turn on all-multi mode if wake on multicast is enabled */
5941 if (wufc & E1000_WUFC_MC) {
5942 rctl = er32(RCTL);
5943 rctl |= E1000_RCTL_MPE;
5944 ew32(RCTL, rctl);
5945 }
5946
5947 ctrl = er32(CTRL);
5948 /* advertise wake from D3Cold */
5949 #define E1000_CTRL_ADVD3WUC 0x00100000
5950 /* phy power management enable */
5951 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005952 ctrl |= E1000_CTRL_ADVD3WUC;
5953 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5954 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 ew32(CTRL, ctrl);
5956
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005957 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5958 adapter->hw.phy.media_type ==
5959 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005960 /* keep the laser running in D3 */
5961 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005962 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005963 ew32(CTRL_EXT, ctrl_ext);
5964 }
5965
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005966 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005967 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005968
Auke Kokbc7f75f2007-09-17 12:30:59 -07005969 /* Allow time for pending master requests to run */
5970 e1000e_disable_pcie_master(&adapter->hw);
5971
Bruce Allan82776a42009-08-14 14:35:33 +00005972 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005973 /* enable wakeup by the PHY */
5974 retval = e1000_init_phy_wakeup(adapter, wufc);
5975 if (retval)
5976 return retval;
5977 } else {
5978 /* enable wakeup by the MAC */
5979 ew32(WUFC, wufc);
5980 ew32(WUC, E1000_WUC_PME_EN);
5981 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982 } else {
5983 ew32(WUC, 0);
5984 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005985 }
5986
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005987 *enable_wake = !!wufc;
5988
Auke Kokbc7f75f2007-09-17 12:30:59 -07005989 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005990 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5991 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005992 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005993
5994 if (adapter->hw.phy.type == e1000_phy_igp_3)
5995 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5996
Bruce Allane921eb12012-11-28 09:28:37 +00005997 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005998 * would have already happened in close and is redundant.
5999 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006000 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006001
6002 pci_disable_device(pdev);
6003
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006004 return 0;
6005}
6006
6007static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
6008{
6009 if (sleep && wake) {
6010 pci_prepare_to_sleep(pdev);
6011 return;
6012 }
6013
6014 pci_wake_from_d3(pdev, wake);
6015 pci_set_power_state(pdev, PCI_D3hot);
6016}
6017
6018static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
6019 bool wake)
6020{
6021 struct net_device *netdev = pci_get_drvdata(pdev);
6022 struct e1000_adapter *adapter = netdev_priv(netdev);
6023
Bruce Allane921eb12012-11-28 09:28:37 +00006024 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006025 * correctable error when the MAC transitions from D0 to D3. To
6026 * prevent this we need to mask off the correctable errors on the
6027 * downstream port of the pci-e switch.
6028 */
6029 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6030 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006031 u16 devctl;
6032
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006033 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6034 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6035 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006036
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006037 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006038
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006039 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006040 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006041 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006042 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006043}
6044
Bruce Allan6f461f62010-04-27 03:33:04 +00006045#ifdef CONFIG_PCIEASPM
6046static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6047{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006048 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006049}
6050#else
6051static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006052{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006053 u16 aspm_ctl = 0;
6054
6055 if (state & PCIE_LINK_STATE_L0S)
6056 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6057 if (state & PCIE_LINK_STATE_L1)
6058 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6059
Bruce Allane921eb12012-11-28 09:28:37 +00006060 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006061 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006062 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006063 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006064
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006065 if (pdev->bus->self)
6066 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006067 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006068}
6069#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006070static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006071{
6072 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6073 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6074 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6075
6076 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006077}
6078
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006079#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006080static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006081{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006082 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006083}
6084
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006085static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086{
6087 struct net_device *netdev = pci_get_drvdata(pdev);
6088 struct e1000_adapter *adapter = netdev_priv(netdev);
6089 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006090 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 u32 err;
6092
Bruce Allan78cd29d2011-03-24 03:09:03 +00006093 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6094 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6095 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6096 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6097 if (aspm_disable_flag)
6098 e1000e_disable_aspm(pdev, aspm_disable_flag);
6099
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100 pci_set_power_state(pdev, PCI_D0);
6101 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006102 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006103
Bruce Allan4662e822008-08-26 18:37:06 -07006104 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006105 if (netif_running(netdev)) {
6106 err = e1000_request_irq(adapter);
6107 if (err)
6108 return err;
6109 }
6110
Bruce Allan2fbe4522012-04-19 03:21:47 +00006111 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006112 e1000_resume_workarounds_pchlan(&adapter->hw);
6113
Auke Kokbc7f75f2007-09-17 12:30:59 -07006114 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006115
6116 /* report the system wakeup cause from S3/S4 */
6117 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6118 u16 phy_data;
6119
6120 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6121 if (phy_data) {
6122 e_info("PHY Wakeup cause - %s\n",
6123 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6124 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6125 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6126 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006127 phy_data & E1000_WUS_LNKC ?
6128 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006129 }
6130 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6131 } else {
6132 u32 wus = er32(WUS);
6133 if (wus) {
6134 e_info("MAC Wakeup cause - %s\n",
6135 wus & E1000_WUS_EX ? "Unicast Packet" :
6136 wus & E1000_WUS_MC ? "Multicast Packet" :
6137 wus & E1000_WUS_BC ? "Broadcast Packet" :
6138 wus & E1000_WUS_MAG ? "Magic Packet" :
6139 wus & E1000_WUS_LNKC ? "Link Status Change" :
6140 "other");
6141 }
6142 ew32(WUS, ~0);
6143 }
6144
Auke Kokbc7f75f2007-09-17 12:30:59 -07006145 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006146
Bruce Allancd791612010-05-10 14:59:51 +00006147 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006148
6149 if (netif_running(netdev))
6150 e1000e_up(adapter);
6151
6152 netif_device_attach(netdev);
6153
Bruce Allane921eb12012-11-28 09:28:37 +00006154 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006155 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006156 * under the control of the driver.
6157 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006158 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006159 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006160
6161 return 0;
6162}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006163
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006164#ifdef CONFIG_PM_SLEEP
6165static int e1000_suspend(struct device *dev)
6166{
6167 struct pci_dev *pdev = to_pci_dev(dev);
6168 int retval;
6169 bool wake;
6170
6171 retval = __e1000_shutdown(pdev, &wake, false);
6172 if (!retval)
6173 e1000_complete_shutdown(pdev, true, wake);
6174
6175 return retval;
6176}
6177
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006178static int e1000_resume(struct device *dev)
6179{
6180 struct pci_dev *pdev = to_pci_dev(dev);
6181 struct net_device *netdev = pci_get_drvdata(pdev);
6182 struct e1000_adapter *adapter = netdev_priv(netdev);
6183
6184 if (e1000e_pm_ready(adapter))
6185 adapter->idle_check = true;
6186
6187 return __e1000_resume(pdev);
6188}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006189#endif /* CONFIG_PM_SLEEP */
6190
6191#ifdef CONFIG_PM_RUNTIME
6192static int e1000_runtime_suspend(struct device *dev)
6193{
6194 struct pci_dev *pdev = to_pci_dev(dev);
6195 struct net_device *netdev = pci_get_drvdata(pdev);
6196 struct e1000_adapter *adapter = netdev_priv(netdev);
6197
6198 if (e1000e_pm_ready(adapter)) {
6199 bool wake;
6200
6201 __e1000_shutdown(pdev, &wake, true);
6202 }
6203
6204 return 0;
6205}
6206
6207static int e1000_idle(struct device *dev)
6208{
6209 struct pci_dev *pdev = to_pci_dev(dev);
6210 struct net_device *netdev = pci_get_drvdata(pdev);
6211 struct e1000_adapter *adapter = netdev_priv(netdev);
6212
6213 if (!e1000e_pm_ready(adapter))
6214 return 0;
6215
6216 if (adapter->idle_check) {
6217 adapter->idle_check = false;
6218 if (!e1000e_has_link(adapter))
6219 pm_schedule_suspend(dev, MSEC_PER_SEC);
6220 }
6221
6222 return -EBUSY;
6223}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006224
6225static int e1000_runtime_resume(struct device *dev)
6226{
6227 struct pci_dev *pdev = to_pci_dev(dev);
6228 struct net_device *netdev = pci_get_drvdata(pdev);
6229 struct e1000_adapter *adapter = netdev_priv(netdev);
6230
6231 if (!e1000e_pm_ready(adapter))
6232 return 0;
6233
6234 adapter->idle_check = !dev->power.runtime_auto;
6235 return __e1000_resume(pdev);
6236}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006237#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006238#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006239
6240static void e1000_shutdown(struct pci_dev *pdev)
6241{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006242 bool wake = false;
6243
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006244 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006245
6246 if (system_state == SYSTEM_POWER_OFF)
6247 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006248}
6249
6250#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006251
6252static irqreturn_t e1000_intr_msix(int irq, void *data)
6253{
6254 struct net_device *netdev = data;
6255 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006256
6257 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006258 int vector, msix_irq;
6259
Dongdong Deng147b2c82010-11-16 19:50:15 -08006260 vector = 0;
6261 msix_irq = adapter->msix_entries[vector].vector;
6262 disable_irq(msix_irq);
6263 e1000_intr_msix_rx(msix_irq, netdev);
6264 enable_irq(msix_irq);
6265
6266 vector++;
6267 msix_irq = adapter->msix_entries[vector].vector;
6268 disable_irq(msix_irq);
6269 e1000_intr_msix_tx(msix_irq, netdev);
6270 enable_irq(msix_irq);
6271
6272 vector++;
6273 msix_irq = adapter->msix_entries[vector].vector;
6274 disable_irq(msix_irq);
6275 e1000_msix_other(msix_irq, netdev);
6276 enable_irq(msix_irq);
6277 }
6278
6279 return IRQ_HANDLED;
6280}
6281
Bruce Allane921eb12012-11-28 09:28:37 +00006282/**
6283 * e1000_netpoll
6284 * @netdev: network interface device structure
6285 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006286 * Polling 'interrupt' - used by things like netconsole to send skbs
6287 * without having to re-enable interrupts. It's not called while
6288 * the interrupt routine is executing.
6289 */
6290static void e1000_netpoll(struct net_device *netdev)
6291{
6292 struct e1000_adapter *adapter = netdev_priv(netdev);
6293
Dongdong Deng147b2c82010-11-16 19:50:15 -08006294 switch (adapter->int_mode) {
6295 case E1000E_INT_MODE_MSIX:
6296 e1000_intr_msix(adapter->pdev->irq, netdev);
6297 break;
6298 case E1000E_INT_MODE_MSI:
6299 disable_irq(adapter->pdev->irq);
6300 e1000_intr_msi(adapter->pdev->irq, netdev);
6301 enable_irq(adapter->pdev->irq);
6302 break;
6303 default: /* E1000E_INT_MODE_LEGACY */
6304 disable_irq(adapter->pdev->irq);
6305 e1000_intr(adapter->pdev->irq, netdev);
6306 enable_irq(adapter->pdev->irq);
6307 break;
6308 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006309}
6310#endif
6311
6312/**
6313 * e1000_io_error_detected - called when PCI error is detected
6314 * @pdev: Pointer to PCI device
6315 * @state: The current pci connection state
6316 *
6317 * This function is called after a PCI bus error affecting
6318 * this device has been detected.
6319 */
6320static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6321 pci_channel_state_t state)
6322{
6323 struct net_device *netdev = pci_get_drvdata(pdev);
6324 struct e1000_adapter *adapter = netdev_priv(netdev);
6325
6326 netif_device_detach(netdev);
6327
Mike Masonc93b5a72009-06-30 12:45:53 +00006328 if (state == pci_channel_io_perm_failure)
6329 return PCI_ERS_RESULT_DISCONNECT;
6330
Auke Kokbc7f75f2007-09-17 12:30:59 -07006331 if (netif_running(netdev))
6332 e1000e_down(adapter);
6333 pci_disable_device(pdev);
6334
6335 /* Request a slot slot reset. */
6336 return PCI_ERS_RESULT_NEED_RESET;
6337}
6338
6339/**
6340 * e1000_io_slot_reset - called after the pci bus has been reset.
6341 * @pdev: Pointer to PCI device
6342 *
6343 * Restart the card from scratch, as if from a cold-boot. Implementation
6344 * resembles the first-half of the e1000_resume routine.
6345 */
6346static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6347{
6348 struct net_device *netdev = pci_get_drvdata(pdev);
6349 struct e1000_adapter *adapter = netdev_priv(netdev);
6350 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006351 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006352 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006353 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006354
Bruce Allan78cd29d2011-03-24 03:09:03 +00006355 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6356 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006357 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006358 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6359 if (aspm_disable_flag)
6360 e1000e_disable_aspm(pdev, aspm_disable_flag);
6361
Bruce Allanf0f422e2008-08-04 17:21:53 -07006362 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006363 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364 dev_err(&pdev->dev,
6365 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006366 result = PCI_ERS_RESULT_DISCONNECT;
6367 } else {
6368 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006369 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006370 pci_restore_state(pdev);
6371
6372 pci_enable_wake(pdev, PCI_D3hot, 0);
6373 pci_enable_wake(pdev, PCI_D3cold, 0);
6374
6375 e1000e_reset(adapter);
6376 ew32(WUS, ~0);
6377 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006378 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006379
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006380 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006381
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006382 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006383}
6384
6385/**
6386 * e1000_io_resume - called when traffic can start flowing again.
6387 * @pdev: Pointer to PCI device
6388 *
6389 * This callback is called when the error recovery driver tells us that
6390 * its OK to resume normal operation. Implementation resembles the
6391 * second-half of the e1000_resume routine.
6392 */
6393static void e1000_io_resume(struct pci_dev *pdev)
6394{
6395 struct net_device *netdev = pci_get_drvdata(pdev);
6396 struct e1000_adapter *adapter = netdev_priv(netdev);
6397
Bruce Allancd791612010-05-10 14:59:51 +00006398 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006399
6400 if (netif_running(netdev)) {
6401 if (e1000e_up(adapter)) {
6402 dev_err(&pdev->dev,
6403 "can't bring device back up after reset\n");
6404 return;
6405 }
6406 }
6407
6408 netif_device_attach(netdev);
6409
Bruce Allane921eb12012-11-28 09:28:37 +00006410 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006411 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006412 * under the control of the driver.
6413 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006414 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006415 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006416
6417}
6418
6419static void e1000_print_device_info(struct e1000_adapter *adapter)
6420{
6421 struct e1000_hw *hw = &adapter->hw;
6422 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006423 u32 ret_val;
6424 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006425
6426 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006427 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006428 /* bus width */
6429 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6430 "Width x1"),
6431 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006432 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006433 e_info("Intel(R) PRO/%s Network Connection\n",
6434 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006435 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6436 E1000_PBANUM_LENGTH);
6437 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006438 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006439 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6440 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006441}
6442
Auke Kok10aa4c02008-08-04 17:21:20 -07006443static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6444{
6445 struct e1000_hw *hw = &adapter->hw;
6446 int ret_val;
6447 u16 buf = 0;
6448
6449 if (hw->mac.type != e1000_82573)
6450 return;
6451
6452 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006453 le16_to_cpus(&buf);
6454 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006455 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006456 dev_warn(&adapter->pdev->dev,
6457 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006458 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006459}
6460
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006461static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006462 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006463{
6464 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006465 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006466
6467 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6468 adapter->flags |= FLAG_TSO_FORCE;
6469
6470 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006471 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6472 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006473 return 0;
6474
Ben Greear01840392012-02-11 15:39:25 +00006475 if (changed & NETIF_F_RXFCS) {
6476 if (features & NETIF_F_RXFCS) {
6477 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6478 } else {
6479 /* We need to take it back to defaults, which might mean
6480 * stripping is still disabled at the adapter level.
6481 */
6482 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6483 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6484 else
6485 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6486 }
6487 }
6488
Bruce Allan70495a52012-01-11 01:26:50 +00006489 netdev->features = features;
6490
Bruce Allandc221292011-08-19 03:23:48 +00006491 if (netif_running(netdev))
6492 e1000e_reinit_locked(adapter);
6493 else
6494 e1000e_reset(adapter);
6495
6496 return 0;
6497}
6498
Stephen Hemminger651c2462008-11-19 21:57:48 -08006499static const struct net_device_ops e1000e_netdev_ops = {
6500 .ndo_open = e1000_open,
6501 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006502 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006503 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006504 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006505 .ndo_set_mac_address = e1000_set_mac,
6506 .ndo_change_mtu = e1000_change_mtu,
6507 .ndo_do_ioctl = e1000_ioctl,
6508 .ndo_tx_timeout = e1000_tx_timeout,
6509 .ndo_validate_addr = eth_validate_addr,
6510
Stephen Hemminger651c2462008-11-19 21:57:48 -08006511 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6512 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6513#ifdef CONFIG_NET_POLL_CONTROLLER
6514 .ndo_poll_controller = e1000_netpoll,
6515#endif
Bruce Allandc221292011-08-19 03:23:48 +00006516 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006517};
6518
Auke Kokbc7f75f2007-09-17 12:30:59 -07006519/**
6520 * e1000_probe - Device Initialization Routine
6521 * @pdev: PCI device information struct
6522 * @ent: entry in e1000_pci_tbl
6523 *
6524 * Returns 0 on success, negative on failure
6525 *
6526 * e1000_probe initializes an adapter identified by a pci_dev structure.
6527 * The OS initialization, configuring of the adapter private structure,
6528 * and a hardware reset occur.
6529 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006530static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006531{
6532 struct net_device *netdev;
6533 struct e1000_adapter *adapter;
6534 struct e1000_hw *hw;
6535 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006536 resource_size_t mmio_start, mmio_len;
6537 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006538 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006539 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006540 int i, err, pci_using_dac;
6541 u16 eeprom_data = 0;
6542 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6543
Bruce Allan78cd29d2011-03-24 03:09:03 +00006544 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6545 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006546 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006547 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6548 if (aspm_disable_flag)
6549 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006550
Bruce Allanf0f422e2008-08-04 17:21:53 -07006551 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006552 if (err)
6553 return err;
6554
6555 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006556 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006557 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006558 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006559 if (!err)
6560 pci_using_dac = 1;
6561 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006562 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006563 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006564 err = dma_set_coherent_mask(&pdev->dev,
6565 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006566 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006567 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006568 goto err_dma;
6569 }
6570 }
6571 }
6572
Arjan van de Vene8de1482008-10-22 19:55:31 -07006573 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006574 pci_select_bars(pdev, IORESOURCE_MEM),
6575 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006576 if (err)
6577 goto err_pci_reg;
6578
Xiaotian Feng68eac462009-08-14 14:35:52 +00006579 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006580 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006581
Auke Kokbc7f75f2007-09-17 12:30:59 -07006582 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006583 /* PCI config space info */
6584 err = pci_save_state(pdev);
6585 if (err)
6586 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006587
6588 err = -ENOMEM;
6589 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6590 if (!netdev)
6591 goto err_alloc_etherdev;
6592
Auke Kokbc7f75f2007-09-17 12:30:59 -07006593 SET_NETDEV_DEV(netdev, &pdev->dev);
6594
Tom Herbertf85e4df2010-05-05 14:03:32 +00006595 netdev->irq = pdev->irq;
6596
Auke Kokbc7f75f2007-09-17 12:30:59 -07006597 pci_set_drvdata(pdev, netdev);
6598 adapter = netdev_priv(netdev);
6599 hw = &adapter->hw;
6600 adapter->netdev = netdev;
6601 adapter->pdev = pdev;
6602 adapter->ei = ei;
6603 adapter->pba = ei->pba;
6604 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006605 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006606 adapter->hw.adapter = adapter;
6607 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006608 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006609 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006610
6611 mmio_start = pci_resource_start(pdev, 0);
6612 mmio_len = pci_resource_len(pdev, 0);
6613
6614 err = -EIO;
6615 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6616 if (!adapter->hw.hw_addr)
6617 goto err_ioremap;
6618
6619 if ((adapter->flags & FLAG_HAS_FLASH) &&
6620 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6621 flash_start = pci_resource_start(pdev, 1);
6622 flash_len = pci_resource_len(pdev, 1);
6623 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6624 if (!adapter->hw.flash_address)
6625 goto err_flashmap;
6626 }
6627
6628 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006629 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006630 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006631 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006632 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006633 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006634
6635 netdev->mem_start = mmio_start;
6636 netdev->mem_end = mmio_start + mmio_len;
6637
6638 adapter->bd_number = cards_found++;
6639
Bruce Allan4662e822008-08-26 18:37:06 -07006640 e1000e_check_options(adapter);
6641
Auke Kokbc7f75f2007-09-17 12:30:59 -07006642 /* setup adapter struct */
6643 err = e1000_sw_init(adapter);
6644 if (err)
6645 goto err_sw_init;
6646
Auke Kokbc7f75f2007-09-17 12:30:59 -07006647 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6648 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6649 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6650
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006651 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006652 if (err)
6653 goto err_hw_init;
6654
Bruce Allan4a770352008-10-01 17:18:35 -07006655 if ((adapter->flags & FLAG_IS_ICH) &&
6656 (adapter->flags & FLAG_READ_ONLY_NVM))
6657 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6658
Auke Kokbc7f75f2007-09-17 12:30:59 -07006659 hw->mac.ops.get_bus_info(&adapter->hw);
6660
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006661 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006662
6663 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006664 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006665 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6666 adapter->hw.phy.disable_polarity_correction = 0;
6667 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6668 }
6669
Bruce Allan470a5422012-05-26 06:08:48 +00006670 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006671 dev_info(&pdev->dev,
6672 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006673
Bruce Allandc221292011-08-19 03:23:48 +00006674 /* Set initial default active device features */
6675 netdev->features = (NETIF_F_SG |
6676 NETIF_F_HW_VLAN_RX |
6677 NETIF_F_HW_VLAN_TX |
6678 NETIF_F_TSO |
6679 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006680 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006681 NETIF_F_RXCSUM |
6682 NETIF_F_HW_CSUM);
6683
6684 /* Set user-changeable features (subset of all device features) */
6685 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006686 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006687 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006688 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006689
6690 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6691 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6692
Bruce Allandc221292011-08-19 03:23:48 +00006693 netdev->vlan_features |= (NETIF_F_SG |
6694 NETIF_F_TSO |
6695 NETIF_F_TSO6 |
6696 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006697
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006698 netdev->priv_flags |= IFF_UNICAST_FLT;
6699
Yi Zou7b872a52010-09-22 17:57:58 +00006700 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006701 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006702 netdev->vlan_features |= NETIF_F_HIGHDMA;
6703 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006704
Auke Kokbc7f75f2007-09-17 12:30:59 -07006705 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6706 adapter->flags |= FLAG_MNG_PT_ENABLED;
6707
Bruce Allane921eb12012-11-28 09:28:37 +00006708 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006709 * put the device in a known good starting state
6710 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006711 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6712
Bruce Allane921eb12012-11-28 09:28:37 +00006713 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006714 * attempt. Let's give it a few tries
6715 */
6716 for (i = 0;; i++) {
6717 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6718 break;
6719 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006720 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006721 err = -EIO;
6722 goto err_eeprom;
6723 }
6724 }
6725
Auke Kok10aa4c02008-08-04 17:21:20 -07006726 e1000_eeprom_checks(adapter);
6727
Bruce Allan608f8a02010-01-13 02:04:58 +00006728 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006729 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006730 dev_err(&pdev->dev,
6731 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006732
6733 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006734
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006735 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006736 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006737 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006738 err = -EIO;
6739 goto err_eeprom;
6740 }
6741
6742 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006743 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006744 adapter->watchdog_timer.data = (unsigned long) adapter;
6745
6746 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006747 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006748 adapter->phy_info_timer.data = (unsigned long) adapter;
6749
6750 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6751 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006752 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6753 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006754 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006755
Auke Kokbc7f75f2007-09-17 12:30:59 -07006756 /* Initialize link parameters. User can change them with ethtool */
6757 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006758 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006759 adapter->hw.fc.requested_mode = e1000_fc_default;
6760 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006761 adapter->hw.phy.autoneg_advertised = 0x2f;
6762
6763 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006764 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6765 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006766
Bruce Allane921eb12012-11-28 09:28:37 +00006767 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006768 * the EEPROM, enable the ACPI Magic Packet filter
6769 */
6770 if (adapter->flags & FLAG_APME_IN_WUC) {
6771 /* APME bit in EEPROM is mapped to WUC.APME */
6772 eeprom_data = er32(WUC);
6773 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006774 if ((hw->mac.type > e1000_ich10lan) &&
6775 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006776 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006777 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6778 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6779 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006780 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6781 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006782 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006783 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6784 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006785 }
6786
6787 /* fetch WoL from EEPROM */
6788 if (eeprom_data & eeprom_apme_mask)
6789 adapter->eeprom_wol |= E1000_WUFC_MAG;
6790
Bruce Allane921eb12012-11-28 09:28:37 +00006791 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006792 * where the eeprom may be wrong or the board simply won't support
6793 * wake on lan on a particular port
6794 */
6795 if (!(adapter->flags & FLAG_HAS_WOL))
6796 adapter->eeprom_wol = 0;
6797
6798 /* initialize the wol settings based on the eeprom settings */
6799 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006800 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006801
Bruce Allan84527592008-11-21 17:00:22 -08006802 /* save off EEPROM version number */
6803 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6804
Auke Kokbc7f75f2007-09-17 12:30:59 -07006805 /* reset the hardware with the new settings */
6806 e1000e_reset(adapter);
6807
Bruce Allane921eb12012-11-28 09:28:37 +00006808 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006810 * under the control of the driver.
6811 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006812 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006813 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006814
Bruce Allanf2315bf2011-12-16 00:46:59 +00006815 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006816 err = register_netdev(netdev);
6817 if (err)
6818 goto err_register;
6819
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006820 /* carrier off reporting is important to ethtool even BEFORE open */
6821 netif_carrier_off(netdev);
6822
Bruce Alland89777b2013-01-19 01:09:58 +00006823 /* init PTP hardware clock */
6824 e1000e_ptp_init(adapter);
6825
Auke Kokbc7f75f2007-09-17 12:30:59 -07006826 e1000_print_device_info(adapter);
6827
Alan Sternf3ec4f82010-06-08 15:23:51 -04006828 if (pci_dev_run_wake(pdev))
6829 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006830
Auke Kokbc7f75f2007-09-17 12:30:59 -07006831 return 0;
6832
6833err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006834 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006835 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006836err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006837 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006838 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006839err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006840 kfree(adapter->tx_ring);
6841 kfree(adapter->rx_ring);
6842err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006843 if (adapter->hw.flash_address)
6844 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006845 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006846err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006847 iounmap(adapter->hw.hw_addr);
6848err_ioremap:
6849 free_netdev(netdev);
6850err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006851 pci_release_selected_regions(pdev,
6852 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006853err_pci_reg:
6854err_dma:
6855 pci_disable_device(pdev);
6856 return err;
6857}
6858
6859/**
6860 * e1000_remove - Device Removal Routine
6861 * @pdev: PCI device information struct
6862 *
6863 * e1000_remove is called by the PCI subsystem to alert the driver
6864 * that it should release a PCI device. The could be caused by a
6865 * Hot-Plug event, or because the driver is going to be removed from
6866 * memory.
6867 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006868static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006869{
6870 struct net_device *netdev = pci_get_drvdata(pdev);
6871 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006872 bool down = test_bit(__E1000_DOWN, &adapter->state);
6873
Bruce Alland89777b2013-01-19 01:09:58 +00006874 e1000e_ptp_remove(adapter);
6875
Bruce Allane921eb12012-11-28 09:28:37 +00006876 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006877 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006878 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006879 if (!down)
6880 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006881 del_timer_sync(&adapter->watchdog_timer);
6882 del_timer_sync(&adapter->phy_info_timer);
6883
Bruce Allan41cec6f2009-11-20 23:28:56 +00006884 cancel_work_sync(&adapter->reset_task);
6885 cancel_work_sync(&adapter->watchdog_task);
6886 cancel_work_sync(&adapter->downshift_task);
6887 cancel_work_sync(&adapter->update_phy_task);
6888 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006889
Bruce Allanb67e1912012-12-27 08:32:33 +00006890 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6891 cancel_work_sync(&adapter->tx_hwtstamp_work);
6892 if (adapter->tx_hwtstamp_skb) {
6893 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6894 adapter->tx_hwtstamp_skb = NULL;
6895 }
6896 }
6897
Bruce Allan17f208d2009-12-01 15:47:22 +00006898 if (!(netdev->flags & IFF_UP))
6899 e1000_power_down_phy(adapter);
6900
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006901 /* Don't lie to e1000_close() down the road. */
6902 if (!down)
6903 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006904 unregister_netdev(netdev);
6905
Alan Sternf3ec4f82010-06-08 15:23:51 -04006906 if (pci_dev_run_wake(pdev))
6907 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006908
Bruce Allane921eb12012-11-28 09:28:37 +00006909 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006910 * would have already happened in close and is redundant.
6911 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006912 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006913
Bruce Allan4662e822008-08-26 18:37:06 -07006914 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006915 kfree(adapter->tx_ring);
6916 kfree(adapter->rx_ring);
6917
6918 iounmap(adapter->hw.hw_addr);
6919 if (adapter->hw.flash_address)
6920 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006921 pci_release_selected_regions(pdev,
6922 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006923
6924 free_netdev(netdev);
6925
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006926 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006927 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006928
Auke Kokbc7f75f2007-09-17 12:30:59 -07006929 pci_disable_device(pdev);
6930}
6931
6932/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006933static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006934 .error_detected = e1000_io_error_detected,
6935 .slot_reset = e1000_io_slot_reset,
6936 .resume = e1000_io_resume,
6937};
6938
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006939static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006949
Auke Kokbc7f75f2007-09-17 12:30:59 -07006950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006954
Auke Kokbc7f75f2007-09-17 12:30:59 -07006955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006958
Bruce Allan4662e822008-08-26 18:37:06 -07006959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006962
Auke Kokbc7f75f2007-09-17 12:30:59 -07006963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6964 board_80003es2lan },
6965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6966 board_80003es2lan },
6967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6968 board_80003es2lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6970 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006971
Auke Kokbc7f75f2007-09-17 12:30:59 -07006972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006980
Auke Kokbc7f75f2007-09-17 12:30:59 -07006981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6984 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6989 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6990
6991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6992 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6993 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006994
Bruce Allanf4187b52008-08-26 18:36:50 -07006995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006998
Bruce Allana4f58f52009-06-02 11:29:18 +00006999 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
7000 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
7001 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
7002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
7003
Bruce Alland3738bb2010-06-16 13:27:28 +00007004 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
7005 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7006
Bruce Allan2fbe4522012-04-19 03:21:47 +00007007 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7008 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007009 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7010 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007011
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007012 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007013};
7014MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7015
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007016#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007017static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007018 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
7019 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
7020 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007021};
David S. Millere50208a2010-03-16 23:36:24 -07007022#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007023
Auke Kokbc7f75f2007-09-17 12:30:59 -07007024/* PCI Device API Driver */
7025static struct pci_driver e1000_driver = {
7026 .name = e1000e_driver_name,
7027 .id_table = e1000_pci_tbl,
7028 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007029 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007030#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007031 .driver = {
7032 .pm = &e1000_pm_ops,
7033 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007034#endif
7035 .shutdown = e1000_shutdown,
7036 .err_handler = &e1000_err_handler
7037};
7038
7039/**
7040 * e1000_init_module - Driver Registration Routine
7041 *
7042 * e1000_init_module is the first routine called when the driver is
7043 * loaded. All it does is register with the PCI subsystem.
7044 **/
7045static int __init e1000_init_module(void)
7046{
7047 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007048 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7049 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007050 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007051 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007052
Auke Kokbc7f75f2007-09-17 12:30:59 -07007053 return ret;
7054}
7055module_init(e1000_init_module);
7056
7057/**
7058 * e1000_exit_module - Driver Exit Cleanup Routine
7059 *
7060 * e1000_exit_module is called just before the driver is removed
7061 * from memory.
7062 **/
7063static void __exit e1000_exit_module(void)
7064{
7065 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007066}
7067module_exit(e1000_exit_module);
7068
7069
7070MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7071MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7072MODULE_LICENSE("GPL");
7073MODULE_VERSION(DRV_VERSION);
7074
Bruce Allan06c24b92012-02-23 03:13:13 +00007075/* netdev.c */