blob: 6fcf9e8008c0280e493810ef78a5d1a9f0dad4a4 [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 */
Bruce Allan4662e822008-08-26 18:37:06 -07002027 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2028 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2029 ew32(CTRL_EXT, ctrl_ext);
2030 e1e_flush();
2031}
2032
2033void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2034{
2035 if (adapter->msix_entries) {
2036 pci_disable_msix(adapter->pdev);
2037 kfree(adapter->msix_entries);
2038 adapter->msix_entries = NULL;
2039 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2040 pci_disable_msi(adapter->pdev);
2041 adapter->flags &= ~FLAG_MSI_ENABLED;
2042 }
Bruce Allan4662e822008-08-26 18:37:06 -07002043}
2044
2045/**
2046 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2047 *
2048 * Attempt to configure interrupts using the best available
2049 * capabilities of the hardware and kernel.
2050 **/
2051void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2052{
2053 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002054 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002055
2056 switch (adapter->int_mode) {
2057 case E1000E_INT_MODE_MSIX:
2058 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002059 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2060 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002061 sizeof(struct msix_entry),
2062 GFP_KERNEL);
2063 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002064 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002065 adapter->msix_entries[i].entry = i;
2066
2067 err = pci_enable_msix(adapter->pdev,
2068 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002069 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002070 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002071 return;
2072 }
2073 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002074 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002075 e1000e_reset_interrupt_capability(adapter);
2076 }
2077 adapter->int_mode = E1000E_INT_MODE_MSI;
2078 /* Fall through */
2079 case E1000E_INT_MODE_MSI:
2080 if (!pci_enable_msi(adapter->pdev)) {
2081 adapter->flags |= FLAG_MSI_ENABLED;
2082 } else {
2083 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002084 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002085 }
2086 /* Fall through */
2087 case E1000E_INT_MODE_LEGACY:
2088 /* Don't do anything; this is the system default */
2089 break;
2090 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002091
2092 /* store the number of vectors being used */
2093 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002094}
2095
2096/**
2097 * e1000_request_msix - Initialize MSI-X interrupts
2098 *
2099 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2100 * kernel.
2101 **/
2102static int e1000_request_msix(struct e1000_adapter *adapter)
2103{
2104 struct net_device *netdev = adapter->netdev;
2105 int err = 0, vector = 0;
2106
2107 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002108 snprintf(adapter->rx_ring->name,
2109 sizeof(adapter->rx_ring->name) - 1,
2110 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002111 else
2112 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2113 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002114 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002115 netdev);
2116 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002117 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002118 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2119 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002120 adapter->rx_ring->itr_val = adapter->itr;
2121 vector++;
2122
2123 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002124 snprintf(adapter->tx_ring->name,
2125 sizeof(adapter->tx_ring->name) - 1,
2126 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002127 else
2128 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2129 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002130 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002131 netdev);
2132 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002133 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002134 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2135 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002136 adapter->tx_ring->itr_val = adapter->itr;
2137 vector++;
2138
2139 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002140 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002141 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002142 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002143
2144 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002145
Bruce Allan4662e822008-08-26 18:37:06 -07002146 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002147}
2148
Bruce Allanf8d59f72008-08-08 18:36:11 -07002149/**
2150 * e1000_request_irq - initialize interrupts
2151 *
2152 * Attempts to configure interrupts using the best available
2153 * capabilities of the hardware and kernel.
2154 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002155static int e1000_request_irq(struct e1000_adapter *adapter)
2156{
2157 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002158 int err;
2159
Bruce Allan4662e822008-08-26 18:37:06 -07002160 if (adapter->msix_entries) {
2161 err = e1000_request_msix(adapter);
2162 if (!err)
2163 return err;
2164 /* fall back to MSI */
2165 e1000e_reset_interrupt_capability(adapter);
2166 adapter->int_mode = E1000E_INT_MODE_MSI;
2167 e1000e_set_interrupt_capability(adapter);
2168 }
2169 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002170 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002171 netdev->name, netdev);
2172 if (!err)
2173 return err;
2174
2175 /* fall back to legacy interrupt */
2176 e1000e_reset_interrupt_capability(adapter);
2177 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002178 }
2179
Joe Perchesa0607fd2009-11-18 23:29:17 -08002180 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002181 netdev->name, netdev);
2182 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002183 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002184
2185 return err;
2186}
2187
2188static void e1000_free_irq(struct e1000_adapter *adapter)
2189{
2190 struct net_device *netdev = adapter->netdev;
2191
Bruce Allan4662e822008-08-26 18:37:06 -07002192 if (adapter->msix_entries) {
2193 int vector = 0;
2194
2195 free_irq(adapter->msix_entries[vector].vector, netdev);
2196 vector++;
2197
2198 free_irq(adapter->msix_entries[vector].vector, netdev);
2199 vector++;
2200
2201 /* Other Causes interrupt vector */
2202 free_irq(adapter->msix_entries[vector].vector, netdev);
2203 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002204 }
Bruce Allan4662e822008-08-26 18:37:06 -07002205
2206 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207}
2208
2209/**
2210 * e1000_irq_disable - Mask off interrupt generation on the NIC
2211 **/
2212static void e1000_irq_disable(struct e1000_adapter *adapter)
2213{
2214 struct e1000_hw *hw = &adapter->hw;
2215
Auke Kokbc7f75f2007-09-17 12:30:59 -07002216 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002217 if (adapter->msix_entries)
2218 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002220
2221 if (adapter->msix_entries) {
2222 int i;
2223 for (i = 0; i < adapter->num_vectors; i++)
2224 synchronize_irq(adapter->msix_entries[i].vector);
2225 } else {
2226 synchronize_irq(adapter->pdev->irq);
2227 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228}
2229
2230/**
2231 * e1000_irq_enable - Enable default interrupt generation settings
2232 **/
2233static void e1000_irq_enable(struct e1000_adapter *adapter)
2234{
2235 struct e1000_hw *hw = &adapter->hw;
2236
Bruce Allan4662e822008-08-26 18:37:06 -07002237 if (adapter->msix_entries) {
2238 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2239 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002240 } else if (hw->mac.type == e1000_pch_lpt) {
2241 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002242 } else {
2243 ew32(IMS, IMS_ENABLE_MASK);
2244 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002245 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002246}
2247
2248/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002249 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250 * @adapter: address of board private structure
2251 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002252 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 * For ASF and Pass Through versions of f/w this means that
2254 * the driver is loaded. For AMT version (only with 82573)
2255 * of the f/w this means that the network i/f is open.
2256 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002257void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002258{
2259 struct e1000_hw *hw = &adapter->hw;
2260 u32 ctrl_ext;
2261 u32 swsm;
2262
2263 /* Let firmware know the driver has taken over */
2264 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2265 swsm = er32(SWSM);
2266 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2267 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2268 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002269 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 }
2271}
2272
2273/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002274 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002275 * @adapter: address of board private structure
2276 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002277 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002278 * For ASF and Pass Through versions of f/w this means that the
2279 * driver is no longer loaded. For AMT version (only with 82573) i
2280 * of the f/w this means that the network i/f is closed.
2281 *
2282 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002283void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002284{
2285 struct e1000_hw *hw = &adapter->hw;
2286 u32 ctrl_ext;
2287 u32 swsm;
2288
2289 /* Let firmware taken over control of h/w */
2290 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2291 swsm = er32(SWSM);
2292 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2293 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2294 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002295 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002296 }
2297}
2298
Auke Kokbc7f75f2007-09-17 12:30:59 -07002299/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002300 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002301 **/
2302static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2303 struct e1000_ring *ring)
2304{
2305 struct pci_dev *pdev = adapter->pdev;
2306
2307 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2308 GFP_KERNEL);
2309 if (!ring->desc)
2310 return -ENOMEM;
2311
2312 return 0;
2313}
2314
2315/**
2316 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002317 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318 *
2319 * Return 0 on success, negative on failure
2320 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002321int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322{
Bruce Allan55aa6982011-12-16 00:45:45 +00002323 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 int err = -ENOMEM, size;
2325
2326 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002327 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002328 if (!tx_ring->buffer_info)
2329 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330
2331 /* round up to nearest 4K */
2332 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2333 tx_ring->size = ALIGN(tx_ring->size, 4096);
2334
2335 err = e1000_alloc_ring_dma(adapter, tx_ring);
2336 if (err)
2337 goto err;
2338
2339 tx_ring->next_to_use = 0;
2340 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341
2342 return 0;
2343err:
2344 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002345 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002346 return err;
2347}
2348
2349/**
2350 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002351 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002352 *
2353 * Returns 0 on success, negative on failure
2354 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002355int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356{
Bruce Allan55aa6982011-12-16 00:45:45 +00002357 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002358 struct e1000_buffer *buffer_info;
2359 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360
2361 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002362 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363 if (!rx_ring->buffer_info)
2364 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365
Auke Kok47f44e42007-10-25 13:57:44 -07002366 for (i = 0; i < rx_ring->count; i++) {
2367 buffer_info = &rx_ring->buffer_info[i];
2368 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2369 sizeof(struct e1000_ps_page),
2370 GFP_KERNEL);
2371 if (!buffer_info->ps_pages)
2372 goto err_pages;
2373 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002374
2375 desc_len = sizeof(union e1000_rx_desc_packet_split);
2376
2377 /* Round up to nearest 4K */
2378 rx_ring->size = rx_ring->count * desc_len;
2379 rx_ring->size = ALIGN(rx_ring->size, 4096);
2380
2381 err = e1000_alloc_ring_dma(adapter, rx_ring);
2382 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002383 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384
2385 rx_ring->next_to_clean = 0;
2386 rx_ring->next_to_use = 0;
2387 rx_ring->rx_skb_top = NULL;
2388
2389 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002390
2391err_pages:
2392 for (i = 0; i < rx_ring->count; i++) {
2393 buffer_info = &rx_ring->buffer_info[i];
2394 kfree(buffer_info->ps_pages);
2395 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396err:
2397 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002398 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399 return err;
2400}
2401
2402/**
2403 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002404 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002406static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002407{
Bruce Allan55aa6982011-12-16 00:45:45 +00002408 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409 struct e1000_buffer *buffer_info;
2410 unsigned long size;
2411 unsigned int i;
2412
2413 for (i = 0; i < tx_ring->count; i++) {
2414 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002415 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 }
2417
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002418 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002419 size = sizeof(struct e1000_buffer) * tx_ring->count;
2420 memset(tx_ring->buffer_info, 0, size);
2421
2422 memset(tx_ring->desc, 0, tx_ring->size);
2423
2424 tx_ring->next_to_use = 0;
2425 tx_ring->next_to_clean = 0;
2426
Bruce Allanc5083cf2011-12-16 00:45:40 +00002427 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002428 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2429 e1000e_update_tdt_wa(tx_ring, 0);
2430 else
2431 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432}
2433
2434/**
2435 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002436 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 *
2438 * Free all transmit software resources
2439 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002440void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441{
Bruce Allan55aa6982011-12-16 00:45:45 +00002442 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444
Bruce Allan55aa6982011-12-16 00:45:45 +00002445 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446
2447 vfree(tx_ring->buffer_info);
2448 tx_ring->buffer_info = NULL;
2449
2450 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2451 tx_ring->dma);
2452 tx_ring->desc = NULL;
2453}
2454
2455/**
2456 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002457 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002458 *
2459 * Free all receive software resources
2460 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002461void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462{
Bruce Allan55aa6982011-12-16 00:45:45 +00002463 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002465 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002466
Bruce Allan55aa6982011-12-16 00:45:45 +00002467 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002469 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002470 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002471
Auke Kokbc7f75f2007-09-17 12:30:59 -07002472 vfree(rx_ring->buffer_info);
2473 rx_ring->buffer_info = NULL;
2474
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2476 rx_ring->dma);
2477 rx_ring->desc = NULL;
2478}
2479
2480/**
2481 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002482 * @adapter: pointer to adapter
2483 * @itr_setting: current adapter->itr
2484 * @packets: the number of packets during this measurement interval
2485 * @bytes: the number of bytes during this measurement interval
2486 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 * Stores a new ITR value based on packets and byte
2488 * counts during the last interrupt. The advantage of per interrupt
2489 * computation is faster updates and more accurate ITR for the current
2490 * traffic pattern. Constants in this function were computed
2491 * based on theoretical maximum wire speed and thresholds were set based
2492 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002493 * while increasing bulk throughput. This functionality is controlled
2494 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002496static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002497{
2498 unsigned int retval = itr_setting;
2499
2500 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002501 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502
2503 switch (itr_setting) {
2504 case lowest_latency:
2505 /* handle TSO and jumbo frames */
2506 if (bytes/packets > 8000)
2507 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002508 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 break;
2511 case low_latency: /* 50 usec aka 20000 ints/s */
2512 if (bytes > 10000) {
2513 /* this if handles the TSO accounting */
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002514 if (bytes/packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002516 else if ((packets < 10) || ((bytes/packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002518 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 retval = lowest_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 } else if (bytes/packets > 2000) {
2521 retval = bulk_latency;
2522 } else if (packets <= 2 && bytes < 512) {
2523 retval = lowest_latency;
2524 }
2525 break;
2526 case bulk_latency: /* 250 usec aka 4000 ints/s */
2527 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002528 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002529 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 } else if (bytes < 6000) {
2531 retval = low_latency;
2532 }
2533 break;
2534 }
2535
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536 return retval;
2537}
2538
2539static void e1000_set_itr(struct e1000_adapter *adapter)
2540{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 u16 current_itr;
2542 u32 new_itr = adapter->itr;
2543
2544 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2545 if (adapter->link_speed != SPEED_1000) {
2546 current_itr = 0;
2547 new_itr = 4000;
2548 goto set_itr_now;
2549 }
2550
Bruce Allan828bac82010-09-29 21:39:37 +00002551 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2552 new_itr = 0;
2553 goto set_itr_now;
2554 }
2555
Bruce Allan8bb62862013-01-16 08:46:49 +00002556 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2557 adapter->total_tx_packets,
2558 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002559 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2560 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2561 adapter->tx_itr = low_latency;
2562
Bruce Allan8bb62862013-01-16 08:46:49 +00002563 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2564 adapter->total_rx_packets,
2565 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2567 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2568 adapter->rx_itr = low_latency;
2569
2570 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2571
2572 switch (current_itr) {
2573 /* counts and packets in update_itr are dependent on these numbers */
2574 case lowest_latency:
2575 new_itr = 70000;
2576 break;
2577 case low_latency:
2578 new_itr = 20000; /* aka hwitr = ~200 */
2579 break;
2580 case bulk_latency:
2581 new_itr = 4000;
2582 break;
2583 default:
2584 break;
2585 }
2586
2587set_itr_now:
2588 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002589 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002590 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002591 * increasing
2592 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 new_itr = new_itr > adapter->itr ?
2594 min(adapter->itr + (new_itr >> 2), new_itr) :
2595 new_itr;
2596 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002597 adapter->rx_ring->itr_val = new_itr;
2598 if (adapter->msix_entries)
2599 adapter->rx_ring->set_itr = 1;
2600 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002601 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602 }
2603}
2604
2605/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002606 * e1000e_write_itr - write the ITR value to the appropriate registers
2607 * @adapter: address of board private structure
2608 * @itr: new ITR value to program
2609 *
2610 * e1000e_write_itr determines if the adapter is in MSI-X mode
2611 * and, if so, writes the EITR registers with the ITR value.
2612 * Otherwise, it writes the ITR value into the ITR register.
2613 **/
2614void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2615{
2616 struct e1000_hw *hw = &adapter->hw;
2617 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2618
2619 if (adapter->msix_entries) {
2620 int vector;
2621
2622 for (vector = 0; vector < adapter->num_vectors; vector++)
2623 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2624 } else {
2625 ew32(ITR, new_itr);
2626 }
2627}
2628
2629/**
Bruce Allan4662e822008-08-26 18:37:06 -07002630 * e1000_alloc_queues - Allocate memory for all rings
2631 * @adapter: board private structure to initialize
2632 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002633static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002634{
Bruce Allan55aa6982011-12-16 00:45:45 +00002635 int size = sizeof(struct e1000_ring);
2636
2637 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002638 if (!adapter->tx_ring)
2639 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002640 adapter->tx_ring->count = adapter->tx_ring_count;
2641 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002642
Bruce Allan55aa6982011-12-16 00:45:45 +00002643 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002644 if (!adapter->rx_ring)
2645 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002646 adapter->rx_ring->count = adapter->rx_ring_count;
2647 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002648
2649 return 0;
2650err:
2651 e_err("Unable to allocate memory for queues\n");
2652 kfree(adapter->rx_ring);
2653 kfree(adapter->tx_ring);
2654 return -ENOMEM;
2655}
2656
2657/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002658 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002659 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002660 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002662static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002664 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2665 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002666 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002668 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669
Wang Chen4cf16532008-11-12 23:38:14 -08002670 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671
Bruce Allanc58c8a72012-03-20 03:48:19 +00002672 if (!adapter->msix_entries ||
2673 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2674 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002675
Bruce Allanc58c8a72012-03-20 03:48:19 +00002676 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677
Alexander Duyck12d04a32009-03-25 22:05:03 +00002678 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002679 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002680
Bruce Allanc58c8a72012-03-20 03:48:19 +00002681 /* If weight not fully consumed, exit the polling mode */
2682 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683 if (adapter->itr_setting & 3)
2684 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002685 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002686 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2687 if (adapter->msix_entries)
2688 ew32(IMS, adapter->rx_ring->ims_val);
2689 else
2690 e1000_irq_enable(adapter);
2691 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002692 }
2693
2694 return work_done;
2695}
2696
Jiri Pirko8e586132011-12-08 19:52:37 -05002697static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698{
2699 struct e1000_adapter *adapter = netdev_priv(netdev);
2700 struct e1000_hw *hw = &adapter->hw;
2701 u32 vfta, index;
2702
2703 /* don't update vlan cookie if already programmed */
2704 if ((adapter->hw.mng_cookie.status &
2705 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2706 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002707 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002708
Auke Kokbc7f75f2007-09-17 12:30:59 -07002709 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002710 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2711 index = (vid >> 5) & 0x7F;
2712 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2713 vfta |= (1 << (vid & 0x1F));
2714 hw->mac.ops.write_vfta(hw, index, vfta);
2715 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002716
2717 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002718
2719 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002720}
2721
Jiri Pirko8e586132011-12-08 19:52:37 -05002722static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002723{
2724 struct e1000_adapter *adapter = netdev_priv(netdev);
2725 struct e1000_hw *hw = &adapter->hw;
2726 u32 vfta, index;
2727
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728 if ((adapter->hw.mng_cookie.status &
2729 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2730 (vid == adapter->mng_vlan_id)) {
2731 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002732 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002733 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002734 }
2735
2736 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002737 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2738 index = (vid >> 5) & 0x7F;
2739 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2740 vfta &= ~(1 << (vid & 0x1F));
2741 hw->mac.ops.write_vfta(hw, index, vfta);
2742 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002743
2744 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002745
2746 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002747}
2748
2749/**
2750 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2751 * @adapter: board private structure to initialize
2752 **/
2753static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2754{
2755 struct net_device *netdev = adapter->netdev;
2756 struct e1000_hw *hw = &adapter->hw;
2757 u32 rctl;
2758
2759 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2760 /* disable VLAN receive filtering */
2761 rctl = er32(RCTL);
2762 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2763 ew32(RCTL, rctl);
2764
2765 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2766 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2767 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2768 }
2769 }
2770}
2771
2772/**
2773 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2774 * @adapter: board private structure to initialize
2775 **/
2776static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2777{
2778 struct e1000_hw *hw = &adapter->hw;
2779 u32 rctl;
2780
2781 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2782 /* enable VLAN receive filtering */
2783 rctl = er32(RCTL);
2784 rctl |= E1000_RCTL_VFE;
2785 rctl &= ~E1000_RCTL_CFIEN;
2786 ew32(RCTL, rctl);
2787 }
2788}
2789
2790/**
2791 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2792 * @adapter: board private structure to initialize
2793 **/
2794static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2795{
2796 struct e1000_hw *hw = &adapter->hw;
2797 u32 ctrl;
2798
2799 /* disable VLAN tag insert/strip */
2800 ctrl = er32(CTRL);
2801 ctrl &= ~E1000_CTRL_VME;
2802 ew32(CTRL, ctrl);
2803}
2804
2805/**
2806 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2807 * @adapter: board private structure to initialize
2808 **/
2809static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2810{
2811 struct e1000_hw *hw = &adapter->hw;
2812 u32 ctrl;
2813
2814 /* enable VLAN tag insert/strip */
2815 ctrl = er32(CTRL);
2816 ctrl |= E1000_CTRL_VME;
2817 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818}
2819
2820static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2821{
2822 struct net_device *netdev = adapter->netdev;
2823 u16 vid = adapter->hw.mng_cookie.vlan_id;
2824 u16 old_vid = adapter->mng_vlan_id;
2825
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002826 if (adapter->hw.mng_cookie.status &
2827 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2828 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 adapter->mng_vlan_id = vid;
2830 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002832 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2833 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834}
2835
2836static void e1000_restore_vlan(struct e1000_adapter *adapter)
2837{
2838 u16 vid;
2839
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002840 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002842 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844}
2845
Bruce Allancd791612010-05-10 14:59:51 +00002846static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002847{
2848 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002849 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850
2851 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2852 return;
2853
2854 manc = er32(MANC);
2855
Bruce Allane921eb12012-11-28 09:28:37 +00002856 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002857 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002858 * the packets will be handled on SMBUS
2859 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860 manc |= E1000_MANC_EN_MNG2HOST;
2861 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002862
2863 switch (hw->mac.type) {
2864 default:
2865 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2866 break;
2867 case e1000_82574:
2868 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002869 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002870 * if so, enable it.
2871 */
2872 for (i = 0, j = 0; i < 8; i++) {
2873 mdef = er32(MDEF(i));
2874
2875 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002876 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002877 continue;
2878
2879 /* Enable this decision filter in MANC2H */
2880 if (mdef)
2881 manc2h |= (1 << i);
2882
2883 j |= mdef;
2884 }
2885
2886 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2887 break;
2888
2889 /* Create new decision filter in an empty filter */
2890 for (i = 0, j = 0; i < 8; i++)
2891 if (er32(MDEF(i)) == 0) {
2892 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2893 E1000_MDEF_PORT_664));
2894 manc2h |= (1 << 1);
2895 j++;
2896 break;
2897 }
2898
2899 if (!j)
2900 e_warn("Unable to create IPMI pass-through filter\n");
2901 break;
2902 }
2903
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904 ew32(MANC2H, manc2h);
2905 ew32(MANC, manc);
2906}
2907
2908/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002909 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002910 * @adapter: board private structure
2911 *
2912 * Configure the Tx unit of the MAC after a reset.
2913 **/
2914static void e1000_configure_tx(struct e1000_adapter *adapter)
2915{
2916 struct e1000_hw *hw = &adapter->hw;
2917 struct e1000_ring *tx_ring = adapter->tx_ring;
2918 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002919 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920
2921 /* Setup the HW Tx Head and Tail descriptor pointers */
2922 tdba = tx_ring->dma;
2923 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002924 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2925 ew32(TDBAH(0), (tdba >> 32));
2926 ew32(TDLEN(0), tdlen);
2927 ew32(TDH(0), 0);
2928 ew32(TDT(0), 0);
2929 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2930 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931
Auke Kokbc7f75f2007-09-17 12:30:59 -07002932 /* Set the Tx Interrupt Delay register */
2933 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002934 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935 ew32(TADV, adapter->tx_abs_int_delay);
2936
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002937 if (adapter->flags2 & FLAG2_DMA_BURST) {
2938 u32 txdctl = er32(TXDCTL(0));
2939 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2940 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002941 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002942 * hardware to use the bus more efficiently in bursts, depends
2943 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002944 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002945 * hthresh = 1 ==> prefetch when one or more available
2946 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2947 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002948 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002949 */
2950 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2951 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002952 }
Bruce Allan56032be2011-12-16 00:46:01 +00002953 /* erratum work around: set txdctl the same for both queues */
2954 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002955
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002957 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002958 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002959 * gigabit link later
2960 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961#define SPEED_MODE_BIT (1 << 21)
2962 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002963 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 }
2965
2966 /* errata: program both queues to unweighted RR */
2967 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002968 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002969 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002970 ew32(TARC(0), tarc);
2971 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002973 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 }
2975
Auke Kokbc7f75f2007-09-17 12:30:59 -07002976 /* Setup Transmit Descriptor Settings for eop descriptor */
2977 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2978
2979 /* only set IDE if we are delaying interrupts using the timers */
2980 if (adapter->tx_int_delay)
2981 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2982
2983 /* enable Report Status bit */
2984 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2985
Bruce Allan57cde762012-02-22 09:02:58 +00002986 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987}
2988
2989/**
2990 * e1000_setup_rctl - configure the receive control registers
2991 * @adapter: Board private structure
2992 **/
2993#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2994 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2995static void e1000_setup_rctl(struct e1000_adapter *adapter)
2996{
2997 struct e1000_hw *hw = &adapter->hw;
2998 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 u32 pages = 0;
3000
Bruce Allan2fbe4522012-04-19 03:21:47 +00003001 /* Workaround Si errata on PCHx - configure jumbo frame flow */
3002 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00003003 s32 ret_val;
3004
3005 if (adapter->netdev->mtu > ETH_DATA_LEN)
3006 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
3007 else
3008 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00003009
3010 if (ret_val)
3011 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003012 }
3013
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 /* Program MC offset vector base */
3015 rctl = er32(RCTL);
3016 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3017 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3018 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3019 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3020
3021 /* Do not Store bad packets */
3022 rctl &= ~E1000_RCTL_SBP;
3023
3024 /* Enable Long Packet receive */
3025 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3026 rctl &= ~E1000_RCTL_LPE;
3027 else
3028 rctl |= E1000_RCTL_LPE;
3029
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003030 /* Some systems expect that the CRC is included in SMBUS traffic. The
3031 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3032 * host memory when this is enabled
3033 */
3034 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3035 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003036
Bruce Allana4f58f52009-06-02 11:29:18 +00003037 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3038 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3039 u16 phy_data;
3040
3041 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3042 phy_data &= 0xfff8;
3043 phy_data |= (1 << 2);
3044 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3045
3046 e1e_rphy(hw, 22, &phy_data);
3047 phy_data &= 0x0fff;
3048 phy_data |= (1 << 14);
3049 e1e_wphy(hw, 0x10, 0x2823);
3050 e1e_wphy(hw, 0x11, 0x0003);
3051 e1e_wphy(hw, 22, phy_data);
3052 }
3053
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054 /* Setup buffer sizes */
3055 rctl &= ~E1000_RCTL_SZ_4096;
3056 rctl |= E1000_RCTL_BSEX;
3057 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003058 case 2048:
3059 default:
3060 rctl |= E1000_RCTL_SZ_2048;
3061 rctl &= ~E1000_RCTL_BSEX;
3062 break;
3063 case 4096:
3064 rctl |= E1000_RCTL_SZ_4096;
3065 break;
3066 case 8192:
3067 rctl |= E1000_RCTL_SZ_8192;
3068 break;
3069 case 16384:
3070 rctl |= E1000_RCTL_SZ_16384;
3071 break;
3072 }
3073
Bruce Allan5f450212011-07-22 06:21:46 +00003074 /* Enable Extended Status in all Receive Descriptors */
3075 rfctl = er32(RFCTL);
3076 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003077 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003078
Bruce Allane921eb12012-11-28 09:28:37 +00003079 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 * header is placed in skb->data and the packet data is
3081 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3082 * In the case of a non-split, skb->data is linearly filled,
3083 * followed by the page buffers. Therefore, skb->data is
3084 * sized to hold the largest protocol header.
3085 *
3086 * allocations using alloc_page take too long for regular MTU
3087 * so only enable packet split for jumbo frames
3088 *
3089 * Using pages when the page size is greater than 16k wastes
3090 * a lot of memory, since we allocate 3 pages at all times
3091 * per packet.
3092 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003094 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003096 else
3097 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003098
3099 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003100 u32 psrctl = 0;
3101
Auke Kok140a7482007-10-25 13:57:58 -07003102 /* Enable Packet split descriptors */
3103 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003104
3105 psrctl |= adapter->rx_ps_bsize0 >>
3106 E1000_PSRCTL_BSIZE0_SHIFT;
3107
3108 switch (adapter->rx_ps_pages) {
3109 case 3:
3110 psrctl |= PAGE_SIZE <<
3111 E1000_PSRCTL_BSIZE3_SHIFT;
3112 case 2:
3113 psrctl |= PAGE_SIZE <<
3114 E1000_PSRCTL_BSIZE2_SHIFT;
3115 case 1:
3116 psrctl |= PAGE_SIZE >>
3117 E1000_PSRCTL_BSIZE1_SHIFT;
3118 break;
3119 }
3120
3121 ew32(PSRCTL, psrctl);
3122 }
3123
Ben Greearcf955e62012-02-11 15:39:51 +00003124 /* This is useful for sniffing bad packets. */
3125 if (adapter->netdev->features & NETIF_F_RXALL) {
3126 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003127 * in e1000e_set_rx_mode
3128 */
Ben Greearcf955e62012-02-11 15:39:51 +00003129 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3130 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3131 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3132
3133 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3134 E1000_RCTL_DPF | /* Allow filtered pause */
3135 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3136 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3137 * and that breaks VLANs.
3138 */
3139 }
3140
Auke Kokbc7f75f2007-09-17 12:30:59 -07003141 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003142 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003143 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144}
3145
3146/**
3147 * e1000_configure_rx - Configure Receive Unit after Reset
3148 * @adapter: board private structure
3149 *
3150 * Configure the Rx unit of the MAC after a reset.
3151 **/
3152static void e1000_configure_rx(struct e1000_adapter *adapter)
3153{
3154 struct e1000_hw *hw = &adapter->hw;
3155 struct e1000_ring *rx_ring = adapter->rx_ring;
3156 u64 rdba;
3157 u32 rdlen, rctl, rxcsum, ctrl_ext;
3158
3159 if (adapter->rx_ps_pages) {
3160 /* this is a 32 byte descriptor */
3161 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003162 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 adapter->clean_rx = e1000_clean_rx_irq_ps;
3164 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003165 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003166 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003167 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3168 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003169 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003170 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171 adapter->clean_rx = e1000_clean_rx_irq;
3172 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3173 }
3174
3175 /* disable receives while setting up the descriptors */
3176 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003177 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3178 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003179 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003180 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003182 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003183 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003184 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003185 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003186 * granularity = 01
3187 * wthresh = 04,
3188 * hthresh = 04,
3189 * pthresh = 0x20
3190 */
3191 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3192 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3193
Bruce Allane921eb12012-11-28 09:28:37 +00003194 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003195 * the value was not set by the user via module options
3196 */
3197 if (adapter->rx_int_delay == DEFAULT_RDTR)
3198 adapter->rx_int_delay = BURST_RDTR;
3199 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3200 adapter->rx_abs_int_delay = BURST_RADV;
3201 }
3202
Auke Kokbc7f75f2007-09-17 12:30:59 -07003203 /* set the Receive Delay Timer Register */
3204 ew32(RDTR, adapter->rx_int_delay);
3205
3206 /* irq moderation */
3207 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003208 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003209 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210
3211 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003212 /* Auto-Mask interrupts upon ICR access */
3213 ctrl_ext |= E1000_CTRL_EXT_IAME;
3214 ew32(IAM, 0xffffffff);
3215 ew32(CTRL_EXT, ctrl_ext);
3216 e1e_flush();
3217
Bruce Allane921eb12012-11-28 09:28:37 +00003218 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003219 * the Base and Length of the Rx Descriptor Ring
3220 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003222 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3223 ew32(RDBAH(0), (rdba >> 32));
3224 ew32(RDLEN(0), rdlen);
3225 ew32(RDH(0), 0);
3226 ew32(RDT(0), 0);
3227 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3228 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003229
3230 /* Enable Receive Checksum Offload for TCP and UDP */
3231 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003232 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003233 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003234 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003235 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236 ew32(RXCSUM, rxcsum);
3237
Bruce Allan3e35d992013-01-12 07:25:22 +00003238 /* With jumbo frames, excessive C-state transition latencies result
3239 * in dropped transactions.
3240 */
3241 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3242 u32 lat =
3243 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3244 adapter->max_frame_size) * 8 / 1000;
3245
3246 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003247 u32 rxdctl = er32(RXDCTL(0));
3248 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003249 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003250
3251 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3252 } else {
3253 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3254 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003255 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003256
3257 /* Enable Receives */
3258 ew32(RCTL, rctl);
3259}
3260
3261/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003262 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263 * @netdev: network interface device structure
3264 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003265 * Writes multicast address list to the MTA hash table.
3266 * Returns: -ENOMEM on failure
3267 * 0 on no addresses written
3268 * X on writing X addresses to MTA
3269 */
3270static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003271{
3272 struct e1000_adapter *adapter = netdev_priv(netdev);
3273 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003274 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003275 u8 *mta_list;
3276 int i;
3277
3278 if (netdev_mc_empty(netdev)) {
3279 /* nothing to program, so clear mc list */
3280 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3281 return 0;
3282 }
3283
3284 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3285 if (!mta_list)
3286 return -ENOMEM;
3287
3288 /* update_mc_addr_list expects a packed array of only addresses. */
3289 i = 0;
3290 netdev_for_each_mc_addr(ha, netdev)
3291 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
3292
3293 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3294 kfree(mta_list);
3295
3296 return netdev_mc_count(netdev);
3297}
3298
3299/**
3300 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3301 * @netdev: network interface device structure
3302 *
3303 * Writes unicast address list to the RAR table.
3304 * Returns: -ENOMEM on failure/insufficient address space
3305 * 0 on no addresses written
3306 * X on writing X addresses to the RAR table
3307 **/
3308static int e1000e_write_uc_addr_list(struct net_device *netdev)
3309{
3310 struct e1000_adapter *adapter = netdev_priv(netdev);
3311 struct e1000_hw *hw = &adapter->hw;
3312 unsigned int rar_entries = hw->mac.rar_entry_count;
3313 int count = 0;
3314
3315 /* save a rar entry for our hardware address */
3316 rar_entries--;
3317
3318 /* save a rar entry for the LAA workaround */
3319 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3320 rar_entries--;
3321
3322 /* return ENOMEM indicating insufficient memory for addresses */
3323 if (netdev_uc_count(netdev) > rar_entries)
3324 return -ENOMEM;
3325
3326 if (!netdev_uc_empty(netdev) && rar_entries) {
3327 struct netdev_hw_addr *ha;
3328
Bruce Allane921eb12012-11-28 09:28:37 +00003329 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003330 * combining
3331 */
3332 netdev_for_each_uc_addr(ha, netdev) {
3333 if (!rar_entries)
3334 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003335 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003336 count++;
3337 }
3338 }
3339
3340 /* zero out the remaining RAR entries not used above */
3341 for (; rar_entries > 0; rar_entries--) {
3342 ew32(RAH(rar_entries), 0);
3343 ew32(RAL(rar_entries), 0);
3344 }
3345 e1e_flush();
3346
3347 return count;
3348}
3349
3350/**
3351 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3352 * @netdev: network interface device structure
3353 *
3354 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3355 * address list or the network interface flags are updated. This routine is
3356 * responsible for configuring the hardware for proper unicast, multicast,
3357 * promiscuous mode, and all-multi behavior.
3358 **/
3359static void e1000e_set_rx_mode(struct net_device *netdev)
3360{
3361 struct e1000_adapter *adapter = netdev_priv(netdev);
3362 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003364
3365 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003366 rctl = er32(RCTL);
3367
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003368 /* clear the affected bits */
3369 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3370
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371 if (netdev->flags & IFF_PROMISC) {
3372 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003373 /* Do not hardware filter VLANs in promisc mode */
3374 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003376 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003377
Patrick McHardy746b9f02008-07-16 20:15:45 -07003378 if (netdev->flags & IFF_ALLMULTI) {
3379 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003380 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003381 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003382 * then we should just turn on promiscuous mode so
3383 * that we can at least receive multicast traffic
3384 */
3385 count = e1000e_write_mc_addr_list(netdev);
3386 if (count < 0)
3387 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003388 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003389 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003390 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003391 * sufficient space to store all the addresses then enable
3392 * unicast promiscuous mode
3393 */
3394 count = e1000e_write_uc_addr_list(netdev);
3395 if (count < 0)
3396 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003397 }
3398
3399 ew32(RCTL, rctl);
3400
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003401 if (netdev->features & NETIF_F_HW_VLAN_RX)
3402 e1000e_vlan_strip_enable(adapter);
3403 else
3404 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003405}
3406
Bruce Allan70495a52012-01-11 01:26:50 +00003407static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3408{
3409 struct e1000_hw *hw = &adapter->hw;
3410 u32 mrqc, rxcsum;
3411 int i;
3412 static const u32 rsskey[10] = {
3413 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3414 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3415 };
3416
3417 /* Fill out hash function seed */
3418 for (i = 0; i < 10; i++)
3419 ew32(RSSRK(i), rsskey[i]);
3420
3421 /* Direct all traffic to queue 0 */
3422 for (i = 0; i < 32; i++)
3423 ew32(RETA(i), 0);
3424
Bruce Allane921eb12012-11-28 09:28:37 +00003425 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003426 * descriptor on writeback.
3427 */
3428 rxcsum = er32(RXCSUM);
3429 rxcsum |= E1000_RXCSUM_PCSD;
3430
3431 ew32(RXCSUM, rxcsum);
3432
3433 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3434 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3435 E1000_MRQC_RSS_FIELD_IPV6 |
3436 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3437 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3438
3439 ew32(MRQC, mrqc);
3440}
3441
Auke Kokbc7f75f2007-09-17 12:30:59 -07003442/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003443 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3444 * @adapter: board private structure
3445 * @timinca: pointer to returned time increment attributes
3446 *
3447 * Get attributes for incrementing the System Time Register SYSTIML/H at
3448 * the default base frequency, and set the cyclecounter shift value.
3449 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003450s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003451{
3452 struct e1000_hw *hw = &adapter->hw;
3453 u32 incvalue, incperiod, shift;
3454
3455 /* Make sure clock is enabled on I217 before checking the frequency */
3456 if ((hw->mac.type == e1000_pch_lpt) &&
3457 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3458 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3459 u32 fextnvm7 = er32(FEXTNVM7);
3460
3461 if (!(fextnvm7 & (1 << 0))) {
3462 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3463 e1e_flush();
3464 }
3465 }
3466
3467 switch (hw->mac.type) {
3468 case e1000_pch2lan:
3469 case e1000_pch_lpt:
3470 /* On I217, the clock frequency is 25MHz or 96MHz as
3471 * indicated by the System Clock Frequency Indication
3472 */
3473 if ((hw->mac.type != e1000_pch_lpt) ||
3474 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3475 /* Stable 96MHz frequency */
3476 incperiod = INCPERIOD_96MHz;
3477 incvalue = INCVALUE_96MHz;
3478 shift = INCVALUE_SHIFT_96MHz;
3479 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3480 break;
3481 }
3482 /* fall-through */
3483 case e1000_82574:
3484 case e1000_82583:
3485 /* Stable 25MHz frequency */
3486 incperiod = INCPERIOD_25MHz;
3487 incvalue = INCVALUE_25MHz;
3488 shift = INCVALUE_SHIFT_25MHz;
3489 adapter->cc.shift = shift;
3490 break;
3491 default:
3492 return -EINVAL;
3493 }
3494
3495 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3496 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3497
3498 return 0;
3499}
3500
3501/**
3502 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3503 * @adapter: board private structure
3504 *
3505 * Outgoing time stamping can be enabled and disabled. Play nice and
3506 * disable it when requested, although it shouldn't cause any overhead
3507 * when no packet needs it. At most one packet in the queue may be
3508 * marked for time stamping, otherwise it would be impossible to tell
3509 * for sure to which packet the hardware time stamp belongs.
3510 *
3511 * Incoming time stamping has to be configured via the hardware filters.
3512 * Not all combinations are supported, in particular event type has to be
3513 * specified. Matching the kind of event packet is not supported, with the
3514 * exception of "all V2 events regardless of level 2 or 4".
3515 **/
3516static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3517{
3518 struct e1000_hw *hw = &adapter->hw;
3519 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3520 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3521 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003522 u32 rxmtrl = 0;
3523 u16 rxudp = 0;
3524 bool is_l4 = false;
3525 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003526 u32 regval;
3527 s32 ret_val;
3528
3529 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3530 return -EINVAL;
3531
3532 /* flags reserved for future extensions - must be zero */
3533 if (config->flags)
3534 return -EINVAL;
3535
3536 switch (config->tx_type) {
3537 case HWTSTAMP_TX_OFF:
3538 tsync_tx_ctl = 0;
3539 break;
3540 case HWTSTAMP_TX_ON:
3541 break;
3542 default:
3543 return -ERANGE;
3544 }
3545
3546 switch (config->rx_filter) {
3547 case HWTSTAMP_FILTER_NONE:
3548 tsync_rx_ctl = 0;
3549 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003550 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3551 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3552 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3553 is_l4 = true;
3554 break;
3555 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3556 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3557 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3558 is_l4 = true;
3559 break;
3560 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3561 /* Also time stamps V2 L2 Path Delay Request/Response */
3562 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3563 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3564 is_l2 = true;
3565 break;
3566 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3567 /* Also time stamps V2 L2 Path Delay Request/Response. */
3568 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3569 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3570 is_l2 = true;
3571 break;
3572 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3573 /* Hardware cannot filter just V2 L4 Sync messages;
3574 * fall-through to V2 (both L2 and L4) Sync.
3575 */
3576 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3577 /* Also time stamps V2 Path Delay Request/Response. */
3578 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3579 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3580 is_l2 = true;
3581 is_l4 = true;
3582 break;
3583 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3584 /* Hardware cannot filter just V2 L4 Delay Request messages;
3585 * fall-through to V2 (both L2 and L4) Delay Request.
3586 */
3587 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3588 /* Also time stamps V2 Path Delay Request/Response. */
3589 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3590 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3591 is_l2 = true;
3592 is_l4 = true;
3593 break;
3594 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3595 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3596 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3597 * fall-through to all V2 (both L2 and L4) Events.
3598 */
3599 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3600 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3601 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3602 is_l2 = true;
3603 is_l4 = true;
3604 break;
3605 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3606 /* For V1, the hardware can only filter Sync messages or
3607 * Delay Request messages but not both so fall-through to
3608 * time stamp all packets.
3609 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003610 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003611 is_l2 = true;
3612 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003613 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3614 config->rx_filter = HWTSTAMP_FILTER_ALL;
3615 break;
3616 default:
3617 return -ERANGE;
3618 }
3619
3620 /* enable/disable Tx h/w time stamping */
3621 regval = er32(TSYNCTXCTL);
3622 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3623 regval |= tsync_tx_ctl;
3624 ew32(TSYNCTXCTL, regval);
3625 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3626 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3627 e_err("Timesync Tx Control register not set as expected\n");
3628 return -EAGAIN;
3629 }
3630
3631 /* enable/disable Rx h/w time stamping */
3632 regval = er32(TSYNCRXCTL);
3633 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3634 regval |= tsync_rx_ctl;
3635 ew32(TSYNCRXCTL, regval);
3636 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3637 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3638 (regval & (E1000_TSYNCRXCTL_ENABLED |
3639 E1000_TSYNCRXCTL_TYPE_MASK))) {
3640 e_err("Timesync Rx Control register not set as expected\n");
3641 return -EAGAIN;
3642 }
3643
Bruce Alland89777b2013-01-19 01:09:58 +00003644 /* L2: define ethertype filter for time stamped packets */
3645 if (is_l2)
3646 rxmtrl |= ETH_P_1588;
3647
3648 /* define which PTP packets get time stamped */
3649 ew32(RXMTRL, rxmtrl);
3650
3651 /* Filter by destination port */
3652 if (is_l4) {
3653 rxudp = PTP_EV_PORT;
3654 cpu_to_be16s(&rxudp);
3655 }
3656 ew32(RXUDP, rxudp);
3657
3658 e1e_flush();
3659
Bruce Allanb67e1912012-12-27 08:32:33 +00003660 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003661 er32(RXSTMPH);
3662 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003663
3664 /* Get and set the System Time Register SYSTIM base frequency */
3665 ret_val = e1000e_get_base_timinca(adapter, &regval);
3666 if (ret_val)
3667 return ret_val;
3668 ew32(TIMINCA, regval);
3669
3670 /* reset the ns time counter */
3671 timecounter_init(&adapter->tc, &adapter->cc,
3672 ktime_to_ns(ktime_get_real()));
3673
3674 return 0;
3675}
3676
3677/**
Bruce Allanad680762008-03-28 09:15:03 -07003678 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679 * @adapter: private board structure
3680 **/
3681static void e1000_configure(struct e1000_adapter *adapter)
3682{
Bruce Allan55aa6982011-12-16 00:45:45 +00003683 struct e1000_ring *rx_ring = adapter->rx_ring;
3684
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003685 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686
3687 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003688 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003689
3690 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003691
3692 if (adapter->netdev->features & NETIF_F_RXHASH)
3693 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694 e1000_setup_rctl(adapter);
3695 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003696 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003697}
3698
3699/**
3700 * e1000e_power_up_phy - restore link in case the phy was powered down
3701 * @adapter: address of board private structure
3702 *
3703 * The phy may be powered down to save power and turn off link when the
3704 * driver is unloaded and wake on lan is not enabled (among others)
3705 * *** this routine MUST be followed by a call to e1000e_reset ***
3706 **/
3707void e1000e_power_up_phy(struct e1000_adapter *adapter)
3708{
Bruce Allan17f208d2009-12-01 15:47:22 +00003709 if (adapter->hw.phy.ops.power_up)
3710 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003711
3712 adapter->hw.mac.ops.setup_link(&adapter->hw);
3713}
3714
3715/**
3716 * e1000_power_down_phy - Power down the PHY
3717 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003718 * Power down the PHY so no link is implied when interface is down.
3719 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720 */
3721static void e1000_power_down_phy(struct e1000_adapter *adapter)
3722{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003723 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003724 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003725 return;
3726
Bruce Allan17f208d2009-12-01 15:47:22 +00003727 if (adapter->hw.phy.ops.power_down)
3728 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003729}
3730
3731/**
3732 * e1000e_reset - bring the hardware into a known good state
3733 *
3734 * This function boots the hardware and enables some settings that
3735 * require a configuration cycle of the hardware - those cannot be
3736 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003737 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003738 */
3739void e1000e_reset(struct e1000_adapter *adapter)
3740{
3741 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003742 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 struct e1000_hw *hw = &adapter->hw;
3744 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003745 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003746 u16 hwm;
3747
Bruce Allanad680762008-03-28 09:15:03 -07003748 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003749 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003750
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003751 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003752 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753 * large enough to accommodate two full transmit packets,
3754 * rounded up to the next 1KB and expressed in KB. Likewise,
3755 * the Rx FIFO should be large enough to accommodate at least
3756 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003757 * expressed in KB.
3758 */
Auke Kokdf762462007-10-25 13:57:53 -07003759 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003761 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003763 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003764 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003765 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003766 */
3767 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 sizeof(struct e1000_tx_desc) -
3769 ETH_FCS_LEN) * 2;
3770 min_tx_space = ALIGN(min_tx_space, 1024);
3771 min_tx_space >>= 10;
3772 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003773 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774 min_rx_space = ALIGN(min_rx_space, 1024);
3775 min_rx_space >>= 10;
3776
Bruce Allane921eb12012-11-28 09:28:37 +00003777 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003779 * allocation, take space away from current Rx allocation
3780 */
Auke Kokdf762462007-10-25 13:57:53 -07003781 if ((tx_space < min_tx_space) &&
3782 ((min_tx_space - tx_space) < pba)) {
3783 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003784
Bruce Allane921eb12012-11-28 09:28:37 +00003785 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003786 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003787 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003788 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003789 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003790 }
Auke Kokdf762462007-10-25 13:57:53 -07003791
3792 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003793 }
3794
Bruce Allane921eb12012-11-28 09:28:37 +00003795 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003796 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003797 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003798 * (or the size used for early receive) above it in the Rx FIFO.
3799 * Set it to the lower of:
3800 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003801 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003802 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003803 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3804 fc->pause_time = 0xFFFF;
3805 else
3806 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003807 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003808 fc->current_mode = fc->requested_mode;
3809
3810 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003811 case e1000_ich9lan:
3812 case e1000_ich10lan:
3813 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3814 pba = 14;
3815 ew32(PBA, pba);
3816 fc->high_water = 0x2800;
3817 fc->low_water = fc->high_water - 8;
3818 break;
3819 }
3820 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003821 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003822 hwm = min(((pba << 10) * 9 / 10),
3823 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003824
3825 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3826 fc->low_water = fc->high_water - 8;
3827 break;
3828 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003829 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003830 * loads. If hangs persist, try disabling Tx flow control.
3831 */
3832 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3833 fc->high_water = 0x3500;
3834 fc->low_water = 0x1500;
3835 } else {
3836 fc->high_water = 0x5000;
3837 fc->low_water = 0x3000;
3838 }
Bruce Allana3055952010-05-10 15:02:12 +00003839 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003840 break;
3841 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003842 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003843 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003844
3845 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3846 fc->high_water = 0x05C20;
3847 fc->low_water = 0x05048;
3848 fc->pause_time = 0x0650;
3849 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003850 }
Bruce Allan347b5202012-12-08 00:35:35 +00003851
3852 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3853 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003854 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003855 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003856
Bruce Allane921eb12012-11-28 09:28:37 +00003857 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003858 * maximum size per Tx descriptor limited only to the transmit
3859 * allocation of the packet buffer minus 96 bytes with an upper
3860 * limit of 24KB due to receive synchronization limitations.
3861 */
3862 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3863 24 << 10);
3864
Bruce Allane921eb12012-11-28 09:28:37 +00003865 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003866 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003867 */
3868 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003869 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003870 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3871 dev_info(&adapter->pdev->dev,
3872 "Interrupt Throttle Rate turned off\n");
3873 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003874 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003875 }
3876 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3877 dev_info(&adapter->pdev->dev,
3878 "Interrupt Throttle Rate turned on\n");
3879 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3880 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003881 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003882 }
3883 }
3884
Auke Kokbc7f75f2007-09-17 12:30:59 -07003885 /* Allow time for pending master requests to run */
3886 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003887
Bruce Allane921eb12012-11-28 09:28:37 +00003888 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003889 * that the network interface is in control
3890 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003891 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003892 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003893
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894 ew32(WUC, 0);
3895
3896 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003897 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003898
3899 e1000_update_mng_vlan(adapter);
3900
3901 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3902 ew32(VET, ETH_P_8021Q);
3903
3904 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003905
Bruce Allanb67e1912012-12-27 08:32:33 +00003906 /* initialize systim and reset the ns time counter */
3907 e1000e_config_hwtstamp(adapter);
3908
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003909 if (!netif_running(adapter->netdev) &&
3910 !test_bit(__E1000_TESTING, &adapter->state)) {
3911 e1000_power_down_phy(adapter);
3912 return;
3913 }
3914
Auke Kokbc7f75f2007-09-17 12:30:59 -07003915 e1000_get_phy_info(hw);
3916
Bruce Allan918d7192009-06-02 11:28:20 +00003917 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3918 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003919 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003920 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003922 * different we would do if it failed
3923 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003924 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3925 phy_data &= ~IGP02E1000_PM_SPD;
3926 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3927 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003928}
3929
3930int e1000e_up(struct e1000_adapter *adapter)
3931{
3932 struct e1000_hw *hw = &adapter->hw;
3933
3934 /* hardware has been reset, we need to reload some things */
3935 e1000_configure(adapter);
3936
3937 clear_bit(__E1000_DOWN, &adapter->state);
3938
Bruce Allan4662e822008-08-26 18:37:06 -07003939 if (adapter->msix_entries)
3940 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 e1000_irq_enable(adapter);
3942
Bruce Allan400484f2011-05-13 07:20:03 +00003943 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003944
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003946 if (adapter->msix_entries)
3947 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3948 else
3949 ew32(ICS, E1000_ICS_LSC);
3950
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951 return 0;
3952}
3953
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003954static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3955{
3956 struct e1000_hw *hw = &adapter->hw;
3957
3958 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3959 return;
3960
3961 /* flush pending descriptor writebacks to memory */
3962 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3963 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3964
3965 /* execute the writes immediately */
3966 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003967
Bruce Allane921eb12012-11-28 09:28:37 +00003968 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003969 * write is successful
3970 */
3971 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3972 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3973
3974 /* execute the writes immediately */
3975 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003976}
3977
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003978static void e1000e_update_stats(struct e1000_adapter *adapter);
3979
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980void e1000e_down(struct e1000_adapter *adapter)
3981{
3982 struct net_device *netdev = adapter->netdev;
3983 struct e1000_hw *hw = &adapter->hw;
3984 u32 tctl, rctl;
3985
Bruce Allane921eb12012-11-28 09:28:37 +00003986 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003987 * reschedule our watchdog timer
3988 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 set_bit(__E1000_DOWN, &adapter->state);
3990
3991 /* disable receives in the hardware */
3992 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003993 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3994 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995 /* flush and sleep below */
3996
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003997 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998
3999 /* disable transmits in the hardware */
4000 tctl = er32(TCTL);
4001 tctl &= ~E1000_TCTL_EN;
4002 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07004003
Auke Kokbc7f75f2007-09-17 12:30:59 -07004004 /* flush both disables and wait for them to finish */
4005 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00004006 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004007
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 e1000_irq_disable(adapter);
4009
4010 del_timer_sync(&adapter->watchdog_timer);
4011 del_timer_sync(&adapter->phy_info_timer);
4012
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004014
4015 spin_lock(&adapter->stats64_lock);
4016 e1000e_update_stats(adapter);
4017 spin_unlock(&adapter->stats64_lock);
4018
Bruce Allan400484f2011-05-13 07:20:03 +00004019 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004020 e1000_clean_tx_ring(adapter->tx_ring);
4021 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004022
Auke Kokbc7f75f2007-09-17 12:30:59 -07004023 adapter->link_speed = 0;
4024 adapter->link_duplex = 0;
4025
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004026 if (!pci_channel_offline(adapter->pdev))
4027 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004028
Bruce Allane921eb12012-11-28 09:28:37 +00004029 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004030 * pci_disable_device here.
4031 */
4032}
4033
4034void e1000e_reinit_locked(struct e1000_adapter *adapter)
4035{
4036 might_sleep();
4037 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004038 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 e1000e_down(adapter);
4040 e1000e_up(adapter);
4041 clear_bit(__E1000_RESETTING, &adapter->state);
4042}
4043
4044/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004045 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4046 * @cc: cyclecounter structure
4047 **/
4048static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4049{
4050 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4051 cc);
4052 struct e1000_hw *hw = &adapter->hw;
4053 cycle_t systim;
4054
4055 /* latch SYSTIMH on read of SYSTIML */
4056 systim = (cycle_t)er32(SYSTIML);
4057 systim |= (cycle_t)er32(SYSTIMH) << 32;
4058
4059 return systim;
4060}
4061
4062/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004063 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4064 * @adapter: board private structure to initialize
4065 *
4066 * e1000_sw_init initializes the Adapter private data structure.
4067 * Fields are initialized based on PCI device information and
4068 * OS network device settings (MTU size).
4069 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004070static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072 struct net_device *netdev = adapter->netdev;
4073
4074 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4075 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004076 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4077 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004078 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4079 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004080
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004081 spin_lock_init(&adapter->stats64_lock);
4082
Bruce Allan4662e822008-08-26 18:37:06 -07004083 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084
Bruce Allan4662e822008-08-26 18:37:06 -07004085 if (e1000_alloc_queues(adapter))
4086 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087
Bruce Allanb67e1912012-12-27 08:32:33 +00004088 /* Setup hardware time stamping cyclecounter */
4089 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4090 adapter->cc.read = e1000e_cyclecounter_read;
4091 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4092 adapter->cc.mult = 1;
4093 /* cc.shift set in e1000e_get_base_tininca() */
4094
4095 spin_lock_init(&adapter->systim_lock);
4096 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4097 }
4098
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004100 e1000_irq_disable(adapter);
4101
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102 set_bit(__E1000_DOWN, &adapter->state);
4103 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004104}
4105
4106/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004107 * e1000_intr_msi_test - Interrupt Handler
4108 * @irq: interrupt number
4109 * @data: pointer to a network interface device structure
4110 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004111static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004112{
4113 struct net_device *netdev = data;
4114 struct e1000_adapter *adapter = netdev_priv(netdev);
4115 struct e1000_hw *hw = &adapter->hw;
4116 u32 icr = er32(ICR);
4117
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004118 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004119 if (icr & E1000_ICR_RXSEQ) {
4120 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004121 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004122 * interrupt is handled.
4123 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004124 wmb();
4125 }
4126
4127 return IRQ_HANDLED;
4128}
4129
4130/**
4131 * e1000_test_msi_interrupt - Returns 0 for successful test
4132 * @adapter: board private struct
4133 *
4134 * code flow taken from tg3.c
4135 **/
4136static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4137{
4138 struct net_device *netdev = adapter->netdev;
4139 struct e1000_hw *hw = &adapter->hw;
4140 int err;
4141
4142 /* poll_enable hasn't been called yet, so don't need disable */
4143 /* clear any pending events */
4144 er32(ICR);
4145
4146 /* free the real vector and request a test handler */
4147 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004148 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004149
4150 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004151 * MSI irq handler will unset this flag
4152 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004153 adapter->flags |= FLAG_MSI_TEST_FAILED;
4154
4155 err = pci_enable_msi(adapter->pdev);
4156 if (err)
4157 goto msi_test_failed;
4158
Joe Perchesa0607fd2009-11-18 23:29:17 -08004159 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004160 netdev->name, netdev);
4161 if (err) {
4162 pci_disable_msi(adapter->pdev);
4163 goto msi_test_failed;
4164 }
4165
Bruce Allane921eb12012-11-28 09:28:37 +00004166 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004167 * interrupt.
4168 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004169 wmb();
4170
4171 e1000_irq_enable(adapter);
4172
4173 /* fire an unusual interrupt on the test handler */
4174 ew32(ICS, E1000_ICS_RXSEQ);
4175 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004176 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004177
4178 e1000_irq_disable(adapter);
4179
Bruce Allanbc763292012-08-17 06:18:07 +00004180 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004181
4182 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004183 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004184 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004185 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004186 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004187 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004188
4189 free_irq(adapter->pdev->irq, netdev);
4190 pci_disable_msi(adapter->pdev);
4191
Bruce Allanf8d59f72008-08-08 18:36:11 -07004192msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004193 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004194 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004195}
4196
4197/**
4198 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4199 * @adapter: board private struct
4200 *
4201 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4202 **/
4203static int e1000_test_msi(struct e1000_adapter *adapter)
4204{
4205 int err;
4206 u16 pci_cmd;
4207
4208 if (!(adapter->flags & FLAG_MSI_ENABLED))
4209 return 0;
4210
4211 /* disable SERR in case the MSI write causes a master abort */
4212 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004213 if (pci_cmd & PCI_COMMAND_SERR)
4214 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4215 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004216
4217 err = e1000_test_msi_interrupt(adapter);
4218
Dean Nelson36f24072010-06-29 18:12:05 +00004219 /* re-enable SERR */
4220 if (pci_cmd & PCI_COMMAND_SERR) {
4221 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4222 pci_cmd |= PCI_COMMAND_SERR;
4223 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4224 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004225
Bruce Allanf8d59f72008-08-08 18:36:11 -07004226 return err;
4227}
4228
4229/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230 * e1000_open - Called when a network interface is made active
4231 * @netdev: network interface device structure
4232 *
4233 * Returns 0 on success, negative value on failure
4234 *
4235 * The open entry point is called when a network interface is made
4236 * active by the system (IFF_UP). At this point all resources needed
4237 * for transmit and receive operations are allocated, the interrupt
4238 * handler is registered with the OS, the watchdog timer is started,
4239 * and the stack is notified that the interface is ready.
4240 **/
4241static int e1000_open(struct net_device *netdev)
4242{
4243 struct e1000_adapter *adapter = netdev_priv(netdev);
4244 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004245 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 int err;
4247
4248 /* disallow open during test */
4249 if (test_bit(__E1000_TESTING, &adapter->state))
4250 return -EBUSY;
4251
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004252 pm_runtime_get_sync(&pdev->dev);
4253
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004254 netif_carrier_off(netdev);
4255
Auke Kokbc7f75f2007-09-17 12:30:59 -07004256 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004257 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004258 if (err)
4259 goto err_setup_tx;
4260
4261 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004262 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004263 if (err)
4264 goto err_setup_rx;
4265
Bruce Allane921eb12012-11-28 09:28:37 +00004266 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004267 * interface is now open and reset the part to a known state.
4268 */
4269 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004270 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004271 e1000e_reset(adapter);
4272 }
4273
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274 e1000e_power_up_phy(adapter);
4275
4276 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4277 if ((adapter->hw.mng_cookie.status &
4278 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4279 e1000_update_mng_vlan(adapter);
4280
Bruce Allan79d4e902011-12-16 00:46:27 +00004281 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004282 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4283 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004284
Bruce Allane921eb12012-11-28 09:28:37 +00004285 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004286 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4287 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004288 * clean_rx handler before we do so.
4289 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290 e1000_configure(adapter);
4291
4292 err = e1000_request_irq(adapter);
4293 if (err)
4294 goto err_req_irq;
4295
Bruce Allane921eb12012-11-28 09:28:37 +00004296 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004297 * ignore e1000e MSI messages, which means we need to test our MSI
4298 * interrupt now
4299 */
Bruce Allan4662e822008-08-26 18:37:06 -07004300 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004301 err = e1000_test_msi(adapter);
4302 if (err) {
4303 e_err("Interrupt allocation failed\n");
4304 goto err_req_irq;
4305 }
4306 }
4307
Auke Kokbc7f75f2007-09-17 12:30:59 -07004308 /* From here on the code is the same as e1000e_up() */
4309 clear_bit(__E1000_DOWN, &adapter->state);
4310
4311 napi_enable(&adapter->napi);
4312
4313 e1000_irq_enable(adapter);
4314
Jeff Kirsher09357b02011-11-18 14:25:00 +00004315 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004316 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004317
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004318 adapter->idle_check = true;
4319 pm_runtime_put(&pdev->dev);
4320
Auke Kokbc7f75f2007-09-17 12:30:59 -07004321 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004322 if (adapter->msix_entries)
4323 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4324 else
4325 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326
4327 return 0;
4328
4329err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004330 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004331 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004332 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004333err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004334 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004335err_setup_tx:
4336 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004337 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004338
4339 return err;
4340}
4341
4342/**
4343 * e1000_close - Disables a network interface
4344 * @netdev: network interface device structure
4345 *
4346 * Returns 0, this is not allowed to fail
4347 *
4348 * The close entry point is called when an interface is de-activated
4349 * by the OS. The hardware is still under the drivers control, but
4350 * needs to be disabled. A global MAC reset is issued to stop the
4351 * hardware, and all transmit and receive resources are freed.
4352 **/
4353static int e1000_close(struct net_device *netdev)
4354{
4355 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004356 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004357 int count = E1000_CHECK_RESET_COUNT;
4358
4359 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4360 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004361
4362 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004363
4364 pm_runtime_get_sync(&pdev->dev);
4365
Bruce Allan5f4a7802011-11-29 08:09:19 +00004366 napi_disable(&adapter->napi);
4367
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004368 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4369 e1000e_down(adapter);
4370 e1000_free_irq(adapter);
4371 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004372 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004373
Bruce Allan55aa6982011-12-16 00:45:45 +00004374 e1000e_free_tx_resources(adapter->tx_ring);
4375 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004376
Bruce Allane921eb12012-11-28 09:28:37 +00004377 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004378 * the same ID is registered on the host OS (let 8021q kill it)
4379 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004380 if (adapter->hw.mng_cookie.status &
4381 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4383
Bruce Allane921eb12012-11-28 09:28:37 +00004384 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004385 * interface is now closed
4386 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004387 if ((adapter->flags & FLAG_HAS_AMT) &&
4388 !test_bit(__E1000_TESTING, &adapter->state))
4389 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004390
Bruce Allan3e35d992013-01-12 07:25:22 +00004391 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004392
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004393 pm_runtime_put_sync(&pdev->dev);
4394
Auke Kokbc7f75f2007-09-17 12:30:59 -07004395 return 0;
4396}
4397/**
4398 * e1000_set_mac - Change the Ethernet Address of the NIC
4399 * @netdev: network interface device structure
4400 * @p: pointer to an address structure
4401 *
4402 * Returns 0 on success, negative on failure
4403 **/
4404static int e1000_set_mac(struct net_device *netdev, void *p)
4405{
4406 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004407 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004408 struct sockaddr *addr = p;
4409
4410 if (!is_valid_ether_addr(addr->sa_data))
4411 return -EADDRNOTAVAIL;
4412
4413 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4414 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4415
Bruce Allan69e1e012012-04-14 03:28:50 +00004416 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004417
4418 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4419 /* activate the work around */
4420 e1000e_set_laa_state_82571(&adapter->hw, 1);
4421
Bruce Allane921eb12012-11-28 09:28:37 +00004422 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004423 * between the time RAR[0] gets clobbered and the time it
4424 * gets fixed (in e1000_watchdog), the actual LAA is in one
4425 * of the RARs and no incoming packets directed to this port
4426 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004427 * RAR[14]
4428 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004429 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4430 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004431 }
4432
4433 return 0;
4434}
4435
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004436/**
4437 * e1000e_update_phy_task - work thread to update phy
4438 * @work: pointer to our work struct
4439 *
4440 * this worker thread exists because we must acquire a
4441 * semaphore to read the phy, which we could msleep while
4442 * waiting for it, and we can't msleep in a timer.
4443 **/
4444static void e1000e_update_phy_task(struct work_struct *work)
4445{
4446 struct e1000_adapter *adapter = container_of(work,
4447 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004448
4449 if (test_bit(__E1000_DOWN, &adapter->state))
4450 return;
4451
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004452 e1000_get_phy_info(&adapter->hw);
4453}
4454
Bruce Allane921eb12012-11-28 09:28:37 +00004455/**
4456 * e1000_update_phy_info - timre call-back to update PHY info
4457 * @data: pointer to adapter cast into an unsigned long
4458 *
Bruce Allanad680762008-03-28 09:15:03 -07004459 * Need to wait a few seconds after link up to get diagnostic information from
4460 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004461 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462static void e1000_update_phy_info(unsigned long data)
4463{
4464 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004465
4466 if (test_bit(__E1000_DOWN, &adapter->state))
4467 return;
4468
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004469 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004470}
4471
4472/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004473 * e1000e_update_phy_stats - Update the PHY statistics counters
4474 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004475 *
4476 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004477 **/
4478static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4479{
4480 struct e1000_hw *hw = &adapter->hw;
4481 s32 ret_val;
4482 u16 phy_data;
4483
4484 ret_val = hw->phy.ops.acquire(hw);
4485 if (ret_val)
4486 return;
4487
Bruce Allane921eb12012-11-28 09:28:37 +00004488 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004489 * If not, set to the page with the PHY status registers.
4490 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004491 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004492 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4493 &phy_data);
4494 if (ret_val)
4495 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004496 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4497 ret_val = hw->phy.ops.set_page(hw,
4498 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004499 if (ret_val)
4500 goto release;
4501 }
4502
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004503 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004504 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4505 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004506 if (!ret_val)
4507 adapter->stats.scc += phy_data;
4508
4509 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004510 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4511 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004512 if (!ret_val)
4513 adapter->stats.ecol += phy_data;
4514
4515 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004516 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4517 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004518 if (!ret_val)
4519 adapter->stats.mcc += phy_data;
4520
4521 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004522 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4523 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004524 if (!ret_val)
4525 adapter->stats.latecol += phy_data;
4526
4527 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004528 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4529 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004530 if (!ret_val)
4531 hw->mac.collision_delta = phy_data;
4532
4533 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004534 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4535 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004536 if (!ret_val)
4537 adapter->stats.dc += phy_data;
4538
4539 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004540 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4541 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004542 if (!ret_val)
4543 adapter->stats.tncrs += phy_data;
4544
4545release:
4546 hw->phy.ops.release(hw);
4547}
4548
4549/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004550 * e1000e_update_stats - Update the board statistics counters
4551 * @adapter: board private structure
4552 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004553static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004555 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556 struct e1000_hw *hw = &adapter->hw;
4557 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558
Bruce Allane921eb12012-11-28 09:28:37 +00004559 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560 * connection is down.
4561 */
4562 if (adapter->link_speed == 0)
4563 return;
4564 if (pci_channel_offline(pdev))
4565 return;
4566
Auke Kokbc7f75f2007-09-17 12:30:59 -07004567 adapter->stats.crcerrs += er32(CRCERRS);
4568 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004569 adapter->stats.gorc += er32(GORCL);
4570 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004571 adapter->stats.bprc += er32(BPRC);
4572 adapter->stats.mprc += er32(MPRC);
4573 adapter->stats.roc += er32(ROC);
4574
Auke Kokbc7f75f2007-09-17 12:30:59 -07004575 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004576
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004577 /* Half-duplex statistics */
4578 if (adapter->link_duplex == HALF_DUPLEX) {
4579 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4580 e1000e_update_phy_stats(adapter);
4581 } else {
4582 adapter->stats.scc += er32(SCC);
4583 adapter->stats.ecol += er32(ECOL);
4584 adapter->stats.mcc += er32(MCC);
4585 adapter->stats.latecol += er32(LATECOL);
4586 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004587
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004588 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004589
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004590 if ((hw->mac.type != e1000_82574) &&
4591 (hw->mac.type != e1000_82583))
4592 adapter->stats.tncrs += er32(TNCRS);
4593 }
4594 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004595 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004596
Auke Kokbc7f75f2007-09-17 12:30:59 -07004597 adapter->stats.xonrxc += er32(XONRXC);
4598 adapter->stats.xontxc += er32(XONTXC);
4599 adapter->stats.xoffrxc += er32(XOFFRXC);
4600 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004601 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004602 adapter->stats.gotc += er32(GOTCL);
4603 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604 adapter->stats.rnbc += er32(RNBC);
4605 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606
4607 adapter->stats.mptc += er32(MPTC);
4608 adapter->stats.bptc += er32(BPTC);
4609
4610 /* used for adaptive IFS */
4611
4612 hw->mac.tx_packet_delta = er32(TPT);
4613 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004614
4615 adapter->stats.algnerrc += er32(ALGNERRC);
4616 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004617 adapter->stats.cexterr += er32(CEXTERR);
4618 adapter->stats.tsctc += er32(TSCTC);
4619 adapter->stats.tsctfc += er32(TSCTFC);
4620
Auke Kokbc7f75f2007-09-17 12:30:59 -07004621 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004622 netdev->stats.multicast = adapter->stats.mprc;
4623 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004624
4625 /* Rx Errors */
4626
Bruce Allane921eb12012-11-28 09:28:37 +00004627 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004628 * our own version based on RUC and ROC
4629 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004630 netdev->stats.rx_errors = adapter->stats.rxerrc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004631 adapter->stats.crcerrs + adapter->stats.algnerrc +
4632 adapter->stats.ruc + adapter->stats.roc +
4633 adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004634 netdev->stats.rx_length_errors = adapter->stats.ruc +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004636 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4637 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4638 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004639
4640 /* Tx Errors */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004641 netdev->stats.tx_errors = adapter->stats.ecol +
Auke Kokbc7f75f2007-09-17 12:30:59 -07004642 adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004643 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4644 netdev->stats.tx_window_errors = adapter->stats.latecol;
4645 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004646
4647 /* Tx Dropped needs to be maintained elsewhere */
4648
Auke Kokbc7f75f2007-09-17 12:30:59 -07004649 /* Management Stats */
4650 adapter->stats.mgptc += er32(MGTPTC);
4651 adapter->stats.mgprc += er32(MGTPRC);
4652 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004653
4654 /* Correctable ECC Errors */
4655 if (hw->mac.type == e1000_pch_lpt) {
4656 u32 pbeccsts = er32(PBECCSTS);
4657 adapter->corr_errors +=
4658 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4659 adapter->uncorr_errors +=
4660 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4661 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4662 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004663}
4664
Bruce Allan7c257692008-04-23 11:09:00 -07004665/**
4666 * e1000_phy_read_status - Update the PHY register status snapshot
4667 * @adapter: board private structure
4668 **/
4669static void e1000_phy_read_status(struct e1000_adapter *adapter)
4670{
4671 struct e1000_hw *hw = &adapter->hw;
4672 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004673
4674 if ((er32(STATUS) & E1000_STATUS_LU) &&
4675 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004676 int ret_val;
4677
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004678 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4679 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4680 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4681 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4682 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4683 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4684 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4685 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004686 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004687 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004688 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004689 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004690 * Set values to typical power-on defaults
4691 */
4692 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4693 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4694 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4695 BMSR_ERCAP);
4696 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4697 ADVERTISE_ALL | ADVERTISE_CSMA);
4698 phy->lpa = 0;
4699 phy->expansion = EXPANSION_ENABLENPAGE;
4700 phy->ctrl1000 = ADVERTISE_1000FULL;
4701 phy->stat1000 = 0;
4702 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4703 }
Bruce Allan7c257692008-04-23 11:09:00 -07004704}
4705
Auke Kokbc7f75f2007-09-17 12:30:59 -07004706static void e1000_print_link_info(struct e1000_adapter *adapter)
4707{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004708 struct e1000_hw *hw = &adapter->hw;
4709 u32 ctrl = er32(CTRL);
4710
Bruce Allan8f12fe82008-11-21 16:54:43 -08004711 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004712 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4713 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004714 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4715 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4716 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4717 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004718}
4719
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004720static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004721{
4722 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004723 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004724 s32 ret_val = 0;
4725
Bruce Allane921eb12012-11-28 09:28:37 +00004726 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004727 * Rx sequence error interrupt. get_link_status will stay
4728 * false until the check_for_link establishes link
4729 * for copper adapters ONLY
4730 */
4731 switch (hw->phy.media_type) {
4732 case e1000_media_type_copper:
4733 if (hw->mac.get_link_status) {
4734 ret_val = hw->mac.ops.check_for_link(hw);
4735 link_active = !hw->mac.get_link_status;
4736 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004737 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004738 }
4739 break;
4740 case e1000_media_type_fiber:
4741 ret_val = hw->mac.ops.check_for_link(hw);
4742 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4743 break;
4744 case e1000_media_type_internal_serdes:
4745 ret_val = hw->mac.ops.check_for_link(hw);
4746 link_active = adapter->hw.mac.serdes_has_link;
4747 break;
4748 default:
4749 case e1000_media_type_unknown:
4750 break;
4751 }
4752
4753 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4754 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4755 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004756 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004757 }
4758
4759 return link_active;
4760}
4761
4762static void e1000e_enable_receives(struct e1000_adapter *adapter)
4763{
4764 /* make sure the receive unit is started */
4765 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004766 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004767 struct e1000_hw *hw = &adapter->hw;
4768 u32 rctl = er32(RCTL);
4769 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004770 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004771 }
4772}
4773
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004774static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4775{
4776 struct e1000_hw *hw = &adapter->hw;
4777
Bruce Allane921eb12012-11-28 09:28:37 +00004778 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004779 * for hung state and reset, if two calls return true
4780 */
4781 if (e1000_check_phy_82574(hw))
4782 adapter->phy_hang_count++;
4783 else
4784 adapter->phy_hang_count = 0;
4785
4786 if (adapter->phy_hang_count > 1) {
4787 adapter->phy_hang_count = 0;
4788 schedule_work(&adapter->reset_task);
4789 }
4790}
4791
Auke Kokbc7f75f2007-09-17 12:30:59 -07004792/**
4793 * e1000_watchdog - Timer Call-back
4794 * @data: pointer to adapter cast into an unsigned long
4795 **/
4796static void e1000_watchdog(unsigned long data)
4797{
4798 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4799
4800 /* Do the rest outside of interrupt context */
4801 schedule_work(&adapter->watchdog_task);
4802
4803 /* TODO: make this use queue_delayed_work() */
4804}
4805
4806static void e1000_watchdog_task(struct work_struct *work)
4807{
4808 struct e1000_adapter *adapter = container_of(work,
4809 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810 struct net_device *netdev = adapter->netdev;
4811 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004812 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004813 struct e1000_ring *tx_ring = adapter->tx_ring;
4814 struct e1000_hw *hw = &adapter->hw;
4815 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004817 if (test_bit(__E1000_DOWN, &adapter->state))
4818 return;
4819
David S. Millerb405e8d2010-02-04 22:31:41 -08004820 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004821 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004822 /* Cancel scheduled suspend requests. */
4823 pm_runtime_resume(netdev->dev.parent);
4824
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004825 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004826 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004827 }
4828
4829 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4830 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4831 e1000_update_mng_vlan(adapter);
4832
Auke Kokbc7f75f2007-09-17 12:30:59 -07004833 if (link) {
4834 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004835 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004836
4837 /* Cancel scheduled suspend requests. */
4838 pm_runtime_resume(netdev->dev.parent);
4839
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004840 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004841 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004842 mac->ops.get_link_up_info(&adapter->hw,
4843 &adapter->link_speed,
4844 &adapter->link_duplex);
4845 e1000_print_link_info(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00004846 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004847 * if link has autonegotiated at 10/100 half
4848 */
4849 if ((hw->phy.type == e1000_phy_igp_3 ||
4850 hw->phy.type == e1000_phy_bm) &&
4851 (hw->mac.autoneg == true) &&
4852 (adapter->link_speed == SPEED_10 ||
4853 adapter->link_speed == SPEED_100) &&
4854 (adapter->link_duplex == HALF_DUPLEX)) {
4855 u16 autoneg_exp;
4856
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004857 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004858
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004859 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004860 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 -07004861 }
4862
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004863 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004864 adapter->tx_timeout_factor = 1;
4865 switch (adapter->link_speed) {
4866 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004867 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004868 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 break;
4870 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004871 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004872 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873 break;
4874 }
4875
Bruce Allane921eb12012-11-28 09:28:37 +00004876 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004877 * link-up event
4878 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004879 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4880 !txb2b) {
4881 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004882 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004883 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004884 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004885 }
4886
Bruce Allane921eb12012-11-28 09:28:37 +00004887 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004888 * some hardware issues
4889 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004890 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4891 switch (adapter->link_speed) {
4892 case SPEED_10:
4893 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004894 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004895 netdev->features &= ~NETIF_F_TSO;
4896 netdev->features &= ~NETIF_F_TSO6;
4897 break;
4898 case SPEED_1000:
4899 netdev->features |= NETIF_F_TSO;
4900 netdev->features |= NETIF_F_TSO6;
4901 break;
4902 default:
4903 /* oops */
4904 break;
4905 }
4906 }
4907
Bruce Allane921eb12012-11-28 09:28:37 +00004908 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004909 * after setting TARC(0)
4910 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 tctl = er32(TCTL);
4912 tctl |= E1000_TCTL_EN;
4913 ew32(TCTL, tctl);
4914
Bruce Allane921eb12012-11-28 09:28:37 +00004915 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004916 * reporting link up.
4917 */
4918 if (phy->ops.cfg_on_link_up)
4919 phy->ops.cfg_on_link_up(hw);
4920
Auke Kokbc7f75f2007-09-17 12:30:59 -07004921 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922
4923 if (!test_bit(__E1000_DOWN, &adapter->state))
4924 mod_timer(&adapter->phy_info_timer,
4925 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004926 }
4927 } else {
4928 if (netif_carrier_ok(netdev)) {
4929 adapter->link_speed = 0;
4930 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004931 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004932 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004933 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004934 if (!test_bit(__E1000_DOWN, &adapter->state))
4935 mod_timer(&adapter->phy_info_timer,
4936 round_jiffies(jiffies + 2 * HZ));
4937
Bruce Allan12d43f72012-12-05 06:26:14 +00004938 /* The link is lost so the controller stops DMA.
4939 * If there is queued Tx work that cannot be done
4940 * or if on an 8000ES2LAN which requires a Rx packet
4941 * buffer work-around on link down event, reset the
4942 * controller to flush the Tx/Rx packet buffers.
4943 * (Do the reset outside of interrupt context).
4944 */
4945 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4946 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4947 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004948 else
4949 pm_schedule_suspend(netdev->dev.parent,
4950 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004951 }
4952 }
4953
4954link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004955 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004956 e1000e_update_stats(adapter);
4957
4958 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4959 adapter->tpt_old = adapter->stats.tpt;
4960 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4961 adapter->colc_old = adapter->stats.colc;
4962
Bruce Allan7c257692008-04-23 11:09:00 -07004963 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4964 adapter->gorc_old = adapter->stats.gorc;
4965 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4966 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004967 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004968
Bruce Allan12d43f72012-12-05 06:26:14 +00004969 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004970 schedule_work(&adapter->reset_task);
4971 /* return immediately since reset is imminent */
4972 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004973 }
4974
Bruce Allan12d43f72012-12-05 06:26:14 +00004975 e1000e_update_adaptive(&adapter->hw);
4976
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004977 /* Simple mode for Interrupt Throttle Rate (ITR) */
4978 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004979 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004980 * Total asymmetrical Tx or Rx gets ITR=8000;
4981 * everyone else is between 2000-8000.
4982 */
4983 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4984 u32 dif = (adapter->gotc > adapter->gorc ?
4985 adapter->gotc - adapter->gorc :
4986 adapter->gorc - adapter->gotc) / 10000;
4987 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4988
Matthew Vick22a4cca2012-07-12 00:02:42 +00004989 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004990 }
4991
Bruce Allanad680762008-03-28 09:15:03 -07004992 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004993 if (adapter->msix_entries)
4994 ew32(ICS, adapter->rx_ring->ims_val);
4995 else
4996 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004998 /* flush pending descriptors to memory before detecting Tx hang */
4999 e1000e_flush_descriptors(adapter);
5000
Auke Kokbc7f75f2007-09-17 12:30:59 -07005001 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00005002 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003
Bruce Allane921eb12012-11-28 09:28:37 +00005004 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005005 * reset from the other port. Set the appropriate LAA in RAR[0]
5006 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005007 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005008 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005010 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5011 e1000e_check_82574_phy_workaround(adapter);
5012
Bruce Allanb67e1912012-12-27 08:32:33 +00005013 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5014 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5015 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5016 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5017 er32(RXSTMPH);
5018 adapter->rx_hwtstamp_cleared++;
5019 } else {
5020 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5021 }
5022 }
5023
Auke Kokbc7f75f2007-09-17 12:30:59 -07005024 /* Reset the timer */
5025 if (!test_bit(__E1000_DOWN, &adapter->state))
5026 mod_timer(&adapter->watchdog_timer,
5027 round_jiffies(jiffies + 2 * HZ));
5028}
5029
5030#define E1000_TX_FLAGS_CSUM 0x00000001
5031#define E1000_TX_FLAGS_VLAN 0x00000002
5032#define E1000_TX_FLAGS_TSO 0x00000004
5033#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005034#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005035#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005036#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5037#define E1000_TX_FLAGS_VLAN_SHIFT 16
5038
Bruce Allan55aa6982011-12-16 00:45:45 +00005039static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005041 struct e1000_context_desc *context_desc;
5042 struct e1000_buffer *buffer_info;
5043 unsigned int i;
5044 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005045 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005048 if (!skb_is_gso(skb))
5049 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005050
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005051 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005052 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5053
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005054 if (err)
5055 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005056 }
5057
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005058 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5059 mss = skb_shinfo(skb)->gso_size;
5060 if (skb->protocol == htons(ETH_P_IP)) {
5061 struct iphdr *iph = ip_hdr(skb);
5062 iph->tot_len = 0;
5063 iph->check = 0;
5064 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
5065 0, IPPROTO_TCP, 0);
5066 cmd_length = E1000_TXD_CMD_IP;
5067 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005068 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005069 ipv6_hdr(skb)->payload_len = 0;
5070 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5071 &ipv6_hdr(skb)->daddr,
5072 0, IPPROTO_TCP, 0);
5073 ipcse = 0;
5074 }
5075 ipcss = skb_network_offset(skb);
5076 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5077 tucss = skb_transport_offset(skb);
5078 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005079
5080 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
5081 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
5082
5083 i = tx_ring->next_to_use;
5084 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5085 buffer_info = &tx_ring->buffer_info[i];
5086
5087 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5088 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5089 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5090 context_desc->upper_setup.tcp_fields.tucss = tucss;
5091 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005092 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005093 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5094 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5095 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5096
5097 buffer_info->time_stamp = jiffies;
5098 buffer_info->next_to_watch = i;
5099
5100 i++;
5101 if (i == tx_ring->count)
5102 i = 0;
5103 tx_ring->next_to_use = i;
5104
5105 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106}
5107
Bruce Allan55aa6982011-12-16 00:45:45 +00005108static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005109{
Bruce Allan55aa6982011-12-16 00:45:45 +00005110 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005111 struct e1000_context_desc *context_desc;
5112 struct e1000_buffer *buffer_info;
5113 unsigned int i;
5114 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005115 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005116 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005117
Dave Grahamaf807c82008-10-09 14:28:58 -07005118 if (skb->ip_summed != CHECKSUM_PARTIAL)
5119 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005120
Arthur Jones5f66f202009-03-19 01:13:08 +00005121 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5122 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5123 else
5124 protocol = skb->protocol;
5125
Arthur Jones3f518392009-03-20 15:56:35 -07005126 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005127 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005128 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5129 cmd_len |= E1000_TXD_CMD_TCP;
5130 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005131 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005132 /* XXX not handling all IPV6 headers */
5133 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5134 cmd_len |= E1000_TXD_CMD_TCP;
5135 break;
5136 default:
5137 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005138 e_warn("checksum_partial proto=%x!\n",
5139 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005140 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005141 }
5142
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005143 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005144
5145 i = tx_ring->next_to_use;
5146 buffer_info = &tx_ring->buffer_info[i];
5147 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5148
5149 context_desc->lower_setup.ip_config = 0;
5150 context_desc->upper_setup.tcp_fields.tucss = css;
5151 context_desc->upper_setup.tcp_fields.tucso =
5152 css + skb->csum_offset;
5153 context_desc->upper_setup.tcp_fields.tucse = 0;
5154 context_desc->tcp_seg_setup.data = 0;
5155 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5156
5157 buffer_info->time_stamp = jiffies;
5158 buffer_info->next_to_watch = i;
5159
5160 i++;
5161 if (i == tx_ring->count)
5162 i = 0;
5163 tx_ring->next_to_use = i;
5164
5165 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005166}
5167
Bruce Allan55aa6982011-12-16 00:45:45 +00005168static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5169 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005170 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005171{
Bruce Allan55aa6982011-12-16 00:45:45 +00005172 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005173 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005174 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005175 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005176 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005177 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005178
5179 i = tx_ring->next_to_use;
5180
5181 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005182 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005183 size = min(len, max_per_txd);
5184
Auke Kokbc7f75f2007-09-17 12:30:59 -07005185 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005186 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005187 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005188 buffer_info->dma = dma_map_single(&pdev->dev,
5189 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005190 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005191 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005192 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005193 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005194
5195 len -= size;
5196 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005197 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005198
5199 if (len) {
5200 i++;
5201 if (i == tx_ring->count)
5202 i = 0;
5203 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005204 }
5205
5206 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005207 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005208
5209 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005210 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005211 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212
5213 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005214 i++;
5215 if (i == tx_ring->count)
5216 i = 0;
5217
Auke Kokbc7f75f2007-09-17 12:30:59 -07005218 buffer_info = &tx_ring->buffer_info[i];
5219 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005220
5221 buffer_info->length = size;
5222 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005223 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005224 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5225 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005226 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005227 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005228 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229
5230 len -= size;
5231 offset += size;
5232 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005233 }
5234 }
5235
Bruce Allanaf667a22010-12-31 06:10:01 +00005236 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005237 /* multiply data chunks by size of headers */
5238 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5239
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005241 tx_ring->buffer_info[i].segs = segs;
5242 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005243 tx_ring->buffer_info[first].next_to_watch = i;
5244
5245 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005246
5247dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005248 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005249 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005250 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005251 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005252
5253 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005254 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005255 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005256 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005257 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005258 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005259 }
5260
5261 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262}
5263
Bruce Allan55aa6982011-12-16 00:45:45 +00005264static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005265{
Bruce Allan55aa6982011-12-16 00:45:45 +00005266 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005267 struct e1000_tx_desc *tx_desc = NULL;
5268 struct e1000_buffer *buffer_info;
5269 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5270 unsigned int i;
5271
5272 if (tx_flags & E1000_TX_FLAGS_TSO) {
5273 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
5274 E1000_TXD_CMD_TSE;
5275 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5276
5277 if (tx_flags & E1000_TX_FLAGS_IPV4)
5278 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5279 }
5280
5281 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5282 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5283 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5284 }
5285
5286 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5287 txd_lower |= E1000_TXD_CMD_VLE;
5288 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5289 }
5290
Ben Greear943146d2012-02-11 15:39:40 +00005291 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5292 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5293
Bruce Allanb67e1912012-12-27 08:32:33 +00005294 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5295 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5296 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5297 }
5298
Auke Kokbc7f75f2007-09-17 12:30:59 -07005299 i = tx_ring->next_to_use;
5300
Bruce Allan36b973d2010-11-24 07:42:43 +00005301 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005302 buffer_info = &tx_ring->buffer_info[i];
5303 tx_desc = E1000_TX_DESC(*tx_ring, i);
5304 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
5305 tx_desc->lower.data =
5306 cpu_to_le32(txd_lower | buffer_info->length);
5307 tx_desc->upper.data = cpu_to_le32(txd_upper);
5308
5309 i++;
5310 if (i == tx_ring->count)
5311 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005312 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005313
5314 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5315
Ben Greear943146d2012-02-11 15:39:40 +00005316 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5317 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5318 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5319
Bruce Allane921eb12012-11-28 09:28:37 +00005320 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005321 * know there are new descriptors to fetch. (Only
5322 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005323 * such as IA-64).
5324 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005325 wmb();
5326
5327 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005328
5329 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005330 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005331 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005332 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005333
Bruce Allane921eb12012-11-28 09:28:37 +00005334 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005335 * at a time, it synchronizes IO on IA64/Altix systems
5336 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005337 mmiowb();
5338}
5339
5340#define MINIMUM_DHCP_PACKET_SIZE 282
5341static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5342 struct sk_buff *skb)
5343{
5344 struct e1000_hw *hw = &adapter->hw;
5345 u16 length, offset;
5346
Bruce Alland60923c2012-12-05 06:26:56 +00005347 if (vlan_tx_tag_present(skb) &&
5348 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5349 (adapter->hw.mng_cookie.status &
5350 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5351 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005352
5353 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5354 return 0;
5355
5356 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5357 return 0;
5358
5359 {
5360 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data+14);
5361 struct udphdr *udp;
5362
5363 if (ip->protocol != IPPROTO_UDP)
5364 return 0;
5365
5366 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5367 if (ntohs(udp->dest) != 67)
5368 return 0;
5369
5370 offset = (u8 *)udp + 8 - skb->data;
5371 length = skb->len - offset;
5372 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5373 }
5374
5375 return 0;
5376}
5377
Bruce Allan55aa6982011-12-16 00:45:45 +00005378static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005379{
Bruce Allan55aa6982011-12-16 00:45:45 +00005380 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381
Bruce Allan55aa6982011-12-16 00:45:45 +00005382 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005383 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005384 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005385 * but since that doesn't exist yet, just open code it.
5386 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005387 smp_mb();
5388
Bruce Allane921eb12012-11-28 09:28:37 +00005389 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005390 * made room available.
5391 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005392 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005393 return -EBUSY;
5394
5395 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005396 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005397 ++adapter->restart_queue;
5398 return 0;
5399}
5400
Bruce Allan55aa6982011-12-16 00:45:45 +00005401static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005402{
Bruce Alland821a4c2012-08-24 20:38:11 +00005403 BUG_ON(size > tx_ring->count);
5404
Bruce Allan55aa6982011-12-16 00:45:45 +00005405 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005406 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005407 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408}
5409
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005410static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5411 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005412{
5413 struct e1000_adapter *adapter = netdev_priv(netdev);
5414 struct e1000_ring *tx_ring = adapter->tx_ring;
5415 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005416 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005417 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005418 unsigned int nr_frags;
5419 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420 int count = 0;
5421 int tso;
5422 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005423
5424 if (test_bit(__E1000_DOWN, &adapter->state)) {
5425 dev_kfree_skb_any(skb);
5426 return NETDEV_TX_OK;
5427 }
5428
5429 if (skb->len <= 0) {
5430 dev_kfree_skb_any(skb);
5431 return NETDEV_TX_OK;
5432 }
5433
Bruce Allane921eb12012-11-28 09:28:37 +00005434 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005435 * pad skb in order to meet this minimum size requirement
5436 */
5437 if (unlikely(skb->len < 17)) {
5438 if (skb_pad(skb, 17 - skb->len))
5439 return NETDEV_TX_OK;
5440 skb->len = 17;
5441 skb_set_tail_pointer(skb, 17);
5442 }
5443
Auke Kokbc7f75f2007-09-17 12:30:59 -07005444 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005445 if (mss) {
5446 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005447
Bruce Allane921eb12012-11-28 09:28:37 +00005448 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005449 * points to just header, pull a few bytes of payload from
5450 * frags into skb->data
5451 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005452 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005453 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005454 * avoiding it could save a lot of cycles
5455 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005456 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005457 unsigned int pull_size;
5458
Bruce Allana2a5b322012-01-31 06:37:17 +00005459 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005460 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005461 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 dev_kfree_skb_any(skb);
5463 return NETDEV_TX_OK;
5464 }
Eric Dumazete743d312010-04-14 15:59:40 -07005465 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005466 }
5467 }
5468
5469 /* reserve a descriptor for the offload context */
5470 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5471 count++;
5472 count++;
5473
Bruce Alland821a4c2012-08-24 20:38:11 +00005474 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005475
5476 nr_frags = skb_shinfo(skb)->nr_frags;
5477 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005478 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5479 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480
5481 if (adapter->hw.mac.tx_pkt_filtering)
5482 e1000_transfer_dhcp_info(adapter, skb);
5483
Bruce Allane921eb12012-11-28 09:28:37 +00005484 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005485 * head, otherwise try next time
5486 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005487 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489
Jesse Grosseab6d182010-10-20 13:56:03 +00005490 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005491 tx_flags |= E1000_TX_FLAGS_VLAN;
5492 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5493 }
5494
5495 first = tx_ring->next_to_use;
5496
Bruce Allan55aa6982011-12-16 00:45:45 +00005497 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005498 if (tso < 0) {
5499 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005500 return NETDEV_TX_OK;
5501 }
5502
5503 if (tso)
5504 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005505 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005506 tx_flags |= E1000_TX_FLAGS_CSUM;
5507
Bruce Allane921eb12012-11-28 09:28:37 +00005508 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005509 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005510 * no longer assume, we must.
5511 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005512 if (skb->protocol == htons(ETH_P_IP))
5513 tx_flags |= E1000_TX_FLAGS_IPV4;
5514
Ben Greear943146d2012-02-11 15:39:40 +00005515 if (unlikely(skb->no_fcs))
5516 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5517
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005518 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005519 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5520 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005521 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005522 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5523 !adapter->tx_hwtstamp_skb)) {
5524 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5525 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5526 adapter->tx_hwtstamp_skb = skb_get(skb);
5527 schedule_work(&adapter->tx_hwtstamp_work);
5528 } else {
5529 skb_tx_timestamp(skb);
5530 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005531
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005532 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005533 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005534 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005535 e1000_maybe_stop_tx(tx_ring,
5536 (MAX_SKB_FRAGS *
5537 DIV_ROUND_UP(PAGE_SIZE,
5538 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005539 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005540 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005541 tx_ring->buffer_info[first].time_stamp = 0;
5542 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005543 }
5544
Auke Kokbc7f75f2007-09-17 12:30:59 -07005545 return NETDEV_TX_OK;
5546}
5547
5548/**
5549 * e1000_tx_timeout - Respond to a Tx Hang
5550 * @netdev: network interface device structure
5551 **/
5552static void e1000_tx_timeout(struct net_device *netdev)
5553{
5554 struct e1000_adapter *adapter = netdev_priv(netdev);
5555
5556 /* Do the reset outside of interrupt context */
5557 adapter->tx_timeout_count++;
5558 schedule_work(&adapter->reset_task);
5559}
5560
5561static void e1000_reset_task(struct work_struct *work)
5562{
5563 struct e1000_adapter *adapter;
5564 adapter = container_of(work, struct e1000_adapter, reset_task);
5565
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005566 /* don't run the task if already down */
5567 if (test_bit(__E1000_DOWN, &adapter->state))
5568 return;
5569
Bruce Allan12d43f72012-12-05 06:26:14 +00005570 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005571 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005572 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005573 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005574 e1000e_reinit_locked(adapter);
5575}
5576
5577/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005578 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005579 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005580 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005581 *
5582 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005583 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005584struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5585 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005586{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005587 struct e1000_adapter *adapter = netdev_priv(netdev);
5588
5589 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5590 spin_lock(&adapter->stats64_lock);
5591 e1000e_update_stats(adapter);
5592 /* Fill out the OS statistics structure */
5593 stats->rx_bytes = adapter->stats.gorc;
5594 stats->rx_packets = adapter->stats.gprc;
5595 stats->tx_bytes = adapter->stats.gotc;
5596 stats->tx_packets = adapter->stats.gptc;
5597 stats->multicast = adapter->stats.mprc;
5598 stats->collisions = adapter->stats.colc;
5599
5600 /* Rx Errors */
5601
Bruce Allane921eb12012-11-28 09:28:37 +00005602 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005603 * our own version based on RUC and ROC
5604 */
5605 stats->rx_errors = adapter->stats.rxerrc +
5606 adapter->stats.crcerrs + adapter->stats.algnerrc +
5607 adapter->stats.ruc + adapter->stats.roc +
5608 adapter->stats.cexterr;
5609 stats->rx_length_errors = adapter->stats.ruc +
5610 adapter->stats.roc;
5611 stats->rx_crc_errors = adapter->stats.crcerrs;
5612 stats->rx_frame_errors = adapter->stats.algnerrc;
5613 stats->rx_missed_errors = adapter->stats.mpc;
5614
5615 /* Tx Errors */
5616 stats->tx_errors = adapter->stats.ecol +
5617 adapter->stats.latecol;
5618 stats->tx_aborted_errors = adapter->stats.ecol;
5619 stats->tx_window_errors = adapter->stats.latecol;
5620 stats->tx_carrier_errors = adapter->stats.tncrs;
5621
5622 /* Tx Dropped needs to be maintained elsewhere */
5623
5624 spin_unlock(&adapter->stats64_lock);
5625 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005626}
5627
5628/**
5629 * e1000_change_mtu - Change the Maximum Transfer Unit
5630 * @netdev: network interface device structure
5631 * @new_mtu: new value for maximum frame size
5632 *
5633 * Returns 0 on success, negative on failure
5634 **/
5635static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5636{
5637 struct e1000_adapter *adapter = netdev_priv(netdev);
5638 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5639
Bruce Allan2adc55c2009-06-02 11:28:58 +00005640 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005641 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5642 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5643 e_err("Jumbo Frames not supported.\n");
5644 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005645 }
5646
Bruce Allan2adc55c2009-06-02 11:28:58 +00005647 /* Supported frame sizes */
5648 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5649 (max_frame > adapter->max_hw_frame_size)) {
5650 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005651 return -EINVAL;
5652 }
5653
Bruce Allan2fbe4522012-04-19 03:21:47 +00005654 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5655 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005656 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5657 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005658 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005659 return -EINVAL;
5660 }
5661
Auke Kokbc7f75f2007-09-17 12:30:59 -07005662 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005663 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005664 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005665 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005666 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5667 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005668 if (netif_running(netdev))
5669 e1000e_down(adapter);
5670
Bruce Allane921eb12012-11-28 09:28:37 +00005671 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672 * means we reserve 2 more, this pushes us to allocate from the next
5673 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005674 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005675 * However with the new *_jumbo_rx* routines, jumbo receives will use
5676 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005677 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005678
Jesse Brandeburg99261462010-01-22 22:56:16 +00005679 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005680 adapter->rx_buffer_len = 2048;
5681 else
5682 adapter->rx_buffer_len = 4096;
5683
5684 /* adjust allocation if LPE protects us, and we aren't using SBP */
5685 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5686 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5687 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005688 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005689
Auke Kokbc7f75f2007-09-17 12:30:59 -07005690 if (netif_running(netdev))
5691 e1000e_up(adapter);
5692 else
5693 e1000e_reset(adapter);
5694
5695 clear_bit(__E1000_RESETTING, &adapter->state);
5696
5697 return 0;
5698}
5699
5700static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5701 int cmd)
5702{
5703 struct e1000_adapter *adapter = netdev_priv(netdev);
5704 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005705
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005706 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005707 return -EOPNOTSUPP;
5708
5709 switch (cmd) {
5710 case SIOCGMIIPHY:
5711 data->phy_id = adapter->hw.phy.addr;
5712 break;
5713 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005714 e1000_phy_read_status(adapter);
5715
Bruce Allan7c257692008-04-23 11:09:00 -07005716 switch (data->reg_num & 0x1F) {
5717 case MII_BMCR:
5718 data->val_out = adapter->phy_regs.bmcr;
5719 break;
5720 case MII_BMSR:
5721 data->val_out = adapter->phy_regs.bmsr;
5722 break;
5723 case MII_PHYSID1:
5724 data->val_out = (adapter->hw.phy.id >> 16);
5725 break;
5726 case MII_PHYSID2:
5727 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5728 break;
5729 case MII_ADVERTISE:
5730 data->val_out = adapter->phy_regs.advertise;
5731 break;
5732 case MII_LPA:
5733 data->val_out = adapter->phy_regs.lpa;
5734 break;
5735 case MII_EXPANSION:
5736 data->val_out = adapter->phy_regs.expansion;
5737 break;
5738 case MII_CTRL1000:
5739 data->val_out = adapter->phy_regs.ctrl1000;
5740 break;
5741 case MII_STAT1000:
5742 data->val_out = adapter->phy_regs.stat1000;
5743 break;
5744 case MII_ESTATUS:
5745 data->val_out = adapter->phy_regs.estatus;
5746 break;
5747 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005748 return -EIO;
5749 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005750 break;
5751 case SIOCSMIIREG:
5752 default:
5753 return -EOPNOTSUPP;
5754 }
5755 return 0;
5756}
5757
Bruce Allanb67e1912012-12-27 08:32:33 +00005758/**
5759 * e1000e_hwtstamp_ioctl - control hardware time stamping
5760 * @netdev: network interface device structure
5761 * @ifreq: interface request
5762 *
5763 * Outgoing time stamping can be enabled and disabled. Play nice and
5764 * disable it when requested, although it shouldn't cause any overhead
5765 * when no packet needs it. At most one packet in the queue may be
5766 * marked for time stamping, otherwise it would be impossible to tell
5767 * for sure to which packet the hardware time stamp belongs.
5768 *
5769 * Incoming time stamping has to be configured via the hardware filters.
5770 * Not all combinations are supported, in particular event type has to be
5771 * specified. Matching the kind of event packet is not supported, with the
5772 * exception of "all V2 events regardless of level 2 or 4".
5773 **/
5774static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5775{
5776 struct e1000_adapter *adapter = netdev_priv(netdev);
5777 struct hwtstamp_config config;
5778 int ret_val;
5779
5780 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5781 return -EFAULT;
5782
5783 adapter->hwtstamp_config = config;
5784
5785 ret_val = e1000e_config_hwtstamp(adapter);
5786 if (ret_val)
5787 return ret_val;
5788
5789 config = adapter->hwtstamp_config;
5790
Bruce Alland89777b2013-01-19 01:09:58 +00005791 switch (config.rx_filter) {
5792 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5793 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5794 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5795 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5796 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5797 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5798 /* With V2 type filters which specify a Sync or Delay Request,
5799 * Path Delay Request/Response messages are also time stamped
5800 * by hardware so notify the caller the requested packets plus
5801 * some others are time stamped.
5802 */
5803 config.rx_filter = HWTSTAMP_FILTER_SOME;
5804 break;
5805 default:
5806 break;
5807 }
5808
Bruce Allanb67e1912012-12-27 08:32:33 +00005809 return copy_to_user(ifr->ifr_data, &config,
5810 sizeof(config)) ? -EFAULT : 0;
5811}
5812
Auke Kokbc7f75f2007-09-17 12:30:59 -07005813static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5814{
5815 switch (cmd) {
5816 case SIOCGMIIPHY:
5817 case SIOCGMIIREG:
5818 case SIOCSMIIREG:
5819 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005820 case SIOCSHWTSTAMP:
5821 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005822 default:
5823 return -EOPNOTSUPP;
5824 }
5825}
5826
Bruce Allana4f58f52009-06-02 11:29:18 +00005827static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5828{
5829 struct e1000_hw *hw = &adapter->hw;
5830 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005831 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005832 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005833
5834 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005835 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005836
Bruce Allan2b6b1682011-05-13 07:20:09 +00005837 retval = hw->phy.ops.acquire(hw);
5838 if (retval) {
5839 e_err("Could not acquire PHY\n");
5840 return retval;
5841 }
5842
5843 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5844 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5845 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005846 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005847
5848 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005849 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5850 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005851 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5852 (u16)(mac_reg & 0xFFFF));
5853 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5854 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005855 }
5856
5857 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005858 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005859 mac_reg = er32(RCTL);
5860 if (mac_reg & E1000_RCTL_UPE)
5861 phy_reg |= BM_RCTL_UPE;
5862 if (mac_reg & E1000_RCTL_MPE)
5863 phy_reg |= BM_RCTL_MPE;
5864 phy_reg &= ~(BM_RCTL_MO_MASK);
5865 if (mac_reg & E1000_RCTL_MO_3)
5866 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5867 << BM_RCTL_MO_SHIFT);
5868 if (mac_reg & E1000_RCTL_BAM)
5869 phy_reg |= BM_RCTL_BAM;
5870 if (mac_reg & E1000_RCTL_PMCF)
5871 phy_reg |= BM_RCTL_PMCF;
5872 mac_reg = er32(CTRL);
5873 if (mac_reg & E1000_CTRL_RFCE)
5874 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005875 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005876
5877 /* enable PHY wakeup in MAC register */
5878 ew32(WUFC, wufc);
5879 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5880
5881 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005882 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5883 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005884
5885 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005886 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5887 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005888 if (retval)
5889 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005890release:
Bruce Allan94d81862009-11-20 23:25:26 +00005891 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005892
5893 return retval;
5894}
5895
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005896static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5897 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005898{
5899 struct net_device *netdev = pci_get_drvdata(pdev);
5900 struct e1000_adapter *adapter = netdev_priv(netdev);
5901 struct e1000_hw *hw = &adapter->hw;
5902 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005903 /* Runtime suspend should only enable wakeup for link changes */
5904 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005905 int retval = 0;
5906
5907 netif_device_detach(netdev);
5908
5909 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005910 int count = E1000_CHECK_RESET_COUNT;
5911
5912 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5913 usleep_range(10000, 20000);
5914
Auke Kokbc7f75f2007-09-17 12:30:59 -07005915 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5916 e1000e_down(adapter);
5917 e1000_free_irq(adapter);
5918 }
Bruce Allan4662e822008-08-26 18:37:06 -07005919 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005920
5921 retval = pci_save_state(pdev);
5922 if (retval)
5923 return retval;
5924
5925 status = er32(STATUS);
5926 if (status & E1000_STATUS_LU)
5927 wufc &= ~E1000_WUFC_LNKC;
5928
5929 if (wufc) {
5930 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005931 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005932
5933 /* turn on all-multi mode if wake on multicast is enabled */
5934 if (wufc & E1000_WUFC_MC) {
5935 rctl = er32(RCTL);
5936 rctl |= E1000_RCTL_MPE;
5937 ew32(RCTL, rctl);
5938 }
5939
5940 ctrl = er32(CTRL);
5941 /* advertise wake from D3Cold */
5942 #define E1000_CTRL_ADVD3WUC 0x00100000
5943 /* phy power management enable */
5944 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005945 ctrl |= E1000_CTRL_ADVD3WUC;
5946 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5947 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005948 ew32(CTRL, ctrl);
5949
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005950 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5951 adapter->hw.phy.media_type ==
5952 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005953 /* keep the laser running in D3 */
5954 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005955 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005956 ew32(CTRL_EXT, ctrl_ext);
5957 }
5958
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005959 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005960 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005961
Auke Kokbc7f75f2007-09-17 12:30:59 -07005962 /* Allow time for pending master requests to run */
5963 e1000e_disable_pcie_master(&adapter->hw);
5964
Bruce Allan82776a42009-08-14 14:35:33 +00005965 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005966 /* enable wakeup by the PHY */
5967 retval = e1000_init_phy_wakeup(adapter, wufc);
5968 if (retval)
5969 return retval;
5970 } else {
5971 /* enable wakeup by the MAC */
5972 ew32(WUFC, wufc);
5973 ew32(WUC, E1000_WUC_PME_EN);
5974 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005975 } else {
5976 ew32(WUC, 0);
5977 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005978 }
5979
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005980 *enable_wake = !!wufc;
5981
Auke Kokbc7f75f2007-09-17 12:30:59 -07005982 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005983 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5984 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005985 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005986
5987 if (adapter->hw.phy.type == e1000_phy_igp_3)
5988 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5989
Bruce Allane921eb12012-11-28 09:28:37 +00005990 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005991 * would have already happened in close and is redundant.
5992 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005993 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005994
5995 pci_disable_device(pdev);
5996
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005997 return 0;
5998}
5999
6000static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
6001{
6002 if (sleep && wake) {
6003 pci_prepare_to_sleep(pdev);
6004 return;
6005 }
6006
6007 pci_wake_from_d3(pdev, wake);
6008 pci_set_power_state(pdev, PCI_D3hot);
6009}
6010
6011static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep,
6012 bool wake)
6013{
6014 struct net_device *netdev = pci_get_drvdata(pdev);
6015 struct e1000_adapter *adapter = netdev_priv(netdev);
6016
Bruce Allane921eb12012-11-28 09:28:37 +00006017 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006018 * correctable error when the MAC transitions from D0 to D3. To
6019 * prevent this we need to mask off the correctable errors on the
6020 * downstream port of the pci-e switch.
6021 */
6022 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6023 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006024 u16 devctl;
6025
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006026 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6027 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6028 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006029
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006030 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006031
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006032 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006033 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006034 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006035 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006036}
6037
Bruce Allan6f461f62010-04-27 03:33:04 +00006038#ifdef CONFIG_PCIEASPM
6039static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6040{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006041 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006042}
6043#else
6044static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006045{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006046 u16 aspm_ctl = 0;
6047
6048 if (state & PCIE_LINK_STATE_L0S)
6049 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6050 if (state & PCIE_LINK_STATE_L1)
6051 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6052
Bruce Allane921eb12012-11-28 09:28:37 +00006053 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006054 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006055 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006056 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006057
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006058 if (pdev->bus->self)
6059 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006060 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006061}
6062#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006063static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006064{
6065 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6066 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6067 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6068
6069 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006070}
6071
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006072#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006073static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006074{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006075 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006076}
6077
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006078static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006079{
6080 struct net_device *netdev = pci_get_drvdata(pdev);
6081 struct e1000_adapter *adapter = netdev_priv(netdev);
6082 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006083 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006084 u32 err;
6085
Bruce Allan78cd29d2011-03-24 03:09:03 +00006086 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6087 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6088 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6089 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6090 if (aspm_disable_flag)
6091 e1000e_disable_aspm(pdev, aspm_disable_flag);
6092
Auke Kokbc7f75f2007-09-17 12:30:59 -07006093 pci_set_power_state(pdev, PCI_D0);
6094 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006095 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006096
Bruce Allan4662e822008-08-26 18:37:06 -07006097 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006098 if (netif_running(netdev)) {
6099 err = e1000_request_irq(adapter);
6100 if (err)
6101 return err;
6102 }
6103
Bruce Allan2fbe4522012-04-19 03:21:47 +00006104 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006105 e1000_resume_workarounds_pchlan(&adapter->hw);
6106
Auke Kokbc7f75f2007-09-17 12:30:59 -07006107 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006108
6109 /* report the system wakeup cause from S3/S4 */
6110 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6111 u16 phy_data;
6112
6113 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6114 if (phy_data) {
6115 e_info("PHY Wakeup cause - %s\n",
6116 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6117 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6118 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6119 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006120 phy_data & E1000_WUS_LNKC ?
6121 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006122 }
6123 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6124 } else {
6125 u32 wus = er32(WUS);
6126 if (wus) {
6127 e_info("MAC Wakeup cause - %s\n",
6128 wus & E1000_WUS_EX ? "Unicast Packet" :
6129 wus & E1000_WUS_MC ? "Multicast Packet" :
6130 wus & E1000_WUS_BC ? "Broadcast Packet" :
6131 wus & E1000_WUS_MAG ? "Magic Packet" :
6132 wus & E1000_WUS_LNKC ? "Link Status Change" :
6133 "other");
6134 }
6135 ew32(WUS, ~0);
6136 }
6137
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006139
Bruce Allancd791612010-05-10 14:59:51 +00006140 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141
6142 if (netif_running(netdev))
6143 e1000e_up(adapter);
6144
6145 netif_device_attach(netdev);
6146
Bruce Allane921eb12012-11-28 09:28:37 +00006147 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006148 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006149 * under the control of the driver.
6150 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006151 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006152 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006153
6154 return 0;
6155}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006156
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006157#ifdef CONFIG_PM_SLEEP
6158static int e1000_suspend(struct device *dev)
6159{
6160 struct pci_dev *pdev = to_pci_dev(dev);
6161 int retval;
6162 bool wake;
6163
6164 retval = __e1000_shutdown(pdev, &wake, false);
6165 if (!retval)
6166 e1000_complete_shutdown(pdev, true, wake);
6167
6168 return retval;
6169}
6170
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006171static int e1000_resume(struct device *dev)
6172{
6173 struct pci_dev *pdev = to_pci_dev(dev);
6174 struct net_device *netdev = pci_get_drvdata(pdev);
6175 struct e1000_adapter *adapter = netdev_priv(netdev);
6176
6177 if (e1000e_pm_ready(adapter))
6178 adapter->idle_check = true;
6179
6180 return __e1000_resume(pdev);
6181}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006182#endif /* CONFIG_PM_SLEEP */
6183
6184#ifdef CONFIG_PM_RUNTIME
6185static int e1000_runtime_suspend(struct device *dev)
6186{
6187 struct pci_dev *pdev = to_pci_dev(dev);
6188 struct net_device *netdev = pci_get_drvdata(pdev);
6189 struct e1000_adapter *adapter = netdev_priv(netdev);
6190
6191 if (e1000e_pm_ready(adapter)) {
6192 bool wake;
6193
6194 __e1000_shutdown(pdev, &wake, true);
6195 }
6196
6197 return 0;
6198}
6199
6200static int e1000_idle(struct device *dev)
6201{
6202 struct pci_dev *pdev = to_pci_dev(dev);
6203 struct net_device *netdev = pci_get_drvdata(pdev);
6204 struct e1000_adapter *adapter = netdev_priv(netdev);
6205
6206 if (!e1000e_pm_ready(adapter))
6207 return 0;
6208
6209 if (adapter->idle_check) {
6210 adapter->idle_check = false;
6211 if (!e1000e_has_link(adapter))
6212 pm_schedule_suspend(dev, MSEC_PER_SEC);
6213 }
6214
6215 return -EBUSY;
6216}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006217
6218static int e1000_runtime_resume(struct device *dev)
6219{
6220 struct pci_dev *pdev = to_pci_dev(dev);
6221 struct net_device *netdev = pci_get_drvdata(pdev);
6222 struct e1000_adapter *adapter = netdev_priv(netdev);
6223
6224 if (!e1000e_pm_ready(adapter))
6225 return 0;
6226
6227 adapter->idle_check = !dev->power.runtime_auto;
6228 return __e1000_resume(pdev);
6229}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006230#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006231#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006232
6233static void e1000_shutdown(struct pci_dev *pdev)
6234{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006235 bool wake = false;
6236
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006237 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006238
6239 if (system_state == SYSTEM_POWER_OFF)
6240 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006241}
6242
6243#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006244
Bruce Allan8bb62862013-01-16 08:46:49 +00006245static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006246{
6247 struct net_device *netdev = data;
6248 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006249
6250 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006251 int vector, msix_irq;
6252
Dongdong Deng147b2c82010-11-16 19:50:15 -08006253 vector = 0;
6254 msix_irq = adapter->msix_entries[vector].vector;
6255 disable_irq(msix_irq);
6256 e1000_intr_msix_rx(msix_irq, netdev);
6257 enable_irq(msix_irq);
6258
6259 vector++;
6260 msix_irq = adapter->msix_entries[vector].vector;
6261 disable_irq(msix_irq);
6262 e1000_intr_msix_tx(msix_irq, netdev);
6263 enable_irq(msix_irq);
6264
6265 vector++;
6266 msix_irq = adapter->msix_entries[vector].vector;
6267 disable_irq(msix_irq);
6268 e1000_msix_other(msix_irq, netdev);
6269 enable_irq(msix_irq);
6270 }
6271
6272 return IRQ_HANDLED;
6273}
6274
Bruce Allane921eb12012-11-28 09:28:37 +00006275/**
6276 * e1000_netpoll
6277 * @netdev: network interface device structure
6278 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006279 * Polling 'interrupt' - used by things like netconsole to send skbs
6280 * without having to re-enable interrupts. It's not called while
6281 * the interrupt routine is executing.
6282 */
6283static void e1000_netpoll(struct net_device *netdev)
6284{
6285 struct e1000_adapter *adapter = netdev_priv(netdev);
6286
Dongdong Deng147b2c82010-11-16 19:50:15 -08006287 switch (adapter->int_mode) {
6288 case E1000E_INT_MODE_MSIX:
6289 e1000_intr_msix(adapter->pdev->irq, netdev);
6290 break;
6291 case E1000E_INT_MODE_MSI:
6292 disable_irq(adapter->pdev->irq);
6293 e1000_intr_msi(adapter->pdev->irq, netdev);
6294 enable_irq(adapter->pdev->irq);
6295 break;
6296 default: /* E1000E_INT_MODE_LEGACY */
6297 disable_irq(adapter->pdev->irq);
6298 e1000_intr(adapter->pdev->irq, netdev);
6299 enable_irq(adapter->pdev->irq);
6300 break;
6301 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006302}
6303#endif
6304
6305/**
6306 * e1000_io_error_detected - called when PCI error is detected
6307 * @pdev: Pointer to PCI device
6308 * @state: The current pci connection state
6309 *
6310 * This function is called after a PCI bus error affecting
6311 * this device has been detected.
6312 */
6313static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6314 pci_channel_state_t state)
6315{
6316 struct net_device *netdev = pci_get_drvdata(pdev);
6317 struct e1000_adapter *adapter = netdev_priv(netdev);
6318
6319 netif_device_detach(netdev);
6320
Mike Masonc93b5a72009-06-30 12:45:53 +00006321 if (state == pci_channel_io_perm_failure)
6322 return PCI_ERS_RESULT_DISCONNECT;
6323
Auke Kokbc7f75f2007-09-17 12:30:59 -07006324 if (netif_running(netdev))
6325 e1000e_down(adapter);
6326 pci_disable_device(pdev);
6327
6328 /* Request a slot slot reset. */
6329 return PCI_ERS_RESULT_NEED_RESET;
6330}
6331
6332/**
6333 * e1000_io_slot_reset - called after the pci bus has been reset.
6334 * @pdev: Pointer to PCI device
6335 *
6336 * Restart the card from scratch, as if from a cold-boot. Implementation
6337 * resembles the first-half of the e1000_resume routine.
6338 */
6339static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6340{
6341 struct net_device *netdev = pci_get_drvdata(pdev);
6342 struct e1000_adapter *adapter = netdev_priv(netdev);
6343 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006344 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006345 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006346 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006347
Bruce Allan78cd29d2011-03-24 03:09:03 +00006348 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6349 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006350 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006351 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6352 if (aspm_disable_flag)
6353 e1000e_disable_aspm(pdev, aspm_disable_flag);
6354
Bruce Allanf0f422e2008-08-04 17:21:53 -07006355 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006356 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006357 dev_err(&pdev->dev,
6358 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006359 result = PCI_ERS_RESULT_DISCONNECT;
6360 } else {
6361 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006362 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006363 pci_restore_state(pdev);
6364
6365 pci_enable_wake(pdev, PCI_D3hot, 0);
6366 pci_enable_wake(pdev, PCI_D3cold, 0);
6367
6368 e1000e_reset(adapter);
6369 ew32(WUS, ~0);
6370 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006371 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006372
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006373 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006374
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006375 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006376}
6377
6378/**
6379 * e1000_io_resume - called when traffic can start flowing again.
6380 * @pdev: Pointer to PCI device
6381 *
6382 * This callback is called when the error recovery driver tells us that
6383 * its OK to resume normal operation. Implementation resembles the
6384 * second-half of the e1000_resume routine.
6385 */
6386static void e1000_io_resume(struct pci_dev *pdev)
6387{
6388 struct net_device *netdev = pci_get_drvdata(pdev);
6389 struct e1000_adapter *adapter = netdev_priv(netdev);
6390
Bruce Allancd791612010-05-10 14:59:51 +00006391 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006392
6393 if (netif_running(netdev)) {
6394 if (e1000e_up(adapter)) {
6395 dev_err(&pdev->dev,
6396 "can't bring device back up after reset\n");
6397 return;
6398 }
6399 }
6400
6401 netif_device_attach(netdev);
6402
Bruce Allane921eb12012-11-28 09:28:37 +00006403 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006404 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006405 * under the control of the driver.
6406 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006407 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006408 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006409
6410}
6411
6412static void e1000_print_device_info(struct e1000_adapter *adapter)
6413{
6414 struct e1000_hw *hw = &adapter->hw;
6415 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006416 u32 ret_val;
6417 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006418
6419 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006420 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006421 /* bus width */
6422 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
6423 "Width x1"),
6424 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006425 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006426 e_info("Intel(R) PRO/%s Network Connection\n",
6427 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006428 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6429 E1000_PBANUM_LENGTH);
6430 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006431 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006432 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6433 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006434}
6435
Auke Kok10aa4c02008-08-04 17:21:20 -07006436static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6437{
6438 struct e1000_hw *hw = &adapter->hw;
6439 int ret_val;
6440 u16 buf = 0;
6441
6442 if (hw->mac.type != e1000_82573)
6443 return;
6444
6445 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006446 le16_to_cpus(&buf);
6447 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006448 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006449 dev_warn(&adapter->pdev->dev,
6450 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006451 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006452}
6453
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006454static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006455 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006456{
6457 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006458 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006459
6460 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6461 adapter->flags |= FLAG_TSO_FORCE;
6462
6463 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006464 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6465 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006466 return 0;
6467
Ben Greear01840392012-02-11 15:39:25 +00006468 if (changed & NETIF_F_RXFCS) {
6469 if (features & NETIF_F_RXFCS) {
6470 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6471 } else {
6472 /* We need to take it back to defaults, which might mean
6473 * stripping is still disabled at the adapter level.
6474 */
6475 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6476 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6477 else
6478 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6479 }
6480 }
6481
Bruce Allan70495a52012-01-11 01:26:50 +00006482 netdev->features = features;
6483
Bruce Allandc221292011-08-19 03:23:48 +00006484 if (netif_running(netdev))
6485 e1000e_reinit_locked(adapter);
6486 else
6487 e1000e_reset(adapter);
6488
6489 return 0;
6490}
6491
Stephen Hemminger651c2462008-11-19 21:57:48 -08006492static const struct net_device_ops e1000e_netdev_ops = {
6493 .ndo_open = e1000_open,
6494 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006495 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006496 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006497 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006498 .ndo_set_mac_address = e1000_set_mac,
6499 .ndo_change_mtu = e1000_change_mtu,
6500 .ndo_do_ioctl = e1000_ioctl,
6501 .ndo_tx_timeout = e1000_tx_timeout,
6502 .ndo_validate_addr = eth_validate_addr,
6503
Stephen Hemminger651c2462008-11-19 21:57:48 -08006504 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6505 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6506#ifdef CONFIG_NET_POLL_CONTROLLER
6507 .ndo_poll_controller = e1000_netpoll,
6508#endif
Bruce Allandc221292011-08-19 03:23:48 +00006509 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006510};
6511
Auke Kokbc7f75f2007-09-17 12:30:59 -07006512/**
6513 * e1000_probe - Device Initialization Routine
6514 * @pdev: PCI device information struct
6515 * @ent: entry in e1000_pci_tbl
6516 *
6517 * Returns 0 on success, negative on failure
6518 *
6519 * e1000_probe initializes an adapter identified by a pci_dev structure.
6520 * The OS initialization, configuring of the adapter private structure,
6521 * and a hardware reset occur.
6522 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006523static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006524{
6525 struct net_device *netdev;
6526 struct e1000_adapter *adapter;
6527 struct e1000_hw *hw;
6528 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006529 resource_size_t mmio_start, mmio_len;
6530 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006531 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006532 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006533 int i, err, pci_using_dac;
6534 u16 eeprom_data = 0;
6535 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6536
Bruce Allan78cd29d2011-03-24 03:09:03 +00006537 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6538 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006539 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006540 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6541 if (aspm_disable_flag)
6542 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006543
Bruce Allanf0f422e2008-08-04 17:21:53 -07006544 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006545 if (err)
6546 return err;
6547
6548 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006549 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006550 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006551 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006552 if (!err)
6553 pci_using_dac = 1;
6554 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006555 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006556 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006557 err = dma_set_coherent_mask(&pdev->dev,
6558 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006559 if (err) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00006560 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006561 goto err_dma;
6562 }
6563 }
6564 }
6565
Arjan van de Vene8de1482008-10-22 19:55:31 -07006566 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allan55c5f552013-01-12 07:28:24 +00006567 pci_select_bars(pdev, IORESOURCE_MEM),
6568 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006569 if (err)
6570 goto err_pci_reg;
6571
Xiaotian Feng68eac462009-08-14 14:35:52 +00006572 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006573 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006574
Auke Kokbc7f75f2007-09-17 12:30:59 -07006575 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006576 /* PCI config space info */
6577 err = pci_save_state(pdev);
6578 if (err)
6579 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006580
6581 err = -ENOMEM;
6582 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6583 if (!netdev)
6584 goto err_alloc_etherdev;
6585
Auke Kokbc7f75f2007-09-17 12:30:59 -07006586 SET_NETDEV_DEV(netdev, &pdev->dev);
6587
Tom Herbertf85e4df2010-05-05 14:03:32 +00006588 netdev->irq = pdev->irq;
6589
Auke Kokbc7f75f2007-09-17 12:30:59 -07006590 pci_set_drvdata(pdev, netdev);
6591 adapter = netdev_priv(netdev);
6592 hw = &adapter->hw;
6593 adapter->netdev = netdev;
6594 adapter->pdev = pdev;
6595 adapter->ei = ei;
6596 adapter->pba = ei->pba;
6597 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006598 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006599 adapter->hw.adapter = adapter;
6600 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006601 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006602 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006603
6604 mmio_start = pci_resource_start(pdev, 0);
6605 mmio_len = pci_resource_len(pdev, 0);
6606
6607 err = -EIO;
6608 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6609 if (!adapter->hw.hw_addr)
6610 goto err_ioremap;
6611
6612 if ((adapter->flags & FLAG_HAS_FLASH) &&
6613 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6614 flash_start = pci_resource_start(pdev, 1);
6615 flash_len = pci_resource_len(pdev, 1);
6616 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6617 if (!adapter->hw.flash_address)
6618 goto err_flashmap;
6619 }
6620
6621 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006622 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006623 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006624 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006625 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006626 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006627
6628 netdev->mem_start = mmio_start;
6629 netdev->mem_end = mmio_start + mmio_len;
6630
6631 adapter->bd_number = cards_found++;
6632
Bruce Allan4662e822008-08-26 18:37:06 -07006633 e1000e_check_options(adapter);
6634
Auke Kokbc7f75f2007-09-17 12:30:59 -07006635 /* setup adapter struct */
6636 err = e1000_sw_init(adapter);
6637 if (err)
6638 goto err_sw_init;
6639
Auke Kokbc7f75f2007-09-17 12:30:59 -07006640 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6641 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6642 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6643
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006644 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006645 if (err)
6646 goto err_hw_init;
6647
Bruce Allan4a770352008-10-01 17:18:35 -07006648 if ((adapter->flags & FLAG_IS_ICH) &&
6649 (adapter->flags & FLAG_READ_ONLY_NVM))
6650 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6651
Auke Kokbc7f75f2007-09-17 12:30:59 -07006652 hw->mac.ops.get_bus_info(&adapter->hw);
6653
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006654 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006655
6656 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006657 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006658 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6659 adapter->hw.phy.disable_polarity_correction = 0;
6660 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6661 }
6662
Bruce Allan470a5422012-05-26 06:08:48 +00006663 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006664 dev_info(&pdev->dev,
6665 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006666
Bruce Allandc221292011-08-19 03:23:48 +00006667 /* Set initial default active device features */
6668 netdev->features = (NETIF_F_SG |
6669 NETIF_F_HW_VLAN_RX |
6670 NETIF_F_HW_VLAN_TX |
6671 NETIF_F_TSO |
6672 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006673 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006674 NETIF_F_RXCSUM |
6675 NETIF_F_HW_CSUM);
6676
6677 /* Set user-changeable features (subset of all device features) */
6678 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006679 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006680 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006681 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006682
6683 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6684 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6685
Bruce Allandc221292011-08-19 03:23:48 +00006686 netdev->vlan_features |= (NETIF_F_SG |
6687 NETIF_F_TSO |
6688 NETIF_F_TSO6 |
6689 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006690
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006691 netdev->priv_flags |= IFF_UNICAST_FLT;
6692
Yi Zou7b872a52010-09-22 17:57:58 +00006693 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006694 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006695 netdev->vlan_features |= NETIF_F_HIGHDMA;
6696 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006697
Auke Kokbc7f75f2007-09-17 12:30:59 -07006698 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6699 adapter->flags |= FLAG_MNG_PT_ENABLED;
6700
Bruce Allane921eb12012-11-28 09:28:37 +00006701 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006702 * put the device in a known good starting state
6703 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006704 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6705
Bruce Allane921eb12012-11-28 09:28:37 +00006706 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 * attempt. Let's give it a few tries
6708 */
6709 for (i = 0;; i++) {
6710 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6711 break;
6712 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006713 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006714 err = -EIO;
6715 goto err_eeprom;
6716 }
6717 }
6718
Auke Kok10aa4c02008-08-04 17:21:20 -07006719 e1000_eeprom_checks(adapter);
6720
Bruce Allan608f8a02010-01-13 02:04:58 +00006721 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006722 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006723 dev_err(&pdev->dev,
6724 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006725
6726 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006727
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006728 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006729 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006730 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006731 err = -EIO;
6732 goto err_eeprom;
6733 }
6734
6735 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006736 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006737 adapter->watchdog_timer.data = (unsigned long) adapter;
6738
6739 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006740 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006741 adapter->phy_info_timer.data = (unsigned long) adapter;
6742
6743 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6744 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006745 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6746 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006747 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006748
Auke Kokbc7f75f2007-09-17 12:30:59 -07006749 /* Initialize link parameters. User can change them with ethtool */
6750 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006751 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006752 adapter->hw.fc.requested_mode = e1000_fc_default;
6753 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006754 adapter->hw.phy.autoneg_advertised = 0x2f;
6755
6756 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006757 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6758 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006759
Bruce Allane921eb12012-11-28 09:28:37 +00006760 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006761 * the EEPROM, enable the ACPI Magic Packet filter
6762 */
6763 if (adapter->flags & FLAG_APME_IN_WUC) {
6764 /* APME bit in EEPROM is mapped to WUC.APME */
6765 eeprom_data = er32(WUC);
6766 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006767 if ((hw->mac.type > e1000_ich10lan) &&
6768 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006769 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006770 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6771 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6772 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006773 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6774 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006775 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006776 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6777 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006778 }
6779
6780 /* fetch WoL from EEPROM */
6781 if (eeprom_data & eeprom_apme_mask)
6782 adapter->eeprom_wol |= E1000_WUFC_MAG;
6783
Bruce Allane921eb12012-11-28 09:28:37 +00006784 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006785 * where the eeprom may be wrong or the board simply won't support
6786 * wake on lan on a particular port
6787 */
6788 if (!(adapter->flags & FLAG_HAS_WOL))
6789 adapter->eeprom_wol = 0;
6790
6791 /* initialize the wol settings based on the eeprom settings */
6792 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006793 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006794
Bruce Allan84527592008-11-21 17:00:22 -08006795 /* save off EEPROM version number */
6796 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6797
Auke Kokbc7f75f2007-09-17 12:30:59 -07006798 /* reset the hardware with the new settings */
6799 e1000e_reset(adapter);
6800
Bruce Allane921eb12012-11-28 09:28:37 +00006801 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006802 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006803 * under the control of the driver.
6804 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006805 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006806 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006807
Bruce Allanf2315bf2011-12-16 00:46:59 +00006808 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809 err = register_netdev(netdev);
6810 if (err)
6811 goto err_register;
6812
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006813 /* carrier off reporting is important to ethtool even BEFORE open */
6814 netif_carrier_off(netdev);
6815
Bruce Alland89777b2013-01-19 01:09:58 +00006816 /* init PTP hardware clock */
6817 e1000e_ptp_init(adapter);
6818
Auke Kokbc7f75f2007-09-17 12:30:59 -07006819 e1000_print_device_info(adapter);
6820
Alan Sternf3ec4f82010-06-08 15:23:51 -04006821 if (pci_dev_run_wake(pdev))
6822 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006823
Auke Kokbc7f75f2007-09-17 12:30:59 -07006824 return 0;
6825
6826err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006827 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006828 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006829err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006830 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006831 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006832err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006833 kfree(adapter->tx_ring);
6834 kfree(adapter->rx_ring);
6835err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006836 if (adapter->hw.flash_address)
6837 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006838 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006839err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006840 iounmap(adapter->hw.hw_addr);
6841err_ioremap:
6842 free_netdev(netdev);
6843err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006844 pci_release_selected_regions(pdev,
6845 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006846err_pci_reg:
6847err_dma:
6848 pci_disable_device(pdev);
6849 return err;
6850}
6851
6852/**
6853 * e1000_remove - Device Removal Routine
6854 * @pdev: PCI device information struct
6855 *
6856 * e1000_remove is called by the PCI subsystem to alert the driver
6857 * that it should release a PCI device. The could be caused by a
6858 * Hot-Plug event, or because the driver is going to be removed from
6859 * memory.
6860 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006861static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006862{
6863 struct net_device *netdev = pci_get_drvdata(pdev);
6864 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006865 bool down = test_bit(__E1000_DOWN, &adapter->state);
6866
Bruce Alland89777b2013-01-19 01:09:58 +00006867 e1000e_ptp_remove(adapter);
6868
Bruce Allane921eb12012-11-28 09:28:37 +00006869 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006870 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006871 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006872 if (!down)
6873 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006874 del_timer_sync(&adapter->watchdog_timer);
6875 del_timer_sync(&adapter->phy_info_timer);
6876
Bruce Allan41cec6f2009-11-20 23:28:56 +00006877 cancel_work_sync(&adapter->reset_task);
6878 cancel_work_sync(&adapter->watchdog_task);
6879 cancel_work_sync(&adapter->downshift_task);
6880 cancel_work_sync(&adapter->update_phy_task);
6881 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006882
Bruce Allanb67e1912012-12-27 08:32:33 +00006883 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6884 cancel_work_sync(&adapter->tx_hwtstamp_work);
6885 if (adapter->tx_hwtstamp_skb) {
6886 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6887 adapter->tx_hwtstamp_skb = NULL;
6888 }
6889 }
6890
Bruce Allan17f208d2009-12-01 15:47:22 +00006891 if (!(netdev->flags & IFF_UP))
6892 e1000_power_down_phy(adapter);
6893
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006894 /* Don't lie to e1000_close() down the road. */
6895 if (!down)
6896 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006897 unregister_netdev(netdev);
6898
Alan Sternf3ec4f82010-06-08 15:23:51 -04006899 if (pci_dev_run_wake(pdev))
6900 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006901
Bruce Allane921eb12012-11-28 09:28:37 +00006902 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006903 * would have already happened in close and is redundant.
6904 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006905 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006906
Bruce Allan4662e822008-08-26 18:37:06 -07006907 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006908 kfree(adapter->tx_ring);
6909 kfree(adapter->rx_ring);
6910
6911 iounmap(adapter->hw.hw_addr);
6912 if (adapter->hw.flash_address)
6913 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006914 pci_release_selected_regions(pdev,
6915 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006916
6917 free_netdev(netdev);
6918
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006919 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006920 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006921
Auke Kokbc7f75f2007-09-17 12:30:59 -07006922 pci_disable_device(pdev);
6923}
6924
6925/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006926static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006927 .error_detected = e1000_io_error_detected,
6928 .slot_reset = e1000_io_slot_reset,
6929 .resume = e1000_io_resume,
6930};
6931
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006932static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6936 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006942
Auke Kokbc7f75f2007-09-17 12:30:59 -07006943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006947
Auke Kokbc7f75f2007-09-17 12:30:59 -07006948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006951
Bruce Allan4662e822008-08-26 18:37:06 -07006952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006955
Auke Kokbc7f75f2007-09-17 12:30:59 -07006956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6957 board_80003es2lan },
6958 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6959 board_80003es2lan },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6961 board_80003es2lan },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6963 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006964
Auke Kokbc7f75f2007-09-17 12:30:59 -07006965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006973
Auke Kokbc7f75f2007-09-17 12:30:59 -07006974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006980 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6983
6984 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006987
Bruce Allanf4187b52008-08-26 18:36:50 -07006988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6989 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006990 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006991
Bruce Allana4f58f52009-06-02 11:29:18 +00006992 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6993 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6996
Bruce Alland3738bb2010-06-16 13:27:28 +00006997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6998 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6999
Bruce Allan2fbe4522012-04-19 03:21:47 +00007000 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
7001 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00007002 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
7003 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00007004
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007005 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007006};
7007MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7008
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007009#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007010static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007011 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
7012 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
7013 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007014};
David S. Millere50208a2010-03-16 23:36:24 -07007015#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007016
Auke Kokbc7f75f2007-09-17 12:30:59 -07007017/* PCI Device API Driver */
7018static struct pci_driver e1000_driver = {
7019 .name = e1000e_driver_name,
7020 .id_table = e1000_pci_tbl,
7021 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007022 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007023#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007024 .driver = {
7025 .pm = &e1000_pm_ops,
7026 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007027#endif
7028 .shutdown = e1000_shutdown,
7029 .err_handler = &e1000_err_handler
7030};
7031
7032/**
7033 * e1000_init_module - Driver Registration Routine
7034 *
7035 * e1000_init_module is the first routine called when the driver is
7036 * loaded. All it does is register with the PCI subsystem.
7037 **/
7038static int __init e1000_init_module(void)
7039{
7040 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007041 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7042 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007043 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007044 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007045
Auke Kokbc7f75f2007-09-17 12:30:59 -07007046 return ret;
7047}
7048module_init(e1000_init_module);
7049
7050/**
7051 * e1000_exit_module - Driver Exit Cleanup Routine
7052 *
7053 * e1000_exit_module is called just before the driver is removed
7054 * from memory.
7055 **/
7056static void __exit e1000_exit_module(void)
7057{
7058 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007059}
7060module_exit(e1000_exit_module);
7061
7062
7063MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7064MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7065MODULE_LICENSE("GPL");
7066MODULE_VERSION(DRV_VERSION);
7067
Bruce Allan06c24b92012-02-23 03:13:13 +00007068/* netdev.c */