blob: e0eb5dddf3eae5b3f09b7acb0679270c3b0e6840 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allan8544b9f2010-03-24 12:55:30 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36#include <linux/pagemap.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000039#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070040#include <linux/tcp.h>
41#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070045#include <linux/ethtool.h>
46#include <linux/if_vlan.h>
47#include <linux/cpu.h>
48#include <linux/smp.h>
Linus Torvalds7e0bb712011-10-25 15:18:39 +020049#include <linux/pm_qos.h>
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +000050#include <linux/pm_runtime.h>
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +000051#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040052#include <linux/prefetch.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070053
54#include "e1000.h"
55
Bruce Allanb3ccf262011-05-19 01:53:41 +000056#define DRV_EXTRAVERSION "-k"
Bruce Allanc14c6432010-06-16 13:28:34 +000057
Bruce Allan9e019902013-01-12 07:28:54 +000058#define DRV_VERSION "2.2.14" DRV_EXTRAVERSION
Auke Kokbc7f75f2007-09-17 12:30:59 -070059char e1000e_driver_name[] = "e1000e";
60const char e1000e_driver_version[] = DRV_VERSION;
61
stephen hemmingerb3f4d592012-03-13 06:04:20 +000062#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
63static int debug = -1;
64module_param(debug, int, 0);
65MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
66
Bruce Allan78cd29d2011-03-24 03:09:03 +000067static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state);
68
Auke Kokbc7f75f2007-09-17 12:30:59 -070069static const struct e1000_info *e1000_info_tbl[] = {
70 [board_82571] = &e1000_82571_info,
71 [board_82572] = &e1000_82572_info,
72 [board_82573] = &e1000_82573_info,
Bruce Allan4662e822008-08-26 18:37:06 -070073 [board_82574] = &e1000_82574_info,
Alexander Duyck8c81c9c2009-03-19 01:12:27 +000074 [board_82583] = &e1000_82583_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070075 [board_80003es2lan] = &e1000_es2_info,
76 [board_ich8lan] = &e1000_ich8_info,
77 [board_ich9lan] = &e1000_ich9_info,
Bruce Allanf4187b52008-08-26 18:36:50 -070078 [board_ich10lan] = &e1000_ich10_info,
Bruce Allana4f58f52009-06-02 11:29:18 +000079 [board_pchlan] = &e1000_pch_info,
Bruce Alland3738bb2010-06-16 13:27:28 +000080 [board_pch2lan] = &e1000_pch2_info,
Bruce Allan2fbe4522012-04-19 03:21:47 +000081 [board_pch_lpt] = &e1000_pch_lpt_info,
Auke Kokbc7f75f2007-09-17 12:30:59 -070082};
83
Taku Izumi84f4ee92010-04-27 14:39:08 +000084struct e1000_reg_info {
85 u32 ofs;
86 char *name;
87};
88
Bruce Allanaf667a22010-12-31 06:10:01 +000089#define E1000_RDFH 0x02410 /* Rx Data FIFO Head - RW */
90#define E1000_RDFT 0x02418 /* Rx Data FIFO Tail - RW */
91#define E1000_RDFHS 0x02420 /* Rx Data FIFO Head Saved - RW */
92#define E1000_RDFTS 0x02428 /* Rx Data FIFO Tail Saved - RW */
93#define E1000_RDFPC 0x02430 /* Rx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +000094
Bruce Allanaf667a22010-12-31 06:10:01 +000095#define E1000_TDFH 0x03410 /* Tx Data FIFO Head - RW */
96#define E1000_TDFT 0x03418 /* Tx Data FIFO Tail - RW */
97#define E1000_TDFHS 0x03420 /* Tx Data FIFO Head Saved - RW */
98#define E1000_TDFTS 0x03428 /* Tx Data FIFO Tail Saved - RW */
99#define E1000_TDFPC 0x03430 /* Tx Data FIFO Packet Count - RW */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000100
101static const struct e1000_reg_info e1000_reg_info_tbl[] = {
102
103 /* General Registers */
104 {E1000_CTRL, "CTRL"},
105 {E1000_STATUS, "STATUS"},
106 {E1000_CTRL_EXT, "CTRL_EXT"},
107
108 /* Interrupt Registers */
109 {E1000_ICR, "ICR"},
110
Bruce Allanaf667a22010-12-31 06:10:01 +0000111 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000112 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000113 {E1000_RDLEN(0), "RDLEN"},
114 {E1000_RDH(0), "RDH"},
115 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000116 {E1000_RDTR, "RDTR"},
117 {E1000_RXDCTL(0), "RXDCTL"},
118 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000119 {E1000_RDBAL(0), "RDBAL"},
120 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000121 {E1000_RDFH, "RDFH"},
122 {E1000_RDFT, "RDFT"},
123 {E1000_RDFHS, "RDFHS"},
124 {E1000_RDFTS, "RDFTS"},
125 {E1000_RDFPC, "RDFPC"},
126
Bruce Allanaf667a22010-12-31 06:10:01 +0000127 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000128 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000129 {E1000_TDBAL(0), "TDBAL"},
130 {E1000_TDBAH(0), "TDBAH"},
131 {E1000_TDLEN(0), "TDLEN"},
132 {E1000_TDH(0), "TDH"},
133 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000134 {E1000_TIDV, "TIDV"},
135 {E1000_TXDCTL(0), "TXDCTL"},
136 {E1000_TADV, "TADV"},
137 {E1000_TARC(0), "TARC"},
138 {E1000_TDFH, "TDFH"},
139 {E1000_TDFT, "TDFT"},
140 {E1000_TDFHS, "TDFHS"},
141 {E1000_TDFTS, "TDFTS"},
142 {E1000_TDFPC, "TDFPC"},
143
144 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000145 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000146};
147
Bruce Allane921eb12012-11-28 09:28:37 +0000148/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000149 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000150 * @hw: pointer to the HW structure
151 * @reginfo: pointer to the register info table
152 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000153static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
154{
155 int n = 0;
156 char rname[16];
157 u32 regs[8];
158
159 switch (reginfo->ofs) {
160 case E1000_RXDCTL(0):
161 for (n = 0; n < 2; n++)
162 regs[n] = __er32(hw, E1000_RXDCTL(n));
163 break;
164 case E1000_TXDCTL(0):
165 for (n = 0; n < 2; n++)
166 regs[n] = __er32(hw, E1000_TXDCTL(n));
167 break;
168 case E1000_TARC(0):
169 for (n = 0; n < 2; n++)
170 regs[n] = __er32(hw, E1000_TARC(n));
171 break;
172 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000173 pr_info("%-15s %08x\n",
174 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000175 return;
176 }
177
178 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000179 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000180}
181
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000182static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
183 struct e1000_buffer *bi)
184{
185 int i;
186 struct e1000_ps_page *ps_page;
187
188 for (i = 0; i < adapter->rx_ps_pages; i++) {
189 ps_page = &bi->ps_pages[i];
190
191 if (ps_page->page) {
192 pr_info("packet dump for ps_page %d:\n", i);
193 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
194 16, 1, page_address(ps_page->page),
195 PAGE_SIZE, true);
196 }
197 }
198}
199
Bruce Allane921eb12012-11-28 09:28:37 +0000200/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000201 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000202 * @adapter: board private structure
203 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000204static void e1000e_dump(struct e1000_adapter *adapter)
205{
206 struct net_device *netdev = adapter->netdev;
207 struct e1000_hw *hw = &adapter->hw;
208 struct e1000_reg_info *reginfo;
209 struct e1000_ring *tx_ring = adapter->tx_ring;
210 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000211 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000212 __le64 a;
213 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000214 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000215 struct e1000_buffer *buffer_info;
216 struct e1000_ring *rx_ring = adapter->rx_ring;
217 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000218 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000219 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000220 __le64 a;
221 __le64 b;
222 __le64 c;
223 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000224 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000225 u32 staterr;
226 int i = 0;
227
228 if (!netif_msg_hw(adapter))
229 return;
230
231 /* Print netdevice Info */
232 if (netdev) {
233 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000234 pr_info("Device Name state trans_start last_rx\n");
235 pr_info("%-15s %016lX %016lX %016lX\n",
236 netdev->name, netdev->state, netdev->trans_start,
237 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238 }
239
240 /* Print Registers */
241 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000242 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000243 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
244 reginfo->name; reginfo++) {
245 e1000_regdump(hw, reginfo);
246 }
247
Bruce Allanaf667a22010-12-31 06:10:01 +0000248 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000249 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000250 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000251
Bruce Allanaf667a22010-12-31 06:10:01 +0000252 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000253 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000254 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000255 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
256 0, tx_ring->next_to_use, tx_ring->next_to_clean,
257 (unsigned long long)buffer_info->dma,
258 buffer_info->length,
259 buffer_info->next_to_watch,
260 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000261
Bruce Allanaf667a22010-12-31 06:10:01 +0000262 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000263 if (!netif_msg_tx_done(adapter))
264 goto rx_ring_summary;
265
Bruce Allanaf667a22010-12-31 06:10:01 +0000266 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000267
268 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
269 *
270 * Legacy Transmit Descriptor
271 * +--------------------------------------------------------------+
272 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
273 * +--------------------------------------------------------------+
274 * 8 | Special | CSS | Status | CMD | CSO | Length |
275 * +--------------------------------------------------------------+
276 * 63 48 47 36 35 32 31 24 23 16 15 0
277 *
278 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
279 * 63 48 47 40 39 32 31 16 15 8 7 0
280 * +----------------------------------------------------------------+
281 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
282 * +----------------------------------------------------------------+
283 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
284 * +----------------------------------------------------------------+
285 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
286 *
287 * Extended Data Descriptor (DTYP=0x1)
288 * +----------------------------------------------------------------+
289 * 0 | Buffer Address [63:0] |
290 * +----------------------------------------------------------------+
291 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
292 * +----------------------------------------------------------------+
293 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
294 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000295 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
296 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
297 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 +0000298 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000299 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000300 tx_desc = E1000_TX_DESC(*tx_ring, i);
301 buffer_info = &tx_ring->buffer_info[i];
302 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000303 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000304 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000305 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000306 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000307 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000308 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000309 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000310 next_desc = "";
311 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
312 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
313 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
314 i,
315 (unsigned long long)le64_to_cpu(u0->a),
316 (unsigned long long)le64_to_cpu(u0->b),
317 (unsigned long long)buffer_info->dma,
318 buffer_info->length, buffer_info->next_to_watch,
319 (unsigned long long)buffer_info->time_stamp,
320 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000321
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000322 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000323 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000324 16, 1, buffer_info->skb->data,
325 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000326 }
327
Bruce Allanaf667a22010-12-31 06:10:01 +0000328 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000329rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000330 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000331 pr_info("Queue [NTU] [NTC]\n");
332 pr_info(" %5d %5X %5X\n",
333 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000334
Bruce Allanaf667a22010-12-31 06:10:01 +0000335 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000336 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000337 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000338
Bruce Allanaf667a22010-12-31 06:10:01 +0000339 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000340 switch (adapter->rx_ps_pages) {
341 case 1:
342 case 2:
343 case 3:
344 /* [Extended] Packet Split Receive Descriptor Format
345 *
346 * +-----------------------------------------------------+
347 * 0 | Buffer Address 0 [63:0] |
348 * +-----------------------------------------------------+
349 * 8 | Buffer Address 1 [63:0] |
350 * +-----------------------------------------------------+
351 * 16 | Buffer Address 2 [63:0] |
352 * +-----------------------------------------------------+
353 * 24 | Buffer Address 3 [63:0] |
354 * +-----------------------------------------------------+
355 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000356 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 +0000357 /* [Extended] Receive Descriptor (Write-Back) Format
358 *
359 * 63 48 47 32 31 13 12 8 7 4 3 0
360 * +------------------------------------------------------+
361 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
362 * | Checksum | Ident | | Queue | | Type |
363 * +------------------------------------------------------+
364 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
365 * +------------------------------------------------------+
366 * 63 48 47 32 31 20 19 0
367 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000368 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 +0000369 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000370 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000371 buffer_info = &rx_ring->buffer_info[i];
372 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
373 u1 = (struct my_u1 *)rx_desc_ps;
374 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000375 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000376
377 if (i == rx_ring->next_to_use)
378 next_desc = " NTU";
379 else if (i == rx_ring->next_to_clean)
380 next_desc = " NTC";
381 else
382 next_desc = "";
383
Taku Izumi84f4ee92010-04-27 14:39:08 +0000384 if (staterr & E1000_RXD_STAT_DD) {
385 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000386 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
387 "RWB", i,
388 (unsigned long long)le64_to_cpu(u1->a),
389 (unsigned long long)le64_to_cpu(u1->b),
390 (unsigned long long)le64_to_cpu(u1->c),
391 (unsigned long long)le64_to_cpu(u1->d),
392 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000393 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000394 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
395 "R ", i,
396 (unsigned long long)le64_to_cpu(u1->a),
397 (unsigned long long)le64_to_cpu(u1->b),
398 (unsigned long long)le64_to_cpu(u1->c),
399 (unsigned long long)le64_to_cpu(u1->d),
400 (unsigned long long)buffer_info->dma,
401 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000402
403 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000404 e1000e_dump_ps_pages(adapter,
405 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000406 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000407 }
408 break;
409 default:
410 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000411 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000412 *
Bruce Allan5f450212011-07-22 06:21:46 +0000413 * +-----------------------------------------------------+
414 * 0 | Buffer Address [63:0] |
415 * +-----------------------------------------------------+
416 * 8 | Reserved |
417 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000418 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000419 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 +0000420 /* Extended Receive Descriptor (Write-Back) Format
421 *
422 * 63 48 47 32 31 24 23 4 3 0
423 * +------------------------------------------------------+
424 * | RSS Hash | | | |
425 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
426 * | Packet | IP | | | Type |
427 * | Checksum | Ident | | | |
428 * +------------------------------------------------------+
429 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
430 * +------------------------------------------------------+
431 * 63 48 47 32 31 20 19 0
432 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000433 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 +0000434
435 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000436 const char *next_desc;
437
Taku Izumi84f4ee92010-04-27 14:39:08 +0000438 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000439 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
440 u1 = (struct my_u1 *)rx_desc;
441 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000442
443 if (i == rx_ring->next_to_use)
444 next_desc = " NTU";
445 else if (i == rx_ring->next_to_clean)
446 next_desc = " NTC";
447 else
448 next_desc = "";
449
Bruce Allan5f450212011-07-22 06:21:46 +0000450 if (staterr & E1000_RXD_STAT_DD) {
451 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000452 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
453 "RWB", i,
454 (unsigned long long)le64_to_cpu(u1->a),
455 (unsigned long long)le64_to_cpu(u1->b),
456 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000457 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000458 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
459 "R ", i,
460 (unsigned long long)le64_to_cpu(u1->a),
461 (unsigned long long)le64_to_cpu(u1->b),
462 (unsigned long long)buffer_info->dma,
463 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000464
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000465 if (netif_msg_pktdata(adapter) &&
466 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000467 print_hex_dump(KERN_INFO, "",
468 DUMP_PREFIX_ADDRESS, 16,
469 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000470 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000471 adapter->rx_buffer_len,
472 true);
473 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000474 }
475 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000476}
477
Auke Kokbc7f75f2007-09-17 12:30:59 -0700478/**
479 * e1000_desc_unused - calculate if we have unused descriptors
480 **/
481static int e1000_desc_unused(struct e1000_ring *ring)
482{
483 if (ring->next_to_clean > ring->next_to_use)
484 return ring->next_to_clean - ring->next_to_use - 1;
485
486 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
487}
488
489/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000490 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
491 * @adapter: board private structure
492 * @hwtstamps: time stamp structure to update
493 * @systim: unsigned 64bit system time value.
494 *
495 * Convert the system time value stored in the RX/TXSTMP registers into a
496 * hwtstamp which can be used by the upper level time stamping functions.
497 *
498 * The 'systim_lock' spinlock is used to protect the consistency of the
499 * system time value. This is needed because reading the 64 bit time
500 * value involves reading two 32 bit registers. The first read latches the
501 * value.
502 **/
503static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
504 struct skb_shared_hwtstamps *hwtstamps,
505 u64 systim)
506{
507 u64 ns;
508 unsigned long flags;
509
510 spin_lock_irqsave(&adapter->systim_lock, flags);
511 ns = timecounter_cyc2time(&adapter->tc, systim);
512 spin_unlock_irqrestore(&adapter->systim_lock, flags);
513
514 memset(hwtstamps, 0, sizeof(*hwtstamps));
515 hwtstamps->hwtstamp = ns_to_ktime(ns);
516}
517
518/**
519 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
520 * @adapter: board private structure
521 * @status: descriptor extended error and status field
522 * @skb: particular skb to include time stamp
523 *
524 * If the time stamp is valid, convert it into the timecounter ns value
525 * and store that result into the shhwtstamps structure which is passed
526 * up the network stack.
527 **/
528static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
529 struct sk_buff *skb)
530{
531 struct e1000_hw *hw = &adapter->hw;
532 u64 rxstmp;
533
534 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
535 !(status & E1000_RXDEXT_STATERR_TST) ||
536 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
537 return;
538
539 /* The Rx time stamp registers contain the time stamp. No other
540 * received packet will be time stamped until the Rx time stamp
541 * registers are read. Because only one packet can be time stamped
542 * at a time, the register values must belong to this packet and
543 * therefore none of the other additional attributes need to be
544 * compared.
545 */
546 rxstmp = (u64)er32(RXSTMPL);
547 rxstmp |= (u64)er32(RXSTMPH) << 32;
548 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
549
550 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
551}
552
553/**
Bruce Allanad680762008-03-28 09:15:03 -0700554 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700555 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000556 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
558 * @skb: pointer to sk_buff to be indicated to stack
559 **/
560static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000561 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000562 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700563{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000564 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000565
566 e1000e_rx_hwtstamp(adapter, staterr, skb);
567
Auke Kokbc7f75f2007-09-17 12:30:59 -0700568 skb->protocol = eth_type_trans(skb, netdev);
569
Bruce Allanb67e1912012-12-27 08:32:33 +0000570 if (staterr & E1000_RXD_STAT_VP)
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000571 __vlan_hwaccel_put_tag(skb, tag);
572
573 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574}
575
576/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000577 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000578 * @adapter: board private structure
579 * @status_err: receive descriptor status and error fields
580 * @csum: receive descriptor csum field
581 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582 **/
583static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000584 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700585{
586 u16 status = (u16)status_err;
587 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700588
589 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590
Bruce Allanafd12932012-01-05 00:34:05 +0000591 /* Rx checksum disabled */
592 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
593 return;
594
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595 /* Ignore Checksum bit is set */
596 if (status & E1000_RXD_STAT_IXSM)
597 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000598
Bruce Allan2e1706f2012-06-30 20:02:42 +0000599 /* TCP/UDP checksum error bit or IP checksum error bit is set */
600 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 /* let the stack verify checksum errors */
602 adapter->hw_csum_err++;
603 return;
604 }
605
606 /* TCP/UDP Checksum has not been calculated */
607 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
608 return;
609
610 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000611 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 adapter->hw_csum_good++;
613}
614
Bruce Allan55aa6982011-12-16 00:45:45 +0000615static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700616{
Bruce Allan55aa6982011-12-16 00:45:45 +0000617 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700618 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000619 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700620
Bruce Allanbdc125f2012-03-20 03:47:52 +0000621 writel(i, rx_ring->tail);
622
623 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700624 u32 rctl = er32(RCTL);
625 ew32(RCTL, rctl & ~E1000_RCTL_EN);
626 e_err("ME firmware caused invalid RDT - resetting\n");
627 schedule_work(&adapter->reset_task);
628 }
629}
630
Bruce Allan55aa6982011-12-16 00:45:45 +0000631static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700632{
Bruce Allan55aa6982011-12-16 00:45:45 +0000633 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700634 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000635 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700636
Bruce Allanbdc125f2012-03-20 03:47:52 +0000637 writel(i, tx_ring->tail);
638
639 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700640 u32 tctl = er32(TCTL);
641 ew32(TCTL, tctl & ~E1000_TCTL_EN);
642 e_err("ME firmware caused invalid TDT - resetting\n");
643 schedule_work(&adapter->reset_task);
644 }
645}
646
647/**
Bruce Allan5f450212011-07-22 06:21:46 +0000648 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000649 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000651static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000652 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700653{
Bruce Allan55aa6982011-12-16 00:45:45 +0000654 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655 struct net_device *netdev = adapter->netdev;
656 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000657 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700658 struct e1000_buffer *buffer_info;
659 struct sk_buff *skb;
660 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000661 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700662
663 i = rx_ring->next_to_use;
664 buffer_info = &rx_ring->buffer_info[i];
665
666 while (cleaned_count--) {
667 skb = buffer_info->skb;
668 if (skb) {
669 skb_trim(skb, 0);
670 goto map_skb;
671 }
672
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000673 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 if (!skb) {
675 /* Better luck next round */
676 adapter->alloc_rx_buff_failed++;
677 break;
678 }
679
Auke Kokbc7f75f2007-09-17 12:30:59 -0700680 buffer_info->skb = skb;
681map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000682 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000684 DMA_FROM_DEVICE);
685 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000686 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687 adapter->rx_dma_failed++;
688 break;
689 }
690
Bruce Allan5f450212011-07-22 06:21:46 +0000691 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
692 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693
Tom Herbert50849d72010-05-05 14:02:49 +0000694 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000695 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000696 * know there are new descriptors to fetch. (Only
697 * applicable for weak-ordered memory model archs,
698 * such as IA-64).
699 */
700 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700701 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000702 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700703 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000704 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000705 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706 i++;
707 if (i == rx_ring->count)
708 i = 0;
709 buffer_info = &rx_ring->buffer_info[i];
710 }
711
Tom Herbert50849d72010-05-05 14:02:49 +0000712 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700713}
714
715/**
716 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000717 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000719static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000720 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700721{
Bruce Allan55aa6982011-12-16 00:45:45 +0000722 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700723 struct net_device *netdev = adapter->netdev;
724 struct pci_dev *pdev = adapter->pdev;
725 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700726 struct e1000_buffer *buffer_info;
727 struct e1000_ps_page *ps_page;
728 struct sk_buff *skb;
729 unsigned int i, j;
730
731 i = rx_ring->next_to_use;
732 buffer_info = &rx_ring->buffer_info[i];
733
734 while (cleaned_count--) {
735 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
736
737 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700738 ps_page = &buffer_info->ps_pages[j];
739 if (j >= adapter->rx_ps_pages) {
740 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000741 rx_desc->read.buffer_addr[j + 1] =
742 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700743 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700744 }
Auke Kok47f44e42007-10-25 13:57:44 -0700745 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000746 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700747 if (!ps_page->page) {
748 adapter->alloc_rx_buff_failed++;
749 goto no_buffers;
750 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000751 ps_page->dma = dma_map_page(&pdev->dev,
752 ps_page->page,
753 0, PAGE_SIZE,
754 DMA_FROM_DEVICE);
755 if (dma_mapping_error(&pdev->dev,
756 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700757 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000758 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700759 adapter->rx_dma_failed++;
760 goto no_buffers;
761 }
762 }
Bruce Allane921eb12012-11-28 09:28:37 +0000763 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700764 * didn't change because each write-back
765 * erases this info.
766 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000767 rx_desc->read.buffer_addr[j + 1] =
768 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700769 }
770
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000771 skb = __netdev_alloc_skb_ip_align(netdev,
772 adapter->rx_ps_bsize0,
773 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774
775 if (!skb) {
776 adapter->alloc_rx_buff_failed++;
777 break;
778 }
779
Auke Kokbc7f75f2007-09-17 12:30:59 -0700780 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000781 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700782 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000783 DMA_FROM_DEVICE);
784 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000785 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700786 adapter->rx_dma_failed++;
787 /* cleanup skb */
788 dev_kfree_skb_any(skb);
789 buffer_info->skb = NULL;
790 break;
791 }
792
793 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
794
Tom Herbert50849d72010-05-05 14:02:49 +0000795 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000796 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000797 * know there are new descriptors to fetch. (Only
798 * applicable for weak-ordered memory model archs,
799 * such as IA-64).
800 */
801 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700802 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000803 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700804 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000805 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000806 }
807
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808 i++;
809 if (i == rx_ring->count)
810 i = 0;
811 buffer_info = &rx_ring->buffer_info[i];
812 }
813
814no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000815 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816}
817
818/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700819 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000820 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821 * @cleaned_count: number of buffers to allocate this pass
822 **/
823
Bruce Allan55aa6982011-12-16 00:45:45 +0000824static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000825 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700826{
Bruce Allan55aa6982011-12-16 00:45:45 +0000827 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700828 struct net_device *netdev = adapter->netdev;
829 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000830 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700831 struct e1000_buffer *buffer_info;
832 struct sk_buff *skb;
833 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000834 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700835
836 i = rx_ring->next_to_use;
837 buffer_info = &rx_ring->buffer_info[i];
838
839 while (cleaned_count--) {
840 skb = buffer_info->skb;
841 if (skb) {
842 skb_trim(skb, 0);
843 goto check_page;
844 }
845
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000846 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700847 if (unlikely(!skb)) {
848 /* Better luck next round */
849 adapter->alloc_rx_buff_failed++;
850 break;
851 }
852
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700853 buffer_info->skb = skb;
854check_page:
855 /* allocate a new page if necessary */
856 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000857 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700858 if (unlikely(!buffer_info->page)) {
859 adapter->alloc_rx_buff_failed++;
860 break;
861 }
862 }
863
864 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000865 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700866 buffer_info->page, 0,
867 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000868 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700869
Bruce Allan5f450212011-07-22 06:21:46 +0000870 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
871 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700872
873 if (unlikely(++i == rx_ring->count))
874 i = 0;
875 buffer_info = &rx_ring->buffer_info[i];
876 }
877
878 if (likely(rx_ring->next_to_use != i)) {
879 rx_ring->next_to_use = i;
880 if (unlikely(i-- == 0))
881 i = (rx_ring->count - 1);
882
883 /* Force memory writes to complete before letting h/w
884 * know there are new descriptors to fetch. (Only
885 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000886 * such as IA-64).
887 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700888 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700889 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000890 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700891 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000892 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700893 }
894}
895
Bruce Allan70495a52012-01-11 01:26:50 +0000896static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
897 struct sk_buff *skb)
898{
899 if (netdev->features & NETIF_F_RXHASH)
900 skb->rxhash = le32_to_cpu(rss);
901}
902
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700903/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000904 * e1000_clean_rx_irq - Send received data up the network stack
905 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 *
907 * the return value indicates whether actual cleaning was done, there
908 * is no guarantee that everything was cleaned
909 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000910static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
911 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700912{
Bruce Allan55aa6982011-12-16 00:45:45 +0000913 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700914 struct net_device *netdev = adapter->netdev;
915 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000916 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000917 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000919 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 unsigned int i;
921 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000922 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700923 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
924
925 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000926 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
927 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700928 buffer_info = &rx_ring->buffer_info[i];
929
Bruce Allan5f450212011-07-22 06:21:46 +0000930 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932
933 if (*work_done >= work_to_do)
934 break;
935 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000936 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937
Auke Kokbc7f75f2007-09-17 12:30:59 -0700938 skb = buffer_info->skb;
939 buffer_info->skb = NULL;
940
941 prefetch(skb->data - NET_IP_ALIGN);
942
943 i++;
944 if (i == rx_ring->count)
945 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000946 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 prefetch(next_rxd);
948
949 next_buffer = &rx_ring->buffer_info[i];
950
Rusty Russell3db1cd52011-12-19 13:56:45 +0000951 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000953 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 buffer_info->dma,
955 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000956 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 buffer_info->dma = 0;
958
Bruce Allan5f450212011-07-22 06:21:46 +0000959 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960
Bruce Allane921eb12012-11-28 09:28:37 +0000961 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000962 * packet, if that's the case we need to toss it. In fact, we
963 * need to toss every packet with the EOP bit clear and the
964 * next frame that _does_ have the EOP bit set, as it is by
965 * definition only a frame fragment
966 */
Bruce Allan5f450212011-07-22 06:21:46 +0000967 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000968 adapter->flags2 |= FLAG2_IS_DISCARDING;
969
970 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000972 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 /* recycle */
974 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000975 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000976 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 goto next_desc;
978 }
979
Ben Greearcf955e62012-02-11 15:39:51 +0000980 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
981 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 /* recycle */
983 buffer_info->skb = skb;
984 goto next_desc;
985 }
986
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000987 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000988 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
989 /* If configured to store CRC, don't subtract FCS,
990 * but keep the FCS bytes out of the total_rx_bytes
991 * counter
992 */
993 if (netdev->features & NETIF_F_RXFCS)
994 total_rx_bytes -= 4;
995 else
996 length -= 4;
997 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000998
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 total_rx_bytes += length;
1000 total_rx_packets++;
1001
Bruce Allane921eb12012-11-28 09:28:37 +00001002 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -07001004 * of reassembly being done in the stack
1005 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 if (length < copybreak) {
1007 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +00001008 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -07001010 skb_copy_to_linear_data_offset(new_skb,
1011 -NET_IP_ALIGN,
1012 (skb->data -
1013 NET_IP_ALIGN),
1014 (length +
1015 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016 /* save the skb in buffer_info as good */
1017 buffer_info->skb = skb;
1018 skb = new_skb;
1019 }
1020 /* else just continue with the old one */
1021 }
1022 /* end copybreak code */
1023 skb_put(skb, length);
1024
1025 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001026 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027
Bruce Allan70495a52012-01-11 01:26:50 +00001028 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1029
Bruce Allan5f450212011-07-22 06:21:46 +00001030 e1000_receive_skb(adapter, netdev, skb, staterr,
1031 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032
1033next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001034 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035
1036 /* return some buffers to hardware, one at a time is too slow */
1037 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001038 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001039 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 cleaned_count = 0;
1041 }
1042
1043 /* use prefetched values */
1044 rx_desc = next_rxd;
1045 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001046
1047 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048 }
1049 rx_ring->next_to_clean = i;
1050
1051 cleaned_count = e1000_desc_unused(rx_ring);
1052 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001053 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001056 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 return cleaned;
1058}
1059
Bruce Allan55aa6982011-12-16 00:45:45 +00001060static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1061 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062{
Bruce Allan55aa6982011-12-16 00:45:45 +00001063 struct e1000_adapter *adapter = tx_ring->adapter;
1064
Alexander Duyck03b13202009-12-02 16:45:31 +00001065 if (buffer_info->dma) {
1066 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001067 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1068 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001069 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001070 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1071 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001072 buffer_info->dma = 0;
1073 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 if (buffer_info->skb) {
1075 dev_kfree_skb_any(buffer_info->skb);
1076 buffer_info->skb = NULL;
1077 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001078 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079}
1080
Bruce Allan41cec6f2009-11-20 23:28:56 +00001081static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001082{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001083 struct e1000_adapter *adapter = container_of(work,
1084 struct e1000_adapter,
1085 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001086 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 struct e1000_ring *tx_ring = adapter->tx_ring;
1088 unsigned int i = tx_ring->next_to_clean;
1089 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1090 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001091 struct e1000_hw *hw = &adapter->hw;
1092 u16 phy_status, phy_1000t_status, phy_ext_status;
1093 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001094
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001095 if (test_bit(__E1000_DOWN, &adapter->state))
1096 return;
1097
Jeff Kirsher09357b02011-11-18 14:25:00 +00001098 if (!adapter->tx_hang_recheck &&
1099 (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001100 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001101 * flush pending descriptor writebacks to memory
1102 */
1103 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1104 /* execute the writes immediately */
1105 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001106 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001107 * the write is successful
1108 */
1109 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1110 /* execute the writes immediately */
1111 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001112 adapter->tx_hang_recheck = true;
1113 return;
1114 }
1115 /* Real hang detected */
1116 adapter->tx_hang_recheck = false;
1117 netif_stop_queue(netdev);
1118
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001119 e1e_rphy(hw, MII_BMSR, &phy_status);
1120 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1121 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001122
1123 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1124
1125 /* detected Hardware unit hang */
1126 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001127 " TDH <%x>\n"
1128 " TDT <%x>\n"
1129 " next_to_use <%x>\n"
1130 " next_to_clean <%x>\n"
1131 "buffer_info[next_to_clean]:\n"
1132 " time_stamp <%lx>\n"
1133 " next_to_watch <%x>\n"
1134 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001135 " next_to_watch.status <%x>\n"
1136 "MAC Status <%x>\n"
1137 "PHY Status <%x>\n"
1138 "PHY 1000BASE-T Status <%x>\n"
1139 "PHY Extended Status <%x>\n"
1140 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001141 readl(tx_ring->head),
1142 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001143 tx_ring->next_to_use,
1144 tx_ring->next_to_clean,
1145 tx_ring->buffer_info[eop].time_stamp,
1146 eop,
1147 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001148 eop_desc->upper.fields.status,
1149 er32(STATUS),
1150 phy_status,
1151 phy_1000t_status,
1152 phy_ext_status,
1153 pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001154
1155 /* Suggest workaround for known h/w issue */
1156 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1157 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158}
1159
1160/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001161 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1162 * @work: pointer to work struct
1163 *
1164 * This work function polls the TSYNCTXCTL valid bit to determine when a
1165 * timestamp has been taken for the current stored skb. The timestamp must
1166 * be for this skb because only one such packet is allowed in the queue.
1167 */
1168static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1169{
1170 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1171 tx_hwtstamp_work);
1172 struct e1000_hw *hw = &adapter->hw;
1173
1174 if (!adapter->tx_hwtstamp_skb)
1175 return;
1176
1177 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1178 struct skb_shared_hwtstamps shhwtstamps;
1179 u64 txstmp;
1180
1181 txstmp = er32(TXSTMPL);
1182 txstmp |= (u64)er32(TXSTMPH) << 32;
1183
1184 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1185
1186 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1187 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1188 adapter->tx_hwtstamp_skb = NULL;
1189 } else {
1190 /* reschedule to check later */
1191 schedule_work(&adapter->tx_hwtstamp_work);
1192 }
1193}
1194
1195/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001197 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 *
1199 * the return value indicates whether actual cleaning was done, there
1200 * is no guarantee that everything was cleaned
1201 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001202static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203{
Bruce Allan55aa6982011-12-16 00:45:45 +00001204 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205 struct net_device *netdev = adapter->netdev;
1206 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 struct e1000_tx_desc *tx_desc, *eop_desc;
1208 struct e1000_buffer *buffer_info;
1209 unsigned int i, eop;
1210 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001212 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213
1214 i = tx_ring->next_to_clean;
1215 eop = tx_ring->buffer_info[i].next_to_watch;
1216 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1217
Alexander Duyck12d04a32009-03-25 22:05:03 +00001218 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1219 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001220 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001221 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001222 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223 tx_desc = E1000_TX_DESC(*tx_ring, i);
1224 buffer_info = &tx_ring->buffer_info[i];
1225 cleaned = (i == eop);
1226
1227 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001228 total_tx_packets += buffer_info->segs;
1229 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001230 if (buffer_info->skb) {
1231 bytes_compl += buffer_info->skb->len;
1232 pkts_compl++;
1233 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 }
1235
Bruce Allan55aa6982011-12-16 00:45:45 +00001236 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 tx_desc->upper.data = 0;
1238
1239 i++;
1240 if (i == tx_ring->count)
1241 i = 0;
1242 }
1243
Terry Loftindac87612010-04-09 10:29:49 +00001244 if (i == tx_ring->next_to_use)
1245 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 eop = tx_ring->buffer_info[i].next_to_watch;
1247 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 }
1249
1250 tx_ring->next_to_clean = i;
1251
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001252 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1253
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001255 if (count && netif_carrier_ok(netdev) &&
1256 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 /* Make sure that anybody stopping the queue after this
1258 * sees the new next_to_clean.
1259 */
1260 smp_mb();
1261
1262 if (netif_queue_stopped(netdev) &&
1263 !(test_bit(__E1000_DOWN, &adapter->state))) {
1264 netif_wake_queue(netdev);
1265 ++adapter->restart_queue;
1266 }
1267 }
1268
1269 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001270 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001271 * check with the clearing of time_stamp and movement of i
1272 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001273 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001274 if (tx_ring->buffer_info[i].time_stamp &&
1275 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001276 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001277 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001278 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001279 else
1280 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 }
1282 adapter->total_tx_bytes += total_tx_bytes;
1283 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001284 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001285}
1286
1287/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001288 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001289 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 *
1291 * the return value indicates whether actual cleaning was done, there
1292 * is no guarantee that everything was cleaned
1293 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001294static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1295 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001296{
Bruce Allan55aa6982011-12-16 00:45:45 +00001297 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001298 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001299 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1300 struct net_device *netdev = adapter->netdev;
1301 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001302 struct e1000_buffer *buffer_info, *next_buffer;
1303 struct e1000_ps_page *ps_page;
1304 struct sk_buff *skb;
1305 unsigned int i, j;
1306 u32 length, staterr;
1307 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001308 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1310
1311 i = rx_ring->next_to_clean;
1312 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1313 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1314 buffer_info = &rx_ring->buffer_info[i];
1315
1316 while (staterr & E1000_RXD_STAT_DD) {
1317 if (*work_done >= work_to_do)
1318 break;
1319 (*work_done)++;
1320 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001321 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322
1323 /* in the packet split case this is header only */
1324 prefetch(skb->data - NET_IP_ALIGN);
1325
1326 i++;
1327 if (i == rx_ring->count)
1328 i = 0;
1329 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1330 prefetch(next_rxd);
1331
1332 next_buffer = &rx_ring->buffer_info[i];
1333
Rusty Russell3db1cd52011-12-19 13:56:45 +00001334 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001336 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001337 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338 buffer_info->dma = 0;
1339
Bruce Allanaf667a22010-12-31 06:10:01 +00001340 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001341 if (!(staterr & E1000_RXD_STAT_EOP))
1342 adapter->flags2 |= FLAG2_IS_DISCARDING;
1343
1344 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001345 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001346 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001347 if (staterr & E1000_RXD_STAT_EOP)
1348 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001349 goto next_desc;
1350 }
1351
Ben Greearcf955e62012-02-11 15:39:51 +00001352 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1353 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354 dev_kfree_skb_irq(skb);
1355 goto next_desc;
1356 }
1357
1358 length = le16_to_cpu(rx_desc->wb.middle.length0);
1359
1360 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001361 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001362 dev_kfree_skb_irq(skb);
1363 goto next_desc;
1364 }
1365
1366 /* Good Receive */
1367 skb_put(skb, length);
1368
1369 {
Bruce Allane921eb12012-11-28 09:28:37 +00001370 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001371 * it more efficient than reusing j
1372 */
1373 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001374
Bruce Allane921eb12012-11-28 09:28:37 +00001375 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001376 * packet throughput, so unsplit small packets and
1377 * save the alloc/put only valid in softirq (napi)
1378 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001379 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001380 if (l1 && (l1 <= copybreak) &&
1381 ((length + l1) <= adapter->rx_ps_bsize0)) {
1382 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001383
Bruce Allan0e15df42012-01-31 06:37:11 +00001384 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001385
Bruce Allane921eb12012-11-28 09:28:37 +00001386 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001387 * kmap_atomic, so we can't hold the mapping
1388 * very long
1389 */
1390 dma_sync_single_for_cpu(&pdev->dev,
1391 ps_page->dma,
1392 PAGE_SIZE,
1393 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001394 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001395 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001396 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001397 dma_sync_single_for_device(&pdev->dev,
1398 ps_page->dma,
1399 PAGE_SIZE,
1400 DMA_FROM_DEVICE);
1401
1402 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001403 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1404 if (!(netdev->features & NETIF_F_RXFCS))
1405 l1 -= 4;
1406 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001407
1408 skb_put(skb, l1);
1409 goto copydone;
1410 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001411 }
1412
1413 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1414 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1415 if (!length)
1416 break;
1417
Auke Kok47f44e42007-10-25 13:57:44 -07001418 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001419 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1420 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001421 ps_page->dma = 0;
1422 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1423 ps_page->page = NULL;
1424 skb->len += length;
1425 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001426 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001427 }
1428
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001429 /* strip the ethernet crc, problem is we're using pages now so
1430 * this whole operation can get a little cpu intensive
1431 */
Ben Greear01840392012-02-11 15:39:25 +00001432 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1433 if (!(netdev->features & NETIF_F_RXFCS))
1434 pskb_trim(skb, skb->len - 4);
1435 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001436
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437copydone:
1438 total_rx_bytes += skb->len;
1439 total_rx_packets++;
1440
Bruce Allan2e1706f2012-06-30 20:02:42 +00001441 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001442
Bruce Allan70495a52012-01-11 01:26:50 +00001443 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1444
Auke Kokbc7f75f2007-09-17 12:30:59 -07001445 if (rx_desc->wb.upper.header_status &
1446 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1447 adapter->rx_hdr_split++;
1448
Bruce Allanb67e1912012-12-27 08:32:33 +00001449 e1000_receive_skb(adapter, netdev, skb, staterr,
1450 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451
1452next_desc:
1453 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1454 buffer_info->skb = NULL;
1455
1456 /* return some buffers to hardware, one at a time is too slow */
1457 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001458 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001459 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 cleaned_count = 0;
1461 }
1462
1463 /* use prefetched values */
1464 rx_desc = next_rxd;
1465 buffer_info = next_buffer;
1466
1467 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1468 }
1469 rx_ring->next_to_clean = i;
1470
1471 cleaned_count = e1000_desc_unused(rx_ring);
1472 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001473 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001476 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001477 return cleaned;
1478}
1479
1480/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001481 * e1000_consume_page - helper function
1482 **/
1483static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
1484 u16 length)
1485{
1486 bi->page = NULL;
1487 skb->len += length;
1488 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001489 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490}
1491
1492/**
1493 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1494 * @adapter: board private structure
1495 *
1496 * the return value indicates whether actual cleaning was done, there
1497 * is no guarantee that everything was cleaned
1498 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001499static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1500 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001501{
Bruce Allan55aa6982011-12-16 00:45:45 +00001502 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 struct net_device *netdev = adapter->netdev;
1504 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001505 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001506 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001507 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001508 unsigned int i;
1509 int cleaned_count = 0;
1510 bool cleaned = false;
1511 unsigned int total_rx_bytes=0, total_rx_packets=0;
1512
1513 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001514 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1515 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001516 buffer_info = &rx_ring->buffer_info[i];
1517
Bruce Allan5f450212011-07-22 06:21:46 +00001518 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001519 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001520
1521 if (*work_done >= work_to_do)
1522 break;
1523 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001524 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001525
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001526 skb = buffer_info->skb;
1527 buffer_info->skb = NULL;
1528
1529 ++i;
1530 if (i == rx_ring->count)
1531 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001532 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001533 prefetch(next_rxd);
1534
1535 next_buffer = &rx_ring->buffer_info[i];
1536
1537 cleaned = true;
1538 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001539 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1540 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001541 buffer_info->dma = 0;
1542
Bruce Allan5f450212011-07-22 06:21:46 +00001543 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001544
1545 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001546 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001547 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1548 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001549 /* recycle both page and skb */
1550 buffer_info->skb = skb;
1551 /* an error means any chain goes out the window too */
1552 if (rx_ring->rx_skb_top)
1553 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1554 rx_ring->rx_skb_top = NULL;
1555 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001556 }
1557
Bruce Allanf0f1a172010-12-11 05:53:32 +00001558#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001559 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001560 /* this descriptor is only the beginning (or middle) */
1561 if (!rxtop) {
1562 /* this is the beginning of a chain */
1563 rxtop = skb;
1564 skb_fill_page_desc(rxtop, 0, buffer_info->page,
1565 0, length);
1566 } else {
1567 /* this is the middle of a chain */
1568 skb_fill_page_desc(rxtop,
1569 skb_shinfo(rxtop)->nr_frags,
1570 buffer_info->page, 0, length);
1571 /* re-use the skb, only consumed the page */
1572 buffer_info->skb = skb;
1573 }
1574 e1000_consume_page(buffer_info, rxtop, length);
1575 goto next_desc;
1576 } else {
1577 if (rxtop) {
1578 /* end of the chain */
1579 skb_fill_page_desc(rxtop,
1580 skb_shinfo(rxtop)->nr_frags,
1581 buffer_info->page, 0, length);
1582 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001583 * page
1584 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001585 buffer_info->skb = skb;
1586 skb = rxtop;
1587 rxtop = NULL;
1588 e1000_consume_page(buffer_info, skb, length);
1589 } else {
1590 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001591 * copybreak to save the put_page/alloc_page
1592 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001593 if (length <= copybreak &&
1594 skb_tailroom(skb) >= length) {
1595 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001596 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001597 memcpy(skb_tail_pointer(skb), vaddr,
1598 length);
Cong Wang46790262011-11-25 23:14:23 +08001599 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001600 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001601 * buffer_info->page
1602 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001603 skb_put(skb, length);
1604 } else {
1605 skb_fill_page_desc(skb, 0,
1606 buffer_info->page, 0,
1607 length);
1608 e1000_consume_page(buffer_info, skb,
1609 length);
1610 }
1611 }
1612 }
1613
Bruce Allan2e1706f2012-06-30 20:02:42 +00001614 /* Receive Checksum Offload */
1615 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001616
Bruce Allan70495a52012-01-11 01:26:50 +00001617 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1618
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001619 /* probably a little skewed due to removing CRC */
1620 total_rx_bytes += skb->len;
1621 total_rx_packets++;
1622
1623 /* eth type trans needs skb->data to point to something */
1624 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001625 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001626 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001627 goto next_desc;
1628 }
1629
Bruce Allan5f450212011-07-22 06:21:46 +00001630 e1000_receive_skb(adapter, netdev, skb, staterr,
1631 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001632
1633next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001634 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001635
1636 /* return some buffers to hardware, one at a time is too slow */
1637 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001638 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001639 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001640 cleaned_count = 0;
1641 }
1642
1643 /* use prefetched values */
1644 rx_desc = next_rxd;
1645 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001646
1647 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001648 }
1649 rx_ring->next_to_clean = i;
1650
1651 cleaned_count = e1000_desc_unused(rx_ring);
1652 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001653 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001654
1655 adapter->total_rx_bytes += total_rx_bytes;
1656 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001657 return cleaned;
1658}
1659
1660/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001662 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001664static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001665{
Bruce Allan55aa6982011-12-16 00:45:45 +00001666 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001667 struct e1000_buffer *buffer_info;
1668 struct e1000_ps_page *ps_page;
1669 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670 unsigned int i, j;
1671
1672 /* Free all the Rx ring sk_buffs */
1673 for (i = 0; i < rx_ring->count; i++) {
1674 buffer_info = &rx_ring->buffer_info[i];
1675 if (buffer_info->dma) {
1676 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001677 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001679 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001680 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001681 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001682 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +00001683 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001685 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001687 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 buffer_info->dma = 0;
1689 }
1690
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001691 if (buffer_info->page) {
1692 put_page(buffer_info->page);
1693 buffer_info->page = NULL;
1694 }
1695
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 if (buffer_info->skb) {
1697 dev_kfree_skb(buffer_info->skb);
1698 buffer_info->skb = NULL;
1699 }
1700
1701 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001702 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001703 if (!ps_page->page)
1704 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001705 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1706 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 ps_page->dma = 0;
1708 put_page(ps_page->page);
1709 ps_page->page = NULL;
1710 }
1711 }
1712
1713 /* there also may be some cached data from a chained receive */
1714 if (rx_ring->rx_skb_top) {
1715 dev_kfree_skb(rx_ring->rx_skb_top);
1716 rx_ring->rx_skb_top = NULL;
1717 }
1718
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719 /* Zero out the descriptor ring */
1720 memset(rx_ring->desc, 0, rx_ring->size);
1721
1722 rx_ring->next_to_clean = 0;
1723 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001724 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725
Bruce Allanc5083cf2011-12-16 00:45:40 +00001726 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001727 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1728 e1000e_update_rdt_wa(rx_ring, 0);
1729 else
1730 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731}
1732
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001733static void e1000e_downshift_workaround(struct work_struct *work)
1734{
1735 struct e1000_adapter *adapter = container_of(work,
1736 struct e1000_adapter, downshift_task);
1737
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001738 if (test_bit(__E1000_DOWN, &adapter->state))
1739 return;
1740
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001741 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1742}
1743
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744/**
1745 * e1000_intr_msi - Interrupt Handler
1746 * @irq: interrupt number
1747 * @data: pointer to a network interface device structure
1748 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001749static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001750{
1751 struct net_device *netdev = data;
1752 struct e1000_adapter *adapter = netdev_priv(netdev);
1753 struct e1000_hw *hw = &adapter->hw;
1754 u32 icr = er32(ICR);
1755
Bruce Allane921eb12012-11-28 09:28:37 +00001756 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001757 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001758 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001759 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001760 * disconnect (LSC) before accessing any PHY registers
1761 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1763 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001764 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765
Bruce Allane921eb12012-11-28 09:28:37 +00001766 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001768 * adapter in watchdog
1769 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001770 if (netif_carrier_ok(netdev) &&
1771 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1772 /* disable receives */
1773 u32 rctl = er32(RCTL);
1774 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001775 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 }
1777 /* guard against interrupt when we're going down */
1778 if (!test_bit(__E1000_DOWN, &adapter->state))
1779 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1780 }
1781
Bruce Allan94fb8482013-01-23 09:00:03 +00001782 /* Reset on uncorrectable ECC error */
1783 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1784 u32 pbeccsts = er32(PBECCSTS);
1785
1786 adapter->corr_errors +=
1787 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1788 adapter->uncorr_errors +=
1789 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1790 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1791
1792 /* Do the reset outside of interrupt context */
1793 schedule_work(&adapter->reset_task);
1794
1795 /* return immediately since reset is imminent */
1796 return IRQ_HANDLED;
1797 }
1798
Ben Hutchings288379f2009-01-19 16:43:59 -08001799 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001800 adapter->total_tx_bytes = 0;
1801 adapter->total_tx_packets = 0;
1802 adapter->total_rx_bytes = 0;
1803 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001804 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001805 }
1806
1807 return IRQ_HANDLED;
1808}
1809
1810/**
1811 * e1000_intr - Interrupt Handler
1812 * @irq: interrupt number
1813 * @data: pointer to a network interface device structure
1814 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001815static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816{
1817 struct net_device *netdev = data;
1818 struct e1000_adapter *adapter = netdev_priv(netdev);
1819 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001820 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001821
Bruce Allana68ea772009-11-20 23:23:16 +00001822 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823 return IRQ_NONE; /* Not our interrupt */
1824
Bruce Allane921eb12012-11-28 09:28:37 +00001825 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001826 * not set, then the adapter didn't send an interrupt
1827 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001828 if (!(icr & E1000_ICR_INT_ASSERTED))
1829 return IRQ_NONE;
1830
Bruce Allane921eb12012-11-28 09:28:37 +00001831 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001832 * interrupts are masked. No need for the
1833 * IMC write
1834 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835
dave graham573cca82009-02-10 12:52:05 +00001836 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001837 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001838 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001839 * disconnect (LSC) before accessing any PHY registers
1840 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001841 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1842 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001843 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001844
Bruce Allane921eb12012-11-28 09:28:37 +00001845 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 * For packet buffer work-around on link down event;
1847 * disable receives here in the ISR and
1848 * reset adapter in watchdog
1849 */
1850 if (netif_carrier_ok(netdev) &&
1851 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1852 /* disable receives */
1853 rctl = er32(RCTL);
1854 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001855 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 }
1857 /* guard against interrupt when we're going down */
1858 if (!test_bit(__E1000_DOWN, &adapter->state))
1859 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1860 }
1861
Bruce Allan94fb8482013-01-23 09:00:03 +00001862 /* Reset on uncorrectable ECC error */
1863 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1864 u32 pbeccsts = er32(PBECCSTS);
1865
1866 adapter->corr_errors +=
1867 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1868 adapter->uncorr_errors +=
1869 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1870 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1871
1872 /* Do the reset outside of interrupt context */
1873 schedule_work(&adapter->reset_task);
1874
1875 /* return immediately since reset is imminent */
1876 return IRQ_HANDLED;
1877 }
1878
Ben Hutchings288379f2009-01-19 16:43:59 -08001879 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001880 adapter->total_tx_bytes = 0;
1881 adapter->total_tx_packets = 0;
1882 adapter->total_rx_bytes = 0;
1883 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001884 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885 }
1886
1887 return IRQ_HANDLED;
1888}
1889
Bruce Allan8bb62862013-01-16 08:46:49 +00001890static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001891{
1892 struct net_device *netdev = data;
1893 struct e1000_adapter *adapter = netdev_priv(netdev);
1894 struct e1000_hw *hw = &adapter->hw;
1895 u32 icr = er32(ICR);
1896
1897 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001898 if (!test_bit(__E1000_DOWN, &adapter->state))
1899 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001900 return IRQ_NONE;
1901 }
1902
1903 if (icr & adapter->eiac_mask)
1904 ew32(ICS, (icr & adapter->eiac_mask));
1905
1906 if (icr & E1000_ICR_OTHER) {
1907 if (!(icr & E1000_ICR_LSC))
1908 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001909 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001910 /* guard against interrupt when we're going down */
1911 if (!test_bit(__E1000_DOWN, &adapter->state))
1912 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1913 }
1914
1915no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001916 if (!test_bit(__E1000_DOWN, &adapter->state))
1917 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001918
1919 return IRQ_HANDLED;
1920}
1921
Bruce Allan8bb62862013-01-16 08:46:49 +00001922static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001923{
1924 struct net_device *netdev = data;
1925 struct e1000_adapter *adapter = netdev_priv(netdev);
1926 struct e1000_hw *hw = &adapter->hw;
1927 struct e1000_ring *tx_ring = adapter->tx_ring;
1928
1929
1930 adapter->total_tx_bytes = 0;
1931 adapter->total_tx_packets = 0;
1932
Bruce Allan55aa6982011-12-16 00:45:45 +00001933 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001934 /* Ring was not completely cleaned, so fire another interrupt */
1935 ew32(ICS, tx_ring->ims_val);
1936
1937 return IRQ_HANDLED;
1938}
1939
Bruce Allan8bb62862013-01-16 08:46:49 +00001940static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001941{
1942 struct net_device *netdev = data;
1943 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001944 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001945
1946 /* Write the ITR value calculated at the end of the
1947 * previous interrupt.
1948 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001949 if (rx_ring->set_itr) {
1950 writel(1000000000 / (rx_ring->itr_val * 256),
1951 rx_ring->itr_register);
1952 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001953 }
1954
Ben Hutchings288379f2009-01-19 16:43:59 -08001955 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001956 adapter->total_rx_bytes = 0;
1957 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001958 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001959 }
1960 return IRQ_HANDLED;
1961}
1962
1963/**
1964 * e1000_configure_msix - Configure MSI-X hardware
1965 *
1966 * e1000_configure_msix sets up the hardware to properly
1967 * generate MSI-X interrupts.
1968 **/
1969static void e1000_configure_msix(struct e1000_adapter *adapter)
1970{
1971 struct e1000_hw *hw = &adapter->hw;
1972 struct e1000_ring *rx_ring = adapter->rx_ring;
1973 struct e1000_ring *tx_ring = adapter->tx_ring;
1974 int vector = 0;
1975 u32 ctrl_ext, ivar = 0;
1976
1977 adapter->eiac_mask = 0;
1978
1979 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1980 if (hw->mac.type == e1000_82574) {
1981 u32 rfctl = er32(RFCTL);
1982 rfctl |= E1000_RFCTL_ACK_DIS;
1983 ew32(RFCTL, rfctl);
1984 }
1985
1986#define E1000_IVAR_INT_ALLOC_VALID 0x8
1987 /* Configure Rx vector */
1988 rx_ring->ims_val = E1000_IMS_RXQ0;
1989 adapter->eiac_mask |= rx_ring->ims_val;
1990 if (rx_ring->itr_val)
1991 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001992 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001993 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001994 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001995 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1996
1997 /* Configure Tx vector */
1998 tx_ring->ims_val = E1000_IMS_TXQ0;
1999 vector++;
2000 if (tx_ring->itr_val)
2001 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00002002 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002003 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00002004 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07002005 adapter->eiac_mask |= tx_ring->ims_val;
2006 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
2007
2008 /* set vector for Other Causes, e.g. link changes */
2009 vector++;
2010 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2011 if (rx_ring->itr_val)
2012 writel(1000000000 / (rx_ring->itr_val * 256),
2013 hw->hw_addr + E1000_EITR_82574(vector));
2014 else
2015 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2016
2017 /* Cause Tx interrupts on every write back */
2018 ivar |= (1 << 31);
2019
2020 ew32(IVAR, ivar);
2021
2022 /* enable MSI-X PBA support */
2023 ctrl_ext = er32(CTRL_EXT);
2024 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2025
2026 /* Auto-Mask Other interrupts upon ICR read */
2027#define E1000_EIAC_MASK_82574 0x01F00000
2028 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2029 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2030 ew32(CTRL_EXT, ctrl_ext);
2031 e1e_flush();
2032}
2033
2034void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2035{
2036 if (adapter->msix_entries) {
2037 pci_disable_msix(adapter->pdev);
2038 kfree(adapter->msix_entries);
2039 adapter->msix_entries = NULL;
2040 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2041 pci_disable_msi(adapter->pdev);
2042 adapter->flags &= ~FLAG_MSI_ENABLED;
2043 }
Bruce Allan4662e822008-08-26 18:37:06 -07002044}
2045
2046/**
2047 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2048 *
2049 * Attempt to configure interrupts using the best available
2050 * capabilities of the hardware and kernel.
2051 **/
2052void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2053{
2054 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002055 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002056
2057 switch (adapter->int_mode) {
2058 case E1000E_INT_MODE_MSIX:
2059 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002060 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2061 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002062 sizeof(struct msix_entry),
2063 GFP_KERNEL);
2064 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002065 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002066 adapter->msix_entries[i].entry = i;
2067
2068 err = pci_enable_msix(adapter->pdev,
2069 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002070 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002071 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002072 return;
2073 }
2074 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002075 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002076 e1000e_reset_interrupt_capability(adapter);
2077 }
2078 adapter->int_mode = E1000E_INT_MODE_MSI;
2079 /* Fall through */
2080 case E1000E_INT_MODE_MSI:
2081 if (!pci_enable_msi(adapter->pdev)) {
2082 adapter->flags |= FLAG_MSI_ENABLED;
2083 } else {
2084 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002085 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002086 }
2087 /* Fall through */
2088 case E1000E_INT_MODE_LEGACY:
2089 /* Don't do anything; this is the system default */
2090 break;
2091 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002092
2093 /* store the number of vectors being used */
2094 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002095}
2096
2097/**
2098 * e1000_request_msix - Initialize MSI-X interrupts
2099 *
2100 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2101 * kernel.
2102 **/
2103static int e1000_request_msix(struct e1000_adapter *adapter)
2104{
2105 struct net_device *netdev = adapter->netdev;
2106 int err = 0, vector = 0;
2107
2108 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002109 snprintf(adapter->rx_ring->name,
2110 sizeof(adapter->rx_ring->name) - 1,
2111 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002112 else
2113 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2114 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002115 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002116 netdev);
2117 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002118 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002119 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2120 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002121 adapter->rx_ring->itr_val = adapter->itr;
2122 vector++;
2123
2124 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002125 snprintf(adapter->tx_ring->name,
2126 sizeof(adapter->tx_ring->name) - 1,
2127 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002128 else
2129 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2130 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002131 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002132 netdev);
2133 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002134 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002135 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2136 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002137 adapter->tx_ring->itr_val = adapter->itr;
2138 vector++;
2139
2140 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002141 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002142 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002143 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002144
2145 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002146
Bruce Allan4662e822008-08-26 18:37:06 -07002147 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002148}
2149
Bruce Allanf8d59f72008-08-08 18:36:11 -07002150/**
2151 * e1000_request_irq - initialize interrupts
2152 *
2153 * Attempts to configure interrupts using the best available
2154 * capabilities of the hardware and kernel.
2155 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002156static int e1000_request_irq(struct e1000_adapter *adapter)
2157{
2158 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 int err;
2160
Bruce Allan4662e822008-08-26 18:37:06 -07002161 if (adapter->msix_entries) {
2162 err = e1000_request_msix(adapter);
2163 if (!err)
2164 return err;
2165 /* fall back to MSI */
2166 e1000e_reset_interrupt_capability(adapter);
2167 adapter->int_mode = E1000E_INT_MODE_MSI;
2168 e1000e_set_interrupt_capability(adapter);
2169 }
2170 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002171 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002172 netdev->name, netdev);
2173 if (!err)
2174 return err;
2175
2176 /* fall back to legacy interrupt */
2177 e1000e_reset_interrupt_capability(adapter);
2178 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002179 }
2180
Joe Perchesa0607fd2009-11-18 23:29:17 -08002181 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002182 netdev->name, netdev);
2183 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002184 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185
2186 return err;
2187}
2188
2189static void e1000_free_irq(struct e1000_adapter *adapter)
2190{
2191 struct net_device *netdev = adapter->netdev;
2192
Bruce Allan4662e822008-08-26 18:37:06 -07002193 if (adapter->msix_entries) {
2194 int vector = 0;
2195
2196 free_irq(adapter->msix_entries[vector].vector, netdev);
2197 vector++;
2198
2199 free_irq(adapter->msix_entries[vector].vector, netdev);
2200 vector++;
2201
2202 /* Other Causes interrupt vector */
2203 free_irq(adapter->msix_entries[vector].vector, netdev);
2204 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002205 }
Bruce Allan4662e822008-08-26 18:37:06 -07002206
2207 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208}
2209
2210/**
2211 * e1000_irq_disable - Mask off interrupt generation on the NIC
2212 **/
2213static void e1000_irq_disable(struct e1000_adapter *adapter)
2214{
2215 struct e1000_hw *hw = &adapter->hw;
2216
Auke Kokbc7f75f2007-09-17 12:30:59 -07002217 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002218 if (adapter->msix_entries)
2219 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002221
2222 if (adapter->msix_entries) {
2223 int i;
2224 for (i = 0; i < adapter->num_vectors; i++)
2225 synchronize_irq(adapter->msix_entries[i].vector);
2226 } else {
2227 synchronize_irq(adapter->pdev->irq);
2228 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229}
2230
2231/**
2232 * e1000_irq_enable - Enable default interrupt generation settings
2233 **/
2234static void e1000_irq_enable(struct e1000_adapter *adapter)
2235{
2236 struct e1000_hw *hw = &adapter->hw;
2237
Bruce Allan4662e822008-08-26 18:37:06 -07002238 if (adapter->msix_entries) {
2239 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2240 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002241 } else if (hw->mac.type == e1000_pch_lpt) {
2242 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002243 } else {
2244 ew32(IMS, IMS_ENABLE_MASK);
2245 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002246 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247}
2248
2249/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002250 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 * @adapter: address of board private structure
2252 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002253 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002254 * For ASF and Pass Through versions of f/w this means that
2255 * the driver is loaded. For AMT version (only with 82573)
2256 * of the f/w this means that the network i/f is open.
2257 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002258void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259{
2260 struct e1000_hw *hw = &adapter->hw;
2261 u32 ctrl_ext;
2262 u32 swsm;
2263
2264 /* Let firmware know the driver has taken over */
2265 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2266 swsm = er32(SWSM);
2267 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2268 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2269 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002270 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271 }
2272}
2273
2274/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002275 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002276 * @adapter: address of board private structure
2277 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002278 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002279 * For ASF and Pass Through versions of f/w this means that the
2280 * driver is no longer loaded. For AMT version (only with 82573) i
2281 * of the f/w this means that the network i/f is closed.
2282 *
2283 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002284void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285{
2286 struct e1000_hw *hw = &adapter->hw;
2287 u32 ctrl_ext;
2288 u32 swsm;
2289
2290 /* Let firmware taken over control of h/w */
2291 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2292 swsm = er32(SWSM);
2293 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2294 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2295 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002296 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 }
2298}
2299
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002301 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302 **/
2303static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2304 struct e1000_ring *ring)
2305{
2306 struct pci_dev *pdev = adapter->pdev;
2307
2308 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2309 GFP_KERNEL);
2310 if (!ring->desc)
2311 return -ENOMEM;
2312
2313 return 0;
2314}
2315
2316/**
2317 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002318 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 *
2320 * Return 0 on success, negative on failure
2321 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002322int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323{
Bruce Allan55aa6982011-12-16 00:45:45 +00002324 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 int err = -ENOMEM, size;
2326
2327 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002328 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329 if (!tx_ring->buffer_info)
2330 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002331
2332 /* round up to nearest 4K */
2333 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2334 tx_ring->size = ALIGN(tx_ring->size, 4096);
2335
2336 err = e1000_alloc_ring_dma(adapter, tx_ring);
2337 if (err)
2338 goto err;
2339
2340 tx_ring->next_to_use = 0;
2341 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342
2343 return 0;
2344err:
2345 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002346 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347 return err;
2348}
2349
2350/**
2351 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002352 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 *
2354 * Returns 0 on success, negative on failure
2355 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002356int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357{
Bruce Allan55aa6982011-12-16 00:45:45 +00002358 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002359 struct e1000_buffer *buffer_info;
2360 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361
2362 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002363 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364 if (!rx_ring->buffer_info)
2365 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366
Auke Kok47f44e42007-10-25 13:57:44 -07002367 for (i = 0; i < rx_ring->count; i++) {
2368 buffer_info = &rx_ring->buffer_info[i];
2369 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2370 sizeof(struct e1000_ps_page),
2371 GFP_KERNEL);
2372 if (!buffer_info->ps_pages)
2373 goto err_pages;
2374 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375
2376 desc_len = sizeof(union e1000_rx_desc_packet_split);
2377
2378 /* Round up to nearest 4K */
2379 rx_ring->size = rx_ring->count * desc_len;
2380 rx_ring->size = ALIGN(rx_ring->size, 4096);
2381
2382 err = e1000_alloc_ring_dma(adapter, rx_ring);
2383 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002384 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385
2386 rx_ring->next_to_clean = 0;
2387 rx_ring->next_to_use = 0;
2388 rx_ring->rx_skb_top = NULL;
2389
2390 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002391
2392err_pages:
2393 for (i = 0; i < rx_ring->count; i++) {
2394 buffer_info = &rx_ring->buffer_info[i];
2395 kfree(buffer_info->ps_pages);
2396 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397err:
2398 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002399 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 return err;
2401}
2402
2403/**
2404 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002405 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002407static void e1000_clean_tx_ring(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 e1000_buffer *buffer_info;
2411 unsigned long size;
2412 unsigned int i;
2413
2414 for (i = 0; i < tx_ring->count; i++) {
2415 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002416 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417 }
2418
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002419 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420 size = sizeof(struct e1000_buffer) * tx_ring->count;
2421 memset(tx_ring->buffer_info, 0, size);
2422
2423 memset(tx_ring->desc, 0, tx_ring->size);
2424
2425 tx_ring->next_to_use = 0;
2426 tx_ring->next_to_clean = 0;
2427
Bruce Allanc5083cf2011-12-16 00:45:40 +00002428 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002429 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2430 e1000e_update_tdt_wa(tx_ring, 0);
2431 else
2432 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002433}
2434
2435/**
2436 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002437 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002438 *
2439 * Free all transmit software resources
2440 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002441void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442{
Bruce Allan55aa6982011-12-16 00:45:45 +00002443 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445
Bruce Allan55aa6982011-12-16 00:45:45 +00002446 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447
2448 vfree(tx_ring->buffer_info);
2449 tx_ring->buffer_info = NULL;
2450
2451 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2452 tx_ring->dma);
2453 tx_ring->desc = NULL;
2454}
2455
2456/**
2457 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002458 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459 *
2460 * Free all receive software resources
2461 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002462void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002463{
Bruce Allan55aa6982011-12-16 00:45:45 +00002464 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002466 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467
Bruce Allan55aa6982011-12-16 00:45:45 +00002468 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002469
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002470 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002471 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002472
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473 vfree(rx_ring->buffer_info);
2474 rx_ring->buffer_info = NULL;
2475
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2477 rx_ring->dma);
2478 rx_ring->desc = NULL;
2479}
2480
2481/**
2482 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002483 * @adapter: pointer to adapter
2484 * @itr_setting: current adapter->itr
2485 * @packets: the number of packets during this measurement interval
2486 * @bytes: the number of bytes during this measurement interval
2487 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 * Stores a new ITR value based on packets and byte
2489 * counts during the last interrupt. The advantage of per interrupt
2490 * computation is faster updates and more accurate ITR for the current
2491 * traffic pattern. Constants in this function were computed
2492 * based on theoretical maximum wire speed and thresholds were set based
2493 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002494 * while increasing bulk throughput. This functionality is controlled
2495 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002497static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498{
2499 unsigned int retval = itr_setting;
2500
2501 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002502 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503
2504 switch (itr_setting) {
2505 case lowest_latency:
2506 /* handle TSO and jumbo frames */
2507 if (bytes/packets > 8000)
2508 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002509 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002511 break;
2512 case low_latency: /* 50 usec aka 20000 ints/s */
2513 if (bytes > 10000) {
2514 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002515 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002516 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002517 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002519 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 } else if (bytes/packets > 2000) {
2522 retval = bulk_latency;
2523 } else if (packets <= 2 && bytes < 512) {
2524 retval = lowest_latency;
2525 }
2526 break;
2527 case bulk_latency: /* 250 usec aka 4000 ints/s */
2528 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002529 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002531 } else if (bytes < 6000) {
2532 retval = low_latency;
2533 }
2534 break;
2535 }
2536
Auke Kokbc7f75f2007-09-17 12:30:59 -07002537 return retval;
2538}
2539
2540static void e1000_set_itr(struct e1000_adapter *adapter)
2541{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002542 u16 current_itr;
2543 u32 new_itr = adapter->itr;
2544
2545 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2546 if (adapter->link_speed != SPEED_1000) {
2547 current_itr = 0;
2548 new_itr = 4000;
2549 goto set_itr_now;
2550 }
2551
Bruce Allan828bac82010-09-29 21:39:37 +00002552 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2553 new_itr = 0;
2554 goto set_itr_now;
2555 }
2556
Bruce Allan8bb62862013-01-16 08:46:49 +00002557 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2558 adapter->total_tx_packets,
2559 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2561 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2562 adapter->tx_itr = low_latency;
2563
Bruce Allan8bb62862013-01-16 08:46:49 +00002564 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2565 adapter->total_rx_packets,
2566 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002567 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2568 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2569 adapter->rx_itr = low_latency;
2570
2571 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2572
2573 switch (current_itr) {
2574 /* counts and packets in update_itr are dependent on these numbers */
2575 case lowest_latency:
2576 new_itr = 70000;
2577 break;
2578 case low_latency:
2579 new_itr = 20000; /* aka hwitr = ~200 */
2580 break;
2581 case bulk_latency:
2582 new_itr = 4000;
2583 break;
2584 default:
2585 break;
2586 }
2587
2588set_itr_now:
2589 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002590 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002591 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002592 * increasing
2593 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002594 new_itr = new_itr > adapter->itr ?
2595 min(adapter->itr + (new_itr >> 2), new_itr) :
2596 new_itr;
2597 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002598 adapter->rx_ring->itr_val = new_itr;
2599 if (adapter->msix_entries)
2600 adapter->rx_ring->set_itr = 1;
2601 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002602 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002603 }
2604}
2605
2606/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002607 * e1000e_write_itr - write the ITR value to the appropriate registers
2608 * @adapter: address of board private structure
2609 * @itr: new ITR value to program
2610 *
2611 * e1000e_write_itr determines if the adapter is in MSI-X mode
2612 * and, if so, writes the EITR registers with the ITR value.
2613 * Otherwise, it writes the ITR value into the ITR register.
2614 **/
2615void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2616{
2617 struct e1000_hw *hw = &adapter->hw;
2618 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2619
2620 if (adapter->msix_entries) {
2621 int vector;
2622
2623 for (vector = 0; vector < adapter->num_vectors; vector++)
2624 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2625 } else {
2626 ew32(ITR, new_itr);
2627 }
2628}
2629
2630/**
Bruce Allan4662e822008-08-26 18:37:06 -07002631 * e1000_alloc_queues - Allocate memory for all rings
2632 * @adapter: board private structure to initialize
2633 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002634static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002635{
Bruce Allan55aa6982011-12-16 00:45:45 +00002636 int size = sizeof(struct e1000_ring);
2637
2638 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002639 if (!adapter->tx_ring)
2640 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002641 adapter->tx_ring->count = adapter->tx_ring_count;
2642 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002643
Bruce Allan55aa6982011-12-16 00:45:45 +00002644 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002645 if (!adapter->rx_ring)
2646 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002647 adapter->rx_ring->count = adapter->rx_ring_count;
2648 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002649
2650 return 0;
2651err:
2652 e_err("Unable to allocate memory for queues\n");
2653 kfree(adapter->rx_ring);
2654 kfree(adapter->tx_ring);
2655 return -ENOMEM;
2656}
2657
2658/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002659 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002660 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002661 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002662 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002663static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002665 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2666 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002667 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002668 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002669 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670
Wang Chen4cf16532008-11-12 23:38:14 -08002671 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672
Bruce Allanc58c8a72012-03-20 03:48:19 +00002673 if (!adapter->msix_entries ||
2674 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2675 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002676
Bruce Allanc58c8a72012-03-20 03:48:19 +00002677 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678
Alexander Duyck12d04a32009-03-25 22:05:03 +00002679 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002680 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002681
Bruce Allanc58c8a72012-03-20 03:48:19 +00002682 /* If weight not fully consumed, exit the polling mode */
2683 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684 if (adapter->itr_setting & 3)
2685 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002686 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002687 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2688 if (adapter->msix_entries)
2689 ew32(IMS, adapter->rx_ring->ims_val);
2690 else
2691 e1000_irq_enable(adapter);
2692 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002693 }
2694
2695 return work_done;
2696}
2697
Jiri Pirko8e586132011-12-08 19:52:37 -05002698static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699{
2700 struct e1000_adapter *adapter = netdev_priv(netdev);
2701 struct e1000_hw *hw = &adapter->hw;
2702 u32 vfta, index;
2703
2704 /* don't update vlan cookie if already programmed */
2705 if ((adapter->hw.mng_cookie.status &
2706 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2707 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002708 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002709
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002711 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2712 index = (vid >> 5) & 0x7F;
2713 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2714 vfta |= (1 << (vid & 0x1F));
2715 hw->mac.ops.write_vfta(hw, index, vfta);
2716 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002717
2718 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002719
2720 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002721}
2722
Jiri Pirko8e586132011-12-08 19:52:37 -05002723static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002724{
2725 struct e1000_adapter *adapter = netdev_priv(netdev);
2726 struct e1000_hw *hw = &adapter->hw;
2727 u32 vfta, index;
2728
Auke Kokbc7f75f2007-09-17 12:30:59 -07002729 if ((adapter->hw.mng_cookie.status &
2730 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2731 (vid == adapter->mng_vlan_id)) {
2732 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002733 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002734 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 }
2736
2737 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002738 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2739 index = (vid >> 5) & 0x7F;
2740 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2741 vfta &= ~(1 << (vid & 0x1F));
2742 hw->mac.ops.write_vfta(hw, index, vfta);
2743 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002744
2745 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002746
2747 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002748}
2749
2750/**
2751 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2752 * @adapter: board private structure to initialize
2753 **/
2754static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2755{
2756 struct net_device *netdev = adapter->netdev;
2757 struct e1000_hw *hw = &adapter->hw;
2758 u32 rctl;
2759
2760 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2761 /* disable VLAN receive filtering */
2762 rctl = er32(RCTL);
2763 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2764 ew32(RCTL, rctl);
2765
2766 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2767 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2768 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2769 }
2770 }
2771}
2772
2773/**
2774 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2775 * @adapter: board private structure to initialize
2776 **/
2777static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2778{
2779 struct e1000_hw *hw = &adapter->hw;
2780 u32 rctl;
2781
2782 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2783 /* enable VLAN receive filtering */
2784 rctl = er32(RCTL);
2785 rctl |= E1000_RCTL_VFE;
2786 rctl &= ~E1000_RCTL_CFIEN;
2787 ew32(RCTL, rctl);
2788 }
2789}
2790
2791/**
2792 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2793 * @adapter: board private structure to initialize
2794 **/
2795static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2796{
2797 struct e1000_hw *hw = &adapter->hw;
2798 u32 ctrl;
2799
2800 /* disable VLAN tag insert/strip */
2801 ctrl = er32(CTRL);
2802 ctrl &= ~E1000_CTRL_VME;
2803 ew32(CTRL, ctrl);
2804}
2805
2806/**
2807 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2808 * @adapter: board private structure to initialize
2809 **/
2810static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2811{
2812 struct e1000_hw *hw = &adapter->hw;
2813 u32 ctrl;
2814
2815 /* enable VLAN tag insert/strip */
2816 ctrl = er32(CTRL);
2817 ctrl |= E1000_CTRL_VME;
2818 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819}
2820
2821static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2822{
2823 struct net_device *netdev = adapter->netdev;
2824 u16 vid = adapter->hw.mng_cookie.vlan_id;
2825 u16 old_vid = adapter->mng_vlan_id;
2826
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002827 if (adapter->hw.mng_cookie.status &
2828 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2829 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830 adapter->mng_vlan_id = vid;
2831 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002833 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2834 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835}
2836
2837static void e1000_restore_vlan(struct e1000_adapter *adapter)
2838{
2839 u16 vid;
2840
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002841 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002843 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845}
2846
Bruce Allancd791612010-05-10 14:59:51 +00002847static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848{
2849 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002850 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002851
2852 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2853 return;
2854
2855 manc = er32(MANC);
2856
Bruce Allane921eb12012-11-28 09:28:37 +00002857 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002858 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002859 * the packets will be handled on SMBUS
2860 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002861 manc |= E1000_MANC_EN_MNG2HOST;
2862 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002863
2864 switch (hw->mac.type) {
2865 default:
2866 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2867 break;
2868 case e1000_82574:
2869 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002870 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002871 * if so, enable it.
2872 */
2873 for (i = 0, j = 0; i < 8; i++) {
2874 mdef = er32(MDEF(i));
2875
2876 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002877 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002878 continue;
2879
2880 /* Enable this decision filter in MANC2H */
2881 if (mdef)
2882 manc2h |= (1 << i);
2883
2884 j |= mdef;
2885 }
2886
2887 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2888 break;
2889
2890 /* Create new decision filter in an empty filter */
2891 for (i = 0, j = 0; i < 8; i++)
2892 if (er32(MDEF(i)) == 0) {
2893 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2894 E1000_MDEF_PORT_664));
2895 manc2h |= (1 << 1);
2896 j++;
2897 break;
2898 }
2899
2900 if (!j)
2901 e_warn("Unable to create IPMI pass-through filter\n");
2902 break;
2903 }
2904
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 ew32(MANC2H, manc2h);
2906 ew32(MANC, manc);
2907}
2908
2909/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002910 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 * @adapter: board private structure
2912 *
2913 * Configure the Tx unit of the MAC after a reset.
2914 **/
2915static void e1000_configure_tx(struct e1000_adapter *adapter)
2916{
2917 struct e1000_hw *hw = &adapter->hw;
2918 struct e1000_ring *tx_ring = adapter->tx_ring;
2919 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002920 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002921
2922 /* Setup the HW Tx Head and Tail descriptor pointers */
2923 tdba = tx_ring->dma;
2924 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002925 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2926 ew32(TDBAH(0), (tdba >> 32));
2927 ew32(TDLEN(0), tdlen);
2928 ew32(TDH(0), 0);
2929 ew32(TDT(0), 0);
2930 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2931 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002932
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 /* Set the Tx Interrupt Delay register */
2934 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002935 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002936 ew32(TADV, adapter->tx_abs_int_delay);
2937
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002938 if (adapter->flags2 & FLAG2_DMA_BURST) {
2939 u32 txdctl = er32(TXDCTL(0));
2940 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2941 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002942 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002943 * hardware to use the bus more efficiently in bursts, depends
2944 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002945 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002946 * hthresh = 1 ==> prefetch when one or more available
2947 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2948 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002949 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002950 */
2951 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2952 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002953 }
Bruce Allan56032be2011-12-16 00:46:01 +00002954 /* erratum work around: set txdctl the same for both queues */
2955 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002956
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002958 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002959 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002960 * gigabit link later
2961 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962#define SPEED_MODE_BIT (1 << 21)
2963 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002964 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002965 }
2966
2967 /* errata: program both queues to unweighted RR */
2968 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002969 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002971 ew32(TARC(0), tarc);
2972 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002973 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002974 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 }
2976
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977 /* Setup Transmit Descriptor Settings for eop descriptor */
2978 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2979
2980 /* only set IDE if we are delaying interrupts using the timers */
2981 if (adapter->tx_int_delay)
2982 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2983
2984 /* enable Report Status bit */
2985 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2986
Bruce Allan57cde762012-02-22 09:02:58 +00002987 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988}
2989
2990/**
2991 * e1000_setup_rctl - configure the receive control registers
2992 * @adapter: Board private structure
2993 **/
2994#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2995 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2996static void e1000_setup_rctl(struct e1000_adapter *adapter)
2997{
2998 struct e1000_hw *hw = &adapter->hw;
2999 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003000 u32 pages = 0;
3001
Bruce Allan2fbe4522012-04-19 03:21:47 +00003002 /* Workaround Si errata on PCHx - configure jumbo frame flow */
3003 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00003004 s32 ret_val;
3005
3006 if (adapter->netdev->mtu > ETH_DATA_LEN)
3007 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3008 else
3009 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00003010
3011 if (ret_val)
3012 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003013 }
3014
Auke Kokbc7f75f2007-09-17 12:30:59 -07003015 /* Program MC offset vector base */
3016 rctl = er32(RCTL);
3017 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3018 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3019 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3020 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3021
3022 /* Do not Store bad packets */
3023 rctl &= ~E1000_RCTL_SBP;
3024
3025 /* Enable Long Packet receive */
3026 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3027 rctl &= ~E1000_RCTL_LPE;
3028 else
3029 rctl |= E1000_RCTL_LPE;
3030
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003031 /* Some systems expect that the CRC is included in SMBUS traffic. The
3032 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3033 * host memory when this is enabled
3034 */
3035 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3036 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003037
Bruce Allana4f58f52009-06-02 11:29:18 +00003038 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3039 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3040 u16 phy_data;
3041
3042 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3043 phy_data &= 0xfff8;
3044 phy_data |= (1 << 2);
3045 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3046
3047 e1e_rphy(hw, 22, &phy_data);
3048 phy_data &= 0x0fff;
3049 phy_data |= (1 << 14);
3050 e1e_wphy(hw, 0x10, 0x2823);
3051 e1e_wphy(hw, 0x11, 0x0003);
3052 e1e_wphy(hw, 22, phy_data);
3053 }
3054
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055 /* Setup buffer sizes */
3056 rctl &= ~E1000_RCTL_SZ_4096;
3057 rctl |= E1000_RCTL_BSEX;
3058 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003059 case 2048:
3060 default:
3061 rctl |= E1000_RCTL_SZ_2048;
3062 rctl &= ~E1000_RCTL_BSEX;
3063 break;
3064 case 4096:
3065 rctl |= E1000_RCTL_SZ_4096;
3066 break;
3067 case 8192:
3068 rctl |= E1000_RCTL_SZ_8192;
3069 break;
3070 case 16384:
3071 rctl |= E1000_RCTL_SZ_16384;
3072 break;
3073 }
3074
Bruce Allan5f450212011-07-22 06:21:46 +00003075 /* Enable Extended Status in all Receive Descriptors */
3076 rfctl = er32(RFCTL);
3077 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003078 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003079
Bruce Allane921eb12012-11-28 09:28:37 +00003080 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 * header is placed in skb->data and the packet data is
3082 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3083 * In the case of a non-split, skb->data is linearly filled,
3084 * followed by the page buffers. Therefore, skb->data is
3085 * sized to hold the largest protocol header.
3086 *
3087 * allocations using alloc_page take too long for regular MTU
3088 * so only enable packet split for jumbo frames
3089 *
3090 * Using pages when the page size is greater than 16k wastes
3091 * a lot of memory, since we allocate 3 pages at all times
3092 * per packet.
3093 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003095 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003097 else
3098 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099
3100 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003101 u32 psrctl = 0;
3102
Auke Kok140a7482007-10-25 13:57:58 -07003103 /* Enable Packet split descriptors */
3104 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105
3106 psrctl |= adapter->rx_ps_bsize0 >>
3107 E1000_PSRCTL_BSIZE0_SHIFT;
3108
3109 switch (adapter->rx_ps_pages) {
3110 case 3:
3111 psrctl |= PAGE_SIZE <<
3112 E1000_PSRCTL_BSIZE3_SHIFT;
3113 case 2:
3114 psrctl |= PAGE_SIZE <<
3115 E1000_PSRCTL_BSIZE2_SHIFT;
3116 case 1:
3117 psrctl |= PAGE_SIZE >>
3118 E1000_PSRCTL_BSIZE1_SHIFT;
3119 break;
3120 }
3121
3122 ew32(PSRCTL, psrctl);
3123 }
3124
Ben Greearcf955e62012-02-11 15:39:51 +00003125 /* This is useful for sniffing bad packets. */
3126 if (adapter->netdev->features & NETIF_F_RXALL) {
3127 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003128 * in e1000e_set_rx_mode
3129 */
Ben Greearcf955e62012-02-11 15:39:51 +00003130 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3131 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3132 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3133
3134 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3135 E1000_RCTL_DPF | /* Allow filtered pause */
3136 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3137 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3138 * and that breaks VLANs.
3139 */
3140 }
3141
Auke Kokbc7f75f2007-09-17 12:30:59 -07003142 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003143 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003144 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003145}
3146
3147/**
3148 * e1000_configure_rx - Configure Receive Unit after Reset
3149 * @adapter: board private structure
3150 *
3151 * Configure the Rx unit of the MAC after a reset.
3152 **/
3153static void e1000_configure_rx(struct e1000_adapter *adapter)
3154{
3155 struct e1000_hw *hw = &adapter->hw;
3156 struct e1000_ring *rx_ring = adapter->rx_ring;
3157 u64 rdba;
3158 u32 rdlen, rctl, rxcsum, ctrl_ext;
3159
3160 if (adapter->rx_ps_pages) {
3161 /* this is a 32 byte descriptor */
3162 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003163 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164 adapter->clean_rx = e1000_clean_rx_irq_ps;
3165 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003166 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003167 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003168 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3169 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003170 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003171 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003172 adapter->clean_rx = e1000_clean_rx_irq;
3173 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3174 }
3175
3176 /* disable receives while setting up the descriptors */
3177 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003178 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3179 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003181 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003182
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003183 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003184 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003185 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003186 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003187 * granularity = 01
3188 * wthresh = 04,
3189 * hthresh = 04,
3190 * pthresh = 0x20
3191 */
3192 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3193 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3194
Bruce Allane921eb12012-11-28 09:28:37 +00003195 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003196 * the value was not set by the user via module options
3197 */
3198 if (adapter->rx_int_delay == DEFAULT_RDTR)
3199 adapter->rx_int_delay = BURST_RDTR;
3200 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3201 adapter->rx_abs_int_delay = BURST_RADV;
3202 }
3203
Auke Kokbc7f75f2007-09-17 12:30:59 -07003204 /* set the Receive Delay Timer Register */
3205 ew32(RDTR, adapter->rx_int_delay);
3206
3207 /* irq moderation */
3208 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003209 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003210 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003211
3212 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 /* Auto-Mask interrupts upon ICR access */
3214 ctrl_ext |= E1000_CTRL_EXT_IAME;
3215 ew32(IAM, 0xffffffff);
3216 ew32(CTRL_EXT, ctrl_ext);
3217 e1e_flush();
3218
Bruce Allane921eb12012-11-28 09:28:37 +00003219 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003220 * the Base and Length of the Rx Descriptor Ring
3221 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003222 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003223 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3224 ew32(RDBAH(0), (rdba >> 32));
3225 ew32(RDLEN(0), rdlen);
3226 ew32(RDH(0), 0);
3227 ew32(RDT(0), 0);
3228 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3229 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003230
3231 /* Enable Receive Checksum Offload for TCP and UDP */
3232 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003233 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003235 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237 ew32(RXCSUM, rxcsum);
3238
Bruce Allan3e35d992013-01-12 07:25:22 +00003239 /* With jumbo frames, excessive C-state transition latencies result
3240 * in dropped transactions.
3241 */
3242 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3243 u32 lat =
3244 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3245 adapter->max_frame_size) * 8 / 1000;
3246
3247 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003248 u32 rxdctl = er32(RXDCTL(0));
3249 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003250 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003251
3252 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3253 } else {
3254 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3255 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003256 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257
3258 /* Enable Receives */
3259 ew32(RCTL, rctl);
3260}
3261
3262/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003263 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264 * @netdev: network interface device structure
3265 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003266 * Writes multicast address list to the MTA hash table.
3267 * Returns: -ENOMEM on failure
3268 * 0 on no addresses written
3269 * X on writing X addresses to MTA
3270 */
3271static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272{
3273 struct e1000_adapter *adapter = netdev_priv(netdev);
3274 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003275 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003276 u8 *mta_list;
3277 int i;
3278
3279 if (netdev_mc_empty(netdev)) {
3280 /* nothing to program, so clear mc list */
3281 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3282 return 0;
3283 }
3284
3285 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3286 if (!mta_list)
3287 return -ENOMEM;
3288
3289 /* update_mc_addr_list expects a packed array of only addresses. */
3290 i = 0;
3291 netdev_for_each_mc_addr(ha, netdev)
3292 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3293
3294 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3295 kfree(mta_list);
3296
3297 return netdev_mc_count(netdev);
3298}
3299
3300/**
3301 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3302 * @netdev: network interface device structure
3303 *
3304 * Writes unicast address list to the RAR table.
3305 * Returns: -ENOMEM on failure/insufficient address space
3306 * 0 on no addresses written
3307 * X on writing X addresses to the RAR table
3308 **/
3309static int e1000e_write_uc_addr_list(struct net_device *netdev)
3310{
3311 struct e1000_adapter *adapter = netdev_priv(netdev);
3312 struct e1000_hw *hw = &adapter->hw;
3313 unsigned int rar_entries = hw->mac.rar_entry_count;
3314 int count = 0;
3315
3316 /* save a rar entry for our hardware address */
3317 rar_entries--;
3318
3319 /* save a rar entry for the LAA workaround */
3320 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3321 rar_entries--;
3322
3323 /* return ENOMEM indicating insufficient memory for addresses */
3324 if (netdev_uc_count(netdev) > rar_entries)
3325 return -ENOMEM;
3326
3327 if (!netdev_uc_empty(netdev) && rar_entries) {
3328 struct netdev_hw_addr *ha;
3329
Bruce Allane921eb12012-11-28 09:28:37 +00003330 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003331 * combining
3332 */
3333 netdev_for_each_uc_addr(ha, netdev) {
3334 if (!rar_entries)
3335 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003336 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003337 count++;
3338 }
3339 }
3340
3341 /* zero out the remaining RAR entries not used above */
3342 for (; rar_entries > 0; rar_entries--) {
3343 ew32(RAH(rar_entries), 0);
3344 ew32(RAL(rar_entries), 0);
3345 }
3346 e1e_flush();
3347
3348 return count;
3349}
3350
3351/**
3352 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3353 * @netdev: network interface device structure
3354 *
3355 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3356 * address list or the network interface flags are updated. This routine is
3357 * responsible for configuring the hardware for proper unicast, multicast,
3358 * promiscuous mode, and all-multi behavior.
3359 **/
3360static void e1000e_set_rx_mode(struct net_device *netdev)
3361{
3362 struct e1000_adapter *adapter = netdev_priv(netdev);
3363 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003364 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365
3366 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 rctl = er32(RCTL);
3368
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003369 /* clear the affected bits */
3370 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3371
Auke Kokbc7f75f2007-09-17 12:30:59 -07003372 if (netdev->flags & IFF_PROMISC) {
3373 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003374 /* Do not hardware filter VLANs in promisc mode */
3375 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003377 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003378
Patrick McHardy746b9f02008-07-16 20:15:45 -07003379 if (netdev->flags & IFF_ALLMULTI) {
3380 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003381 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003382 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003383 * then we should just turn on promiscuous mode so
3384 * that we can at least receive multicast traffic
3385 */
3386 count = e1000e_write_mc_addr_list(netdev);
3387 if (count < 0)
3388 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003389 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003390 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003391 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003392 * sufficient space to store all the addresses then enable
3393 * unicast promiscuous mode
3394 */
3395 count = e1000e_write_uc_addr_list(netdev);
3396 if (count < 0)
3397 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003398 }
3399
3400 ew32(RCTL, rctl);
3401
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003402 if (netdev->features & NETIF_F_HW_VLAN_RX)
3403 e1000e_vlan_strip_enable(adapter);
3404 else
3405 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406}
3407
Bruce Allan70495a52012-01-11 01:26:50 +00003408static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3409{
3410 struct e1000_hw *hw = &adapter->hw;
3411 u32 mrqc, rxcsum;
3412 int i;
3413 static const u32 rsskey[10] = {
3414 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3415 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3416 };
3417
3418 /* Fill out hash function seed */
3419 for (i = 0; i < 10; i++)
3420 ew32(RSSRK(i), rsskey[i]);
3421
3422 /* Direct all traffic to queue 0 */
3423 for (i = 0; i < 32; i++)
3424 ew32(RETA(i), 0);
3425
Bruce Allane921eb12012-11-28 09:28:37 +00003426 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003427 * descriptor on writeback.
3428 */
3429 rxcsum = er32(RXCSUM);
3430 rxcsum |= E1000_RXCSUM_PCSD;
3431
3432 ew32(RXCSUM, rxcsum);
3433
3434 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3435 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3436 E1000_MRQC_RSS_FIELD_IPV6 |
3437 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3438 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3439
3440 ew32(MRQC, mrqc);
3441}
3442
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003444 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3445 * @adapter: board private structure
3446 * @timinca: pointer to returned time increment attributes
3447 *
3448 * Get attributes for incrementing the System Time Register SYSTIML/H at
3449 * the default base frequency, and set the cyclecounter shift value.
3450 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003451s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003452{
3453 struct e1000_hw *hw = &adapter->hw;
3454 u32 incvalue, incperiod, shift;
3455
3456 /* Make sure clock is enabled on I217 before checking the frequency */
3457 if ((hw->mac.type == e1000_pch_lpt) &&
3458 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3459 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3460 u32 fextnvm7 = er32(FEXTNVM7);
3461
3462 if (!(fextnvm7 & (1 << 0))) {
3463 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3464 e1e_flush();
3465 }
3466 }
3467
3468 switch (hw->mac.type) {
3469 case e1000_pch2lan:
3470 case e1000_pch_lpt:
3471 /* On I217, the clock frequency is 25MHz or 96MHz as
3472 * indicated by the System Clock Frequency Indication
3473 */
3474 if ((hw->mac.type != e1000_pch_lpt) ||
3475 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3476 /* Stable 96MHz frequency */
3477 incperiod = INCPERIOD_96MHz;
3478 incvalue = INCVALUE_96MHz;
3479 shift = INCVALUE_SHIFT_96MHz;
3480 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3481 break;
3482 }
3483 /* fall-through */
3484 case e1000_82574:
3485 case e1000_82583:
3486 /* Stable 25MHz frequency */
3487 incperiod = INCPERIOD_25MHz;
3488 incvalue = INCVALUE_25MHz;
3489 shift = INCVALUE_SHIFT_25MHz;
3490 adapter->cc.shift = shift;
3491 break;
3492 default:
3493 return -EINVAL;
3494 }
3495
3496 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3497 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3498
3499 return 0;
3500}
3501
3502/**
3503 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3504 * @adapter: board private structure
3505 *
3506 * Outgoing time stamping can be enabled and disabled. Play nice and
3507 * disable it when requested, although it shouldn't cause any overhead
3508 * when no packet needs it. At most one packet in the queue may be
3509 * marked for time stamping, otherwise it would be impossible to tell
3510 * for sure to which packet the hardware time stamp belongs.
3511 *
3512 * Incoming time stamping has to be configured via the hardware filters.
3513 * Not all combinations are supported, in particular event type has to be
3514 * specified. Matching the kind of event packet is not supported, with the
3515 * exception of "all V2 events regardless of level 2 or 4".
3516 **/
3517static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3518{
3519 struct e1000_hw *hw = &adapter->hw;
3520 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3521 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3522 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003523 u32 rxmtrl = 0;
3524 u16 rxudp = 0;
3525 bool is_l4 = false;
3526 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003527 u32 regval;
3528 s32 ret_val;
3529
3530 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3531 return -EINVAL;
3532
3533 /* flags reserved for future extensions - must be zero */
3534 if (config->flags)
3535 return -EINVAL;
3536
3537 switch (config->tx_type) {
3538 case HWTSTAMP_TX_OFF:
3539 tsync_tx_ctl = 0;
3540 break;
3541 case HWTSTAMP_TX_ON:
3542 break;
3543 default:
3544 return -ERANGE;
3545 }
3546
3547 switch (config->rx_filter) {
3548 case HWTSTAMP_FILTER_NONE:
3549 tsync_rx_ctl = 0;
3550 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003551 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3552 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3553 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3554 is_l4 = true;
3555 break;
3556 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3557 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3558 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3559 is_l4 = true;
3560 break;
3561 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3562 /* Also time stamps V2 L2 Path Delay Request/Response */
3563 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3564 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3565 is_l2 = true;
3566 break;
3567 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3568 /* Also time stamps V2 L2 Path Delay Request/Response. */
3569 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3570 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3571 is_l2 = true;
3572 break;
3573 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3574 /* Hardware cannot filter just V2 L4 Sync messages;
3575 * fall-through to V2 (both L2 and L4) Sync.
3576 */
3577 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3578 /* Also time stamps V2 Path Delay Request/Response. */
3579 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3580 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3581 is_l2 = true;
3582 is_l4 = true;
3583 break;
3584 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3585 /* Hardware cannot filter just V2 L4 Delay Request messages;
3586 * fall-through to V2 (both L2 and L4) Delay Request.
3587 */
3588 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3589 /* Also time stamps V2 Path Delay Request/Response. */
3590 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3591 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3592 is_l2 = true;
3593 is_l4 = true;
3594 break;
3595 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3596 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3597 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3598 * fall-through to all V2 (both L2 and L4) Events.
3599 */
3600 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3601 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3602 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3603 is_l2 = true;
3604 is_l4 = true;
3605 break;
3606 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3607 /* For V1, the hardware can only filter Sync messages or
3608 * Delay Request messages but not both so fall-through to
3609 * time stamp all packets.
3610 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003611 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003612 is_l2 = true;
3613 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003614 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3615 config->rx_filter = HWTSTAMP_FILTER_ALL;
3616 break;
3617 default:
3618 return -ERANGE;
3619 }
3620
3621 /* enable/disable Tx h/w time stamping */
3622 regval = er32(TSYNCTXCTL);
3623 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3624 regval |= tsync_tx_ctl;
3625 ew32(TSYNCTXCTL, regval);
3626 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3627 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3628 e_err("Timesync Tx Control register not set as expected\n");
3629 return -EAGAIN;
3630 }
3631
3632 /* enable/disable Rx h/w time stamping */
3633 regval = er32(TSYNCRXCTL);
3634 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3635 regval |= tsync_rx_ctl;
3636 ew32(TSYNCRXCTL, regval);
3637 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3638 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3639 (regval & (E1000_TSYNCRXCTL_ENABLED |
3640 E1000_TSYNCRXCTL_TYPE_MASK))) {
3641 e_err("Timesync Rx Control register not set as expected\n");
3642 return -EAGAIN;
3643 }
3644
Bruce Alland89777b2013-01-19 01:09:58 +00003645 /* L2: define ethertype filter for time stamped packets */
3646 if (is_l2)
3647 rxmtrl |= ETH_P_1588;
3648
3649 /* define which PTP packets get time stamped */
3650 ew32(RXMTRL, rxmtrl);
3651
3652 /* Filter by destination port */
3653 if (is_l4) {
3654 rxudp = PTP_EV_PORT;
3655 cpu_to_be16s(&rxudp);
3656 }
3657 ew32(RXUDP, rxudp);
3658
3659 e1e_flush();
3660
Bruce Allanb67e1912012-12-27 08:32:33 +00003661 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003662 er32(RXSTMPH);
3663 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003664
3665 /* Get and set the System Time Register SYSTIM base frequency */
3666 ret_val = e1000e_get_base_timinca(adapter, &regval);
3667 if (ret_val)
3668 return ret_val;
3669 ew32(TIMINCA, regval);
3670
3671 /* reset the ns time counter */
3672 timecounter_init(&adapter->tc, &adapter->cc,
3673 ktime_to_ns(ktime_get_real()));
3674
3675 return 0;
3676}
3677
3678/**
Bruce Allanad680762008-03-28 09:15:03 -07003679 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680 * @adapter: private board structure
3681 **/
3682static void e1000_configure(struct e1000_adapter *adapter)
3683{
Bruce Allan55aa6982011-12-16 00:45:45 +00003684 struct e1000_ring *rx_ring = adapter->rx_ring;
3685
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003686 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687
3688 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003689 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003690
3691 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003692
3693 if (adapter->netdev->features & NETIF_F_RXHASH)
3694 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003695 e1000_setup_rctl(adapter);
3696 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003697 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003698}
3699
3700/**
3701 * e1000e_power_up_phy - restore link in case the phy was powered down
3702 * @adapter: address of board private structure
3703 *
3704 * The phy may be powered down to save power and turn off link when the
3705 * driver is unloaded and wake on lan is not enabled (among others)
3706 * *** this routine MUST be followed by a call to e1000e_reset ***
3707 **/
3708void e1000e_power_up_phy(struct e1000_adapter *adapter)
3709{
Bruce Allan17f208d2009-12-01 15:47:22 +00003710 if (adapter->hw.phy.ops.power_up)
3711 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712
3713 adapter->hw.mac.ops.setup_link(&adapter->hw);
3714}
3715
3716/**
3717 * e1000_power_down_phy - Power down the PHY
3718 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003719 * Power down the PHY so no link is implied when interface is down.
3720 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003721 */
3722static void e1000_power_down_phy(struct e1000_adapter *adapter)
3723{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003724 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003725 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726 return;
3727
Bruce Allan17f208d2009-12-01 15:47:22 +00003728 if (adapter->hw.phy.ops.power_down)
3729 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730}
3731
3732/**
3733 * e1000e_reset - bring the hardware into a known good state
3734 *
3735 * This function boots the hardware and enables some settings that
3736 * require a configuration cycle of the hardware - those cannot be
3737 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003738 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 */
3740void e1000e_reset(struct e1000_adapter *adapter)
3741{
3742 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003743 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 struct e1000_hw *hw = &adapter->hw;
3745 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003746 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003747 u16 hwm;
3748
Bruce Allanad680762008-03-28 09:15:03 -07003749 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003750 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003751
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003752 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003753 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003754 * large enough to accommodate two full transmit packets,
3755 * rounded up to the next 1KB and expressed in KB. Likewise,
3756 * the Rx FIFO should be large enough to accommodate at least
3757 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003758 * expressed in KB.
3759 */
Auke Kokdf762462007-10-25 13:57:53 -07003760 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003761 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003762 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003764 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003765 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003766 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003767 */
3768 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769 sizeof(struct e1000_tx_desc) -
3770 ETH_FCS_LEN) * 2;
3771 min_tx_space = ALIGN(min_tx_space, 1024);
3772 min_tx_space >>= 10;
3773 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003774 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775 min_rx_space = ALIGN(min_rx_space, 1024);
3776 min_rx_space >>= 10;
3777
Bruce Allane921eb12012-11-28 09:28:37 +00003778 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003780 * allocation, take space away from current Rx allocation
3781 */
Auke Kokdf762462007-10-25 13:57:53 -07003782 if ((tx_space < min_tx_space) &&
3783 ((min_tx_space - tx_space) < pba)) {
3784 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785
Bruce Allane921eb12012-11-28 09:28:37 +00003786 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003787 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003788 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003789 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003790 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791 }
Auke Kokdf762462007-10-25 13:57:53 -07003792
3793 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 }
3795
Bruce Allane921eb12012-11-28 09:28:37 +00003796 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003797 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003798 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003799 * (or the size used for early receive) above it in the Rx FIFO.
3800 * Set it to the lower of:
3801 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003802 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003803 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003804 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3805 fc->pause_time = 0xFFFF;
3806 else
3807 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003808 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003809 fc->current_mode = fc->requested_mode;
3810
3811 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003812 case e1000_ich9lan:
3813 case e1000_ich10lan:
3814 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3815 pba = 14;
3816 ew32(PBA, pba);
3817 fc->high_water = 0x2800;
3818 fc->low_water = fc->high_water - 8;
3819 break;
3820 }
3821 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003822 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003823 hwm = min(((pba << 10) * 9 / 10),
3824 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003825
3826 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3827 fc->low_water = fc->high_water - 8;
3828 break;
3829 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003830 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003831 * loads. If hangs persist, try disabling Tx flow control.
3832 */
3833 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3834 fc->high_water = 0x3500;
3835 fc->low_water = 0x1500;
3836 } else {
3837 fc->high_water = 0x5000;
3838 fc->low_water = 0x3000;
3839 }
Bruce Allana3055952010-05-10 15:02:12 +00003840 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003841 break;
3842 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003843 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003844 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003845
3846 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3847 fc->high_water = 0x05C20;
3848 fc->low_water = 0x05048;
3849 fc->pause_time = 0x0650;
3850 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003851 }
Bruce Allan347b5202012-12-08 00:35:35 +00003852
3853 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3854 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003855 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003856 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003857
Bruce Allane921eb12012-11-28 09:28:37 +00003858 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003859 * maximum size per Tx descriptor limited only to the transmit
3860 * allocation of the packet buffer minus 96 bytes with an upper
3861 * limit of 24KB due to receive synchronization limitations.
3862 */
3863 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3864 24 << 10);
3865
Bruce Allane921eb12012-11-28 09:28:37 +00003866 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003867 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003868 */
3869 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003870 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003871 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3872 dev_info(&adapter->pdev->dev,
3873 "Interrupt Throttle Rate turned off\n");
3874 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003875 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003876 }
3877 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3878 dev_info(&adapter->pdev->dev,
3879 "Interrupt Throttle Rate turned on\n");
3880 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3881 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003882 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003883 }
3884 }
3885
Auke Kokbc7f75f2007-09-17 12:30:59 -07003886 /* Allow time for pending master requests to run */
3887 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003888
Bruce Allane921eb12012-11-28 09:28:37 +00003889 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003890 * that the network interface is in control
3891 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003892 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003893 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003894
Auke Kokbc7f75f2007-09-17 12:30:59 -07003895 ew32(WUC, 0);
3896
3897 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003898 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003899
3900 e1000_update_mng_vlan(adapter);
3901
3902 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3903 ew32(VET, ETH_P_8021Q);
3904
3905 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003906
Bruce Allanb67e1912012-12-27 08:32:33 +00003907 /* initialize systim and reset the ns time counter */
3908 e1000e_config_hwtstamp(adapter);
3909
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003910 if (!netif_running(adapter->netdev) &&
3911 !test_bit(__E1000_TESTING, &adapter->state)) {
3912 e1000_power_down_phy(adapter);
3913 return;
3914 }
3915
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916 e1000_get_phy_info(hw);
3917
Bruce Allan918d7192009-06-02 11:28:20 +00003918 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3919 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003920 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003921 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003923 * different we would do if it failed
3924 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003925 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3926 phy_data &= ~IGP02E1000_PM_SPD;
3927 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3928 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003929}
3930
3931int e1000e_up(struct e1000_adapter *adapter)
3932{
3933 struct e1000_hw *hw = &adapter->hw;
3934
3935 /* hardware has been reset, we need to reload some things */
3936 e1000_configure(adapter);
3937
3938 clear_bit(__E1000_DOWN, &adapter->state);
3939
Bruce Allan4662e822008-08-26 18:37:06 -07003940 if (adapter->msix_entries)
3941 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942 e1000_irq_enable(adapter);
3943
Bruce Allan400484f2011-05-13 07:20:03 +00003944 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003945
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003947 if (adapter->msix_entries)
3948 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3949 else
3950 ew32(ICS, E1000_ICS_LSC);
3951
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 return 0;
3953}
3954
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003955static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3956{
3957 struct e1000_hw *hw = &adapter->hw;
3958
3959 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3960 return;
3961
3962 /* flush pending descriptor writebacks to memory */
3963 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3964 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3965
3966 /* execute the writes immediately */
3967 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003968
Bruce Allane921eb12012-11-28 09:28:37 +00003969 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003970 * write is successful
3971 */
3972 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3973 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3974
3975 /* execute the writes immediately */
3976 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003977}
3978
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003979static void e1000e_update_stats(struct e1000_adapter *adapter);
3980
Auke Kokbc7f75f2007-09-17 12:30:59 -07003981void e1000e_down(struct e1000_adapter *adapter)
3982{
3983 struct net_device *netdev = adapter->netdev;
3984 struct e1000_hw *hw = &adapter->hw;
3985 u32 tctl, rctl;
3986
Bruce Allane921eb12012-11-28 09:28:37 +00003987 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003988 * reschedule our watchdog timer
3989 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 set_bit(__E1000_DOWN, &adapter->state);
3991
3992 /* disable receives in the hardware */
3993 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003994 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3995 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 /* flush and sleep below */
3997
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003998 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999
4000 /* disable transmits in the hardware */
4001 tctl = er32(TCTL);
4002 tctl &= ~E1000_TCTL_EN;
4003 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004004
Auke Kokbc7f75f2007-09-17 12:30:59 -07004005 /* flush both disables and wait for them to finish */
4006 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004007 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 e1000_irq_disable(adapter);
4010
4011 del_timer_sync(&adapter->watchdog_timer);
4012 del_timer_sync(&adapter->phy_info_timer);
4013
Auke Kokbc7f75f2007-09-17 12:30:59 -07004014 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004015
4016 spin_lock(&adapter->stats64_lock);
4017 e1000e_update_stats(adapter);
4018 spin_unlock(&adapter->stats64_lock);
4019
Bruce Allan400484f2011-05-13 07:20:03 +00004020 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004021 e1000_clean_tx_ring(adapter->tx_ring);
4022 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004023
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 adapter->link_speed = 0;
4025 adapter->link_duplex = 0;
4026
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004027 if (!pci_channel_offline(adapter->pdev))
4028 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004029
Bruce Allane921eb12012-11-28 09:28:37 +00004030 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004031 * pci_disable_device here.
4032 */
4033}
4034
4035void e1000e_reinit_locked(struct e1000_adapter *adapter)
4036{
4037 might_sleep();
4038 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004039 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040 e1000e_down(adapter);
4041 e1000e_up(adapter);
4042 clear_bit(__E1000_RESETTING, &adapter->state);
4043}
4044
4045/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004046 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4047 * @cc: cyclecounter structure
4048 **/
4049static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4050{
4051 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4052 cc);
4053 struct e1000_hw *hw = &adapter->hw;
4054 cycle_t systim;
4055
4056 /* latch SYSTIMH on read of SYSTIML */
4057 systim = (cycle_t)er32(SYSTIML);
4058 systim |= (cycle_t)er32(SYSTIMH) << 32;
4059
4060 return systim;
4061}
4062
4063/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4065 * @adapter: board private structure to initialize
4066 *
4067 * e1000_sw_init initializes the Adapter private data structure.
4068 * Fields are initialized based on PCI device information and
4069 * OS network device settings (MTU size).
4070 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004071static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004073 struct net_device *netdev = adapter->netdev;
4074
4075 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4076 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004077 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4078 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004079 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4080 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004082 spin_lock_init(&adapter->stats64_lock);
4083
Bruce Allan4662e822008-08-26 18:37:06 -07004084 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085
Bruce Allan4662e822008-08-26 18:37:06 -07004086 if (e1000_alloc_queues(adapter))
4087 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088
Bruce Allanb67e1912012-12-27 08:32:33 +00004089 /* Setup hardware time stamping cyclecounter */
4090 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4091 adapter->cc.read = e1000e_cyclecounter_read;
4092 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4093 adapter->cc.mult = 1;
4094 /* cc.shift set in e1000e_get_base_tininca() */
4095
4096 spin_lock_init(&adapter->systim_lock);
4097 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4098 }
4099
Auke Kokbc7f75f2007-09-17 12:30:59 -07004100 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004101 e1000_irq_disable(adapter);
4102
Auke Kokbc7f75f2007-09-17 12:30:59 -07004103 set_bit(__E1000_DOWN, &adapter->state);
4104 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004105}
4106
4107/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004108 * e1000_intr_msi_test - Interrupt Handler
4109 * @irq: interrupt number
4110 * @data: pointer to a network interface device structure
4111 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004112static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004113{
4114 struct net_device *netdev = data;
4115 struct e1000_adapter *adapter = netdev_priv(netdev);
4116 struct e1000_hw *hw = &adapter->hw;
4117 u32 icr = er32(ICR);
4118
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004119 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004120 if (icr & E1000_ICR_RXSEQ) {
4121 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004122 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004123 * interrupt is handled.
4124 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004125 wmb();
4126 }
4127
4128 return IRQ_HANDLED;
4129}
4130
4131/**
4132 * e1000_test_msi_interrupt - Returns 0 for successful test
4133 * @adapter: board private struct
4134 *
4135 * code flow taken from tg3.c
4136 **/
4137static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4138{
4139 struct net_device *netdev = adapter->netdev;
4140 struct e1000_hw *hw = &adapter->hw;
4141 int err;
4142
4143 /* poll_enable hasn't been called yet, so don't need disable */
4144 /* clear any pending events */
4145 er32(ICR);
4146
4147 /* free the real vector and request a test handler */
4148 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004149 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004150
4151 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004152 * MSI irq handler will unset this flag
4153 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004154 adapter->flags |= FLAG_MSI_TEST_FAILED;
4155
4156 err = pci_enable_msi(adapter->pdev);
4157 if (err)
4158 goto msi_test_failed;
4159
Joe Perchesa0607fd2009-11-18 23:29:17 -08004160 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004161 netdev->name, netdev);
4162 if (err) {
4163 pci_disable_msi(adapter->pdev);
4164 goto msi_test_failed;
4165 }
4166
Bruce Allane921eb12012-11-28 09:28:37 +00004167 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004168 * interrupt.
4169 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004170 wmb();
4171
4172 e1000_irq_enable(adapter);
4173
4174 /* fire an unusual interrupt on the test handler */
4175 ew32(ICS, E1000_ICS_RXSEQ);
4176 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004177 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004178
4179 e1000_irq_disable(adapter);
4180
Bruce Allanbc763292012-08-17 06:18:07 +00004181 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004182
4183 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004184 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004185 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004186 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004187 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004188 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004189
4190 free_irq(adapter->pdev->irq, netdev);
4191 pci_disable_msi(adapter->pdev);
4192
Bruce Allanf8d59f72008-08-08 18:36:11 -07004193msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004194 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004195 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004196}
4197
4198/**
4199 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4200 * @adapter: board private struct
4201 *
4202 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4203 **/
4204static int e1000_test_msi(struct e1000_adapter *adapter)
4205{
4206 int err;
4207 u16 pci_cmd;
4208
4209 if (!(adapter->flags & FLAG_MSI_ENABLED))
4210 return 0;
4211
4212 /* disable SERR in case the MSI write causes a master abort */
4213 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004214 if (pci_cmd & PCI_COMMAND_SERR)
4215 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4216 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004217
4218 err = e1000_test_msi_interrupt(adapter);
4219
Dean Nelson36f24072010-06-29 18:12:05 +00004220 /* re-enable SERR */
4221 if (pci_cmd & PCI_COMMAND_SERR) {
4222 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4223 pci_cmd |= PCI_COMMAND_SERR;
4224 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4225 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004226
Bruce Allanf8d59f72008-08-08 18:36:11 -07004227 return err;
4228}
4229
4230/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231 * e1000_open - Called when a network interface is made active
4232 * @netdev: network interface device structure
4233 *
4234 * Returns 0 on success, negative value on failure
4235 *
4236 * The open entry point is called when a network interface is made
4237 * active by the system (IFF_UP). At this point all resources needed
4238 * for transmit and receive operations are allocated, the interrupt
4239 * handler is registered with the OS, the watchdog timer is started,
4240 * and the stack is notified that the interface is ready.
4241 **/
4242static int e1000_open(struct net_device *netdev)
4243{
4244 struct e1000_adapter *adapter = netdev_priv(netdev);
4245 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004246 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004247 int err;
4248
4249 /* disallow open during test */
4250 if (test_bit(__E1000_TESTING, &adapter->state))
4251 return -EBUSY;
4252
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004253 pm_runtime_get_sync(&pdev->dev);
4254
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004255 netif_carrier_off(netdev);
4256
Auke Kokbc7f75f2007-09-17 12:30:59 -07004257 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004258 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 if (err)
4260 goto err_setup_tx;
4261
4262 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004263 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 if (err)
4265 goto err_setup_rx;
4266
Bruce Allane921eb12012-11-28 09:28:37 +00004267 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004268 * interface is now open and reset the part to a known state.
4269 */
4270 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004271 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004272 e1000e_reset(adapter);
4273 }
4274
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 e1000e_power_up_phy(adapter);
4276
4277 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4278 if ((adapter->hw.mng_cookie.status &
4279 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4280 e1000_update_mng_vlan(adapter);
4281
Bruce Allan79d4e902011-12-16 00:46:27 +00004282 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004283 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4284 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004285
Bruce Allane921eb12012-11-28 09:28:37 +00004286 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004287 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4288 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004289 * clean_rx handler before we do so.
4290 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004291 e1000_configure(adapter);
4292
4293 err = e1000_request_irq(adapter);
4294 if (err)
4295 goto err_req_irq;
4296
Bruce Allane921eb12012-11-28 09:28:37 +00004297 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004298 * ignore e1000e MSI messages, which means we need to test our MSI
4299 * interrupt now
4300 */
Bruce Allan4662e822008-08-26 18:37:06 -07004301 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004302 err = e1000_test_msi(adapter);
4303 if (err) {
4304 e_err("Interrupt allocation failed\n");
4305 goto err_req_irq;
4306 }
4307 }
4308
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309 /* From here on the code is the same as e1000e_up() */
4310 clear_bit(__E1000_DOWN, &adapter->state);
4311
4312 napi_enable(&adapter->napi);
4313
4314 e1000_irq_enable(adapter);
4315
Jeff Kirsher09357b02011-11-18 14:25:00 +00004316 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004317 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004318
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004319 adapter->idle_check = true;
4320 pm_runtime_put(&pdev->dev);
4321
Auke Kokbc7f75f2007-09-17 12:30:59 -07004322 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004323 if (adapter->msix_entries)
4324 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4325 else
4326 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004327
4328 return 0;
4329
4330err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004331 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004332 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004333 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004334err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004335 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004336err_setup_tx:
4337 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004338 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004339
4340 return err;
4341}
4342
4343/**
4344 * e1000_close - Disables a network interface
4345 * @netdev: network interface device structure
4346 *
4347 * Returns 0, this is not allowed to fail
4348 *
4349 * The close entry point is called when an interface is de-activated
4350 * by the OS. The hardware is still under the drivers control, but
4351 * needs to be disabled. A global MAC reset is issued to stop the
4352 * hardware, and all transmit and receive resources are freed.
4353 **/
4354static int e1000_close(struct net_device *netdev)
4355{
4356 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004357 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004358 int count = E1000_CHECK_RESET_COUNT;
4359
4360 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4361 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004362
4363 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004364
4365 pm_runtime_get_sync(&pdev->dev);
4366
Bruce Allan5f4a7802011-11-29 08:09:19 +00004367 napi_disable(&adapter->napi);
4368
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004369 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4370 e1000e_down(adapter);
4371 e1000_free_irq(adapter);
4372 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004373 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004374
Bruce Allan55aa6982011-12-16 00:45:45 +00004375 e1000e_free_tx_resources(adapter->tx_ring);
4376 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004377
Bruce Allane921eb12012-11-28 09:28:37 +00004378 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004379 * the same ID is registered on the host OS (let 8021q kill it)
4380 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004381 if (adapter->hw.mng_cookie.status &
4382 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4384
Bruce Allane921eb12012-11-28 09:28:37 +00004385 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004386 * interface is now closed
4387 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004388 if ((adapter->flags & FLAG_HAS_AMT) &&
4389 !test_bit(__E1000_TESTING, &adapter->state))
4390 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391
Bruce Allan3e35d992013-01-12 07:25:22 +00004392 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004393
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004394 pm_runtime_put_sync(&pdev->dev);
4395
Auke Kokbc7f75f2007-09-17 12:30:59 -07004396 return 0;
4397}
4398/**
4399 * e1000_set_mac - Change the Ethernet Address of the NIC
4400 * @netdev: network interface device structure
4401 * @p: pointer to an address structure
4402 *
4403 * Returns 0 on success, negative on failure
4404 **/
4405static int e1000_set_mac(struct net_device *netdev, void *p)
4406{
4407 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004408 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004409 struct sockaddr *addr = p;
4410
4411 if (!is_valid_ether_addr(addr->sa_data))
4412 return -EADDRNOTAVAIL;
4413
4414 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4415 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4416
Bruce Allan69e1e012012-04-14 03:28:50 +00004417 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418
4419 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4420 /* activate the work around */
4421 e1000e_set_laa_state_82571(&adapter->hw, 1);
4422
Bruce Allane921eb12012-11-28 09:28:37 +00004423 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 * between the time RAR[0] gets clobbered and the time it
4425 * gets fixed (in e1000_watchdog), the actual LAA is in one
4426 * of the RARs and no incoming packets directed to this port
4427 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004428 * RAR[14]
4429 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004430 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4431 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004432 }
4433
4434 return 0;
4435}
4436
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004437/**
4438 * e1000e_update_phy_task - work thread to update phy
4439 * @work: pointer to our work struct
4440 *
4441 * this worker thread exists because we must acquire a
4442 * semaphore to read the phy, which we could msleep while
4443 * waiting for it, and we can't msleep in a timer.
4444 **/
4445static void e1000e_update_phy_task(struct work_struct *work)
4446{
4447 struct e1000_adapter *adapter = container_of(work,
4448 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004449
4450 if (test_bit(__E1000_DOWN, &adapter->state))
4451 return;
4452
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004453 e1000_get_phy_info(&adapter->hw);
4454}
4455
Bruce Allane921eb12012-11-28 09:28:37 +00004456/**
4457 * e1000_update_phy_info - timre call-back to update PHY info
4458 * @data: pointer to adapter cast into an unsigned long
4459 *
Bruce Allanad680762008-03-28 09:15:03 -07004460 * Need to wait a few seconds after link up to get diagnostic information from
4461 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004462 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463static void e1000_update_phy_info(unsigned long data)
4464{
4465 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004466
4467 if (test_bit(__E1000_DOWN, &adapter->state))
4468 return;
4469
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004470 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004471}
4472
4473/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004474 * e1000e_update_phy_stats - Update the PHY statistics counters
4475 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004476 *
4477 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004478 **/
4479static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4480{
4481 struct e1000_hw *hw = &adapter->hw;
4482 s32 ret_val;
4483 u16 phy_data;
4484
4485 ret_val = hw->phy.ops.acquire(hw);
4486 if (ret_val)
4487 return;
4488
Bruce Allane921eb12012-11-28 09:28:37 +00004489 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004490 * If not, set to the page with the PHY status registers.
4491 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004492 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004493 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4494 &phy_data);
4495 if (ret_val)
4496 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004497 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4498 ret_val = hw->phy.ops.set_page(hw,
4499 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004500 if (ret_val)
4501 goto release;
4502 }
4503
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004504 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004505 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4506 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004507 if (!ret_val)
4508 adapter->stats.scc += phy_data;
4509
4510 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004511 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4512 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004513 if (!ret_val)
4514 adapter->stats.ecol += phy_data;
4515
4516 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004517 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4518 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004519 if (!ret_val)
4520 adapter->stats.mcc += phy_data;
4521
4522 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004523 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4524 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004525 if (!ret_val)
4526 adapter->stats.latecol += phy_data;
4527
4528 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004529 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4530 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004531 if (!ret_val)
4532 hw->mac.collision_delta = phy_data;
4533
4534 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004535 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4536 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004537 if (!ret_val)
4538 adapter->stats.dc += phy_data;
4539
4540 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004541 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4542 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004543 if (!ret_val)
4544 adapter->stats.tncrs += phy_data;
4545
4546release:
4547 hw->phy.ops.release(hw);
4548}
4549
4550/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004551 * e1000e_update_stats - Update the board statistics counters
4552 * @adapter: board private structure
4553 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004554static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004556 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 struct e1000_hw *hw = &adapter->hw;
4558 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559
Bruce Allane921eb12012-11-28 09:28:37 +00004560 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004561 * connection is down.
4562 */
4563 if (adapter->link_speed == 0)
4564 return;
4565 if (pci_channel_offline(pdev))
4566 return;
4567
Auke Kokbc7f75f2007-09-17 12:30:59 -07004568 adapter->stats.crcerrs += er32(CRCERRS);
4569 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004570 adapter->stats.gorc += er32(GORCL);
4571 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004572 adapter->stats.bprc += er32(BPRC);
4573 adapter->stats.mprc += er32(MPRC);
4574 adapter->stats.roc += er32(ROC);
4575
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004577
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004578 /* Half-duplex statistics */
4579 if (adapter->link_duplex == HALF_DUPLEX) {
4580 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4581 e1000e_update_phy_stats(adapter);
4582 } else {
4583 adapter->stats.scc += er32(SCC);
4584 adapter->stats.ecol += er32(ECOL);
4585 adapter->stats.mcc += er32(MCC);
4586 adapter->stats.latecol += er32(LATECOL);
4587 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004588
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004589 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004590
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004591 if ((hw->mac.type != e1000_82574) &&
4592 (hw->mac.type != e1000_82583))
4593 adapter->stats.tncrs += er32(TNCRS);
4594 }
4595 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004596 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004597
Auke Kokbc7f75f2007-09-17 12:30:59 -07004598 adapter->stats.xonrxc += er32(XONRXC);
4599 adapter->stats.xontxc += er32(XONTXC);
4600 adapter->stats.xoffrxc += er32(XOFFRXC);
4601 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004603 adapter->stats.gotc += er32(GOTCL);
4604 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004605 adapter->stats.rnbc += er32(RNBC);
4606 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004607
4608 adapter->stats.mptc += er32(MPTC);
4609 adapter->stats.bptc += er32(BPTC);
4610
4611 /* used for adaptive IFS */
4612
4613 hw->mac.tx_packet_delta = er32(TPT);
4614 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615
4616 adapter->stats.algnerrc += er32(ALGNERRC);
4617 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004618 adapter->stats.cexterr += er32(CEXTERR);
4619 adapter->stats.tsctc += er32(TSCTC);
4620 adapter->stats.tsctfc += er32(TSCTFC);
4621
Auke Kokbc7f75f2007-09-17 12:30:59 -07004622 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004623 netdev->stats.multicast = adapter->stats.mprc;
4624 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625
4626 /* Rx Errors */
4627
Bruce Allane921eb12012-11-28 09:28:37 +00004628 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004629 * our own version based on RUC and ROC
4630 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004631 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 adapter->stats.crcerrs + adapter->stats.algnerrc +
4633 adapter->stats.ruc + adapter->stats.roc +
4634 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004635 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004636 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004637 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4638 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4639 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004640
4641 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004642 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004643 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004644 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4645 netdev->stats.tx_window_errors = adapter->stats.latecol;
4646 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004647
4648 /* Tx Dropped needs to be maintained elsewhere */
4649
Auke Kokbc7f75f2007-09-17 12:30:59 -07004650 /* Management Stats */
4651 adapter->stats.mgptc += er32(MGTPTC);
4652 adapter->stats.mgprc += er32(MGTPRC);
4653 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004654
4655 /* Correctable ECC Errors */
4656 if (hw->mac.type == e1000_pch_lpt) {
4657 u32 pbeccsts = er32(PBECCSTS);
4658 adapter->corr_errors +=
4659 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4660 adapter->uncorr_errors +=
4661 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4662 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4663 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004664}
4665
Bruce Allan7c257692008-04-23 11:09:00 -07004666/**
4667 * e1000_phy_read_status - Update the PHY register status snapshot
4668 * @adapter: board private structure
4669 **/
4670static void e1000_phy_read_status(struct e1000_adapter *adapter)
4671{
4672 struct e1000_hw *hw = &adapter->hw;
4673 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004674
4675 if ((er32(STATUS) & E1000_STATUS_LU) &&
4676 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004677 int ret_val;
4678
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004679 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4680 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4681 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4682 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4683 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4684 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4685 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4686 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004687 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004688 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004689 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004690 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004691 * Set values to typical power-on defaults
4692 */
4693 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4694 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4695 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4696 BMSR_ERCAP);
4697 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4698 ADVERTISE_ALL | ADVERTISE_CSMA);
4699 phy->lpa = 0;
4700 phy->expansion = EXPANSION_ENABLENPAGE;
4701 phy->ctrl1000 = ADVERTISE_1000FULL;
4702 phy->stat1000 = 0;
4703 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4704 }
Bruce Allan7c257692008-04-23 11:09:00 -07004705}
4706
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707static void e1000_print_link_info(struct e1000_adapter *adapter)
4708{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004709 struct e1000_hw *hw = &adapter->hw;
4710 u32 ctrl = er32(CTRL);
4711
Bruce Allan8f12fe82008-11-21 16:54:43 -08004712 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004713 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4714 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004715 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4716 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4717 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4718 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004719}
4720
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004721static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004722{
4723 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004724 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004725 s32 ret_val = 0;
4726
Bruce Allane921eb12012-11-28 09:28:37 +00004727 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004728 * Rx sequence error interrupt. get_link_status will stay
4729 * false until the check_for_link establishes link
4730 * for copper adapters ONLY
4731 */
4732 switch (hw->phy.media_type) {
4733 case e1000_media_type_copper:
4734 if (hw->mac.get_link_status) {
4735 ret_val = hw->mac.ops.check_for_link(hw);
4736 link_active = !hw->mac.get_link_status;
4737 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004738 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004739 }
4740 break;
4741 case e1000_media_type_fiber:
4742 ret_val = hw->mac.ops.check_for_link(hw);
4743 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4744 break;
4745 case e1000_media_type_internal_serdes:
4746 ret_val = hw->mac.ops.check_for_link(hw);
4747 link_active = adapter->hw.mac.serdes_has_link;
4748 break;
4749 default:
4750 case e1000_media_type_unknown:
4751 break;
4752 }
4753
4754 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4755 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4756 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004757 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004758 }
4759
4760 return link_active;
4761}
4762
4763static void e1000e_enable_receives(struct e1000_adapter *adapter)
4764{
4765 /* make sure the receive unit is started */
4766 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004767 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004768 struct e1000_hw *hw = &adapter->hw;
4769 u32 rctl = er32(RCTL);
4770 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004771 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004772 }
4773}
4774
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004775static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4776{
4777 struct e1000_hw *hw = &adapter->hw;
4778
Bruce Allane921eb12012-11-28 09:28:37 +00004779 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004780 * for hung state and reset, if two calls return true
4781 */
4782 if (e1000_check_phy_82574(hw))
4783 adapter->phy_hang_count++;
4784 else
4785 adapter->phy_hang_count = 0;
4786
4787 if (adapter->phy_hang_count > 1) {
4788 adapter->phy_hang_count = 0;
4789 schedule_work(&adapter->reset_task);
4790 }
4791}
4792
Auke Kokbc7f75f2007-09-17 12:30:59 -07004793/**
4794 * e1000_watchdog - Timer Call-back
4795 * @data: pointer to adapter cast into an unsigned long
4796 **/
4797static void e1000_watchdog(unsigned long data)
4798{
4799 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4800
4801 /* Do the rest outside of interrupt context */
4802 schedule_work(&adapter->watchdog_task);
4803
4804 /* TODO: make this use queue_delayed_work() */
4805}
4806
4807static void e1000_watchdog_task(struct work_struct *work)
4808{
4809 struct e1000_adapter *adapter = container_of(work,
4810 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004811 struct net_device *netdev = adapter->netdev;
4812 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004813 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004814 struct e1000_ring *tx_ring = adapter->tx_ring;
4815 struct e1000_hw *hw = &adapter->hw;
4816 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004818 if (test_bit(__E1000_DOWN, &adapter->state))
4819 return;
4820
David S. Millerb405e8d2010-02-04 22:31:41 -08004821 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004822 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004823 /* Cancel scheduled suspend requests. */
4824 pm_runtime_resume(netdev->dev.parent);
4825
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004826 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004828 }
4829
4830 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4831 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4832 e1000_update_mng_vlan(adapter);
4833
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834 if (link) {
4835 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004836 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004837
4838 /* Cancel scheduled suspend requests. */
4839 pm_runtime_resume(netdev->dev.parent);
4840
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004841 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004842 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004843 mac->ops.get_link_up_info(&adapter->hw,
4844 &adapter->link_speed,
4845 &adapter->link_duplex);
4846 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004847 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004848 * if link has autonegotiated at 10/100 half
4849 */
4850 if ((hw->phy.type == e1000_phy_igp_3 ||
4851 hw->phy.type == e1000_phy_bm) &&
4852 (hw->mac.autoneg == true) &&
4853 (adapter->link_speed == SPEED_10 ||
4854 adapter->link_speed == SPEED_100) &&
4855 (adapter->link_duplex == HALF_DUPLEX)) {
4856 u16 autoneg_exp;
4857
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004858 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004859
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004860 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004861 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 -07004862 }
4863
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004864 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 adapter->tx_timeout_factor = 1;
4866 switch (adapter->link_speed) {
4867 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004868 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004869 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870 break;
4871 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004872 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004873 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004874 break;
4875 }
4876
Bruce Allane921eb12012-11-28 09:28:37 +00004877 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004878 * link-up event
4879 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4881 !txb2b) {
4882 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004883 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004884 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004885 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 }
4887
Bruce Allane921eb12012-11-28 09:28:37 +00004888 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004889 * some hardware issues
4890 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004891 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4892 switch (adapter->link_speed) {
4893 case SPEED_10:
4894 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004895 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004896 netdev->features &= ~NETIF_F_TSO;
4897 netdev->features &= ~NETIF_F_TSO6;
4898 break;
4899 case SPEED_1000:
4900 netdev->features |= NETIF_F_TSO;
4901 netdev->features |= NETIF_F_TSO6;
4902 break;
4903 default:
4904 /* oops */
4905 break;
4906 }
4907 }
4908
Bruce Allane921eb12012-11-28 09:28:37 +00004909 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004910 * after setting TARC(0)
4911 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004912 tctl = er32(TCTL);
4913 tctl |= E1000_TCTL_EN;
4914 ew32(TCTL, tctl);
4915
Bruce Allane921eb12012-11-28 09:28:37 +00004916 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004917 * reporting link up.
4918 */
4919 if (phy->ops.cfg_on_link_up)
4920 phy->ops.cfg_on_link_up(hw);
4921
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923
4924 if (!test_bit(__E1000_DOWN, &adapter->state))
4925 mod_timer(&adapter->phy_info_timer,
4926 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004927 }
4928 } else {
4929 if (netif_carrier_ok(netdev)) {
4930 adapter->link_speed = 0;
4931 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004932 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004933 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004934 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004935 if (!test_bit(__E1000_DOWN, &adapter->state))
4936 mod_timer(&adapter->phy_info_timer,
4937 round_jiffies(jiffies + 2 * HZ));
4938
Bruce Allan12d43f72012-12-05 06:26:14 +00004939 /* The link is lost so the controller stops DMA.
4940 * If there is queued Tx work that cannot be done
4941 * or if on an 8000ES2LAN which requires a Rx packet
4942 * buffer work-around on link down event, reset the
4943 * controller to flush the Tx/Rx packet buffers.
4944 * (Do the reset outside of interrupt context).
4945 */
4946 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4947 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4948 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004949 else
4950 pm_schedule_suspend(netdev->dev.parent,
4951 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 }
4953 }
4954
4955link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004956 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004957 e1000e_update_stats(adapter);
4958
4959 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4960 adapter->tpt_old = adapter->stats.tpt;
4961 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4962 adapter->colc_old = adapter->stats.colc;
4963
Bruce Allan7c257692008-04-23 11:09:00 -07004964 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4965 adapter->gorc_old = adapter->stats.gorc;
4966 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4967 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004968 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004969
Bruce Allan12d43f72012-12-05 06:26:14 +00004970 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004971 schedule_work(&adapter->reset_task);
4972 /* return immediately since reset is imminent */
4973 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004974 }
4975
Bruce Allan12d43f72012-12-05 06:26:14 +00004976 e1000e_update_adaptive(&adapter->hw);
4977
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004978 /* Simple mode for Interrupt Throttle Rate (ITR) */
4979 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004980 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004981 * Total asymmetrical Tx or Rx gets ITR=8000;
4982 * everyone else is between 2000-8000.
4983 */
4984 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4985 u32 dif = (adapter->gotc > adapter->gorc ?
4986 adapter->gotc - adapter->gorc :
4987 adapter->gorc - adapter->gotc) / 10000;
4988 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4989
Matthew Vick22a4cca2012-07-12 00:02:42 +00004990 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004991 }
4992
Bruce Allanad680762008-03-28 09:15:03 -07004993 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004994 if (adapter->msix_entries)
4995 ew32(ICS, adapter->rx_ring->ims_val);
4996 else
4997 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004999 /* flush pending descriptors to memory before detecting Tx hang */
5000 e1000e_flush_descriptors(adapter);
5001
Auke Kokbc7f75f2007-09-17 12:30:59 -07005002 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005003 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004
Bruce Allane921eb12012-11-28 09:28:37 +00005005 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005006 * reset from the other port. Set the appropriate LAA in RAR[0]
5007 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005008 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005009 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005011 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5012 e1000e_check_82574_phy_workaround(adapter);
5013
Bruce Allanb67e1912012-12-27 08:32:33 +00005014 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5015 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5016 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5017 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5018 er32(RXSTMPH);
5019 adapter->rx_hwtstamp_cleared++;
5020 } else {
5021 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5022 }
5023 }
5024
Auke Kokbc7f75f2007-09-17 12:30:59 -07005025 /* Reset the timer */
5026 if (!test_bit(__E1000_DOWN, &adapter->state))
5027 mod_timer(&adapter->watchdog_timer,
5028 round_jiffies(jiffies + 2 * HZ));
5029}
5030
5031#define E1000_TX_FLAGS_CSUM 0x00000001
5032#define E1000_TX_FLAGS_VLAN 0x00000002
5033#define E1000_TX_FLAGS_TSO 0x00000004
5034#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005035#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005036#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5038#define E1000_TX_FLAGS_VLAN_SHIFT 16
5039
Bruce Allan55aa6982011-12-16 00:45:45 +00005040static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042 struct e1000_context_desc *context_desc;
5043 struct e1000_buffer *buffer_info;
5044 unsigned int i;
5045 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005046 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005048
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005049 if (!skb_is_gso(skb))
5050 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005051
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005052 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005053 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5054
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005055 if (err)
5056 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005057 }
5058
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005059 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5060 mss = skb_shinfo(skb)->gso_size;
5061 if (skb->protocol == htons(ETH_P_IP)) {
5062 struct iphdr *iph = ip_hdr(skb);
5063 iph->tot_len = 0;
5064 iph->check = 0;
5065 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5066 0, IPPROTO_TCP, 0);
5067 cmd_length = E1000_TXD_CMD_IP;
5068 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005069 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005070 ipv6_hdr(skb)->payload_len = 0;
5071 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5072 &ipv6_hdr(skb)->daddr,
5073 0, IPPROTO_TCP, 0);
5074 ipcse = 0;
5075 }
5076 ipcss = skb_network_offset(skb);
5077 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5078 tucss = skb_transport_offset(skb);
5079 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005080
5081 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5082 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5083
5084 i = tx_ring->next_to_use;
5085 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5086 buffer_info = &tx_ring->buffer_info[i];
5087
5088 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5089 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5090 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5091 context_desc->upper_setup.tcp_fields.tucss = tucss;
5092 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005093 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005094 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5095 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5096 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5097
5098 buffer_info->time_stamp = jiffies;
5099 buffer_info->next_to_watch = i;
5100
5101 i++;
5102 if (i == tx_ring->count)
5103 i = 0;
5104 tx_ring->next_to_use = i;
5105
5106 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107}
5108
Bruce Allan55aa6982011-12-16 00:45:45 +00005109static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110{
Bruce Allan55aa6982011-12-16 00:45:45 +00005111 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005112 struct e1000_context_desc *context_desc;
5113 struct e1000_buffer *buffer_info;
5114 unsigned int i;
5115 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005116 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005117 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005118
Dave Grahamaf807c82008-10-09 14:28:58 -07005119 if (skb->ip_summed != CHECKSUM_PARTIAL)
5120 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005121
Arthur Jones5f66f202009-03-19 01:13:08 +00005122 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5123 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5124 else
5125 protocol = skb->protocol;
5126
Arthur Jones3f518392009-03-20 15:56:35 -07005127 switch (protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08005128 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005129 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5130 cmd_len |= E1000_TXD_CMD_TCP;
5131 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08005132 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005133 /* XXX not handling all IPV6 headers */
5134 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5135 cmd_len |= E1000_TXD_CMD_TCP;
5136 break;
5137 default:
5138 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005139 e_warn("checksum_partial proto=%x!\n",
5140 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005141 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005142 }
5143
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005144 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005145
5146 i = tx_ring->next_to_use;
5147 buffer_info = &tx_ring->buffer_info[i];
5148 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5149
5150 context_desc->lower_setup.ip_config = 0;
5151 context_desc->upper_setup.tcp_fields.tucss = css;
5152 context_desc->upper_setup.tcp_fields.tucso =
5153 css + skb->csum_offset;
5154 context_desc->upper_setup.tcp_fields.tucse = 0;
5155 context_desc->tcp_seg_setup.data = 0;
5156 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5157
5158 buffer_info->time_stamp = jiffies;
5159 buffer_info->next_to_watch = i;
5160
5161 i++;
5162 if (i == tx_ring->count)
5163 i = 0;
5164 tx_ring->next_to_use = i;
5165
5166 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167}
5168
Bruce Allan55aa6982011-12-16 00:45:45 +00005169static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5170 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005171 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005172{
Bruce Allan55aa6982011-12-16 00:45:45 +00005173 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005174 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005175 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005176 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005177 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005178 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179
5180 i = tx_ring->next_to_use;
5181
5182 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005183 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005184 size = min(len, max_per_txd);
5185
Auke Kokbc7f75f2007-09-17 12:30:59 -07005186 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005188 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005189 buffer_info->dma = dma_map_single(&pdev->dev,
5190 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005191 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005192 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005193 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005194 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005195
5196 len -= size;
5197 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005198 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005199
5200 if (len) {
5201 i++;
5202 if (i == tx_ring->count)
5203 i = 0;
5204 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005205 }
5206
5207 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005208 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005209
5210 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005211 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005212 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213
5214 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005215 i++;
5216 if (i == tx_ring->count)
5217 i = 0;
5218
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219 buffer_info = &tx_ring->buffer_info[i];
5220 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005221
5222 buffer_info->length = size;
5223 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005224 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005225 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5226 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005227 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005228 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005229 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230
5231 len -= size;
5232 offset += size;
5233 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005234 }
5235 }
5236
Bruce Allanaf667a22010-12-31 06:10:01 +00005237 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005238 /* multiply data chunks by size of headers */
5239 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5240
Auke Kokbc7f75f2007-09-17 12:30:59 -07005241 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005242 tx_ring->buffer_info[i].segs = segs;
5243 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005244 tx_ring->buffer_info[first].next_to_watch = i;
5245
5246 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005247
5248dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005249 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005250 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005251 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005252 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005253
5254 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005255 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005256 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005257 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005258 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005259 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005260 }
5261
5262 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005263}
5264
Bruce Allan55aa6982011-12-16 00:45:45 +00005265static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005266{
Bruce Allan55aa6982011-12-16 00:45:45 +00005267 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005268 struct e1000_tx_desc *tx_desc = NULL;
5269 struct e1000_buffer *buffer_info;
5270 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5271 unsigned int i;
5272
5273 if (tx_flags & E1000_TX_FLAGS_TSO) {
5274 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5275 E1000_TXD_CMD_TSE;
5276 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5277
5278 if (tx_flags & E1000_TX_FLAGS_IPV4)
5279 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5280 }
5281
5282 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5283 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5284 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5285 }
5286
5287 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5288 txd_lower |= E1000_TXD_CMD_VLE;
5289 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5290 }
5291
Ben Greear943146d2012-02-11 15:39:40 +00005292 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5293 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5294
Bruce Allanb67e1912012-12-27 08:32:33 +00005295 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5296 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5297 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5298 }
5299
Auke Kokbc7f75f2007-09-17 12:30:59 -07005300 i = tx_ring->next_to_use;
5301
Bruce Allan36b973d2010-11-24 07:42:43 +00005302 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005303 buffer_info = &tx_ring->buffer_info[i];
5304 tx_desc = E1000_TX_DESC(*tx_ring, i);
5305 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5306 tx_desc->lower.data =
5307 cpu_to_le32(txd_lower | buffer_info->length);
5308 tx_desc->upper.data = cpu_to_le32(txd_upper);
5309
5310 i++;
5311 if (i == tx_ring->count)
5312 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005313 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005314
5315 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5316
Ben Greear943146d2012-02-11 15:39:40 +00005317 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5318 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5319 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5320
Bruce Allane921eb12012-11-28 09:28:37 +00005321 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005322 * know there are new descriptors to fetch. (Only
5323 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005324 * such as IA-64).
5325 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005326 wmb();
5327
5328 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005329
5330 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005331 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005332 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005333 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005334
Bruce Allane921eb12012-11-28 09:28:37 +00005335 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005336 * at a time, it synchronizes IO on IA64/Altix systems
5337 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005338 mmiowb();
5339}
5340
5341#define MINIMUM_DHCP_PACKET_SIZE 282
5342static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5343 struct sk_buff *skb)
5344{
5345 struct e1000_hw *hw = &adapter->hw;
5346 u16 length, offset;
5347
Bruce Alland60923c2012-12-05 06:26:56 +00005348 if (vlan_tx_tag_present(skb) &&
5349 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5350 (adapter->hw.mng_cookie.status &
5351 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5352 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005353
5354 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5355 return 0;
5356
5357 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5358 return 0;
5359
5360 {
5361 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5362 struct udphdr *udp;
5363
5364 if (ip->protocol != IPPROTO_UDP)
5365 return 0;
5366
5367 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5368 if (ntohs(udp->dest) != 67)
5369 return 0;
5370
5371 offset = (u8 *)udp + 8 - skb->data;
5372 length = skb->len - offset;
5373 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5374 }
5375
5376 return 0;
5377}
5378
Bruce Allan55aa6982011-12-16 00:45:45 +00005379static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005380{
Bruce Allan55aa6982011-12-16 00:45:45 +00005381 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005382
Bruce Allan55aa6982011-12-16 00:45:45 +00005383 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005384 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005385 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005386 * but since that doesn't exist yet, just open code it.
5387 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005388 smp_mb();
5389
Bruce Allane921eb12012-11-28 09:28:37 +00005390 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005391 * made room available.
5392 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005393 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005394 return -EBUSY;
5395
5396 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005397 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005398 ++adapter->restart_queue;
5399 return 0;
5400}
5401
Bruce Allan55aa6982011-12-16 00:45:45 +00005402static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403{
Bruce Alland821a4c2012-08-24 20:38:11 +00005404 BUG_ON(size > tx_ring->count);
5405
Bruce Allan55aa6982011-12-16 00:45:45 +00005406 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005407 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005408 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005409}
5410
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005411static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5412 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005413{
5414 struct e1000_adapter *adapter = netdev_priv(netdev);
5415 struct e1000_ring *tx_ring = adapter->tx_ring;
5416 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005417 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005418 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005419 unsigned int nr_frags;
5420 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005421 int count = 0;
5422 int tso;
5423 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005424
5425 if (test_bit(__E1000_DOWN, &adapter->state)) {
5426 dev_kfree_skb_any(skb);
5427 return NETDEV_TX_OK;
5428 }
5429
5430 if (skb->len <= 0) {
5431 dev_kfree_skb_any(skb);
5432 return NETDEV_TX_OK;
5433 }
5434
Bruce Allane921eb12012-11-28 09:28:37 +00005435 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005436 * pad skb in order to meet this minimum size requirement
5437 */
5438 if (unlikely(skb->len < 17)) {
5439 if (skb_pad(skb, 17 - skb->len))
5440 return NETDEV_TX_OK;
5441 skb->len = 17;
5442 skb_set_tail_pointer(skb, 17);
5443 }
5444
Auke Kokbc7f75f2007-09-17 12:30:59 -07005445 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446 if (mss) {
5447 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448
Bruce Allane921eb12012-11-28 09:28:37 +00005449 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005450 * points to just header, pull a few bytes of payload from
5451 * frags into skb->data
5452 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005453 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005454 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005455 * avoiding it could save a lot of cycles
5456 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005457 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005458 unsigned int pull_size;
5459
Bruce Allana2a5b322012-01-31 06:37:17 +00005460 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005461 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005462 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 dev_kfree_skb_any(skb);
5464 return NETDEV_TX_OK;
5465 }
Eric Dumazete743d312010-04-14 15:59:40 -07005466 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005467 }
5468 }
5469
5470 /* reserve a descriptor for the offload context */
5471 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5472 count++;
5473 count++;
5474
Bruce Alland821a4c2012-08-24 20:38:11 +00005475 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005476
5477 nr_frags = skb_shinfo(skb)->nr_frags;
5478 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005479 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5480 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005481
5482 if (adapter->hw.mac.tx_pkt_filtering)
5483 e1000_transfer_dhcp_info(adapter, skb);
5484
Bruce Allane921eb12012-11-28 09:28:37 +00005485 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005486 * head, otherwise try next time
5487 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005488 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005490
Jesse Grosseab6d182010-10-20 13:56:03 +00005491 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005492 tx_flags |= E1000_TX_FLAGS_VLAN;
5493 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5494 }
5495
5496 first = tx_ring->next_to_use;
5497
Bruce Allan55aa6982011-12-16 00:45:45 +00005498 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005499 if (tso < 0) {
5500 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005501 return NETDEV_TX_OK;
5502 }
5503
5504 if (tso)
5505 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005506 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005507 tx_flags |= E1000_TX_FLAGS_CSUM;
5508
Bruce Allane921eb12012-11-28 09:28:37 +00005509 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005510 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005511 * no longer assume, we must.
5512 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005513 if (skb->protocol == htons(ETH_P_IP))
5514 tx_flags |= E1000_TX_FLAGS_IPV4;
5515
Ben Greear943146d2012-02-11 15:39:40 +00005516 if (unlikely(skb->no_fcs))
5517 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5518
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005519 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005520 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5521 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005522 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005523 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5524 !adapter->tx_hwtstamp_skb)) {
5525 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5526 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5527 adapter->tx_hwtstamp_skb = skb_get(skb);
5528 schedule_work(&adapter->tx_hwtstamp_work);
5529 } else {
5530 skb_tx_timestamp(skb);
5531 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005532
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005533 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005534 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005535 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005536 e1000_maybe_stop_tx(tx_ring,
5537 (MAX_SKB_FRAGS *
5538 DIV_ROUND_UP(PAGE_SIZE,
5539 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005540 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005541 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005542 tx_ring->buffer_info[first].time_stamp = 0;
5543 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005544 }
5545
Auke Kokbc7f75f2007-09-17 12:30:59 -07005546 return NETDEV_TX_OK;
5547}
5548
5549/**
5550 * e1000_tx_timeout - Respond to a Tx Hang
5551 * @netdev: network interface device structure
5552 **/
5553static void e1000_tx_timeout(struct net_device *netdev)
5554{
5555 struct e1000_adapter *adapter = netdev_priv(netdev);
5556
5557 /* Do the reset outside of interrupt context */
5558 adapter->tx_timeout_count++;
5559 schedule_work(&adapter->reset_task);
5560}
5561
5562static void e1000_reset_task(struct work_struct *work)
5563{
5564 struct e1000_adapter *adapter;
5565 adapter = container_of(work, struct e1000_adapter, reset_task);
5566
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005567 /* don't run the task if already down */
5568 if (test_bit(__E1000_DOWN, &adapter->state))
5569 return;
5570
Bruce Allan12d43f72012-12-05 06:26:14 +00005571 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005572 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005573 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005574 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005575 e1000e_reinit_locked(adapter);
5576}
5577
5578/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005579 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005580 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005581 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005582 *
5583 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005584 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005585struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5586 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005587{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005588 struct e1000_adapter *adapter = netdev_priv(netdev);
5589
5590 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5591 spin_lock(&adapter->stats64_lock);
5592 e1000e_update_stats(adapter);
5593 /* Fill out the OS statistics structure */
5594 stats->rx_bytes = adapter->stats.gorc;
5595 stats->rx_packets = adapter->stats.gprc;
5596 stats->tx_bytes = adapter->stats.gotc;
5597 stats->tx_packets = adapter->stats.gptc;
5598 stats->multicast = adapter->stats.mprc;
5599 stats->collisions = adapter->stats.colc;
5600
5601 /* Rx Errors */
5602
Bruce Allane921eb12012-11-28 09:28:37 +00005603 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005604 * our own version based on RUC and ROC
5605 */
5606 stats->rx_errors = adapter->stats.rxerrc +
5607 adapter->stats.crcerrs + adapter->stats.algnerrc +
5608 adapter->stats.ruc + adapter->stats.roc +
5609 adapter->stats.cexterr;
5610 stats->rx_length_errors = adapter->stats.ruc +
5611 adapter->stats.roc;
5612 stats->rx_crc_errors = adapter->stats.crcerrs;
5613 stats->rx_frame_errors = adapter->stats.algnerrc;
5614 stats->rx_missed_errors = adapter->stats.mpc;
5615
5616 /* Tx Errors */
5617 stats->tx_errors = adapter->stats.ecol +
5618 adapter->stats.latecol;
5619 stats->tx_aborted_errors = adapter->stats.ecol;
5620 stats->tx_window_errors = adapter->stats.latecol;
5621 stats->tx_carrier_errors = adapter->stats.tncrs;
5622
5623 /* Tx Dropped needs to be maintained elsewhere */
5624
5625 spin_unlock(&adapter->stats64_lock);
5626 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005627}
5628
5629/**
5630 * e1000_change_mtu - Change the Maximum Transfer Unit
5631 * @netdev: network interface device structure
5632 * @new_mtu: new value for maximum frame size
5633 *
5634 * Returns 0 on success, negative on failure
5635 **/
5636static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5637{
5638 struct e1000_adapter *adapter = netdev_priv(netdev);
5639 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5640
Bruce Allan2adc55c2009-06-02 11:28:58 +00005641 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005642 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5643 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5644 e_err("Jumbo Frames not supported.\n");
5645 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005646 }
5647
Bruce Allan2adc55c2009-06-02 11:28:58 +00005648 /* Supported frame sizes */
5649 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5650 (max_frame > adapter->max_hw_frame_size)) {
5651 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005652 return -EINVAL;
5653 }
5654
Bruce Allan2fbe4522012-04-19 03:21:47 +00005655 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5656 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005657 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5658 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005659 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005660 return -EINVAL;
5661 }
5662
Auke Kokbc7f75f2007-09-17 12:30:59 -07005663 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005664 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005665 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005666 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005667 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5668 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005669 if (netif_running(netdev))
5670 e1000e_down(adapter);
5671
Bruce Allane921eb12012-11-28 09:28:37 +00005672 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005673 * means we reserve 2 more, this pushes us to allocate from the next
5674 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005675 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005676 * However with the new *_jumbo_rx* routines, jumbo receives will use
5677 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005678 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005679
Jesse Brandeburg99261462010-01-22 22:56:16 +00005680 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005681 adapter->rx_buffer_len = 2048;
5682 else
5683 adapter->rx_buffer_len = 4096;
5684
5685 /* adjust allocation if LPE protects us, and we aren't using SBP */
5686 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5687 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5688 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005689 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005690
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691 if (netif_running(netdev))
5692 e1000e_up(adapter);
5693 else
5694 e1000e_reset(adapter);
5695
5696 clear_bit(__E1000_RESETTING, &adapter->state);
5697
5698 return 0;
5699}
5700
5701static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5702 int cmd)
5703{
5704 struct e1000_adapter *adapter = netdev_priv(netdev);
5705 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005706
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005707 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005708 return -EOPNOTSUPP;
5709
5710 switch (cmd) {
5711 case SIOCGMIIPHY:
5712 data->phy_id = adapter->hw.phy.addr;
5713 break;
5714 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005715 e1000_phy_read_status(adapter);
5716
Bruce Allan7c257692008-04-23 11:09:00 -07005717 switch (data->reg_num & 0x1F) {
5718 case MII_BMCR:
5719 data->val_out = adapter->phy_regs.bmcr;
5720 break;
5721 case MII_BMSR:
5722 data->val_out = adapter->phy_regs.bmsr;
5723 break;
5724 case MII_PHYSID1:
5725 data->val_out = (adapter->hw.phy.id >> 16);
5726 break;
5727 case MII_PHYSID2:
5728 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5729 break;
5730 case MII_ADVERTISE:
5731 data->val_out = adapter->phy_regs.advertise;
5732 break;
5733 case MII_LPA:
5734 data->val_out = adapter->phy_regs.lpa;
5735 break;
5736 case MII_EXPANSION:
5737 data->val_out = adapter->phy_regs.expansion;
5738 break;
5739 case MII_CTRL1000:
5740 data->val_out = adapter->phy_regs.ctrl1000;
5741 break;
5742 case MII_STAT1000:
5743 data->val_out = adapter->phy_regs.stat1000;
5744 break;
5745 case MII_ESTATUS:
5746 data->val_out = adapter->phy_regs.estatus;
5747 break;
5748 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005749 return -EIO;
5750 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005751 break;
5752 case SIOCSMIIREG:
5753 default:
5754 return -EOPNOTSUPP;
5755 }
5756 return 0;
5757}
5758
Bruce Allanb67e1912012-12-27 08:32:33 +00005759/**
5760 * e1000e_hwtstamp_ioctl - control hardware time stamping
5761 * @netdev: network interface device structure
5762 * @ifreq: interface request
5763 *
5764 * Outgoing time stamping can be enabled and disabled. Play nice and
5765 * disable it when requested, although it shouldn't cause any overhead
5766 * when no packet needs it. At most one packet in the queue may be
5767 * marked for time stamping, otherwise it would be impossible to tell
5768 * for sure to which packet the hardware time stamp belongs.
5769 *
5770 * Incoming time stamping has to be configured via the hardware filters.
5771 * Not all combinations are supported, in particular event type has to be
5772 * specified. Matching the kind of event packet is not supported, with the
5773 * exception of "all V2 events regardless of level 2 or 4".
5774 **/
5775static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5776{
5777 struct e1000_adapter *adapter = netdev_priv(netdev);
5778 struct hwtstamp_config config;
5779 int ret_val;
5780
5781 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5782 return -EFAULT;
5783
5784 adapter->hwtstamp_config = config;
5785
5786 ret_val = e1000e_config_hwtstamp(adapter);
5787 if (ret_val)
5788 return ret_val;
5789
5790 config = adapter->hwtstamp_config;
5791
Bruce Alland89777b2013-01-19 01:09:58 +00005792 switch (config.rx_filter) {
5793 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5794 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5795 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5796 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5797 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5798 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5799 /* With V2 type filters which specify a Sync or Delay Request,
5800 * Path Delay Request/Response messages are also time stamped
5801 * by hardware so notify the caller the requested packets plus
5802 * some others are time stamped.
5803 */
5804 config.rx_filter = HWTSTAMP_FILTER_SOME;
5805 break;
5806 default:
5807 break;
5808 }
5809
Bruce Allanb67e1912012-12-27 08:32:33 +00005810 return copy_to_user(ifr->ifr_data, &config,
5811 sizeof(config)) ? -EFAULT : 0;
5812}
5813
Auke Kokbc7f75f2007-09-17 12:30:59 -07005814static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5815{
5816 switch (cmd) {
5817 case SIOCGMIIPHY:
5818 case SIOCGMIIREG:
5819 case SIOCSMIIREG:
5820 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005821 case SIOCSHWTSTAMP:
5822 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005823 default:
5824 return -EOPNOTSUPP;
5825 }
5826}
5827
Bruce Allana4f58f52009-06-02 11:29:18 +00005828static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5829{
5830 struct e1000_hw *hw = &adapter->hw;
5831 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005832 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005833 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005834
5835 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005836 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005837
Bruce Allan2b6b1682011-05-13 07:20:09 +00005838 retval = hw->phy.ops.acquire(hw);
5839 if (retval) {
5840 e_err("Could not acquire PHY\n");
5841 return retval;
5842 }
5843
5844 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5845 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5846 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005847 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005848
5849 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005850 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5851 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005852 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5853 (u16)(mac_reg & 0xFFFF));
5854 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5855 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005856 }
5857
5858 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005859 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005860 mac_reg = er32(RCTL);
5861 if (mac_reg & E1000_RCTL_UPE)
5862 phy_reg |= BM_RCTL_UPE;
5863 if (mac_reg & E1000_RCTL_MPE)
5864 phy_reg |= BM_RCTL_MPE;
5865 phy_reg &= ~(BM_RCTL_MO_MASK);
5866 if (mac_reg & E1000_RCTL_MO_3)
5867 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5868 << BM_RCTL_MO_SHIFT);
5869 if (mac_reg & E1000_RCTL_BAM)
5870 phy_reg |= BM_RCTL_BAM;
5871 if (mac_reg & E1000_RCTL_PMCF)
5872 phy_reg |= BM_RCTL_PMCF;
5873 mac_reg = er32(CTRL);
5874 if (mac_reg & E1000_CTRL_RFCE)
5875 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005876 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005877
5878 /* enable PHY wakeup in MAC register */
5879 ew32(WUFC, wufc);
5880 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5881
5882 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005883 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5884 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005885
5886 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005887 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5888 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005889 if (retval)
5890 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005891release:
Bruce Allan94d81862009-11-20 23:25:26 +00005892 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005893
5894 return retval;
5895}
5896
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005897static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5898 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005899{
5900 struct net_device *netdev = pci_get_drvdata(pdev);
5901 struct e1000_adapter *adapter = netdev_priv(netdev);
5902 struct e1000_hw *hw = &adapter->hw;
5903 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005904 /* Runtime suspend should only enable wakeup for link changes */
5905 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005906 int retval = 0;
5907
5908 netif_device_detach(netdev);
5909
5910 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005911 int count = E1000_CHECK_RESET_COUNT;
5912
5913 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5914 usleep_range(10000, 20000);
5915
Auke Kokbc7f75f2007-09-17 12:30:59 -07005916 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5917 e1000e_down(adapter);
5918 e1000_free_irq(adapter);
5919 }
Bruce Allan4662e822008-08-26 18:37:06 -07005920 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005921
5922 retval = pci_save_state(pdev);
5923 if (retval)
5924 return retval;
5925
5926 status = er32(STATUS);
5927 if (status & E1000_STATUS_LU)
5928 wufc &= ~E1000_WUFC_LNKC;
5929
5930 if (wufc) {
5931 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005932 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005933
5934 /* turn on all-multi mode if wake on multicast is enabled */
5935 if (wufc & E1000_WUFC_MC) {
5936 rctl = er32(RCTL);
5937 rctl |= E1000_RCTL_MPE;
5938 ew32(RCTL, rctl);
5939 }
5940
5941 ctrl = er32(CTRL);
5942 /* advertise wake from D3Cold */
5943 #define E1000_CTRL_ADVD3WUC 0x00100000
5944 /* phy power management enable */
5945 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005946 ctrl |= E1000_CTRL_ADVD3WUC;
5947 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5948 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005949 ew32(CTRL, ctrl);
5950
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005951 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5952 adapter->hw.phy.media_type ==
5953 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005954 /* keep the laser running in D3 */
5955 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005956 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005957 ew32(CTRL_EXT, ctrl_ext);
5958 }
5959
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005960 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005961 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005962
Auke Kokbc7f75f2007-09-17 12:30:59 -07005963 /* Allow time for pending master requests to run */
5964 e1000e_disable_pcie_master(&adapter->hw);
5965
Bruce Allan82776a42009-08-14 14:35:33 +00005966 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005967 /* enable wakeup by the PHY */
5968 retval = e1000_init_phy_wakeup(adapter, wufc);
5969 if (retval)
5970 return retval;
5971 } else {
5972 /* enable wakeup by the MAC */
5973 ew32(WUFC, wufc);
5974 ew32(WUC, E1000_WUC_PME_EN);
5975 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005976 } else {
5977 ew32(WUC, 0);
5978 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979 }
5980
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005981 *enable_wake = !!wufc;
5982
Auke Kokbc7f75f2007-09-17 12:30:59 -07005983 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005984 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5985 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005986 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005987
5988 if (adapter->hw.phy.type == e1000_phy_igp_3)
5989 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5990
Bruce Allane921eb12012-11-28 09:28:37 +00005991 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005992 * would have already happened in close and is redundant.
5993 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005994 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005995
5996 pci_disable_device(pdev);
5997
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005998 return 0;
5999}
6000
6001static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
6002{
6003 if (sleep && wake) {
6004 pci_prepare_to_sleep(pdev);
6005 return;
6006 }
6007
6008 pci_wake_from_d3(pdev, wake);
6009 pci_set_power_state(pdev, PCI_D3hot);
6010}
6011
6012static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
6013 bool wake)
6014{
6015 struct net_device *netdev = pci_get_drvdata(pdev);
6016 struct e1000_adapter *adapter = netdev_priv(netdev);
6017
Bruce Allane921eb12012-11-28 09:28:37 +00006018 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006019 * correctable error when the MAC transitions from D0 to D3. To
6020 * prevent this we need to mask off the correctable errors on the
6021 * downstream port of the pci-e switch.
6022 */
6023 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6024 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006025 u16 devctl;
6026
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006027 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6028 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6029 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006030
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006031 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006032
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006033 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006034 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006035 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006036 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006037}
6038
Bruce Allan6f461f62010-04-27 03:33:04 +00006039#ifdef CONFIG_PCIEASPM
6040static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6041{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006042 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006043}
6044#else
6045static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006046{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006047 u16 aspm_ctl = 0;
6048
6049 if (state & PCIE_LINK_STATE_L0S)
6050 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6051 if (state & PCIE_LINK_STATE_L1)
6052 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6053
Bruce Allane921eb12012-11-28 09:28:37 +00006054 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006055 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006056 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006057 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006058
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006059 if (pdev->bus->self)
6060 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006061 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006062}
6063#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006064static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006065{
6066 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6067 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6068 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6069
6070 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006071}
6072
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006073#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006074static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006075{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006076 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006077}
6078
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006079static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006080{
6081 struct net_device *netdev = pci_get_drvdata(pdev);
6082 struct e1000_adapter *adapter = netdev_priv(netdev);
6083 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006084 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 u32 err;
6086
Bruce Allan78cd29d2011-03-24 03:09:03 +00006087 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6088 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6089 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6090 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6091 if (aspm_disable_flag)
6092 e1000e_disable_aspm(pdev, aspm_disable_flag);
6093
Auke Kokbc7f75f2007-09-17 12:30:59 -07006094 pci_set_power_state(pdev, PCI_D0);
6095 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006096 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006097
Bruce Allan4662e822008-08-26 18:37:06 -07006098 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099 if (netif_running(netdev)) {
6100 err = e1000_request_irq(adapter);
6101 if (err)
6102 return err;
6103 }
6104
Bruce Allan2fbe4522012-04-19 03:21:47 +00006105 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006106 e1000_resume_workarounds_pchlan(&adapter->hw);
6107
Auke Kokbc7f75f2007-09-17 12:30:59 -07006108 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006109
6110 /* report the system wakeup cause from S3/S4 */
6111 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6112 u16 phy_data;
6113
6114 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6115 if (phy_data) {
6116 e_info("PHY Wakeup cause - %s\n",
6117 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6118 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6119 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6120 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006121 phy_data & E1000_WUS_LNKC ?
6122 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006123 }
6124 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6125 } else {
6126 u32 wus = er32(WUS);
6127 if (wus) {
6128 e_info("MAC Wakeup cause - %s\n",
6129 wus & E1000_WUS_EX ? "Unicast Packet" :
6130 wus & E1000_WUS_MC ? "Multicast Packet" :
6131 wus & E1000_WUS_BC ? "Broadcast Packet" :
6132 wus & E1000_WUS_MAG ? "Magic Packet" :
6133 wus & E1000_WUS_LNKC ? "Link Status Change" :
6134 "other");
6135 }
6136 ew32(WUS, ~0);
6137 }
6138
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006140
Bruce Allancd791612010-05-10 14:59:51 +00006141 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006142
6143 if (netif_running(netdev))
6144 e1000e_up(adapter);
6145
6146 netif_device_attach(netdev);
6147
Bruce Allane921eb12012-11-28 09:28:37 +00006148 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006149 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006150 * under the control of the driver.
6151 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006152 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006153 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006154
6155 return 0;
6156}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006157
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006158#ifdef CONFIG_PM_SLEEP
6159static int e1000_suspend(struct device *dev)
6160{
6161 struct pci_dev *pdev = to_pci_dev(dev);
6162 int retval;
6163 bool wake;
6164
6165 retval = __e1000_shutdown(pdev, &wake, false);
6166 if (!retval)
6167 e1000_complete_shutdown(pdev, true, wake);
6168
6169 return retval;
6170}
6171
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006172static int e1000_resume(struct device *dev)
6173{
6174 struct pci_dev *pdev = to_pci_dev(dev);
6175 struct net_device *netdev = pci_get_drvdata(pdev);
6176 struct e1000_adapter *adapter = netdev_priv(netdev);
6177
6178 if (e1000e_pm_ready(adapter))
6179 adapter->idle_check = true;
6180
6181 return __e1000_resume(pdev);
6182}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006183#endif /* CONFIG_PM_SLEEP */
6184
6185#ifdef CONFIG_PM_RUNTIME
6186static int e1000_runtime_suspend(struct device *dev)
6187{
6188 struct pci_dev *pdev = to_pci_dev(dev);
6189 struct net_device *netdev = pci_get_drvdata(pdev);
6190 struct e1000_adapter *adapter = netdev_priv(netdev);
6191
6192 if (e1000e_pm_ready(adapter)) {
6193 bool wake;
6194
6195 __e1000_shutdown(pdev, &wake, true);
6196 }
6197
6198 return 0;
6199}
6200
6201static int e1000_idle(struct device *dev)
6202{
6203 struct pci_dev *pdev = to_pci_dev(dev);
6204 struct net_device *netdev = pci_get_drvdata(pdev);
6205 struct e1000_adapter *adapter = netdev_priv(netdev);
6206
6207 if (!e1000e_pm_ready(adapter))
6208 return 0;
6209
6210 if (adapter->idle_check) {
6211 adapter->idle_check = false;
6212 if (!e1000e_has_link(adapter))
6213 pm_schedule_suspend(dev, MSEC_PER_SEC);
6214 }
6215
6216 return -EBUSY;
6217}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006218
6219static int e1000_runtime_resume(struct device *dev)
6220{
6221 struct pci_dev *pdev = to_pci_dev(dev);
6222 struct net_device *netdev = pci_get_drvdata(pdev);
6223 struct e1000_adapter *adapter = netdev_priv(netdev);
6224
6225 if (!e1000e_pm_ready(adapter))
6226 return 0;
6227
6228 adapter->idle_check = !dev->power.runtime_auto;
6229 return __e1000_resume(pdev);
6230}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006231#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006232#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233
6234static void e1000_shutdown(struct pci_dev *pdev)
6235{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006236 bool wake = false;
6237
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006238 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006239
6240 if (system_state == SYSTEM_POWER_OFF)
6241 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006242}
6243
6244#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006245
Bruce Allan8bb62862013-01-16 08:46:49 +00006246static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006247{
6248 struct net_device *netdev = data;
6249 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006250
6251 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006252 int vector, msix_irq;
6253
Dongdong Deng147b2c82010-11-16 19:50:15 -08006254 vector = 0;
6255 msix_irq = adapter->msix_entries[vector].vector;
6256 disable_irq(msix_irq);
6257 e1000_intr_msix_rx(msix_irq, netdev);
6258 enable_irq(msix_irq);
6259
6260 vector++;
6261 msix_irq = adapter->msix_entries[vector].vector;
6262 disable_irq(msix_irq);
6263 e1000_intr_msix_tx(msix_irq, netdev);
6264 enable_irq(msix_irq);
6265
6266 vector++;
6267 msix_irq = adapter->msix_entries[vector].vector;
6268 disable_irq(msix_irq);
6269 e1000_msix_other(msix_irq, netdev);
6270 enable_irq(msix_irq);
6271 }
6272
6273 return IRQ_HANDLED;
6274}
6275
Bruce Allane921eb12012-11-28 09:28:37 +00006276/**
6277 * e1000_netpoll
6278 * @netdev: network interface device structure
6279 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006280 * Polling 'interrupt' - used by things like netconsole to send skbs
6281 * without having to re-enable interrupts. It's not called while
6282 * the interrupt routine is executing.
6283 */
6284static void e1000_netpoll(struct net_device *netdev)
6285{
6286 struct e1000_adapter *adapter = netdev_priv(netdev);
6287
Dongdong Deng147b2c82010-11-16 19:50:15 -08006288 switch (adapter->int_mode) {
6289 case E1000E_INT_MODE_MSIX:
6290 e1000_intr_msix(adapter->pdev->irq, netdev);
6291 break;
6292 case E1000E_INT_MODE_MSI:
6293 disable_irq(adapter->pdev->irq);
6294 e1000_intr_msi(adapter->pdev->irq, netdev);
6295 enable_irq(adapter->pdev->irq);
6296 break;
6297 default: /* E1000E_INT_MODE_LEGACY */
6298 disable_irq(adapter->pdev->irq);
6299 e1000_intr(adapter->pdev->irq, netdev);
6300 enable_irq(adapter->pdev->irq);
6301 break;
6302 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006303}
6304#endif
6305
6306/**
6307 * e1000_io_error_detected - called when PCI error is detected
6308 * @pdev: Pointer to PCI device
6309 * @state: The current pci connection state
6310 *
6311 * This function is called after a PCI bus error affecting
6312 * this device has been detected.
6313 */
6314static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6315 pci_channel_state_t state)
6316{
6317 struct net_device *netdev = pci_get_drvdata(pdev);
6318 struct e1000_adapter *adapter = netdev_priv(netdev);
6319
6320 netif_device_detach(netdev);
6321
Mike Masonc93b5a72009-06-30 12:45:53 +00006322 if (state == pci_channel_io_perm_failure)
6323 return PCI_ERS_RESULT_DISCONNECT;
6324
Auke Kokbc7f75f2007-09-17 12:30:59 -07006325 if (netif_running(netdev))
6326 e1000e_down(adapter);
6327 pci_disable_device(pdev);
6328
6329 /* Request a slot slot reset. */
6330 return PCI_ERS_RESULT_NEED_RESET;
6331}
6332
6333/**
6334 * e1000_io_slot_reset - called after the pci bus has been reset.
6335 * @pdev: Pointer to PCI device
6336 *
6337 * Restart the card from scratch, as if from a cold-boot. Implementation
6338 * resembles the first-half of the e1000_resume routine.
6339 */
6340static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6341{
6342 struct net_device *netdev = pci_get_drvdata(pdev);
6343 struct e1000_adapter *adapter = netdev_priv(netdev);
6344 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006345 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006346 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006347 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006348
Bruce Allan78cd29d2011-03-24 03:09:03 +00006349 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6350 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006351 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006352 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6353 if (aspm_disable_flag)
6354 e1000e_disable_aspm(pdev, aspm_disable_flag);
6355
Bruce Allanf0f422e2008-08-04 17:21:53 -07006356 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006357 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006358 dev_err(&pdev->dev,
6359 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006360 result = PCI_ERS_RESULT_DISCONNECT;
6361 } else {
6362 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006363 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006364 pci_restore_state(pdev);
6365
6366 pci_enable_wake(pdev, PCI_D3hot, 0);
6367 pci_enable_wake(pdev, PCI_D3cold, 0);
6368
6369 e1000e_reset(adapter);
6370 ew32(WUS, ~0);
6371 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006373
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006374 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006375
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006376 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006377}
6378
6379/**
6380 * e1000_io_resume - called when traffic can start flowing again.
6381 * @pdev: Pointer to PCI device
6382 *
6383 * This callback is called when the error recovery driver tells us that
6384 * its OK to resume normal operation. Implementation resembles the
6385 * second-half of the e1000_resume routine.
6386 */
6387static void e1000_io_resume(struct pci_dev *pdev)
6388{
6389 struct net_device *netdev = pci_get_drvdata(pdev);
6390 struct e1000_adapter *adapter = netdev_priv(netdev);
6391
Bruce Allancd791612010-05-10 14:59:51 +00006392 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006393
6394 if (netif_running(netdev)) {
6395 if (e1000e_up(adapter)) {
6396 dev_err(&pdev->dev,
6397 "can't bring device back up after reset\n");
6398 return;
6399 }
6400 }
6401
6402 netif_device_attach(netdev);
6403
Bruce Allane921eb12012-11-28 09:28:37 +00006404 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006405 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006406 * under the control of the driver.
6407 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006408 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006409 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006410
6411}
6412
6413static void e1000_print_device_info(struct e1000_adapter *adapter)
6414{
6415 struct e1000_hw *hw = &adapter->hw;
6416 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006417 u32 ret_val;
6418 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006419
6420 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006421 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006422 /* bus width */
6423 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6424 "Width x1"),
6425 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006426 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006427 e_info("Intel(R) PRO/%s Network Connection\n",
6428 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006429 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6430 E1000_PBANUM_LENGTH);
6431 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006432 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006433 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6434 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006435}
6436
Auke Kok10aa4c02008-08-04 17:21:20 -07006437static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6438{
6439 struct e1000_hw *hw = &adapter->hw;
6440 int ret_val;
6441 u16 buf = 0;
6442
6443 if (hw->mac.type != e1000_82573)
6444 return;
6445
6446 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006447 le16_to_cpus(&buf);
6448 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006449 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006450 dev_warn(&adapter->pdev->dev,
6451 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006452 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006453}
6454
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006455static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006456 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006457{
6458 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006459 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006460
6461 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6462 adapter->flags |= FLAG_TSO_FORCE;
6463
6464 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006465 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6466 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006467 return 0;
6468
Ben Greear01840392012-02-11 15:39:25 +00006469 if (changed & NETIF_F_RXFCS) {
6470 if (features & NETIF_F_RXFCS) {
6471 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6472 } else {
6473 /* We need to take it back to defaults, which might mean
6474 * stripping is still disabled at the adapter level.
6475 */
6476 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6477 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6478 else
6479 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6480 }
6481 }
6482
Bruce Allan70495a52012-01-11 01:26:50 +00006483 netdev->features = features;
6484
Bruce Allandc221292011-08-19 03:23:48 +00006485 if (netif_running(netdev))
6486 e1000e_reinit_locked(adapter);
6487 else
6488 e1000e_reset(adapter);
6489
6490 return 0;
6491}
6492
Stephen Hemminger651c2462008-11-19 21:57:48 -08006493static const struct net_device_ops e1000e_netdev_ops = {
6494 .ndo_open = e1000_open,
6495 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006496 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006497 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006498 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006499 .ndo_set_mac_address = e1000_set_mac,
6500 .ndo_change_mtu = e1000_change_mtu,
6501 .ndo_do_ioctl = e1000_ioctl,
6502 .ndo_tx_timeout = e1000_tx_timeout,
6503 .ndo_validate_addr = eth_validate_addr,
6504
Stephen Hemminger651c2462008-11-19 21:57:48 -08006505 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6506 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6507#ifdef CONFIG_NET_POLL_CONTROLLER
6508 .ndo_poll_controller = e1000_netpoll,
6509#endif
Bruce Allandc221292011-08-19 03:23:48 +00006510 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006511};
6512
Auke Kokbc7f75f2007-09-17 12:30:59 -07006513/**
6514 * e1000_probe - Device Initialization Routine
6515 * @pdev: PCI device information struct
6516 * @ent: entry in e1000_pci_tbl
6517 *
6518 * Returns 0 on success, negative on failure
6519 *
6520 * e1000_probe initializes an adapter identified by a pci_dev structure.
6521 * The OS initialization, configuring of the adapter private structure,
6522 * and a hardware reset occur.
6523 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006524static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006525{
6526 struct net_device *netdev;
6527 struct e1000_adapter *adapter;
6528 struct e1000_hw *hw;
6529 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006530 resource_size_t mmio_start, mmio_len;
6531 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006532 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006533 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534 int i, err, pci_using_dac;
6535 u16 eeprom_data = 0;
6536 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6537
Bruce Allan78cd29d2011-03-24 03:09:03 +00006538 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6539 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006540 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006541 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6542 if (aspm_disable_flag)
6543 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006544
Bruce Allanf0f422e2008-08-04 17:21:53 -07006545 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006546 if (err)
6547 return err;
6548
6549 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006550 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006551 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006552 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006553 if (!err)
6554 pci_using_dac = 1;
6555 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006556 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006557 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006558 err = dma_set_coherent_mask(&pdev->dev,
6559 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006560 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006561 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006562 goto err_dma;
6563 }
6564 }
6565 }
6566
Arjan van de Vene8de1482008-10-22 19:55:31 -07006567 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allan55c5f552013-01-12 07:28:24 +00006568 pci_select_bars(pdev, IORESOURCE_MEM),
6569 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006570 if (err)
6571 goto err_pci_reg;
6572
Xiaotian Feng68eac462009-08-14 14:35:52 +00006573 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006574 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006575
Auke Kokbc7f75f2007-09-17 12:30:59 -07006576 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006577 /* PCI config space info */
6578 err = pci_save_state(pdev);
6579 if (err)
6580 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006581
6582 err = -ENOMEM;
6583 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6584 if (!netdev)
6585 goto err_alloc_etherdev;
6586
Auke Kokbc7f75f2007-09-17 12:30:59 -07006587 SET_NETDEV_DEV(netdev, &pdev->dev);
6588
Tom Herbertf85e4df2010-05-05 14:03:32 +00006589 netdev->irq = pdev->irq;
6590
Auke Kokbc7f75f2007-09-17 12:30:59 -07006591 pci_set_drvdata(pdev, netdev);
6592 adapter = netdev_priv(netdev);
6593 hw = &adapter->hw;
6594 adapter->netdev = netdev;
6595 adapter->pdev = pdev;
6596 adapter->ei = ei;
6597 adapter->pba = ei->pba;
6598 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006599 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006600 adapter->hw.adapter = adapter;
6601 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006602 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006603 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006604
6605 mmio_start = pci_resource_start(pdev, 0);
6606 mmio_len = pci_resource_len(pdev, 0);
6607
6608 err = -EIO;
6609 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6610 if (!adapter->hw.hw_addr)
6611 goto err_ioremap;
6612
6613 if ((adapter->flags & FLAG_HAS_FLASH) &&
6614 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6615 flash_start = pci_resource_start(pdev, 1);
6616 flash_len = pci_resource_len(pdev, 1);
6617 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6618 if (!adapter->hw.flash_address)
6619 goto err_flashmap;
6620 }
6621
6622 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006623 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006624 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006625 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006626 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006627 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006628
6629 netdev->mem_start = mmio_start;
6630 netdev->mem_end = mmio_start + mmio_len;
6631
6632 adapter->bd_number = cards_found++;
6633
Bruce Allan4662e822008-08-26 18:37:06 -07006634 e1000e_check_options(adapter);
6635
Auke Kokbc7f75f2007-09-17 12:30:59 -07006636 /* setup adapter struct */
6637 err = e1000_sw_init(adapter);
6638 if (err)
6639 goto err_sw_init;
6640
Auke Kokbc7f75f2007-09-17 12:30:59 -07006641 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6642 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6643 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6644
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006645 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006646 if (err)
6647 goto err_hw_init;
6648
Bruce Allan4a770352008-10-01 17:18:35 -07006649 if ((adapter->flags & FLAG_IS_ICH) &&
6650 (adapter->flags & FLAG_READ_ONLY_NVM))
6651 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6652
Auke Kokbc7f75f2007-09-17 12:30:59 -07006653 hw->mac.ops.get_bus_info(&adapter->hw);
6654
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006655 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006656
6657 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006658 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006659 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6660 adapter->hw.phy.disable_polarity_correction = 0;
6661 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6662 }
6663
Bruce Allan470a5422012-05-26 06:08:48 +00006664 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006665 dev_info(&pdev->dev,
6666 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006667
Bruce Allandc221292011-08-19 03:23:48 +00006668 /* Set initial default active device features */
6669 netdev->features = (NETIF_F_SG |
6670 NETIF_F_HW_VLAN_RX |
6671 NETIF_F_HW_VLAN_TX |
6672 NETIF_F_TSO |
6673 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006674 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006675 NETIF_F_RXCSUM |
6676 NETIF_F_HW_CSUM);
6677
6678 /* Set user-changeable features (subset of all device features) */
6679 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006680 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006681 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006682 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006683
6684 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6685 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6686
Bruce Allandc221292011-08-19 03:23:48 +00006687 netdev->vlan_features |= (NETIF_F_SG |
6688 NETIF_F_TSO |
6689 NETIF_F_TSO6 |
6690 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006691
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006692 netdev->priv_flags |= IFF_UNICAST_FLT;
6693
Yi Zou7b872a52010-09-22 17:57:58 +00006694 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006695 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006696 netdev->vlan_features |= NETIF_F_HIGHDMA;
6697 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006698
Auke Kokbc7f75f2007-09-17 12:30:59 -07006699 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6700 adapter->flags |= FLAG_MNG_PT_ENABLED;
6701
Bruce Allane921eb12012-11-28 09:28:37 +00006702 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006703 * put the device in a known good starting state
6704 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006705 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6706
Bruce Allane921eb12012-11-28 09:28:37 +00006707 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006708 * attempt. Let's give it a few tries
6709 */
6710 for (i = 0;; i++) {
6711 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6712 break;
6713 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006714 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006715 err = -EIO;
6716 goto err_eeprom;
6717 }
6718 }
6719
Auke Kok10aa4c02008-08-04 17:21:20 -07006720 e1000_eeprom_checks(adapter);
6721
Bruce Allan608f8a02010-01-13 02:04:58 +00006722 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006723 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006724 dev_err(&pdev->dev,
6725 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006726
6727 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006728
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006729 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006730 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006731 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006732 err = -EIO;
6733 goto err_eeprom;
6734 }
6735
6736 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006737 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006738 adapter->watchdog_timer.data = (unsigned long) adapter;
6739
6740 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006741 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006742 adapter->phy_info_timer.data = (unsigned long) adapter;
6743
6744 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6745 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006746 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6747 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006748 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006749
Auke Kokbc7f75f2007-09-17 12:30:59 -07006750 /* Initialize link parameters. User can change them with ethtool */
6751 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006752 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006753 adapter->hw.fc.requested_mode = e1000_fc_default;
6754 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006755 adapter->hw.phy.autoneg_advertised = 0x2f;
6756
6757 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006758 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6759 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006760
Bruce Allane921eb12012-11-28 09:28:37 +00006761 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006762 * the EEPROM, enable the ACPI Magic Packet filter
6763 */
6764 if (adapter->flags & FLAG_APME_IN_WUC) {
6765 /* APME bit in EEPROM is mapped to WUC.APME */
6766 eeprom_data = er32(WUC);
6767 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006768 if ((hw->mac.type > e1000_ich10lan) &&
6769 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006770 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006771 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6772 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6773 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006774 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6775 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006776 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006777 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6778 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006779 }
6780
6781 /* fetch WoL from EEPROM */
6782 if (eeprom_data & eeprom_apme_mask)
6783 adapter->eeprom_wol |= E1000_WUFC_MAG;
6784
Bruce Allane921eb12012-11-28 09:28:37 +00006785 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006786 * where the eeprom may be wrong or the board simply won't support
6787 * wake on lan on a particular port
6788 */
6789 if (!(adapter->flags & FLAG_HAS_WOL))
6790 adapter->eeprom_wol = 0;
6791
6792 /* initialize the wol settings based on the eeprom settings */
6793 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006794 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006795
Bruce Allan84527592008-11-21 17:00:22 -08006796 /* save off EEPROM version number */
6797 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6798
Auke Kokbc7f75f2007-09-17 12:30:59 -07006799 /* reset the hardware with the new settings */
6800 e1000e_reset(adapter);
6801
Bruce Allane921eb12012-11-28 09:28:37 +00006802 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006803 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006804 * under the control of the driver.
6805 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006806 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006807 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006808
Bruce Allanf2315bf2011-12-16 00:46:59 +00006809 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006810 err = register_netdev(netdev);
6811 if (err)
6812 goto err_register;
6813
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006814 /* carrier off reporting is important to ethtool even BEFORE open */
6815 netif_carrier_off(netdev);
6816
Bruce Alland89777b2013-01-19 01:09:58 +00006817 /* init PTP hardware clock */
6818 e1000e_ptp_init(adapter);
6819
Auke Kokbc7f75f2007-09-17 12:30:59 -07006820 e1000_print_device_info(adapter);
6821
Alan Sternf3ec4f82010-06-08 15:23:51 -04006822 if (pci_dev_run_wake(pdev))
6823 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006824
Auke Kokbc7f75f2007-09-17 12:30:59 -07006825 return 0;
6826
6827err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006828 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006829 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006830err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006831 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006832 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006833err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006834 kfree(adapter->tx_ring);
6835 kfree(adapter->rx_ring);
6836err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006837 if (adapter->hw.flash_address)
6838 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006839 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006840err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006841 iounmap(adapter->hw.hw_addr);
6842err_ioremap:
6843 free_netdev(netdev);
6844err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006845 pci_release_selected_regions(pdev,
6846 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006847err_pci_reg:
6848err_dma:
6849 pci_disable_device(pdev);
6850 return err;
6851}
6852
6853/**
6854 * e1000_remove - Device Removal Routine
6855 * @pdev: PCI device information struct
6856 *
6857 * e1000_remove is called by the PCI subsystem to alert the driver
6858 * that it should release a PCI device. The could be caused by a
6859 * Hot-Plug event, or because the driver is going to be removed from
6860 * memory.
6861 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006862static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006863{
6864 struct net_device *netdev = pci_get_drvdata(pdev);
6865 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006866 bool down = test_bit(__E1000_DOWN, &adapter->state);
6867
Bruce Alland89777b2013-01-19 01:09:58 +00006868 e1000e_ptp_remove(adapter);
6869
Bruce Allane921eb12012-11-28 09:28:37 +00006870 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006871 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006872 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006873 if (!down)
6874 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006875 del_timer_sync(&adapter->watchdog_timer);
6876 del_timer_sync(&adapter->phy_info_timer);
6877
Bruce Allan41cec6f2009-11-20 23:28:56 +00006878 cancel_work_sync(&adapter->reset_task);
6879 cancel_work_sync(&adapter->watchdog_task);
6880 cancel_work_sync(&adapter->downshift_task);
6881 cancel_work_sync(&adapter->update_phy_task);
6882 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006883
Bruce Allanb67e1912012-12-27 08:32:33 +00006884 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6885 cancel_work_sync(&adapter->tx_hwtstamp_work);
6886 if (adapter->tx_hwtstamp_skb) {
6887 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6888 adapter->tx_hwtstamp_skb = NULL;
6889 }
6890 }
6891
Bruce Allan17f208d2009-12-01 15:47:22 +00006892 if (!(netdev->flags & IFF_UP))
6893 e1000_power_down_phy(adapter);
6894
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006895 /* Don't lie to e1000_close() down the road. */
6896 if (!down)
6897 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006898 unregister_netdev(netdev);
6899
Alan Sternf3ec4f82010-06-08 15:23:51 -04006900 if (pci_dev_run_wake(pdev))
6901 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006902
Bruce Allane921eb12012-11-28 09:28:37 +00006903 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006904 * would have already happened in close and is redundant.
6905 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006906 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006907
Bruce Allan4662e822008-08-26 18:37:06 -07006908 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006909 kfree(adapter->tx_ring);
6910 kfree(adapter->rx_ring);
6911
6912 iounmap(adapter->hw.hw_addr);
6913 if (adapter->hw.flash_address)
6914 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006915 pci_release_selected_regions(pdev,
6916 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006917
6918 free_netdev(netdev);
6919
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006920 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006921 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006922
Auke Kokbc7f75f2007-09-17 12:30:59 -07006923 pci_disable_device(pdev);
6924}
6925
6926/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006927static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006928 .error_detected = e1000_io_error_detected,
6929 .slot_reset = e1000_io_slot_reset,
6930 .resume = e1000_io_resume,
6931};
6932
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006933static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6936 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006943
Auke Kokbc7f75f2007-09-17 12:30:59 -07006944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006948
Auke Kokbc7f75f2007-09-17 12:30:59 -07006949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006952
Bruce Allan4662e822008-08-26 18:37:06 -07006953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006956
Auke Kokbc7f75f2007-09-17 12:30:59 -07006957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6958 board_80003es2lan },
6959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6960 board_80003es2lan },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6962 board_80003es2lan },
6963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6964 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006965
Auke Kokbc7f75f2007-09-17 12:30:59 -07006966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006974
Auke Kokbc7f75f2007-09-17 12:30:59 -07006975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006980 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6984
6985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006988
Bruce Allanf4187b52008-08-26 18:36:50 -07006989 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6990 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006992
Bruce Allana4f58f52009-06-02 11:29:18 +00006993 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6997
Bruce Alland3738bb2010-06-16 13:27:28 +00006998 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6999 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
7000
Bruce Allan2fbe4522012-04-19 03:21:47 +00007001 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007003 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7004 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007005
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007006 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007007};
7008MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7009
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007010#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007011static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007012 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
7013 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
7014 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007015};
David S. Millere50208a2010-03-16 23:36:24 -07007016#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007017
Auke Kokbc7f75f2007-09-17 12:30:59 -07007018/* PCI Device API Driver */
7019static struct pci_driver e1000_driver = {
7020 .name = e1000e_driver_name,
7021 .id_table = e1000_pci_tbl,
7022 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007023 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007024#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007025 .driver = {
7026 .pm = &e1000_pm_ops,
7027 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007028#endif
7029 .shutdown = e1000_shutdown,
7030 .err_handler = &e1000_err_handler
7031};
7032
7033/**
7034 * e1000_init_module - Driver Registration Routine
7035 *
7036 * e1000_init_module is the first routine called when the driver is
7037 * loaded. All it does is register with the PCI subsystem.
7038 **/
7039static int __init e1000_init_module(void)
7040{
7041 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007042 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7043 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007044 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007045 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007046
Auke Kokbc7f75f2007-09-17 12:30:59 -07007047 return ret;
7048}
7049module_init(e1000_init_module);
7050
7051/**
7052 * e1000_exit_module - Driver Exit Cleanup Routine
7053 *
7054 * e1000_exit_module is called just before the driver is removed
7055 * from memory.
7056 **/
7057static void __exit e1000_exit_module(void)
7058{
7059 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007060}
7061module_exit(e1000_exit_module);
7062
7063
7064MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7065MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7066MODULE_LICENSE("GPL");
7067MODULE_VERSION(DRV_VERSION);
7068
Bruce Allan06c24b92012-02-23 03:13:13 +00007069/* netdev.c */