blob: 8bb5d28eca1474a24c7a30e09b8542345dfe8052 [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 **/
3416static s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
3417{
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;
3488 u32 regval;
3489 s32 ret_val;
3490
3491 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3492 return -EINVAL;
3493
3494 /* flags reserved for future extensions - must be zero */
3495 if (config->flags)
3496 return -EINVAL;
3497
3498 switch (config->tx_type) {
3499 case HWTSTAMP_TX_OFF:
3500 tsync_tx_ctl = 0;
3501 break;
3502 case HWTSTAMP_TX_ON:
3503 break;
3504 default:
3505 return -ERANGE;
3506 }
3507
3508 switch (config->rx_filter) {
3509 case HWTSTAMP_FILTER_NONE:
3510 tsync_rx_ctl = 0;
3511 break;
3512 case HWTSTAMP_FILTER_ALL:
3513 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3514 config->rx_filter = HWTSTAMP_FILTER_ALL;
3515 break;
3516 default:
3517 return -ERANGE;
3518 }
3519
3520 /* enable/disable Tx h/w time stamping */
3521 regval = er32(TSYNCTXCTL);
3522 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3523 regval |= tsync_tx_ctl;
3524 ew32(TSYNCTXCTL, regval);
3525 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3526 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3527 e_err("Timesync Tx Control register not set as expected\n");
3528 return -EAGAIN;
3529 }
3530
3531 /* enable/disable Rx h/w time stamping */
3532 regval = er32(TSYNCRXCTL);
3533 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3534 regval |= tsync_rx_ctl;
3535 ew32(TSYNCRXCTL, regval);
3536 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3537 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3538 (regval & (E1000_TSYNCRXCTL_ENABLED |
3539 E1000_TSYNCRXCTL_TYPE_MASK))) {
3540 e_err("Timesync Rx Control register not set as expected\n");
3541 return -EAGAIN;
3542 }
3543
3544 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
3545 regval = er32(RXSTMPH);
3546 regval = er32(TXSTMPH);
3547
3548 /* Get and set the System Time Register SYSTIM base frequency */
3549 ret_val = e1000e_get_base_timinca(adapter, &regval);
3550 if (ret_val)
3551 return ret_val;
3552 ew32(TIMINCA, regval);
3553
3554 /* reset the ns time counter */
3555 timecounter_init(&adapter->tc, &adapter->cc,
3556 ktime_to_ns(ktime_get_real()));
3557
3558 return 0;
3559}
3560
3561/**
Bruce Allanad680762008-03-28 09:15:03 -07003562 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003563 * @adapter: private board structure
3564 **/
3565static void e1000_configure(struct e1000_adapter *adapter)
3566{
Bruce Allan55aa6982011-12-16 00:45:45 +00003567 struct e1000_ring *rx_ring = adapter->rx_ring;
3568
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003569 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570
3571 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003572 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003573
3574 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003575
3576 if (adapter->netdev->features & NETIF_F_RXHASH)
3577 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578 e1000_setup_rctl(adapter);
3579 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003580 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003581}
3582
3583/**
3584 * e1000e_power_up_phy - restore link in case the phy was powered down
3585 * @adapter: address of board private structure
3586 *
3587 * The phy may be powered down to save power and turn off link when the
3588 * driver is unloaded and wake on lan is not enabled (among others)
3589 * *** this routine MUST be followed by a call to e1000e_reset ***
3590 **/
3591void e1000e_power_up_phy(struct e1000_adapter *adapter)
3592{
Bruce Allan17f208d2009-12-01 15:47:22 +00003593 if (adapter->hw.phy.ops.power_up)
3594 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595
3596 adapter->hw.mac.ops.setup_link(&adapter->hw);
3597}
3598
3599/**
3600 * e1000_power_down_phy - Power down the PHY
3601 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003602 * Power down the PHY so no link is implied when interface is down.
3603 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003604 */
3605static void e1000_power_down_phy(struct e1000_adapter *adapter)
3606{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003608 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 return;
3610
Bruce Allan17f208d2009-12-01 15:47:22 +00003611 if (adapter->hw.phy.ops.power_down)
3612 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003613}
3614
3615/**
3616 * e1000e_reset - bring the hardware into a known good state
3617 *
3618 * This function boots the hardware and enables some settings that
3619 * require a configuration cycle of the hardware - those cannot be
3620 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003621 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003622 */
3623void e1000e_reset(struct e1000_adapter *adapter)
3624{
3625 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003626 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 struct e1000_hw *hw = &adapter->hw;
3628 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003629 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003630 u16 hwm;
3631
Bruce Allanad680762008-03-28 09:15:03 -07003632 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003633 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003634
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003635 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003636 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003637 * large enough to accommodate two full transmit packets,
3638 * rounded up to the next 1KB and expressed in KB. Likewise,
3639 * the Rx FIFO should be large enough to accommodate at least
3640 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003641 * expressed in KB.
3642 */
Auke Kokdf762462007-10-25 13:57:53 -07003643 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003644 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003645 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003647 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003648 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003649 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003650 */
3651 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003652 sizeof(struct e1000_tx_desc) -
3653 ETH_FCS_LEN) * 2;
3654 min_tx_space = ALIGN(min_tx_space, 1024);
3655 min_tx_space >>= 10;
3656 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003657 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003658 min_rx_space = ALIGN(min_rx_space, 1024);
3659 min_rx_space >>= 10;
3660
Bruce Allane921eb12012-11-28 09:28:37 +00003661 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003662 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003663 * allocation, take space away from current Rx allocation
3664 */
Auke Kokdf762462007-10-25 13:57:53 -07003665 if ((tx_space < min_tx_space) &&
3666 ((min_tx_space - tx_space) < pba)) {
3667 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003668
Bruce Allane921eb12012-11-28 09:28:37 +00003669 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003670 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003671 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003672 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003673 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003674 }
Auke Kokdf762462007-10-25 13:57:53 -07003675
3676 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677 }
3678
Bruce Allane921eb12012-11-28 09:28:37 +00003679 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003680 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003681 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 * (or the size used for early receive) above it in the Rx FIFO.
3683 * Set it to the lower of:
3684 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003685 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003686 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003687 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3688 fc->pause_time = 0xFFFF;
3689 else
3690 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003691 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003692 fc->current_mode = fc->requested_mode;
3693
3694 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003695 case e1000_ich9lan:
3696 case e1000_ich10lan:
3697 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3698 pba = 14;
3699 ew32(PBA, pba);
3700 fc->high_water = 0x2800;
3701 fc->low_water = fc->high_water - 8;
3702 break;
3703 }
3704 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003705 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003706 hwm = min(((pba << 10) * 9 / 10),
3707 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003708
3709 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3710 fc->low_water = fc->high_water - 8;
3711 break;
3712 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003713 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003714 * loads. If hangs persist, try disabling Tx flow control.
3715 */
3716 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3717 fc->high_water = 0x3500;
3718 fc->low_water = 0x1500;
3719 } else {
3720 fc->high_water = 0x5000;
3721 fc->low_water = 0x3000;
3722 }
Bruce Allana3055952010-05-10 15:02:12 +00003723 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003724 break;
3725 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003726 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003727 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003728
3729 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3730 fc->high_water = 0x05C20;
3731 fc->low_water = 0x05048;
3732 fc->pause_time = 0x0650;
3733 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003734 }
Bruce Allan347b5202012-12-08 00:35:35 +00003735
3736 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3737 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003738 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003739 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740
Bruce Allane921eb12012-11-28 09:28:37 +00003741 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003742 * maximum size per Tx descriptor limited only to the transmit
3743 * allocation of the packet buffer minus 96 bytes with an upper
3744 * limit of 24KB due to receive synchronization limitations.
3745 */
3746 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3747 24 << 10);
3748
Bruce Allane921eb12012-11-28 09:28:37 +00003749 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003750 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003751 */
3752 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003753 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003754 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3755 dev_info(&adapter->pdev->dev,
3756 "Interrupt Throttle Rate turned off\n");
3757 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003758 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003759 }
3760 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3761 dev_info(&adapter->pdev->dev,
3762 "Interrupt Throttle Rate turned on\n");
3763 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3764 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003765 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003766 }
3767 }
3768
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769 /* Allow time for pending master requests to run */
3770 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003771
Bruce Allane921eb12012-11-28 09:28:37 +00003772 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003773 * that the network interface is in control
3774 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003775 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003776 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003777
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 ew32(WUC, 0);
3779
3780 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003781 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003782
3783 e1000_update_mng_vlan(adapter);
3784
3785 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3786 ew32(VET, ETH_P_8021Q);
3787
3788 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003789
Bruce Allanb67e1912012-12-27 08:32:33 +00003790 /* initialize systim and reset the ns time counter */
3791 e1000e_config_hwtstamp(adapter);
3792
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003793 if (!netif_running(adapter->netdev) &&
3794 !test_bit(__E1000_TESTING, &adapter->state)) {
3795 e1000_power_down_phy(adapter);
3796 return;
3797 }
3798
Auke Kokbc7f75f2007-09-17 12:30:59 -07003799 e1000_get_phy_info(hw);
3800
Bruce Allan918d7192009-06-02 11:28:20 +00003801 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3802 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003803 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003804 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003805 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003806 * different we would do if it failed
3807 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003808 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3809 phy_data &= ~IGP02E1000_PM_SPD;
3810 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3811 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003812}
3813
3814int e1000e_up(struct e1000_adapter *adapter)
3815{
3816 struct e1000_hw *hw = &adapter->hw;
3817
3818 /* hardware has been reset, we need to reload some things */
3819 e1000_configure(adapter);
3820
3821 clear_bit(__E1000_DOWN, &adapter->state);
3822
Bruce Allan4662e822008-08-26 18:37:06 -07003823 if (adapter->msix_entries)
3824 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003825 e1000_irq_enable(adapter);
3826
Bruce Allan400484f2011-05-13 07:20:03 +00003827 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003828
Auke Kokbc7f75f2007-09-17 12:30:59 -07003829 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003830 if (adapter->msix_entries)
3831 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3832 else
3833 ew32(ICS, E1000_ICS_LSC);
3834
Auke Kokbc7f75f2007-09-17 12:30:59 -07003835 return 0;
3836}
3837
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003838static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3839{
3840 struct e1000_hw *hw = &adapter->hw;
3841
3842 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3843 return;
3844
3845 /* flush pending descriptor writebacks to memory */
3846 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3847 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3848
3849 /* execute the writes immediately */
3850 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003851
Bruce Allane921eb12012-11-28 09:28:37 +00003852 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003853 * write is successful
3854 */
3855 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3856 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3857
3858 /* execute the writes immediately */
3859 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003860}
3861
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003862static void e1000e_update_stats(struct e1000_adapter *adapter);
3863
Auke Kokbc7f75f2007-09-17 12:30:59 -07003864void e1000e_down(struct e1000_adapter *adapter)
3865{
3866 struct net_device *netdev = adapter->netdev;
3867 struct e1000_hw *hw = &adapter->hw;
3868 u32 tctl, rctl;
3869
Bruce Allane921eb12012-11-28 09:28:37 +00003870 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003871 * reschedule our watchdog timer
3872 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003873 set_bit(__E1000_DOWN, &adapter->state);
3874
3875 /* disable receives in the hardware */
3876 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003877 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3878 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003879 /* flush and sleep below */
3880
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003881 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003882
3883 /* disable transmits in the hardware */
3884 tctl = er32(TCTL);
3885 tctl &= ~E1000_TCTL_EN;
3886 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003887
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888 /* flush both disables and wait for them to finish */
3889 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003890 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003891
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 e1000_irq_disable(adapter);
3893
3894 del_timer_sync(&adapter->watchdog_timer);
3895 del_timer_sync(&adapter->phy_info_timer);
3896
Auke Kokbc7f75f2007-09-17 12:30:59 -07003897 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003898
3899 spin_lock(&adapter->stats64_lock);
3900 e1000e_update_stats(adapter);
3901 spin_unlock(&adapter->stats64_lock);
3902
Bruce Allan400484f2011-05-13 07:20:03 +00003903 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003904 e1000_clean_tx_ring(adapter->tx_ring);
3905 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00003906
Auke Kokbc7f75f2007-09-17 12:30:59 -07003907 adapter->link_speed = 0;
3908 adapter->link_duplex = 0;
3909
Jeff Kirsher52cc3082008-06-24 17:01:29 -07003910 if (!pci_channel_offline(adapter->pdev))
3911 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003912
Bruce Allane921eb12012-11-28 09:28:37 +00003913 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 * pci_disable_device here.
3915 */
3916}
3917
3918void e1000e_reinit_locked(struct e1000_adapter *adapter)
3919{
3920 might_sleep();
3921 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00003922 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003923 e1000e_down(adapter);
3924 e1000e_up(adapter);
3925 clear_bit(__E1000_RESETTING, &adapter->state);
3926}
3927
3928/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003929 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
3930 * @cc: cyclecounter structure
3931 **/
3932static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
3933{
3934 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
3935 cc);
3936 struct e1000_hw *hw = &adapter->hw;
3937 cycle_t systim;
3938
3939 /* latch SYSTIMH on read of SYSTIML */
3940 systim = (cycle_t)er32(SYSTIML);
3941 systim |= (cycle_t)er32(SYSTIMH) << 32;
3942
3943 return systim;
3944}
3945
3946/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003947 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
3948 * @adapter: board private structure to initialize
3949 *
3950 * e1000_sw_init initializes the Adapter private data structure.
3951 * Fields are initialized based on PCI device information and
3952 * OS network device settings (MTU size).
3953 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05003954static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003956 struct net_device *netdev = adapter->netdev;
3957
3958 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
3959 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003960 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3961 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00003962 adapter->tx_ring_count = E1000_DEFAULT_TXD;
3963 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003964
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003965 spin_lock_init(&adapter->stats64_lock);
3966
Bruce Allan4662e822008-08-26 18:37:06 -07003967 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968
Bruce Allan4662e822008-08-26 18:37:06 -07003969 if (e1000_alloc_queues(adapter))
3970 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971
Bruce Allanb67e1912012-12-27 08:32:33 +00003972 /* Setup hardware time stamping cyclecounter */
3973 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
3974 adapter->cc.read = e1000e_cyclecounter_read;
3975 adapter->cc.mask = CLOCKSOURCE_MASK(64);
3976 adapter->cc.mult = 1;
3977 /* cc.shift set in e1000e_get_base_tininca() */
3978
3979 spin_lock_init(&adapter->systim_lock);
3980 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
3981 }
3982
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984 e1000_irq_disable(adapter);
3985
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986 set_bit(__E1000_DOWN, &adapter->state);
3987 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003988}
3989
3990/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07003991 * e1000_intr_msi_test - Interrupt Handler
3992 * @irq: interrupt number
3993 * @data: pointer to a network interface device structure
3994 **/
3995static irqreturn_t e1000_intr_msi_test(int irq, void *data)
3996{
3997 struct net_device *netdev = data;
3998 struct e1000_adapter *adapter = netdev_priv(netdev);
3999 struct e1000_hw *hw = &adapter->hw;
4000 u32 icr = er32(ICR);
4001
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004002 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004003 if (icr & E1000_ICR_RXSEQ) {
4004 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004005 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004006 * interrupt is handled.
4007 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004008 wmb();
4009 }
4010
4011 return IRQ_HANDLED;
4012}
4013
4014/**
4015 * e1000_test_msi_interrupt - Returns 0 for successful test
4016 * @adapter: board private struct
4017 *
4018 * code flow taken from tg3.c
4019 **/
4020static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4021{
4022 struct net_device *netdev = adapter->netdev;
4023 struct e1000_hw *hw = &adapter->hw;
4024 int err;
4025
4026 /* poll_enable hasn't been called yet, so don't need disable */
4027 /* clear any pending events */
4028 er32(ICR);
4029
4030 /* free the real vector and request a test handler */
4031 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004032 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004033
4034 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004035 * MSI irq handler will unset this flag
4036 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004037 adapter->flags |= FLAG_MSI_TEST_FAILED;
4038
4039 err = pci_enable_msi(adapter->pdev);
4040 if (err)
4041 goto msi_test_failed;
4042
Joe Perchesa0607fd2009-11-18 23:29:17 -08004043 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004044 netdev->name, netdev);
4045 if (err) {
4046 pci_disable_msi(adapter->pdev);
4047 goto msi_test_failed;
4048 }
4049
Bruce Allane921eb12012-11-28 09:28:37 +00004050 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004051 * interrupt.
4052 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004053 wmb();
4054
4055 e1000_irq_enable(adapter);
4056
4057 /* fire an unusual interrupt on the test handler */
4058 ew32(ICS, E1000_ICS_RXSEQ);
4059 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004060 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004061
4062 e1000_irq_disable(adapter);
4063
Bruce Allanbc763292012-08-17 06:18:07 +00004064 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004065
4066 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004067 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004068 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004069 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004070 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004071 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004072
4073 free_irq(adapter->pdev->irq, netdev);
4074 pci_disable_msi(adapter->pdev);
4075
Bruce Allanf8d59f72008-08-08 18:36:11 -07004076msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004077 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004078 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004079}
4080
4081/**
4082 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4083 * @adapter: board private struct
4084 *
4085 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4086 **/
4087static int e1000_test_msi(struct e1000_adapter *adapter)
4088{
4089 int err;
4090 u16 pci_cmd;
4091
4092 if (!(adapter->flags & FLAG_MSI_ENABLED))
4093 return 0;
4094
4095 /* disable SERR in case the MSI write causes a master abort */
4096 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004097 if (pci_cmd & PCI_COMMAND_SERR)
4098 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4099 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004100
4101 err = e1000_test_msi_interrupt(adapter);
4102
Dean Nelson36f24072010-06-29 18:12:05 +00004103 /* re-enable SERR */
4104 if (pci_cmd & PCI_COMMAND_SERR) {
4105 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4106 pci_cmd |= PCI_COMMAND_SERR;
4107 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4108 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004109
Bruce Allanf8d59f72008-08-08 18:36:11 -07004110 return err;
4111}
4112
4113/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004114 * e1000_open - Called when a network interface is made active
4115 * @netdev: network interface device structure
4116 *
4117 * Returns 0 on success, negative value on failure
4118 *
4119 * The open entry point is called when a network interface is made
4120 * active by the system (IFF_UP). At this point all resources needed
4121 * for transmit and receive operations are allocated, the interrupt
4122 * handler is registered with the OS, the watchdog timer is started,
4123 * and the stack is notified that the interface is ready.
4124 **/
4125static int e1000_open(struct net_device *netdev)
4126{
4127 struct e1000_adapter *adapter = netdev_priv(netdev);
4128 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004129 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004130 int err;
4131
4132 /* disallow open during test */
4133 if (test_bit(__E1000_TESTING, &adapter->state))
4134 return -EBUSY;
4135
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004136 pm_runtime_get_sync(&pdev->dev);
4137
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004138 netif_carrier_off(netdev);
4139
Auke Kokbc7f75f2007-09-17 12:30:59 -07004140 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004141 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004142 if (err)
4143 goto err_setup_tx;
4144
4145 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004146 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004147 if (err)
4148 goto err_setup_rx;
4149
Bruce Allane921eb12012-11-28 09:28:37 +00004150 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004151 * interface is now open and reset the part to a known state.
4152 */
4153 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004154 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004155 e1000e_reset(adapter);
4156 }
4157
Auke Kokbc7f75f2007-09-17 12:30:59 -07004158 e1000e_power_up_phy(adapter);
4159
4160 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4161 if ((adapter->hw.mng_cookie.status &
4162 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4163 e1000_update_mng_vlan(adapter);
4164
Bruce Allan79d4e902011-12-16 00:46:27 +00004165 /* DMA latency requirement to workaround jumbo issue */
4166 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004167 pm_qos_add_request(&adapter->netdev->pm_qos_req,
4168 PM_QOS_CPU_DMA_LATENCY,
4169 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004170
Bruce Allane921eb12012-11-28 09:28:37 +00004171 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004172 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4173 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004174 * clean_rx handler before we do so.
4175 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176 e1000_configure(adapter);
4177
4178 err = e1000_request_irq(adapter);
4179 if (err)
4180 goto err_req_irq;
4181
Bruce Allane921eb12012-11-28 09:28:37 +00004182 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004183 * ignore e1000e MSI messages, which means we need to test our MSI
4184 * interrupt now
4185 */
Bruce Allan4662e822008-08-26 18:37:06 -07004186 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004187 err = e1000_test_msi(adapter);
4188 if (err) {
4189 e_err("Interrupt allocation failed\n");
4190 goto err_req_irq;
4191 }
4192 }
4193
Auke Kokbc7f75f2007-09-17 12:30:59 -07004194 /* From here on the code is the same as e1000e_up() */
4195 clear_bit(__E1000_DOWN, &adapter->state);
4196
4197 napi_enable(&adapter->napi);
4198
4199 e1000_irq_enable(adapter);
4200
Jeff Kirsher09357b02011-11-18 14:25:00 +00004201 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004202 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004203
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004204 adapter->idle_check = true;
4205 pm_runtime_put(&pdev->dev);
4206
Auke Kokbc7f75f2007-09-17 12:30:59 -07004207 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004208 if (adapter->msix_entries)
4209 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4210 else
4211 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212
4213 return 0;
4214
4215err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004216 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004217 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004218 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004220 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004221err_setup_tx:
4222 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004223 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004224
4225 return err;
4226}
4227
4228/**
4229 * e1000_close - Disables a network interface
4230 * @netdev: network interface device structure
4231 *
4232 * Returns 0, this is not allowed to fail
4233 *
4234 * The close entry point is called when an interface is de-activated
4235 * by the OS. The hardware is still under the drivers control, but
4236 * needs to be disabled. A global MAC reset is issued to stop the
4237 * hardware, and all transmit and receive resources are freed.
4238 **/
4239static int e1000_close(struct net_device *netdev)
4240{
4241 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004242 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004243 int count = E1000_CHECK_RESET_COUNT;
4244
4245 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4246 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004247
4248 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004249
4250 pm_runtime_get_sync(&pdev->dev);
4251
Bruce Allan5f4a7802011-11-29 08:09:19 +00004252 napi_disable(&adapter->napi);
4253
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004254 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4255 e1000e_down(adapter);
4256 e1000_free_irq(adapter);
4257 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004258 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259
Bruce Allan55aa6982011-12-16 00:45:45 +00004260 e1000e_free_tx_resources(adapter->tx_ring);
4261 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262
Bruce Allane921eb12012-11-28 09:28:37 +00004263 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004264 * the same ID is registered on the host OS (let 8021q kill it)
4265 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004266 if (adapter->hw.mng_cookie.status &
4267 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4269
Bruce Allane921eb12012-11-28 09:28:37 +00004270 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004271 * interface is now closed
4272 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004273 if ((adapter->flags & FLAG_HAS_AMT) &&
4274 !test_bit(__E1000_TESTING, &adapter->state))
4275 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276
Bruce Allan79d4e902011-12-16 00:46:27 +00004277 if (adapter->hw.mac.type == e1000_pch2lan)
Linus Torvalds6ba74012010-08-04 11:47:58 -07004278 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004279
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004280 pm_runtime_put_sync(&pdev->dev);
4281
Auke Kokbc7f75f2007-09-17 12:30:59 -07004282 return 0;
4283}
4284/**
4285 * e1000_set_mac - Change the Ethernet Address of the NIC
4286 * @netdev: network interface device structure
4287 * @p: pointer to an address structure
4288 *
4289 * Returns 0 on success, negative on failure
4290 **/
4291static int e1000_set_mac(struct net_device *netdev, void *p)
4292{
4293 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004294 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004295 struct sockaddr *addr = p;
4296
4297 if (!is_valid_ether_addr(addr->sa_data))
4298 return -EADDRNOTAVAIL;
4299
4300 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4301 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4302
Bruce Allan69e1e012012-04-14 03:28:50 +00004303 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004304
4305 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4306 /* activate the work around */
4307 e1000e_set_laa_state_82571(&adapter->hw, 1);
4308
Bruce Allane921eb12012-11-28 09:28:37 +00004309 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004310 * between the time RAR[0] gets clobbered and the time it
4311 * gets fixed (in e1000_watchdog), the actual LAA is in one
4312 * of the RARs and no incoming packets directed to this port
4313 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004314 * RAR[14]
4315 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004316 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4317 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318 }
4319
4320 return 0;
4321}
4322
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004323/**
4324 * e1000e_update_phy_task - work thread to update phy
4325 * @work: pointer to our work struct
4326 *
4327 * this worker thread exists because we must acquire a
4328 * semaphore to read the phy, which we could msleep while
4329 * waiting for it, and we can't msleep in a timer.
4330 **/
4331static void e1000e_update_phy_task(struct work_struct *work)
4332{
4333 struct e1000_adapter *adapter = container_of(work,
4334 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004335
4336 if (test_bit(__E1000_DOWN, &adapter->state))
4337 return;
4338
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004339 e1000_get_phy_info(&adapter->hw);
4340}
4341
Bruce Allane921eb12012-11-28 09:28:37 +00004342/**
4343 * e1000_update_phy_info - timre call-back to update PHY info
4344 * @data: pointer to adapter cast into an unsigned long
4345 *
Bruce Allanad680762008-03-28 09:15:03 -07004346 * Need to wait a few seconds after link up to get diagnostic information from
4347 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004348 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349static void e1000_update_phy_info(unsigned long data)
4350{
4351 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004352
4353 if (test_bit(__E1000_DOWN, &adapter->state))
4354 return;
4355
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004356 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004357}
4358
4359/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004360 * e1000e_update_phy_stats - Update the PHY statistics counters
4361 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004362 *
4363 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004364 **/
4365static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4366{
4367 struct e1000_hw *hw = &adapter->hw;
4368 s32 ret_val;
4369 u16 phy_data;
4370
4371 ret_val = hw->phy.ops.acquire(hw);
4372 if (ret_val)
4373 return;
4374
Bruce Allane921eb12012-11-28 09:28:37 +00004375 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004376 * If not, set to the page with the PHY status registers.
4377 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004378 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004379 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4380 &phy_data);
4381 if (ret_val)
4382 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004383 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4384 ret_val = hw->phy.ops.set_page(hw,
4385 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004386 if (ret_val)
4387 goto release;
4388 }
4389
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004390 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004391 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4392 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004393 if (!ret_val)
4394 adapter->stats.scc += phy_data;
4395
4396 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004397 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4398 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004399 if (!ret_val)
4400 adapter->stats.ecol += phy_data;
4401
4402 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004403 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4404 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004405 if (!ret_val)
4406 adapter->stats.mcc += phy_data;
4407
4408 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004409 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4410 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004411 if (!ret_val)
4412 adapter->stats.latecol += phy_data;
4413
4414 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004415 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4416 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004417 if (!ret_val)
4418 hw->mac.collision_delta = phy_data;
4419
4420 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004421 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4422 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004423 if (!ret_val)
4424 adapter->stats.dc += phy_data;
4425
4426 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004427 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4428 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004429 if (!ret_val)
4430 adapter->stats.tncrs += phy_data;
4431
4432release:
4433 hw->phy.ops.release(hw);
4434}
4435
4436/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004437 * e1000e_update_stats - Update the board statistics counters
4438 * @adapter: board private structure
4439 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004440static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004442 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004443 struct e1000_hw *hw = &adapter->hw;
4444 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004445
Bruce Allane921eb12012-11-28 09:28:37 +00004446 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447 * connection is down.
4448 */
4449 if (adapter->link_speed == 0)
4450 return;
4451 if (pci_channel_offline(pdev))
4452 return;
4453
Auke Kokbc7f75f2007-09-17 12:30:59 -07004454 adapter->stats.crcerrs += er32(CRCERRS);
4455 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004456 adapter->stats.gorc += er32(GORCL);
4457 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004458 adapter->stats.bprc += er32(BPRC);
4459 adapter->stats.mprc += er32(MPRC);
4460 adapter->stats.roc += er32(ROC);
4461
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004463
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004464 /* Half-duplex statistics */
4465 if (adapter->link_duplex == HALF_DUPLEX) {
4466 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4467 e1000e_update_phy_stats(adapter);
4468 } else {
4469 adapter->stats.scc += er32(SCC);
4470 adapter->stats.ecol += er32(ECOL);
4471 adapter->stats.mcc += er32(MCC);
4472 adapter->stats.latecol += er32(LATECOL);
4473 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004474
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004475 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004476
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004477 if ((hw->mac.type != e1000_82574) &&
4478 (hw->mac.type != e1000_82583))
4479 adapter->stats.tncrs += er32(TNCRS);
4480 }
4481 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004482 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004483
Auke Kokbc7f75f2007-09-17 12:30:59 -07004484 adapter->stats.xonrxc += er32(XONRXC);
4485 adapter->stats.xontxc += er32(XONTXC);
4486 adapter->stats.xoffrxc += er32(XOFFRXC);
4487 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004488 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004489 adapter->stats.gotc += er32(GOTCL);
4490 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491 adapter->stats.rnbc += er32(RNBC);
4492 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493
4494 adapter->stats.mptc += er32(MPTC);
4495 adapter->stats.bptc += er32(BPTC);
4496
4497 /* used for adaptive IFS */
4498
4499 hw->mac.tx_packet_delta = er32(TPT);
4500 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004501
4502 adapter->stats.algnerrc += er32(ALGNERRC);
4503 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504 adapter->stats.cexterr += er32(CEXTERR);
4505 adapter->stats.tsctc += er32(TSCTC);
4506 adapter->stats.tsctfc += er32(TSCTFC);
4507
Auke Kokbc7f75f2007-09-17 12:30:59 -07004508 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004509 netdev->stats.multicast = adapter->stats.mprc;
4510 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004511
4512 /* Rx Errors */
4513
Bruce Allane921eb12012-11-28 09:28:37 +00004514 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004515 * our own version based on RUC and ROC
4516 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004517 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004518 adapter->stats.crcerrs + adapter->stats.algnerrc +
4519 adapter->stats.ruc + adapter->stats.roc +
4520 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004521 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004522 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004523 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4524 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4525 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004526
4527 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004528 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004530 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4531 netdev->stats.tx_window_errors = adapter->stats.latecol;
4532 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533
4534 /* Tx Dropped needs to be maintained elsewhere */
4535
Auke Kokbc7f75f2007-09-17 12:30:59 -07004536 /* Management Stats */
4537 adapter->stats.mgptc += er32(MGTPTC);
4538 adapter->stats.mgprc += er32(MGTPRC);
4539 adapter->stats.mgpdc += er32(MGTPDC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540}
4541
Bruce Allan7c257692008-04-23 11:09:00 -07004542/**
4543 * e1000_phy_read_status - Update the PHY register status snapshot
4544 * @adapter: board private structure
4545 **/
4546static void e1000_phy_read_status(struct e1000_adapter *adapter)
4547{
4548 struct e1000_hw *hw = &adapter->hw;
4549 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004550
4551 if ((er32(STATUS) & E1000_STATUS_LU) &&
4552 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004553 int ret_val;
4554
Bruce Allan7c257692008-04-23 11:09:00 -07004555 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
4556 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
4557 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
4558 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
4559 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
4560 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
4561 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
4562 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
4563 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004564 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004565 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004566 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004567 * Set values to typical power-on defaults
4568 */
4569 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4570 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4571 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4572 BMSR_ERCAP);
4573 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4574 ADVERTISE_ALL | ADVERTISE_CSMA);
4575 phy->lpa = 0;
4576 phy->expansion = EXPANSION_ENABLENPAGE;
4577 phy->ctrl1000 = ADVERTISE_1000FULL;
4578 phy->stat1000 = 0;
4579 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4580 }
Bruce Allan7c257692008-04-23 11:09:00 -07004581}
4582
Auke Kokbc7f75f2007-09-17 12:30:59 -07004583static void e1000_print_link_info(struct e1000_adapter *adapter)
4584{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004585 struct e1000_hw *hw = &adapter->hw;
4586 u32 ctrl = er32(CTRL);
4587
Bruce Allan8f12fe82008-11-21 16:54:43 -08004588 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004589 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4590 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004591 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4592 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4593 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4594 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004595}
4596
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004597static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004598{
4599 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004600 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004601 s32 ret_val = 0;
4602
Bruce Allane921eb12012-11-28 09:28:37 +00004603 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004604 * Rx sequence error interrupt. get_link_status will stay
4605 * false until the check_for_link establishes link
4606 * for copper adapters ONLY
4607 */
4608 switch (hw->phy.media_type) {
4609 case e1000_media_type_copper:
4610 if (hw->mac.get_link_status) {
4611 ret_val = hw->mac.ops.check_for_link(hw);
4612 link_active = !hw->mac.get_link_status;
4613 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004614 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004615 }
4616 break;
4617 case e1000_media_type_fiber:
4618 ret_val = hw->mac.ops.check_for_link(hw);
4619 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4620 break;
4621 case e1000_media_type_internal_serdes:
4622 ret_val = hw->mac.ops.check_for_link(hw);
4623 link_active = adapter->hw.mac.serdes_has_link;
4624 break;
4625 default:
4626 case e1000_media_type_unknown:
4627 break;
4628 }
4629
4630 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4631 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4632 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004633 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004634 }
4635
4636 return link_active;
4637}
4638
4639static void e1000e_enable_receives(struct e1000_adapter *adapter)
4640{
4641 /* make sure the receive unit is started */
4642 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004643 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004644 struct e1000_hw *hw = &adapter->hw;
4645 u32 rctl = er32(RCTL);
4646 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004647 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004648 }
4649}
4650
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004651static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4652{
4653 struct e1000_hw *hw = &adapter->hw;
4654
Bruce Allane921eb12012-11-28 09:28:37 +00004655 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004656 * for hung state and reset, if two calls return true
4657 */
4658 if (e1000_check_phy_82574(hw))
4659 adapter->phy_hang_count++;
4660 else
4661 adapter->phy_hang_count = 0;
4662
4663 if (adapter->phy_hang_count > 1) {
4664 adapter->phy_hang_count = 0;
4665 schedule_work(&adapter->reset_task);
4666 }
4667}
4668
Auke Kokbc7f75f2007-09-17 12:30:59 -07004669/**
4670 * e1000_watchdog - Timer Call-back
4671 * @data: pointer to adapter cast into an unsigned long
4672 **/
4673static void e1000_watchdog(unsigned long data)
4674{
4675 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4676
4677 /* Do the rest outside of interrupt context */
4678 schedule_work(&adapter->watchdog_task);
4679
4680 /* TODO: make this use queue_delayed_work() */
4681}
4682
4683static void e1000_watchdog_task(struct work_struct *work)
4684{
4685 struct e1000_adapter *adapter = container_of(work,
4686 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687 struct net_device *netdev = adapter->netdev;
4688 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004689 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004690 struct e1000_ring *tx_ring = adapter->tx_ring;
4691 struct e1000_hw *hw = &adapter->hw;
4692 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004693
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004694 if (test_bit(__E1000_DOWN, &adapter->state))
4695 return;
4696
David S. Millerb405e8d2010-02-04 22:31:41 -08004697 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004698 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004699 /* Cancel scheduled suspend requests. */
4700 pm_runtime_resume(netdev->dev.parent);
4701
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004702 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004703 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004704 }
4705
4706 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4707 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4708 e1000_update_mng_vlan(adapter);
4709
Auke Kokbc7f75f2007-09-17 12:30:59 -07004710 if (link) {
4711 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004712 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004713
4714 /* Cancel scheduled suspend requests. */
4715 pm_runtime_resume(netdev->dev.parent);
4716
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004717 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004718 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719 mac->ops.get_link_up_info(&adapter->hw,
4720 &adapter->link_speed,
4721 &adapter->link_duplex);
4722 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004723 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004724 * if link has autonegotiated at 10/100 half
4725 */
4726 if ((hw->phy.type == e1000_phy_igp_3 ||
4727 hw->phy.type == e1000_phy_bm) &&
4728 (hw->mac.autoneg == true) &&
4729 (adapter->link_speed == SPEED_10 ||
4730 adapter->link_speed == SPEED_100) &&
4731 (adapter->link_duplex == HALF_DUPLEX)) {
4732 u16 autoneg_exp;
4733
4734 e1e_rphy(hw, PHY_AUTONEG_EXP, &autoneg_exp);
4735
4736 if (!(autoneg_exp & NWAY_ER_LP_NWAY_CAPS))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004737 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 -07004738 }
4739
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004740 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004741 adapter->tx_timeout_factor = 1;
4742 switch (adapter->link_speed) {
4743 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004744 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004745 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004746 break;
4747 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004748 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004749 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004750 break;
4751 }
4752
Bruce Allane921eb12012-11-28 09:28:37 +00004753 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004754 * link-up event
4755 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004756 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4757 !txb2b) {
4758 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004759 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004760 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004761 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004762 }
4763
Bruce Allane921eb12012-11-28 09:28:37 +00004764 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004765 * some hardware issues
4766 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004767 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4768 switch (adapter->link_speed) {
4769 case SPEED_10:
4770 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004771 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004772 netdev->features &= ~NETIF_F_TSO;
4773 netdev->features &= ~NETIF_F_TSO6;
4774 break;
4775 case SPEED_1000:
4776 netdev->features |= NETIF_F_TSO;
4777 netdev->features |= NETIF_F_TSO6;
4778 break;
4779 default:
4780 /* oops */
4781 break;
4782 }
4783 }
4784
Bruce Allane921eb12012-11-28 09:28:37 +00004785 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004786 * after setting TARC(0)
4787 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788 tctl = er32(TCTL);
4789 tctl |= E1000_TCTL_EN;
4790 ew32(TCTL, tctl);
4791
Bruce Allane921eb12012-11-28 09:28:37 +00004792 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004793 * reporting link up.
4794 */
4795 if (phy->ops.cfg_on_link_up)
4796 phy->ops.cfg_on_link_up(hw);
4797
Auke Kokbc7f75f2007-09-17 12:30:59 -07004798 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799
4800 if (!test_bit(__E1000_DOWN, &adapter->state))
4801 mod_timer(&adapter->phy_info_timer,
4802 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004803 }
4804 } else {
4805 if (netif_carrier_ok(netdev)) {
4806 adapter->link_speed = 0;
4807 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004808 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004809 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004811 if (!test_bit(__E1000_DOWN, &adapter->state))
4812 mod_timer(&adapter->phy_info_timer,
4813 round_jiffies(jiffies + 2 * HZ));
4814
Bruce Allan12d43f72012-12-05 06:26:14 +00004815 /* The link is lost so the controller stops DMA.
4816 * If there is queued Tx work that cannot be done
4817 * or if on an 8000ES2LAN which requires a Rx packet
4818 * buffer work-around on link down event, reset the
4819 * controller to flush the Tx/Rx packet buffers.
4820 * (Do the reset outside of interrupt context).
4821 */
4822 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4823 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4824 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004825 else
4826 pm_schedule_suspend(netdev->dev.parent,
4827 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 }
4829 }
4830
4831link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004832 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 e1000e_update_stats(adapter);
4834
4835 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4836 adapter->tpt_old = adapter->stats.tpt;
4837 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4838 adapter->colc_old = adapter->stats.colc;
4839
Bruce Allan7c257692008-04-23 11:09:00 -07004840 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4841 adapter->gorc_old = adapter->stats.gorc;
4842 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4843 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004844 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004845
Bruce Allan12d43f72012-12-05 06:26:14 +00004846 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004847 schedule_work(&adapter->reset_task);
4848 /* return immediately since reset is imminent */
4849 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004850 }
4851
Bruce Allan12d43f72012-12-05 06:26:14 +00004852 e1000e_update_adaptive(&adapter->hw);
4853
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004854 /* Simple mode for Interrupt Throttle Rate (ITR) */
4855 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004856 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004857 * Total asymmetrical Tx or Rx gets ITR=8000;
4858 * everyone else is between 2000-8000.
4859 */
4860 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4861 u32 dif = (adapter->gotc > adapter->gorc ?
4862 adapter->gotc - adapter->gorc :
4863 adapter->gorc - adapter->gotc) / 10000;
4864 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4865
Matthew Vick22a4cca2012-07-12 00:02:42 +00004866 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004867 }
4868
Bruce Allanad680762008-03-28 09:15:03 -07004869 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004870 if (adapter->msix_entries)
4871 ew32(ICS, adapter->rx_ring->ims_val);
4872 else
4873 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004875 /* flush pending descriptors to memory before detecting Tx hang */
4876 e1000e_flush_descriptors(adapter);
4877
Auke Kokbc7f75f2007-09-17 12:30:59 -07004878 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004879 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880
Bruce Allane921eb12012-11-28 09:28:37 +00004881 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07004882 * reset from the other port. Set the appropriate LAA in RAR[0]
4883 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004884 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00004885 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004887 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
4888 e1000e_check_82574_phy_workaround(adapter);
4889
Bruce Allanb67e1912012-12-27 08:32:33 +00004890 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
4891 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
4892 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
4893 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
4894 er32(RXSTMPH);
4895 adapter->rx_hwtstamp_cleared++;
4896 } else {
4897 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
4898 }
4899 }
4900
Auke Kokbc7f75f2007-09-17 12:30:59 -07004901 /* Reset the timer */
4902 if (!test_bit(__E1000_DOWN, &adapter->state))
4903 mod_timer(&adapter->watchdog_timer,
4904 round_jiffies(jiffies + 2 * HZ));
4905}
4906
4907#define E1000_TX_FLAGS_CSUM 0x00000001
4908#define E1000_TX_FLAGS_VLAN 0x00000002
4909#define E1000_TX_FLAGS_TSO 0x00000004
4910#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00004911#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00004912#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
4914#define E1000_TX_FLAGS_VLAN_SHIFT 16
4915
Bruce Allan55aa6982011-12-16 00:45:45 +00004916static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004917{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918 struct e1000_context_desc *context_desc;
4919 struct e1000_buffer *buffer_info;
4920 unsigned int i;
4921 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00004922 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004925 if (!skb_is_gso(skb))
4926 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004927
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004928 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004929 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4930
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004931 if (err)
4932 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933 }
4934
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004935 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
4936 mss = skb_shinfo(skb)->gso_size;
4937 if (skb->protocol == htons(ETH_P_IP)) {
4938 struct iphdr *iph = ip_hdr(skb);
4939 iph->tot_len = 0;
4940 iph->check = 0;
4941 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
4942 0, IPPROTO_TCP, 0);
4943 cmd_length = E1000_TXD_CMD_IP;
4944 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004945 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004946 ipv6_hdr(skb)->payload_len = 0;
4947 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4948 &ipv6_hdr(skb)->daddr,
4949 0, IPPROTO_TCP, 0);
4950 ipcse = 0;
4951 }
4952 ipcss = skb_network_offset(skb);
4953 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
4954 tucss = skb_transport_offset(skb);
4955 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004956
4957 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
4958 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
4959
4960 i = tx_ring->next_to_use;
4961 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
4962 buffer_info = &tx_ring->buffer_info[i];
4963
4964 context_desc->lower_setup.ip_fields.ipcss = ipcss;
4965 context_desc->lower_setup.ip_fields.ipcso = ipcso;
4966 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
4967 context_desc->upper_setup.tcp_fields.tucss = tucss;
4968 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00004969 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00004970 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
4971 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
4972 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
4973
4974 buffer_info->time_stamp = jiffies;
4975 buffer_info->next_to_watch = i;
4976
4977 i++;
4978 if (i == tx_ring->count)
4979 i = 0;
4980 tx_ring->next_to_use = i;
4981
4982 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004983}
4984
Bruce Allan55aa6982011-12-16 00:45:45 +00004985static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004986{
Bruce Allan55aa6982011-12-16 00:45:45 +00004987 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 struct e1000_context_desc *context_desc;
4989 struct e1000_buffer *buffer_info;
4990 unsigned int i;
4991 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07004992 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00004993 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994
Dave Grahamaf807c82008-10-09 14:28:58 -07004995 if (skb->ip_summed != CHECKSUM_PARTIAL)
4996 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997
Arthur Jones5f66f202009-03-19 01:13:08 +00004998 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
4999 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5000 else
5001 protocol = skb->protocol;
5002
Arthur Jones3f518392009-03-20 15:56:35 -07005003 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005004 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005005 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5006 cmd_len |= E1000_TXD_CMD_TCP;
5007 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005008 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005009 /* XXX not handling all IPV6 headers */
5010 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5011 cmd_len |= E1000_TXD_CMD_TCP;
5012 break;
5013 default:
5014 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005015 e_warn("checksum_partial proto=%x!\n",
5016 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005017 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005018 }
5019
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005020 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005021
5022 i = tx_ring->next_to_use;
5023 buffer_info = &tx_ring->buffer_info[i];
5024 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5025
5026 context_desc->lower_setup.ip_config = 0;
5027 context_desc->upper_setup.tcp_fields.tucss = css;
5028 context_desc->upper_setup.tcp_fields.tucso =
5029 css + skb->csum_offset;
5030 context_desc->upper_setup.tcp_fields.tucse = 0;
5031 context_desc->tcp_seg_setup.data = 0;
5032 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5033
5034 buffer_info->time_stamp = jiffies;
5035 buffer_info->next_to_watch = i;
5036
5037 i++;
5038 if (i == tx_ring->count)
5039 i = 0;
5040 tx_ring->next_to_use = i;
5041
5042 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043}
5044
Bruce Allan55aa6982011-12-16 00:45:45 +00005045static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5046 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005047 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048{
Bruce Allan55aa6982011-12-16 00:45:45 +00005049 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005050 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005051 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005052 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005053 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005054 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005055
5056 i = tx_ring->next_to_use;
5057
5058 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005059 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005060 size = min(len, max_per_txd);
5061
Auke Kokbc7f75f2007-09-17 12:30:59 -07005062 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005063 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005064 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005065 buffer_info->dma = dma_map_single(&pdev->dev,
5066 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005067 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005068 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005069 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005070 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071
5072 len -= size;
5073 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005074 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005075
5076 if (len) {
5077 i++;
5078 if (i == tx_ring->count)
5079 i = 0;
5080 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005081 }
5082
5083 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005084 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005085
5086 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005087 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005088 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005089
5090 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005091 i++;
5092 if (i == tx_ring->count)
5093 i = 0;
5094
Auke Kokbc7f75f2007-09-17 12:30:59 -07005095 buffer_info = &tx_ring->buffer_info[i];
5096 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005097
5098 buffer_info->length = size;
5099 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005100 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005101 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5102 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005103 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005104 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005105 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106
5107 len -= size;
5108 offset += size;
5109 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110 }
5111 }
5112
Bruce Allanaf667a22010-12-31 06:10:01 +00005113 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005114 /* multiply data chunks by size of headers */
5115 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5116
Auke Kokbc7f75f2007-09-17 12:30:59 -07005117 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005118 tx_ring->buffer_info[i].segs = segs;
5119 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005120 tx_ring->buffer_info[first].next_to_watch = i;
5121
5122 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005123
5124dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005125 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005126 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005127 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005128 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005129
5130 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005131 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005132 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005133 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005134 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005135 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005136 }
5137
5138 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005139}
5140
Bruce Allan55aa6982011-12-16 00:45:45 +00005141static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142{
Bruce Allan55aa6982011-12-16 00:45:45 +00005143 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005144 struct e1000_tx_desc *tx_desc = NULL;
5145 struct e1000_buffer *buffer_info;
5146 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5147 unsigned int i;
5148
5149 if (tx_flags & E1000_TX_FLAGS_TSO) {
5150 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5151 E1000_TXD_CMD_TSE;
5152 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5153
5154 if (tx_flags & E1000_TX_FLAGS_IPV4)
5155 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5156 }
5157
5158 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5159 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5160 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5161 }
5162
5163 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5164 txd_lower |= E1000_TXD_CMD_VLE;
5165 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5166 }
5167
Ben Greear943146d2012-02-11 15:39:40 +00005168 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5169 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5170
Bruce Allanb67e1912012-12-27 08:32:33 +00005171 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5172 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5173 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5174 }
5175
Auke Kokbc7f75f2007-09-17 12:30:59 -07005176 i = tx_ring->next_to_use;
5177
Bruce Allan36b973d2010-11-24 07:42:43 +00005178 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179 buffer_info = &tx_ring->buffer_info[i];
5180 tx_desc = E1000_TX_DESC(*tx_ring, i);
5181 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5182 tx_desc->lower.data =
5183 cpu_to_le32(txd_lower | buffer_info->length);
5184 tx_desc->upper.data = cpu_to_le32(txd_upper);
5185
5186 i++;
5187 if (i == tx_ring->count)
5188 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005189 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005190
5191 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5192
Ben Greear943146d2012-02-11 15:39:40 +00005193 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5194 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5195 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5196
Bruce Allane921eb12012-11-28 09:28:37 +00005197 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005198 * know there are new descriptors to fetch. (Only
5199 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005200 * such as IA-64).
5201 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005202 wmb();
5203
5204 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005205
5206 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005207 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005208 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005209 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005210
Bruce Allane921eb12012-11-28 09:28:37 +00005211 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005212 * at a time, it synchronizes IO on IA64/Altix systems
5213 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214 mmiowb();
5215}
5216
5217#define MINIMUM_DHCP_PACKET_SIZE 282
5218static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5219 struct sk_buff *skb)
5220{
5221 struct e1000_hw *hw = &adapter->hw;
5222 u16 length, offset;
5223
Bruce Alland60923c2012-12-05 06:26:56 +00005224 if (vlan_tx_tag_present(skb) &&
5225 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5226 (adapter->hw.mng_cookie.status &
5227 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5228 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229
5230 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5231 return 0;
5232
5233 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5234 return 0;
5235
5236 {
5237 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5238 struct udphdr *udp;
5239
5240 if (ip->protocol != IPPROTO_UDP)
5241 return 0;
5242
5243 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5244 if (ntohs(udp->dest) != 67)
5245 return 0;
5246
5247 offset = (u8 *)udp + 8 - skb->data;
5248 length = skb->len - offset;
5249 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5250 }
5251
5252 return 0;
5253}
5254
Bruce Allan55aa6982011-12-16 00:45:45 +00005255static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256{
Bruce Allan55aa6982011-12-16 00:45:45 +00005257 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005258
Bruce Allan55aa6982011-12-16 00:45:45 +00005259 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005260 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005262 * but since that doesn't exist yet, just open code it.
5263 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005264 smp_mb();
5265
Bruce Allane921eb12012-11-28 09:28:37 +00005266 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005267 * made room available.
5268 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005269 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005270 return -EBUSY;
5271
5272 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005273 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005274 ++adapter->restart_queue;
5275 return 0;
5276}
5277
Bruce Allan55aa6982011-12-16 00:45:45 +00005278static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005279{
Bruce Alland821a4c2012-08-24 20:38:11 +00005280 BUG_ON(size > tx_ring->count);
5281
Bruce Allan55aa6982011-12-16 00:45:45 +00005282 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005283 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005284 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005285}
5286
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005287static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5288 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005289{
5290 struct e1000_adapter *adapter = netdev_priv(netdev);
5291 struct e1000_ring *tx_ring = adapter->tx_ring;
5292 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005293 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005294 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005295 unsigned int nr_frags;
5296 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005297 int count = 0;
5298 int tso;
5299 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005300
5301 if (test_bit(__E1000_DOWN, &adapter->state)) {
5302 dev_kfree_skb_any(skb);
5303 return NETDEV_TX_OK;
5304 }
5305
5306 if (skb->len <= 0) {
5307 dev_kfree_skb_any(skb);
5308 return NETDEV_TX_OK;
5309 }
5310
Bruce Allane921eb12012-11-28 09:28:37 +00005311 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005312 * pad skb in order to meet this minimum size requirement
5313 */
5314 if (unlikely(skb->len < 17)) {
5315 if (skb_pad(skb, 17 - skb->len))
5316 return NETDEV_TX_OK;
5317 skb->len = 17;
5318 skb_set_tail_pointer(skb, 17);
5319 }
5320
Auke Kokbc7f75f2007-09-17 12:30:59 -07005321 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005322 if (mss) {
5323 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005324
Bruce Allane921eb12012-11-28 09:28:37 +00005325 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005326 * points to just header, pull a few bytes of payload from
5327 * frags into skb->data
5328 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005329 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005330 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005331 * avoiding it could save a lot of cycles
5332 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005333 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005334 unsigned int pull_size;
5335
Bruce Allana2a5b322012-01-31 06:37:17 +00005336 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005337 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005338 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005339 dev_kfree_skb_any(skb);
5340 return NETDEV_TX_OK;
5341 }
Eric Dumazete743d312010-04-14 15:59:40 -07005342 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005343 }
5344 }
5345
5346 /* reserve a descriptor for the offload context */
5347 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5348 count++;
5349 count++;
5350
Bruce Alland821a4c2012-08-24 20:38:11 +00005351 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005352
5353 nr_frags = skb_shinfo(skb)->nr_frags;
5354 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005355 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5356 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005357
5358 if (adapter->hw.mac.tx_pkt_filtering)
5359 e1000_transfer_dhcp_info(adapter, skb);
5360
Bruce Allane921eb12012-11-28 09:28:37 +00005361 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005362 * head, otherwise try next time
5363 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005364 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005365 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005366
Jesse Grosseab6d182010-10-20 13:56:03 +00005367 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368 tx_flags |= E1000_TX_FLAGS_VLAN;
5369 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5370 }
5371
5372 first = tx_ring->next_to_use;
5373
Bruce Allan55aa6982011-12-16 00:45:45 +00005374 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375 if (tso < 0) {
5376 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005377 return NETDEV_TX_OK;
5378 }
5379
5380 if (tso)
5381 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005382 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005383 tx_flags |= E1000_TX_FLAGS_CSUM;
5384
Bruce Allane921eb12012-11-28 09:28:37 +00005385 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005387 * no longer assume, we must.
5388 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005389 if (skb->protocol == htons(ETH_P_IP))
5390 tx_flags |= E1000_TX_FLAGS_IPV4;
5391
Ben Greear943146d2012-02-11 15:39:40 +00005392 if (unlikely(skb->no_fcs))
5393 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5394
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005395 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005396 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5397 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005398 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005399 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5400 !adapter->tx_hwtstamp_skb)) {
5401 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5402 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5403 adapter->tx_hwtstamp_skb = skb_get(skb);
5404 schedule_work(&adapter->tx_hwtstamp_work);
5405 } else {
5406 skb_tx_timestamp(skb);
5407 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005408
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005409 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005410 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005411 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005412 e1000_maybe_stop_tx(tx_ring,
5413 (MAX_SKB_FRAGS *
5414 DIV_ROUND_UP(PAGE_SIZE,
5415 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005416 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005417 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005418 tx_ring->buffer_info[first].time_stamp = 0;
5419 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420 }
5421
Auke Kokbc7f75f2007-09-17 12:30:59 -07005422 return NETDEV_TX_OK;
5423}
5424
5425/**
5426 * e1000_tx_timeout - Respond to a Tx Hang
5427 * @netdev: network interface device structure
5428 **/
5429static void e1000_tx_timeout(struct net_device *netdev)
5430{
5431 struct e1000_adapter *adapter = netdev_priv(netdev);
5432
5433 /* Do the reset outside of interrupt context */
5434 adapter->tx_timeout_count++;
5435 schedule_work(&adapter->reset_task);
5436}
5437
5438static void e1000_reset_task(struct work_struct *work)
5439{
5440 struct e1000_adapter *adapter;
5441 adapter = container_of(work, struct e1000_adapter, reset_task);
5442
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005443 /* don't run the task if already down */
5444 if (test_bit(__E1000_DOWN, &adapter->state))
5445 return;
5446
Bruce Allan12d43f72012-12-05 06:26:14 +00005447 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005448 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005449 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005450 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005451 e1000e_reinit_locked(adapter);
5452}
5453
5454/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005455 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005457 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005458 *
5459 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005460 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005461struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5462 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005464 struct e1000_adapter *adapter = netdev_priv(netdev);
5465
5466 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5467 spin_lock(&adapter->stats64_lock);
5468 e1000e_update_stats(adapter);
5469 /* Fill out the OS statistics structure */
5470 stats->rx_bytes = adapter->stats.gorc;
5471 stats->rx_packets = adapter->stats.gprc;
5472 stats->tx_bytes = adapter->stats.gotc;
5473 stats->tx_packets = adapter->stats.gptc;
5474 stats->multicast = adapter->stats.mprc;
5475 stats->collisions = adapter->stats.colc;
5476
5477 /* Rx Errors */
5478
Bruce Allane921eb12012-11-28 09:28:37 +00005479 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005480 * our own version based on RUC and ROC
5481 */
5482 stats->rx_errors = adapter->stats.rxerrc +
5483 adapter->stats.crcerrs + adapter->stats.algnerrc +
5484 adapter->stats.ruc + adapter->stats.roc +
5485 adapter->stats.cexterr;
5486 stats->rx_length_errors = adapter->stats.ruc +
5487 adapter->stats.roc;
5488 stats->rx_crc_errors = adapter->stats.crcerrs;
5489 stats->rx_frame_errors = adapter->stats.algnerrc;
5490 stats->rx_missed_errors = adapter->stats.mpc;
5491
5492 /* Tx Errors */
5493 stats->tx_errors = adapter->stats.ecol +
5494 adapter->stats.latecol;
5495 stats->tx_aborted_errors = adapter->stats.ecol;
5496 stats->tx_window_errors = adapter->stats.latecol;
5497 stats->tx_carrier_errors = adapter->stats.tncrs;
5498
5499 /* Tx Dropped needs to be maintained elsewhere */
5500
5501 spin_unlock(&adapter->stats64_lock);
5502 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005503}
5504
5505/**
5506 * e1000_change_mtu - Change the Maximum Transfer Unit
5507 * @netdev: network interface device structure
5508 * @new_mtu: new value for maximum frame size
5509 *
5510 * Returns 0 on success, negative on failure
5511 **/
5512static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5513{
5514 struct e1000_adapter *adapter = netdev_priv(netdev);
5515 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5516
Bruce Allan2adc55c2009-06-02 11:28:58 +00005517 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005518 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5519 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5520 e_err("Jumbo Frames not supported.\n");
5521 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005522 }
5523
Bruce Allan2adc55c2009-06-02 11:28:58 +00005524 /* Supported frame sizes */
5525 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5526 (max_frame > adapter->max_hw_frame_size)) {
5527 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005528 return -EINVAL;
5529 }
5530
Bruce Allan2fbe4522012-04-19 03:21:47 +00005531 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5532 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005533 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5534 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005535 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005536 return -EINVAL;
5537 }
5538
Auke Kokbc7f75f2007-09-17 12:30:59 -07005539 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005540 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005541 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005542 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005543 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5544 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545 if (netif_running(netdev))
5546 e1000e_down(adapter);
5547
Bruce Allane921eb12012-11-28 09:28:37 +00005548 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005549 * means we reserve 2 more, this pushes us to allocate from the next
5550 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005551 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005552 * However with the new *_jumbo_rx* routines, jumbo receives will use
5553 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005554 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005555
Jesse Brandeburg99261462010-01-22 22:56:16 +00005556 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005557 adapter->rx_buffer_len = 2048;
5558 else
5559 adapter->rx_buffer_len = 4096;
5560
5561 /* adjust allocation if LPE protects us, and we aren't using SBP */
5562 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5563 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5564 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005565 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005566
Auke Kokbc7f75f2007-09-17 12:30:59 -07005567 if (netif_running(netdev))
5568 e1000e_up(adapter);
5569 else
5570 e1000e_reset(adapter);
5571
5572 clear_bit(__E1000_RESETTING, &adapter->state);
5573
5574 return 0;
5575}
5576
5577static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5578 int cmd)
5579{
5580 struct e1000_adapter *adapter = netdev_priv(netdev);
5581 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005582
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005583 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005584 return -EOPNOTSUPP;
5585
5586 switch (cmd) {
5587 case SIOCGMIIPHY:
5588 data->phy_id = adapter->hw.phy.addr;
5589 break;
5590 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005591 e1000_phy_read_status(adapter);
5592
Bruce Allan7c257692008-04-23 11:09:00 -07005593 switch (data->reg_num & 0x1F) {
5594 case MII_BMCR:
5595 data->val_out = adapter->phy_regs.bmcr;
5596 break;
5597 case MII_BMSR:
5598 data->val_out = adapter->phy_regs.bmsr;
5599 break;
5600 case MII_PHYSID1:
5601 data->val_out = (adapter->hw.phy.id >> 16);
5602 break;
5603 case MII_PHYSID2:
5604 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5605 break;
5606 case MII_ADVERTISE:
5607 data->val_out = adapter->phy_regs.advertise;
5608 break;
5609 case MII_LPA:
5610 data->val_out = adapter->phy_regs.lpa;
5611 break;
5612 case MII_EXPANSION:
5613 data->val_out = adapter->phy_regs.expansion;
5614 break;
5615 case MII_CTRL1000:
5616 data->val_out = adapter->phy_regs.ctrl1000;
5617 break;
5618 case MII_STAT1000:
5619 data->val_out = adapter->phy_regs.stat1000;
5620 break;
5621 case MII_ESTATUS:
5622 data->val_out = adapter->phy_regs.estatus;
5623 break;
5624 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005625 return -EIO;
5626 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627 break;
5628 case SIOCSMIIREG:
5629 default:
5630 return -EOPNOTSUPP;
5631 }
5632 return 0;
5633}
5634
Bruce Allanb67e1912012-12-27 08:32:33 +00005635/**
5636 * e1000e_hwtstamp_ioctl - control hardware time stamping
5637 * @netdev: network interface device structure
5638 * @ifreq: interface request
5639 *
5640 * Outgoing time stamping can be enabled and disabled. Play nice and
5641 * disable it when requested, although it shouldn't cause any overhead
5642 * when no packet needs it. At most one packet in the queue may be
5643 * marked for time stamping, otherwise it would be impossible to tell
5644 * for sure to which packet the hardware time stamp belongs.
5645 *
5646 * Incoming time stamping has to be configured via the hardware filters.
5647 * Not all combinations are supported, in particular event type has to be
5648 * specified. Matching the kind of event packet is not supported, with the
5649 * exception of "all V2 events regardless of level 2 or 4".
5650 **/
5651static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5652{
5653 struct e1000_adapter *adapter = netdev_priv(netdev);
5654 struct hwtstamp_config config;
5655 int ret_val;
5656
5657 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5658 return -EFAULT;
5659
5660 adapter->hwtstamp_config = config;
5661
5662 ret_val = e1000e_config_hwtstamp(adapter);
5663 if (ret_val)
5664 return ret_val;
5665
5666 config = adapter->hwtstamp_config;
5667
5668 return copy_to_user(ifr->ifr_data, &config,
5669 sizeof(config)) ? -EFAULT : 0;
5670}
5671
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5673{
5674 switch (cmd) {
5675 case SIOCGMIIPHY:
5676 case SIOCGMIIREG:
5677 case SIOCSMIIREG:
5678 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005679 case SIOCSHWTSTAMP:
5680 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005681 default:
5682 return -EOPNOTSUPP;
5683 }
5684}
5685
Bruce Allana4f58f52009-06-02 11:29:18 +00005686static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5687{
5688 struct e1000_hw *hw = &adapter->hw;
5689 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005690 u16 phy_reg, wuc_enable;
Bruce Allana4f58f52009-06-02 11:29:18 +00005691 int retval = 0;
5692
5693 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005694 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005695
Bruce Allan2b6b1682011-05-13 07:20:09 +00005696 retval = hw->phy.ops.acquire(hw);
5697 if (retval) {
5698 e_err("Could not acquire PHY\n");
5699 return retval;
5700 }
5701
5702 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5703 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5704 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005705 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005706
5707 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005708 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5709 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005710 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5711 (u16)(mac_reg & 0xFFFF));
5712 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5713 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005714 }
5715
5716 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005717 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005718 mac_reg = er32(RCTL);
5719 if (mac_reg & E1000_RCTL_UPE)
5720 phy_reg |= BM_RCTL_UPE;
5721 if (mac_reg & E1000_RCTL_MPE)
5722 phy_reg |= BM_RCTL_MPE;
5723 phy_reg &= ~(BM_RCTL_MO_MASK);
5724 if (mac_reg & E1000_RCTL_MO_3)
5725 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5726 << BM_RCTL_MO_SHIFT);
5727 if (mac_reg & E1000_RCTL_BAM)
5728 phy_reg |= BM_RCTL_BAM;
5729 if (mac_reg & E1000_RCTL_PMCF)
5730 phy_reg |= BM_RCTL_PMCF;
5731 mac_reg = er32(CTRL);
5732 if (mac_reg & E1000_CTRL_RFCE)
5733 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005734 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005735
5736 /* enable PHY wakeup in MAC register */
5737 ew32(WUFC, wufc);
5738 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5739
5740 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005741 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5742 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005743
5744 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005745 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5746 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005747 if (retval)
5748 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005749release:
Bruce Allan94d81862009-11-20 23:25:26 +00005750 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005751
5752 return retval;
5753}
5754
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005755static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5756 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005757{
5758 struct net_device *netdev = pci_get_drvdata(pdev);
5759 struct e1000_adapter *adapter = netdev_priv(netdev);
5760 struct e1000_hw *hw = &adapter->hw;
5761 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005762 /* Runtime suspend should only enable wakeup for link changes */
5763 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005764 int retval = 0;
5765
5766 netif_device_detach(netdev);
5767
5768 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005769 int count = E1000_CHECK_RESET_COUNT;
5770
5771 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5772 usleep_range(10000, 20000);
5773
Auke Kokbc7f75f2007-09-17 12:30:59 -07005774 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5775 e1000e_down(adapter);
5776 e1000_free_irq(adapter);
5777 }
Bruce Allan4662e822008-08-26 18:37:06 -07005778 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005779
5780 retval = pci_save_state(pdev);
5781 if (retval)
5782 return retval;
5783
5784 status = er32(STATUS);
5785 if (status & E1000_STATUS_LU)
5786 wufc &= ~E1000_WUFC_LNKC;
5787
5788 if (wufc) {
5789 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005790 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005791
5792 /* turn on all-multi mode if wake on multicast is enabled */
5793 if (wufc & E1000_WUFC_MC) {
5794 rctl = er32(RCTL);
5795 rctl |= E1000_RCTL_MPE;
5796 ew32(RCTL, rctl);
5797 }
5798
5799 ctrl = er32(CTRL);
5800 /* advertise wake from D3Cold */
5801 #define E1000_CTRL_ADVD3WUC 0x00100000
5802 /* phy power management enable */
5803 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005804 ctrl |= E1000_CTRL_ADVD3WUC;
5805 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5806 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005807 ew32(CTRL, ctrl);
5808
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005809 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5810 adapter->hw.phy.media_type ==
5811 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005812 /* keep the laser running in D3 */
5813 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005814 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815 ew32(CTRL_EXT, ctrl_ext);
5816 }
5817
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005818 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005819 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005820
Auke Kokbc7f75f2007-09-17 12:30:59 -07005821 /* Allow time for pending master requests to run */
5822 e1000e_disable_pcie_master(&adapter->hw);
5823
Bruce Allan82776a42009-08-14 14:35:33 +00005824 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005825 /* enable wakeup by the PHY */
5826 retval = e1000_init_phy_wakeup(adapter, wufc);
5827 if (retval)
5828 return retval;
5829 } else {
5830 /* enable wakeup by the MAC */
5831 ew32(WUFC, wufc);
5832 ew32(WUC, E1000_WUC_PME_EN);
5833 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005834 } else {
5835 ew32(WUC, 0);
5836 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005837 }
5838
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005839 *enable_wake = !!wufc;
5840
Auke Kokbc7f75f2007-09-17 12:30:59 -07005841 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005842 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5843 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005844 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005845
5846 if (adapter->hw.phy.type == e1000_phy_igp_3)
5847 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5848
Bruce Allane921eb12012-11-28 09:28:37 +00005849 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005850 * would have already happened in close and is redundant.
5851 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005852 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005853
5854 pci_disable_device(pdev);
5855
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005856 return 0;
5857}
5858
5859static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5860{
5861 if (sleep && wake) {
5862 pci_prepare_to_sleep(pdev);
5863 return;
5864 }
5865
5866 pci_wake_from_d3(pdev, wake);
5867 pci_set_power_state(pdev, PCI_D3hot);
5868}
5869
5870static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
5871 bool wake)
5872{
5873 struct net_device *netdev = pci_get_drvdata(pdev);
5874 struct e1000_adapter *adapter = netdev_priv(netdev);
5875
Bruce Allane921eb12012-11-28 09:28:37 +00005876 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005877 * correctable error when the MAC transitions from D0 to D3. To
5878 * prevent this we need to mask off the correctable errors on the
5879 * downstream port of the pci-e switch.
5880 */
5881 if (adapter->flags & FLAG_IS_QUAD_PORT) {
5882 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005883 u16 devctl;
5884
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005885 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
5886 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
5887 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005888
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005889 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005890
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005891 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005892 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005893 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08005894 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005895}
5896
Bruce Allan6f461f62010-04-27 03:33:04 +00005897#ifdef CONFIG_PCIEASPM
5898static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
5899{
Yinghai Lu9f728f52011-05-12 17:11:47 -07005900 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00005901}
5902#else
5903static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07005904{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00005905 u16 aspm_ctl = 0;
5906
5907 if (state & PCIE_LINK_STATE_L0S)
5908 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
5909 if (state & PCIE_LINK_STATE_L1)
5910 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
5911
Bruce Allane921eb12012-11-28 09:28:37 +00005912 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00005913 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07005914 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00005915 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00005916
Jiang Liuf8c0fca2012-08-20 13:30:43 -06005917 if (pdev->bus->self)
5918 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00005919 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00005920}
5921#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00005922static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00005923{
5924 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
5925 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
5926 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
5927
5928 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07005929}
5930
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01005931#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005932static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005933{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005934 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005935}
5936
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005937static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005938{
5939 struct net_device *netdev = pci_get_drvdata(pdev);
5940 struct e1000_adapter *adapter = netdev_priv(netdev);
5941 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00005942 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005943 u32 err;
5944
Bruce Allan78cd29d2011-03-24 03:09:03 +00005945 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
5946 aspm_disable_flag = PCIE_LINK_STATE_L0S;
5947 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
5948 aspm_disable_flag |= PCIE_LINK_STATE_L1;
5949 if (aspm_disable_flag)
5950 e1000e_disable_aspm(pdev, aspm_disable_flag);
5951
Auke Kokbc7f75f2007-09-17 12:30:59 -07005952 pci_set_power_state(pdev, PCI_D0);
5953 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00005954 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09005955
Bruce Allan4662e822008-08-26 18:37:06 -07005956 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005957 if (netif_running(netdev)) {
5958 err = e1000_request_irq(adapter);
5959 if (err)
5960 return err;
5961 }
5962
Bruce Allan2fbe4522012-04-19 03:21:47 +00005963 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00005964 e1000_resume_workarounds_pchlan(&adapter->hw);
5965
Auke Kokbc7f75f2007-09-17 12:30:59 -07005966 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00005967
5968 /* report the system wakeup cause from S3/S4 */
5969 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
5970 u16 phy_data;
5971
5972 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
5973 if (phy_data) {
5974 e_info("PHY Wakeup cause - %s\n",
5975 phy_data & E1000_WUS_EX ? "Unicast Packet" :
5976 phy_data & E1000_WUS_MC ? "Multicast Packet" :
5977 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
5978 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00005979 phy_data & E1000_WUS_LNKC ?
5980 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00005981 }
5982 e1e_wphy(&adapter->hw, BM_WUS, ~0);
5983 } else {
5984 u32 wus = er32(WUS);
5985 if (wus) {
5986 e_info("MAC Wakeup cause - %s\n",
5987 wus & E1000_WUS_EX ? "Unicast Packet" :
5988 wus & E1000_WUS_MC ? "Multicast Packet" :
5989 wus & E1000_WUS_BC ? "Broadcast Packet" :
5990 wus & E1000_WUS_MAG ? "Magic Packet" :
5991 wus & E1000_WUS_LNKC ? "Link Status Change" :
5992 "other");
5993 }
5994 ew32(WUS, ~0);
5995 }
5996
Auke Kokbc7f75f2007-09-17 12:30:59 -07005997 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005998
Bruce Allancd791612010-05-10 14:59:51 +00005999 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006000
6001 if (netif_running(netdev))
6002 e1000e_up(adapter);
6003
6004 netif_device_attach(netdev);
6005
Bruce Allane921eb12012-11-28 09:28:37 +00006006 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006007 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006008 * under the control of the driver.
6009 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006010 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006011 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006012
6013 return 0;
6014}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006015
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006016#ifdef CONFIG_PM_SLEEP
6017static int e1000_suspend(struct device *dev)
6018{
6019 struct pci_dev *pdev = to_pci_dev(dev);
6020 int retval;
6021 bool wake;
6022
6023 retval = __e1000_shutdown(pdev, &wake, false);
6024 if (!retval)
6025 e1000_complete_shutdown(pdev, true, wake);
6026
6027 return retval;
6028}
6029
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006030static int e1000_resume(struct device *dev)
6031{
6032 struct pci_dev *pdev = to_pci_dev(dev);
6033 struct net_device *netdev = pci_get_drvdata(pdev);
6034 struct e1000_adapter *adapter = netdev_priv(netdev);
6035
6036 if (e1000e_pm_ready(adapter))
6037 adapter->idle_check = true;
6038
6039 return __e1000_resume(pdev);
6040}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006041#endif /* CONFIG_PM_SLEEP */
6042
6043#ifdef CONFIG_PM_RUNTIME
6044static int e1000_runtime_suspend(struct device *dev)
6045{
6046 struct pci_dev *pdev = to_pci_dev(dev);
6047 struct net_device *netdev = pci_get_drvdata(pdev);
6048 struct e1000_adapter *adapter = netdev_priv(netdev);
6049
6050 if (e1000e_pm_ready(adapter)) {
6051 bool wake;
6052
6053 __e1000_shutdown(pdev, &wake, true);
6054 }
6055
6056 return 0;
6057}
6058
6059static int e1000_idle(struct device *dev)
6060{
6061 struct pci_dev *pdev = to_pci_dev(dev);
6062 struct net_device *netdev = pci_get_drvdata(pdev);
6063 struct e1000_adapter *adapter = netdev_priv(netdev);
6064
6065 if (!e1000e_pm_ready(adapter))
6066 return 0;
6067
6068 if (adapter->idle_check) {
6069 adapter->idle_check = false;
6070 if (!e1000e_has_link(adapter))
6071 pm_schedule_suspend(dev, MSEC_PER_SEC);
6072 }
6073
6074 return -EBUSY;
6075}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006076
6077static int e1000_runtime_resume(struct device *dev)
6078{
6079 struct pci_dev *pdev = to_pci_dev(dev);
6080 struct net_device *netdev = pci_get_drvdata(pdev);
6081 struct e1000_adapter *adapter = netdev_priv(netdev);
6082
6083 if (!e1000e_pm_ready(adapter))
6084 return 0;
6085
6086 adapter->idle_check = !dev->power.runtime_auto;
6087 return __e1000_resume(pdev);
6088}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006089#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006090#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091
6092static void e1000_shutdown(struct pci_dev *pdev)
6093{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006094 bool wake = false;
6095
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006096 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006097
6098 if (system_state == SYSTEM_POWER_OFF)
6099 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100}
6101
6102#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006103
6104static irqreturn_t e1000_intr_msix(int irq, void *data)
6105{
6106 struct net_device *netdev = data;
6107 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006108
6109 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006110 int vector, msix_irq;
6111
Dongdong Deng147b2c82010-11-16 19:50:15 -08006112 vector = 0;
6113 msix_irq = adapter->msix_entries[vector].vector;
6114 disable_irq(msix_irq);
6115 e1000_intr_msix_rx(msix_irq, netdev);
6116 enable_irq(msix_irq);
6117
6118 vector++;
6119 msix_irq = adapter->msix_entries[vector].vector;
6120 disable_irq(msix_irq);
6121 e1000_intr_msix_tx(msix_irq, netdev);
6122 enable_irq(msix_irq);
6123
6124 vector++;
6125 msix_irq = adapter->msix_entries[vector].vector;
6126 disable_irq(msix_irq);
6127 e1000_msix_other(msix_irq, netdev);
6128 enable_irq(msix_irq);
6129 }
6130
6131 return IRQ_HANDLED;
6132}
6133
Bruce Allane921eb12012-11-28 09:28:37 +00006134/**
6135 * e1000_netpoll
6136 * @netdev: network interface device structure
6137 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138 * Polling 'interrupt' - used by things like netconsole to send skbs
6139 * without having to re-enable interrupts. It's not called while
6140 * the interrupt routine is executing.
6141 */
6142static void e1000_netpoll(struct net_device *netdev)
6143{
6144 struct e1000_adapter *adapter = netdev_priv(netdev);
6145
Dongdong Deng147b2c82010-11-16 19:50:15 -08006146 switch (adapter->int_mode) {
6147 case E1000E_INT_MODE_MSIX:
6148 e1000_intr_msix(adapter->pdev->irq, netdev);
6149 break;
6150 case E1000E_INT_MODE_MSI:
6151 disable_irq(adapter->pdev->irq);
6152 e1000_intr_msi(adapter->pdev->irq, netdev);
6153 enable_irq(adapter->pdev->irq);
6154 break;
6155 default: /* E1000E_INT_MODE_LEGACY */
6156 disable_irq(adapter->pdev->irq);
6157 e1000_intr(adapter->pdev->irq, netdev);
6158 enable_irq(adapter->pdev->irq);
6159 break;
6160 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006161}
6162#endif
6163
6164/**
6165 * e1000_io_error_detected - called when PCI error is detected
6166 * @pdev: Pointer to PCI device
6167 * @state: The current pci connection state
6168 *
6169 * This function is called after a PCI bus error affecting
6170 * this device has been detected.
6171 */
6172static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6173 pci_channel_state_t state)
6174{
6175 struct net_device *netdev = pci_get_drvdata(pdev);
6176 struct e1000_adapter *adapter = netdev_priv(netdev);
6177
6178 netif_device_detach(netdev);
6179
Mike Masonc93b5a72009-06-30 12:45:53 +00006180 if (state == pci_channel_io_perm_failure)
6181 return PCI_ERS_RESULT_DISCONNECT;
6182
Auke Kokbc7f75f2007-09-17 12:30:59 -07006183 if (netif_running(netdev))
6184 e1000e_down(adapter);
6185 pci_disable_device(pdev);
6186
6187 /* Request a slot slot reset. */
6188 return PCI_ERS_RESULT_NEED_RESET;
6189}
6190
6191/**
6192 * e1000_io_slot_reset - called after the pci bus has been reset.
6193 * @pdev: Pointer to PCI device
6194 *
6195 * Restart the card from scratch, as if from a cold-boot. Implementation
6196 * resembles the first-half of the e1000_resume routine.
6197 */
6198static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6199{
6200 struct net_device *netdev = pci_get_drvdata(pdev);
6201 struct e1000_adapter *adapter = netdev_priv(netdev);
6202 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006203 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006204 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006205 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006206
Bruce Allan78cd29d2011-03-24 03:09:03 +00006207 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6208 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006209 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006210 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6211 if (aspm_disable_flag)
6212 e1000e_disable_aspm(pdev, aspm_disable_flag);
6213
Bruce Allanf0f422e2008-08-04 17:21:53 -07006214 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006215 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006216 dev_err(&pdev->dev,
6217 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006218 result = PCI_ERS_RESULT_DISCONNECT;
6219 } else {
6220 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006221 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006222 pci_restore_state(pdev);
6223
6224 pci_enable_wake(pdev, PCI_D3hot, 0);
6225 pci_enable_wake(pdev, PCI_D3cold, 0);
6226
6227 e1000e_reset(adapter);
6228 ew32(WUS, ~0);
6229 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006230 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006231
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006232 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006234 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006235}
6236
6237/**
6238 * e1000_io_resume - called when traffic can start flowing again.
6239 * @pdev: Pointer to PCI device
6240 *
6241 * This callback is called when the error recovery driver tells us that
6242 * its OK to resume normal operation. Implementation resembles the
6243 * second-half of the e1000_resume routine.
6244 */
6245static void e1000_io_resume(struct pci_dev *pdev)
6246{
6247 struct net_device *netdev = pci_get_drvdata(pdev);
6248 struct e1000_adapter *adapter = netdev_priv(netdev);
6249
Bruce Allancd791612010-05-10 14:59:51 +00006250 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006251
6252 if (netif_running(netdev)) {
6253 if (e1000e_up(adapter)) {
6254 dev_err(&pdev->dev,
6255 "can't bring device back up after reset\n");
6256 return;
6257 }
6258 }
6259
6260 netif_device_attach(netdev);
6261
Bruce Allane921eb12012-11-28 09:28:37 +00006262 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006263 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006264 * under the control of the driver.
6265 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006266 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006267 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006268
6269}
6270
6271static void e1000_print_device_info(struct e1000_adapter *adapter)
6272{
6273 struct e1000_hw *hw = &adapter->hw;
6274 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006275 u32 ret_val;
6276 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006277
6278 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006279 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006280 /* bus width */
6281 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6282 "Width x1"),
6283 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006284 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006285 e_info("Intel(R) PRO/%s Network Connection\n",
6286 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006287 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6288 E1000_PBANUM_LENGTH);
6289 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006290 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006291 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6292 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006293}
6294
Auke Kok10aa4c02008-08-04 17:21:20 -07006295static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6296{
6297 struct e1000_hw *hw = &adapter->hw;
6298 int ret_val;
6299 u16 buf = 0;
6300
6301 if (hw->mac.type != e1000_82573)
6302 return;
6303
6304 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006305 le16_to_cpus(&buf);
6306 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006307 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006308 dev_warn(&adapter->pdev->dev,
6309 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006310 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006311}
6312
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006313static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006314 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006315{
6316 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006317 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006318
6319 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6320 adapter->flags |= FLAG_TSO_FORCE;
6321
6322 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006323 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6324 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006325 return 0;
6326
Ben Greear01840392012-02-11 15:39:25 +00006327 if (changed & NETIF_F_RXFCS) {
6328 if (features & NETIF_F_RXFCS) {
6329 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6330 } else {
6331 /* We need to take it back to defaults, which might mean
6332 * stripping is still disabled at the adapter level.
6333 */
6334 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6335 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6336 else
6337 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6338 }
6339 }
6340
Bruce Allan70495a52012-01-11 01:26:50 +00006341 netdev->features = features;
6342
Bruce Allandc221292011-08-19 03:23:48 +00006343 if (netif_running(netdev))
6344 e1000e_reinit_locked(adapter);
6345 else
6346 e1000e_reset(adapter);
6347
6348 return 0;
6349}
6350
Stephen Hemminger651c2462008-11-19 21:57:48 -08006351static const struct net_device_ops e1000e_netdev_ops = {
6352 .ndo_open = e1000_open,
6353 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006354 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006355 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006356 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006357 .ndo_set_mac_address = e1000_set_mac,
6358 .ndo_change_mtu = e1000_change_mtu,
6359 .ndo_do_ioctl = e1000_ioctl,
6360 .ndo_tx_timeout = e1000_tx_timeout,
6361 .ndo_validate_addr = eth_validate_addr,
6362
Stephen Hemminger651c2462008-11-19 21:57:48 -08006363 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6364 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6365#ifdef CONFIG_NET_POLL_CONTROLLER
6366 .ndo_poll_controller = e1000_netpoll,
6367#endif
Bruce Allandc221292011-08-19 03:23:48 +00006368 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006369};
6370
Auke Kokbc7f75f2007-09-17 12:30:59 -07006371/**
6372 * e1000_probe - Device Initialization Routine
6373 * @pdev: PCI device information struct
6374 * @ent: entry in e1000_pci_tbl
6375 *
6376 * Returns 0 on success, negative on failure
6377 *
6378 * e1000_probe initializes an adapter identified by a pci_dev structure.
6379 * The OS initialization, configuring of the adapter private structure,
6380 * and a hardware reset occur.
6381 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006382static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006383{
6384 struct net_device *netdev;
6385 struct e1000_adapter *adapter;
6386 struct e1000_hw *hw;
6387 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006388 resource_size_t mmio_start, mmio_len;
6389 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006390 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006391 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006392 int i, err, pci_using_dac;
6393 u16 eeprom_data = 0;
6394 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6395
Bruce Allan78cd29d2011-03-24 03:09:03 +00006396 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6397 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006398 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006399 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6400 if (aspm_disable_flag)
6401 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006402
Bruce Allanf0f422e2008-08-04 17:21:53 -07006403 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006404 if (err)
6405 return err;
6406
6407 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006408 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006409 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006410 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006411 if (!err)
6412 pci_using_dac = 1;
6413 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006414 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006415 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006416 err = dma_set_coherent_mask(&pdev->dev,
6417 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006418 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006419 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006420 goto err_dma;
6421 }
6422 }
6423 }
6424
Arjan van de Vene8de1482008-10-22 19:55:31 -07006425 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allanf0f422e2008-08-04 17:21:53 -07006426 pci_select_bars(pdev, IORESOURCE_MEM),
6427 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006428 if (err)
6429 goto err_pci_reg;
6430
Xiaotian Feng68eac462009-08-14 14:35:52 +00006431 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006432 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006433
Auke Kokbc7f75f2007-09-17 12:30:59 -07006434 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006435 /* PCI config space info */
6436 err = pci_save_state(pdev);
6437 if (err)
6438 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006439
6440 err = -ENOMEM;
6441 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6442 if (!netdev)
6443 goto err_alloc_etherdev;
6444
Auke Kokbc7f75f2007-09-17 12:30:59 -07006445 SET_NETDEV_DEV(netdev, &pdev->dev);
6446
Tom Herbertf85e4df2010-05-05 14:03:32 +00006447 netdev->irq = pdev->irq;
6448
Auke Kokbc7f75f2007-09-17 12:30:59 -07006449 pci_set_drvdata(pdev, netdev);
6450 adapter = netdev_priv(netdev);
6451 hw = &adapter->hw;
6452 adapter->netdev = netdev;
6453 adapter->pdev = pdev;
6454 adapter->ei = ei;
6455 adapter->pba = ei->pba;
6456 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006457 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006458 adapter->hw.adapter = adapter;
6459 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006460 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006461 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006462
6463 mmio_start = pci_resource_start(pdev, 0);
6464 mmio_len = pci_resource_len(pdev, 0);
6465
6466 err = -EIO;
6467 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6468 if (!adapter->hw.hw_addr)
6469 goto err_ioremap;
6470
6471 if ((adapter->flags & FLAG_HAS_FLASH) &&
6472 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6473 flash_start = pci_resource_start(pdev, 1);
6474 flash_len = pci_resource_len(pdev, 1);
6475 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6476 if (!adapter->hw.flash_address)
6477 goto err_flashmap;
6478 }
6479
6480 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006481 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006482 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006483 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006484 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006485 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006486
6487 netdev->mem_start = mmio_start;
6488 netdev->mem_end = mmio_start + mmio_len;
6489
6490 adapter->bd_number = cards_found++;
6491
Bruce Allan4662e822008-08-26 18:37:06 -07006492 e1000e_check_options(adapter);
6493
Auke Kokbc7f75f2007-09-17 12:30:59 -07006494 /* setup adapter struct */
6495 err = e1000_sw_init(adapter);
6496 if (err)
6497 goto err_sw_init;
6498
Auke Kokbc7f75f2007-09-17 12:30:59 -07006499 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6500 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6501 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6502
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006503 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006504 if (err)
6505 goto err_hw_init;
6506
Bruce Allan4a770352008-10-01 17:18:35 -07006507 if ((adapter->flags & FLAG_IS_ICH) &&
6508 (adapter->flags & FLAG_READ_ONLY_NVM))
6509 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6510
Auke Kokbc7f75f2007-09-17 12:30:59 -07006511 hw->mac.ops.get_bus_info(&adapter->hw);
6512
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006513 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006514
6515 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006516 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006517 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6518 adapter->hw.phy.disable_polarity_correction = 0;
6519 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6520 }
6521
Bruce Allan470a5422012-05-26 06:08:48 +00006522 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006523 dev_info(&pdev->dev,
6524 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006525
Bruce Allandc221292011-08-19 03:23:48 +00006526 /* Set initial default active device features */
6527 netdev->features = (NETIF_F_SG |
6528 NETIF_F_HW_VLAN_RX |
6529 NETIF_F_HW_VLAN_TX |
6530 NETIF_F_TSO |
6531 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006532 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006533 NETIF_F_RXCSUM |
6534 NETIF_F_HW_CSUM);
6535
6536 /* Set user-changeable features (subset of all device features) */
6537 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006538 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006539 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006540 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006541
6542 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6543 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6544
Bruce Allandc221292011-08-19 03:23:48 +00006545 netdev->vlan_features |= (NETIF_F_SG |
6546 NETIF_F_TSO |
6547 NETIF_F_TSO6 |
6548 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006549
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006550 netdev->priv_flags |= IFF_UNICAST_FLT;
6551
Yi Zou7b872a52010-09-22 17:57:58 +00006552 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006553 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006554 netdev->vlan_features |= NETIF_F_HIGHDMA;
6555 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006556
Auke Kokbc7f75f2007-09-17 12:30:59 -07006557 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6558 adapter->flags |= FLAG_MNG_PT_ENABLED;
6559
Bruce Allane921eb12012-11-28 09:28:37 +00006560 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006561 * put the device in a known good starting state
6562 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006563 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6564
Bruce Allane921eb12012-11-28 09:28:37 +00006565 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006566 * attempt. Let's give it a few tries
6567 */
6568 for (i = 0;; i++) {
6569 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6570 break;
6571 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006572 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006573 err = -EIO;
6574 goto err_eeprom;
6575 }
6576 }
6577
Auke Kok10aa4c02008-08-04 17:21:20 -07006578 e1000_eeprom_checks(adapter);
6579
Bruce Allan608f8a02010-01-13 02:04:58 +00006580 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006581 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006582 dev_err(&pdev->dev,
6583 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006584
6585 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006586
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006587 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006588 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006589 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006590 err = -EIO;
6591 goto err_eeprom;
6592 }
6593
6594 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006595 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006596 adapter->watchdog_timer.data = (unsigned long) adapter;
6597
6598 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006599 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006600 adapter->phy_info_timer.data = (unsigned long) adapter;
6601
6602 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6603 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006604 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6605 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006606 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006607
Auke Kokbc7f75f2007-09-17 12:30:59 -07006608 /* Initialize link parameters. User can change them with ethtool */
6609 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006610 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006611 adapter->hw.fc.requested_mode = e1000_fc_default;
6612 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006613 adapter->hw.phy.autoneg_advertised = 0x2f;
6614
6615 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006616 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6617 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006618
Bruce Allane921eb12012-11-28 09:28:37 +00006619 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006620 * the EEPROM, enable the ACPI Magic Packet filter
6621 */
6622 if (adapter->flags & FLAG_APME_IN_WUC) {
6623 /* APME bit in EEPROM is mapped to WUC.APME */
6624 eeprom_data = er32(WUC);
6625 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006626 if ((hw->mac.type > e1000_ich10lan) &&
6627 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006628 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006629 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6630 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6631 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006632 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6633 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006634 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006635 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6636 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006637 }
6638
6639 /* fetch WoL from EEPROM */
6640 if (eeprom_data & eeprom_apme_mask)
6641 adapter->eeprom_wol |= E1000_WUFC_MAG;
6642
Bruce Allane921eb12012-11-28 09:28:37 +00006643 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006644 * where the eeprom may be wrong or the board simply won't support
6645 * wake on lan on a particular port
6646 */
6647 if (!(adapter->flags & FLAG_HAS_WOL))
6648 adapter->eeprom_wol = 0;
6649
6650 /* initialize the wol settings based on the eeprom settings */
6651 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006652 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006653
Bruce Allan84527592008-11-21 17:00:22 -08006654 /* save off EEPROM version number */
6655 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6656
Auke Kokbc7f75f2007-09-17 12:30:59 -07006657 /* reset the hardware with the new settings */
6658 e1000e_reset(adapter);
6659
Bruce Allane921eb12012-11-28 09:28:37 +00006660 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006661 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006662 * under the control of the driver.
6663 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006664 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006665 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006666
Bruce Allanf2315bf2011-12-16 00:46:59 +00006667 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006668 err = register_netdev(netdev);
6669 if (err)
6670 goto err_register;
6671
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006672 /* carrier off reporting is important to ethtool even BEFORE open */
6673 netif_carrier_off(netdev);
6674
Auke Kokbc7f75f2007-09-17 12:30:59 -07006675 e1000_print_device_info(adapter);
6676
Alan Sternf3ec4f82010-06-08 15:23:51 -04006677 if (pci_dev_run_wake(pdev))
6678 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006679
Auke Kokbc7f75f2007-09-17 12:30:59 -07006680 return 0;
6681
6682err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006683 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006684 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006685err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006686 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006687 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006688err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006689 kfree(adapter->tx_ring);
6690 kfree(adapter->rx_ring);
6691err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006692 if (adapter->hw.flash_address)
6693 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006694 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006695err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006696 iounmap(adapter->hw.hw_addr);
6697err_ioremap:
6698 free_netdev(netdev);
6699err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006700 pci_release_selected_regions(pdev,
6701 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006702err_pci_reg:
6703err_dma:
6704 pci_disable_device(pdev);
6705 return err;
6706}
6707
6708/**
6709 * e1000_remove - Device Removal Routine
6710 * @pdev: PCI device information struct
6711 *
6712 * e1000_remove is called by the PCI subsystem to alert the driver
6713 * that it should release a PCI device. The could be caused by a
6714 * Hot-Plug event, or because the driver is going to be removed from
6715 * memory.
6716 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006717static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006718{
6719 struct net_device *netdev = pci_get_drvdata(pdev);
6720 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006721 bool down = test_bit(__E1000_DOWN, &adapter->state);
6722
Bruce Allane921eb12012-11-28 09:28:37 +00006723 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006724 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006725 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006726 if (!down)
6727 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006728 del_timer_sync(&adapter->watchdog_timer);
6729 del_timer_sync(&adapter->phy_info_timer);
6730
Bruce Allan41cec6f2009-11-20 23:28:56 +00006731 cancel_work_sync(&adapter->reset_task);
6732 cancel_work_sync(&adapter->watchdog_task);
6733 cancel_work_sync(&adapter->downshift_task);
6734 cancel_work_sync(&adapter->update_phy_task);
6735 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006736
Bruce Allanb67e1912012-12-27 08:32:33 +00006737 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6738 cancel_work_sync(&adapter->tx_hwtstamp_work);
6739 if (adapter->tx_hwtstamp_skb) {
6740 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6741 adapter->tx_hwtstamp_skb = NULL;
6742 }
6743 }
6744
Bruce Allan17f208d2009-12-01 15:47:22 +00006745 if (!(netdev->flags & IFF_UP))
6746 e1000_power_down_phy(adapter);
6747
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006748 /* Don't lie to e1000_close() down the road. */
6749 if (!down)
6750 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006751 unregister_netdev(netdev);
6752
Alan Sternf3ec4f82010-06-08 15:23:51 -04006753 if (pci_dev_run_wake(pdev))
6754 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006755
Bruce Allane921eb12012-11-28 09:28:37 +00006756 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006757 * would have already happened in close and is redundant.
6758 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006759 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006760
Bruce Allan4662e822008-08-26 18:37:06 -07006761 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006762 kfree(adapter->tx_ring);
6763 kfree(adapter->rx_ring);
6764
6765 iounmap(adapter->hw.hw_addr);
6766 if (adapter->hw.flash_address)
6767 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006768 pci_release_selected_regions(pdev,
6769 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006770
6771 free_netdev(netdev);
6772
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006773 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006774 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006775
Auke Kokbc7f75f2007-09-17 12:30:59 -07006776 pci_disable_device(pdev);
6777}
6778
6779/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006780static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006781 .error_detected = e1000_io_error_detected,
6782 .slot_reset = e1000_io_slot_reset,
6783 .resume = e1000_io_resume,
6784};
6785
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006786static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006787 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6788 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6789 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6790 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6791 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6792 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006793 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6794 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6795 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006796
Auke Kokbc7f75f2007-09-17 12:30:59 -07006797 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6798 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6799 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6800 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006801
Auke Kokbc7f75f2007-09-17 12:30:59 -07006802 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6803 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6804 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006805
Bruce Allan4662e822008-08-26 18:37:06 -07006806 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006807 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006808 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006809
Auke Kokbc7f75f2007-09-17 12:30:59 -07006810 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6811 board_80003es2lan },
6812 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6813 board_80003es2lan },
6814 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6815 board_80003es2lan },
6816 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6817 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006818
Auke Kokbc7f75f2007-09-17 12:30:59 -07006819 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6820 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6821 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6822 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6823 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6824 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6825 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006826 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006827
Auke Kokbc7f75f2007-09-17 12:30:59 -07006828 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6829 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6830 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6831 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6832 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006833 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006834 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6835 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6836 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6837
6838 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6839 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6840 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006841
Bruce Allanf4187b52008-08-26 18:36:50 -07006842 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6843 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006844 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006845
Bruce Allana4f58f52009-06-02 11:29:18 +00006846 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6847 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6848 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6849 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6850
Bruce Alland3738bb2010-06-16 13:27:28 +00006851 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6852 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6853
Bruce Allan2fbe4522012-04-19 03:21:47 +00006854 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6855 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006856 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6857 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006858
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006859 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006860};
6861MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6862
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006863#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006864static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006865 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6866 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6867 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006868};
David S. Millere50208a2010-03-16 23:36:24 -07006869#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006870
Auke Kokbc7f75f2007-09-17 12:30:59 -07006871/* PCI Device API Driver */
6872static struct pci_driver e1000_driver = {
6873 .name = e1000e_driver_name,
6874 .id_table = e1000_pci_tbl,
6875 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006876 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006877#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006878 .driver = {
6879 .pm = &e1000_pm_ops,
6880 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006881#endif
6882 .shutdown = e1000_shutdown,
6883 .err_handler = &e1000_err_handler
6884};
6885
6886/**
6887 * e1000_init_module - Driver Registration Routine
6888 *
6889 * e1000_init_module is the first routine called when the driver is
6890 * loaded. All it does is register with the PCI subsystem.
6891 **/
6892static int __init e1000_init_module(void)
6893{
6894 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00006895 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
6896 e1000e_driver_version);
Bruce Allanf5e261e2012-01-01 16:00:03 +00006897 pr_info("Copyright(c) 1999 - 2012 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006898 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00006899
Auke Kokbc7f75f2007-09-17 12:30:59 -07006900 return ret;
6901}
6902module_init(e1000_init_module);
6903
6904/**
6905 * e1000_exit_module - Driver Exit Cleanup Routine
6906 *
6907 * e1000_exit_module is called just before the driver is removed
6908 * from memory.
6909 **/
6910static void __exit e1000_exit_module(void)
6911{
6912 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006913}
6914module_exit(e1000_exit_module);
6915
6916
6917MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
6918MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
6919MODULE_LICENSE("GPL");
6920MODULE_VERSION(DRV_VERSION);
6921
Bruce Allan06c24b92012-02-23 03:13:13 +00006922/* netdev.c */