blob: 34be756ee1e2b15097800021be34738f40bb38d6 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 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
Ben Hutchings288379f2009-01-19 16:43:59 -08001783 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 adapter->total_tx_bytes = 0;
1785 adapter->total_tx_packets = 0;
1786 adapter->total_rx_bytes = 0;
1787 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001788 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001789 }
1790
1791 return IRQ_HANDLED;
1792}
1793
1794/**
1795 * e1000_intr - Interrupt Handler
1796 * @irq: interrupt number
1797 * @data: pointer to a network interface device structure
1798 **/
1799static irqreturn_t e1000_intr(int irq, void *data)
1800{
1801 struct net_device *netdev = data;
1802 struct e1000_adapter *adapter = netdev_priv(netdev);
1803 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001804 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001805
Bruce Allana68ea772009-11-20 23:23:16 +00001806 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 return IRQ_NONE; /* Not our interrupt */
1808
Bruce Allane921eb12012-11-28 09:28:37 +00001809 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001810 * not set, then the adapter didn't send an interrupt
1811 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 if (!(icr & E1000_ICR_INT_ASSERTED))
1813 return IRQ_NONE;
1814
Bruce Allane921eb12012-11-28 09:28:37 +00001815 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001816 * interrupts are masked. No need for the
1817 * IMC write
1818 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819
dave graham573cca82009-02-10 12:52:05 +00001820 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001821 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001822 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001823 * disconnect (LSC) before accessing any PHY registers
1824 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1826 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001827 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001828
Bruce Allane921eb12012-11-28 09:28:37 +00001829 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830 * For packet buffer work-around on link down event;
1831 * disable receives here in the ISR and
1832 * reset adapter in watchdog
1833 */
1834 if (netif_carrier_ok(netdev) &&
1835 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1836 /* disable receives */
1837 rctl = er32(RCTL);
1838 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001839 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001840 }
1841 /* guard against interrupt when we're going down */
1842 if (!test_bit(__E1000_DOWN, &adapter->state))
1843 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1844 }
1845
Ben Hutchings288379f2009-01-19 16:43:59 -08001846 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847 adapter->total_tx_bytes = 0;
1848 adapter->total_tx_packets = 0;
1849 adapter->total_rx_bytes = 0;
1850 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001851 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 }
1853
1854 return IRQ_HANDLED;
1855}
1856
Bruce Allan4662e822008-08-26 18:37:06 -07001857static irqreturn_t e1000_msix_other(int irq, void *data)
1858{
1859 struct net_device *netdev = data;
1860 struct e1000_adapter *adapter = netdev_priv(netdev);
1861 struct e1000_hw *hw = &adapter->hw;
1862 u32 icr = er32(ICR);
1863
1864 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001865 if (!test_bit(__E1000_DOWN, &adapter->state))
1866 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001867 return IRQ_NONE;
1868 }
1869
1870 if (icr & adapter->eiac_mask)
1871 ew32(ICS, (icr & adapter->eiac_mask));
1872
1873 if (icr & E1000_ICR_OTHER) {
1874 if (!(icr & E1000_ICR_LSC))
1875 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001876 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001877 /* guard against interrupt when we're going down */
1878 if (!test_bit(__E1000_DOWN, &adapter->state))
1879 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1880 }
1881
1882no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001883 if (!test_bit(__E1000_DOWN, &adapter->state))
1884 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001885
1886 return IRQ_HANDLED;
1887}
1888
1889
1890static irqreturn_t e1000_intr_msix_tx(int irq, void *data)
1891{
1892 struct net_device *netdev = data;
1893 struct e1000_adapter *adapter = netdev_priv(netdev);
1894 struct e1000_hw *hw = &adapter->hw;
1895 struct e1000_ring *tx_ring = adapter->tx_ring;
1896
1897
1898 adapter->total_tx_bytes = 0;
1899 adapter->total_tx_packets = 0;
1900
Bruce Allan55aa6982011-12-16 00:45:45 +00001901 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001902 /* Ring was not completely cleaned, so fire another interrupt */
1903 ew32(ICS, tx_ring->ims_val);
1904
1905 return IRQ_HANDLED;
1906}
1907
1908static irqreturn_t e1000_intr_msix_rx(int irq, void *data)
1909{
1910 struct net_device *netdev = data;
1911 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001912 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001913
1914 /* Write the ITR value calculated at the end of the
1915 * previous interrupt.
1916 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001917 if (rx_ring->set_itr) {
1918 writel(1000000000 / (rx_ring->itr_val * 256),
1919 rx_ring->itr_register);
1920 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001921 }
1922
Ben Hutchings288379f2009-01-19 16:43:59 -08001923 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001924 adapter->total_rx_bytes = 0;
1925 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001926 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001927 }
1928 return IRQ_HANDLED;
1929}
1930
1931/**
1932 * e1000_configure_msix - Configure MSI-X hardware
1933 *
1934 * e1000_configure_msix sets up the hardware to properly
1935 * generate MSI-X interrupts.
1936 **/
1937static void e1000_configure_msix(struct e1000_adapter *adapter)
1938{
1939 struct e1000_hw *hw = &adapter->hw;
1940 struct e1000_ring *rx_ring = adapter->rx_ring;
1941 struct e1000_ring *tx_ring = adapter->tx_ring;
1942 int vector = 0;
1943 u32 ctrl_ext, ivar = 0;
1944
1945 adapter->eiac_mask = 0;
1946
1947 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1948 if (hw->mac.type == e1000_82574) {
1949 u32 rfctl = er32(RFCTL);
1950 rfctl |= E1000_RFCTL_ACK_DIS;
1951 ew32(RFCTL, rfctl);
1952 }
1953
1954#define E1000_IVAR_INT_ALLOC_VALID 0x8
1955 /* Configure Rx vector */
1956 rx_ring->ims_val = E1000_IMS_RXQ0;
1957 adapter->eiac_mask |= rx_ring->ims_val;
1958 if (rx_ring->itr_val)
1959 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001960 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001961 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001962 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001963 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1964
1965 /* Configure Tx vector */
1966 tx_ring->ims_val = E1000_IMS_TXQ0;
1967 vector++;
1968 if (tx_ring->itr_val)
1969 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001970 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001971 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001972 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001973 adapter->eiac_mask |= tx_ring->ims_val;
1974 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1975
1976 /* set vector for Other Causes, e.g. link changes */
1977 vector++;
1978 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1979 if (rx_ring->itr_val)
1980 writel(1000000000 / (rx_ring->itr_val * 256),
1981 hw->hw_addr + E1000_EITR_82574(vector));
1982 else
1983 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
1984
1985 /* Cause Tx interrupts on every write back */
1986 ivar |= (1 << 31);
1987
1988 ew32(IVAR, ivar);
1989
1990 /* enable MSI-X PBA support */
1991 ctrl_ext = er32(CTRL_EXT);
1992 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
1993
1994 /* Auto-Mask Other interrupts upon ICR read */
1995#define E1000_EIAC_MASK_82574 0x01F00000
1996 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
1997 ctrl_ext |= E1000_CTRL_EXT_EIAME;
1998 ew32(CTRL_EXT, ctrl_ext);
1999 e1e_flush();
2000}
2001
2002void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2003{
2004 if (adapter->msix_entries) {
2005 pci_disable_msix(adapter->pdev);
2006 kfree(adapter->msix_entries);
2007 adapter->msix_entries = NULL;
2008 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2009 pci_disable_msi(adapter->pdev);
2010 adapter->flags &= ~FLAG_MSI_ENABLED;
2011 }
Bruce Allan4662e822008-08-26 18:37:06 -07002012}
2013
2014/**
2015 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2016 *
2017 * Attempt to configure interrupts using the best available
2018 * capabilities of the hardware and kernel.
2019 **/
2020void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2021{
2022 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002023 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002024
2025 switch (adapter->int_mode) {
2026 case E1000E_INT_MODE_MSIX:
2027 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002028 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2029 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002030 sizeof(struct msix_entry),
2031 GFP_KERNEL);
2032 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002033 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002034 adapter->msix_entries[i].entry = i;
2035
2036 err = pci_enable_msix(adapter->pdev,
2037 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002038 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002039 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002040 return;
2041 }
2042 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002043 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002044 e1000e_reset_interrupt_capability(adapter);
2045 }
2046 adapter->int_mode = E1000E_INT_MODE_MSI;
2047 /* Fall through */
2048 case E1000E_INT_MODE_MSI:
2049 if (!pci_enable_msi(adapter->pdev)) {
2050 adapter->flags |= FLAG_MSI_ENABLED;
2051 } else {
2052 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002053 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002054 }
2055 /* Fall through */
2056 case E1000E_INT_MODE_LEGACY:
2057 /* Don't do anything; this is the system default */
2058 break;
2059 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002060
2061 /* store the number of vectors being used */
2062 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002063}
2064
2065/**
2066 * e1000_request_msix - Initialize MSI-X interrupts
2067 *
2068 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2069 * kernel.
2070 **/
2071static int e1000_request_msix(struct e1000_adapter *adapter)
2072{
2073 struct net_device *netdev = adapter->netdev;
2074 int err = 0, vector = 0;
2075
2076 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002077 snprintf(adapter->rx_ring->name,
2078 sizeof(adapter->rx_ring->name) - 1,
2079 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002080 else
2081 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2082 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002083 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002084 netdev);
2085 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002086 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002087 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2088 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002089 adapter->rx_ring->itr_val = adapter->itr;
2090 vector++;
2091
2092 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002093 snprintf(adapter->tx_ring->name,
2094 sizeof(adapter->tx_ring->name) - 1,
2095 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002096 else
2097 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2098 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002099 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002100 netdev);
2101 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002102 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002103 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2104 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002105 adapter->tx_ring->itr_val = adapter->itr;
2106 vector++;
2107
2108 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002109 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002110 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002111 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002112
2113 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002114
Bruce Allan4662e822008-08-26 18:37:06 -07002115 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002116}
2117
Bruce Allanf8d59f72008-08-08 18:36:11 -07002118/**
2119 * e1000_request_irq - initialize interrupts
2120 *
2121 * Attempts to configure interrupts using the best available
2122 * capabilities of the hardware and kernel.
2123 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124static int e1000_request_irq(struct e1000_adapter *adapter)
2125{
2126 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002127 int err;
2128
Bruce Allan4662e822008-08-26 18:37:06 -07002129 if (adapter->msix_entries) {
2130 err = e1000_request_msix(adapter);
2131 if (!err)
2132 return err;
2133 /* fall back to MSI */
2134 e1000e_reset_interrupt_capability(adapter);
2135 adapter->int_mode = E1000E_INT_MODE_MSI;
2136 e1000e_set_interrupt_capability(adapter);
2137 }
2138 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002139 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002140 netdev->name, netdev);
2141 if (!err)
2142 return err;
2143
2144 /* fall back to legacy interrupt */
2145 e1000e_reset_interrupt_capability(adapter);
2146 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 }
2148
Joe Perchesa0607fd2009-11-18 23:29:17 -08002149 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002150 netdev->name, netdev);
2151 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002152 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153
2154 return err;
2155}
2156
2157static void e1000_free_irq(struct e1000_adapter *adapter)
2158{
2159 struct net_device *netdev = adapter->netdev;
2160
Bruce Allan4662e822008-08-26 18:37:06 -07002161 if (adapter->msix_entries) {
2162 int vector = 0;
2163
2164 free_irq(adapter->msix_entries[vector].vector, netdev);
2165 vector++;
2166
2167 free_irq(adapter->msix_entries[vector].vector, netdev);
2168 vector++;
2169
2170 /* Other Causes interrupt vector */
2171 free_irq(adapter->msix_entries[vector].vector, netdev);
2172 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002173 }
Bruce Allan4662e822008-08-26 18:37:06 -07002174
2175 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176}
2177
2178/**
2179 * e1000_irq_disable - Mask off interrupt generation on the NIC
2180 **/
2181static void e1000_irq_disable(struct e1000_adapter *adapter)
2182{
2183 struct e1000_hw *hw = &adapter->hw;
2184
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002186 if (adapter->msix_entries)
2187 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002188 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002189
2190 if (adapter->msix_entries) {
2191 int i;
2192 for (i = 0; i < adapter->num_vectors; i++)
2193 synchronize_irq(adapter->msix_entries[i].vector);
2194 } else {
2195 synchronize_irq(adapter->pdev->irq);
2196 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002197}
2198
2199/**
2200 * e1000_irq_enable - Enable default interrupt generation settings
2201 **/
2202static void e1000_irq_enable(struct e1000_adapter *adapter)
2203{
2204 struct e1000_hw *hw = &adapter->hw;
2205
Bruce Allan4662e822008-08-26 18:37:06 -07002206 if (adapter->msix_entries) {
2207 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2208 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
2209 } else {
2210 ew32(IMS, IMS_ENABLE_MASK);
2211 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002212 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213}
2214
2215/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002216 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002217 * @adapter: address of board private structure
2218 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002219 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220 * For ASF and Pass Through versions of f/w this means that
2221 * the driver is loaded. For AMT version (only with 82573)
2222 * of the f/w this means that the network i/f is open.
2223 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002224void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002225{
2226 struct e1000_hw *hw = &adapter->hw;
2227 u32 ctrl_ext;
2228 u32 swsm;
2229
2230 /* Let firmware know the driver has taken over */
2231 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2232 swsm = er32(SWSM);
2233 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2234 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2235 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002236 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237 }
2238}
2239
2240/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002241 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002242 * @adapter: address of board private structure
2243 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002244 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002245 * For ASF and Pass Through versions of f/w this means that the
2246 * driver is no longer loaded. For AMT version (only with 82573) i
2247 * of the f/w this means that the network i/f is closed.
2248 *
2249 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002250void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251{
2252 struct e1000_hw *hw = &adapter->hw;
2253 u32 ctrl_ext;
2254 u32 swsm;
2255
2256 /* Let firmware taken over control of h/w */
2257 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2258 swsm = er32(SWSM);
2259 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2260 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2261 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002262 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 }
2264}
2265
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002267 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268 **/
2269static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2270 struct e1000_ring *ring)
2271{
2272 struct pci_dev *pdev = adapter->pdev;
2273
2274 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2275 GFP_KERNEL);
2276 if (!ring->desc)
2277 return -ENOMEM;
2278
2279 return 0;
2280}
2281
2282/**
2283 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002284 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285 *
2286 * Return 0 on success, negative on failure
2287 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002288int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002289{
Bruce Allan55aa6982011-12-16 00:45:45 +00002290 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291 int err = -ENOMEM, size;
2292
2293 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002294 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002295 if (!tx_ring->buffer_info)
2296 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297
2298 /* round up to nearest 4K */
2299 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2300 tx_ring->size = ALIGN(tx_ring->size, 4096);
2301
2302 err = e1000_alloc_ring_dma(adapter, tx_ring);
2303 if (err)
2304 goto err;
2305
2306 tx_ring->next_to_use = 0;
2307 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308
2309 return 0;
2310err:
2311 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002312 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 return err;
2314}
2315
2316/**
2317 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002318 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 *
2320 * Returns 0 on success, negative on failure
2321 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002322int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323{
Bruce Allan55aa6982011-12-16 00:45:45 +00002324 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002325 struct e1000_buffer *buffer_info;
2326 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327
2328 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002329 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 if (!rx_ring->buffer_info)
2331 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332
Auke Kok47f44e42007-10-25 13:57:44 -07002333 for (i = 0; i < rx_ring->count; i++) {
2334 buffer_info = &rx_ring->buffer_info[i];
2335 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2336 sizeof(struct e1000_ps_page),
2337 GFP_KERNEL);
2338 if (!buffer_info->ps_pages)
2339 goto err_pages;
2340 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341
2342 desc_len = sizeof(union e1000_rx_desc_packet_split);
2343
2344 /* Round up to nearest 4K */
2345 rx_ring->size = rx_ring->count * desc_len;
2346 rx_ring->size = ALIGN(rx_ring->size, 4096);
2347
2348 err = e1000_alloc_ring_dma(adapter, rx_ring);
2349 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002350 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351
2352 rx_ring->next_to_clean = 0;
2353 rx_ring->next_to_use = 0;
2354 rx_ring->rx_skb_top = NULL;
2355
2356 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002357
2358err_pages:
2359 for (i = 0; i < rx_ring->count; i++) {
2360 buffer_info = &rx_ring->buffer_info[i];
2361 kfree(buffer_info->ps_pages);
2362 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363err:
2364 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002365 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 return err;
2367}
2368
2369/**
2370 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002371 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002373static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002374{
Bruce Allan55aa6982011-12-16 00:45:45 +00002375 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002376 struct e1000_buffer *buffer_info;
2377 unsigned long size;
2378 unsigned int i;
2379
2380 for (i = 0; i < tx_ring->count; i++) {
2381 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002382 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 }
2384
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002385 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 size = sizeof(struct e1000_buffer) * tx_ring->count;
2387 memset(tx_ring->buffer_info, 0, size);
2388
2389 memset(tx_ring->desc, 0, tx_ring->size);
2390
2391 tx_ring->next_to_use = 0;
2392 tx_ring->next_to_clean = 0;
2393
Bruce Allanc5083cf2011-12-16 00:45:40 +00002394 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002395 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2396 e1000e_update_tdt_wa(tx_ring, 0);
2397 else
2398 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399}
2400
2401/**
2402 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002403 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 *
2405 * Free all transmit software resources
2406 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002407void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002408{
Bruce Allan55aa6982011-12-16 00:45:45 +00002409 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411
Bruce Allan55aa6982011-12-16 00:45:45 +00002412 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413
2414 vfree(tx_ring->buffer_info);
2415 tx_ring->buffer_info = NULL;
2416
2417 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2418 tx_ring->dma);
2419 tx_ring->desc = NULL;
2420}
2421
2422/**
2423 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002424 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 *
2426 * Free all receive software resources
2427 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002428void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429{
Bruce Allan55aa6982011-12-16 00:45:45 +00002430 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002432 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002433
Bruce Allan55aa6982011-12-16 00:45:45 +00002434 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002436 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002437 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002438
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 vfree(rx_ring->buffer_info);
2440 rx_ring->buffer_info = NULL;
2441
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2443 rx_ring->dma);
2444 rx_ring->desc = NULL;
2445}
2446
2447/**
2448 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002449 * @adapter: pointer to adapter
2450 * @itr_setting: current adapter->itr
2451 * @packets: the number of packets during this measurement interval
2452 * @bytes: the number of bytes during this measurement interval
2453 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 * Stores a new ITR value based on packets and byte
2455 * counts during the last interrupt. The advantage of per interrupt
2456 * computation is faster updates and more accurate ITR for the current
2457 * traffic pattern. Constants in this function were computed
2458 * based on theoretical maximum wire speed and thresholds were set based
2459 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002460 * while increasing bulk throughput. This functionality is controlled
2461 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462 **/
2463static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2464 u16 itr_setting, int packets,
2465 int bytes)
2466{
2467 unsigned int retval = itr_setting;
2468
2469 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002470 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471
2472 switch (itr_setting) {
2473 case lowest_latency:
2474 /* handle TSO and jumbo frames */
2475 if (bytes/packets > 8000)
2476 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002477 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002479 break;
2480 case low_latency: /* 50 usec aka 20000 ints/s */
2481 if (bytes > 10000) {
2482 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002483 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002485 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002486 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002487 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002489 } else if (bytes/packets > 2000) {
2490 retval = bulk_latency;
2491 } else if (packets <= 2 && bytes < 512) {
2492 retval = lowest_latency;
2493 }
2494 break;
2495 case bulk_latency: /* 250 usec aka 4000 ints/s */
2496 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002497 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002499 } else if (bytes < 6000) {
2500 retval = low_latency;
2501 }
2502 break;
2503 }
2504
Auke Kokbc7f75f2007-09-17 12:30:59 -07002505 return retval;
2506}
2507
2508static void e1000_set_itr(struct e1000_adapter *adapter)
2509{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 u16 current_itr;
2511 u32 new_itr = adapter->itr;
2512
2513 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2514 if (adapter->link_speed != SPEED_1000) {
2515 current_itr = 0;
2516 new_itr = 4000;
2517 goto set_itr_now;
2518 }
2519
Bruce Allan828bac82010-09-29 21:39:37 +00002520 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2521 new_itr = 0;
2522 goto set_itr_now;
2523 }
2524
Auke Kokbc7f75f2007-09-17 12:30:59 -07002525 adapter->tx_itr = e1000_update_itr(adapter,
2526 adapter->tx_itr,
2527 adapter->total_tx_packets,
2528 adapter->total_tx_bytes);
2529 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2530 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2531 adapter->tx_itr = low_latency;
2532
2533 adapter->rx_itr = e1000_update_itr(adapter,
2534 adapter->rx_itr,
2535 adapter->total_rx_packets,
2536 adapter->total_rx_bytes);
2537 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2538 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2539 adapter->rx_itr = low_latency;
2540
2541 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2542
2543 switch (current_itr) {
2544 /* counts and packets in update_itr are dependent on these numbers */
2545 case lowest_latency:
2546 new_itr = 70000;
2547 break;
2548 case low_latency:
2549 new_itr = 20000; /* aka hwitr = ~200 */
2550 break;
2551 case bulk_latency:
2552 new_itr = 4000;
2553 break;
2554 default:
2555 break;
2556 }
2557
2558set_itr_now:
2559 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002560 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002562 * increasing
2563 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 new_itr = new_itr > adapter->itr ?
2565 min(adapter->itr + (new_itr >> 2), new_itr) :
2566 new_itr;
2567 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002568 adapter->rx_ring->itr_val = new_itr;
2569 if (adapter->msix_entries)
2570 adapter->rx_ring->set_itr = 1;
2571 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002572 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573 }
2574}
2575
2576/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002577 * e1000e_write_itr - write the ITR value to the appropriate registers
2578 * @adapter: address of board private structure
2579 * @itr: new ITR value to program
2580 *
2581 * e1000e_write_itr determines if the adapter is in MSI-X mode
2582 * and, if so, writes the EITR registers with the ITR value.
2583 * Otherwise, it writes the ITR value into the ITR register.
2584 **/
2585void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2586{
2587 struct e1000_hw *hw = &adapter->hw;
2588 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2589
2590 if (adapter->msix_entries) {
2591 int vector;
2592
2593 for (vector = 0; vector < adapter->num_vectors; vector++)
2594 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2595 } else {
2596 ew32(ITR, new_itr);
2597 }
2598}
2599
2600/**
Bruce Allan4662e822008-08-26 18:37:06 -07002601 * e1000_alloc_queues - Allocate memory for all rings
2602 * @adapter: board private structure to initialize
2603 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002604static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002605{
Bruce Allan55aa6982011-12-16 00:45:45 +00002606 int size = sizeof(struct e1000_ring);
2607
2608 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002609 if (!adapter->tx_ring)
2610 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002611 adapter->tx_ring->count = adapter->tx_ring_count;
2612 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002613
Bruce Allan55aa6982011-12-16 00:45:45 +00002614 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002615 if (!adapter->rx_ring)
2616 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002617 adapter->rx_ring->count = adapter->rx_ring_count;
2618 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002619
2620 return 0;
2621err:
2622 e_err("Unable to allocate memory for queues\n");
2623 kfree(adapter->rx_ring);
2624 kfree(adapter->tx_ring);
2625 return -ENOMEM;
2626}
2627
2628/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002629 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002630 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002631 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002632 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002633static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002634{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002635 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2636 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002637 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002638 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002639 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002640
Wang Chen4cf16532008-11-12 23:38:14 -08002641 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002642
Bruce Allanc58c8a72012-03-20 03:48:19 +00002643 if (!adapter->msix_entries ||
2644 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2645 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002646
Bruce Allanc58c8a72012-03-20 03:48:19 +00002647 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002648
Alexander Duyck12d04a32009-03-25 22:05:03 +00002649 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002650 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002651
Bruce Allanc58c8a72012-03-20 03:48:19 +00002652 /* If weight not fully consumed, exit the polling mode */
2653 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002654 if (adapter->itr_setting & 3)
2655 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002656 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002657 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2658 if (adapter->msix_entries)
2659 ew32(IMS, adapter->rx_ring->ims_val);
2660 else
2661 e1000_irq_enable(adapter);
2662 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 }
2664
2665 return work_done;
2666}
2667
Jiri Pirko8e586132011-12-08 19:52:37 -05002668static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669{
2670 struct e1000_adapter *adapter = netdev_priv(netdev);
2671 struct e1000_hw *hw = &adapter->hw;
2672 u32 vfta, index;
2673
2674 /* don't update vlan cookie if already programmed */
2675 if ((adapter->hw.mng_cookie.status &
2676 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2677 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002678 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002679
Auke Kokbc7f75f2007-09-17 12:30:59 -07002680 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002681 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2682 index = (vid >> 5) & 0x7F;
2683 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2684 vfta |= (1 << (vid & 0x1F));
2685 hw->mac.ops.write_vfta(hw, index, vfta);
2686 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002687
2688 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002689
2690 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691}
2692
Jiri Pirko8e586132011-12-08 19:52:37 -05002693static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694{
2695 struct e1000_adapter *adapter = netdev_priv(netdev);
2696 struct e1000_hw *hw = &adapter->hw;
2697 u32 vfta, index;
2698
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699 if ((adapter->hw.mng_cookie.status &
2700 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2701 (vid == adapter->mng_vlan_id)) {
2702 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002703 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002704 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 }
2706
2707 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002708 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2709 index = (vid >> 5) & 0x7F;
2710 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2711 vfta &= ~(1 << (vid & 0x1F));
2712 hw->mac.ops.write_vfta(hw, index, vfta);
2713 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002714
2715 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002716
2717 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002718}
2719
2720/**
2721 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2722 * @adapter: board private structure to initialize
2723 **/
2724static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2725{
2726 struct net_device *netdev = adapter->netdev;
2727 struct e1000_hw *hw = &adapter->hw;
2728 u32 rctl;
2729
2730 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2731 /* disable VLAN receive filtering */
2732 rctl = er32(RCTL);
2733 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2734 ew32(RCTL, rctl);
2735
2736 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2737 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2738 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2739 }
2740 }
2741}
2742
2743/**
2744 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2745 * @adapter: board private structure to initialize
2746 **/
2747static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2748{
2749 struct e1000_hw *hw = &adapter->hw;
2750 u32 rctl;
2751
2752 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2753 /* enable VLAN receive filtering */
2754 rctl = er32(RCTL);
2755 rctl |= E1000_RCTL_VFE;
2756 rctl &= ~E1000_RCTL_CFIEN;
2757 ew32(RCTL, rctl);
2758 }
2759}
2760
2761/**
2762 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2763 * @adapter: board private structure to initialize
2764 **/
2765static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2766{
2767 struct e1000_hw *hw = &adapter->hw;
2768 u32 ctrl;
2769
2770 /* disable VLAN tag insert/strip */
2771 ctrl = er32(CTRL);
2772 ctrl &= ~E1000_CTRL_VME;
2773 ew32(CTRL, ctrl);
2774}
2775
2776/**
2777 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2778 * @adapter: board private structure to initialize
2779 **/
2780static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2781{
2782 struct e1000_hw *hw = &adapter->hw;
2783 u32 ctrl;
2784
2785 /* enable VLAN tag insert/strip */
2786 ctrl = er32(CTRL);
2787 ctrl |= E1000_CTRL_VME;
2788 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002789}
2790
2791static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2792{
2793 struct net_device *netdev = adapter->netdev;
2794 u16 vid = adapter->hw.mng_cookie.vlan_id;
2795 u16 old_vid = adapter->mng_vlan_id;
2796
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002797 if (adapter->hw.mng_cookie.status &
2798 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2799 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002800 adapter->mng_vlan_id = vid;
2801 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002802
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002803 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2804 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805}
2806
2807static void e1000_restore_vlan(struct e1000_adapter *adapter)
2808{
2809 u16 vid;
2810
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002811 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002813 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002814 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815}
2816
Bruce Allancd791612010-05-10 14:59:51 +00002817static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818{
2819 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002820 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821
2822 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2823 return;
2824
2825 manc = er32(MANC);
2826
Bruce Allane921eb12012-11-28 09:28:37 +00002827 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002829 * the packets will be handled on SMBUS
2830 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 manc |= E1000_MANC_EN_MNG2HOST;
2832 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002833
2834 switch (hw->mac.type) {
2835 default:
2836 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2837 break;
2838 case e1000_82574:
2839 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002840 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002841 * if so, enable it.
2842 */
2843 for (i = 0, j = 0; i < 8; i++) {
2844 mdef = er32(MDEF(i));
2845
2846 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002847 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002848 continue;
2849
2850 /* Enable this decision filter in MANC2H */
2851 if (mdef)
2852 manc2h |= (1 << i);
2853
2854 j |= mdef;
2855 }
2856
2857 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2858 break;
2859
2860 /* Create new decision filter in an empty filter */
2861 for (i = 0, j = 0; i < 8; i++)
2862 if (er32(MDEF(i)) == 0) {
2863 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2864 E1000_MDEF_PORT_664));
2865 manc2h |= (1 << 1);
2866 j++;
2867 break;
2868 }
2869
2870 if (!j)
2871 e_warn("Unable to create IPMI pass-through filter\n");
2872 break;
2873 }
2874
Auke Kokbc7f75f2007-09-17 12:30:59 -07002875 ew32(MANC2H, manc2h);
2876 ew32(MANC, manc);
2877}
2878
2879/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002880 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 * @adapter: board private structure
2882 *
2883 * Configure the Tx unit of the MAC after a reset.
2884 **/
2885static void e1000_configure_tx(struct e1000_adapter *adapter)
2886{
2887 struct e1000_hw *hw = &adapter->hw;
2888 struct e1000_ring *tx_ring = adapter->tx_ring;
2889 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002890 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002891
2892 /* Setup the HW Tx Head and Tail descriptor pointers */
2893 tdba = tx_ring->dma;
2894 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002895 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2896 ew32(TDBAH(0), (tdba >> 32));
2897 ew32(TDLEN(0), tdlen);
2898 ew32(TDH(0), 0);
2899 ew32(TDT(0), 0);
2900 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2901 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903 /* Set the Tx Interrupt Delay register */
2904 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002905 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 ew32(TADV, adapter->tx_abs_int_delay);
2907
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002908 if (adapter->flags2 & FLAG2_DMA_BURST) {
2909 u32 txdctl = er32(TXDCTL(0));
2910 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2911 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002912 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002913 * hardware to use the bus more efficiently in bursts, depends
2914 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002915 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002916 * hthresh = 1 ==> prefetch when one or more available
2917 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2918 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002919 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002920 */
2921 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2922 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002923 }
Bruce Allan56032be2011-12-16 00:46:01 +00002924 /* erratum work around: set txdctl the same for both queues */
2925 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002926
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002928 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002929 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002930 * gigabit link later
2931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002932#define SPEED_MODE_BIT (1 << 21)
2933 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002934 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935 }
2936
2937 /* errata: program both queues to unweighted RR */
2938 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002939 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002941 ew32(TARC(0), tarc);
2942 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002944 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002945 }
2946
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 /* Setup Transmit Descriptor Settings for eop descriptor */
2948 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2949
2950 /* only set IDE if we are delaying interrupts using the timers */
2951 if (adapter->tx_int_delay)
2952 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2953
2954 /* enable Report Status bit */
2955 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2956
Bruce Allan57cde762012-02-22 09:02:58 +00002957 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958}
2959
2960/**
2961 * e1000_setup_rctl - configure the receive control registers
2962 * @adapter: Board private structure
2963 **/
2964#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2965 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2966static void e1000_setup_rctl(struct e1000_adapter *adapter)
2967{
2968 struct e1000_hw *hw = &adapter->hw;
2969 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970 u32 pages = 0;
2971
Bruce Allan2fbe4522012-04-19 03:21:47 +00002972 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2973 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002974 s32 ret_val;
2975
2976 if (adapter->netdev->mtu > ETH_DATA_LEN)
2977 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2978 else
2979 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002980
2981 if (ret_val)
2982 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002983 }
2984
Auke Kokbc7f75f2007-09-17 12:30:59 -07002985 /* Program MC offset vector base */
2986 rctl = er32(RCTL);
2987 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2988 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
2989 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
2990 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2991
2992 /* Do not Store bad packets */
2993 rctl &= ~E1000_RCTL_SBP;
2994
2995 /* Enable Long Packet receive */
2996 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2997 rctl &= ~E1000_RCTL_LPE;
2998 else
2999 rctl |= E1000_RCTL_LPE;
3000
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003001 /* Some systems expect that the CRC is included in SMBUS traffic. The
3002 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3003 * host memory when this is enabled
3004 */
3005 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3006 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003007
Bruce Allana4f58f52009-06-02 11:29:18 +00003008 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3009 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3010 u16 phy_data;
3011
3012 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3013 phy_data &= 0xfff8;
3014 phy_data |= (1 << 2);
3015 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3016
3017 e1e_rphy(hw, 22, &phy_data);
3018 phy_data &= 0x0fff;
3019 phy_data |= (1 << 14);
3020 e1e_wphy(hw, 0x10, 0x2823);
3021 e1e_wphy(hw, 0x11, 0x0003);
3022 e1e_wphy(hw, 22, phy_data);
3023 }
3024
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025 /* Setup buffer sizes */
3026 rctl &= ~E1000_RCTL_SZ_4096;
3027 rctl |= E1000_RCTL_BSEX;
3028 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029 case 2048:
3030 default:
3031 rctl |= E1000_RCTL_SZ_2048;
3032 rctl &= ~E1000_RCTL_BSEX;
3033 break;
3034 case 4096:
3035 rctl |= E1000_RCTL_SZ_4096;
3036 break;
3037 case 8192:
3038 rctl |= E1000_RCTL_SZ_8192;
3039 break;
3040 case 16384:
3041 rctl |= E1000_RCTL_SZ_16384;
3042 break;
3043 }
3044
Bruce Allan5f450212011-07-22 06:21:46 +00003045 /* Enable Extended Status in all Receive Descriptors */
3046 rfctl = er32(RFCTL);
3047 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003048 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003049
Bruce Allane921eb12012-11-28 09:28:37 +00003050 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003051 * header is placed in skb->data and the packet data is
3052 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3053 * In the case of a non-split, skb->data is linearly filled,
3054 * followed by the page buffers. Therefore, skb->data is
3055 * sized to hold the largest protocol header.
3056 *
3057 * allocations using alloc_page take too long for regular MTU
3058 * so only enable packet split for jumbo frames
3059 *
3060 * Using pages when the page size is greater than 16k wastes
3061 * a lot of memory, since we allocate 3 pages at all times
3062 * per packet.
3063 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003064 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003065 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003066 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003067 else
3068 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003069
3070 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003071 u32 psrctl = 0;
3072
Auke Kok140a7482007-10-25 13:57:58 -07003073 /* Enable Packet split descriptors */
3074 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003075
3076 psrctl |= adapter->rx_ps_bsize0 >>
3077 E1000_PSRCTL_BSIZE0_SHIFT;
3078
3079 switch (adapter->rx_ps_pages) {
3080 case 3:
3081 psrctl |= PAGE_SIZE <<
3082 E1000_PSRCTL_BSIZE3_SHIFT;
3083 case 2:
3084 psrctl |= PAGE_SIZE <<
3085 E1000_PSRCTL_BSIZE2_SHIFT;
3086 case 1:
3087 psrctl |= PAGE_SIZE >>
3088 E1000_PSRCTL_BSIZE1_SHIFT;
3089 break;
3090 }
3091
3092 ew32(PSRCTL, psrctl);
3093 }
3094
Ben Greearcf955e62012-02-11 15:39:51 +00003095 /* This is useful for sniffing bad packets. */
3096 if (adapter->netdev->features & NETIF_F_RXALL) {
3097 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003098 * in e1000e_set_rx_mode
3099 */
Ben Greearcf955e62012-02-11 15:39:51 +00003100 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3101 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3102 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3103
3104 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3105 E1000_RCTL_DPF | /* Allow filtered pause */
3106 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3107 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3108 * and that breaks VLANs.
3109 */
3110 }
3111
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003113 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003114 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115}
3116
3117/**
3118 * e1000_configure_rx - Configure Receive Unit after Reset
3119 * @adapter: board private structure
3120 *
3121 * Configure the Rx unit of the MAC after a reset.
3122 **/
3123static void e1000_configure_rx(struct e1000_adapter *adapter)
3124{
3125 struct e1000_hw *hw = &adapter->hw;
3126 struct e1000_ring *rx_ring = adapter->rx_ring;
3127 u64 rdba;
3128 u32 rdlen, rctl, rxcsum, ctrl_ext;
3129
3130 if (adapter->rx_ps_pages) {
3131 /* this is a 32 byte descriptor */
3132 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003133 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003134 adapter->clean_rx = e1000_clean_rx_irq_ps;
3135 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003136 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003137 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003138 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3139 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003140 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003141 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003142 adapter->clean_rx = e1000_clean_rx_irq;
3143 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3144 }
3145
3146 /* disable receives while setting up the descriptors */
3147 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003148 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3149 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003151 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003153 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003154 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003155 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003156 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003157 * granularity = 01
3158 * wthresh = 04,
3159 * hthresh = 04,
3160 * pthresh = 0x20
3161 */
3162 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3163 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3164
Bruce Allane921eb12012-11-28 09:28:37 +00003165 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003166 * the value was not set by the user via module options
3167 */
3168 if (adapter->rx_int_delay == DEFAULT_RDTR)
3169 adapter->rx_int_delay = BURST_RDTR;
3170 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3171 adapter->rx_abs_int_delay = BURST_RADV;
3172 }
3173
Auke Kokbc7f75f2007-09-17 12:30:59 -07003174 /* set the Receive Delay Timer Register */
3175 ew32(RDTR, adapter->rx_int_delay);
3176
3177 /* irq moderation */
3178 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003179 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003180 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181
3182 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003183 /* Auto-Mask interrupts upon ICR access */
3184 ctrl_ext |= E1000_CTRL_EXT_IAME;
3185 ew32(IAM, 0xffffffff);
3186 ew32(CTRL_EXT, ctrl_ext);
3187 e1e_flush();
3188
Bruce Allane921eb12012-11-28 09:28:37 +00003189 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003190 * the Base and Length of the Rx Descriptor Ring
3191 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003192 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003193 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3194 ew32(RDBAH(0), (rdba >> 32));
3195 ew32(RDLEN(0), rdlen);
3196 ew32(RDH(0), 0);
3197 ew32(RDT(0), 0);
3198 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3199 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003200
3201 /* Enable Receive Checksum Offload for TCP and UDP */
3202 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003203 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003205 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 ew32(RXCSUM, rxcsum);
3208
Bruce Allan79d4e902011-12-16 00:46:27 +00003209 if (adapter->hw.mac.type == e1000_pch2lan) {
Bruce Allane921eb12012-11-28 09:28:37 +00003210 /* With jumbo frames, excessive C-state transition
Bruce Allan79d4e902011-12-16 00:46:27 +00003211 * latencies result in dropped transactions.
3212 */
Bruce Allan53ec5492009-11-20 23:27:40 +00003213 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3214 u32 rxdctl = er32(RXDCTL(0));
3215 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allanaf667a22010-12-31 06:10:01 +00003216 pm_qos_update_request(&adapter->netdev->pm_qos_req, 55);
Bruce Allan53ec5492009-11-20 23:27:40 +00003217 } else {
Bruce Allanaf667a22010-12-31 06:10:01 +00003218 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3219 PM_QOS_DEFAULT_VALUE);
Bruce Allan53ec5492009-11-20 23:27:40 +00003220 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003221 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003222
3223 /* Enable Receives */
3224 ew32(RCTL, rctl);
3225}
3226
3227/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003228 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003229 * @netdev: network interface device structure
3230 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003231 * Writes multicast address list to the MTA hash table.
3232 * Returns: -ENOMEM on failure
3233 * 0 on no addresses written
3234 * X on writing X addresses to MTA
3235 */
3236static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237{
3238 struct e1000_adapter *adapter = netdev_priv(netdev);
3239 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003240 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003241 u8 *mta_list;
3242 int i;
3243
3244 if (netdev_mc_empty(netdev)) {
3245 /* nothing to program, so clear mc list */
3246 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3247 return 0;
3248 }
3249
3250 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3251 if (!mta_list)
3252 return -ENOMEM;
3253
3254 /* update_mc_addr_list expects a packed array of only addresses. */
3255 i = 0;
3256 netdev_for_each_mc_addr(ha, netdev)
3257 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3258
3259 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3260 kfree(mta_list);
3261
3262 return netdev_mc_count(netdev);
3263}
3264
3265/**
3266 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3267 * @netdev: network interface device structure
3268 *
3269 * Writes unicast address list to the RAR table.
3270 * Returns: -ENOMEM on failure/insufficient address space
3271 * 0 on no addresses written
3272 * X on writing X addresses to the RAR table
3273 **/
3274static int e1000e_write_uc_addr_list(struct net_device *netdev)
3275{
3276 struct e1000_adapter *adapter = netdev_priv(netdev);
3277 struct e1000_hw *hw = &adapter->hw;
3278 unsigned int rar_entries = hw->mac.rar_entry_count;
3279 int count = 0;
3280
3281 /* save a rar entry for our hardware address */
3282 rar_entries--;
3283
3284 /* save a rar entry for the LAA workaround */
3285 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3286 rar_entries--;
3287
3288 /* return ENOMEM indicating insufficient memory for addresses */
3289 if (netdev_uc_count(netdev) > rar_entries)
3290 return -ENOMEM;
3291
3292 if (!netdev_uc_empty(netdev) && rar_entries) {
3293 struct netdev_hw_addr *ha;
3294
Bruce Allane921eb12012-11-28 09:28:37 +00003295 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003296 * combining
3297 */
3298 netdev_for_each_uc_addr(ha, netdev) {
3299 if (!rar_entries)
3300 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003301 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003302 count++;
3303 }
3304 }
3305
3306 /* zero out the remaining RAR entries not used above */
3307 for (; rar_entries > 0; rar_entries--) {
3308 ew32(RAH(rar_entries), 0);
3309 ew32(RAL(rar_entries), 0);
3310 }
3311 e1e_flush();
3312
3313 return count;
3314}
3315
3316/**
3317 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3318 * @netdev: network interface device structure
3319 *
3320 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3321 * address list or the network interface flags are updated. This routine is
3322 * responsible for configuring the hardware for proper unicast, multicast,
3323 * promiscuous mode, and all-multi behavior.
3324 **/
3325static void e1000e_set_rx_mode(struct net_device *netdev)
3326{
3327 struct e1000_adapter *adapter = netdev_priv(netdev);
3328 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330
3331 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 rctl = er32(RCTL);
3333
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003334 /* clear the affected bits */
3335 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3336
Auke Kokbc7f75f2007-09-17 12:30:59 -07003337 if (netdev->flags & IFF_PROMISC) {
3338 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003339 /* Do not hardware filter VLANs in promisc mode */
3340 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003342 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003343
Patrick McHardy746b9f02008-07-16 20:15:45 -07003344 if (netdev->flags & IFF_ALLMULTI) {
3345 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003346 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003347 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003348 * then we should just turn on promiscuous mode so
3349 * that we can at least receive multicast traffic
3350 */
3351 count = e1000e_write_mc_addr_list(netdev);
3352 if (count < 0)
3353 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003354 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003355 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003356 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003357 * sufficient space to store all the addresses then enable
3358 * unicast promiscuous mode
3359 */
3360 count = e1000e_write_uc_addr_list(netdev);
3361 if (count < 0)
3362 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 }
3364
3365 ew32(RCTL, rctl);
3366
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003367 if (netdev->features & NETIF_F_HW_VLAN_RX)
3368 e1000e_vlan_strip_enable(adapter);
3369 else
3370 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371}
3372
Bruce Allan70495a52012-01-11 01:26:50 +00003373static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3374{
3375 struct e1000_hw *hw = &adapter->hw;
3376 u32 mrqc, rxcsum;
3377 int i;
3378 static const u32 rsskey[10] = {
3379 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3380 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3381 };
3382
3383 /* Fill out hash function seed */
3384 for (i = 0; i < 10; i++)
3385 ew32(RSSRK(i), rsskey[i]);
3386
3387 /* Direct all traffic to queue 0 */
3388 for (i = 0; i < 32; i++)
3389 ew32(RETA(i), 0);
3390
Bruce Allane921eb12012-11-28 09:28:37 +00003391 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003392 * descriptor on writeback.
3393 */
3394 rxcsum = er32(RXCSUM);
3395 rxcsum |= E1000_RXCSUM_PCSD;
3396
3397 ew32(RXCSUM, rxcsum);
3398
3399 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3400 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3401 E1000_MRQC_RSS_FIELD_IPV6 |
3402 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3403 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3404
3405 ew32(MRQC, mrqc);
3406}
3407
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003409 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3410 * @adapter: board private structure
3411 * @timinca: pointer to returned time increment attributes
3412 *
3413 * Get attributes for incrementing the System Time Register SYSTIML/H at
3414 * the default base frequency, and set the cyclecounter shift value.
3415 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003416s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003417{
3418 struct e1000_hw *hw = &adapter->hw;
3419 u32 incvalue, incperiod, shift;
3420
3421 /* Make sure clock is enabled on I217 before checking the frequency */
3422 if ((hw->mac.type == e1000_pch_lpt) &&
3423 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3424 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3425 u32 fextnvm7 = er32(FEXTNVM7);
3426
3427 if (!(fextnvm7 & (1 << 0))) {
3428 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3429 e1e_flush();
3430 }
3431 }
3432
3433 switch (hw->mac.type) {
3434 case e1000_pch2lan:
3435 case e1000_pch_lpt:
3436 /* On I217, the clock frequency is 25MHz or 96MHz as
3437 * indicated by the System Clock Frequency Indication
3438 */
3439 if ((hw->mac.type != e1000_pch_lpt) ||
3440 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3441 /* Stable 96MHz frequency */
3442 incperiod = INCPERIOD_96MHz;
3443 incvalue = INCVALUE_96MHz;
3444 shift = INCVALUE_SHIFT_96MHz;
3445 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3446 break;
3447 }
3448 /* fall-through */
3449 case e1000_82574:
3450 case e1000_82583:
3451 /* Stable 25MHz frequency */
3452 incperiod = INCPERIOD_25MHz;
3453 incvalue = INCVALUE_25MHz;
3454 shift = INCVALUE_SHIFT_25MHz;
3455 adapter->cc.shift = shift;
3456 break;
3457 default:
3458 return -EINVAL;
3459 }
3460
3461 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3462 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3463
3464 return 0;
3465}
3466
3467/**
3468 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3469 * @adapter: board private structure
3470 *
3471 * Outgoing time stamping can be enabled and disabled. Play nice and
3472 * disable it when requested, although it shouldn't cause any overhead
3473 * when no packet needs it. At most one packet in the queue may be
3474 * marked for time stamping, otherwise it would be impossible to tell
3475 * for sure to which packet the hardware time stamp belongs.
3476 *
3477 * Incoming time stamping has to be configured via the hardware filters.
3478 * Not all combinations are supported, in particular event type has to be
3479 * specified. Matching the kind of event packet is not supported, with the
3480 * exception of "all V2 events regardless of level 2 or 4".
3481 **/
3482static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3483{
3484 struct e1000_hw *hw = &adapter->hw;
3485 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3486 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3487 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003488 u32 rxmtrl = 0;
3489 u16 rxudp = 0;
3490 bool is_l4 = false;
3491 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003492 u32 regval;
3493 s32 ret_val;
3494
3495 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3496 return -EINVAL;
3497
3498 /* flags reserved for future extensions - must be zero */
3499 if (config->flags)
3500 return -EINVAL;
3501
3502 switch (config->tx_type) {
3503 case HWTSTAMP_TX_OFF:
3504 tsync_tx_ctl = 0;
3505 break;
3506 case HWTSTAMP_TX_ON:
3507 break;
3508 default:
3509 return -ERANGE;
3510 }
3511
3512 switch (config->rx_filter) {
3513 case HWTSTAMP_FILTER_NONE:
3514 tsync_rx_ctl = 0;
3515 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003516 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3517 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3518 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3519 is_l4 = true;
3520 break;
3521 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3522 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3523 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3524 is_l4 = true;
3525 break;
3526 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3527 /* Also time stamps V2 L2 Path Delay Request/Response */
3528 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3529 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3530 is_l2 = true;
3531 break;
3532 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3533 /* Also time stamps V2 L2 Path Delay Request/Response. */
3534 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3535 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3536 is_l2 = true;
3537 break;
3538 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3539 /* Hardware cannot filter just V2 L4 Sync messages;
3540 * fall-through to V2 (both L2 and L4) Sync.
3541 */
3542 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3543 /* Also time stamps V2 Path Delay Request/Response. */
3544 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3545 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3546 is_l2 = true;
3547 is_l4 = true;
3548 break;
3549 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3550 /* Hardware cannot filter just V2 L4 Delay Request messages;
3551 * fall-through to V2 (both L2 and L4) Delay Request.
3552 */
3553 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3554 /* Also time stamps V2 Path Delay Request/Response. */
3555 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3556 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3557 is_l2 = true;
3558 is_l4 = true;
3559 break;
3560 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3561 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3562 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3563 * fall-through to all V2 (both L2 and L4) Events.
3564 */
3565 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3566 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3567 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3568 is_l2 = true;
3569 is_l4 = true;
3570 break;
3571 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3572 /* For V1, the hardware can only filter Sync messages or
3573 * Delay Request messages but not both so fall-through to
3574 * time stamp all packets.
3575 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003576 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003577 is_l2 = true;
3578 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003579 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3580 config->rx_filter = HWTSTAMP_FILTER_ALL;
3581 break;
3582 default:
3583 return -ERANGE;
3584 }
3585
3586 /* enable/disable Tx h/w time stamping */
3587 regval = er32(TSYNCTXCTL);
3588 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3589 regval |= tsync_tx_ctl;
3590 ew32(TSYNCTXCTL, regval);
3591 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3592 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3593 e_err("Timesync Tx Control register not set as expected\n");
3594 return -EAGAIN;
3595 }
3596
3597 /* enable/disable Rx h/w time stamping */
3598 regval = er32(TSYNCRXCTL);
3599 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3600 regval |= tsync_rx_ctl;
3601 ew32(TSYNCRXCTL, regval);
3602 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3603 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3604 (regval & (E1000_TSYNCRXCTL_ENABLED |
3605 E1000_TSYNCRXCTL_TYPE_MASK))) {
3606 e_err("Timesync Rx Control register not set as expected\n");
3607 return -EAGAIN;
3608 }
3609
Bruce Alland89777b2013-01-19 01:09:58 +00003610 /* L2: define ethertype filter for time stamped packets */
3611 if (is_l2)
3612 rxmtrl |= ETH_P_1588;
3613
3614 /* define which PTP packets get time stamped */
3615 ew32(RXMTRL, rxmtrl);
3616
3617 /* Filter by destination port */
3618 if (is_l4) {
3619 rxudp = PTP_EV_PORT;
3620 cpu_to_be16s(&rxudp);
3621 }
3622 ew32(RXUDP, rxudp);
3623
3624 e1e_flush();
3625
Bruce Allanb67e1912012-12-27 08:32:33 +00003626 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
3627 regval = er32(RXSTMPH);
3628 regval = er32(TXSTMPH);
3629
3630 /* Get and set the System Time Register SYSTIM base frequency */
3631 ret_val = e1000e_get_base_timinca(adapter, &regval);
3632 if (ret_val)
3633 return ret_val;
3634 ew32(TIMINCA, regval);
3635
3636 /* reset the ns time counter */
3637 timecounter_init(&adapter->tc, &adapter->cc,
3638 ktime_to_ns(ktime_get_real()));
3639
3640 return 0;
3641}
3642
3643/**
Bruce Allanad680762008-03-28 09:15:03 -07003644 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645 * @adapter: private board structure
3646 **/
3647static void e1000_configure(struct e1000_adapter *adapter)
3648{
Bruce Allan55aa6982011-12-16 00:45:45 +00003649 struct e1000_ring *rx_ring = adapter->rx_ring;
3650
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003651 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003652
3653 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003654 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655
3656 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003657
3658 if (adapter->netdev->features & NETIF_F_RXHASH)
3659 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003660 e1000_setup_rctl(adapter);
3661 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003662 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003663}
3664
3665/**
3666 * e1000e_power_up_phy - restore link in case the phy was powered down
3667 * @adapter: address of board private structure
3668 *
3669 * The phy may be powered down to save power and turn off link when the
3670 * driver is unloaded and wake on lan is not enabled (among others)
3671 * *** this routine MUST be followed by a call to e1000e_reset ***
3672 **/
3673void e1000e_power_up_phy(struct e1000_adapter *adapter)
3674{
Bruce Allan17f208d2009-12-01 15:47:22 +00003675 if (adapter->hw.phy.ops.power_up)
3676 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677
3678 adapter->hw.mac.ops.setup_link(&adapter->hw);
3679}
3680
3681/**
3682 * e1000_power_down_phy - Power down the PHY
3683 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003684 * Power down the PHY so no link is implied when interface is down.
3685 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 */
3687static void e1000_power_down_phy(struct e1000_adapter *adapter)
3688{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003689 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003690 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 return;
3692
Bruce Allan17f208d2009-12-01 15:47:22 +00003693 if (adapter->hw.phy.ops.power_down)
3694 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695}
3696
3697/**
3698 * e1000e_reset - bring the hardware into a known good state
3699 *
3700 * This function boots the hardware and enables some settings that
3701 * require a configuration cycle of the hardware - those cannot be
3702 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003703 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003704 */
3705void e1000e_reset(struct e1000_adapter *adapter)
3706{
3707 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003708 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709 struct e1000_hw *hw = &adapter->hw;
3710 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003711 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712 u16 hwm;
3713
Bruce Allanad680762008-03-28 09:15:03 -07003714 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003715 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003716
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003717 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003718 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719 * large enough to accommodate two full transmit packets,
3720 * rounded up to the next 1KB and expressed in KB. Likewise,
3721 * the Rx FIFO should be large enough to accommodate at least
3722 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003723 * expressed in KB.
3724 */
Auke Kokdf762462007-10-25 13:57:53 -07003725 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003727 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003729 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003730 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003731 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003732 */
3733 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003734 sizeof(struct e1000_tx_desc) -
3735 ETH_FCS_LEN) * 2;
3736 min_tx_space = ALIGN(min_tx_space, 1024);
3737 min_tx_space >>= 10;
3738 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003739 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740 min_rx_space = ALIGN(min_rx_space, 1024);
3741 min_rx_space >>= 10;
3742
Bruce Allane921eb12012-11-28 09:28:37 +00003743 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003745 * allocation, take space away from current Rx allocation
3746 */
Auke Kokdf762462007-10-25 13:57:53 -07003747 if ((tx_space < min_tx_space) &&
3748 ((min_tx_space - tx_space) < pba)) {
3749 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750
Bruce Allane921eb12012-11-28 09:28:37 +00003751 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003752 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003753 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003754 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003755 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756 }
Auke Kokdf762462007-10-25 13:57:53 -07003757
3758 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 }
3760
Bruce Allane921eb12012-11-28 09:28:37 +00003761 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003762 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003763 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 * (or the size used for early receive) above it in the Rx FIFO.
3765 * Set it to the lower of:
3766 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003767 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003768 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003769 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3770 fc->pause_time = 0xFFFF;
3771 else
3772 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003773 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003774 fc->current_mode = fc->requested_mode;
3775
3776 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003777 case e1000_ich9lan:
3778 case e1000_ich10lan:
3779 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3780 pba = 14;
3781 ew32(PBA, pba);
3782 fc->high_water = 0x2800;
3783 fc->low_water = fc->high_water - 8;
3784 break;
3785 }
3786 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003787 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003788 hwm = min(((pba << 10) * 9 / 10),
3789 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003790
3791 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3792 fc->low_water = fc->high_water - 8;
3793 break;
3794 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003795 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003796 * loads. If hangs persist, try disabling Tx flow control.
3797 */
3798 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3799 fc->high_water = 0x3500;
3800 fc->low_water = 0x1500;
3801 } else {
3802 fc->high_water = 0x5000;
3803 fc->low_water = 0x3000;
3804 }
Bruce Allana3055952010-05-10 15:02:12 +00003805 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003806 break;
3807 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003808 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003809 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003810
3811 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3812 fc->high_water = 0x05C20;
3813 fc->low_water = 0x05048;
3814 fc->pause_time = 0x0650;
3815 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003816 }
Bruce Allan347b5202012-12-08 00:35:35 +00003817
3818 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3819 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003820 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003821 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003822
Bruce Allane921eb12012-11-28 09:28:37 +00003823 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003824 * maximum size per Tx descriptor limited only to the transmit
3825 * allocation of the packet buffer minus 96 bytes with an upper
3826 * limit of 24KB due to receive synchronization limitations.
3827 */
3828 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3829 24 << 10);
3830
Bruce Allane921eb12012-11-28 09:28:37 +00003831 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003832 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003833 */
3834 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003835 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003836 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3837 dev_info(&adapter->pdev->dev,
3838 "Interrupt Throttle Rate turned off\n");
3839 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003840 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003841 }
3842 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3843 dev_info(&adapter->pdev->dev,
3844 "Interrupt Throttle Rate turned on\n");
3845 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3846 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003847 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003848 }
3849 }
3850
Auke Kokbc7f75f2007-09-17 12:30:59 -07003851 /* Allow time for pending master requests to run */
3852 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003853
Bruce Allane921eb12012-11-28 09:28:37 +00003854 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003855 * that the network interface is in control
3856 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003857 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003858 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003859
Auke Kokbc7f75f2007-09-17 12:30:59 -07003860 ew32(WUC, 0);
3861
3862 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003863 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003864
3865 e1000_update_mng_vlan(adapter);
3866
3867 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3868 ew32(VET, ETH_P_8021Q);
3869
3870 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003871
Bruce Allanb67e1912012-12-27 08:32:33 +00003872 /* initialize systim and reset the ns time counter */
3873 e1000e_config_hwtstamp(adapter);
3874
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003875 if (!netif_running(adapter->netdev) &&
3876 !test_bit(__E1000_TESTING, &adapter->state)) {
3877 e1000_power_down_phy(adapter);
3878 return;
3879 }
3880
Auke Kokbc7f75f2007-09-17 12:30:59 -07003881 e1000_get_phy_info(hw);
3882
Bruce Allan918d7192009-06-02 11:28:20 +00003883 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3884 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003885 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003886 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003887 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003888 * different we would do if it failed
3889 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003890 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3891 phy_data &= ~IGP02E1000_PM_SPD;
3892 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3893 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894}
3895
3896int e1000e_up(struct e1000_adapter *adapter)
3897{
3898 struct e1000_hw *hw = &adapter->hw;
3899
3900 /* hardware has been reset, we need to reload some things */
3901 e1000_configure(adapter);
3902
3903 clear_bit(__E1000_DOWN, &adapter->state);
3904
Bruce Allan4662e822008-08-26 18:37:06 -07003905 if (adapter->msix_entries)
3906 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003907 e1000_irq_enable(adapter);
3908
Bruce Allan400484f2011-05-13 07:20:03 +00003909 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003910
Auke Kokbc7f75f2007-09-17 12:30:59 -07003911 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003912 if (adapter->msix_entries)
3913 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3914 else
3915 ew32(ICS, E1000_ICS_LSC);
3916
Auke Kokbc7f75f2007-09-17 12:30:59 -07003917 return 0;
3918}
3919
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003920static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3921{
3922 struct e1000_hw *hw = &adapter->hw;
3923
3924 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3925 return;
3926
3927 /* flush pending descriptor writebacks to memory */
3928 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3929 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3930
3931 /* execute the writes immediately */
3932 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003933
Bruce Allane921eb12012-11-28 09:28:37 +00003934 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003935 * write is successful
3936 */
3937 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3938 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3939
3940 /* execute the writes immediately */
3941 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003942}
3943
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003944static void e1000e_update_stats(struct e1000_adapter *adapter);
3945
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946void e1000e_down(struct e1000_adapter *adapter)
3947{
3948 struct net_device *netdev = adapter->netdev;
3949 struct e1000_hw *hw = &adapter->hw;
3950 u32 tctl, rctl;
3951
Bruce Allane921eb12012-11-28 09:28:37 +00003952 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003953 * reschedule our watchdog timer
3954 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 set_bit(__E1000_DOWN, &adapter->state);
3956
3957 /* disable receives in the hardware */
3958 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003959 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3960 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961 /* flush and sleep below */
3962
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003963 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964
3965 /* disable transmits in the hardware */
3966 tctl = er32(TCTL);
3967 tctl &= ~E1000_TCTL_EN;
3968 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003969
Auke Kokbc7f75f2007-09-17 12:30:59 -07003970 /* flush both disables and wait for them to finish */
3971 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003972 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974 e1000_irq_disable(adapter);
3975
3976 del_timer_sync(&adapter->watchdog_timer);
3977 del_timer_sync(&adapter->phy_info_timer);
3978
Auke Kokbc7f75f2007-09-17 12:30:59 -07003979 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003980
3981 spin_lock(&adapter->stats64_lock);
3982 e1000e_update_stats(adapter);
3983 spin_unlock(&adapter->stats64_lock);
3984
Bruce Allan400484f2011-05-13 07:20:03 +00003985 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003986 e1000_clean_tx_ring(adapter->tx_ring);
3987 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003988
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 adapter->link_speed = 0;
3990 adapter->link_duplex = 0;
3991
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003992 if (!pci_channel_offline(adapter->pdev))
3993 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003994
Bruce Allane921eb12012-11-28 09:28:37 +00003995 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 * pci_disable_device here.
3997 */
3998}
3999
4000void e1000e_reinit_locked(struct e1000_adapter *adapter)
4001{
4002 might_sleep();
4003 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004004 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 e1000e_down(adapter);
4006 e1000e_up(adapter);
4007 clear_bit(__E1000_RESETTING, &adapter->state);
4008}
4009
4010/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004011 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4012 * @cc: cyclecounter structure
4013 **/
4014static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4015{
4016 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4017 cc);
4018 struct e1000_hw *hw = &adapter->hw;
4019 cycle_t systim;
4020
4021 /* latch SYSTIMH on read of SYSTIML */
4022 systim = (cycle_t)er32(SYSTIML);
4023 systim |= (cycle_t)er32(SYSTIMH) << 32;
4024
4025 return systim;
4026}
4027
4028/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004029 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4030 * @adapter: board private structure to initialize
4031 *
4032 * e1000_sw_init initializes the Adapter private data structure.
4033 * Fields are initialized based on PCI device information and
4034 * OS network device settings (MTU size).
4035 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004036static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004037{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 struct net_device *netdev = adapter->netdev;
4039
4040 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4041 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004042 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4043 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004044 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4045 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004046
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004047 spin_lock_init(&adapter->stats64_lock);
4048
Bruce Allan4662e822008-08-26 18:37:06 -07004049 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004050
Bruce Allan4662e822008-08-26 18:37:06 -07004051 if (e1000_alloc_queues(adapter))
4052 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004053
Bruce Allanb67e1912012-12-27 08:32:33 +00004054 /* Setup hardware time stamping cyclecounter */
4055 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4056 adapter->cc.read = e1000e_cyclecounter_read;
4057 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4058 adapter->cc.mult = 1;
4059 /* cc.shift set in e1000e_get_base_tininca() */
4060
4061 spin_lock_init(&adapter->systim_lock);
4062 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4063 }
4064
Auke Kokbc7f75f2007-09-17 12:30:59 -07004065 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004066 e1000_irq_disable(adapter);
4067
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068 set_bit(__E1000_DOWN, &adapter->state);
4069 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070}
4071
4072/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004073 * e1000_intr_msi_test - Interrupt Handler
4074 * @irq: interrupt number
4075 * @data: pointer to a network interface device structure
4076 **/
4077static irqreturn_t e1000_intr_msi_test(int irq, void *data)
4078{
4079 struct net_device *netdev = data;
4080 struct e1000_adapter *adapter = netdev_priv(netdev);
4081 struct e1000_hw *hw = &adapter->hw;
4082 u32 icr = er32(ICR);
4083
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004084 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004085 if (icr & E1000_ICR_RXSEQ) {
4086 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004087 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004088 * interrupt is handled.
4089 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004090 wmb();
4091 }
4092
4093 return IRQ_HANDLED;
4094}
4095
4096/**
4097 * e1000_test_msi_interrupt - Returns 0 for successful test
4098 * @adapter: board private struct
4099 *
4100 * code flow taken from tg3.c
4101 **/
4102static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4103{
4104 struct net_device *netdev = adapter->netdev;
4105 struct e1000_hw *hw = &adapter->hw;
4106 int err;
4107
4108 /* poll_enable hasn't been called yet, so don't need disable */
4109 /* clear any pending events */
4110 er32(ICR);
4111
4112 /* free the real vector and request a test handler */
4113 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004114 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004115
4116 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004117 * MSI irq handler will unset this flag
4118 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004119 adapter->flags |= FLAG_MSI_TEST_FAILED;
4120
4121 err = pci_enable_msi(adapter->pdev);
4122 if (err)
4123 goto msi_test_failed;
4124
Joe Perchesa0607fd2009-11-18 23:29:17 -08004125 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004126 netdev->name, netdev);
4127 if (err) {
4128 pci_disable_msi(adapter->pdev);
4129 goto msi_test_failed;
4130 }
4131
Bruce Allane921eb12012-11-28 09:28:37 +00004132 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004133 * interrupt.
4134 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004135 wmb();
4136
4137 e1000_irq_enable(adapter);
4138
4139 /* fire an unusual interrupt on the test handler */
4140 ew32(ICS, E1000_ICS_RXSEQ);
4141 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004142 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004143
4144 e1000_irq_disable(adapter);
4145
Bruce Allanbc763292012-08-17 06:18:07 +00004146 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004147
4148 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004149 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004150 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004151 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004152 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004153 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004154
4155 free_irq(adapter->pdev->irq, netdev);
4156 pci_disable_msi(adapter->pdev);
4157
Bruce Allanf8d59f72008-08-08 18:36:11 -07004158msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004159 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004160 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004161}
4162
4163/**
4164 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4165 * @adapter: board private struct
4166 *
4167 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4168 **/
4169static int e1000_test_msi(struct e1000_adapter *adapter)
4170{
4171 int err;
4172 u16 pci_cmd;
4173
4174 if (!(adapter->flags & FLAG_MSI_ENABLED))
4175 return 0;
4176
4177 /* disable SERR in case the MSI write causes a master abort */
4178 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004179 if (pci_cmd & PCI_COMMAND_SERR)
4180 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4181 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004182
4183 err = e1000_test_msi_interrupt(adapter);
4184
Dean Nelson36f24072010-06-29 18:12:05 +00004185 /* re-enable SERR */
4186 if (pci_cmd & PCI_COMMAND_SERR) {
4187 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4188 pci_cmd |= PCI_COMMAND_SERR;
4189 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4190 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004191
Bruce Allanf8d59f72008-08-08 18:36:11 -07004192 return err;
4193}
4194
4195/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004196 * e1000_open - Called when a network interface is made active
4197 * @netdev: network interface device structure
4198 *
4199 * Returns 0 on success, negative value on failure
4200 *
4201 * The open entry point is called when a network interface is made
4202 * active by the system (IFF_UP). At this point all resources needed
4203 * for transmit and receive operations are allocated, the interrupt
4204 * handler is registered with the OS, the watchdog timer is started,
4205 * and the stack is notified that the interface is ready.
4206 **/
4207static int e1000_open(struct net_device *netdev)
4208{
4209 struct e1000_adapter *adapter = netdev_priv(netdev);
4210 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004211 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212 int err;
4213
4214 /* disallow open during test */
4215 if (test_bit(__E1000_TESTING, &adapter->state))
4216 return -EBUSY;
4217
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004218 pm_runtime_get_sync(&pdev->dev);
4219
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004220 netif_carrier_off(netdev);
4221
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004223 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004224 if (err)
4225 goto err_setup_tx;
4226
4227 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004228 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004229 if (err)
4230 goto err_setup_rx;
4231
Bruce Allane921eb12012-11-28 09:28:37 +00004232 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004233 * interface is now open and reset the part to a known state.
4234 */
4235 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004236 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004237 e1000e_reset(adapter);
4238 }
4239
Auke Kokbc7f75f2007-09-17 12:30:59 -07004240 e1000e_power_up_phy(adapter);
4241
4242 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4243 if ((adapter->hw.mng_cookie.status &
4244 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4245 e1000_update_mng_vlan(adapter);
4246
Bruce Allan79d4e902011-12-16 00:46:27 +00004247 /* DMA latency requirement to workaround jumbo issue */
4248 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004249 pm_qos_add_request(&adapter->netdev->pm_qos_req,
4250 PM_QOS_CPU_DMA_LATENCY,
4251 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004252
Bruce Allane921eb12012-11-28 09:28:37 +00004253 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4255 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004256 * clean_rx handler before we do so.
4257 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004258 e1000_configure(adapter);
4259
4260 err = e1000_request_irq(adapter);
4261 if (err)
4262 goto err_req_irq;
4263
Bruce Allane921eb12012-11-28 09:28:37 +00004264 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004265 * ignore e1000e MSI messages, which means we need to test our MSI
4266 * interrupt now
4267 */
Bruce Allan4662e822008-08-26 18:37:06 -07004268 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004269 err = e1000_test_msi(adapter);
4270 if (err) {
4271 e_err("Interrupt allocation failed\n");
4272 goto err_req_irq;
4273 }
4274 }
4275
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 /* From here on the code is the same as e1000e_up() */
4277 clear_bit(__E1000_DOWN, &adapter->state);
4278
4279 napi_enable(&adapter->napi);
4280
4281 e1000_irq_enable(adapter);
4282
Jeff Kirsher09357b02011-11-18 14:25:00 +00004283 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004284 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004285
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004286 adapter->idle_check = true;
4287 pm_runtime_put(&pdev->dev);
4288
Auke Kokbc7f75f2007-09-17 12:30:59 -07004289 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004290 if (adapter->msix_entries)
4291 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4292 else
4293 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004294
4295 return 0;
4296
4297err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004298 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004299 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004300 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004301err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004302 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004303err_setup_tx:
4304 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004305 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004306
4307 return err;
4308}
4309
4310/**
4311 * e1000_close - Disables a network interface
4312 * @netdev: network interface device structure
4313 *
4314 * Returns 0, this is not allowed to fail
4315 *
4316 * The close entry point is called when an interface is de-activated
4317 * by the OS. The hardware is still under the drivers control, but
4318 * needs to be disabled. A global MAC reset is issued to stop the
4319 * hardware, and all transmit and receive resources are freed.
4320 **/
4321static int e1000_close(struct net_device *netdev)
4322{
4323 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004324 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004325 int count = E1000_CHECK_RESET_COUNT;
4326
4327 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4328 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004329
4330 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004331
4332 pm_runtime_get_sync(&pdev->dev);
4333
Bruce Allan5f4a7802011-11-29 08:09:19 +00004334 napi_disable(&adapter->napi);
4335
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004336 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4337 e1000e_down(adapter);
4338 e1000_free_irq(adapter);
4339 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004340 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004341
Bruce Allan55aa6982011-12-16 00:45:45 +00004342 e1000e_free_tx_resources(adapter->tx_ring);
4343 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004344
Bruce Allane921eb12012-11-28 09:28:37 +00004345 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004346 * the same ID is registered on the host OS (let 8021q kill it)
4347 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004348 if (adapter->hw.mng_cookie.status &
4349 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004350 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4351
Bruce Allane921eb12012-11-28 09:28:37 +00004352 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004353 * interface is now closed
4354 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004355 if ((adapter->flags & FLAG_HAS_AMT) &&
4356 !test_bit(__E1000_TESTING, &adapter->state))
4357 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004358
Bruce Allan79d4e902011-12-16 00:46:27 +00004359 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004360 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004361
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004362 pm_runtime_put_sync(&pdev->dev);
4363
Auke Kokbc7f75f2007-09-17 12:30:59 -07004364 return 0;
4365}
4366/**
4367 * e1000_set_mac - Change the Ethernet Address of the NIC
4368 * @netdev: network interface device structure
4369 * @p: pointer to an address structure
4370 *
4371 * Returns 0 on success, negative on failure
4372 **/
4373static int e1000_set_mac(struct net_device *netdev, void *p)
4374{
4375 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004376 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004377 struct sockaddr *addr = p;
4378
4379 if (!is_valid_ether_addr(addr->sa_data))
4380 return -EADDRNOTAVAIL;
4381
4382 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4383 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4384
Bruce Allan69e1e012012-04-14 03:28:50 +00004385 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004386
4387 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4388 /* activate the work around */
4389 e1000e_set_laa_state_82571(&adapter->hw, 1);
4390
Bruce Allane921eb12012-11-28 09:28:37 +00004391 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004392 * between the time RAR[0] gets clobbered and the time it
4393 * gets fixed (in e1000_watchdog), the actual LAA is in one
4394 * of the RARs and no incoming packets directed to this port
4395 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004396 * RAR[14]
4397 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004398 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4399 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004400 }
4401
4402 return 0;
4403}
4404
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004405/**
4406 * e1000e_update_phy_task - work thread to update phy
4407 * @work: pointer to our work struct
4408 *
4409 * this worker thread exists because we must acquire a
4410 * semaphore to read the phy, which we could msleep while
4411 * waiting for it, and we can't msleep in a timer.
4412 **/
4413static void e1000e_update_phy_task(struct work_struct *work)
4414{
4415 struct e1000_adapter *adapter = container_of(work,
4416 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004417
4418 if (test_bit(__E1000_DOWN, &adapter->state))
4419 return;
4420
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004421 e1000_get_phy_info(&adapter->hw);
4422}
4423
Bruce Allane921eb12012-11-28 09:28:37 +00004424/**
4425 * e1000_update_phy_info - timre call-back to update PHY info
4426 * @data: pointer to adapter cast into an unsigned long
4427 *
Bruce Allanad680762008-03-28 09:15:03 -07004428 * Need to wait a few seconds after link up to get diagnostic information from
4429 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004430 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004431static void e1000_update_phy_info(unsigned long data)
4432{
4433 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004434
4435 if (test_bit(__E1000_DOWN, &adapter->state))
4436 return;
4437
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004438 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439}
4440
4441/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004442 * e1000e_update_phy_stats - Update the PHY statistics counters
4443 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004444 *
4445 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004446 **/
4447static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4448{
4449 struct e1000_hw *hw = &adapter->hw;
4450 s32 ret_val;
4451 u16 phy_data;
4452
4453 ret_val = hw->phy.ops.acquire(hw);
4454 if (ret_val)
4455 return;
4456
Bruce Allane921eb12012-11-28 09:28:37 +00004457 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004458 * If not, set to the page with the PHY status registers.
4459 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004460 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004461 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4462 &phy_data);
4463 if (ret_val)
4464 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004465 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4466 ret_val = hw->phy.ops.set_page(hw,
4467 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004468 if (ret_val)
4469 goto release;
4470 }
4471
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004472 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004473 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4474 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004475 if (!ret_val)
4476 adapter->stats.scc += phy_data;
4477
4478 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004479 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4480 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004481 if (!ret_val)
4482 adapter->stats.ecol += phy_data;
4483
4484 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004485 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4486 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004487 if (!ret_val)
4488 adapter->stats.mcc += phy_data;
4489
4490 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004491 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4492 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004493 if (!ret_val)
4494 adapter->stats.latecol += phy_data;
4495
4496 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004497 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4498 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004499 if (!ret_val)
4500 hw->mac.collision_delta = phy_data;
4501
4502 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004503 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4504 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004505 if (!ret_val)
4506 adapter->stats.dc += phy_data;
4507
4508 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004509 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4510 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004511 if (!ret_val)
4512 adapter->stats.tncrs += phy_data;
4513
4514release:
4515 hw->phy.ops.release(hw);
4516}
4517
4518/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004519 * e1000e_update_stats - Update the board statistics counters
4520 * @adapter: board private structure
4521 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004522static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004523{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004524 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004525 struct e1000_hw *hw = &adapter->hw;
4526 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004527
Bruce Allane921eb12012-11-28 09:28:37 +00004528 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 * connection is down.
4530 */
4531 if (adapter->link_speed == 0)
4532 return;
4533 if (pci_channel_offline(pdev))
4534 return;
4535
Auke Kokbc7f75f2007-09-17 12:30:59 -07004536 adapter->stats.crcerrs += er32(CRCERRS);
4537 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004538 adapter->stats.gorc += er32(GORCL);
4539 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540 adapter->stats.bprc += er32(BPRC);
4541 adapter->stats.mprc += er32(MPRC);
4542 adapter->stats.roc += er32(ROC);
4543
Auke Kokbc7f75f2007-09-17 12:30:59 -07004544 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004545
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004546 /* Half-duplex statistics */
4547 if (adapter->link_duplex == HALF_DUPLEX) {
4548 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4549 e1000e_update_phy_stats(adapter);
4550 } else {
4551 adapter->stats.scc += er32(SCC);
4552 adapter->stats.ecol += er32(ECOL);
4553 adapter->stats.mcc += er32(MCC);
4554 adapter->stats.latecol += er32(LATECOL);
4555 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004556
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004557 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004558
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004559 if ((hw->mac.type != e1000_82574) &&
4560 (hw->mac.type != e1000_82583))
4561 adapter->stats.tncrs += er32(TNCRS);
4562 }
4563 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004564 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004565
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566 adapter->stats.xonrxc += er32(XONRXC);
4567 adapter->stats.xontxc += er32(XONTXC);
4568 adapter->stats.xoffrxc += er32(XOFFRXC);
4569 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004571 adapter->stats.gotc += er32(GOTCL);
4572 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 adapter->stats.rnbc += er32(RNBC);
4574 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575
4576 adapter->stats.mptc += er32(MPTC);
4577 adapter->stats.bptc += er32(BPTC);
4578
4579 /* used for adaptive IFS */
4580
4581 hw->mac.tx_packet_delta = er32(TPT);
4582 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583
4584 adapter->stats.algnerrc += er32(ALGNERRC);
4585 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586 adapter->stats.cexterr += er32(CEXTERR);
4587 adapter->stats.tsctc += er32(TSCTC);
4588 adapter->stats.tsctfc += er32(TSCTFC);
4589
Auke Kokbc7f75f2007-09-17 12:30:59 -07004590 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004591 netdev->stats.multicast = adapter->stats.mprc;
4592 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004593
4594 /* Rx Errors */
4595
Bruce Allane921eb12012-11-28 09:28:37 +00004596 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004597 * our own version based on RUC and ROC
4598 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004599 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004600 adapter->stats.crcerrs + adapter->stats.algnerrc +
4601 adapter->stats.ruc + adapter->stats.roc +
4602 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004603 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004605 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4606 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4607 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608
4609 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004610 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004612 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4613 netdev->stats.tx_window_errors = adapter->stats.latecol;
4614 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615
4616 /* Tx Dropped needs to be maintained elsewhere */
4617
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618 /* Management Stats */
4619 adapter->stats.mgptc += er32(MGTPTC);
4620 adapter->stats.mgprc += er32(MGTPRC);
4621 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004622}
4623
Bruce Allan7c257692008-04-23 11:09:00 -07004624/**
4625 * e1000_phy_read_status - Update the PHY register status snapshot
4626 * @adapter: board private structure
4627 **/
4628static void e1000_phy_read_status(struct e1000_adapter *adapter)
4629{
4630 struct e1000_hw *hw = &adapter->hw;
4631 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004632
4633 if ((er32(STATUS) & E1000_STATUS_LU) &&
4634 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004635 int ret_val;
4636
Bruce Allan7c257692008-04-23 11:09:00 -07004637 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4638 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4639 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4640 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4641 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4642 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4643 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4644 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4645 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004646 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004647 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004648 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004649 * Set values to typical power-on defaults
4650 */
4651 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4652 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4653 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4654 BMSR_ERCAP);
4655 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4656 ADVERTISE_ALL | ADVERTISE_CSMA);
4657 phy->lpa = 0;
4658 phy->expansion = EXPANSION_ENABLENPAGE;
4659 phy->ctrl1000 = ADVERTISE_1000FULL;
4660 phy->stat1000 = 0;
4661 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4662 }
Bruce Allan7c257692008-04-23 11:09:00 -07004663}
4664
Auke Kokbc7f75f2007-09-17 12:30:59 -07004665static void e1000_print_link_info(struct e1000_adapter *adapter)
4666{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004667 struct e1000_hw *hw = &adapter->hw;
4668 u32 ctrl = er32(CTRL);
4669
Bruce Allan8f12fe82008-11-21 16:54:43 -08004670 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004671 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4672 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004673 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4674 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4675 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4676 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677}
4678
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004679static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004680{
4681 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004682 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004683 s32 ret_val = 0;
4684
Bruce Allane921eb12012-11-28 09:28:37 +00004685 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004686 * Rx sequence error interrupt. get_link_status will stay
4687 * false until the check_for_link establishes link
4688 * for copper adapters ONLY
4689 */
4690 switch (hw->phy.media_type) {
4691 case e1000_media_type_copper:
4692 if (hw->mac.get_link_status) {
4693 ret_val = hw->mac.ops.check_for_link(hw);
4694 link_active = !hw->mac.get_link_status;
4695 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004696 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004697 }
4698 break;
4699 case e1000_media_type_fiber:
4700 ret_val = hw->mac.ops.check_for_link(hw);
4701 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4702 break;
4703 case e1000_media_type_internal_serdes:
4704 ret_val = hw->mac.ops.check_for_link(hw);
4705 link_active = adapter->hw.mac.serdes_has_link;
4706 break;
4707 default:
4708 case e1000_media_type_unknown:
4709 break;
4710 }
4711
4712 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4713 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4714 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004715 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004716 }
4717
4718 return link_active;
4719}
4720
4721static void e1000e_enable_receives(struct e1000_adapter *adapter)
4722{
4723 /* make sure the receive unit is started */
4724 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004725 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004726 struct e1000_hw *hw = &adapter->hw;
4727 u32 rctl = er32(RCTL);
4728 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004729 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004730 }
4731}
4732
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004733static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4734{
4735 struct e1000_hw *hw = &adapter->hw;
4736
Bruce Allane921eb12012-11-28 09:28:37 +00004737 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004738 * for hung state and reset, if two calls return true
4739 */
4740 if (e1000_check_phy_82574(hw))
4741 adapter->phy_hang_count++;
4742 else
4743 adapter->phy_hang_count = 0;
4744
4745 if (adapter->phy_hang_count > 1) {
4746 adapter->phy_hang_count = 0;
4747 schedule_work(&adapter->reset_task);
4748 }
4749}
4750
Auke Kokbc7f75f2007-09-17 12:30:59 -07004751/**
4752 * e1000_watchdog - Timer Call-back
4753 * @data: pointer to adapter cast into an unsigned long
4754 **/
4755static void e1000_watchdog(unsigned long data)
4756{
4757 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4758
4759 /* Do the rest outside of interrupt context */
4760 schedule_work(&adapter->watchdog_task);
4761
4762 /* TODO: make this use queue_delayed_work() */
4763}
4764
4765static void e1000_watchdog_task(struct work_struct *work)
4766{
4767 struct e1000_adapter *adapter = container_of(work,
4768 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004769 struct net_device *netdev = adapter->netdev;
4770 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004771 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004772 struct e1000_ring *tx_ring = adapter->tx_ring;
4773 struct e1000_hw *hw = &adapter->hw;
4774 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004775
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004776 if (test_bit(__E1000_DOWN, &adapter->state))
4777 return;
4778
David S. Millerb405e8d2010-02-04 22:31:41 -08004779 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004780 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004781 /* Cancel scheduled suspend requests. */
4782 pm_runtime_resume(netdev->dev.parent);
4783
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004784 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004785 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004786 }
4787
4788 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4789 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4790 e1000_update_mng_vlan(adapter);
4791
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792 if (link) {
4793 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004794 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004795
4796 /* Cancel scheduled suspend requests. */
4797 pm_runtime_resume(netdev->dev.parent);
4798
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004799 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004800 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004801 mac->ops.get_link_up_info(&adapter->hw,
4802 &adapter->link_speed,
4803 &adapter->link_duplex);
4804 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004805 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004806 * if link has autonegotiated at 10/100 half
4807 */
4808 if ((hw->phy.type == e1000_phy_igp_3 ||
4809 hw->phy.type == e1000_phy_bm) &&
4810 (hw->mac.autoneg == true) &&
4811 (adapter->link_speed == SPEED_10 ||
4812 adapter->link_speed == SPEED_100) &&
4813 (adapter->link_duplex == HALF_DUPLEX)) {
4814 u16 autoneg_exp;
4815
4816 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4817
4818 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004819 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 -07004820 }
4821
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004822 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004823 adapter->tx_timeout_factor = 1;
4824 switch (adapter->link_speed) {
4825 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004826 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004827 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 break;
4829 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004830 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004831 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832 break;
4833 }
4834
Bruce Allane921eb12012-11-28 09:28:37 +00004835 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004836 * link-up event
4837 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004838 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4839 !txb2b) {
4840 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004841 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004843 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004844 }
4845
Bruce Allane921eb12012-11-28 09:28:37 +00004846 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004847 * some hardware issues
4848 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004849 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4850 switch (adapter->link_speed) {
4851 case SPEED_10:
4852 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004853 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004854 netdev->features &= ~NETIF_F_TSO;
4855 netdev->features &= ~NETIF_F_TSO6;
4856 break;
4857 case SPEED_1000:
4858 netdev->features |= NETIF_F_TSO;
4859 netdev->features |= NETIF_F_TSO6;
4860 break;
4861 default:
4862 /* oops */
4863 break;
4864 }
4865 }
4866
Bruce Allane921eb12012-11-28 09:28:37 +00004867 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004868 * after setting TARC(0)
4869 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870 tctl = er32(TCTL);
4871 tctl |= E1000_TCTL_EN;
4872 ew32(TCTL, tctl);
4873
Bruce Allane921eb12012-11-28 09:28:37 +00004874 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004875 * reporting link up.
4876 */
4877 if (phy->ops.cfg_on_link_up)
4878 phy->ops.cfg_on_link_up(hw);
4879
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881
4882 if (!test_bit(__E1000_DOWN, &adapter->state))
4883 mod_timer(&adapter->phy_info_timer,
4884 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004885 }
4886 } else {
4887 if (netif_carrier_ok(netdev)) {
4888 adapter->link_speed = 0;
4889 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004890 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004891 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004892 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004893 if (!test_bit(__E1000_DOWN, &adapter->state))
4894 mod_timer(&adapter->phy_info_timer,
4895 round_jiffies(jiffies + 2 * HZ));
4896
Bruce Allan12d43f72012-12-05 06:26:14 +00004897 /* The link is lost so the controller stops DMA.
4898 * If there is queued Tx work that cannot be done
4899 * or if on an 8000ES2LAN which requires a Rx packet
4900 * buffer work-around on link down event, reset the
4901 * controller to flush the Tx/Rx packet buffers.
4902 * (Do the reset outside of interrupt context).
4903 */
4904 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4905 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4906 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004907 else
4908 pm_schedule_suspend(netdev->dev.parent,
4909 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004910 }
4911 }
4912
4913link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004914 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004915 e1000e_update_stats(adapter);
4916
4917 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4918 adapter->tpt_old = adapter->stats.tpt;
4919 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4920 adapter->colc_old = adapter->stats.colc;
4921
Bruce Allan7c257692008-04-23 11:09:00 -07004922 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4923 adapter->gorc_old = adapter->stats.gorc;
4924 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4925 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004926 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004927
Bruce Allan12d43f72012-12-05 06:26:14 +00004928 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004929 schedule_work(&adapter->reset_task);
4930 /* return immediately since reset is imminent */
4931 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004932 }
4933
Bruce Allan12d43f72012-12-05 06:26:14 +00004934 e1000e_update_adaptive(&adapter->hw);
4935
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004936 /* Simple mode for Interrupt Throttle Rate (ITR) */
4937 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004938 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004939 * Total asymmetrical Tx or Rx gets ITR=8000;
4940 * everyone else is between 2000-8000.
4941 */
4942 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4943 u32 dif = (adapter->gotc > adapter->gorc ?
4944 adapter->gotc - adapter->gorc :
4945 adapter->gorc - adapter->gotc) / 10000;
4946 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4947
Matthew Vick22a4cca2012-07-12 00:02:42 +00004948 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004949 }
4950
Bruce Allanad680762008-03-28 09:15:03 -07004951 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004952 if (adapter->msix_entries)
4953 ew32(ICS, adapter->rx_ring->ims_val);
4954 else
4955 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004957 /* flush pending descriptors to memory before detecting Tx hang */
4958 e1000e_flush_descriptors(adapter);
4959
Auke Kokbc7f75f2007-09-17 12:30:59 -07004960 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004961 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004962
Bruce Allane921eb12012-11-28 09:28:37 +00004963 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07004964 * reset from the other port. Set the appropriate LAA in RAR[0]
4965 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004966 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00004967 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004969 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4970 e1000e_check_82574_phy_workaround(adapter);
4971
Bruce Allanb67e1912012-12-27 08:32:33 +00004972 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
4973 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
4974 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
4975 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
4976 er32(RXSTMPH);
4977 adapter->rx_hwtstamp_cleared++;
4978 } else {
4979 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
4980 }
4981 }
4982
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983 /* Reset the timer */
4984 if (!test_bit(__E1000_DOWN, &adapter->state))
4985 mod_timer(&adapter->watchdog_timer,
4986 round_jiffies(jiffies + 2 * HZ));
4987}
4988
4989#define E1000_TX_FLAGS_CSUM 0x00000001
4990#define E1000_TX_FLAGS_VLAN 0x00000002
4991#define E1000_TX_FLAGS_TSO 0x00000004
4992#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00004993#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00004994#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07004995#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4996#define E1000_TX_FLAGS_VLAN_SHIFT 16
4997
Bruce Allan55aa6982011-12-16 00:45:45 +00004998static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000 struct e1000_context_desc *context_desc;
5001 struct e1000_buffer *buffer_info;
5002 unsigned int i;
5003 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005004 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005006
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005007 if (!skb_is_gso(skb))
5008 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005010 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005011 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5012
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005013 if (err)
5014 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005015 }
5016
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005017 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5018 mss = skb_shinfo(skb)->gso_size;
5019 if (skb->protocol == htons(ETH_P_IP)) {
5020 struct iphdr *iph = ip_hdr(skb);
5021 iph->tot_len = 0;
5022 iph->check = 0;
5023 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5024 0, IPPROTO_TCP, 0);
5025 cmd_length = E1000_TXD_CMD_IP;
5026 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005027 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005028 ipv6_hdr(skb)->payload_len = 0;
5029 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5030 &ipv6_hdr(skb)->daddr,
5031 0, IPPROTO_TCP, 0);
5032 ipcse = 0;
5033 }
5034 ipcss = skb_network_offset(skb);
5035 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5036 tucss = skb_transport_offset(skb);
5037 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005038
5039 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5040 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5041
5042 i = tx_ring->next_to_use;
5043 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5044 buffer_info = &tx_ring->buffer_info[i];
5045
5046 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5047 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5048 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5049 context_desc->upper_setup.tcp_fields.tucss = tucss;
5050 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005051 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005052 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5053 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5054 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5055
5056 buffer_info->time_stamp = jiffies;
5057 buffer_info->next_to_watch = i;
5058
5059 i++;
5060 if (i == tx_ring->count)
5061 i = 0;
5062 tx_ring->next_to_use = i;
5063
5064 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005065}
5066
Bruce Allan55aa6982011-12-16 00:45:45 +00005067static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068{
Bruce Allan55aa6982011-12-16 00:45:45 +00005069 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005070 struct e1000_context_desc *context_desc;
5071 struct e1000_buffer *buffer_info;
5072 unsigned int i;
5073 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005074 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005075 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005076
Dave Grahamaf807c82008-10-09 14:28:58 -07005077 if (skb->ip_summed != CHECKSUM_PARTIAL)
5078 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005079
Arthur Jones5f66f202009-03-19 01:13:08 +00005080 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5081 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5082 else
5083 protocol = skb->protocol;
5084
Arthur Jones3f518392009-03-20 15:56:35 -07005085 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005086 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005087 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5088 cmd_len |= E1000_TXD_CMD_TCP;
5089 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005090 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005091 /* XXX not handling all IPV6 headers */
5092 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5093 cmd_len |= E1000_TXD_CMD_TCP;
5094 break;
5095 default:
5096 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005097 e_warn("checksum_partial proto=%x!\n",
5098 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005099 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 }
5101
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005102 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005103
5104 i = tx_ring->next_to_use;
5105 buffer_info = &tx_ring->buffer_info[i];
5106 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5107
5108 context_desc->lower_setup.ip_config = 0;
5109 context_desc->upper_setup.tcp_fields.tucss = css;
5110 context_desc->upper_setup.tcp_fields.tucso =
5111 css + skb->csum_offset;
5112 context_desc->upper_setup.tcp_fields.tucse = 0;
5113 context_desc->tcp_seg_setup.data = 0;
5114 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5115
5116 buffer_info->time_stamp = jiffies;
5117 buffer_info->next_to_watch = i;
5118
5119 i++;
5120 if (i == tx_ring->count)
5121 i = 0;
5122 tx_ring->next_to_use = i;
5123
5124 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005125}
5126
Bruce Allan55aa6982011-12-16 00:45:45 +00005127static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5128 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005129 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005130{
Bruce Allan55aa6982011-12-16 00:45:45 +00005131 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005132 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005133 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005134 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005135 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005136 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005137
5138 i = tx_ring->next_to_use;
5139
5140 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005141 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142 size = min(len, max_per_txd);
5143
Auke Kokbc7f75f2007-09-17 12:30:59 -07005144 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005145 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005146 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005147 buffer_info->dma = dma_map_single(&pdev->dev,
5148 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005149 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005150 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005151 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005152 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005153
5154 len -= size;
5155 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005156 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005157
5158 if (len) {
5159 i++;
5160 if (i == tx_ring->count)
5161 i = 0;
5162 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005163 }
5164
5165 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005166 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167
5168 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005169 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005170 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005171
5172 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005173 i++;
5174 if (i == tx_ring->count)
5175 i = 0;
5176
Auke Kokbc7f75f2007-09-17 12:30:59 -07005177 buffer_info = &tx_ring->buffer_info[i];
5178 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179
5180 buffer_info->length = size;
5181 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005182 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005183 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5184 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005185 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005186 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005187 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188
5189 len -= size;
5190 offset += size;
5191 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005192 }
5193 }
5194
Bruce Allanaf667a22010-12-31 06:10:01 +00005195 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005196 /* multiply data chunks by size of headers */
5197 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5198
Auke Kokbc7f75f2007-09-17 12:30:59 -07005199 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005200 tx_ring->buffer_info[i].segs = segs;
5201 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005202 tx_ring->buffer_info[first].next_to_watch = i;
5203
5204 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005205
5206dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005207 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005208 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005209 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005210 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005211
5212 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005213 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005214 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005215 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005216 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005217 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005218 }
5219
5220 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005221}
5222
Bruce Allan55aa6982011-12-16 00:45:45 +00005223static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005224{
Bruce Allan55aa6982011-12-16 00:45:45 +00005225 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226 struct e1000_tx_desc *tx_desc = NULL;
5227 struct e1000_buffer *buffer_info;
5228 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5229 unsigned int i;
5230
5231 if (tx_flags & E1000_TX_FLAGS_TSO) {
5232 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5233 E1000_TXD_CMD_TSE;
5234 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5235
5236 if (tx_flags & E1000_TX_FLAGS_IPV4)
5237 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5238 }
5239
5240 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5241 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5242 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5243 }
5244
5245 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5246 txd_lower |= E1000_TXD_CMD_VLE;
5247 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5248 }
5249
Ben Greear943146d2012-02-11 15:39:40 +00005250 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5251 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5252
Bruce Allanb67e1912012-12-27 08:32:33 +00005253 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5254 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5255 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5256 }
5257
Auke Kokbc7f75f2007-09-17 12:30:59 -07005258 i = tx_ring->next_to_use;
5259
Bruce Allan36b973d2010-11-24 07:42:43 +00005260 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261 buffer_info = &tx_ring->buffer_info[i];
5262 tx_desc = E1000_TX_DESC(*tx_ring, i);
5263 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5264 tx_desc->lower.data =
5265 cpu_to_le32(txd_lower | buffer_info->length);
5266 tx_desc->upper.data = cpu_to_le32(txd_upper);
5267
5268 i++;
5269 if (i == tx_ring->count)
5270 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005271 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272
5273 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5274
Ben Greear943146d2012-02-11 15:39:40 +00005275 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5276 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5277 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5278
Bruce Allane921eb12012-11-28 09:28:37 +00005279 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005280 * know there are new descriptors to fetch. (Only
5281 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005282 * such as IA-64).
5283 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005284 wmb();
5285
5286 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005287
5288 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005289 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005290 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005291 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005292
Bruce Allane921eb12012-11-28 09:28:37 +00005293 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005294 * at a time, it synchronizes IO on IA64/Altix systems
5295 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 mmiowb();
5297}
5298
5299#define MINIMUM_DHCP_PACKET_SIZE 282
5300static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5301 struct sk_buff *skb)
5302{
5303 struct e1000_hw *hw = &adapter->hw;
5304 u16 length, offset;
5305
Bruce Alland60923c2012-12-05 06:26:56 +00005306 if (vlan_tx_tag_present(skb) &&
5307 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5308 (adapter->hw.mng_cookie.status &
5309 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5310 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005311
5312 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5313 return 0;
5314
5315 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5316 return 0;
5317
5318 {
5319 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5320 struct udphdr *udp;
5321
5322 if (ip->protocol != IPPROTO_UDP)
5323 return 0;
5324
5325 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5326 if (ntohs(udp->dest) != 67)
5327 return 0;
5328
5329 offset = (u8 *)udp + 8 - skb->data;
5330 length = skb->len - offset;
5331 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5332 }
5333
5334 return 0;
5335}
5336
Bruce Allan55aa6982011-12-16 00:45:45 +00005337static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005338{
Bruce Allan55aa6982011-12-16 00:45:45 +00005339 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005340
Bruce Allan55aa6982011-12-16 00:45:45 +00005341 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005342 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005343 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005344 * but since that doesn't exist yet, just open code it.
5345 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005346 smp_mb();
5347
Bruce Allane921eb12012-11-28 09:28:37 +00005348 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005349 * made room available.
5350 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005351 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005352 return -EBUSY;
5353
5354 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005355 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005356 ++adapter->restart_queue;
5357 return 0;
5358}
5359
Bruce Allan55aa6982011-12-16 00:45:45 +00005360static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005361{
Bruce Alland821a4c2012-08-24 20:38:11 +00005362 BUG_ON(size > tx_ring->count);
5363
Bruce Allan55aa6982011-12-16 00:45:45 +00005364 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005365 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005366 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005367}
5368
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005369static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5370 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005371{
5372 struct e1000_adapter *adapter = netdev_priv(netdev);
5373 struct e1000_ring *tx_ring = adapter->tx_ring;
5374 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005376 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005377 unsigned int nr_frags;
5378 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005379 int count = 0;
5380 int tso;
5381 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005382
5383 if (test_bit(__E1000_DOWN, &adapter->state)) {
5384 dev_kfree_skb_any(skb);
5385 return NETDEV_TX_OK;
5386 }
5387
5388 if (skb->len <= 0) {
5389 dev_kfree_skb_any(skb);
5390 return NETDEV_TX_OK;
5391 }
5392
Bruce Allane921eb12012-11-28 09:28:37 +00005393 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005394 * pad skb in order to meet this minimum size requirement
5395 */
5396 if (unlikely(skb->len < 17)) {
5397 if (skb_pad(skb, 17 - skb->len))
5398 return NETDEV_TX_OK;
5399 skb->len = 17;
5400 skb_set_tail_pointer(skb, 17);
5401 }
5402
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404 if (mss) {
5405 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005406
Bruce Allane921eb12012-11-28 09:28:37 +00005407 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005408 * points to just header, pull a few bytes of payload from
5409 * frags into skb->data
5410 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005411 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005412 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005413 * avoiding it could save a lot of cycles
5414 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005415 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005416 unsigned int pull_size;
5417
Bruce Allana2a5b322012-01-31 06:37:17 +00005418 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005420 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005421 dev_kfree_skb_any(skb);
5422 return NETDEV_TX_OK;
5423 }
Eric Dumazete743d312010-04-14 15:59:40 -07005424 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005425 }
5426 }
5427
5428 /* reserve a descriptor for the offload context */
5429 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5430 count++;
5431 count++;
5432
Bruce Alland821a4c2012-08-24 20:38:11 +00005433 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005434
5435 nr_frags = skb_shinfo(skb)->nr_frags;
5436 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005437 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5438 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005439
5440 if (adapter->hw.mac.tx_pkt_filtering)
5441 e1000_transfer_dhcp_info(adapter, skb);
5442
Bruce Allane921eb12012-11-28 09:28:37 +00005443 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005444 * head, otherwise try next time
5445 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005446 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448
Jesse Grosseab6d182010-10-20 13:56:03 +00005449 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005450 tx_flags |= E1000_TX_FLAGS_VLAN;
5451 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5452 }
5453
5454 first = tx_ring->next_to_use;
5455
Bruce Allan55aa6982011-12-16 00:45:45 +00005456 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005457 if (tso < 0) {
5458 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459 return NETDEV_TX_OK;
5460 }
5461
5462 if (tso)
5463 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005464 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005465 tx_flags |= E1000_TX_FLAGS_CSUM;
5466
Bruce Allane921eb12012-11-28 09:28:37 +00005467 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005468 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005469 * no longer assume, we must.
5470 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005471 if (skb->protocol == htons(ETH_P_IP))
5472 tx_flags |= E1000_TX_FLAGS_IPV4;
5473
Ben Greear943146d2012-02-11 15:39:40 +00005474 if (unlikely(skb->no_fcs))
5475 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5476
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005477 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005478 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5479 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005480 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005481 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5482 !adapter->tx_hwtstamp_skb)) {
5483 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5484 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5485 adapter->tx_hwtstamp_skb = skb_get(skb);
5486 schedule_work(&adapter->tx_hwtstamp_work);
5487 } else {
5488 skb_tx_timestamp(skb);
5489 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005490
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005491 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005492 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005493 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005494 e1000_maybe_stop_tx(tx_ring,
5495 (MAX_SKB_FRAGS *
5496 DIV_ROUND_UP(PAGE_SIZE,
5497 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005498 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005499 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005500 tx_ring->buffer_info[first].time_stamp = 0;
5501 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502 }
5503
Auke Kokbc7f75f2007-09-17 12:30:59 -07005504 return NETDEV_TX_OK;
5505}
5506
5507/**
5508 * e1000_tx_timeout - Respond to a Tx Hang
5509 * @netdev: network interface device structure
5510 **/
5511static void e1000_tx_timeout(struct net_device *netdev)
5512{
5513 struct e1000_adapter *adapter = netdev_priv(netdev);
5514
5515 /* Do the reset outside of interrupt context */
5516 adapter->tx_timeout_count++;
5517 schedule_work(&adapter->reset_task);
5518}
5519
5520static void e1000_reset_task(struct work_struct *work)
5521{
5522 struct e1000_adapter *adapter;
5523 adapter = container_of(work, struct e1000_adapter, reset_task);
5524
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005525 /* don't run the task if already down */
5526 if (test_bit(__E1000_DOWN, &adapter->state))
5527 return;
5528
Bruce Allan12d43f72012-12-05 06:26:14 +00005529 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005530 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005531 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005533 e1000e_reinit_locked(adapter);
5534}
5535
5536/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005537 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005538 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005539 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005540 *
5541 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005542 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005543struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5544 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005546 struct e1000_adapter *adapter = netdev_priv(netdev);
5547
5548 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5549 spin_lock(&adapter->stats64_lock);
5550 e1000e_update_stats(adapter);
5551 /* Fill out the OS statistics structure */
5552 stats->rx_bytes = adapter->stats.gorc;
5553 stats->rx_packets = adapter->stats.gprc;
5554 stats->tx_bytes = adapter->stats.gotc;
5555 stats->tx_packets = adapter->stats.gptc;
5556 stats->multicast = adapter->stats.mprc;
5557 stats->collisions = adapter->stats.colc;
5558
5559 /* Rx Errors */
5560
Bruce Allane921eb12012-11-28 09:28:37 +00005561 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005562 * our own version based on RUC and ROC
5563 */
5564 stats->rx_errors = adapter->stats.rxerrc +
5565 adapter->stats.crcerrs + adapter->stats.algnerrc +
5566 adapter->stats.ruc + adapter->stats.roc +
5567 adapter->stats.cexterr;
5568 stats->rx_length_errors = adapter->stats.ruc +
5569 adapter->stats.roc;
5570 stats->rx_crc_errors = adapter->stats.crcerrs;
5571 stats->rx_frame_errors = adapter->stats.algnerrc;
5572 stats->rx_missed_errors = adapter->stats.mpc;
5573
5574 /* Tx Errors */
5575 stats->tx_errors = adapter->stats.ecol +
5576 adapter->stats.latecol;
5577 stats->tx_aborted_errors = adapter->stats.ecol;
5578 stats->tx_window_errors = adapter->stats.latecol;
5579 stats->tx_carrier_errors = adapter->stats.tncrs;
5580
5581 /* Tx Dropped needs to be maintained elsewhere */
5582
5583 spin_unlock(&adapter->stats64_lock);
5584 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005585}
5586
5587/**
5588 * e1000_change_mtu - Change the Maximum Transfer Unit
5589 * @netdev: network interface device structure
5590 * @new_mtu: new value for maximum frame size
5591 *
5592 * Returns 0 on success, negative on failure
5593 **/
5594static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5595{
5596 struct e1000_adapter *adapter = netdev_priv(netdev);
5597 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5598
Bruce Allan2adc55c2009-06-02 11:28:58 +00005599 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005600 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5601 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5602 e_err("Jumbo Frames not supported.\n");
5603 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005604 }
5605
Bruce Allan2adc55c2009-06-02 11:28:58 +00005606 /* Supported frame sizes */
5607 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5608 (max_frame > adapter->max_hw_frame_size)) {
5609 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005610 return -EINVAL;
5611 }
5612
Bruce Allan2fbe4522012-04-19 03:21:47 +00005613 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5614 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005615 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5616 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005617 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005618 return -EINVAL;
5619 }
5620
Auke Kokbc7f75f2007-09-17 12:30:59 -07005621 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005622 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005623 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005624 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005625 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5626 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627 if (netif_running(netdev))
5628 e1000e_down(adapter);
5629
Bruce Allane921eb12012-11-28 09:28:37 +00005630 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005631 * means we reserve 2 more, this pushes us to allocate from the next
5632 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005633 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005634 * However with the new *_jumbo_rx* routines, jumbo receives will use
5635 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005636 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005637
Jesse Brandeburg99261462010-01-22 22:56:16 +00005638 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005639 adapter->rx_buffer_len = 2048;
5640 else
5641 adapter->rx_buffer_len = 4096;
5642
5643 /* adjust allocation if LPE protects us, and we aren't using SBP */
5644 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5645 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5646 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005647 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005648
Auke Kokbc7f75f2007-09-17 12:30:59 -07005649 if (netif_running(netdev))
5650 e1000e_up(adapter);
5651 else
5652 e1000e_reset(adapter);
5653
5654 clear_bit(__E1000_RESETTING, &adapter->state);
5655
5656 return 0;
5657}
5658
5659static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5660 int cmd)
5661{
5662 struct e1000_adapter *adapter = netdev_priv(netdev);
5663 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005664
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005665 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005666 return -EOPNOTSUPP;
5667
5668 switch (cmd) {
5669 case SIOCGMIIPHY:
5670 data->phy_id = adapter->hw.phy.addr;
5671 break;
5672 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005673 e1000_phy_read_status(adapter);
5674
Bruce Allan7c257692008-04-23 11:09:00 -07005675 switch (data->reg_num & 0x1F) {
5676 case MII_BMCR:
5677 data->val_out = adapter->phy_regs.bmcr;
5678 break;
5679 case MII_BMSR:
5680 data->val_out = adapter->phy_regs.bmsr;
5681 break;
5682 case MII_PHYSID1:
5683 data->val_out = (adapter->hw.phy.id >> 16);
5684 break;
5685 case MII_PHYSID2:
5686 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5687 break;
5688 case MII_ADVERTISE:
5689 data->val_out = adapter->phy_regs.advertise;
5690 break;
5691 case MII_LPA:
5692 data->val_out = adapter->phy_regs.lpa;
5693 break;
5694 case MII_EXPANSION:
5695 data->val_out = adapter->phy_regs.expansion;
5696 break;
5697 case MII_CTRL1000:
5698 data->val_out = adapter->phy_regs.ctrl1000;
5699 break;
5700 case MII_STAT1000:
5701 data->val_out = adapter->phy_regs.stat1000;
5702 break;
5703 case MII_ESTATUS:
5704 data->val_out = adapter->phy_regs.estatus;
5705 break;
5706 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005707 return -EIO;
5708 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005709 break;
5710 case SIOCSMIIREG:
5711 default:
5712 return -EOPNOTSUPP;
5713 }
5714 return 0;
5715}
5716
Bruce Allanb67e1912012-12-27 08:32:33 +00005717/**
5718 * e1000e_hwtstamp_ioctl - control hardware time stamping
5719 * @netdev: network interface device structure
5720 * @ifreq: interface request
5721 *
5722 * Outgoing time stamping can be enabled and disabled. Play nice and
5723 * disable it when requested, although it shouldn't cause any overhead
5724 * when no packet needs it. At most one packet in the queue may be
5725 * marked for time stamping, otherwise it would be impossible to tell
5726 * for sure to which packet the hardware time stamp belongs.
5727 *
5728 * Incoming time stamping has to be configured via the hardware filters.
5729 * Not all combinations are supported, in particular event type has to be
5730 * specified. Matching the kind of event packet is not supported, with the
5731 * exception of "all V2 events regardless of level 2 or 4".
5732 **/
5733static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5734{
5735 struct e1000_adapter *adapter = netdev_priv(netdev);
5736 struct hwtstamp_config config;
5737 int ret_val;
5738
5739 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5740 return -EFAULT;
5741
5742 adapter->hwtstamp_config = config;
5743
5744 ret_val = e1000e_config_hwtstamp(adapter);
5745 if (ret_val)
5746 return ret_val;
5747
5748 config = adapter->hwtstamp_config;
5749
Bruce Alland89777b2013-01-19 01:09:58 +00005750 switch (config.rx_filter) {
5751 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5752 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5753 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5754 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5755 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5756 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5757 /* With V2 type filters which specify a Sync or Delay Request,
5758 * Path Delay Request/Response messages are also time stamped
5759 * by hardware so notify the caller the requested packets plus
5760 * some others are time stamped.
5761 */
5762 config.rx_filter = HWTSTAMP_FILTER_SOME;
5763 break;
5764 default:
5765 break;
5766 }
5767
Bruce Allanb67e1912012-12-27 08:32:33 +00005768 return copy_to_user(ifr->ifr_data, &config,
5769 sizeof(config)) ? -EFAULT : 0;
5770}
5771
Auke Kokbc7f75f2007-09-17 12:30:59 -07005772static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5773{
5774 switch (cmd) {
5775 case SIOCGMIIPHY:
5776 case SIOCGMIIREG:
5777 case SIOCSMIIREG:
5778 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005779 case SIOCSHWTSTAMP:
5780 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005781 default:
5782 return -EOPNOTSUPP;
5783 }
5784}
5785
Bruce Allana4f58f52009-06-02 11:29:18 +00005786static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5787{
5788 struct e1000_hw *hw = &adapter->hw;
5789 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005790 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005791 int retval = 0;
5792
5793 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005794 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005795
Bruce Allan2b6b1682011-05-13 07:20:09 +00005796 retval = hw->phy.ops.acquire(hw);
5797 if (retval) {
5798 e_err("Could not acquire PHY\n");
5799 return retval;
5800 }
5801
5802 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5803 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5804 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005805 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005806
5807 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005808 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5809 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005810 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5811 (u16)(mac_reg & 0xFFFF));
5812 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5813 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005814 }
5815
5816 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005817 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005818 mac_reg = er32(RCTL);
5819 if (mac_reg & E1000_RCTL_UPE)
5820 phy_reg |= BM_RCTL_UPE;
5821 if (mac_reg & E1000_RCTL_MPE)
5822 phy_reg |= BM_RCTL_MPE;
5823 phy_reg &= ~(BM_RCTL_MO_MASK);
5824 if (mac_reg & E1000_RCTL_MO_3)
5825 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5826 << BM_RCTL_MO_SHIFT);
5827 if (mac_reg & E1000_RCTL_BAM)
5828 phy_reg |= BM_RCTL_BAM;
5829 if (mac_reg & E1000_RCTL_PMCF)
5830 phy_reg |= BM_RCTL_PMCF;
5831 mac_reg = er32(CTRL);
5832 if (mac_reg & E1000_CTRL_RFCE)
5833 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005834 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005835
5836 /* enable PHY wakeup in MAC register */
5837 ew32(WUFC, wufc);
5838 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5839
5840 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005841 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5842 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005843
5844 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005845 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5846 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005847 if (retval)
5848 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005849release:
Bruce Allan94d81862009-11-20 23:25:26 +00005850 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005851
5852 return retval;
5853}
5854
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005855static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5856 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005857{
5858 struct net_device *netdev = pci_get_drvdata(pdev);
5859 struct e1000_adapter *adapter = netdev_priv(netdev);
5860 struct e1000_hw *hw = &adapter->hw;
5861 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005862 /* Runtime suspend should only enable wakeup for link changes */
5863 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005864 int retval = 0;
5865
5866 netif_device_detach(netdev);
5867
5868 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005869 int count = E1000_CHECK_RESET_COUNT;
5870
5871 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5872 usleep_range(10000, 20000);
5873
Auke Kokbc7f75f2007-09-17 12:30:59 -07005874 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5875 e1000e_down(adapter);
5876 e1000_free_irq(adapter);
5877 }
Bruce Allan4662e822008-08-26 18:37:06 -07005878 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005879
5880 retval = pci_save_state(pdev);
5881 if (retval)
5882 return retval;
5883
5884 status = er32(STATUS);
5885 if (status & E1000_STATUS_LU)
5886 wufc &= ~E1000_WUFC_LNKC;
5887
5888 if (wufc) {
5889 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005890 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891
5892 /* turn on all-multi mode if wake on multicast is enabled */
5893 if (wufc & E1000_WUFC_MC) {
5894 rctl = er32(RCTL);
5895 rctl |= E1000_RCTL_MPE;
5896 ew32(RCTL, rctl);
5897 }
5898
5899 ctrl = er32(CTRL);
5900 /* advertise wake from D3Cold */
5901 #define E1000_CTRL_ADVD3WUC 0x00100000
5902 /* phy power management enable */
5903 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005904 ctrl |= E1000_CTRL_ADVD3WUC;
5905 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5906 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005907 ew32(CTRL, ctrl);
5908
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005909 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5910 adapter->hw.phy.media_type ==
5911 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005912 /* keep the laser running in D3 */
5913 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005914 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005915 ew32(CTRL_EXT, ctrl_ext);
5916 }
5917
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005918 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005919 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005920
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921 /* Allow time for pending master requests to run */
5922 e1000e_disable_pcie_master(&adapter->hw);
5923
Bruce Allan82776a42009-08-14 14:35:33 +00005924 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005925 /* enable wakeup by the PHY */
5926 retval = e1000_init_phy_wakeup(adapter, wufc);
5927 if (retval)
5928 return retval;
5929 } else {
5930 /* enable wakeup by the MAC */
5931 ew32(WUFC, wufc);
5932 ew32(WUC, E1000_WUC_PME_EN);
5933 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934 } else {
5935 ew32(WUC, 0);
5936 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005937 }
5938
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005939 *enable_wake = !!wufc;
5940
Auke Kokbc7f75f2007-09-17 12:30:59 -07005941 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005942 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5943 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005944 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005945
5946 if (adapter->hw.phy.type == e1000_phy_igp_3)
5947 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5948
Bruce Allane921eb12012-11-28 09:28:37 +00005949 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005950 * would have already happened in close and is redundant.
5951 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005952 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005953
5954 pci_disable_device(pdev);
5955
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005956 return 0;
5957}
5958
5959static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5960{
5961 if (sleep && wake) {
5962 pci_prepare_to_sleep(pdev);
5963 return;
5964 }
5965
5966 pci_wake_from_d3(pdev, wake);
5967 pci_set_power_state(pdev, PCI_D3hot);
5968}
5969
5970static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5971 bool wake)
5972{
5973 struct net_device *netdev = pci_get_drvdata(pdev);
5974 struct e1000_adapter *adapter = netdev_priv(netdev);
5975
Bruce Allane921eb12012-11-28 09:28:37 +00005976 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005977 * correctable error when the MAC transitions from D0 to D3. To
5978 * prevent this we need to mask off the correctable errors on the
5979 * downstream port of the pci-e switch.
5980 */
5981 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5982 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005983 u16 devctl;
5984
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005985 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
5986 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
5987 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005988
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005989 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005990
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005991 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005992 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005993 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005994 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995}
5996
Bruce Allan6f461f62010-04-27 03:33:04 +00005997#ifdef CONFIG_PCIEASPM
5998static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5999{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006000 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006001}
6002#else
6003static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006004{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006005 u16 aspm_ctl = 0;
6006
6007 if (state & PCIE_LINK_STATE_L0S)
6008 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6009 if (state & PCIE_LINK_STATE_L1)
6010 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6011
Bruce Allane921eb12012-11-28 09:28:37 +00006012 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006013 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006014 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006015 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006016
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006017 if (pdev->bus->self)
6018 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006019 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006020}
6021#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006022static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006023{
6024 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6025 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6026 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6027
6028 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006029}
6030
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006031#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006032static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006033{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006034 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006035}
6036
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006037static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006038{
6039 struct net_device *netdev = pci_get_drvdata(pdev);
6040 struct e1000_adapter *adapter = netdev_priv(netdev);
6041 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006042 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006043 u32 err;
6044
Bruce Allan78cd29d2011-03-24 03:09:03 +00006045 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6046 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6047 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6048 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6049 if (aspm_disable_flag)
6050 e1000e_disable_aspm(pdev, aspm_disable_flag);
6051
Auke Kokbc7f75f2007-09-17 12:30:59 -07006052 pci_set_power_state(pdev, PCI_D0);
6053 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006054 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006055
Bruce Allan4662e822008-08-26 18:37:06 -07006056 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006057 if (netif_running(netdev)) {
6058 err = e1000_request_irq(adapter);
6059 if (err)
6060 return err;
6061 }
6062
Bruce Allan2fbe4522012-04-19 03:21:47 +00006063 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006064 e1000_resume_workarounds_pchlan(&adapter->hw);
6065
Auke Kokbc7f75f2007-09-17 12:30:59 -07006066 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006067
6068 /* report the system wakeup cause from S3/S4 */
6069 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6070 u16 phy_data;
6071
6072 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6073 if (phy_data) {
6074 e_info("PHY Wakeup cause - %s\n",
6075 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6076 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6077 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6078 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006079 phy_data & E1000_WUS_LNKC ?
6080 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006081 }
6082 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6083 } else {
6084 u32 wus = er32(WUS);
6085 if (wus) {
6086 e_info("MAC Wakeup cause - %s\n",
6087 wus & E1000_WUS_EX ? "Unicast Packet" :
6088 wus & E1000_WUS_MC ? "Multicast Packet" :
6089 wus & E1000_WUS_BC ? "Broadcast Packet" :
6090 wus & E1000_WUS_MAG ? "Magic Packet" :
6091 wus & E1000_WUS_LNKC ? "Link Status Change" :
6092 "other");
6093 }
6094 ew32(WUS, ~0);
6095 }
6096
Auke Kokbc7f75f2007-09-17 12:30:59 -07006097 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006098
Bruce Allancd791612010-05-10 14:59:51 +00006099 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100
6101 if (netif_running(netdev))
6102 e1000e_up(adapter);
6103
6104 netif_device_attach(netdev);
6105
Bruce Allane921eb12012-11-28 09:28:37 +00006106 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006107 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006108 * under the control of the driver.
6109 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006110 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006111 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006112
6113 return 0;
6114}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006115
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006116#ifdef CONFIG_PM_SLEEP
6117static int e1000_suspend(struct device *dev)
6118{
6119 struct pci_dev *pdev = to_pci_dev(dev);
6120 int retval;
6121 bool wake;
6122
6123 retval = __e1000_shutdown(pdev, &wake, false);
6124 if (!retval)
6125 e1000_complete_shutdown(pdev, true, wake);
6126
6127 return retval;
6128}
6129
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006130static int e1000_resume(struct device *dev)
6131{
6132 struct pci_dev *pdev = to_pci_dev(dev);
6133 struct net_device *netdev = pci_get_drvdata(pdev);
6134 struct e1000_adapter *adapter = netdev_priv(netdev);
6135
6136 if (e1000e_pm_ready(adapter))
6137 adapter->idle_check = true;
6138
6139 return __e1000_resume(pdev);
6140}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006141#endif /* CONFIG_PM_SLEEP */
6142
6143#ifdef CONFIG_PM_RUNTIME
6144static int e1000_runtime_suspend(struct device *dev)
6145{
6146 struct pci_dev *pdev = to_pci_dev(dev);
6147 struct net_device *netdev = pci_get_drvdata(pdev);
6148 struct e1000_adapter *adapter = netdev_priv(netdev);
6149
6150 if (e1000e_pm_ready(adapter)) {
6151 bool wake;
6152
6153 __e1000_shutdown(pdev, &wake, true);
6154 }
6155
6156 return 0;
6157}
6158
6159static int e1000_idle(struct device *dev)
6160{
6161 struct pci_dev *pdev = to_pci_dev(dev);
6162 struct net_device *netdev = pci_get_drvdata(pdev);
6163 struct e1000_adapter *adapter = netdev_priv(netdev);
6164
6165 if (!e1000e_pm_ready(adapter))
6166 return 0;
6167
6168 if (adapter->idle_check) {
6169 adapter->idle_check = false;
6170 if (!e1000e_has_link(adapter))
6171 pm_schedule_suspend(dev, MSEC_PER_SEC);
6172 }
6173
6174 return -EBUSY;
6175}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006176
6177static int e1000_runtime_resume(struct device *dev)
6178{
6179 struct pci_dev *pdev = to_pci_dev(dev);
6180 struct net_device *netdev = pci_get_drvdata(pdev);
6181 struct e1000_adapter *adapter = netdev_priv(netdev);
6182
6183 if (!e1000e_pm_ready(adapter))
6184 return 0;
6185
6186 adapter->idle_check = !dev->power.runtime_auto;
6187 return __e1000_resume(pdev);
6188}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006189#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006190#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006191
6192static void e1000_shutdown(struct pci_dev *pdev)
6193{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006194 bool wake = false;
6195
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006196 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006197
6198 if (system_state == SYSTEM_POWER_OFF)
6199 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006200}
6201
6202#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006203
6204static irqreturn_t e1000_intr_msix(int irq, void *data)
6205{
6206 struct net_device *netdev = data;
6207 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006208
6209 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006210 int vector, msix_irq;
6211
Dongdong Deng147b2c82010-11-16 19:50:15 -08006212 vector = 0;
6213 msix_irq = adapter->msix_entries[vector].vector;
6214 disable_irq(msix_irq);
6215 e1000_intr_msix_rx(msix_irq, netdev);
6216 enable_irq(msix_irq);
6217
6218 vector++;
6219 msix_irq = adapter->msix_entries[vector].vector;
6220 disable_irq(msix_irq);
6221 e1000_intr_msix_tx(msix_irq, netdev);
6222 enable_irq(msix_irq);
6223
6224 vector++;
6225 msix_irq = adapter->msix_entries[vector].vector;
6226 disable_irq(msix_irq);
6227 e1000_msix_other(msix_irq, netdev);
6228 enable_irq(msix_irq);
6229 }
6230
6231 return IRQ_HANDLED;
6232}
6233
Bruce Allane921eb12012-11-28 09:28:37 +00006234/**
6235 * e1000_netpoll
6236 * @netdev: network interface device structure
6237 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006238 * Polling 'interrupt' - used by things like netconsole to send skbs
6239 * without having to re-enable interrupts. It's not called while
6240 * the interrupt routine is executing.
6241 */
6242static void e1000_netpoll(struct net_device *netdev)
6243{
6244 struct e1000_adapter *adapter = netdev_priv(netdev);
6245
Dongdong Deng147b2c82010-11-16 19:50:15 -08006246 switch (adapter->int_mode) {
6247 case E1000E_INT_MODE_MSIX:
6248 e1000_intr_msix(adapter->pdev->irq, netdev);
6249 break;
6250 case E1000E_INT_MODE_MSI:
6251 disable_irq(adapter->pdev->irq);
6252 e1000_intr_msi(adapter->pdev->irq, netdev);
6253 enable_irq(adapter->pdev->irq);
6254 break;
6255 default: /* E1000E_INT_MODE_LEGACY */
6256 disable_irq(adapter->pdev->irq);
6257 e1000_intr(adapter->pdev->irq, netdev);
6258 enable_irq(adapter->pdev->irq);
6259 break;
6260 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006261}
6262#endif
6263
6264/**
6265 * e1000_io_error_detected - called when PCI error is detected
6266 * @pdev: Pointer to PCI device
6267 * @state: The current pci connection state
6268 *
6269 * This function is called after a PCI bus error affecting
6270 * this device has been detected.
6271 */
6272static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6273 pci_channel_state_t state)
6274{
6275 struct net_device *netdev = pci_get_drvdata(pdev);
6276 struct e1000_adapter *adapter = netdev_priv(netdev);
6277
6278 netif_device_detach(netdev);
6279
Mike Masonc93b5a72009-06-30 12:45:53 +00006280 if (state == pci_channel_io_perm_failure)
6281 return PCI_ERS_RESULT_DISCONNECT;
6282
Auke Kokbc7f75f2007-09-17 12:30:59 -07006283 if (netif_running(netdev))
6284 e1000e_down(adapter);
6285 pci_disable_device(pdev);
6286
6287 /* Request a slot slot reset. */
6288 return PCI_ERS_RESULT_NEED_RESET;
6289}
6290
6291/**
6292 * e1000_io_slot_reset - called after the pci bus has been reset.
6293 * @pdev: Pointer to PCI device
6294 *
6295 * Restart the card from scratch, as if from a cold-boot. Implementation
6296 * resembles the first-half of the e1000_resume routine.
6297 */
6298static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6299{
6300 struct net_device *netdev = pci_get_drvdata(pdev);
6301 struct e1000_adapter *adapter = netdev_priv(netdev);
6302 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006303 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006304 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006305 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006306
Bruce Allan78cd29d2011-03-24 03:09:03 +00006307 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6308 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006309 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006310 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6311 if (aspm_disable_flag)
6312 e1000e_disable_aspm(pdev, aspm_disable_flag);
6313
Bruce Allanf0f422e2008-08-04 17:21:53 -07006314 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006315 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006316 dev_err(&pdev->dev,
6317 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006318 result = PCI_ERS_RESULT_DISCONNECT;
6319 } else {
6320 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006321 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006322 pci_restore_state(pdev);
6323
6324 pci_enable_wake(pdev, PCI_D3hot, 0);
6325 pci_enable_wake(pdev, PCI_D3cold, 0);
6326
6327 e1000e_reset(adapter);
6328 ew32(WUS, ~0);
6329 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006330 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006331
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006332 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006333
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006334 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006335}
6336
6337/**
6338 * e1000_io_resume - called when traffic can start flowing again.
6339 * @pdev: Pointer to PCI device
6340 *
6341 * This callback is called when the error recovery driver tells us that
6342 * its OK to resume normal operation. Implementation resembles the
6343 * second-half of the e1000_resume routine.
6344 */
6345static void e1000_io_resume(struct pci_dev *pdev)
6346{
6347 struct net_device *netdev = pci_get_drvdata(pdev);
6348 struct e1000_adapter *adapter = netdev_priv(netdev);
6349
Bruce Allancd791612010-05-10 14:59:51 +00006350 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006351
6352 if (netif_running(netdev)) {
6353 if (e1000e_up(adapter)) {
6354 dev_err(&pdev->dev,
6355 "can't bring device back up after reset\n");
6356 return;
6357 }
6358 }
6359
6360 netif_device_attach(netdev);
6361
Bruce Allane921eb12012-11-28 09:28:37 +00006362 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006363 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006364 * under the control of the driver.
6365 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006366 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006367 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006368
6369}
6370
6371static void e1000_print_device_info(struct e1000_adapter *adapter)
6372{
6373 struct e1000_hw *hw = &adapter->hw;
6374 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006375 u32 ret_val;
6376 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006377
6378 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006379 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006380 /* bus width */
6381 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6382 "Width x1"),
6383 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006384 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006385 e_info("Intel(R) PRO/%s Network Connection\n",
6386 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006387 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6388 E1000_PBANUM_LENGTH);
6389 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006390 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006391 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6392 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393}
6394
Auke Kok10aa4c02008-08-04 17:21:20 -07006395static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6396{
6397 struct e1000_hw *hw = &adapter->hw;
6398 int ret_val;
6399 u16 buf = 0;
6400
6401 if (hw->mac.type != e1000_82573)
6402 return;
6403
6404 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006405 le16_to_cpus(&buf);
6406 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006407 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006408 dev_warn(&adapter->pdev->dev,
6409 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006410 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006411}
6412
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006413static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006414 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006415{
6416 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006417 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006418
6419 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6420 adapter->flags |= FLAG_TSO_FORCE;
6421
6422 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006423 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6424 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006425 return 0;
6426
Ben Greear01840392012-02-11 15:39:25 +00006427 if (changed & NETIF_F_RXFCS) {
6428 if (features & NETIF_F_RXFCS) {
6429 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6430 } else {
6431 /* We need to take it back to defaults, which might mean
6432 * stripping is still disabled at the adapter level.
6433 */
6434 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6435 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6436 else
6437 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6438 }
6439 }
6440
Bruce Allan70495a52012-01-11 01:26:50 +00006441 netdev->features = features;
6442
Bruce Allandc221292011-08-19 03:23:48 +00006443 if (netif_running(netdev))
6444 e1000e_reinit_locked(adapter);
6445 else
6446 e1000e_reset(adapter);
6447
6448 return 0;
6449}
6450
Stephen Hemminger651c2462008-11-19 21:57:48 -08006451static const struct net_device_ops e1000e_netdev_ops = {
6452 .ndo_open = e1000_open,
6453 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006454 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006455 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006456 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006457 .ndo_set_mac_address = e1000_set_mac,
6458 .ndo_change_mtu = e1000_change_mtu,
6459 .ndo_do_ioctl = e1000_ioctl,
6460 .ndo_tx_timeout = e1000_tx_timeout,
6461 .ndo_validate_addr = eth_validate_addr,
6462
Stephen Hemminger651c2462008-11-19 21:57:48 -08006463 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6464 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6465#ifdef CONFIG_NET_POLL_CONTROLLER
6466 .ndo_poll_controller = e1000_netpoll,
6467#endif
Bruce Allandc221292011-08-19 03:23:48 +00006468 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006469};
6470
Auke Kokbc7f75f2007-09-17 12:30:59 -07006471/**
6472 * e1000_probe - Device Initialization Routine
6473 * @pdev: PCI device information struct
6474 * @ent: entry in e1000_pci_tbl
6475 *
6476 * Returns 0 on success, negative on failure
6477 *
6478 * e1000_probe initializes an adapter identified by a pci_dev structure.
6479 * The OS initialization, configuring of the adapter private structure,
6480 * and a hardware reset occur.
6481 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006482static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006483{
6484 struct net_device *netdev;
6485 struct e1000_adapter *adapter;
6486 struct e1000_hw *hw;
6487 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006488 resource_size_t mmio_start, mmio_len;
6489 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006490 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006491 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006492 int i, err, pci_using_dac;
6493 u16 eeprom_data = 0;
6494 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6495
Bruce Allan78cd29d2011-03-24 03:09:03 +00006496 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6497 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006498 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006499 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6500 if (aspm_disable_flag)
6501 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006502
Bruce Allanf0f422e2008-08-04 17:21:53 -07006503 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006504 if (err)
6505 return err;
6506
6507 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006508 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006509 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006510 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006511 if (!err)
6512 pci_using_dac = 1;
6513 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006514 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006515 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006516 err = dma_set_coherent_mask(&pdev->dev,
6517 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006518 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006519 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006520 goto err_dma;
6521 }
6522 }
6523 }
6524
Arjan van de Vene8de1482008-10-22 19:55:31 -07006525 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006526 pci_select_bars(pdev, IORESOURCE_MEM),
6527 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006528 if (err)
6529 goto err_pci_reg;
6530
Xiaotian Feng68eac462009-08-14 14:35:52 +00006531 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006532 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006533
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006535 /* PCI config space info */
6536 err = pci_save_state(pdev);
6537 if (err)
6538 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006539
6540 err = -ENOMEM;
6541 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6542 if (!netdev)
6543 goto err_alloc_etherdev;
6544
Auke Kokbc7f75f2007-09-17 12:30:59 -07006545 SET_NETDEV_DEV(netdev, &pdev->dev);
6546
Tom Herbertf85e4df2010-05-05 14:03:32 +00006547 netdev->irq = pdev->irq;
6548
Auke Kokbc7f75f2007-09-17 12:30:59 -07006549 pci_set_drvdata(pdev, netdev);
6550 adapter = netdev_priv(netdev);
6551 hw = &adapter->hw;
6552 adapter->netdev = netdev;
6553 adapter->pdev = pdev;
6554 adapter->ei = ei;
6555 adapter->pba = ei->pba;
6556 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006557 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006558 adapter->hw.adapter = adapter;
6559 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006560 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006561 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006562
6563 mmio_start = pci_resource_start(pdev, 0);
6564 mmio_len = pci_resource_len(pdev, 0);
6565
6566 err = -EIO;
6567 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6568 if (!adapter->hw.hw_addr)
6569 goto err_ioremap;
6570
6571 if ((adapter->flags & FLAG_HAS_FLASH) &&
6572 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6573 flash_start = pci_resource_start(pdev, 1);
6574 flash_len = pci_resource_len(pdev, 1);
6575 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6576 if (!adapter->hw.flash_address)
6577 goto err_flashmap;
6578 }
6579
6580 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006581 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006582 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006583 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006584 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006585 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006586
6587 netdev->mem_start = mmio_start;
6588 netdev->mem_end = mmio_start + mmio_len;
6589
6590 adapter->bd_number = cards_found++;
6591
Bruce Allan4662e822008-08-26 18:37:06 -07006592 e1000e_check_options(adapter);
6593
Auke Kokbc7f75f2007-09-17 12:30:59 -07006594 /* setup adapter struct */
6595 err = e1000_sw_init(adapter);
6596 if (err)
6597 goto err_sw_init;
6598
Auke Kokbc7f75f2007-09-17 12:30:59 -07006599 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6600 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6601 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6602
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006603 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006604 if (err)
6605 goto err_hw_init;
6606
Bruce Allan4a770352008-10-01 17:18:35 -07006607 if ((adapter->flags & FLAG_IS_ICH) &&
6608 (adapter->flags & FLAG_READ_ONLY_NVM))
6609 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6610
Auke Kokbc7f75f2007-09-17 12:30:59 -07006611 hw->mac.ops.get_bus_info(&adapter->hw);
6612
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006613 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006614
6615 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006616 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006617 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6618 adapter->hw.phy.disable_polarity_correction = 0;
6619 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6620 }
6621
Bruce Allan470a5422012-05-26 06:08:48 +00006622 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006623 dev_info(&pdev->dev,
6624 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006625
Bruce Allandc221292011-08-19 03:23:48 +00006626 /* Set initial default active device features */
6627 netdev->features = (NETIF_F_SG |
6628 NETIF_F_HW_VLAN_RX |
6629 NETIF_F_HW_VLAN_TX |
6630 NETIF_F_TSO |
6631 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006632 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006633 NETIF_F_RXCSUM |
6634 NETIF_F_HW_CSUM);
6635
6636 /* Set user-changeable features (subset of all device features) */
6637 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006638 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006639 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006640 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006641
6642 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6643 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6644
Bruce Allandc221292011-08-19 03:23:48 +00006645 netdev->vlan_features |= (NETIF_F_SG |
6646 NETIF_F_TSO |
6647 NETIF_F_TSO6 |
6648 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006649
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006650 netdev->priv_flags |= IFF_UNICAST_FLT;
6651
Yi Zou7b872a52010-09-22 17:57:58 +00006652 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006653 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006654 netdev->vlan_features |= NETIF_F_HIGHDMA;
6655 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006656
Auke Kokbc7f75f2007-09-17 12:30:59 -07006657 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6658 adapter->flags |= FLAG_MNG_PT_ENABLED;
6659
Bruce Allane921eb12012-11-28 09:28:37 +00006660 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006661 * put the device in a known good starting state
6662 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006663 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6664
Bruce Allane921eb12012-11-28 09:28:37 +00006665 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006666 * attempt. Let's give it a few tries
6667 */
6668 for (i = 0;; i++) {
6669 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6670 break;
6671 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006672 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006673 err = -EIO;
6674 goto err_eeprom;
6675 }
6676 }
6677
Auke Kok10aa4c02008-08-04 17:21:20 -07006678 e1000_eeprom_checks(adapter);
6679
Bruce Allan608f8a02010-01-13 02:04:58 +00006680 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006681 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006682 dev_err(&pdev->dev,
6683 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006684
6685 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006686
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006687 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006688 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006689 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006690 err = -EIO;
6691 goto err_eeprom;
6692 }
6693
6694 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006695 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006696 adapter->watchdog_timer.data = (unsigned long) adapter;
6697
6698 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006699 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006700 adapter->phy_info_timer.data = (unsigned long) adapter;
6701
6702 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6703 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006704 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6705 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006706 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707
Auke Kokbc7f75f2007-09-17 12:30:59 -07006708 /* Initialize link parameters. User can change them with ethtool */
6709 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006710 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006711 adapter->hw.fc.requested_mode = e1000_fc_default;
6712 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006713 adapter->hw.phy.autoneg_advertised = 0x2f;
6714
6715 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006716 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6717 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006718
Bruce Allane921eb12012-11-28 09:28:37 +00006719 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006720 * the EEPROM, enable the ACPI Magic Packet filter
6721 */
6722 if (adapter->flags & FLAG_APME_IN_WUC) {
6723 /* APME bit in EEPROM is mapped to WUC.APME */
6724 eeprom_data = er32(WUC);
6725 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006726 if ((hw->mac.type > e1000_ich10lan) &&
6727 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006728 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006729 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6730 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6731 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006732 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6733 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006734 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006735 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6736 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006737 }
6738
6739 /* fetch WoL from EEPROM */
6740 if (eeprom_data & eeprom_apme_mask)
6741 adapter->eeprom_wol |= E1000_WUFC_MAG;
6742
Bruce Allane921eb12012-11-28 09:28:37 +00006743 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006744 * where the eeprom may be wrong or the board simply won't support
6745 * wake on lan on a particular port
6746 */
6747 if (!(adapter->flags & FLAG_HAS_WOL))
6748 adapter->eeprom_wol = 0;
6749
6750 /* initialize the wol settings based on the eeprom settings */
6751 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006752 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006753
Bruce Allan84527592008-11-21 17:00:22 -08006754 /* save off EEPROM version number */
6755 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6756
Auke Kokbc7f75f2007-09-17 12:30:59 -07006757 /* reset the hardware with the new settings */
6758 e1000e_reset(adapter);
6759
Bruce Allane921eb12012-11-28 09:28:37 +00006760 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006761 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006762 * under the control of the driver.
6763 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006764 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006765 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006766
Bruce Allanf2315bf2011-12-16 00:46:59 +00006767 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006768 err = register_netdev(netdev);
6769 if (err)
6770 goto err_register;
6771
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006772 /* carrier off reporting is important to ethtool even BEFORE open */
6773 netif_carrier_off(netdev);
6774
Bruce Alland89777b2013-01-19 01:09:58 +00006775 /* init PTP hardware clock */
6776 e1000e_ptp_init(adapter);
6777
Auke Kokbc7f75f2007-09-17 12:30:59 -07006778 e1000_print_device_info(adapter);
6779
Alan Sternf3ec4f82010-06-08 15:23:51 -04006780 if (pci_dev_run_wake(pdev))
6781 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006782
Auke Kokbc7f75f2007-09-17 12:30:59 -07006783 return 0;
6784
6785err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006786 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006787 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006788err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006789 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006790 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006791err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006792 kfree(adapter->tx_ring);
6793 kfree(adapter->rx_ring);
6794err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006795 if (adapter->hw.flash_address)
6796 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006797 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006798err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006799 iounmap(adapter->hw.hw_addr);
6800err_ioremap:
6801 free_netdev(netdev);
6802err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006803 pci_release_selected_regions(pdev,
6804 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006805err_pci_reg:
6806err_dma:
6807 pci_disable_device(pdev);
6808 return err;
6809}
6810
6811/**
6812 * e1000_remove - Device Removal Routine
6813 * @pdev: PCI device information struct
6814 *
6815 * e1000_remove is called by the PCI subsystem to alert the driver
6816 * that it should release a PCI device. The could be caused by a
6817 * Hot-Plug event, or because the driver is going to be removed from
6818 * memory.
6819 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006820static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006821{
6822 struct net_device *netdev = pci_get_drvdata(pdev);
6823 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006824 bool down = test_bit(__E1000_DOWN, &adapter->state);
6825
Bruce Alland89777b2013-01-19 01:09:58 +00006826 e1000e_ptp_remove(adapter);
6827
Bruce Allane921eb12012-11-28 09:28:37 +00006828 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006829 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006830 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006831 if (!down)
6832 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006833 del_timer_sync(&adapter->watchdog_timer);
6834 del_timer_sync(&adapter->phy_info_timer);
6835
Bruce Allan41cec6f2009-11-20 23:28:56 +00006836 cancel_work_sync(&adapter->reset_task);
6837 cancel_work_sync(&adapter->watchdog_task);
6838 cancel_work_sync(&adapter->downshift_task);
6839 cancel_work_sync(&adapter->update_phy_task);
6840 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006841
Bruce Allanb67e1912012-12-27 08:32:33 +00006842 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6843 cancel_work_sync(&adapter->tx_hwtstamp_work);
6844 if (adapter->tx_hwtstamp_skb) {
6845 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6846 adapter->tx_hwtstamp_skb = NULL;
6847 }
6848 }
6849
Bruce Allan17f208d2009-12-01 15:47:22 +00006850 if (!(netdev->flags & IFF_UP))
6851 e1000_power_down_phy(adapter);
6852
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006853 /* Don't lie to e1000_close() down the road. */
6854 if (!down)
6855 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006856 unregister_netdev(netdev);
6857
Alan Sternf3ec4f82010-06-08 15:23:51 -04006858 if (pci_dev_run_wake(pdev))
6859 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006860
Bruce Allane921eb12012-11-28 09:28:37 +00006861 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006862 * would have already happened in close and is redundant.
6863 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006864 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006865
Bruce Allan4662e822008-08-26 18:37:06 -07006866 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006867 kfree(adapter->tx_ring);
6868 kfree(adapter->rx_ring);
6869
6870 iounmap(adapter->hw.hw_addr);
6871 if (adapter->hw.flash_address)
6872 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006873 pci_release_selected_regions(pdev,
6874 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006875
6876 free_netdev(netdev);
6877
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006878 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006879 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006880
Auke Kokbc7f75f2007-09-17 12:30:59 -07006881 pci_disable_device(pdev);
6882}
6883
6884/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006885static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006886 .error_detected = e1000_io_error_detected,
6887 .slot_reset = e1000_io_slot_reset,
6888 .resume = e1000_io_resume,
6889};
6890
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006891static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006892 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6893 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6894 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6895 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6896 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6897 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006898 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6899 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6900 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006901
Auke Kokbc7f75f2007-09-17 12:30:59 -07006902 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6903 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6904 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6905 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006906
Auke Kokbc7f75f2007-09-17 12:30:59 -07006907 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6908 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6909 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006910
Bruce Allan4662e822008-08-26 18:37:06 -07006911 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006912 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006913 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006914
Auke Kokbc7f75f2007-09-17 12:30:59 -07006915 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6916 board_80003es2lan },
6917 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6918 board_80003es2lan },
6919 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6920 board_80003es2lan },
6921 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6922 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006923
Auke Kokbc7f75f2007-09-17 12:30:59 -07006924 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6925 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6926 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6927 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6928 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6929 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6930 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006931 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006932
Auke Kokbc7f75f2007-09-17 12:30:59 -07006933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6936 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6942
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006946
Bruce Allanf4187b52008-08-26 18:36:50 -07006947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006950
Bruce Allana4f58f52009-06-02 11:29:18 +00006951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6955
Bruce Alland3738bb2010-06-16 13:27:28 +00006956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6958
Bruce Allan2fbe4522012-04-19 03:21:47 +00006959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006963
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006964 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006965};
6966MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6967
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006968#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006969static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006970 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6971 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6972 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006973};
David S. Millere50208a2010-03-16 23:36:24 -07006974#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006975
Auke Kokbc7f75f2007-09-17 12:30:59 -07006976/* PCI Device API Driver */
6977static struct pci_driver e1000_driver = {
6978 .name = e1000e_driver_name,
6979 .id_table = e1000_pci_tbl,
6980 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006981 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006982#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006983 .driver = {
6984 .pm = &e1000_pm_ops,
6985 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006986#endif
6987 .shutdown = e1000_shutdown,
6988 .err_handler = &e1000_err_handler
6989};
6990
6991/**
6992 * e1000_init_module - Driver Registration Routine
6993 *
6994 * e1000_init_module is the first routine called when the driver is
6995 * loaded. All it does is register with the PCI subsystem.
6996 **/
6997static int __init e1000_init_module(void)
6998{
6999 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007000 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7001 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00007002 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007003 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007004
Auke Kokbc7f75f2007-09-17 12:30:59 -07007005 return ret;
7006}
7007module_init(e1000_init_module);
7008
7009/**
7010 * e1000_exit_module - Driver Exit Cleanup Routine
7011 *
7012 * e1000_exit_module is called just before the driver is removed
7013 * from memory.
7014 **/
7015static void __exit e1000_exit_module(void)
7016{
7017 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007018}
7019module_exit(e1000_exit_module);
7020
7021
7022MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7023MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7024MODULE_LICENSE("GPL");
7025MODULE_VERSION(DRV_VERSION);
7026
Bruce Allan06c24b92012-02-23 03:13:13 +00007027/* netdev.c */