blob: ca1c10e5f69bfdf70623af58819675afa1b248c0 [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
Taku Izumi84f4ee92010-04-27 14:39:08 +000089static const struct e1000_reg_info e1000_reg_info_tbl[] = {
Taku Izumi84f4ee92010-04-27 14:39:08 +000090 /* General Registers */
91 {E1000_CTRL, "CTRL"},
92 {E1000_STATUS, "STATUS"},
93 {E1000_CTRL_EXT, "CTRL_EXT"},
94
95 /* Interrupt Registers */
96 {E1000_ICR, "ICR"},
97
Bruce Allanaf667a22010-12-31 06:10:01 +000098 /* Rx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +000099 {E1000_RCTL, "RCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000100 {E1000_RDLEN(0), "RDLEN"},
101 {E1000_RDH(0), "RDH"},
102 {E1000_RDT(0), "RDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000103 {E1000_RDTR, "RDTR"},
104 {E1000_RXDCTL(0), "RXDCTL"},
105 {E1000_ERT, "ERT"},
Bruce Allan1e360522012-03-20 03:48:13 +0000106 {E1000_RDBAL(0), "RDBAL"},
107 {E1000_RDBAH(0), "RDBAH"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000108 {E1000_RDFH, "RDFH"},
109 {E1000_RDFT, "RDFT"},
110 {E1000_RDFHS, "RDFHS"},
111 {E1000_RDFTS, "RDFTS"},
112 {E1000_RDFPC, "RDFPC"},
113
Bruce Allanaf667a22010-12-31 06:10:01 +0000114 /* Tx Registers */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000115 {E1000_TCTL, "TCTL"},
Bruce Allan1e360522012-03-20 03:48:13 +0000116 {E1000_TDBAL(0), "TDBAL"},
117 {E1000_TDBAH(0), "TDBAH"},
118 {E1000_TDLEN(0), "TDLEN"},
119 {E1000_TDH(0), "TDH"},
120 {E1000_TDT(0), "TDT"},
Taku Izumi84f4ee92010-04-27 14:39:08 +0000121 {E1000_TIDV, "TIDV"},
122 {E1000_TXDCTL(0), "TXDCTL"},
123 {E1000_TADV, "TADV"},
124 {E1000_TARC(0), "TARC"},
125 {E1000_TDFH, "TDFH"},
126 {E1000_TDFT, "TDFT"},
127 {E1000_TDFHS, "TDFHS"},
128 {E1000_TDFTS, "TDFTS"},
129 {E1000_TDFPC, "TDFPC"},
130
131 /* List Terminator */
Bruce Allanf36bb6c2012-01-31 06:38:04 +0000132 {0, NULL}
Taku Izumi84f4ee92010-04-27 14:39:08 +0000133};
134
Bruce Allane921eb12012-11-28 09:28:37 +0000135/**
Taku Izumi84f4ee92010-04-27 14:39:08 +0000136 * e1000_regdump - register printout routine
Bruce Allane921eb12012-11-28 09:28:37 +0000137 * @hw: pointer to the HW structure
138 * @reginfo: pointer to the register info table
139 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000140static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
141{
142 int n = 0;
143 char rname[16];
144 u32 regs[8];
145
146 switch (reginfo->ofs) {
147 case E1000_RXDCTL(0):
148 for (n = 0; n < 2; n++)
149 regs[n] = __er32(hw, E1000_RXDCTL(n));
150 break;
151 case E1000_TXDCTL(0):
152 for (n = 0; n < 2; n++)
153 regs[n] = __er32(hw, E1000_TXDCTL(n));
154 break;
155 case E1000_TARC(0):
156 for (n = 0; n < 2; n++)
157 regs[n] = __er32(hw, E1000_TARC(n));
158 break;
159 default:
Jeff Kirsheref456f82011-11-03 11:40:28 +0000160 pr_info("%-15s %08x\n",
161 reginfo->name, __er32(hw, reginfo->ofs));
Taku Izumi84f4ee92010-04-27 14:39:08 +0000162 return;
163 }
164
165 snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000166 pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000167}
168
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000169static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
170 struct e1000_buffer *bi)
171{
172 int i;
173 struct e1000_ps_page *ps_page;
174
175 for (i = 0; i < adapter->rx_ps_pages; i++) {
176 ps_page = &bi->ps_pages[i];
177
178 if (ps_page->page) {
179 pr_info("packet dump for ps_page %d:\n", i);
180 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
181 16, 1, page_address(ps_page->page),
182 PAGE_SIZE, true);
183 }
184 }
185}
186
Bruce Allane921eb12012-11-28 09:28:37 +0000187/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000188 * e1000e_dump - Print registers, Tx-ring and Rx-ring
Bruce Allane921eb12012-11-28 09:28:37 +0000189 * @adapter: board private structure
190 **/
Taku Izumi84f4ee92010-04-27 14:39:08 +0000191static void e1000e_dump(struct e1000_adapter *adapter)
192{
193 struct net_device *netdev = adapter->netdev;
194 struct e1000_hw *hw = &adapter->hw;
195 struct e1000_reg_info *reginfo;
196 struct e1000_ring *tx_ring = adapter->tx_ring;
197 struct e1000_tx_desc *tx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000198 struct my_u0 {
Bruce Allane885d762012-01-31 06:37:32 +0000199 __le64 a;
200 __le64 b;
Bruce Allanaf667a22010-12-31 06:10:01 +0000201 } *u0;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000202 struct e1000_buffer *buffer_info;
203 struct e1000_ring *rx_ring = adapter->rx_ring;
204 union e1000_rx_desc_packet_split *rx_desc_ps;
Bruce Allan5f450212011-07-22 06:21:46 +0000205 union e1000_rx_desc_extended *rx_desc;
Bruce Allanaf667a22010-12-31 06:10:01 +0000206 struct my_u1 {
Bruce Allane885d762012-01-31 06:37:32 +0000207 __le64 a;
208 __le64 b;
209 __le64 c;
210 __le64 d;
Bruce Allanaf667a22010-12-31 06:10:01 +0000211 } *u1;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000212 u32 staterr;
213 int i = 0;
214
215 if (!netif_msg_hw(adapter))
216 return;
217
218 /* Print netdevice Info */
219 if (netdev) {
220 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000221 pr_info("Device Name state trans_start last_rx\n");
222 pr_info("%-15s %016lX %016lX %016lX\n",
223 netdev->name, netdev->state, netdev->trans_start,
224 netdev->last_rx);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000225 }
226
227 /* Print Registers */
228 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000229 pr_info(" Register Name Value\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000230 for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
231 reginfo->name; reginfo++) {
232 e1000_regdump(hw, reginfo);
233 }
234
Bruce Allanaf667a22010-12-31 06:10:01 +0000235 /* Print Tx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000236 if (!netdev || !netif_running(netdev))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000237 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000238
Bruce Allanaf667a22010-12-31 06:10:01 +0000239 dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000240 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000241 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
Jeff Kirsheref456f82011-11-03 11:40:28 +0000242 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
243 0, tx_ring->next_to_use, tx_ring->next_to_clean,
244 (unsigned long long)buffer_info->dma,
245 buffer_info->length,
246 buffer_info->next_to_watch,
247 (unsigned long long)buffer_info->time_stamp);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000248
Bruce Allanaf667a22010-12-31 06:10:01 +0000249 /* Print Tx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000250 if (!netif_msg_tx_done(adapter))
251 goto rx_ring_summary;
252
Bruce Allanaf667a22010-12-31 06:10:01 +0000253 dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000254
255 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
256 *
257 * Legacy Transmit Descriptor
258 * +--------------------------------------------------------------+
259 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
260 * +--------------------------------------------------------------+
261 * 8 | Special | CSS | Status | CMD | CSO | Length |
262 * +--------------------------------------------------------------+
263 * 63 48 47 36 35 32 31 24 23 16 15 0
264 *
265 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
266 * 63 48 47 40 39 32 31 16 15 8 7 0
267 * +----------------------------------------------------------------+
268 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
269 * +----------------------------------------------------------------+
270 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
271 * +----------------------------------------------------------------+
272 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
273 *
274 * Extended Data Descriptor (DTYP=0x1)
275 * +----------------------------------------------------------------+
276 * 0 | Buffer Address [63:0] |
277 * +----------------------------------------------------------------+
278 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
279 * +----------------------------------------------------------------+
280 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
281 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000282 pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
283 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
284 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 +0000285 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000286 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000287 tx_desc = E1000_TX_DESC(*tx_ring, i);
288 buffer_info = &tx_ring->buffer_info[i];
289 u0 = (struct my_u0 *)tx_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000290 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000291 next_desc = " NTC/U";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000292 else if (i == tx_ring->next_to_use)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000293 next_desc = " NTU";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000294 else if (i == tx_ring->next_to_clean)
Jeff Kirsheref456f82011-11-03 11:40:28 +0000295 next_desc = " NTC";
Taku Izumi84f4ee92010-04-27 14:39:08 +0000296 else
Jeff Kirsheref456f82011-11-03 11:40:28 +0000297 next_desc = "";
298 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
299 (!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
300 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
301 i,
302 (unsigned long long)le64_to_cpu(u0->a),
303 (unsigned long long)le64_to_cpu(u0->b),
304 (unsigned long long)buffer_info->dma,
305 buffer_info->length, buffer_info->next_to_watch,
306 (unsigned long long)buffer_info->time_stamp,
307 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000308
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000309 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumi84f4ee92010-04-27 14:39:08 +0000310 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000311 16, 1, buffer_info->skb->data,
312 buffer_info->skb->len, true);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000313 }
314
Bruce Allanaf667a22010-12-31 06:10:01 +0000315 /* Print Rx Ring Summary */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000316rx_ring_summary:
Bruce Allanaf667a22010-12-31 06:10:01 +0000317 dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
Jeff Kirsheref456f82011-11-03 11:40:28 +0000318 pr_info("Queue [NTU] [NTC]\n");
319 pr_info(" %5d %5X %5X\n",
320 0, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000321
Bruce Allanaf667a22010-12-31 06:10:01 +0000322 /* Print Rx Ring */
Taku Izumi84f4ee92010-04-27 14:39:08 +0000323 if (!netif_msg_rx_status(adapter))
Bruce Allanfe1e9802012-01-31 06:37:54 +0000324 return;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000325
Bruce Allanaf667a22010-12-31 06:10:01 +0000326 dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
Taku Izumi84f4ee92010-04-27 14:39:08 +0000327 switch (adapter->rx_ps_pages) {
328 case 1:
329 case 2:
330 case 3:
331 /* [Extended] Packet Split Receive Descriptor Format
332 *
333 * +-----------------------------------------------------+
334 * 0 | Buffer Address 0 [63:0] |
335 * +-----------------------------------------------------+
336 * 8 | Buffer Address 1 [63:0] |
337 * +-----------------------------------------------------+
338 * 16 | Buffer Address 2 [63:0] |
339 * +-----------------------------------------------------+
340 * 24 | Buffer Address 3 [63:0] |
341 * +-----------------------------------------------------+
342 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000343 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 +0000344 /* [Extended] Receive Descriptor (Write-Back) Format
345 *
346 * 63 48 47 32 31 13 12 8 7 4 3 0
347 * +------------------------------------------------------+
348 * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
349 * | Checksum | Ident | | Queue | | Type |
350 * +------------------------------------------------------+
351 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
352 * +------------------------------------------------------+
353 * 63 48 47 32 31 20 19 0
354 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000355 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 +0000356 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000357 const char *next_desc;
Taku Izumi84f4ee92010-04-27 14:39:08 +0000358 buffer_info = &rx_ring->buffer_info[i];
359 rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
360 u1 = (struct my_u1 *)rx_desc_ps;
361 staterr =
Bruce Allanaf667a22010-12-31 06:10:01 +0000362 le32_to_cpu(rx_desc_ps->wb.middle.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000363
364 if (i == rx_ring->next_to_use)
365 next_desc = " NTU";
366 else if (i == rx_ring->next_to_clean)
367 next_desc = " NTC";
368 else
369 next_desc = "";
370
Taku Izumi84f4ee92010-04-27 14:39:08 +0000371 if (staterr & E1000_RXD_STAT_DD) {
372 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000373 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
374 "RWB", i,
375 (unsigned long long)le64_to_cpu(u1->a),
376 (unsigned long long)le64_to_cpu(u1->b),
377 (unsigned long long)le64_to_cpu(u1->c),
378 (unsigned long long)le64_to_cpu(u1->d),
379 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000380 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000381 pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
382 "R ", i,
383 (unsigned long long)le64_to_cpu(u1->a),
384 (unsigned long long)le64_to_cpu(u1->b),
385 (unsigned long long)le64_to_cpu(u1->c),
386 (unsigned long long)le64_to_cpu(u1->d),
387 (unsigned long long)buffer_info->dma,
388 buffer_info->skb, next_desc);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000389
390 if (netif_msg_pktdata(adapter))
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000391 e1000e_dump_ps_pages(adapter,
392 buffer_info);
Taku Izumi84f4ee92010-04-27 14:39:08 +0000393 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000394 }
395 break;
396 default:
397 case 0:
Bruce Allan5f450212011-07-22 06:21:46 +0000398 /* Extended Receive Descriptor (Read) Format
Taku Izumi84f4ee92010-04-27 14:39:08 +0000399 *
Bruce Allan5f450212011-07-22 06:21:46 +0000400 * +-----------------------------------------------------+
401 * 0 | Buffer Address [63:0] |
402 * +-----------------------------------------------------+
403 * 8 | Reserved |
404 * +-----------------------------------------------------+
Taku Izumi84f4ee92010-04-27 14:39:08 +0000405 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000406 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 +0000407 /* Extended Receive Descriptor (Write-Back) Format
408 *
409 * 63 48 47 32 31 24 23 4 3 0
410 * +------------------------------------------------------+
411 * | RSS Hash | | | |
412 * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
413 * | Packet | IP | | | Type |
414 * | Checksum | Ident | | | |
415 * +------------------------------------------------------+
416 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
417 * +------------------------------------------------------+
418 * 63 48 47 32 31 20 19 0
419 */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000420 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 +0000421
422 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000423 const char *next_desc;
424
Taku Izumi84f4ee92010-04-27 14:39:08 +0000425 buffer_info = &rx_ring->buffer_info[i];
Bruce Allan5f450212011-07-22 06:21:46 +0000426 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
427 u1 = (struct my_u1 *)rx_desc;
428 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsheref456f82011-11-03 11:40:28 +0000429
430 if (i == rx_ring->next_to_use)
431 next_desc = " NTU";
432 else if (i == rx_ring->next_to_clean)
433 next_desc = " NTC";
434 else
435 next_desc = "";
436
Bruce Allan5f450212011-07-22 06:21:46 +0000437 if (staterr & E1000_RXD_STAT_DD) {
438 /* Descriptor Done */
Jeff Kirsheref456f82011-11-03 11:40:28 +0000439 pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
440 "RWB", i,
441 (unsigned long long)le64_to_cpu(u1->a),
442 (unsigned long long)le64_to_cpu(u1->b),
443 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000444 } else {
Jeff Kirsheref456f82011-11-03 11:40:28 +0000445 pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
446 "R ", i,
447 (unsigned long long)le64_to_cpu(u1->a),
448 (unsigned long long)le64_to_cpu(u1->b),
449 (unsigned long long)buffer_info->dma,
450 buffer_info->skb, next_desc);
Bruce Allan5f450212011-07-22 06:21:46 +0000451
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000452 if (netif_msg_pktdata(adapter) &&
453 buffer_info->skb)
Bruce Allan5f450212011-07-22 06:21:46 +0000454 print_hex_dump(KERN_INFO, "",
455 DUMP_PREFIX_ADDRESS, 16,
456 1,
Emil Tantilovf0c5dad2012-08-01 08:12:21 +0000457 buffer_info->skb->data,
Bruce Allan5f450212011-07-22 06:21:46 +0000458 adapter->rx_buffer_len,
459 true);
460 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000461 }
462 }
Taku Izumi84f4ee92010-04-27 14:39:08 +0000463}
464
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465/**
466 * e1000_desc_unused - calculate if we have unused descriptors
467 **/
468static int e1000_desc_unused(struct e1000_ring *ring)
469{
470 if (ring->next_to_clean > ring->next_to_use)
471 return ring->next_to_clean - ring->next_to_use - 1;
472
473 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
474}
475
476/**
Bruce Allanb67e1912012-12-27 08:32:33 +0000477 * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
478 * @adapter: board private structure
479 * @hwtstamps: time stamp structure to update
480 * @systim: unsigned 64bit system time value.
481 *
482 * Convert the system time value stored in the RX/TXSTMP registers into a
483 * hwtstamp which can be used by the upper level time stamping functions.
484 *
485 * The 'systim_lock' spinlock is used to protect the consistency of the
486 * system time value. This is needed because reading the 64 bit time
487 * value involves reading two 32 bit registers. The first read latches the
488 * value.
489 **/
490static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
491 struct skb_shared_hwtstamps *hwtstamps,
492 u64 systim)
493{
494 u64 ns;
495 unsigned long flags;
496
497 spin_lock_irqsave(&adapter->systim_lock, flags);
498 ns = timecounter_cyc2time(&adapter->tc, systim);
499 spin_unlock_irqrestore(&adapter->systim_lock, flags);
500
501 memset(hwtstamps, 0, sizeof(*hwtstamps));
502 hwtstamps->hwtstamp = ns_to_ktime(ns);
503}
504
505/**
506 * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
507 * @adapter: board private structure
508 * @status: descriptor extended error and status field
509 * @skb: particular skb to include time stamp
510 *
511 * If the time stamp is valid, convert it into the timecounter ns value
512 * and store that result into the shhwtstamps structure which is passed
513 * up the network stack.
514 **/
515static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
516 struct sk_buff *skb)
517{
518 struct e1000_hw *hw = &adapter->hw;
519 u64 rxstmp;
520
521 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
522 !(status & E1000_RXDEXT_STATERR_TST) ||
523 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
524 return;
525
526 /* The Rx time stamp registers contain the time stamp. No other
527 * received packet will be time stamped until the Rx time stamp
528 * registers are read. Because only one packet can be time stamped
529 * at a time, the register values must belong to this packet and
530 * therefore none of the other additional attributes need to be
531 * compared.
532 */
533 rxstmp = (u64)er32(RXSTMPL);
534 rxstmp |= (u64)er32(RXSTMPH) << 32;
535 e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
536
537 adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
538}
539
540/**
Bruce Allanad680762008-03-28 09:15:03 -0700541 * e1000_receive_skb - helper function to handle Rx indications
Auke Kokbc7f75f2007-09-17 12:30:59 -0700542 * @adapter: board private structure
Bruce Allanb67e1912012-12-27 08:32:33 +0000543 * @staterr: descriptor extended error and status field as written by hardware
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
545 * @skb: pointer to sk_buff to be indicated to stack
546 **/
547static void e1000_receive_skb(struct e1000_adapter *adapter,
Bruce Allanaf667a22010-12-31 06:10:01 +0000548 struct net_device *netdev, struct sk_buff *skb,
Bruce Allanb67e1912012-12-27 08:32:33 +0000549 u32 staterr, __le16 vlan)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700550{
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000551 u16 tag = le16_to_cpu(vlan);
Bruce Allanb67e1912012-12-27 08:32:33 +0000552
553 e1000e_rx_hwtstamp(adapter, staterr, skb);
554
Auke Kokbc7f75f2007-09-17 12:30:59 -0700555 skb->protocol = eth_type_trans(skb, netdev);
556
Bruce Allanb67e1912012-12-27 08:32:33 +0000557 if (staterr & E1000_RXD_STAT_VP)
Jeff Kirsher86d70e52011-03-25 16:01:01 +0000558 __vlan_hwaccel_put_tag(skb, tag);
559
560 napi_gro_receive(&adapter->napi, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561}
562
563/**
Bruce Allanaf667a22010-12-31 06:10:01 +0000564 * e1000_rx_checksum - Receive Checksum Offload
Bruce Allanafd12932012-01-05 00:34:05 +0000565 * @adapter: board private structure
566 * @status_err: receive descriptor status and error fields
567 * @csum: receive descriptor csum field
568 * @sk_buff: socket buffer with received data
Auke Kokbc7f75f2007-09-17 12:30:59 -0700569 **/
570static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
Bruce Allan2e1706f2012-06-30 20:02:42 +0000571 struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572{
573 u16 status = (u16)status_err;
574 u8 errors = (u8)(status_err >> 24);
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700575
576 skb_checksum_none_assert(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577
Bruce Allanafd12932012-01-05 00:34:05 +0000578 /* Rx checksum disabled */
579 if (!(adapter->netdev->features & NETIF_F_RXCSUM))
580 return;
581
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582 /* Ignore Checksum bit is set */
583 if (status & E1000_RXD_STAT_IXSM)
584 return;
Bruce Allanafd12932012-01-05 00:34:05 +0000585
Bruce Allan2e1706f2012-06-30 20:02:42 +0000586 /* TCP/UDP checksum error bit or IP checksum error bit is set */
587 if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700588 /* let the stack verify checksum errors */
589 adapter->hw_csum_err++;
590 return;
591 }
592
593 /* TCP/UDP Checksum has not been calculated */
594 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
595 return;
596
597 /* It must be a TCP or UDP packet with a valid checksum */
Bruce Allan2e1706f2012-06-30 20:02:42 +0000598 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700599 adapter->hw_csum_good++;
600}
601
Bruce Allan55aa6982011-12-16 00:45:45 +0000602static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700603{
Bruce Allan55aa6982011-12-16 00:45:45 +0000604 struct e1000_adapter *adapter = rx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700605 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000606 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700607
Bruce Allanbdc125f2012-03-20 03:47:52 +0000608 writel(i, rx_ring->tail);
609
610 if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700611 u32 rctl = er32(RCTL);
612 ew32(RCTL, rctl & ~E1000_RCTL_EN);
613 e_err("ME firmware caused invalid RDT - resetting\n");
614 schedule_work(&adapter->reset_task);
615 }
616}
617
Bruce Allan55aa6982011-12-16 00:45:45 +0000618static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
David S. Miller823dcd22011-08-20 10:39:12 -0700619{
Bruce Allan55aa6982011-12-16 00:45:45 +0000620 struct e1000_adapter *adapter = tx_ring->adapter;
David S. Miller823dcd22011-08-20 10:39:12 -0700621 struct e1000_hw *hw = &adapter->hw;
Bruce Allanbdc125f2012-03-20 03:47:52 +0000622 s32 ret_val = __ew32_prepare(hw);
David S. Miller823dcd22011-08-20 10:39:12 -0700623
Bruce Allanbdc125f2012-03-20 03:47:52 +0000624 writel(i, tx_ring->tail);
625
626 if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
David S. Miller823dcd22011-08-20 10:39:12 -0700627 u32 tctl = er32(TCTL);
628 ew32(TCTL, tctl & ~E1000_TCTL_EN);
629 e_err("ME firmware caused invalid TDT - resetting\n");
630 schedule_work(&adapter->reset_task);
631 }
632}
633
634/**
Bruce Allan5f450212011-07-22 06:21:46 +0000635 * e1000_alloc_rx_buffers - Replace used receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000636 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000638static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000639 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640{
Bruce Allan55aa6982011-12-16 00:45:45 +0000641 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642 struct net_device *netdev = adapter->netdev;
643 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000644 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645 struct e1000_buffer *buffer_info;
646 struct sk_buff *skb;
647 unsigned int i;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000648 unsigned int bufsz = adapter->rx_buffer_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649
650 i = rx_ring->next_to_use;
651 buffer_info = &rx_ring->buffer_info[i];
652
653 while (cleaned_count--) {
654 skb = buffer_info->skb;
655 if (skb) {
656 skb_trim(skb, 0);
657 goto map_skb;
658 }
659
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000660 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700661 if (!skb) {
662 /* Better luck next round */
663 adapter->alloc_rx_buff_failed++;
664 break;
665 }
666
Auke Kokbc7f75f2007-09-17 12:30:59 -0700667 buffer_info->skb = skb;
668map_skb:
Nick Nunley0be3f552010-04-27 13:09:05 +0000669 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000671 DMA_FROM_DEVICE);
672 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000673 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 adapter->rx_dma_failed++;
675 break;
676 }
677
Bruce Allan5f450212011-07-22 06:21:46 +0000678 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
679 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700680
Tom Herbert50849d72010-05-05 14:02:49 +0000681 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000682 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000683 * know there are new descriptors to fetch. (Only
684 * applicable for weak-ordered memory model archs,
685 * such as IA-64).
686 */
687 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700688 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000689 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700690 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000691 writel(i, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000692 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693 i++;
694 if (i == rx_ring->count)
695 i = 0;
696 buffer_info = &rx_ring->buffer_info[i];
697 }
698
Tom Herbert50849d72010-05-05 14:02:49 +0000699 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700700}
701
702/**
703 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +0000704 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000706static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000707 int cleaned_count, gfp_t gfp)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708{
Bruce Allan55aa6982011-12-16 00:45:45 +0000709 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700710 struct net_device *netdev = adapter->netdev;
711 struct pci_dev *pdev = adapter->pdev;
712 union e1000_rx_desc_packet_split *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700713 struct e1000_buffer *buffer_info;
714 struct e1000_ps_page *ps_page;
715 struct sk_buff *skb;
716 unsigned int i, j;
717
718 i = rx_ring->next_to_use;
719 buffer_info = &rx_ring->buffer_info[i];
720
721 while (cleaned_count--) {
722 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
723
724 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -0700725 ps_page = &buffer_info->ps_pages[j];
726 if (j >= adapter->rx_ps_pages) {
727 /* all unused desc entries get hw null ptr */
Bruce Allanaf667a22010-12-31 06:10:01 +0000728 rx_desc->read.buffer_addr[j + 1] =
729 ~cpu_to_le64(0);
Auke Kok47f44e42007-10-25 13:57:44 -0700730 continue;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700731 }
Auke Kok47f44e42007-10-25 13:57:44 -0700732 if (!ps_page->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000733 ps_page->page = alloc_page(gfp);
Auke Kok47f44e42007-10-25 13:57:44 -0700734 if (!ps_page->page) {
735 adapter->alloc_rx_buff_failed++;
736 goto no_buffers;
737 }
Nick Nunley0be3f552010-04-27 13:09:05 +0000738 ps_page->dma = dma_map_page(&pdev->dev,
739 ps_page->page,
740 0, PAGE_SIZE,
741 DMA_FROM_DEVICE);
742 if (dma_mapping_error(&pdev->dev,
743 ps_page->dma)) {
Auke Kok47f44e42007-10-25 13:57:44 -0700744 dev_err(&adapter->pdev->dev,
Bruce Allanaf667a22010-12-31 06:10:01 +0000745 "Rx DMA page map failed\n");
Auke Kok47f44e42007-10-25 13:57:44 -0700746 adapter->rx_dma_failed++;
747 goto no_buffers;
748 }
749 }
Bruce Allane921eb12012-11-28 09:28:37 +0000750 /* Refresh the desc even if buffer_addrs
Auke Kok47f44e42007-10-25 13:57:44 -0700751 * didn't change because each write-back
752 * erases this info.
753 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000754 rx_desc->read.buffer_addr[j + 1] =
755 cpu_to_le64(ps_page->dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 }
757
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000758 skb = __netdev_alloc_skb_ip_align(netdev,
759 adapter->rx_ps_bsize0,
760 gfp);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700761
762 if (!skb) {
763 adapter->alloc_rx_buff_failed++;
764 break;
765 }
766
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767 buffer_info->skb = skb;
Nick Nunley0be3f552010-04-27 13:09:05 +0000768 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700769 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +0000770 DMA_FROM_DEVICE);
771 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
Bruce Allanaf667a22010-12-31 06:10:01 +0000772 dev_err(&pdev->dev, "Rx DMA map failed\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773 adapter->rx_dma_failed++;
774 /* cleanup skb */
775 dev_kfree_skb_any(skb);
776 buffer_info->skb = NULL;
777 break;
778 }
779
780 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
781
Tom Herbert50849d72010-05-05 14:02:49 +0000782 if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
Bruce Allane921eb12012-11-28 09:28:37 +0000783 /* Force memory writes to complete before letting h/w
Tom Herbert50849d72010-05-05 14:02:49 +0000784 * know there are new descriptors to fetch. (Only
785 * applicable for weak-ordered memory model archs,
786 * such as IA-64).
787 */
788 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700789 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000790 e1000e_update_rdt_wa(rx_ring, i << 1);
David S. Miller823dcd22011-08-20 10:39:12 -0700791 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000792 writel(i << 1, rx_ring->tail);
Tom Herbert50849d72010-05-05 14:02:49 +0000793 }
794
Auke Kokbc7f75f2007-09-17 12:30:59 -0700795 i++;
796 if (i == rx_ring->count)
797 i = 0;
798 buffer_info = &rx_ring->buffer_info[i];
799 }
800
801no_buffers:
Tom Herbert50849d72010-05-05 14:02:49 +0000802 rx_ring->next_to_use = i;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700803}
804
805/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700806 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
Bruce Allan55aa6982011-12-16 00:45:45 +0000807 * @rx_ring: Rx descriptor ring
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700808 * @cleaned_count: number of buffers to allocate this pass
809 **/
810
Bruce Allan55aa6982011-12-16 00:45:45 +0000811static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000812 int cleaned_count, gfp_t gfp)
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700813{
Bruce Allan55aa6982011-12-16 00:45:45 +0000814 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700815 struct net_device *netdev = adapter->netdev;
816 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +0000817 union e1000_rx_desc_extended *rx_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700818 struct e1000_buffer *buffer_info;
819 struct sk_buff *skb;
820 unsigned int i;
Bruce Allan2a2293b2012-12-05 06:26:35 +0000821 unsigned int bufsz = 256 - 16; /* for skb_reserve */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700822
823 i = rx_ring->next_to_use;
824 buffer_info = &rx_ring->buffer_info[i];
825
826 while (cleaned_count--) {
827 skb = buffer_info->skb;
828 if (skb) {
829 skb_trim(skb, 0);
830 goto check_page;
831 }
832
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000833 skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700834 if (unlikely(!skb)) {
835 /* Better luck next round */
836 adapter->alloc_rx_buff_failed++;
837 break;
838 }
839
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700840 buffer_info->skb = skb;
841check_page:
842 /* allocate a new page if necessary */
843 if (!buffer_info->page) {
Jeff Kirsherc2fed992011-07-12 16:10:12 +0000844 buffer_info->page = alloc_page(gfp);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700845 if (unlikely(!buffer_info->page)) {
846 adapter->alloc_rx_buff_failed++;
847 break;
848 }
849 }
850
851 if (!buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +0000852 buffer_info->dma = dma_map_page(&pdev->dev,
Bruce Allanf0ff4392013-02-20 04:05:39 +0000853 buffer_info->page, 0,
854 PAGE_SIZE,
Nick Nunley0be3f552010-04-27 13:09:05 +0000855 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700856
Bruce Allan5f450212011-07-22 06:21:46 +0000857 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
858 rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700859
860 if (unlikely(++i == rx_ring->count))
861 i = 0;
862 buffer_info = &rx_ring->buffer_info[i];
863 }
864
865 if (likely(rx_ring->next_to_use != i)) {
866 rx_ring->next_to_use = i;
867 if (unlikely(i-- == 0))
868 i = (rx_ring->count - 1);
869
870 /* Force memory writes to complete before letting h/w
871 * know there are new descriptors to fetch. (Only
872 * applicable for weak-ordered memory model archs,
Bruce Allane921eb12012-11-28 09:28:37 +0000873 * such as IA-64).
874 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700875 wmb();
David S. Miller823dcd22011-08-20 10:39:12 -0700876 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +0000877 e1000e_update_rdt_wa(rx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -0700878 else
Bruce Allanc5083cf2011-12-16 00:45:40 +0000879 writel(i, rx_ring->tail);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700880 }
881}
882
Bruce Allan70495a52012-01-11 01:26:50 +0000883static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
884 struct sk_buff *skb)
885{
886 if (netdev->features & NETIF_F_RXHASH)
887 skb->rxhash = le32_to_cpu(rss);
888}
889
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700890/**
Bruce Allan55aa6982011-12-16 00:45:45 +0000891 * e1000_clean_rx_irq - Send received data up the network stack
892 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -0700893 *
894 * the return value indicates whether actual cleaning was done, there
895 * is no guarantee that everything was cleaned
896 **/
Bruce Allan55aa6982011-12-16 00:45:45 +0000897static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
898 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899{
Bruce Allan55aa6982011-12-16 00:45:45 +0000900 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 struct net_device *netdev = adapter->netdev;
902 struct pci_dev *pdev = adapter->pdev;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000903 struct e1000_hw *hw = &adapter->hw;
Bruce Allan5f450212011-07-22 06:21:46 +0000904 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +0000906 u32 length, staterr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700907 unsigned int i;
908 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +0000909 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
911
912 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +0000913 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
914 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700915 buffer_info = &rx_ring->buffer_info[i];
916
Bruce Allan5f450212011-07-22 06:21:46 +0000917 while (staterr & E1000_RXD_STAT_DD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 struct sk_buff *skb;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919
920 if (*work_done >= work_to_do)
921 break;
922 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000923 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925 skb = buffer_info->skb;
926 buffer_info->skb = NULL;
927
928 prefetch(skb->data - NET_IP_ALIGN);
929
930 i++;
931 if (i == rx_ring->count)
932 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +0000933 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934 prefetch(next_rxd);
935
936 next_buffer = &rx_ring->buffer_info[i];
937
Rusty Russell3db1cd52011-12-19 13:56:45 +0000938 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +0000940 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700941 buffer_info->dma,
942 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +0000943 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700944 buffer_info->dma = 0;
945
Bruce Allan5f450212011-07-22 06:21:46 +0000946 length = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947
Bruce Allane921eb12012-11-28 09:28:37 +0000948 /* !EOP means multiple descriptors were used to store a single
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000949 * packet, if that's the case we need to toss it. In fact, we
950 * need to toss every packet with the EOP bit clear and the
951 * next frame that _does_ have the EOP bit set, as it is by
952 * definition only a frame fragment
953 */
Bruce Allan5f450212011-07-22 06:21:46 +0000954 if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000955 adapter->flags2 |= FLAG2_IS_DISCARDING;
956
957 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 /* All receives must fit into a single buffer */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000959 e_dbg("Receive packet consumed multiple buffers\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960 /* recycle */
961 buffer_info->skb = skb;
Bruce Allan5f450212011-07-22 06:21:46 +0000962 if (staterr & E1000_RXD_STAT_EOP)
Jesse Brandeburgb94b5022010-01-19 14:15:59 +0000963 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700964 goto next_desc;
965 }
966
Ben Greearcf955e62012-02-11 15:39:51 +0000967 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
968 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969 /* recycle */
970 buffer_info->skb = skb;
971 goto next_desc;
972 }
973
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000974 /* adjust length to remove Ethernet CRC */
Ben Greear01840392012-02-11 15:39:25 +0000975 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
976 /* If configured to store CRC, don't subtract FCS,
977 * but keep the FCS bytes out of the total_rx_bytes
978 * counter
979 */
980 if (netdev->features & NETIF_F_RXFCS)
981 total_rx_bytes -= 4;
982 else
983 length -= 4;
984 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +0000985
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 total_rx_bytes += length;
987 total_rx_packets++;
988
Bruce Allane921eb12012-11-28 09:28:37 +0000989 /* code added for copybreak, this should improve
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 * performance for small packets with large amounts
Bruce Allanad680762008-03-28 09:15:03 -0700991 * of reassembly being done in the stack
992 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993 if (length < copybreak) {
994 struct sk_buff *new_skb =
Eric Dumazet89d71a62009-10-13 05:34:20 +0000995 netdev_alloc_skb_ip_align(netdev, length);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996 if (new_skb) {
Bruce Allan808ff672008-08-08 18:35:56 -0700997 skb_copy_to_linear_data_offset(new_skb,
998 -NET_IP_ALIGN,
999 (skb->data -
1000 NET_IP_ALIGN),
1001 (length +
1002 NET_IP_ALIGN));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 /* save the skb in buffer_info as good */
1004 buffer_info->skb = skb;
1005 skb = new_skb;
1006 }
1007 /* else just continue with the old one */
1008 }
1009 /* end copybreak code */
1010 skb_put(skb, length);
1011
1012 /* Receive Checksum Offload */
Bruce Allan2e1706f2012-06-30 20:02:42 +00001013 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014
Bruce Allan70495a52012-01-11 01:26:50 +00001015 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1016
Bruce Allan5f450212011-07-22 06:21:46 +00001017 e1000_receive_skb(adapter, netdev, skb, staterr,
1018 rx_desc->wb.upper.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019
1020next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001021 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001022
1023 /* return some buffers to hardware, one at a time is too slow */
1024 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001025 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001026 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 cleaned_count = 0;
1028 }
1029
1030 /* use prefetched values */
1031 rx_desc = next_rxd;
1032 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001033
1034 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 }
1036 rx_ring->next_to_clean = i;
1037
1038 cleaned_count = e1000_desc_unused(rx_ring);
1039 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001040 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001043 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001044 return cleaned;
1045}
1046
Bruce Allan55aa6982011-12-16 00:45:45 +00001047static void e1000_put_txbuf(struct e1000_ring *tx_ring,
1048 struct e1000_buffer *buffer_info)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049{
Bruce Allan55aa6982011-12-16 00:45:45 +00001050 struct e1000_adapter *adapter = tx_ring->adapter;
1051
Alexander Duyck03b13202009-12-02 16:45:31 +00001052 if (buffer_info->dma) {
1053 if (buffer_info->mapped_as_page)
Nick Nunley0be3f552010-04-27 13:09:05 +00001054 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1055 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001056 else
Nick Nunley0be3f552010-04-27 13:09:05 +00001057 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1058 buffer_info->length, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00001059 buffer_info->dma = 0;
1060 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 if (buffer_info->skb) {
1062 dev_kfree_skb_any(buffer_info->skb);
1063 buffer_info->skb = NULL;
1064 }
Alexander Duyck1b7719c2009-03-19 01:12:50 +00001065 buffer_info->time_stamp = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066}
1067
Bruce Allan41cec6f2009-11-20 23:28:56 +00001068static void e1000_print_hw_hang(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001069{
Bruce Allan41cec6f2009-11-20 23:28:56 +00001070 struct e1000_adapter *adapter = container_of(work,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001071 struct e1000_adapter,
1072 print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001073 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 struct e1000_ring *tx_ring = adapter->tx_ring;
1075 unsigned int i = tx_ring->next_to_clean;
1076 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
1077 struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001078 struct e1000_hw *hw = &adapter->hw;
1079 u16 phy_status, phy_1000t_status, phy_ext_status;
1080 u16 pci_status;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001082 if (test_bit(__E1000_DOWN, &adapter->state))
1083 return;
1084
Jeff Kirsher09357b02011-11-18 14:25:00 +00001085 if (!adapter->tx_hang_recheck &&
1086 (adapter->flags2 & FLAG2_DMA_BURST)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001087 /* May be block on write-back, flush and detect again
Jeff Kirsher09357b02011-11-18 14:25:00 +00001088 * flush pending descriptor writebacks to memory
1089 */
1090 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1091 /* execute the writes immediately */
1092 e1e_flush();
Bruce Allane921eb12012-11-28 09:28:37 +00001093 /* Due to rare timing issues, write to TIDV again to ensure
Matthew Vickbf030852012-03-16 09:03:00 +00001094 * the write is successful
1095 */
1096 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
1097 /* execute the writes immediately */
1098 e1e_flush();
Jeff Kirsher09357b02011-11-18 14:25:00 +00001099 adapter->tx_hang_recheck = true;
1100 return;
1101 }
1102 /* Real hang detected */
1103 adapter->tx_hang_recheck = false;
1104 netif_stop_queue(netdev);
1105
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001106 e1e_rphy(hw, MII_BMSR, &phy_status);
1107 e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
1108 e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
Bruce Allan41cec6f2009-11-20 23:28:56 +00001109
1110 pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
1111
1112 /* detected Hardware unit hang */
1113 e_err("Detected Hardware Unit Hang:\n"
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001114 " TDH <%x>\n"
1115 " TDT <%x>\n"
1116 " next_to_use <%x>\n"
1117 " next_to_clean <%x>\n"
1118 "buffer_info[next_to_clean]:\n"
1119 " time_stamp <%lx>\n"
1120 " next_to_watch <%x>\n"
1121 " jiffies <%lx>\n"
Bruce Allan41cec6f2009-11-20 23:28:56 +00001122 " next_to_watch.status <%x>\n"
1123 "MAC Status <%x>\n"
1124 "PHY Status <%x>\n"
1125 "PHY 1000BASE-T Status <%x>\n"
1126 "PHY Extended Status <%x>\n"
1127 "PCI Status <%x>\n",
Bruce Allanc5083cf2011-12-16 00:45:40 +00001128 readl(tx_ring->head),
1129 readl(tx_ring->tail),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001130 tx_ring->next_to_use,
1131 tx_ring->next_to_clean,
1132 tx_ring->buffer_info[eop].time_stamp,
1133 eop,
1134 jiffies,
Bruce Allan41cec6f2009-11-20 23:28:56 +00001135 eop_desc->upper.fields.status,
1136 er32(STATUS),
1137 phy_status,
1138 phy_1000t_status,
1139 phy_ext_status,
1140 pci_status);
Bruce Allan7c0427e2012-03-20 03:48:08 +00001141
1142 /* Suggest workaround for known h/w issue */
1143 if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
1144 e_err("Try turning off Tx pause (flow control) via ethtool\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145}
1146
1147/**
Bruce Allanb67e1912012-12-27 08:32:33 +00001148 * e1000e_tx_hwtstamp_work - check for Tx time stamp
1149 * @work: pointer to work struct
1150 *
1151 * This work function polls the TSYNCTXCTL valid bit to determine when a
1152 * timestamp has been taken for the current stored skb. The timestamp must
1153 * be for this skb because only one such packet is allowed in the queue.
1154 */
1155static void e1000e_tx_hwtstamp_work(struct work_struct *work)
1156{
1157 struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
1158 tx_hwtstamp_work);
1159 struct e1000_hw *hw = &adapter->hw;
1160
1161 if (!adapter->tx_hwtstamp_skb)
1162 return;
1163
1164 if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
1165 struct skb_shared_hwtstamps shhwtstamps;
1166 u64 txstmp;
1167
1168 txstmp = er32(TXSTMPL);
1169 txstmp |= (u64)er32(TXSTMPH) << 32;
1170
1171 e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
1172
1173 skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
1174 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
1175 adapter->tx_hwtstamp_skb = NULL;
1176 } else {
1177 /* reschedule to check later */
1178 schedule_work(&adapter->tx_hwtstamp_work);
1179 }
1180}
1181
1182/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 * e1000_clean_tx_irq - Reclaim resources after transmit completes
Bruce Allan55aa6982011-12-16 00:45:45 +00001184 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 *
1186 * the return value indicates whether actual cleaning was done, there
1187 * is no guarantee that everything was cleaned
1188 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001189static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190{
Bruce Allan55aa6982011-12-16 00:45:45 +00001191 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 struct net_device *netdev = adapter->netdev;
1193 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194 struct e1000_tx_desc *tx_desc, *eop_desc;
1195 struct e1000_buffer *buffer_info;
1196 unsigned int i, eop;
1197 unsigned int count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001199 unsigned int bytes_compl = 0, pkts_compl = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200
1201 i = tx_ring->next_to_clean;
1202 eop = tx_ring->buffer_info[i].next_to_watch;
1203 eop_desc = E1000_TX_DESC(*tx_ring, eop);
1204
Alexander Duyck12d04a32009-03-25 22:05:03 +00001205 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
1206 (count < tx_ring->count)) {
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001207 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001208 rmb(); /* read buffer_info after eop_desc */
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001209 for (; !cleaned; count++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 tx_desc = E1000_TX_DESC(*tx_ring, i);
1211 buffer_info = &tx_ring->buffer_info[i];
1212 cleaned = (i == eop);
1213
1214 if (cleaned) {
Tom Herbert9ed318d2010-05-05 14:02:27 +00001215 total_tx_packets += buffer_info->segs;
1216 total_tx_bytes += buffer_info->bytecount;
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001217 if (buffer_info->skb) {
1218 bytes_compl += buffer_info->skb->len;
1219 pkts_compl++;
1220 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221 }
1222
Bruce Allan55aa6982011-12-16 00:45:45 +00001223 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 tx_desc->upper.data = 0;
1225
1226 i++;
1227 if (i == tx_ring->count)
1228 i = 0;
1229 }
1230
Terry Loftindac87612010-04-09 10:29:49 +00001231 if (i == tx_ring->next_to_use)
1232 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 eop = tx_ring->buffer_info[i].next_to_watch;
1234 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001235 }
1236
1237 tx_ring->next_to_clean = i;
1238
Tom Herbert3f0cfa32011-11-28 16:33:16 +00001239 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
1240
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241#define TX_WAKE_THRESHOLD 32
Jesse Brandeburga86043c2009-04-16 16:59:28 +00001242 if (count && netif_carrier_ok(netdev) &&
1243 e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 /* Make sure that anybody stopping the queue after this
1245 * sees the new next_to_clean.
1246 */
1247 smp_mb();
1248
1249 if (netif_queue_stopped(netdev) &&
1250 !(test_bit(__E1000_DOWN, &adapter->state))) {
1251 netif_wake_queue(netdev);
1252 ++adapter->restart_queue;
1253 }
1254 }
1255
1256 if (adapter->detect_tx_hung) {
Bruce Allane921eb12012-11-28 09:28:37 +00001257 /* Detect a transmit hang in hardware, this serializes the
Bruce Allan41cec6f2009-11-20 23:28:56 +00001258 * check with the clearing of time_stamp and movement of i
1259 */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001260 adapter->detect_tx_hung = false;
Alexander Duyck12d04a32009-03-25 22:05:03 +00001261 if (tx_ring->buffer_info[i].time_stamp &&
1262 time_after(jiffies, tx_ring->buffer_info[i].time_stamp
Joe Perches8e95a202009-12-03 07:58:21 +00001263 + (adapter->tx_timeout_factor * HZ)) &&
Jeff Kirsher09357b02011-11-18 14:25:00 +00001264 !(er32(STATUS) & E1000_STATUS_TXOFF))
Bruce Allan41cec6f2009-11-20 23:28:56 +00001265 schedule_work(&adapter->print_hang_task);
Jeff Kirsher09357b02011-11-18 14:25:00 +00001266 else
1267 adapter->tx_hang_recheck = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 }
1269 adapter->total_tx_bytes += total_tx_bytes;
1270 adapter->total_tx_packets += total_tx_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +00001271 return count < tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272}
1273
1274/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
Bruce Allan55aa6982011-12-16 00:45:45 +00001276 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001277 *
1278 * the return value indicates whether actual cleaning was done, there
1279 * is no guarantee that everything was cleaned
1280 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001281static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
1282 int work_to_do)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001283{
Bruce Allan55aa6982011-12-16 00:45:45 +00001284 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001285 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
1287 struct net_device *netdev = adapter->netdev;
1288 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001289 struct e1000_buffer *buffer_info, *next_buffer;
1290 struct e1000_ps_page *ps_page;
1291 struct sk_buff *skb;
1292 unsigned int i, j;
1293 u32 length, staterr;
1294 int cleaned_count = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00001295 bool cleaned = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001296 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1297
1298 i = rx_ring->next_to_clean;
1299 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
1300 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1301 buffer_info = &rx_ring->buffer_info[i];
1302
1303 while (staterr & E1000_RXD_STAT_DD) {
1304 if (*work_done >= work_to_do)
1305 break;
1306 (*work_done)++;
1307 skb = buffer_info->skb;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001308 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309
1310 /* in the packet split case this is header only */
1311 prefetch(skb->data - NET_IP_ALIGN);
1312
1313 i++;
1314 if (i == rx_ring->count)
1315 i = 0;
1316 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
1317 prefetch(next_rxd);
1318
1319 next_buffer = &rx_ring->buffer_info[i];
1320
Rusty Russell3db1cd52011-12-19 13:56:45 +00001321 cleaned = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001323 dma_unmap_single(&pdev->dev, buffer_info->dma,
Bruce Allanaf667a22010-12-31 06:10:01 +00001324 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001325 buffer_info->dma = 0;
1326
Bruce Allanaf667a22010-12-31 06:10:01 +00001327 /* see !EOP comment in other Rx routine */
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001328 if (!(staterr & E1000_RXD_STAT_EOP))
1329 adapter->flags2 |= FLAG2_IS_DISCARDING;
1330
1331 if (adapter->flags2 & FLAG2_IS_DISCARDING) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001332 e_dbg("Packet Split buffers didn't pick up the full packet\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333 dev_kfree_skb_irq(skb);
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001334 if (staterr & E1000_RXD_STAT_EOP)
1335 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 goto next_desc;
1337 }
1338
Ben Greearcf955e62012-02-11 15:39:51 +00001339 if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1340 !(netdev->features & NETIF_F_RXALL))) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001341 dev_kfree_skb_irq(skb);
1342 goto next_desc;
1343 }
1344
1345 length = le16_to_cpu(rx_desc->wb.middle.length0);
1346
1347 if (!length) {
Jeff Kirsheref456f82011-11-03 11:40:28 +00001348 e_dbg("Last part of the packet spanning multiple descriptors\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001349 dev_kfree_skb_irq(skb);
1350 goto next_desc;
1351 }
1352
1353 /* Good Receive */
1354 skb_put(skb, length);
1355
1356 {
Bruce Allane921eb12012-11-28 09:28:37 +00001357 /* this looks ugly, but it seems compiler issues make
Bruce Allan0e15df42012-01-31 06:37:11 +00001358 * it more efficient than reusing j
1359 */
1360 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001361
Bruce Allane921eb12012-11-28 09:28:37 +00001362 /* page alloc/put takes too long and effects small
Bruce Allan0e15df42012-01-31 06:37:11 +00001363 * packet throughput, so unsplit small packets and
1364 * save the alloc/put only valid in softirq (napi)
1365 * context to call kmap_*
Bruce Allanad680762008-03-28 09:15:03 -07001366 */
Bruce Allan0e15df42012-01-31 06:37:11 +00001367 if (l1 && (l1 <= copybreak) &&
1368 ((length + l1) <= adapter->rx_ps_bsize0)) {
1369 u8 *vaddr;
Auke Kok140a7482007-10-25 13:57:58 -07001370
Bruce Allan0e15df42012-01-31 06:37:11 +00001371 ps_page = &buffer_info->ps_pages[0];
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001372
Bruce Allane921eb12012-11-28 09:28:37 +00001373 /* there is no documentation about how to call
Bruce Allan0e15df42012-01-31 06:37:11 +00001374 * kmap_atomic, so we can't hold the mapping
1375 * very long
1376 */
1377 dma_sync_single_for_cpu(&pdev->dev,
1378 ps_page->dma,
1379 PAGE_SIZE,
1380 DMA_FROM_DEVICE);
Linus Torvalds9f393832012-03-21 09:40:26 -07001381 vaddr = kmap_atomic(ps_page->page);
Bruce Allan0e15df42012-01-31 06:37:11 +00001382 memcpy(skb_tail_pointer(skb), vaddr, l1);
Linus Torvalds9f393832012-03-21 09:40:26 -07001383 kunmap_atomic(vaddr);
Bruce Allan0e15df42012-01-31 06:37:11 +00001384 dma_sync_single_for_device(&pdev->dev,
1385 ps_page->dma,
1386 PAGE_SIZE,
1387 DMA_FROM_DEVICE);
1388
1389 /* remove the CRC */
Ben Greear01840392012-02-11 15:39:25 +00001390 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1391 if (!(netdev->features & NETIF_F_RXFCS))
1392 l1 -= 4;
1393 }
Bruce Allan0e15df42012-01-31 06:37:11 +00001394
1395 skb_put(skb, l1);
1396 goto copydone;
1397 } /* if */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001398 }
1399
1400 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
1401 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
1402 if (!length)
1403 break;
1404
Auke Kok47f44e42007-10-25 13:57:44 -07001405 ps_page = &buffer_info->ps_pages[j];
Nick Nunley0be3f552010-04-27 13:09:05 +00001406 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1407 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001408 ps_page->dma = 0;
1409 skb_fill_page_desc(skb, j, ps_page->page, 0, length);
1410 ps_page->page = NULL;
1411 skb->len += length;
1412 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001413 skb->truesize += PAGE_SIZE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001414 }
1415
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001416 /* strip the ethernet crc, problem is we're using pages now so
1417 * this whole operation can get a little cpu intensive
1418 */
Ben Greear01840392012-02-11 15:39:25 +00001419 if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
1420 if (!(netdev->features & NETIF_F_RXFCS))
1421 pskb_trim(skb, skb->len - 4);
1422 }
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00001423
Auke Kokbc7f75f2007-09-17 12:30:59 -07001424copydone:
1425 total_rx_bytes += skb->len;
1426 total_rx_packets++;
1427
Bruce Allan2e1706f2012-06-30 20:02:42 +00001428 e1000_rx_checksum(adapter, staterr, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001429
Bruce Allan70495a52012-01-11 01:26:50 +00001430 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1431
Auke Kokbc7f75f2007-09-17 12:30:59 -07001432 if (rx_desc->wb.upper.header_status &
Bruce Allan17e813e2013-02-20 04:06:01 +00001433 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001434 adapter->rx_hdr_split++;
1435
Bruce Allanb67e1912012-12-27 08:32:33 +00001436 e1000_receive_skb(adapter, netdev, skb, staterr,
1437 rx_desc->wb.middle.vlan);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001438
1439next_desc:
1440 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
1441 buffer_info->skb = NULL;
1442
1443 /* return some buffers to hardware, one at a time is too slow */
1444 if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001445 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001446 GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 cleaned_count = 0;
1448 }
1449
1450 /* use prefetched values */
1451 rx_desc = next_rxd;
1452 buffer_info = next_buffer;
1453
1454 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
1455 }
1456 rx_ring->next_to_clean = i;
1457
1458 cleaned_count = e1000_desc_unused(rx_ring);
1459 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001460 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461
Auke Kokbc7f75f2007-09-17 12:30:59 -07001462 adapter->total_rx_bytes += total_rx_bytes;
Bruce Allan7c257692008-04-23 11:09:00 -07001463 adapter->total_rx_packets += total_rx_packets;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001464 return cleaned;
1465}
1466
1467/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001468 * e1000_consume_page - helper function
1469 **/
1470static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
Bruce Allan66501f52013-02-20 04:05:55 +00001471 u16 length)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001472{
1473 bi->page = NULL;
1474 skb->len += length;
1475 skb->data_len += length;
Eric Dumazet98a045d2011-10-13 08:03:36 +00001476 skb->truesize += PAGE_SIZE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001477}
1478
1479/**
1480 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
1481 * @adapter: board private structure
1482 *
1483 * the return value indicates whether actual cleaning was done, there
1484 * is no guarantee that everything was cleaned
1485 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001486static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
1487 int work_to_do)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001488{
Bruce Allan55aa6982011-12-16 00:45:45 +00001489 struct e1000_adapter *adapter = rx_ring->adapter;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001490 struct net_device *netdev = adapter->netdev;
1491 struct pci_dev *pdev = adapter->pdev;
Bruce Allan5f450212011-07-22 06:21:46 +00001492 union e1000_rx_desc_extended *rx_desc, *next_rxd;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001493 struct e1000_buffer *buffer_info, *next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001494 u32 length, staterr;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001495 unsigned int i;
1496 int cleaned_count = 0;
1497 bool cleaned = false;
Bruce Allan362e20c2013-02-20 04:05:45 +00001498 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001499 struct skb_shared_info *shinfo;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001500
1501 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001502 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1503 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001504 buffer_info = &rx_ring->buffer_info[i];
1505
Bruce Allan5f450212011-07-22 06:21:46 +00001506 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001507 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001508
1509 if (*work_done >= work_to_do)
1510 break;
1511 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001512 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001514 skb = buffer_info->skb;
1515 buffer_info->skb = NULL;
1516
1517 ++i;
1518 if (i == rx_ring->count)
1519 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001520 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001521 prefetch(next_rxd);
1522
1523 next_buffer = &rx_ring->buffer_info[i];
1524
1525 cleaned = true;
1526 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001527 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1528 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001529 buffer_info->dma = 0;
1530
Bruce Allan5f450212011-07-22 06:21:46 +00001531 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001532
1533 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001534 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001535 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1536 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001537 /* recycle both page and skb */
1538 buffer_info->skb = skb;
1539 /* an error means any chain goes out the window too */
1540 if (rx_ring->rx_skb_top)
1541 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1542 rx_ring->rx_skb_top = NULL;
1543 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001544 }
1545
Bruce Allanf0f1a172010-12-11 05:53:32 +00001546#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001547 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001548 /* this descriptor is only the beginning (or middle) */
1549 if (!rxtop) {
1550 /* this is the beginning of a chain */
1551 rxtop = skb;
1552 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001553 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001554 } else {
1555 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001556 shinfo = skb_shinfo(rxtop);
1557 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1558 buffer_info->page, 0,
1559 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001560 /* re-use the skb, only consumed the page */
1561 buffer_info->skb = skb;
1562 }
1563 e1000_consume_page(buffer_info, rxtop, length);
1564 goto next_desc;
1565 } else {
1566 if (rxtop) {
1567 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001568 shinfo = skb_shinfo(rxtop);
1569 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1570 buffer_info->page, 0,
1571 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001572 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001573 * page
1574 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001575 buffer_info->skb = skb;
1576 skb = rxtop;
1577 rxtop = NULL;
1578 e1000_consume_page(buffer_info, skb, length);
1579 } else {
1580 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001581 * copybreak to save the put_page/alloc_page
1582 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001583 if (length <= copybreak &&
1584 skb_tailroom(skb) >= length) {
1585 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001586 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001587 memcpy(skb_tail_pointer(skb), vaddr,
1588 length);
Cong Wang46790262011-11-25 23:14:23 +08001589 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001590 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001591 * buffer_info->page
1592 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001593 skb_put(skb, length);
1594 } else {
1595 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001596 buffer_info->page, 0,
1597 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001598 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001599 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001600 }
1601 }
1602 }
1603
Bruce Allan2e1706f2012-06-30 20:02:42 +00001604 /* Receive Checksum Offload */
1605 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001606
Bruce Allan70495a52012-01-11 01:26:50 +00001607 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1608
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001609 /* probably a little skewed due to removing CRC */
1610 total_rx_bytes += skb->len;
1611 total_rx_packets++;
1612
1613 /* eth type trans needs skb->data to point to something */
1614 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001615 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001616 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001617 goto next_desc;
1618 }
1619
Bruce Allan5f450212011-07-22 06:21:46 +00001620 e1000_receive_skb(adapter, netdev, skb, staterr,
1621 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001622
1623next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001624 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001625
1626 /* return some buffers to hardware, one at a time is too slow */
1627 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001628 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001629 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001630 cleaned_count = 0;
1631 }
1632
1633 /* use prefetched values */
1634 rx_desc = next_rxd;
1635 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001636
1637 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001638 }
1639 rx_ring->next_to_clean = i;
1640
1641 cleaned_count = e1000_desc_unused(rx_ring);
1642 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001643 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001644
1645 adapter->total_rx_bytes += total_rx_bytes;
1646 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001647 return cleaned;
1648}
1649
1650/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001651 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001652 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001654static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001655{
Bruce Allan55aa6982011-12-16 00:45:45 +00001656 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657 struct e1000_buffer *buffer_info;
1658 struct e1000_ps_page *ps_page;
1659 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 unsigned int i, j;
1661
1662 /* Free all the Rx ring sk_buffs */
1663 for (i = 0; i < rx_ring->count; i++) {
1664 buffer_info = &rx_ring->buffer_info[i];
1665 if (buffer_info->dma) {
1666 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001667 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001669 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001670 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001671 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001672 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001673 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001674 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001676 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677 buffer_info->dma = 0;
1678 }
1679
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001680 if (buffer_info->page) {
1681 put_page(buffer_info->page);
1682 buffer_info->page = NULL;
1683 }
1684
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685 if (buffer_info->skb) {
1686 dev_kfree_skb(buffer_info->skb);
1687 buffer_info->skb = NULL;
1688 }
1689
1690 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001691 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001692 if (!ps_page->page)
1693 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001694 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1695 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 ps_page->dma = 0;
1697 put_page(ps_page->page);
1698 ps_page->page = NULL;
1699 }
1700 }
1701
1702 /* there also may be some cached data from a chained receive */
1703 if (rx_ring->rx_skb_top) {
1704 dev_kfree_skb(rx_ring->rx_skb_top);
1705 rx_ring->rx_skb_top = NULL;
1706 }
1707
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 /* Zero out the descriptor ring */
1709 memset(rx_ring->desc, 0, rx_ring->size);
1710
1711 rx_ring->next_to_clean = 0;
1712 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001713 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714
Bruce Allanc5083cf2011-12-16 00:45:40 +00001715 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001716 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1717 e1000e_update_rdt_wa(rx_ring, 0);
1718 else
1719 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001720}
1721
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001722static void e1000e_downshift_workaround(struct work_struct *work)
1723{
1724 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001725 struct e1000_adapter,
1726 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001727
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001728 if (test_bit(__E1000_DOWN, &adapter->state))
1729 return;
1730
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001731 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1732}
1733
Auke Kokbc7f75f2007-09-17 12:30:59 -07001734/**
1735 * e1000_intr_msi - Interrupt Handler
1736 * @irq: interrupt number
1737 * @data: pointer to a network interface device structure
1738 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001739static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740{
1741 struct net_device *netdev = data;
1742 struct e1000_adapter *adapter = netdev_priv(netdev);
1743 struct e1000_hw *hw = &adapter->hw;
1744 u32 icr = er32(ICR);
1745
Bruce Allane921eb12012-11-28 09:28:37 +00001746 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001747 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001748 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001749 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001750 * disconnect (LSC) before accessing any PHY registers
1751 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1753 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001754 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755
Bruce Allane921eb12012-11-28 09:28:37 +00001756 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001758 * adapter in watchdog
1759 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001760 if (netif_carrier_ok(netdev) &&
1761 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1762 /* disable receives */
1763 u32 rctl = er32(RCTL);
1764 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001765 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766 }
1767 /* guard against interrupt when we're going down */
1768 if (!test_bit(__E1000_DOWN, &adapter->state))
1769 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1770 }
1771
Bruce Allan94fb8482013-01-23 09:00:03 +00001772 /* Reset on uncorrectable ECC error */
1773 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1774 u32 pbeccsts = er32(PBECCSTS);
1775
1776 adapter->corr_errors +=
1777 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1778 adapter->uncorr_errors +=
1779 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1780 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1781
1782 /* Do the reset outside of interrupt context */
1783 schedule_work(&adapter->reset_task);
1784
1785 /* return immediately since reset is imminent */
1786 return IRQ_HANDLED;
1787 }
1788
Ben Hutchings288379f2009-01-19 16:43:59 -08001789 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790 adapter->total_tx_bytes = 0;
1791 adapter->total_tx_packets = 0;
1792 adapter->total_rx_bytes = 0;
1793 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001794 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 }
1796
1797 return IRQ_HANDLED;
1798}
1799
1800/**
1801 * e1000_intr - Interrupt Handler
1802 * @irq: interrupt number
1803 * @data: pointer to a network interface device structure
1804 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001805static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806{
1807 struct net_device *netdev = data;
1808 struct e1000_adapter *adapter = netdev_priv(netdev);
1809 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001811
Bruce Allana68ea772009-11-20 23:23:16 +00001812 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001813 return IRQ_NONE; /* Not our interrupt */
1814
Bruce Allane921eb12012-11-28 09:28:37 +00001815 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001816 * not set, then the adapter didn't send an interrupt
1817 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001818 if (!(icr & E1000_ICR_INT_ASSERTED))
1819 return IRQ_NONE;
1820
Bruce Allane921eb12012-11-28 09:28:37 +00001821 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001822 * interrupts are masked. No need for the
1823 * IMC write
1824 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825
dave graham573cca82009-02-10 12:52:05 +00001826 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001827 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001828 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001829 * disconnect (LSC) before accessing any PHY registers
1830 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1832 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001833 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
Bruce Allane921eb12012-11-28 09:28:37 +00001835 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 * For packet buffer work-around on link down event;
1837 * disable receives here in the ISR and
1838 * reset adapter in watchdog
1839 */
1840 if (netif_carrier_ok(netdev) &&
1841 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1842 /* disable receives */
1843 rctl = er32(RCTL);
1844 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001845 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 }
1847 /* guard against interrupt when we're going down */
1848 if (!test_bit(__E1000_DOWN, &adapter->state))
1849 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1850 }
1851
Bruce Allan94fb8482013-01-23 09:00:03 +00001852 /* Reset on uncorrectable ECC error */
1853 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1854 u32 pbeccsts = er32(PBECCSTS);
1855
1856 adapter->corr_errors +=
1857 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1858 adapter->uncorr_errors +=
1859 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1860 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1861
1862 /* Do the reset outside of interrupt context */
1863 schedule_work(&adapter->reset_task);
1864
1865 /* return immediately since reset is imminent */
1866 return IRQ_HANDLED;
1867 }
1868
Ben Hutchings288379f2009-01-19 16:43:59 -08001869 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001870 adapter->total_tx_bytes = 0;
1871 adapter->total_tx_packets = 0;
1872 adapter->total_rx_bytes = 0;
1873 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001874 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875 }
1876
1877 return IRQ_HANDLED;
1878}
1879
Bruce Allan8bb62862013-01-16 08:46:49 +00001880static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001881{
1882 struct net_device *netdev = data;
1883 struct e1000_adapter *adapter = netdev_priv(netdev);
1884 struct e1000_hw *hw = &adapter->hw;
1885 u32 icr = er32(ICR);
1886
1887 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001888 if (!test_bit(__E1000_DOWN, &adapter->state))
1889 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001890 return IRQ_NONE;
1891 }
1892
1893 if (icr & adapter->eiac_mask)
1894 ew32(ICS, (icr & adapter->eiac_mask));
1895
1896 if (icr & E1000_ICR_OTHER) {
1897 if (!(icr & E1000_ICR_LSC))
1898 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001899 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001900 /* guard against interrupt when we're going down */
1901 if (!test_bit(__E1000_DOWN, &adapter->state))
1902 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1903 }
1904
1905no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001906 if (!test_bit(__E1000_DOWN, &adapter->state))
1907 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001908
1909 return IRQ_HANDLED;
1910}
1911
Bruce Allan8bb62862013-01-16 08:46:49 +00001912static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001913{
1914 struct net_device *netdev = data;
1915 struct e1000_adapter *adapter = netdev_priv(netdev);
1916 struct e1000_hw *hw = &adapter->hw;
1917 struct e1000_ring *tx_ring = adapter->tx_ring;
1918
1919
1920 adapter->total_tx_bytes = 0;
1921 adapter->total_tx_packets = 0;
1922
Bruce Allan55aa6982011-12-16 00:45:45 +00001923 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001924 /* Ring was not completely cleaned, so fire another interrupt */
1925 ew32(ICS, tx_ring->ims_val);
1926
1927 return IRQ_HANDLED;
1928}
1929
Bruce Allan8bb62862013-01-16 08:46:49 +00001930static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001931{
1932 struct net_device *netdev = data;
1933 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001934 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001935
1936 /* Write the ITR value calculated at the end of the
1937 * previous interrupt.
1938 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001939 if (rx_ring->set_itr) {
1940 writel(1000000000 / (rx_ring->itr_val * 256),
1941 rx_ring->itr_register);
1942 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001943 }
1944
Ben Hutchings288379f2009-01-19 16:43:59 -08001945 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001946 adapter->total_rx_bytes = 0;
1947 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001948 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001949 }
1950 return IRQ_HANDLED;
1951}
1952
1953/**
1954 * e1000_configure_msix - Configure MSI-X hardware
1955 *
1956 * e1000_configure_msix sets up the hardware to properly
1957 * generate MSI-X interrupts.
1958 **/
1959static void e1000_configure_msix(struct e1000_adapter *adapter)
1960{
1961 struct e1000_hw *hw = &adapter->hw;
1962 struct e1000_ring *rx_ring = adapter->rx_ring;
1963 struct e1000_ring *tx_ring = adapter->tx_ring;
1964 int vector = 0;
1965 u32 ctrl_ext, ivar = 0;
1966
1967 adapter->eiac_mask = 0;
1968
1969 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1970 if (hw->mac.type == e1000_82574) {
1971 u32 rfctl = er32(RFCTL);
1972 rfctl |= E1000_RFCTL_ACK_DIS;
1973 ew32(RFCTL, rfctl);
1974 }
1975
1976#define E1000_IVAR_INT_ALLOC_VALID 0x8
1977 /* Configure Rx vector */
1978 rx_ring->ims_val = E1000_IMS_RXQ0;
1979 adapter->eiac_mask |= rx_ring->ims_val;
1980 if (rx_ring->itr_val)
1981 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001982 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001983 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001984 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001985 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1986
1987 /* Configure Tx vector */
1988 tx_ring->ims_val = E1000_IMS_TXQ0;
1989 vector++;
1990 if (tx_ring->itr_val)
1991 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001992 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001993 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001994 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001995 adapter->eiac_mask |= tx_ring->ims_val;
1996 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1997
1998 /* set vector for Other Causes, e.g. link changes */
1999 vector++;
2000 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
2001 if (rx_ring->itr_val)
2002 writel(1000000000 / (rx_ring->itr_val * 256),
2003 hw->hw_addr + E1000_EITR_82574(vector));
2004 else
2005 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2006
2007 /* Cause Tx interrupts on every write back */
2008 ivar |= (1 << 31);
2009
2010 ew32(IVAR, ivar);
2011
2012 /* enable MSI-X PBA support */
2013 ctrl_ext = er32(CTRL_EXT);
2014 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2015
2016 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07002017 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2018 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2019 ew32(CTRL_EXT, ctrl_ext);
2020 e1e_flush();
2021}
2022
2023void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2024{
2025 if (adapter->msix_entries) {
2026 pci_disable_msix(adapter->pdev);
2027 kfree(adapter->msix_entries);
2028 adapter->msix_entries = NULL;
2029 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2030 pci_disable_msi(adapter->pdev);
2031 adapter->flags &= ~FLAG_MSI_ENABLED;
2032 }
Bruce Allan4662e822008-08-26 18:37:06 -07002033}
2034
2035/**
2036 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2037 *
2038 * Attempt to configure interrupts using the best available
2039 * capabilities of the hardware and kernel.
2040 **/
2041void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2042{
2043 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002044 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002045
2046 switch (adapter->int_mode) {
2047 case E1000E_INT_MODE_MSIX:
2048 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002049 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2050 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002051 sizeof(struct
2052 msix_entry),
2053 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002054 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002055 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002056 adapter->msix_entries[i].entry = i;
2057
2058 err = pci_enable_msix(adapter->pdev,
2059 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002060 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002061 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002062 return;
2063 }
2064 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002065 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002066 e1000e_reset_interrupt_capability(adapter);
2067 }
2068 adapter->int_mode = E1000E_INT_MODE_MSI;
2069 /* Fall through */
2070 case E1000E_INT_MODE_MSI:
2071 if (!pci_enable_msi(adapter->pdev)) {
2072 adapter->flags |= FLAG_MSI_ENABLED;
2073 } else {
2074 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002075 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002076 }
2077 /* Fall through */
2078 case E1000E_INT_MODE_LEGACY:
2079 /* Don't do anything; this is the system default */
2080 break;
2081 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002082
2083 /* store the number of vectors being used */
2084 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002085}
2086
2087/**
2088 * e1000_request_msix - Initialize MSI-X interrupts
2089 *
2090 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2091 * kernel.
2092 **/
2093static int e1000_request_msix(struct e1000_adapter *adapter)
2094{
2095 struct net_device *netdev = adapter->netdev;
2096 int err = 0, vector = 0;
2097
2098 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002099 snprintf(adapter->rx_ring->name,
2100 sizeof(adapter->rx_ring->name) - 1,
2101 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002102 else
2103 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2104 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002105 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002106 netdev);
2107 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002108 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002109 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2110 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002111 adapter->rx_ring->itr_val = adapter->itr;
2112 vector++;
2113
2114 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002115 snprintf(adapter->tx_ring->name,
2116 sizeof(adapter->tx_ring->name) - 1,
2117 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002118 else
2119 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2120 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002121 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002122 netdev);
2123 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002124 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002125 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2126 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002127 adapter->tx_ring->itr_val = adapter->itr;
2128 vector++;
2129
2130 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002131 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002132 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002133 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002134
2135 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002136
Bruce Allan4662e822008-08-26 18:37:06 -07002137 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002138}
2139
Bruce Allanf8d59f72008-08-08 18:36:11 -07002140/**
2141 * e1000_request_irq - initialize interrupts
2142 *
2143 * Attempts to configure interrupts using the best available
2144 * capabilities of the hardware and kernel.
2145 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002146static int e1000_request_irq(struct e1000_adapter *adapter)
2147{
2148 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002149 int err;
2150
Bruce Allan4662e822008-08-26 18:37:06 -07002151 if (adapter->msix_entries) {
2152 err = e1000_request_msix(adapter);
2153 if (!err)
2154 return err;
2155 /* fall back to MSI */
2156 e1000e_reset_interrupt_capability(adapter);
2157 adapter->int_mode = E1000E_INT_MODE_MSI;
2158 e1000e_set_interrupt_capability(adapter);
2159 }
2160 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002161 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002162 netdev->name, netdev);
2163 if (!err)
2164 return err;
2165
2166 /* fall back to legacy interrupt */
2167 e1000e_reset_interrupt_capability(adapter);
2168 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002169 }
2170
Joe Perchesa0607fd2009-11-18 23:29:17 -08002171 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002172 netdev->name, netdev);
2173 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002174 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002175
2176 return err;
2177}
2178
2179static void e1000_free_irq(struct e1000_adapter *adapter)
2180{
2181 struct net_device *netdev = adapter->netdev;
2182
Bruce Allan4662e822008-08-26 18:37:06 -07002183 if (adapter->msix_entries) {
2184 int vector = 0;
2185
2186 free_irq(adapter->msix_entries[vector].vector, netdev);
2187 vector++;
2188
2189 free_irq(adapter->msix_entries[vector].vector, netdev);
2190 vector++;
2191
2192 /* Other Causes interrupt vector */
2193 free_irq(adapter->msix_entries[vector].vector, netdev);
2194 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002195 }
Bruce Allan4662e822008-08-26 18:37:06 -07002196
2197 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002198}
2199
2200/**
2201 * e1000_irq_disable - Mask off interrupt generation on the NIC
2202 **/
2203static void e1000_irq_disable(struct e1000_adapter *adapter)
2204{
2205 struct e1000_hw *hw = &adapter->hw;
2206
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002208 if (adapter->msix_entries)
2209 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002211
2212 if (adapter->msix_entries) {
2213 int i;
2214 for (i = 0; i < adapter->num_vectors; i++)
2215 synchronize_irq(adapter->msix_entries[i].vector);
2216 } else {
2217 synchronize_irq(adapter->pdev->irq);
2218 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219}
2220
2221/**
2222 * e1000_irq_enable - Enable default interrupt generation settings
2223 **/
2224static void e1000_irq_enable(struct e1000_adapter *adapter)
2225{
2226 struct e1000_hw *hw = &adapter->hw;
2227
Bruce Allan4662e822008-08-26 18:37:06 -07002228 if (adapter->msix_entries) {
2229 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2230 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002231 } else if (hw->mac.type == e1000_pch_lpt) {
2232 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002233 } else {
2234 ew32(IMS, IMS_ENABLE_MASK);
2235 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002236 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237}
2238
2239/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002240 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002241 * @adapter: address of board private structure
2242 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002243 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 * For ASF and Pass Through versions of f/w this means that
2245 * the driver is loaded. For AMT version (only with 82573)
2246 * of the f/w this means that the network i/f is open.
2247 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002248void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002249{
2250 struct e1000_hw *hw = &adapter->hw;
2251 u32 ctrl_ext;
2252 u32 swsm;
2253
2254 /* Let firmware know the driver has taken over */
2255 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2256 swsm = er32(SWSM);
2257 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2258 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2259 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002260 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261 }
2262}
2263
2264/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002265 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266 * @adapter: address of board private structure
2267 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002268 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 * For ASF and Pass Through versions of f/w this means that the
2270 * driver is no longer loaded. For AMT version (only with 82573) i
2271 * of the f/w this means that the network i/f is closed.
2272 *
2273 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002274void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002275{
2276 struct e1000_hw *hw = &adapter->hw;
2277 u32 ctrl_ext;
2278 u32 swsm;
2279
2280 /* Let firmware taken over control of h/w */
2281 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2282 swsm = er32(SWSM);
2283 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2284 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2285 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002286 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002287 }
2288}
2289
Auke Kokbc7f75f2007-09-17 12:30:59 -07002290/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002291 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002292 **/
2293static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2294 struct e1000_ring *ring)
2295{
2296 struct pci_dev *pdev = adapter->pdev;
2297
2298 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2299 GFP_KERNEL);
2300 if (!ring->desc)
2301 return -ENOMEM;
2302
2303 return 0;
2304}
2305
2306/**
2307 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002308 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 *
2310 * Return 0 on success, negative on failure
2311 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002312int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313{
Bruce Allan55aa6982011-12-16 00:45:45 +00002314 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002315 int err = -ENOMEM, size;
2316
2317 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002318 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 if (!tx_ring->buffer_info)
2320 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321
2322 /* round up to nearest 4K */
2323 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2324 tx_ring->size = ALIGN(tx_ring->size, 4096);
2325
2326 err = e1000_alloc_ring_dma(adapter, tx_ring);
2327 if (err)
2328 goto err;
2329
2330 tx_ring->next_to_use = 0;
2331 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332
2333 return 0;
2334err:
2335 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002336 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002337 return err;
2338}
2339
2340/**
2341 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002342 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 *
2344 * Returns 0 on success, negative on failure
2345 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002346int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347{
Bruce Allan55aa6982011-12-16 00:45:45 +00002348 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002349 struct e1000_buffer *buffer_info;
2350 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351
2352 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002353 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354 if (!rx_ring->buffer_info)
2355 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356
Auke Kok47f44e42007-10-25 13:57:44 -07002357 for (i = 0; i < rx_ring->count; i++) {
2358 buffer_info = &rx_ring->buffer_info[i];
2359 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2360 sizeof(struct e1000_ps_page),
2361 GFP_KERNEL);
2362 if (!buffer_info->ps_pages)
2363 goto err_pages;
2364 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365
2366 desc_len = sizeof(union e1000_rx_desc_packet_split);
2367
2368 /* Round up to nearest 4K */
2369 rx_ring->size = rx_ring->count * desc_len;
2370 rx_ring->size = ALIGN(rx_ring->size, 4096);
2371
2372 err = e1000_alloc_ring_dma(adapter, rx_ring);
2373 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002374 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375
2376 rx_ring->next_to_clean = 0;
2377 rx_ring->next_to_use = 0;
2378 rx_ring->rx_skb_top = NULL;
2379
2380 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002381
2382err_pages:
2383 for (i = 0; i < rx_ring->count; i++) {
2384 buffer_info = &rx_ring->buffer_info[i];
2385 kfree(buffer_info->ps_pages);
2386 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387err:
2388 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002389 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002390 return err;
2391}
2392
2393/**
2394 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002395 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002397static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398{
Bruce Allan55aa6982011-12-16 00:45:45 +00002399 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 struct e1000_buffer *buffer_info;
2401 unsigned long size;
2402 unsigned int i;
2403
2404 for (i = 0; i < tx_ring->count; i++) {
2405 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002406 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002407 }
2408
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002409 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 size = sizeof(struct e1000_buffer) * tx_ring->count;
2411 memset(tx_ring->buffer_info, 0, size);
2412
2413 memset(tx_ring->desc, 0, tx_ring->size);
2414
2415 tx_ring->next_to_use = 0;
2416 tx_ring->next_to_clean = 0;
2417
Bruce Allanc5083cf2011-12-16 00:45:40 +00002418 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002419 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2420 e1000e_update_tdt_wa(tx_ring, 0);
2421 else
2422 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423}
2424
2425/**
2426 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002427 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002428 *
2429 * Free all transmit software resources
2430 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002431void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432{
Bruce Allan55aa6982011-12-16 00:45:45 +00002433 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435
Bruce Allan55aa6982011-12-16 00:45:45 +00002436 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437
2438 vfree(tx_ring->buffer_info);
2439 tx_ring->buffer_info = NULL;
2440
2441 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2442 tx_ring->dma);
2443 tx_ring->desc = NULL;
2444}
2445
2446/**
2447 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002448 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002449 *
2450 * Free all receive software resources
2451 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002452void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453{
Bruce Allan55aa6982011-12-16 00:45:45 +00002454 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002455 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002456 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002457
Bruce Allan55aa6982011-12-16 00:45:45 +00002458 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002460 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002461 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002462
Auke Kokbc7f75f2007-09-17 12:30:59 -07002463 vfree(rx_ring->buffer_info);
2464 rx_ring->buffer_info = NULL;
2465
Auke Kokbc7f75f2007-09-17 12:30:59 -07002466 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2467 rx_ring->dma);
2468 rx_ring->desc = NULL;
2469}
2470
2471/**
2472 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002473 * @adapter: pointer to adapter
2474 * @itr_setting: current adapter->itr
2475 * @packets: the number of packets during this measurement interval
2476 * @bytes: the number of bytes during this measurement interval
2477 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478 * Stores a new ITR value based on packets and byte
2479 * counts during the last interrupt. The advantage of per interrupt
2480 * computation is faster updates and more accurate ITR for the current
2481 * traffic pattern. Constants in this function were computed
2482 * based on theoretical maximum wire speed and thresholds were set based
2483 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002484 * while increasing bulk throughput. This functionality is controlled
2485 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002486 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002487static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488{
2489 unsigned int retval = itr_setting;
2490
2491 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002492 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002493
2494 switch (itr_setting) {
2495 case lowest_latency:
2496 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002497 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002499 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501 break;
2502 case low_latency: /* 50 usec aka 20000 ints/s */
2503 if (bytes > 10000) {
2504 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002505 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002506 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002507 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002509 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002511 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002512 retval = bulk_latency;
2513 } else if (packets <= 2 && bytes < 512) {
2514 retval = lowest_latency;
2515 }
2516 break;
2517 case bulk_latency: /* 250 usec aka 4000 ints/s */
2518 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002519 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 } else if (bytes < 6000) {
2522 retval = low_latency;
2523 }
2524 break;
2525 }
2526
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 return retval;
2528}
2529
2530static void e1000_set_itr(struct e1000_adapter *adapter)
2531{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 u16 current_itr;
2533 u32 new_itr = adapter->itr;
2534
2535 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2536 if (adapter->link_speed != SPEED_1000) {
2537 current_itr = 0;
2538 new_itr = 4000;
2539 goto set_itr_now;
2540 }
2541
Bruce Allan828bac82010-09-29 21:39:37 +00002542 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2543 new_itr = 0;
2544 goto set_itr_now;
2545 }
2546
Bruce Allan8bb62862013-01-16 08:46:49 +00002547 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2548 adapter->total_tx_packets,
2549 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2551 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2552 adapter->tx_itr = low_latency;
2553
Bruce Allan8bb62862013-01-16 08:46:49 +00002554 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2555 adapter->total_rx_packets,
2556 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2558 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2559 adapter->rx_itr = low_latency;
2560
2561 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2562
2563 switch (current_itr) {
2564 /* counts and packets in update_itr are dependent on these numbers */
2565 case lowest_latency:
2566 new_itr = 70000;
2567 break;
2568 case low_latency:
2569 new_itr = 20000; /* aka hwitr = ~200 */
2570 break;
2571 case bulk_latency:
2572 new_itr = 4000;
2573 break;
2574 default:
2575 break;
2576 }
2577
2578set_itr_now:
2579 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002580 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002581 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002582 * increasing
2583 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002584 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002585 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002586 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002587 adapter->rx_ring->itr_val = new_itr;
2588 if (adapter->msix_entries)
2589 adapter->rx_ring->set_itr = 1;
2590 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002591 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002592 }
2593}
2594
2595/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002596 * e1000e_write_itr - write the ITR value to the appropriate registers
2597 * @adapter: address of board private structure
2598 * @itr: new ITR value to program
2599 *
2600 * e1000e_write_itr determines if the adapter is in MSI-X mode
2601 * and, if so, writes the EITR registers with the ITR value.
2602 * Otherwise, it writes the ITR value into the ITR register.
2603 **/
2604void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2605{
2606 struct e1000_hw *hw = &adapter->hw;
2607 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2608
2609 if (adapter->msix_entries) {
2610 int vector;
2611
2612 for (vector = 0; vector < adapter->num_vectors; vector++)
2613 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2614 } else {
2615 ew32(ITR, new_itr);
2616 }
2617}
2618
2619/**
Bruce Allan4662e822008-08-26 18:37:06 -07002620 * e1000_alloc_queues - Allocate memory for all rings
2621 * @adapter: board private structure to initialize
2622 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002623static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002624{
Bruce Allan55aa6982011-12-16 00:45:45 +00002625 int size = sizeof(struct e1000_ring);
2626
2627 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002628 if (!adapter->tx_ring)
2629 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002630 adapter->tx_ring->count = adapter->tx_ring_count;
2631 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002632
Bruce Allan55aa6982011-12-16 00:45:45 +00002633 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002634 if (!adapter->rx_ring)
2635 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002636 adapter->rx_ring->count = adapter->rx_ring_count;
2637 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002638
2639 return 0;
2640err:
2641 e_err("Unable to allocate memory for queues\n");
2642 kfree(adapter->rx_ring);
2643 kfree(adapter->tx_ring);
2644 return -ENOMEM;
2645}
2646
2647/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002648 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002649 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002650 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002652static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002653{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002654 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2655 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002656 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002658 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659
Wang Chen4cf16532008-11-12 23:38:14 -08002660 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661
Bruce Allanc58c8a72012-03-20 03:48:19 +00002662 if (!adapter->msix_entries ||
2663 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2664 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002665
Bruce Allanc58c8a72012-03-20 03:48:19 +00002666 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667
Alexander Duyck12d04a32009-03-25 22:05:03 +00002668 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002669 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002670
Bruce Allanc58c8a72012-03-20 03:48:19 +00002671 /* If weight not fully consumed, exit the polling mode */
2672 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673 if (adapter->itr_setting & 3)
2674 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002675 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002676 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2677 if (adapter->msix_entries)
2678 ew32(IMS, adapter->rx_ring->ims_val);
2679 else
2680 e1000_irq_enable(adapter);
2681 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002682 }
2683
2684 return work_done;
2685}
2686
Jiri Pirko8e586132011-12-08 19:52:37 -05002687static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688{
2689 struct e1000_adapter *adapter = netdev_priv(netdev);
2690 struct e1000_hw *hw = &adapter->hw;
2691 u32 vfta, index;
2692
2693 /* don't update vlan cookie if already programmed */
2694 if ((adapter->hw.mng_cookie.status &
2695 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2696 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002697 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002698
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002700 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2701 index = (vid >> 5) & 0x7F;
2702 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2703 vfta |= (1 << (vid & 0x1F));
2704 hw->mac.ops.write_vfta(hw, index, vfta);
2705 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002706
2707 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002708
2709 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002710}
2711
Jiri Pirko8e586132011-12-08 19:52:37 -05002712static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713{
2714 struct e1000_adapter *adapter = netdev_priv(netdev);
2715 struct e1000_hw *hw = &adapter->hw;
2716 u32 vfta, index;
2717
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 if ((adapter->hw.mng_cookie.status &
2719 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2720 (vid == adapter->mng_vlan_id)) {
2721 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002722 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002723 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002724 }
2725
2726 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002727 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2728 index = (vid >> 5) & 0x7F;
2729 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2730 vfta &= ~(1 << (vid & 0x1F));
2731 hw->mac.ops.write_vfta(hw, index, vfta);
2732 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002733
2734 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002735
2736 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002737}
2738
2739/**
2740 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2741 * @adapter: board private structure to initialize
2742 **/
2743static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2744{
2745 struct net_device *netdev = adapter->netdev;
2746 struct e1000_hw *hw = &adapter->hw;
2747 u32 rctl;
2748
2749 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2750 /* disable VLAN receive filtering */
2751 rctl = er32(RCTL);
2752 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2753 ew32(RCTL, rctl);
2754
2755 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2756 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2757 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2758 }
2759 }
2760}
2761
2762/**
2763 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2764 * @adapter: board private structure to initialize
2765 **/
2766static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2767{
2768 struct e1000_hw *hw = &adapter->hw;
2769 u32 rctl;
2770
2771 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2772 /* enable VLAN receive filtering */
2773 rctl = er32(RCTL);
2774 rctl |= E1000_RCTL_VFE;
2775 rctl &= ~E1000_RCTL_CFIEN;
2776 ew32(RCTL, rctl);
2777 }
2778}
2779
2780/**
2781 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2782 * @adapter: board private structure to initialize
2783 **/
2784static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2785{
2786 struct e1000_hw *hw = &adapter->hw;
2787 u32 ctrl;
2788
2789 /* disable VLAN tag insert/strip */
2790 ctrl = er32(CTRL);
2791 ctrl &= ~E1000_CTRL_VME;
2792 ew32(CTRL, ctrl);
2793}
2794
2795/**
2796 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2797 * @adapter: board private structure to initialize
2798 **/
2799static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2800{
2801 struct e1000_hw *hw = &adapter->hw;
2802 u32 ctrl;
2803
2804 /* enable VLAN tag insert/strip */
2805 ctrl = er32(CTRL);
2806 ctrl |= E1000_CTRL_VME;
2807 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002808}
2809
2810static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2811{
2812 struct net_device *netdev = adapter->netdev;
2813 u16 vid = adapter->hw.mng_cookie.vlan_id;
2814 u16 old_vid = adapter->mng_vlan_id;
2815
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002816 if (adapter->hw.mng_cookie.status &
2817 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2818 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819 adapter->mng_vlan_id = vid;
2820 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002822 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2823 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824}
2825
2826static void e1000_restore_vlan(struct e1000_adapter *adapter)
2827{
2828 u16 vid;
2829
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002830 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002832 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Bruce Allanf0ff4392013-02-20 04:05:39 +00002833 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834}
2835
Bruce Allancd791612010-05-10 14:59:51 +00002836static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837{
2838 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002839 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840
2841 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2842 return;
2843
2844 manc = er32(MANC);
2845
Bruce Allane921eb12012-11-28 09:28:37 +00002846 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002847 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002848 * the packets will be handled on SMBUS
2849 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002850 manc |= E1000_MANC_EN_MNG2HOST;
2851 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002852
2853 switch (hw->mac.type) {
2854 default:
2855 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2856 break;
2857 case e1000_82574:
2858 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002859 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002860 * if so, enable it.
2861 */
2862 for (i = 0, j = 0; i < 8; i++) {
2863 mdef = er32(MDEF(i));
2864
2865 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002866 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002867 continue;
2868
2869 /* Enable this decision filter in MANC2H */
2870 if (mdef)
2871 manc2h |= (1 << i);
2872
2873 j |= mdef;
2874 }
2875
2876 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2877 break;
2878
2879 /* Create new decision filter in an empty filter */
2880 for (i = 0, j = 0; i < 8; i++)
2881 if (er32(MDEF(i)) == 0) {
2882 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2883 E1000_MDEF_PORT_664));
2884 manc2h |= (1 << 1);
2885 j++;
2886 break;
2887 }
2888
2889 if (!j)
2890 e_warn("Unable to create IPMI pass-through filter\n");
2891 break;
2892 }
2893
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894 ew32(MANC2H, manc2h);
2895 ew32(MANC, manc);
2896}
2897
2898/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002899 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900 * @adapter: board private structure
2901 *
2902 * Configure the Tx unit of the MAC after a reset.
2903 **/
2904static void e1000_configure_tx(struct e1000_adapter *adapter)
2905{
2906 struct e1000_hw *hw = &adapter->hw;
2907 struct e1000_ring *tx_ring = adapter->tx_ring;
2908 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002909 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002910
2911 /* Setup the HW Tx Head and Tail descriptor pointers */
2912 tdba = tx_ring->dma;
2913 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002914 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2915 ew32(TDBAH(0), (tdba >> 32));
2916 ew32(TDLEN(0), tdlen);
2917 ew32(TDH(0), 0);
2918 ew32(TDT(0), 0);
2919 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2920 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002921
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922 /* Set the Tx Interrupt Delay register */
2923 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002924 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925 ew32(TADV, adapter->tx_abs_int_delay);
2926
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002927 if (adapter->flags2 & FLAG2_DMA_BURST) {
2928 u32 txdctl = er32(TXDCTL(0));
2929 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2930 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002931 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002932 * hardware to use the bus more efficiently in bursts, depends
2933 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002934 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002935 * hthresh = 1 ==> prefetch when one or more available
2936 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2937 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002938 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002939 */
2940 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2941 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002942 }
Bruce Allan56032be2011-12-16 00:46:01 +00002943 /* erratum work around: set txdctl the same for both queues */
2944 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002945
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002947 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002948 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002949 * gigabit link later
2950 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002951#define SPEED_MODE_BIT (1 << 21)
2952 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002953 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 }
2955
2956 /* errata: program both queues to unweighted RR */
2957 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002958 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002959 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002960 ew32(TARC(0), tarc);
2961 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002963 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 }
2965
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 /* Setup Transmit Descriptor Settings for eop descriptor */
2967 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2968
2969 /* only set IDE if we are delaying interrupts using the timers */
2970 if (adapter->tx_int_delay)
2971 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2972
2973 /* enable Report Status bit */
2974 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2975
Bruce Allan57cde762012-02-22 09:02:58 +00002976 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977}
2978
2979/**
2980 * e1000_setup_rctl - configure the receive control registers
2981 * @adapter: Board private structure
2982 **/
2983#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2984 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2985static void e1000_setup_rctl(struct e1000_adapter *adapter)
2986{
2987 struct e1000_hw *hw = &adapter->hw;
2988 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989 u32 pages = 0;
2990
Bruce Allan2fbe4522012-04-19 03:21:47 +00002991 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2992 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002993 s32 ret_val;
2994
2995 if (adapter->netdev->mtu > ETH_DATA_LEN)
2996 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2997 else
2998 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002999
3000 if (ret_val)
3001 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003002 }
3003
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004 /* Program MC offset vector base */
3005 rctl = er32(RCTL);
3006 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3007 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003008 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3009 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003010
3011 /* Do not Store bad packets */
3012 rctl &= ~E1000_RCTL_SBP;
3013
3014 /* Enable Long Packet receive */
3015 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3016 rctl &= ~E1000_RCTL_LPE;
3017 else
3018 rctl |= E1000_RCTL_LPE;
3019
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003020 /* Some systems expect that the CRC is included in SMBUS traffic. The
3021 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3022 * host memory when this is enabled
3023 */
3024 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3025 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003026
Bruce Allana4f58f52009-06-02 11:29:18 +00003027 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3028 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3029 u16 phy_data;
3030
3031 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3032 phy_data &= 0xfff8;
3033 phy_data |= (1 << 2);
3034 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3035
3036 e1e_rphy(hw, 22, &phy_data);
3037 phy_data &= 0x0fff;
3038 phy_data |= (1 << 14);
3039 e1e_wphy(hw, 0x10, 0x2823);
3040 e1e_wphy(hw, 0x11, 0x0003);
3041 e1e_wphy(hw, 22, phy_data);
3042 }
3043
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044 /* Setup buffer sizes */
3045 rctl &= ~E1000_RCTL_SZ_4096;
3046 rctl |= E1000_RCTL_BSEX;
3047 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 case 2048:
3049 default:
3050 rctl |= E1000_RCTL_SZ_2048;
3051 rctl &= ~E1000_RCTL_BSEX;
3052 break;
3053 case 4096:
3054 rctl |= E1000_RCTL_SZ_4096;
3055 break;
3056 case 8192:
3057 rctl |= E1000_RCTL_SZ_8192;
3058 break;
3059 case 16384:
3060 rctl |= E1000_RCTL_SZ_16384;
3061 break;
3062 }
3063
Bruce Allan5f450212011-07-22 06:21:46 +00003064 /* Enable Extended Status in all Receive Descriptors */
3065 rfctl = er32(RFCTL);
3066 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003067 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003068
Bruce Allane921eb12012-11-28 09:28:37 +00003069 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070 * header is placed in skb->data and the packet data is
3071 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3072 * In the case of a non-split, skb->data is linearly filled,
3073 * followed by the page buffers. Therefore, skb->data is
3074 * sized to hold the largest protocol header.
3075 *
3076 * allocations using alloc_page take too long for regular MTU
3077 * so only enable packet split for jumbo frames
3078 *
3079 * Using pages when the page size is greater than 16k wastes
3080 * a lot of memory, since we allocate 3 pages at all times
3081 * per packet.
3082 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003084 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003086 else
3087 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088
3089 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003090 u32 psrctl = 0;
3091
Auke Kok140a7482007-10-25 13:57:58 -07003092 /* Enable Packet split descriptors */
3093 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003094
3095 psrctl |= adapter->rx_ps_bsize0 >>
3096 E1000_PSRCTL_BSIZE0_SHIFT;
3097
3098 switch (adapter->rx_ps_pages) {
3099 case 3:
3100 psrctl |= PAGE_SIZE <<
3101 E1000_PSRCTL_BSIZE3_SHIFT;
3102 case 2:
3103 psrctl |= PAGE_SIZE <<
3104 E1000_PSRCTL_BSIZE2_SHIFT;
3105 case 1:
3106 psrctl |= PAGE_SIZE >>
3107 E1000_PSRCTL_BSIZE1_SHIFT;
3108 break;
3109 }
3110
3111 ew32(PSRCTL, psrctl);
3112 }
3113
Ben Greearcf955e62012-02-11 15:39:51 +00003114 /* This is useful for sniffing bad packets. */
3115 if (adapter->netdev->features & NETIF_F_RXALL) {
3116 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003117 * in e1000e_set_rx_mode
3118 */
Ben Greearcf955e62012-02-11 15:39:51 +00003119 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3120 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3121 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3122
3123 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3124 E1000_RCTL_DPF | /* Allow filtered pause */
3125 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3126 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3127 * and that breaks VLANs.
3128 */
3129 }
3130
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003132 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003133 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003134}
3135
3136/**
3137 * e1000_configure_rx - Configure Receive Unit after Reset
3138 * @adapter: board private structure
3139 *
3140 * Configure the Rx unit of the MAC after a reset.
3141 **/
3142static void e1000_configure_rx(struct e1000_adapter *adapter)
3143{
3144 struct e1000_hw *hw = &adapter->hw;
3145 struct e1000_ring *rx_ring = adapter->rx_ring;
3146 u64 rdba;
3147 u32 rdlen, rctl, rxcsum, ctrl_ext;
3148
3149 if (adapter->rx_ps_pages) {
3150 /* this is a 32 byte descriptor */
3151 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003152 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003153 adapter->clean_rx = e1000_clean_rx_irq_ps;
3154 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003155 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003156 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003157 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3158 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003160 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003161 adapter->clean_rx = e1000_clean_rx_irq;
3162 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3163 }
3164
3165 /* disable receives while setting up the descriptors */
3166 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003167 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3168 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003169 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003170 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003172 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003173 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003174 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003175 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003176 * granularity = 01
3177 * wthresh = 04,
3178 * hthresh = 04,
3179 * pthresh = 0x20
3180 */
3181 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3182 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3183
Bruce Allane921eb12012-11-28 09:28:37 +00003184 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003185 * the value was not set by the user via module options
3186 */
3187 if (adapter->rx_int_delay == DEFAULT_RDTR)
3188 adapter->rx_int_delay = BURST_RDTR;
3189 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3190 adapter->rx_abs_int_delay = BURST_RADV;
3191 }
3192
Auke Kokbc7f75f2007-09-17 12:30:59 -07003193 /* set the Receive Delay Timer Register */
3194 ew32(RDTR, adapter->rx_int_delay);
3195
3196 /* irq moderation */
3197 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003198 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003199 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003200
3201 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003202 /* Auto-Mask interrupts upon ICR access */
3203 ctrl_ext |= E1000_CTRL_EXT_IAME;
3204 ew32(IAM, 0xffffffff);
3205 ew32(CTRL_EXT, ctrl_ext);
3206 e1e_flush();
3207
Bruce Allane921eb12012-11-28 09:28:37 +00003208 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003209 * the Base and Length of the Rx Descriptor Ring
3210 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003211 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003212 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3213 ew32(RDBAH(0), (rdba >> 32));
3214 ew32(RDLEN(0), rdlen);
3215 ew32(RDH(0), 0);
3216 ew32(RDT(0), 0);
3217 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3218 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003219
3220 /* Enable Receive Checksum Offload for TCP and UDP */
3221 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003222 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003224 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003225 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226 ew32(RXCSUM, rxcsum);
3227
Bruce Allan3e35d992013-01-12 07:25:22 +00003228 /* With jumbo frames, excessive C-state transition latencies result
3229 * in dropped transactions.
3230 */
3231 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3232 u32 lat =
3233 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3234 adapter->max_frame_size) * 8 / 1000;
3235
3236 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003237 u32 rxdctl = er32(RXDCTL(0));
3238 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003239 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003240
3241 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3242 } else {
3243 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3244 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003245 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246
3247 /* Enable Receives */
3248 ew32(RCTL, rctl);
3249}
3250
3251/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003252 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253 * @netdev: network interface device structure
3254 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003255 * Writes multicast address list to the MTA hash table.
3256 * Returns: -ENOMEM on failure
3257 * 0 on no addresses written
3258 * X on writing X addresses to MTA
3259 */
3260static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261{
3262 struct e1000_adapter *adapter = netdev_priv(netdev);
3263 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003264 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003265 u8 *mta_list;
3266 int i;
3267
3268 if (netdev_mc_empty(netdev)) {
3269 /* nothing to program, so clear mc list */
3270 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3271 return 0;
3272 }
3273
3274 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3275 if (!mta_list)
3276 return -ENOMEM;
3277
3278 /* update_mc_addr_list expects a packed array of only addresses. */
3279 i = 0;
3280 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003281 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003282
3283 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3284 kfree(mta_list);
3285
3286 return netdev_mc_count(netdev);
3287}
3288
3289/**
3290 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3291 * @netdev: network interface device structure
3292 *
3293 * Writes unicast address list to the RAR table.
3294 * Returns: -ENOMEM on failure/insufficient address space
3295 * 0 on no addresses written
3296 * X on writing X addresses to the RAR table
3297 **/
3298static int e1000e_write_uc_addr_list(struct net_device *netdev)
3299{
3300 struct e1000_adapter *adapter = netdev_priv(netdev);
3301 struct e1000_hw *hw = &adapter->hw;
3302 unsigned int rar_entries = hw->mac.rar_entry_count;
3303 int count = 0;
3304
3305 /* save a rar entry for our hardware address */
3306 rar_entries--;
3307
3308 /* save a rar entry for the LAA workaround */
3309 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3310 rar_entries--;
3311
3312 /* return ENOMEM indicating insufficient memory for addresses */
3313 if (netdev_uc_count(netdev) > rar_entries)
3314 return -ENOMEM;
3315
3316 if (!netdev_uc_empty(netdev) && rar_entries) {
3317 struct netdev_hw_addr *ha;
3318
Bruce Allane921eb12012-11-28 09:28:37 +00003319 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003320 * combining
3321 */
3322 netdev_for_each_uc_addr(ha, netdev) {
3323 if (!rar_entries)
3324 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003325 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003326 count++;
3327 }
3328 }
3329
3330 /* zero out the remaining RAR entries not used above */
3331 for (; rar_entries > 0; rar_entries--) {
3332 ew32(RAH(rar_entries), 0);
3333 ew32(RAL(rar_entries), 0);
3334 }
3335 e1e_flush();
3336
3337 return count;
3338}
3339
3340/**
3341 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3342 * @netdev: network interface device structure
3343 *
3344 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3345 * address list or the network interface flags are updated. This routine is
3346 * responsible for configuring the hardware for proper unicast, multicast,
3347 * promiscuous mode, and all-multi behavior.
3348 **/
3349static void e1000e_set_rx_mode(struct net_device *netdev)
3350{
3351 struct e1000_adapter *adapter = netdev_priv(netdev);
3352 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003354
3355 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356 rctl = er32(RCTL);
3357
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003358 /* clear the affected bits */
3359 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3360
Auke Kokbc7f75f2007-09-17 12:30:59 -07003361 if (netdev->flags & IFF_PROMISC) {
3362 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003363 /* Do not hardware filter VLANs in promisc mode */
3364 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003365 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003366 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003367
Patrick McHardy746b9f02008-07-16 20:15:45 -07003368 if (netdev->flags & IFF_ALLMULTI) {
3369 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003370 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003371 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003372 * then we should just turn on promiscuous mode so
3373 * that we can at least receive multicast traffic
3374 */
3375 count = e1000e_write_mc_addr_list(netdev);
3376 if (count < 0)
3377 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003378 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003379 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003380 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003381 * sufficient space to store all the addresses then enable
3382 * unicast promiscuous mode
3383 */
3384 count = e1000e_write_uc_addr_list(netdev);
3385 if (count < 0)
3386 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003387 }
3388
3389 ew32(RCTL, rctl);
3390
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003391 if (netdev->features & NETIF_F_HW_VLAN_RX)
3392 e1000e_vlan_strip_enable(adapter);
3393 else
3394 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003395}
3396
Bruce Allan70495a52012-01-11 01:26:50 +00003397static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3398{
3399 struct e1000_hw *hw = &adapter->hw;
3400 u32 mrqc, rxcsum;
3401 int i;
3402 static const u32 rsskey[10] = {
3403 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3404 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3405 };
3406
3407 /* Fill out hash function seed */
3408 for (i = 0; i < 10; i++)
3409 ew32(RSSRK(i), rsskey[i]);
3410
3411 /* Direct all traffic to queue 0 */
3412 for (i = 0; i < 32; i++)
3413 ew32(RETA(i), 0);
3414
Bruce Allane921eb12012-11-28 09:28:37 +00003415 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003416 * descriptor on writeback.
3417 */
3418 rxcsum = er32(RXCSUM);
3419 rxcsum |= E1000_RXCSUM_PCSD;
3420
3421 ew32(RXCSUM, rxcsum);
3422
3423 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3424 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3425 E1000_MRQC_RSS_FIELD_IPV6 |
3426 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3427 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3428
3429 ew32(MRQC, mrqc);
3430}
3431
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003433 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3434 * @adapter: board private structure
3435 * @timinca: pointer to returned time increment attributes
3436 *
3437 * Get attributes for incrementing the System Time Register SYSTIML/H at
3438 * the default base frequency, and set the cyclecounter shift value.
3439 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003440s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003441{
3442 struct e1000_hw *hw = &adapter->hw;
3443 u32 incvalue, incperiod, shift;
3444
3445 /* Make sure clock is enabled on I217 before checking the frequency */
3446 if ((hw->mac.type == e1000_pch_lpt) &&
3447 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3448 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3449 u32 fextnvm7 = er32(FEXTNVM7);
3450
3451 if (!(fextnvm7 & (1 << 0))) {
3452 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3453 e1e_flush();
3454 }
3455 }
3456
3457 switch (hw->mac.type) {
3458 case e1000_pch2lan:
3459 case e1000_pch_lpt:
3460 /* On I217, the clock frequency is 25MHz or 96MHz as
3461 * indicated by the System Clock Frequency Indication
3462 */
3463 if ((hw->mac.type != e1000_pch_lpt) ||
3464 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3465 /* Stable 96MHz frequency */
3466 incperiod = INCPERIOD_96MHz;
3467 incvalue = INCVALUE_96MHz;
3468 shift = INCVALUE_SHIFT_96MHz;
3469 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3470 break;
3471 }
3472 /* fall-through */
3473 case e1000_82574:
3474 case e1000_82583:
3475 /* Stable 25MHz frequency */
3476 incperiod = INCPERIOD_25MHz;
3477 incvalue = INCVALUE_25MHz;
3478 shift = INCVALUE_SHIFT_25MHz;
3479 adapter->cc.shift = shift;
3480 break;
3481 default:
3482 return -EINVAL;
3483 }
3484
3485 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3486 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3487
3488 return 0;
3489}
3490
3491/**
3492 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3493 * @adapter: board private structure
3494 *
3495 * Outgoing time stamping can be enabled and disabled. Play nice and
3496 * disable it when requested, although it shouldn't cause any overhead
3497 * when no packet needs it. At most one packet in the queue may be
3498 * marked for time stamping, otherwise it would be impossible to tell
3499 * for sure to which packet the hardware time stamp belongs.
3500 *
3501 * Incoming time stamping has to be configured via the hardware filters.
3502 * Not all combinations are supported, in particular event type has to be
3503 * specified. Matching the kind of event packet is not supported, with the
3504 * exception of "all V2 events regardless of level 2 or 4".
3505 **/
3506static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3507{
3508 struct e1000_hw *hw = &adapter->hw;
3509 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3510 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3511 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003512 u32 rxmtrl = 0;
3513 u16 rxudp = 0;
3514 bool is_l4 = false;
3515 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003516 u32 regval;
3517 s32 ret_val;
3518
3519 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3520 return -EINVAL;
3521
3522 /* flags reserved for future extensions - must be zero */
3523 if (config->flags)
3524 return -EINVAL;
3525
3526 switch (config->tx_type) {
3527 case HWTSTAMP_TX_OFF:
3528 tsync_tx_ctl = 0;
3529 break;
3530 case HWTSTAMP_TX_ON:
3531 break;
3532 default:
3533 return -ERANGE;
3534 }
3535
3536 switch (config->rx_filter) {
3537 case HWTSTAMP_FILTER_NONE:
3538 tsync_rx_ctl = 0;
3539 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003540 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3541 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3542 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3543 is_l4 = true;
3544 break;
3545 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3546 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3547 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3548 is_l4 = true;
3549 break;
3550 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3551 /* Also time stamps V2 L2 Path Delay Request/Response */
3552 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3553 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3554 is_l2 = true;
3555 break;
3556 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3557 /* Also time stamps V2 L2 Path Delay Request/Response. */
3558 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3559 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3560 is_l2 = true;
3561 break;
3562 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3563 /* Hardware cannot filter just V2 L4 Sync messages;
3564 * fall-through to V2 (both L2 and L4) Sync.
3565 */
3566 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3567 /* Also time stamps V2 Path Delay Request/Response. */
3568 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3569 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3570 is_l2 = true;
3571 is_l4 = true;
3572 break;
3573 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3574 /* Hardware cannot filter just V2 L4 Delay Request messages;
3575 * fall-through to V2 (both L2 and L4) Delay Request.
3576 */
3577 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3578 /* Also time stamps V2 Path Delay Request/Response. */
3579 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3580 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3581 is_l2 = true;
3582 is_l4 = true;
3583 break;
3584 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3585 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3586 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3587 * fall-through to all V2 (both L2 and L4) Events.
3588 */
3589 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3590 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3591 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3592 is_l2 = true;
3593 is_l4 = true;
3594 break;
3595 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3596 /* For V1, the hardware can only filter Sync messages or
3597 * Delay Request messages but not both so fall-through to
3598 * time stamp all packets.
3599 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003600 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003601 is_l2 = true;
3602 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003603 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3604 config->rx_filter = HWTSTAMP_FILTER_ALL;
3605 break;
3606 default:
3607 return -ERANGE;
3608 }
3609
3610 /* enable/disable Tx h/w time stamping */
3611 regval = er32(TSYNCTXCTL);
3612 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3613 regval |= tsync_tx_ctl;
3614 ew32(TSYNCTXCTL, regval);
3615 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3616 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3617 e_err("Timesync Tx Control register not set as expected\n");
3618 return -EAGAIN;
3619 }
3620
3621 /* enable/disable Rx h/w time stamping */
3622 regval = er32(TSYNCRXCTL);
3623 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3624 regval |= tsync_rx_ctl;
3625 ew32(TSYNCRXCTL, regval);
3626 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3627 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3628 (regval & (E1000_TSYNCRXCTL_ENABLED |
3629 E1000_TSYNCRXCTL_TYPE_MASK))) {
3630 e_err("Timesync Rx Control register not set as expected\n");
3631 return -EAGAIN;
3632 }
3633
Bruce Alland89777b2013-01-19 01:09:58 +00003634 /* L2: define ethertype filter for time stamped packets */
3635 if (is_l2)
3636 rxmtrl |= ETH_P_1588;
3637
3638 /* define which PTP packets get time stamped */
3639 ew32(RXMTRL, rxmtrl);
3640
3641 /* Filter by destination port */
3642 if (is_l4) {
3643 rxudp = PTP_EV_PORT;
3644 cpu_to_be16s(&rxudp);
3645 }
3646 ew32(RXUDP, rxudp);
3647
3648 e1e_flush();
3649
Bruce Allanb67e1912012-12-27 08:32:33 +00003650 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003651 er32(RXSTMPH);
3652 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003653
3654 /* Get and set the System Time Register SYSTIM base frequency */
3655 ret_val = e1000e_get_base_timinca(adapter, &regval);
3656 if (ret_val)
3657 return ret_val;
3658 ew32(TIMINCA, regval);
3659
3660 /* reset the ns time counter */
3661 timecounter_init(&adapter->tc, &adapter->cc,
3662 ktime_to_ns(ktime_get_real()));
3663
3664 return 0;
3665}
3666
3667/**
Bruce Allanad680762008-03-28 09:15:03 -07003668 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003669 * @adapter: private board structure
3670 **/
3671static void e1000_configure(struct e1000_adapter *adapter)
3672{
Bruce Allan55aa6982011-12-16 00:45:45 +00003673 struct e1000_ring *rx_ring = adapter->rx_ring;
3674
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003675 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003676
3677 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003678 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679
3680 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003681
3682 if (adapter->netdev->features & NETIF_F_RXHASH)
3683 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003684 e1000_setup_rctl(adapter);
3685 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003686 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687}
3688
3689/**
3690 * e1000e_power_up_phy - restore link in case the phy was powered down
3691 * @adapter: address of board private structure
3692 *
3693 * The phy may be powered down to save power and turn off link when the
3694 * driver is unloaded and wake on lan is not enabled (among others)
3695 * *** this routine MUST be followed by a call to e1000e_reset ***
3696 **/
3697void e1000e_power_up_phy(struct e1000_adapter *adapter)
3698{
Bruce Allan17f208d2009-12-01 15:47:22 +00003699 if (adapter->hw.phy.ops.power_up)
3700 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701
3702 adapter->hw.mac.ops.setup_link(&adapter->hw);
3703}
3704
3705/**
3706 * e1000_power_down_phy - Power down the PHY
3707 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003708 * Power down the PHY so no link is implied when interface is down.
3709 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 */
3711static void e1000_power_down_phy(struct e1000_adapter *adapter)
3712{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003714 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003715 return;
3716
Bruce Allan17f208d2009-12-01 15:47:22 +00003717 if (adapter->hw.phy.ops.power_down)
3718 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719}
3720
3721/**
3722 * e1000e_reset - bring the hardware into a known good state
3723 *
3724 * This function boots the hardware and enables some settings that
3725 * require a configuration cycle of the hardware - those cannot be
3726 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003727 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 */
3729void e1000e_reset(struct e1000_adapter *adapter)
3730{
3731 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003732 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003733 struct e1000_hw *hw = &adapter->hw;
3734 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003735 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736 u16 hwm;
3737
Bruce Allanad680762008-03-28 09:15:03 -07003738 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003739 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003740
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003741 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003742 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 * large enough to accommodate two full transmit packets,
3744 * rounded up to the next 1KB and expressed in KB. Likewise,
3745 * the Rx FIFO should be large enough to accommodate at least
3746 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003747 * expressed in KB.
3748 */
Auke Kokdf762462007-10-25 13:57:53 -07003749 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003751 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003752 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003753 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003754 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003755 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003756 */
3757 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003758 sizeof(struct e1000_tx_desc) -
3759 ETH_FCS_LEN) * 2;
3760 min_tx_space = ALIGN(min_tx_space, 1024);
3761 min_tx_space >>= 10;
3762 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003763 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 min_rx_space = ALIGN(min_rx_space, 1024);
3765 min_rx_space >>= 10;
3766
Bruce Allane921eb12012-11-28 09:28:37 +00003767 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003769 * allocation, take space away from current Rx allocation
3770 */
Auke Kokdf762462007-10-25 13:57:53 -07003771 if ((tx_space < min_tx_space) &&
3772 ((min_tx_space - tx_space) < pba)) {
3773 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774
Bruce Allane921eb12012-11-28 09:28:37 +00003775 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003776 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003777 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003778 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003779 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003780 }
Auke Kokdf762462007-10-25 13:57:53 -07003781
3782 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003783 }
3784
Bruce Allane921eb12012-11-28 09:28:37 +00003785 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003786 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003787 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003788 * (or the size used for early receive) above it in the Rx FIFO.
3789 * Set it to the lower of:
3790 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003791 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003792 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003793 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3794 fc->pause_time = 0xFFFF;
3795 else
3796 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003797 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003798 fc->current_mode = fc->requested_mode;
3799
3800 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003801 case e1000_ich9lan:
3802 case e1000_ich10lan:
3803 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3804 pba = 14;
3805 ew32(PBA, pba);
3806 fc->high_water = 0x2800;
3807 fc->low_water = fc->high_water - 8;
3808 break;
3809 }
3810 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003811 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003812 hwm = min(((pba << 10) * 9 / 10),
3813 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003814
3815 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3816 fc->low_water = fc->high_water - 8;
3817 break;
3818 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003819 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003820 * loads. If hangs persist, try disabling Tx flow control.
3821 */
3822 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3823 fc->high_water = 0x3500;
3824 fc->low_water = 0x1500;
3825 } else {
3826 fc->high_water = 0x5000;
3827 fc->low_water = 0x3000;
3828 }
Bruce Allana3055952010-05-10 15:02:12 +00003829 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003830 break;
3831 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003832 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003833 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003834
3835 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3836 fc->high_water = 0x05C20;
3837 fc->low_water = 0x05048;
3838 fc->pause_time = 0x0650;
3839 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003840 }
Bruce Allan347b5202012-12-08 00:35:35 +00003841
3842 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3843 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003844 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003845 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003846
Bruce Allane921eb12012-11-28 09:28:37 +00003847 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003848 * maximum size per Tx descriptor limited only to the transmit
3849 * allocation of the packet buffer minus 96 bytes with an upper
3850 * limit of 24KB due to receive synchronization limitations.
3851 */
3852 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3853 24 << 10);
3854
Bruce Allane921eb12012-11-28 09:28:37 +00003855 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003856 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003857 */
3858 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003859 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003860 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3861 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003862 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003863 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003864 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003865 }
3866 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3867 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003868 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003869 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3870 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003871 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003872 }
3873 }
3874
Auke Kokbc7f75f2007-09-17 12:30:59 -07003875 /* Allow time for pending master requests to run */
3876 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003877
Bruce Allane921eb12012-11-28 09:28:37 +00003878 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003879 * that the network interface is in control
3880 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003881 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003882 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003883
Auke Kokbc7f75f2007-09-17 12:30:59 -07003884 ew32(WUC, 0);
3885
3886 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003887 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888
3889 e1000_update_mng_vlan(adapter);
3890
3891 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3892 ew32(VET, ETH_P_8021Q);
3893
3894 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003895
Bruce Allanb67e1912012-12-27 08:32:33 +00003896 /* initialize systim and reset the ns time counter */
3897 e1000e_config_hwtstamp(adapter);
3898
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003899 if (!netif_running(adapter->netdev) &&
3900 !test_bit(__E1000_TESTING, &adapter->state)) {
3901 e1000_power_down_phy(adapter);
3902 return;
3903 }
3904
Auke Kokbc7f75f2007-09-17 12:30:59 -07003905 e1000_get_phy_info(hw);
3906
Bruce Allan918d7192009-06-02 11:28:20 +00003907 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3908 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003909 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003910 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003911 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003912 * different we would do if it failed
3913 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3915 phy_data &= ~IGP02E1000_PM_SPD;
3916 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3917 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918}
3919
3920int e1000e_up(struct e1000_adapter *adapter)
3921{
3922 struct e1000_hw *hw = &adapter->hw;
3923
3924 /* hardware has been reset, we need to reload some things */
3925 e1000_configure(adapter);
3926
3927 clear_bit(__E1000_DOWN, &adapter->state);
3928
Bruce Allan4662e822008-08-26 18:37:06 -07003929 if (adapter->msix_entries)
3930 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 e1000_irq_enable(adapter);
3932
Bruce Allan400484f2011-05-13 07:20:03 +00003933 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003934
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003936 if (adapter->msix_entries)
3937 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3938 else
3939 ew32(ICS, E1000_ICS_LSC);
3940
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 return 0;
3942}
3943
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003944static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3945{
3946 struct e1000_hw *hw = &adapter->hw;
3947
3948 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3949 return;
3950
3951 /* flush pending descriptor writebacks to memory */
3952 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3953 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3954
3955 /* execute the writes immediately */
3956 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003957
Bruce Allane921eb12012-11-28 09:28:37 +00003958 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003959 * write is successful
3960 */
3961 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3962 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3963
3964 /* execute the writes immediately */
3965 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003966}
3967
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003968static void e1000e_update_stats(struct e1000_adapter *adapter);
3969
Auke Kokbc7f75f2007-09-17 12:30:59 -07003970void e1000e_down(struct e1000_adapter *adapter)
3971{
3972 struct net_device *netdev = adapter->netdev;
3973 struct e1000_hw *hw = &adapter->hw;
3974 u32 tctl, rctl;
3975
Bruce Allane921eb12012-11-28 09:28:37 +00003976 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003977 * reschedule our watchdog timer
3978 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003979 set_bit(__E1000_DOWN, &adapter->state);
3980
3981 /* disable receives in the hardware */
3982 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003983 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3984 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003985 /* flush and sleep below */
3986
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003987 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003988
3989 /* disable transmits in the hardware */
3990 tctl = er32(TCTL);
3991 tctl &= ~E1000_TCTL_EN;
3992 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003993
Auke Kokbc7f75f2007-09-17 12:30:59 -07003994 /* flush both disables and wait for them to finish */
3995 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003996 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003997
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998 e1000_irq_disable(adapter);
3999
4000 del_timer_sync(&adapter->watchdog_timer);
4001 del_timer_sync(&adapter->phy_info_timer);
4002
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004004
4005 spin_lock(&adapter->stats64_lock);
4006 e1000e_update_stats(adapter);
4007 spin_unlock(&adapter->stats64_lock);
4008
Bruce Allan400484f2011-05-13 07:20:03 +00004009 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004010 e1000_clean_tx_ring(adapter->tx_ring);
4011 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004012
Auke Kokbc7f75f2007-09-17 12:30:59 -07004013 adapter->link_speed = 0;
4014 adapter->link_duplex = 0;
4015
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004016 if (!pci_channel_offline(adapter->pdev))
4017 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004018
Bruce Allane921eb12012-11-28 09:28:37 +00004019 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 * pci_disable_device here.
4021 */
4022}
4023
4024void e1000e_reinit_locked(struct e1000_adapter *adapter)
4025{
4026 might_sleep();
4027 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004028 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004029 e1000e_down(adapter);
4030 e1000e_up(adapter);
4031 clear_bit(__E1000_RESETTING, &adapter->state);
4032}
4033
4034/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004035 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4036 * @cc: cyclecounter structure
4037 **/
4038static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4039{
4040 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4041 cc);
4042 struct e1000_hw *hw = &adapter->hw;
4043 cycle_t systim;
4044
4045 /* latch SYSTIMH on read of SYSTIML */
4046 systim = (cycle_t)er32(SYSTIML);
4047 systim |= (cycle_t)er32(SYSTIMH) << 32;
4048
4049 return systim;
4050}
4051
4052/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004053 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4054 * @adapter: board private structure to initialize
4055 *
4056 * e1000_sw_init initializes the Adapter private data structure.
4057 * Fields are initialized based on PCI device information and
4058 * OS network device settings (MTU size).
4059 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004060static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004061{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062 struct net_device *netdev = adapter->netdev;
4063
4064 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4065 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004066 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4067 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004068 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4069 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004071 spin_lock_init(&adapter->stats64_lock);
4072
Bruce Allan4662e822008-08-26 18:37:06 -07004073 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004074
Bruce Allan4662e822008-08-26 18:37:06 -07004075 if (e1000_alloc_queues(adapter))
4076 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004077
Bruce Allanb67e1912012-12-27 08:32:33 +00004078 /* Setup hardware time stamping cyclecounter */
4079 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4080 adapter->cc.read = e1000e_cyclecounter_read;
4081 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4082 adapter->cc.mult = 1;
4083 /* cc.shift set in e1000e_get_base_tininca() */
4084
4085 spin_lock_init(&adapter->systim_lock);
4086 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4087 }
4088
Auke Kokbc7f75f2007-09-17 12:30:59 -07004089 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 e1000_irq_disable(adapter);
4091
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092 set_bit(__E1000_DOWN, &adapter->state);
4093 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004094}
4095
4096/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004097 * e1000_intr_msi_test - Interrupt Handler
4098 * @irq: interrupt number
4099 * @data: pointer to a network interface device structure
4100 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004101static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004102{
4103 struct net_device *netdev = data;
4104 struct e1000_adapter *adapter = netdev_priv(netdev);
4105 struct e1000_hw *hw = &adapter->hw;
4106 u32 icr = er32(ICR);
4107
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004108 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004109 if (icr & E1000_ICR_RXSEQ) {
4110 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004111 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004112 * interrupt is handled.
4113 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004114 wmb();
4115 }
4116
4117 return IRQ_HANDLED;
4118}
4119
4120/**
4121 * e1000_test_msi_interrupt - Returns 0 for successful test
4122 * @adapter: board private struct
4123 *
4124 * code flow taken from tg3.c
4125 **/
4126static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4127{
4128 struct net_device *netdev = adapter->netdev;
4129 struct e1000_hw *hw = &adapter->hw;
4130 int err;
4131
4132 /* poll_enable hasn't been called yet, so don't need disable */
4133 /* clear any pending events */
4134 er32(ICR);
4135
4136 /* free the real vector and request a test handler */
4137 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004138 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004139
4140 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004141 * MSI irq handler will unset this flag
4142 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004143 adapter->flags |= FLAG_MSI_TEST_FAILED;
4144
4145 err = pci_enable_msi(adapter->pdev);
4146 if (err)
4147 goto msi_test_failed;
4148
Joe Perchesa0607fd2009-11-18 23:29:17 -08004149 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004150 netdev->name, netdev);
4151 if (err) {
4152 pci_disable_msi(adapter->pdev);
4153 goto msi_test_failed;
4154 }
4155
Bruce Allane921eb12012-11-28 09:28:37 +00004156 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004157 * interrupt.
4158 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004159 wmb();
4160
4161 e1000_irq_enable(adapter);
4162
4163 /* fire an unusual interrupt on the test handler */
4164 ew32(ICS, E1000_ICS_RXSEQ);
4165 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004166 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004167
4168 e1000_irq_disable(adapter);
4169
Bruce Allanbc763292012-08-17 06:18:07 +00004170 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004171
4172 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004173 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004174 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004175 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004176 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004177 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004178
4179 free_irq(adapter->pdev->irq, netdev);
4180 pci_disable_msi(adapter->pdev);
4181
Bruce Allanf8d59f72008-08-08 18:36:11 -07004182msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004183 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004184 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004185}
4186
4187/**
4188 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4189 * @adapter: board private struct
4190 *
4191 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4192 **/
4193static int e1000_test_msi(struct e1000_adapter *adapter)
4194{
4195 int err;
4196 u16 pci_cmd;
4197
4198 if (!(adapter->flags & FLAG_MSI_ENABLED))
4199 return 0;
4200
4201 /* disable SERR in case the MSI write causes a master abort */
4202 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004203 if (pci_cmd & PCI_COMMAND_SERR)
4204 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4205 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004206
4207 err = e1000_test_msi_interrupt(adapter);
4208
Dean Nelson36f24072010-06-29 18:12:05 +00004209 /* re-enable SERR */
4210 if (pci_cmd & PCI_COMMAND_SERR) {
4211 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4212 pci_cmd |= PCI_COMMAND_SERR;
4213 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4214 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004215
Bruce Allanf8d59f72008-08-08 18:36:11 -07004216 return err;
4217}
4218
4219/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004220 * e1000_open - Called when a network interface is made active
4221 * @netdev: network interface device structure
4222 *
4223 * Returns 0 on success, negative value on failure
4224 *
4225 * The open entry point is called when a network interface is made
4226 * active by the system (IFF_UP). At this point all resources needed
4227 * for transmit and receive operations are allocated, the interrupt
4228 * handler is registered with the OS, the watchdog timer is started,
4229 * and the stack is notified that the interface is ready.
4230 **/
4231static int e1000_open(struct net_device *netdev)
4232{
4233 struct e1000_adapter *adapter = netdev_priv(netdev);
4234 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004235 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004236 int err;
4237
4238 /* disallow open during test */
4239 if (test_bit(__E1000_TESTING, &adapter->state))
4240 return -EBUSY;
4241
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004242 pm_runtime_get_sync(&pdev->dev);
4243
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004244 netif_carrier_off(netdev);
4245
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004247 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004248 if (err)
4249 goto err_setup_tx;
4250
4251 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004252 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004253 if (err)
4254 goto err_setup_rx;
4255
Bruce Allane921eb12012-11-28 09:28:37 +00004256 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004257 * interface is now open and reset the part to a known state.
4258 */
4259 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004260 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004261 e1000e_reset(adapter);
4262 }
4263
Auke Kokbc7f75f2007-09-17 12:30:59 -07004264 e1000e_power_up_phy(adapter);
4265
4266 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4267 if ((adapter->hw.mng_cookie.status &
4268 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4269 e1000_update_mng_vlan(adapter);
4270
Bruce Allan79d4e902011-12-16 00:46:27 +00004271 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004272 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4273 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004274
Bruce Allane921eb12012-11-28 09:28:37 +00004275 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4277 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004278 * clean_rx handler before we do so.
4279 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 e1000_configure(adapter);
4281
4282 err = e1000_request_irq(adapter);
4283 if (err)
4284 goto err_req_irq;
4285
Bruce Allane921eb12012-11-28 09:28:37 +00004286 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004287 * ignore e1000e MSI messages, which means we need to test our MSI
4288 * interrupt now
4289 */
Bruce Allan4662e822008-08-26 18:37:06 -07004290 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004291 err = e1000_test_msi(adapter);
4292 if (err) {
4293 e_err("Interrupt allocation failed\n");
4294 goto err_req_irq;
4295 }
4296 }
4297
Auke Kokbc7f75f2007-09-17 12:30:59 -07004298 /* From here on the code is the same as e1000e_up() */
4299 clear_bit(__E1000_DOWN, &adapter->state);
4300
4301 napi_enable(&adapter->napi);
4302
4303 e1000_irq_enable(adapter);
4304
Jeff Kirsher09357b02011-11-18 14:25:00 +00004305 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004306 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004307
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004308 adapter->idle_check = true;
4309 pm_runtime_put(&pdev->dev);
4310
Auke Kokbc7f75f2007-09-17 12:30:59 -07004311 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004312 if (adapter->msix_entries)
4313 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4314 else
4315 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316
4317 return 0;
4318
4319err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004320 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004321 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004322 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004324 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004325err_setup_tx:
4326 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004327 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328
4329 return err;
4330}
4331
4332/**
4333 * e1000_close - Disables a network interface
4334 * @netdev: network interface device structure
4335 *
4336 * Returns 0, this is not allowed to fail
4337 *
4338 * The close entry point is called when an interface is de-activated
4339 * by the OS. The hardware is still under the drivers control, but
4340 * needs to be disabled. A global MAC reset is issued to stop the
4341 * hardware, and all transmit and receive resources are freed.
4342 **/
4343static int e1000_close(struct net_device *netdev)
4344{
4345 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004346 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004347 int count = E1000_CHECK_RESET_COUNT;
4348
4349 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4350 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004351
4352 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004353
4354 pm_runtime_get_sync(&pdev->dev);
4355
Bruce Allan5f4a7802011-11-29 08:09:19 +00004356 napi_disable(&adapter->napi);
4357
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004358 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4359 e1000e_down(adapter);
4360 e1000_free_irq(adapter);
4361 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004362 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004363
Bruce Allan55aa6982011-12-16 00:45:45 +00004364 e1000e_free_tx_resources(adapter->tx_ring);
4365 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004366
Bruce Allane921eb12012-11-28 09:28:37 +00004367 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004368 * the same ID is registered on the host OS (let 8021q kill it)
4369 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004370 if (adapter->hw.mng_cookie.status &
4371 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004372 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4373
Bruce Allane921eb12012-11-28 09:28:37 +00004374 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004375 * interface is now closed
4376 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004377 if ((adapter->flags & FLAG_HAS_AMT) &&
4378 !test_bit(__E1000_TESTING, &adapter->state))
4379 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004380
Bruce Allan3e35d992013-01-12 07:25:22 +00004381 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004382
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004383 pm_runtime_put_sync(&pdev->dev);
4384
Auke Kokbc7f75f2007-09-17 12:30:59 -07004385 return 0;
4386}
4387/**
4388 * e1000_set_mac - Change the Ethernet Address of the NIC
4389 * @netdev: network interface device structure
4390 * @p: pointer to an address structure
4391 *
4392 * Returns 0 on success, negative on failure
4393 **/
4394static int e1000_set_mac(struct net_device *netdev, void *p)
4395{
4396 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004397 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004398 struct sockaddr *addr = p;
4399
4400 if (!is_valid_ether_addr(addr->sa_data))
4401 return -EADDRNOTAVAIL;
4402
4403 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4404 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4405
Bruce Allan69e1e012012-04-14 03:28:50 +00004406 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407
4408 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4409 /* activate the work around */
4410 e1000e_set_laa_state_82571(&adapter->hw, 1);
4411
Bruce Allane921eb12012-11-28 09:28:37 +00004412 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004413 * between the time RAR[0] gets clobbered and the time it
4414 * gets fixed (in e1000_watchdog), the actual LAA is in one
4415 * of the RARs and no incoming packets directed to this port
4416 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004417 * RAR[14]
4418 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004419 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4420 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004421 }
4422
4423 return 0;
4424}
4425
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004426/**
4427 * e1000e_update_phy_task - work thread to update phy
4428 * @work: pointer to our work struct
4429 *
4430 * this worker thread exists because we must acquire a
4431 * semaphore to read the phy, which we could msleep while
4432 * waiting for it, and we can't msleep in a timer.
4433 **/
4434static void e1000e_update_phy_task(struct work_struct *work)
4435{
4436 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004437 struct e1000_adapter,
4438 update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004439
4440 if (test_bit(__E1000_DOWN, &adapter->state))
4441 return;
4442
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004443 e1000_get_phy_info(&adapter->hw);
4444}
4445
Bruce Allane921eb12012-11-28 09:28:37 +00004446/**
4447 * e1000_update_phy_info - timre call-back to update PHY info
4448 * @data: pointer to adapter cast into an unsigned long
4449 *
Bruce Allanad680762008-03-28 09:15:03 -07004450 * Need to wait a few seconds after link up to get diagnostic information from
4451 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004452 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004453static void e1000_update_phy_info(unsigned long data)
4454{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004455 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004456
4457 if (test_bit(__E1000_DOWN, &adapter->state))
4458 return;
4459
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004460 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004461}
4462
4463/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004464 * e1000e_update_phy_stats - Update the PHY statistics counters
4465 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004466 *
4467 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004468 **/
4469static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4470{
4471 struct e1000_hw *hw = &adapter->hw;
4472 s32 ret_val;
4473 u16 phy_data;
4474
4475 ret_val = hw->phy.ops.acquire(hw);
4476 if (ret_val)
4477 return;
4478
Bruce Allane921eb12012-11-28 09:28:37 +00004479 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004480 * If not, set to the page with the PHY status registers.
4481 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004482 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004483 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4484 &phy_data);
4485 if (ret_val)
4486 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004487 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4488 ret_val = hw->phy.ops.set_page(hw,
4489 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004490 if (ret_val)
4491 goto release;
4492 }
4493
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004494 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004495 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4496 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004497 if (!ret_val)
4498 adapter->stats.scc += phy_data;
4499
4500 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004501 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4502 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004503 if (!ret_val)
4504 adapter->stats.ecol += phy_data;
4505
4506 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004507 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4508 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004509 if (!ret_val)
4510 adapter->stats.mcc += phy_data;
4511
4512 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004513 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4514 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004515 if (!ret_val)
4516 adapter->stats.latecol += phy_data;
4517
4518 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004519 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4520 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004521 if (!ret_val)
4522 hw->mac.collision_delta = phy_data;
4523
4524 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004525 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4526 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004527 if (!ret_val)
4528 adapter->stats.dc += phy_data;
4529
4530 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004531 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4532 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004533 if (!ret_val)
4534 adapter->stats.tncrs += phy_data;
4535
4536release:
4537 hw->phy.ops.release(hw);
4538}
4539
4540/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004541 * e1000e_update_stats - Update the board statistics counters
4542 * @adapter: board private structure
4543 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004544static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004545{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004546 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 struct e1000_hw *hw = &adapter->hw;
4548 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004549
Bruce Allane921eb12012-11-28 09:28:37 +00004550 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004551 * connection is down.
4552 */
4553 if (adapter->link_speed == 0)
4554 return;
4555 if (pci_channel_offline(pdev))
4556 return;
4557
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558 adapter->stats.crcerrs += er32(CRCERRS);
4559 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004560 adapter->stats.gorc += er32(GORCL);
4561 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562 adapter->stats.bprc += er32(BPRC);
4563 adapter->stats.mprc += er32(MPRC);
4564 adapter->stats.roc += er32(ROC);
4565
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004567
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004568 /* Half-duplex statistics */
4569 if (adapter->link_duplex == HALF_DUPLEX) {
4570 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4571 e1000e_update_phy_stats(adapter);
4572 } else {
4573 adapter->stats.scc += er32(SCC);
4574 adapter->stats.ecol += er32(ECOL);
4575 adapter->stats.mcc += er32(MCC);
4576 adapter->stats.latecol += er32(LATECOL);
4577 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004578
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004579 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004580
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004581 if ((hw->mac.type != e1000_82574) &&
4582 (hw->mac.type != e1000_82583))
4583 adapter->stats.tncrs += er32(TNCRS);
4584 }
4585 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004586 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004587
Auke Kokbc7f75f2007-09-17 12:30:59 -07004588 adapter->stats.xonrxc += er32(XONRXC);
4589 adapter->stats.xontxc += er32(XONTXC);
4590 adapter->stats.xoffrxc += er32(XOFFRXC);
4591 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004592 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004593 adapter->stats.gotc += er32(GOTCL);
4594 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004595 adapter->stats.rnbc += er32(RNBC);
4596 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004597
4598 adapter->stats.mptc += er32(MPTC);
4599 adapter->stats.bptc += er32(BPTC);
4600
4601 /* used for adaptive IFS */
4602
4603 hw->mac.tx_packet_delta = er32(TPT);
4604 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004605
4606 adapter->stats.algnerrc += er32(ALGNERRC);
4607 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004608 adapter->stats.cexterr += er32(CEXTERR);
4609 adapter->stats.tsctc += er32(TSCTC);
4610 adapter->stats.tsctfc += er32(TSCTFC);
4611
Auke Kokbc7f75f2007-09-17 12:30:59 -07004612 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004613 netdev->stats.multicast = adapter->stats.mprc;
4614 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004615
4616 /* Rx Errors */
4617
Bruce Allane921eb12012-11-28 09:28:37 +00004618 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004619 * our own version based on RUC and ROC
4620 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004621 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004622 adapter->stats.crcerrs + adapter->stats.algnerrc +
4623 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004624 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004625 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004626 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4627 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4628 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629
4630 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004631 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004632 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4633 netdev->stats.tx_window_errors = adapter->stats.latecol;
4634 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635
4636 /* Tx Dropped needs to be maintained elsewhere */
4637
Auke Kokbc7f75f2007-09-17 12:30:59 -07004638 /* Management Stats */
4639 adapter->stats.mgptc += er32(MGTPTC);
4640 adapter->stats.mgprc += er32(MGTPRC);
4641 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004642
4643 /* Correctable ECC Errors */
4644 if (hw->mac.type == e1000_pch_lpt) {
4645 u32 pbeccsts = er32(PBECCSTS);
4646 adapter->corr_errors +=
4647 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4648 adapter->uncorr_errors +=
4649 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4650 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4651 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004652}
4653
Bruce Allan7c257692008-04-23 11:09:00 -07004654/**
4655 * e1000_phy_read_status - Update the PHY register status snapshot
4656 * @adapter: board private structure
4657 **/
4658static void e1000_phy_read_status(struct e1000_adapter *adapter)
4659{
4660 struct e1000_hw *hw = &adapter->hw;
4661 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004662
4663 if ((er32(STATUS) & E1000_STATUS_LU) &&
4664 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004665 int ret_val;
4666
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004667 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4668 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4669 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4670 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4671 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4672 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4673 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4674 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004675 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004676 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004677 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004678 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004679 * Set values to typical power-on defaults
4680 */
4681 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4682 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4683 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4684 BMSR_ERCAP);
4685 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4686 ADVERTISE_ALL | ADVERTISE_CSMA);
4687 phy->lpa = 0;
4688 phy->expansion = EXPANSION_ENABLENPAGE;
4689 phy->ctrl1000 = ADVERTISE_1000FULL;
4690 phy->stat1000 = 0;
4691 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4692 }
Bruce Allan7c257692008-04-23 11:09:00 -07004693}
4694
Auke Kokbc7f75f2007-09-17 12:30:59 -07004695static void e1000_print_link_info(struct e1000_adapter *adapter)
4696{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004697 struct e1000_hw *hw = &adapter->hw;
4698 u32 ctrl = er32(CTRL);
4699
Bruce Allan8f12fe82008-11-21 16:54:43 -08004700 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004701 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4702 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004703 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4704 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4705 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4706 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707}
4708
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004709static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004710{
4711 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004712 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004713 s32 ret_val = 0;
4714
Bruce Allane921eb12012-11-28 09:28:37 +00004715 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004716 * Rx sequence error interrupt. get_link_status will stay
4717 * false until the check_for_link establishes link
4718 * for copper adapters ONLY
4719 */
4720 switch (hw->phy.media_type) {
4721 case e1000_media_type_copper:
4722 if (hw->mac.get_link_status) {
4723 ret_val = hw->mac.ops.check_for_link(hw);
4724 link_active = !hw->mac.get_link_status;
4725 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004726 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004727 }
4728 break;
4729 case e1000_media_type_fiber:
4730 ret_val = hw->mac.ops.check_for_link(hw);
4731 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4732 break;
4733 case e1000_media_type_internal_serdes:
4734 ret_val = hw->mac.ops.check_for_link(hw);
4735 link_active = adapter->hw.mac.serdes_has_link;
4736 break;
4737 default:
4738 case e1000_media_type_unknown:
4739 break;
4740 }
4741
4742 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4743 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4744 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004745 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004746 }
4747
4748 return link_active;
4749}
4750
4751static void e1000e_enable_receives(struct e1000_adapter *adapter)
4752{
4753 /* make sure the receive unit is started */
4754 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004755 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004756 struct e1000_hw *hw = &adapter->hw;
4757 u32 rctl = er32(RCTL);
4758 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004759 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004760 }
4761}
4762
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004763static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4764{
4765 struct e1000_hw *hw = &adapter->hw;
4766
Bruce Allane921eb12012-11-28 09:28:37 +00004767 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004768 * for hung state and reset, if two calls return true
4769 */
4770 if (e1000_check_phy_82574(hw))
4771 adapter->phy_hang_count++;
4772 else
4773 adapter->phy_hang_count = 0;
4774
4775 if (adapter->phy_hang_count > 1) {
4776 adapter->phy_hang_count = 0;
4777 schedule_work(&adapter->reset_task);
4778 }
4779}
4780
Auke Kokbc7f75f2007-09-17 12:30:59 -07004781/**
4782 * e1000_watchdog - Timer Call-back
4783 * @data: pointer to adapter cast into an unsigned long
4784 **/
4785static void e1000_watchdog(unsigned long data)
4786{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004787 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004788
4789 /* Do the rest outside of interrupt context */
4790 schedule_work(&adapter->watchdog_task);
4791
4792 /* TODO: make this use queue_delayed_work() */
4793}
4794
4795static void e1000_watchdog_task(struct work_struct *work)
4796{
4797 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004798 struct e1000_adapter,
4799 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004800 struct net_device *netdev = adapter->netdev;
4801 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004802 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004803 struct e1000_ring *tx_ring = adapter->tx_ring;
4804 struct e1000_hw *hw = &adapter->hw;
4805 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004806
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004807 if (test_bit(__E1000_DOWN, &adapter->state))
4808 return;
4809
David S. Millerb405e8d2010-02-04 22:31:41 -08004810 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004811 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004812 /* Cancel scheduled suspend requests. */
4813 pm_runtime_resume(netdev->dev.parent);
4814
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004815 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004817 }
4818
4819 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4820 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4821 e1000_update_mng_vlan(adapter);
4822
Auke Kokbc7f75f2007-09-17 12:30:59 -07004823 if (link) {
4824 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004825 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004826
4827 /* Cancel scheduled suspend requests. */
4828 pm_runtime_resume(netdev->dev.parent);
4829
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004830 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004831 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004832 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004833 &adapter->link_speed,
4834 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004835 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004836
4837 /* check if SmartSpeed worked */
4838 e1000e_check_downshift(hw);
4839 if (phy->speed_downgraded)
4840 netdev_warn(netdev,
4841 "Link Speed was downgraded by SmartSpeed\n");
4842
Bruce Allane921eb12012-11-28 09:28:37 +00004843 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004844 * if link has autonegotiated at 10/100 half
4845 */
4846 if ((hw->phy.type == e1000_phy_igp_3 ||
4847 hw->phy.type == e1000_phy_bm) &&
4848 (hw->mac.autoneg == true) &&
4849 (adapter->link_speed == SPEED_10 ||
4850 adapter->link_speed == SPEED_100) &&
4851 (adapter->link_duplex == HALF_DUPLEX)) {
4852 u16 autoneg_exp;
4853
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004854 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004855
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004856 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004857 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 -07004858 }
4859
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004860 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004861 adapter->tx_timeout_factor = 1;
4862 switch (adapter->link_speed) {
4863 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004864 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004865 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004866 break;
4867 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004868 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004869 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004870 break;
4871 }
4872
Bruce Allane921eb12012-11-28 09:28:37 +00004873 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004874 * link-up event
4875 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004876 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4877 !txb2b) {
4878 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004879 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004881 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004882 }
4883
Bruce Allane921eb12012-11-28 09:28:37 +00004884 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004885 * some hardware issues
4886 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004887 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4888 switch (adapter->link_speed) {
4889 case SPEED_10:
4890 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004891 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004892 netdev->features &= ~NETIF_F_TSO;
4893 netdev->features &= ~NETIF_F_TSO6;
4894 break;
4895 case SPEED_1000:
4896 netdev->features |= NETIF_F_TSO;
4897 netdev->features |= NETIF_F_TSO6;
4898 break;
4899 default:
4900 /* oops */
4901 break;
4902 }
4903 }
4904
Bruce Allane921eb12012-11-28 09:28:37 +00004905 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004906 * after setting TARC(0)
4907 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004908 tctl = er32(TCTL);
4909 tctl |= E1000_TCTL_EN;
4910 ew32(TCTL, tctl);
4911
Bruce Allane921eb12012-11-28 09:28:37 +00004912 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004913 * reporting link up.
4914 */
4915 if (phy->ops.cfg_on_link_up)
4916 phy->ops.cfg_on_link_up(hw);
4917
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004919
4920 if (!test_bit(__E1000_DOWN, &adapter->state))
4921 mod_timer(&adapter->phy_info_timer,
4922 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 }
4924 } else {
4925 if (netif_carrier_ok(netdev)) {
4926 adapter->link_speed = 0;
4927 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004928 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004929 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004931 if (!test_bit(__E1000_DOWN, &adapter->state))
4932 mod_timer(&adapter->phy_info_timer,
4933 round_jiffies(jiffies + 2 * HZ));
4934
Bruce Allan12d43f72012-12-05 06:26:14 +00004935 /* The link is lost so the controller stops DMA.
4936 * If there is queued Tx work that cannot be done
4937 * or if on an 8000ES2LAN which requires a Rx packet
4938 * buffer work-around on link down event, reset the
4939 * controller to flush the Tx/Rx packet buffers.
4940 * (Do the reset outside of interrupt context).
4941 */
4942 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4943 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4944 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004945 else
4946 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004947 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004948 }
4949 }
4950
4951link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004952 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004953 e1000e_update_stats(adapter);
4954
4955 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4956 adapter->tpt_old = adapter->stats.tpt;
4957 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4958 adapter->colc_old = adapter->stats.colc;
4959
Bruce Allan7c257692008-04-23 11:09:00 -07004960 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4961 adapter->gorc_old = adapter->stats.gorc;
4962 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4963 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004964 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004965
Bruce Allan12d43f72012-12-05 06:26:14 +00004966 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004967 schedule_work(&adapter->reset_task);
4968 /* return immediately since reset is imminent */
4969 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970 }
4971
Bruce Allan12d43f72012-12-05 06:26:14 +00004972 e1000e_update_adaptive(&adapter->hw);
4973
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004974 /* Simple mode for Interrupt Throttle Rate (ITR) */
4975 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004976 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004977 * Total asymmetrical Tx or Rx gets ITR=8000;
4978 * everyone else is between 2000-8000.
4979 */
4980 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4981 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00004982 adapter->gotc - adapter->gorc :
4983 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004984 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4985
Matthew Vick22a4cca2012-07-12 00:02:42 +00004986 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004987 }
4988
Bruce Allanad680762008-03-28 09:15:03 -07004989 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004990 if (adapter->msix_entries)
4991 ew32(ICS, adapter->rx_ring->ims_val);
4992 else
4993 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004995 /* flush pending descriptors to memory before detecting Tx hang */
4996 e1000e_flush_descriptors(adapter);
4997
Auke Kokbc7f75f2007-09-17 12:30:59 -07004998 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004999 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000
Bruce Allane921eb12012-11-28 09:28:37 +00005001 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005002 * reset from the other port. Set the appropriate LAA in RAR[0]
5003 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005005 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005006
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005007 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5008 e1000e_check_82574_phy_workaround(adapter);
5009
Bruce Allanb67e1912012-12-27 08:32:33 +00005010 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5011 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5012 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5013 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5014 er32(RXSTMPH);
5015 adapter->rx_hwtstamp_cleared++;
5016 } else {
5017 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5018 }
5019 }
5020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 /* Reset the timer */
5022 if (!test_bit(__E1000_DOWN, &adapter->state))
5023 mod_timer(&adapter->watchdog_timer,
5024 round_jiffies(jiffies + 2 * HZ));
5025}
5026
5027#define E1000_TX_FLAGS_CSUM 0x00000001
5028#define E1000_TX_FLAGS_VLAN 0x00000002
5029#define E1000_TX_FLAGS_TSO 0x00000004
5030#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005031#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005032#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005033#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5034#define E1000_TX_FLAGS_VLAN_SHIFT 16
5035
Bruce Allan55aa6982011-12-16 00:45:45 +00005036static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005038 struct e1000_context_desc *context_desc;
5039 struct e1000_buffer *buffer_info;
5040 unsigned int i;
5041 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005042 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005044
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005045 if (!skb_is_gso(skb))
5046 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005047
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005048 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005049 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5050
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005051 if (err)
5052 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005053 }
5054
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005055 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5056 mss = skb_shinfo(skb)->gso_size;
5057 if (skb->protocol == htons(ETH_P_IP)) {
5058 struct iphdr *iph = ip_hdr(skb);
5059 iph->tot_len = 0;
5060 iph->check = 0;
5061 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005062 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005063 cmd_length = E1000_TXD_CMD_IP;
5064 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005065 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005066 ipv6_hdr(skb)->payload_len = 0;
5067 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005068 &ipv6_hdr(skb)->daddr,
5069 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005070 ipcse = 0;
5071 }
5072 ipcss = skb_network_offset(skb);
5073 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5074 tucss = skb_transport_offset(skb);
5075 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005076
5077 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005078 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005079
5080 i = tx_ring->next_to_use;
5081 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5082 buffer_info = &tx_ring->buffer_info[i];
5083
5084 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5085 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5086 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5087 context_desc->upper_setup.tcp_fields.tucss = tucss;
5088 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005089 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005090 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5091 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5092 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5093
5094 buffer_info->time_stamp = jiffies;
5095 buffer_info->next_to_watch = i;
5096
5097 i++;
5098 if (i == tx_ring->count)
5099 i = 0;
5100 tx_ring->next_to_use = i;
5101
5102 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005103}
5104
Bruce Allan55aa6982011-12-16 00:45:45 +00005105static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005106{
Bruce Allan55aa6982011-12-16 00:45:45 +00005107 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005108 struct e1000_context_desc *context_desc;
5109 struct e1000_buffer *buffer_info;
5110 unsigned int i;
5111 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005112 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005113 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005114
Dave Grahamaf807c82008-10-09 14:28:58 -07005115 if (skb->ip_summed != CHECKSUM_PARTIAL)
5116 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005117
Arthur Jones5f66f202009-03-19 01:13:08 +00005118 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5119 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5120 else
5121 protocol = skb->protocol;
5122
Arthur Jones3f518392009-03-20 15:56:35 -07005123 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005124 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005125 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5126 cmd_len |= E1000_TXD_CMD_TCP;
5127 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005128 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005129 /* XXX not handling all IPV6 headers */
5130 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5131 cmd_len |= E1000_TXD_CMD_TCP;
5132 break;
5133 default:
5134 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005135 e_warn("checksum_partial proto=%x!\n",
5136 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005137 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005138 }
5139
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005140 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005141
5142 i = tx_ring->next_to_use;
5143 buffer_info = &tx_ring->buffer_info[i];
5144 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5145
5146 context_desc->lower_setup.ip_config = 0;
5147 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005148 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005149 context_desc->upper_setup.tcp_fields.tucse = 0;
5150 context_desc->tcp_seg_setup.data = 0;
5151 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5152
5153 buffer_info->time_stamp = jiffies;
5154 buffer_info->next_to_watch = i;
5155
5156 i++;
5157 if (i == tx_ring->count)
5158 i = 0;
5159 tx_ring->next_to_use = i;
5160
5161 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005162}
5163
Bruce Allan55aa6982011-12-16 00:45:45 +00005164static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5165 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005166 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167{
Bruce Allan55aa6982011-12-16 00:45:45 +00005168 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005169 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005170 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005171 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005172 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005173 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005174
5175 i = tx_ring->next_to_use;
5176
5177 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005178 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005179 size = min(len, max_per_txd);
5180
Auke Kokbc7f75f2007-09-17 12:30:59 -07005181 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005182 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005183 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005184 buffer_info->dma = dma_map_single(&pdev->dev,
5185 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005186 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005187 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005188 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005189 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005190
5191 len -= size;
5192 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005193 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005194
5195 if (len) {
5196 i++;
5197 if (i == tx_ring->count)
5198 i = 0;
5199 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005200 }
5201
5202 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005203 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005204
5205 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005206 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005207 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005208
5209 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005210 i++;
5211 if (i == tx_ring->count)
5212 i = 0;
5213
Auke Kokbc7f75f2007-09-17 12:30:59 -07005214 buffer_info = &tx_ring->buffer_info[i];
5215 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005216
5217 buffer_info->length = size;
5218 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005219 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005220 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005221 offset, size,
5222 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005223 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005224 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005225 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005226
5227 len -= size;
5228 offset += size;
5229 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005230 }
5231 }
5232
Bruce Allanaf667a22010-12-31 06:10:01 +00005233 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005234 /* multiply data chunks by size of headers */
5235 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5236
Auke Kokbc7f75f2007-09-17 12:30:59 -07005237 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005238 tx_ring->buffer_info[i].segs = segs;
5239 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005240 tx_ring->buffer_info[first].next_to_watch = i;
5241
5242 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005243
5244dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005245 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005246 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005247 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005248 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005249
5250 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005251 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005252 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005253 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005254 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005255 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005256 }
5257
5258 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005259}
5260
Bruce Allan55aa6982011-12-16 00:45:45 +00005261static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005262{
Bruce Allan55aa6982011-12-16 00:45:45 +00005263 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005264 struct e1000_tx_desc *tx_desc = NULL;
5265 struct e1000_buffer *buffer_info;
5266 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5267 unsigned int i;
5268
5269 if (tx_flags & E1000_TX_FLAGS_TSO) {
5270 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005271 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005272 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5273
5274 if (tx_flags & E1000_TX_FLAGS_IPV4)
5275 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5276 }
5277
5278 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5279 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5280 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5281 }
5282
5283 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5284 txd_lower |= E1000_TXD_CMD_VLE;
5285 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5286 }
5287
Ben Greear943146d2012-02-11 15:39:40 +00005288 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5289 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5290
Bruce Allanb67e1912012-12-27 08:32:33 +00005291 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5292 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5293 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5294 }
5295
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 i = tx_ring->next_to_use;
5297
Bruce Allan36b973d2010-11-24 07:42:43 +00005298 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005299 buffer_info = &tx_ring->buffer_info[i];
5300 tx_desc = E1000_TX_DESC(*tx_ring, i);
5301 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005302 tx_desc->lower.data = cpu_to_le32(txd_lower |
5303 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005304 tx_desc->upper.data = cpu_to_le32(txd_upper);
5305
5306 i++;
5307 if (i == tx_ring->count)
5308 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005309 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005310
5311 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5312
Ben Greear943146d2012-02-11 15:39:40 +00005313 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5314 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5315 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5316
Bruce Allane921eb12012-11-28 09:28:37 +00005317 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005318 * know there are new descriptors to fetch. (Only
5319 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005320 * such as IA-64).
5321 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005322 wmb();
5323
5324 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005325
5326 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005327 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005328 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005329 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005330
Bruce Allane921eb12012-11-28 09:28:37 +00005331 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005332 * at a time, it synchronizes IO on IA64/Altix systems
5333 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005334 mmiowb();
5335}
5336
5337#define MINIMUM_DHCP_PACKET_SIZE 282
5338static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5339 struct sk_buff *skb)
5340{
5341 struct e1000_hw *hw = &adapter->hw;
5342 u16 length, offset;
5343
Bruce Alland60923c2012-12-05 06:26:56 +00005344 if (vlan_tx_tag_present(skb) &&
5345 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5346 (adapter->hw.mng_cookie.status &
5347 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5348 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005349
5350 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5351 return 0;
5352
Bruce Allan53aa82d2013-02-20 04:06:06 +00005353 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005354 return 0;
5355
5356 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005357 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005358 struct udphdr *udp;
5359
5360 if (ip->protocol != IPPROTO_UDP)
5361 return 0;
5362
5363 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5364 if (ntohs(udp->dest) != 67)
5365 return 0;
5366
5367 offset = (u8 *)udp + 8 - skb->data;
5368 length = skb->len - offset;
5369 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5370 }
5371
5372 return 0;
5373}
5374
Bruce Allan55aa6982011-12-16 00:45:45 +00005375static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005376{
Bruce Allan55aa6982011-12-16 00:45:45 +00005377 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005378
Bruce Allan55aa6982011-12-16 00:45:45 +00005379 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005380 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005381 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005382 * but since that doesn't exist yet, just open code it.
5383 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005384 smp_mb();
5385
Bruce Allane921eb12012-11-28 09:28:37 +00005386 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005387 * made room available.
5388 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005389 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005390 return -EBUSY;
5391
5392 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005393 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005394 ++adapter->restart_queue;
5395 return 0;
5396}
5397
Bruce Allan55aa6982011-12-16 00:45:45 +00005398static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005399{
Bruce Alland821a4c2012-08-24 20:38:11 +00005400 BUG_ON(size > tx_ring->count);
5401
Bruce Allan55aa6982011-12-16 00:45:45 +00005402 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005403 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005404 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005405}
5406
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005407static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5408 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005409{
5410 struct e1000_adapter *adapter = netdev_priv(netdev);
5411 struct e1000_ring *tx_ring = adapter->tx_ring;
5412 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005413 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005414 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005415 unsigned int nr_frags;
5416 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005417 int count = 0;
5418 int tso;
5419 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005420
5421 if (test_bit(__E1000_DOWN, &adapter->state)) {
5422 dev_kfree_skb_any(skb);
5423 return NETDEV_TX_OK;
5424 }
5425
5426 if (skb->len <= 0) {
5427 dev_kfree_skb_any(skb);
5428 return NETDEV_TX_OK;
5429 }
5430
Bruce Allane921eb12012-11-28 09:28:37 +00005431 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005432 * pad skb in order to meet this minimum size requirement
5433 */
5434 if (unlikely(skb->len < 17)) {
5435 if (skb_pad(skb, 17 - skb->len))
5436 return NETDEV_TX_OK;
5437 skb->len = 17;
5438 skb_set_tail_pointer(skb, 17);
5439 }
5440
Auke Kokbc7f75f2007-09-17 12:30:59 -07005441 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005442 if (mss) {
5443 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005444
Bruce Allane921eb12012-11-28 09:28:37 +00005445 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005446 * points to just header, pull a few bytes of payload from
5447 * frags into skb->data
5448 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005450 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005451 * avoiding it could save a lot of cycles
5452 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005453 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005454 unsigned int pull_size;
5455
Bruce Allana2a5b322012-01-31 06:37:17 +00005456 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005457 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005458 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005459 dev_kfree_skb_any(skb);
5460 return NETDEV_TX_OK;
5461 }
Eric Dumazete743d312010-04-14 15:59:40 -07005462 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005463 }
5464 }
5465
5466 /* reserve a descriptor for the offload context */
5467 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5468 count++;
5469 count++;
5470
Bruce Alland821a4c2012-08-24 20:38:11 +00005471 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005472
5473 nr_frags = skb_shinfo(skb)->nr_frags;
5474 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005475 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5476 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005477
5478 if (adapter->hw.mac.tx_pkt_filtering)
5479 e1000_transfer_dhcp_info(adapter, skb);
5480
Bruce Allane921eb12012-11-28 09:28:37 +00005481 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005482 * head, otherwise try next time
5483 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005484 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005485 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005486
Jesse Grosseab6d182010-10-20 13:56:03 +00005487 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005488 tx_flags |= E1000_TX_FLAGS_VLAN;
5489 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5490 }
5491
5492 first = tx_ring->next_to_use;
5493
Bruce Allan55aa6982011-12-16 00:45:45 +00005494 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005495 if (tso < 0) {
5496 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005497 return NETDEV_TX_OK;
5498 }
5499
5500 if (tso)
5501 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005502 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005503 tx_flags |= E1000_TX_FLAGS_CSUM;
5504
Bruce Allane921eb12012-11-28 09:28:37 +00005505 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005506 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005507 * no longer assume, we must.
5508 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005509 if (skb->protocol == htons(ETH_P_IP))
5510 tx_flags |= E1000_TX_FLAGS_IPV4;
5511
Ben Greear943146d2012-02-11 15:39:40 +00005512 if (unlikely(skb->no_fcs))
5513 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5514
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005515 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005516 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5517 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005518 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005519 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5520 !adapter->tx_hwtstamp_skb)) {
5521 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5522 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5523 adapter->tx_hwtstamp_skb = skb_get(skb);
5524 schedule_work(&adapter->tx_hwtstamp_work);
5525 } else {
5526 skb_tx_timestamp(skb);
5527 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005528
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005529 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005530 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005531 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005532 e1000_maybe_stop_tx(tx_ring,
5533 (MAX_SKB_FRAGS *
5534 DIV_ROUND_UP(PAGE_SIZE,
5535 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005536 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005537 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005538 tx_ring->buffer_info[first].time_stamp = 0;
5539 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005540 }
5541
Auke Kokbc7f75f2007-09-17 12:30:59 -07005542 return NETDEV_TX_OK;
5543}
5544
5545/**
5546 * e1000_tx_timeout - Respond to a Tx Hang
5547 * @netdev: network interface device structure
5548 **/
5549static void e1000_tx_timeout(struct net_device *netdev)
5550{
5551 struct e1000_adapter *adapter = netdev_priv(netdev);
5552
5553 /* Do the reset outside of interrupt context */
5554 adapter->tx_timeout_count++;
5555 schedule_work(&adapter->reset_task);
5556}
5557
5558static void e1000_reset_task(struct work_struct *work)
5559{
5560 struct e1000_adapter *adapter;
5561 adapter = container_of(work, struct e1000_adapter, reset_task);
5562
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005563 /* don't run the task if already down */
5564 if (test_bit(__E1000_DOWN, &adapter->state))
5565 return;
5566
Bruce Allan12d43f72012-12-05 06:26:14 +00005567 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005568 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005569 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005570 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005571 e1000e_reinit_locked(adapter);
5572}
5573
5574/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005575 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005576 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005577 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005578 *
5579 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005580 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005581struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005582 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005583{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005584 struct e1000_adapter *adapter = netdev_priv(netdev);
5585
5586 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5587 spin_lock(&adapter->stats64_lock);
5588 e1000e_update_stats(adapter);
5589 /* Fill out the OS statistics structure */
5590 stats->rx_bytes = adapter->stats.gorc;
5591 stats->rx_packets = adapter->stats.gprc;
5592 stats->tx_bytes = adapter->stats.gotc;
5593 stats->tx_packets = adapter->stats.gptc;
5594 stats->multicast = adapter->stats.mprc;
5595 stats->collisions = adapter->stats.colc;
5596
5597 /* Rx Errors */
5598
Bruce Allane921eb12012-11-28 09:28:37 +00005599 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005600 * our own version based on RUC and ROC
5601 */
5602 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005603 adapter->stats.crcerrs + adapter->stats.algnerrc +
5604 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5605 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005606 stats->rx_crc_errors = adapter->stats.crcerrs;
5607 stats->rx_frame_errors = adapter->stats.algnerrc;
5608 stats->rx_missed_errors = adapter->stats.mpc;
5609
5610 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005611 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005612 stats->tx_aborted_errors = adapter->stats.ecol;
5613 stats->tx_window_errors = adapter->stats.latecol;
5614 stats->tx_carrier_errors = adapter->stats.tncrs;
5615
5616 /* Tx Dropped needs to be maintained elsewhere */
5617
5618 spin_unlock(&adapter->stats64_lock);
5619 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005620}
5621
5622/**
5623 * e1000_change_mtu - Change the Maximum Transfer Unit
5624 * @netdev: network interface device structure
5625 * @new_mtu: new value for maximum frame size
5626 *
5627 * Returns 0 on success, negative on failure
5628 **/
5629static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5630{
5631 struct e1000_adapter *adapter = netdev_priv(netdev);
5632 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5633
Bruce Allan2adc55c2009-06-02 11:28:58 +00005634 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005635 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5636 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5637 e_err("Jumbo Frames not supported.\n");
5638 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005639 }
5640
Bruce Allan2adc55c2009-06-02 11:28:58 +00005641 /* Supported frame sizes */
5642 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5643 (max_frame > adapter->max_hw_frame_size)) {
5644 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005645 return -EINVAL;
5646 }
5647
Bruce Allan2fbe4522012-04-19 03:21:47 +00005648 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5649 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005650 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5651 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005652 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005653 return -EINVAL;
5654 }
5655
Auke Kokbc7f75f2007-09-17 12:30:59 -07005656 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005657 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005658 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005659 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005660 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5661 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005662 if (netif_running(netdev))
5663 e1000e_down(adapter);
5664
Bruce Allane921eb12012-11-28 09:28:37 +00005665 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005666 * means we reserve 2 more, this pushes us to allocate from the next
5667 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005668 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005669 * However with the new *_jumbo_rx* routines, jumbo receives will use
5670 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005671 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005672
Jesse Brandeburg99261462010-01-22 22:56:16 +00005673 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005674 adapter->rx_buffer_len = 2048;
5675 else
5676 adapter->rx_buffer_len = 4096;
5677
5678 /* adjust allocation if LPE protects us, and we aren't using SBP */
5679 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005680 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005681 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005682 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005683
Auke Kokbc7f75f2007-09-17 12:30:59 -07005684 if (netif_running(netdev))
5685 e1000e_up(adapter);
5686 else
5687 e1000e_reset(adapter);
5688
5689 clear_bit(__E1000_RESETTING, &adapter->state);
5690
5691 return 0;
5692}
5693
5694static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5695 int cmd)
5696{
5697 struct e1000_adapter *adapter = netdev_priv(netdev);
5698 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005699
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005700 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005701 return -EOPNOTSUPP;
5702
5703 switch (cmd) {
5704 case SIOCGMIIPHY:
5705 data->phy_id = adapter->hw.phy.addr;
5706 break;
5707 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005708 e1000_phy_read_status(adapter);
5709
Bruce Allan7c257692008-04-23 11:09:00 -07005710 switch (data->reg_num & 0x1F) {
5711 case MII_BMCR:
5712 data->val_out = adapter->phy_regs.bmcr;
5713 break;
5714 case MII_BMSR:
5715 data->val_out = adapter->phy_regs.bmsr;
5716 break;
5717 case MII_PHYSID1:
5718 data->val_out = (adapter->hw.phy.id >> 16);
5719 break;
5720 case MII_PHYSID2:
5721 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5722 break;
5723 case MII_ADVERTISE:
5724 data->val_out = adapter->phy_regs.advertise;
5725 break;
5726 case MII_LPA:
5727 data->val_out = adapter->phy_regs.lpa;
5728 break;
5729 case MII_EXPANSION:
5730 data->val_out = adapter->phy_regs.expansion;
5731 break;
5732 case MII_CTRL1000:
5733 data->val_out = adapter->phy_regs.ctrl1000;
5734 break;
5735 case MII_STAT1000:
5736 data->val_out = adapter->phy_regs.stat1000;
5737 break;
5738 case MII_ESTATUS:
5739 data->val_out = adapter->phy_regs.estatus;
5740 break;
5741 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005742 return -EIO;
5743 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005744 break;
5745 case SIOCSMIIREG:
5746 default:
5747 return -EOPNOTSUPP;
5748 }
5749 return 0;
5750}
5751
Bruce Allanb67e1912012-12-27 08:32:33 +00005752/**
5753 * e1000e_hwtstamp_ioctl - control hardware time stamping
5754 * @netdev: network interface device structure
5755 * @ifreq: interface request
5756 *
5757 * Outgoing time stamping can be enabled and disabled. Play nice and
5758 * disable it when requested, although it shouldn't cause any overhead
5759 * when no packet needs it. At most one packet in the queue may be
5760 * marked for time stamping, otherwise it would be impossible to tell
5761 * for sure to which packet the hardware time stamp belongs.
5762 *
5763 * Incoming time stamping has to be configured via the hardware filters.
5764 * Not all combinations are supported, in particular event type has to be
5765 * specified. Matching the kind of event packet is not supported, with the
5766 * exception of "all V2 events regardless of level 2 or 4".
5767 **/
5768static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5769{
5770 struct e1000_adapter *adapter = netdev_priv(netdev);
5771 struct hwtstamp_config config;
5772 int ret_val;
5773
5774 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5775 return -EFAULT;
5776
5777 adapter->hwtstamp_config = config;
5778
5779 ret_val = e1000e_config_hwtstamp(adapter);
5780 if (ret_val)
5781 return ret_val;
5782
5783 config = adapter->hwtstamp_config;
5784
Bruce Alland89777b2013-01-19 01:09:58 +00005785 switch (config.rx_filter) {
5786 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5787 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5788 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5789 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5790 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5791 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5792 /* With V2 type filters which specify a Sync or Delay Request,
5793 * Path Delay Request/Response messages are also time stamped
5794 * by hardware so notify the caller the requested packets plus
5795 * some others are time stamped.
5796 */
5797 config.rx_filter = HWTSTAMP_FILTER_SOME;
5798 break;
5799 default:
5800 break;
5801 }
5802
Bruce Allanb67e1912012-12-27 08:32:33 +00005803 return copy_to_user(ifr->ifr_data, &config,
5804 sizeof(config)) ? -EFAULT : 0;
5805}
5806
Auke Kokbc7f75f2007-09-17 12:30:59 -07005807static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5808{
5809 switch (cmd) {
5810 case SIOCGMIIPHY:
5811 case SIOCGMIIREG:
5812 case SIOCSMIIREG:
5813 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005814 case SIOCSHWTSTAMP:
5815 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005816 default:
5817 return -EOPNOTSUPP;
5818 }
5819}
5820
Bruce Allana4f58f52009-06-02 11:29:18 +00005821static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5822{
5823 struct e1000_hw *hw = &adapter->hw;
5824 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005825 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005826 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005827
5828 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005829 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005830
Bruce Allan2b6b1682011-05-13 07:20:09 +00005831 retval = hw->phy.ops.acquire(hw);
5832 if (retval) {
5833 e_err("Could not acquire PHY\n");
5834 return retval;
5835 }
5836
5837 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5838 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5839 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005840 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005841
5842 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005843 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5844 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005845 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5846 (u16)(mac_reg & 0xFFFF));
5847 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5848 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005849 }
5850
5851 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005852 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005853 mac_reg = er32(RCTL);
5854 if (mac_reg & E1000_RCTL_UPE)
5855 phy_reg |= BM_RCTL_UPE;
5856 if (mac_reg & E1000_RCTL_MPE)
5857 phy_reg |= BM_RCTL_MPE;
5858 phy_reg &= ~(BM_RCTL_MO_MASK);
5859 if (mac_reg & E1000_RCTL_MO_3)
5860 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005861 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005862 if (mac_reg & E1000_RCTL_BAM)
5863 phy_reg |= BM_RCTL_BAM;
5864 if (mac_reg & E1000_RCTL_PMCF)
5865 phy_reg |= BM_RCTL_PMCF;
5866 mac_reg = er32(CTRL);
5867 if (mac_reg & E1000_CTRL_RFCE)
5868 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005869 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005870
5871 /* enable PHY wakeup in MAC register */
5872 ew32(WUFC, wufc);
5873 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5874
5875 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005876 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5877 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005878
5879 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005880 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5881 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005882 if (retval)
5883 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005884release:
Bruce Allan94d81862009-11-20 23:25:26 +00005885 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005886
5887 return retval;
5888}
5889
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005890static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5891 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005892{
5893 struct net_device *netdev = pci_get_drvdata(pdev);
5894 struct e1000_adapter *adapter = netdev_priv(netdev);
5895 struct e1000_hw *hw = &adapter->hw;
5896 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005897 /* Runtime suspend should only enable wakeup for link changes */
5898 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005899 int retval = 0;
5900
5901 netif_device_detach(netdev);
5902
5903 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005904 int count = E1000_CHECK_RESET_COUNT;
5905
5906 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5907 usleep_range(10000, 20000);
5908
Auke Kokbc7f75f2007-09-17 12:30:59 -07005909 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5910 e1000e_down(adapter);
5911 e1000_free_irq(adapter);
5912 }
Bruce Allan4662e822008-08-26 18:37:06 -07005913 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005914
5915 retval = pci_save_state(pdev);
5916 if (retval)
5917 return retval;
5918
5919 status = er32(STATUS);
5920 if (status & E1000_STATUS_LU)
5921 wufc &= ~E1000_WUFC_LNKC;
5922
5923 if (wufc) {
5924 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005925 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005926
5927 /* turn on all-multi mode if wake on multicast is enabled */
5928 if (wufc & E1000_WUFC_MC) {
5929 rctl = er32(RCTL);
5930 rctl |= E1000_RCTL_MPE;
5931 ew32(RCTL, rctl);
5932 }
5933
5934 ctrl = er32(CTRL);
5935 /* advertise wake from D3Cold */
5936 #define E1000_CTRL_ADVD3WUC 0x00100000
5937 /* phy power management enable */
5938 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005939 ctrl |= E1000_CTRL_ADVD3WUC;
5940 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5941 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005942 ew32(CTRL, ctrl);
5943
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005944 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5945 adapter->hw.phy.media_type ==
5946 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005947 /* keep the laser running in D3 */
5948 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005949 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005950 ew32(CTRL_EXT, ctrl_ext);
5951 }
5952
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005953 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005954 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005955
Auke Kokbc7f75f2007-09-17 12:30:59 -07005956 /* Allow time for pending master requests to run */
5957 e1000e_disable_pcie_master(&adapter->hw);
5958
Bruce Allan82776a42009-08-14 14:35:33 +00005959 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005960 /* enable wakeup by the PHY */
5961 retval = e1000_init_phy_wakeup(adapter, wufc);
5962 if (retval)
5963 return retval;
5964 } else {
5965 /* enable wakeup by the MAC */
5966 ew32(WUFC, wufc);
5967 ew32(WUC, E1000_WUC_PME_EN);
5968 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005969 } else {
5970 ew32(WUC, 0);
5971 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972 }
5973
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005974 *enable_wake = !!wufc;
5975
Auke Kokbc7f75f2007-09-17 12:30:59 -07005976 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005977 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5978 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005979 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980
5981 if (adapter->hw.phy.type == e1000_phy_igp_3)
5982 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5983
Bruce Allane921eb12012-11-28 09:28:37 +00005984 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005985 * would have already happened in close and is redundant.
5986 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005987 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005988
5989 pci_disable_device(pdev);
5990
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005991 return 0;
5992}
5993
5994static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5995{
5996 if (sleep && wake) {
5997 pci_prepare_to_sleep(pdev);
5998 return;
5999 }
6000
6001 pci_wake_from_d3(pdev, wake);
6002 pci_set_power_state(pdev, PCI_D3hot);
6003}
6004
Bruce Allanf0ff4392013-02-20 04:05:39 +00006005static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, bool wake)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006006{
6007 struct net_device *netdev = pci_get_drvdata(pdev);
6008 struct e1000_adapter *adapter = netdev_priv(netdev);
6009
Bruce Allane921eb12012-11-28 09:28:37 +00006010 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006011 * correctable error when the MAC transitions from D0 to D3. To
6012 * prevent this we need to mask off the correctable errors on the
6013 * downstream port of the pci-e switch.
6014 */
6015 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6016 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006017 u16 devctl;
6018
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006019 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6020 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6021 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006022
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006023 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006024
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006025 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006026 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006027 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006028 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006029}
6030
Bruce Allan6f461f62010-04-27 03:33:04 +00006031#ifdef CONFIG_PCIEASPM
6032static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6033{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006034 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006035}
6036#else
6037static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006038{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006039 u16 aspm_ctl = 0;
6040
6041 if (state & PCIE_LINK_STATE_L0S)
6042 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6043 if (state & PCIE_LINK_STATE_L1)
6044 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6045
Bruce Allane921eb12012-11-28 09:28:37 +00006046 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006047 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006048 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006049 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006050
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006051 if (pdev->bus->self)
6052 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006053 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006054}
6055#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006056static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006057{
6058 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6059 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6060 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6061
6062 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006063}
6064
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006065#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006066static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006067{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006068 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006069}
6070
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006071static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006072{
6073 struct net_device *netdev = pci_get_drvdata(pdev);
6074 struct e1000_adapter *adapter = netdev_priv(netdev);
6075 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006076 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006077 u32 err;
6078
Bruce Allan78cd29d2011-03-24 03:09:03 +00006079 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6080 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6081 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6082 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6083 if (aspm_disable_flag)
6084 e1000e_disable_aspm(pdev, aspm_disable_flag);
6085
Auke Kokbc7f75f2007-09-17 12:30:59 -07006086 pci_set_power_state(pdev, PCI_D0);
6087 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006088 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006089
Bruce Allan4662e822008-08-26 18:37:06 -07006090 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006091 if (netif_running(netdev)) {
6092 err = e1000_request_irq(adapter);
6093 if (err)
6094 return err;
6095 }
6096
Bruce Allan2fbe4522012-04-19 03:21:47 +00006097 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006098 e1000_resume_workarounds_pchlan(&adapter->hw);
6099
Auke Kokbc7f75f2007-09-17 12:30:59 -07006100 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006101
6102 /* report the system wakeup cause from S3/S4 */
6103 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6104 u16 phy_data;
6105
6106 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6107 if (phy_data) {
6108 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006109 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6110 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6111 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6112 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6113 phy_data & E1000_WUS_LNKC ?
6114 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006115 }
6116 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6117 } else {
6118 u32 wus = er32(WUS);
6119 if (wus) {
6120 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006121 wus & E1000_WUS_EX ? "Unicast Packet" :
6122 wus & E1000_WUS_MC ? "Multicast Packet" :
6123 wus & E1000_WUS_BC ? "Broadcast Packet" :
6124 wus & E1000_WUS_MAG ? "Magic Packet" :
6125 wus & E1000_WUS_LNKC ? "Link Status Change" :
6126 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006127 }
6128 ew32(WUS, ~0);
6129 }
6130
Auke Kokbc7f75f2007-09-17 12:30:59 -07006131 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006132
Bruce Allancd791612010-05-10 14:59:51 +00006133 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006134
6135 if (netif_running(netdev))
6136 e1000e_up(adapter);
6137
6138 netif_device_attach(netdev);
6139
Bruce Allane921eb12012-11-28 09:28:37 +00006140 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006141 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006142 * under the control of the driver.
6143 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006144 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006145 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006146
6147 return 0;
6148}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006149
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006150#ifdef CONFIG_PM_SLEEP
6151static int e1000_suspend(struct device *dev)
6152{
6153 struct pci_dev *pdev = to_pci_dev(dev);
6154 int retval;
6155 bool wake;
6156
6157 retval = __e1000_shutdown(pdev, &wake, false);
6158 if (!retval)
6159 e1000_complete_shutdown(pdev, true, wake);
6160
6161 return retval;
6162}
6163
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006164static int e1000_resume(struct device *dev)
6165{
6166 struct pci_dev *pdev = to_pci_dev(dev);
6167 struct net_device *netdev = pci_get_drvdata(pdev);
6168 struct e1000_adapter *adapter = netdev_priv(netdev);
6169
6170 if (e1000e_pm_ready(adapter))
6171 adapter->idle_check = true;
6172
6173 return __e1000_resume(pdev);
6174}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006175#endif /* CONFIG_PM_SLEEP */
6176
6177#ifdef CONFIG_PM_RUNTIME
6178static int e1000_runtime_suspend(struct device *dev)
6179{
6180 struct pci_dev *pdev = to_pci_dev(dev);
6181 struct net_device *netdev = pci_get_drvdata(pdev);
6182 struct e1000_adapter *adapter = netdev_priv(netdev);
6183
6184 if (e1000e_pm_ready(adapter)) {
6185 bool wake;
6186
6187 __e1000_shutdown(pdev, &wake, true);
6188 }
6189
6190 return 0;
6191}
6192
6193static int e1000_idle(struct device *dev)
6194{
6195 struct pci_dev *pdev = to_pci_dev(dev);
6196 struct net_device *netdev = pci_get_drvdata(pdev);
6197 struct e1000_adapter *adapter = netdev_priv(netdev);
6198
6199 if (!e1000e_pm_ready(adapter))
6200 return 0;
6201
6202 if (adapter->idle_check) {
6203 adapter->idle_check = false;
6204 if (!e1000e_has_link(adapter))
6205 pm_schedule_suspend(dev, MSEC_PER_SEC);
6206 }
6207
6208 return -EBUSY;
6209}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006210
6211static int e1000_runtime_resume(struct device *dev)
6212{
6213 struct pci_dev *pdev = to_pci_dev(dev);
6214 struct net_device *netdev = pci_get_drvdata(pdev);
6215 struct e1000_adapter *adapter = netdev_priv(netdev);
6216
6217 if (!e1000e_pm_ready(adapter))
6218 return 0;
6219
6220 adapter->idle_check = !dev->power.runtime_auto;
6221 return __e1000_resume(pdev);
6222}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006223#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006224#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006225
6226static void e1000_shutdown(struct pci_dev *pdev)
6227{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006228 bool wake = false;
6229
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006230 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006231
6232 if (system_state == SYSTEM_POWER_OFF)
6233 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006234}
6235
6236#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006237
Bruce Allan8bb62862013-01-16 08:46:49 +00006238static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006239{
6240 struct net_device *netdev = data;
6241 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006242
6243 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006244 int vector, msix_irq;
6245
Dongdong Deng147b2c82010-11-16 19:50:15 -08006246 vector = 0;
6247 msix_irq = adapter->msix_entries[vector].vector;
6248 disable_irq(msix_irq);
6249 e1000_intr_msix_rx(msix_irq, netdev);
6250 enable_irq(msix_irq);
6251
6252 vector++;
6253 msix_irq = adapter->msix_entries[vector].vector;
6254 disable_irq(msix_irq);
6255 e1000_intr_msix_tx(msix_irq, netdev);
6256 enable_irq(msix_irq);
6257
6258 vector++;
6259 msix_irq = adapter->msix_entries[vector].vector;
6260 disable_irq(msix_irq);
6261 e1000_msix_other(msix_irq, netdev);
6262 enable_irq(msix_irq);
6263 }
6264
6265 return IRQ_HANDLED;
6266}
6267
Bruce Allane921eb12012-11-28 09:28:37 +00006268/**
6269 * e1000_netpoll
6270 * @netdev: network interface device structure
6271 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006272 * Polling 'interrupt' - used by things like netconsole to send skbs
6273 * without having to re-enable interrupts. It's not called while
6274 * the interrupt routine is executing.
6275 */
6276static void e1000_netpoll(struct net_device *netdev)
6277{
6278 struct e1000_adapter *adapter = netdev_priv(netdev);
6279
Dongdong Deng147b2c82010-11-16 19:50:15 -08006280 switch (adapter->int_mode) {
6281 case E1000E_INT_MODE_MSIX:
6282 e1000_intr_msix(adapter->pdev->irq, netdev);
6283 break;
6284 case E1000E_INT_MODE_MSI:
6285 disable_irq(adapter->pdev->irq);
6286 e1000_intr_msi(adapter->pdev->irq, netdev);
6287 enable_irq(adapter->pdev->irq);
6288 break;
6289 default: /* E1000E_INT_MODE_LEGACY */
6290 disable_irq(adapter->pdev->irq);
6291 e1000_intr(adapter->pdev->irq, netdev);
6292 enable_irq(adapter->pdev->irq);
6293 break;
6294 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006295}
6296#endif
6297
6298/**
6299 * e1000_io_error_detected - called when PCI error is detected
6300 * @pdev: Pointer to PCI device
6301 * @state: The current pci connection state
6302 *
6303 * This function is called after a PCI bus error affecting
6304 * this device has been detected.
6305 */
6306static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6307 pci_channel_state_t state)
6308{
6309 struct net_device *netdev = pci_get_drvdata(pdev);
6310 struct e1000_adapter *adapter = netdev_priv(netdev);
6311
6312 netif_device_detach(netdev);
6313
Mike Masonc93b5a72009-06-30 12:45:53 +00006314 if (state == pci_channel_io_perm_failure)
6315 return PCI_ERS_RESULT_DISCONNECT;
6316
Auke Kokbc7f75f2007-09-17 12:30:59 -07006317 if (netif_running(netdev))
6318 e1000e_down(adapter);
6319 pci_disable_device(pdev);
6320
6321 /* Request a slot slot reset. */
6322 return PCI_ERS_RESULT_NEED_RESET;
6323}
6324
6325/**
6326 * e1000_io_slot_reset - called after the pci bus has been reset.
6327 * @pdev: Pointer to PCI device
6328 *
6329 * Restart the card from scratch, as if from a cold-boot. Implementation
6330 * resembles the first-half of the e1000_resume routine.
6331 */
6332static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6333{
6334 struct net_device *netdev = pci_get_drvdata(pdev);
6335 struct e1000_adapter *adapter = netdev_priv(netdev);
6336 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006337 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006338 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006339 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006340
Bruce Allan78cd29d2011-03-24 03:09:03 +00006341 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6342 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006343 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006344 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6345 if (aspm_disable_flag)
6346 e1000e_disable_aspm(pdev, aspm_disable_flag);
6347
Bruce Allanf0f422e2008-08-04 17:21:53 -07006348 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006349 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006350 dev_err(&pdev->dev,
6351 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006352 result = PCI_ERS_RESULT_DISCONNECT;
6353 } else {
6354 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006355 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006356 pci_restore_state(pdev);
6357
6358 pci_enable_wake(pdev, PCI_D3hot, 0);
6359 pci_enable_wake(pdev, PCI_D3cold, 0);
6360
6361 e1000e_reset(adapter);
6362 ew32(WUS, ~0);
6363 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006365
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006366 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006367
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006368 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006369}
6370
6371/**
6372 * e1000_io_resume - called when traffic can start flowing again.
6373 * @pdev: Pointer to PCI device
6374 *
6375 * This callback is called when the error recovery driver tells us that
6376 * its OK to resume normal operation. Implementation resembles the
6377 * second-half of the e1000_resume routine.
6378 */
6379static void e1000_io_resume(struct pci_dev *pdev)
6380{
6381 struct net_device *netdev = pci_get_drvdata(pdev);
6382 struct e1000_adapter *adapter = netdev_priv(netdev);
6383
Bruce Allancd791612010-05-10 14:59:51 +00006384 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006385
6386 if (netif_running(netdev)) {
6387 if (e1000e_up(adapter)) {
6388 dev_err(&pdev->dev,
6389 "can't bring device back up after reset\n");
6390 return;
6391 }
6392 }
6393
6394 netif_device_attach(netdev);
6395
Bruce Allane921eb12012-11-28 09:28:37 +00006396 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006397 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006398 * under the control of the driver.
6399 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006400 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006401 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006402}
6403
6404static void e1000_print_device_info(struct e1000_adapter *adapter)
6405{
6406 struct e1000_hw *hw = &adapter->hw;
6407 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006408 u32 ret_val;
6409 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006410
6411 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006412 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006413 /* bus width */
6414 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006415 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006416 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006417 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006418 e_info("Intel(R) PRO/%s Network Connection\n",
6419 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006420 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6421 E1000_PBANUM_LENGTH);
6422 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006423 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006424 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6425 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006426}
6427
Auke Kok10aa4c02008-08-04 17:21:20 -07006428static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6429{
6430 struct e1000_hw *hw = &adapter->hw;
6431 int ret_val;
6432 u16 buf = 0;
6433
6434 if (hw->mac.type != e1000_82573)
6435 return;
6436
6437 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006438 le16_to_cpus(&buf);
6439 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006440 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006441 dev_warn(&adapter->pdev->dev,
6442 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006443 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006444}
6445
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006446static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006447 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006448{
6449 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006450 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006451
6452 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6453 adapter->flags |= FLAG_TSO_FORCE;
6454
6455 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006456 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6457 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006458 return 0;
6459
Ben Greear01840392012-02-11 15:39:25 +00006460 if (changed & NETIF_F_RXFCS) {
6461 if (features & NETIF_F_RXFCS) {
6462 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6463 } else {
6464 /* We need to take it back to defaults, which might mean
6465 * stripping is still disabled at the adapter level.
6466 */
6467 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6468 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6469 else
6470 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6471 }
6472 }
6473
Bruce Allan70495a52012-01-11 01:26:50 +00006474 netdev->features = features;
6475
Bruce Allandc221292011-08-19 03:23:48 +00006476 if (netif_running(netdev))
6477 e1000e_reinit_locked(adapter);
6478 else
6479 e1000e_reset(adapter);
6480
6481 return 0;
6482}
6483
Stephen Hemminger651c2462008-11-19 21:57:48 -08006484static const struct net_device_ops e1000e_netdev_ops = {
6485 .ndo_open = e1000_open,
6486 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006487 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006488 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006489 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006490 .ndo_set_mac_address = e1000_set_mac,
6491 .ndo_change_mtu = e1000_change_mtu,
6492 .ndo_do_ioctl = e1000_ioctl,
6493 .ndo_tx_timeout = e1000_tx_timeout,
6494 .ndo_validate_addr = eth_validate_addr,
6495
Stephen Hemminger651c2462008-11-19 21:57:48 -08006496 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6497 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6498#ifdef CONFIG_NET_POLL_CONTROLLER
6499 .ndo_poll_controller = e1000_netpoll,
6500#endif
Bruce Allandc221292011-08-19 03:23:48 +00006501 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006502};
6503
Auke Kokbc7f75f2007-09-17 12:30:59 -07006504/**
6505 * e1000_probe - Device Initialization Routine
6506 * @pdev: PCI device information struct
6507 * @ent: entry in e1000_pci_tbl
6508 *
6509 * Returns 0 on success, negative on failure
6510 *
6511 * e1000_probe initializes an adapter identified by a pci_dev structure.
6512 * The OS initialization, configuring of the adapter private structure,
6513 * and a hardware reset occur.
6514 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006515static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006516{
6517 struct net_device *netdev;
6518 struct e1000_adapter *adapter;
6519 struct e1000_hw *hw;
6520 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006521 resource_size_t mmio_start, mmio_len;
6522 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006523 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006524 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006525 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006526 u16 eeprom_data = 0;
6527 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6528
Bruce Allan78cd29d2011-03-24 03:09:03 +00006529 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6530 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006531 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006532 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6533 if (aspm_disable_flag)
6534 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006535
Bruce Allanf0f422e2008-08-04 17:21:53 -07006536 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006537 if (err)
6538 return err;
6539
6540 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006541 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006542 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006543 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006544 if (!err)
6545 pci_using_dac = 1;
6546 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006547 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006548 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006549 err = dma_set_coherent_mask(&pdev->dev,
6550 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006551 if (err) {
Bruce Allanf0ff4392013-02-20 04:05:39 +00006552 dev_err(&pdev->dev,
6553 "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006554 goto err_dma;
6555 }
6556 }
6557 }
6558
Bruce Allan17e813e2013-02-20 04:06:01 +00006559 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6560 err = pci_request_selected_regions_exclusive(pdev, bars,
6561 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006562 if (err)
6563 goto err_pci_reg;
6564
Xiaotian Feng68eac462009-08-14 14:35:52 +00006565 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006566 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006567
Auke Kokbc7f75f2007-09-17 12:30:59 -07006568 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006569 /* PCI config space info */
6570 err = pci_save_state(pdev);
6571 if (err)
6572 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006573
6574 err = -ENOMEM;
6575 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6576 if (!netdev)
6577 goto err_alloc_etherdev;
6578
Auke Kokbc7f75f2007-09-17 12:30:59 -07006579 SET_NETDEV_DEV(netdev, &pdev->dev);
6580
Tom Herbertf85e4df2010-05-05 14:03:32 +00006581 netdev->irq = pdev->irq;
6582
Auke Kokbc7f75f2007-09-17 12:30:59 -07006583 pci_set_drvdata(pdev, netdev);
6584 adapter = netdev_priv(netdev);
6585 hw = &adapter->hw;
6586 adapter->netdev = netdev;
6587 adapter->pdev = pdev;
6588 adapter->ei = ei;
6589 adapter->pba = ei->pba;
6590 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006591 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006592 adapter->hw.adapter = adapter;
6593 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006594 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006595 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006596
6597 mmio_start = pci_resource_start(pdev, 0);
6598 mmio_len = pci_resource_len(pdev, 0);
6599
6600 err = -EIO;
6601 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6602 if (!adapter->hw.hw_addr)
6603 goto err_ioremap;
6604
6605 if ((adapter->flags & FLAG_HAS_FLASH) &&
6606 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6607 flash_start = pci_resource_start(pdev, 1);
6608 flash_len = pci_resource_len(pdev, 1);
6609 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6610 if (!adapter->hw.flash_address)
6611 goto err_flashmap;
6612 }
6613
6614 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006615 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006616 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006617 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006618 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006619 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006620
6621 netdev->mem_start = mmio_start;
6622 netdev->mem_end = mmio_start + mmio_len;
6623
6624 adapter->bd_number = cards_found++;
6625
Bruce Allan4662e822008-08-26 18:37:06 -07006626 e1000e_check_options(adapter);
6627
Auke Kokbc7f75f2007-09-17 12:30:59 -07006628 /* setup adapter struct */
6629 err = e1000_sw_init(adapter);
6630 if (err)
6631 goto err_sw_init;
6632
Auke Kokbc7f75f2007-09-17 12:30:59 -07006633 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6634 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6635 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6636
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006637 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006638 if (err)
6639 goto err_hw_init;
6640
Bruce Allan4a770352008-10-01 17:18:35 -07006641 if ((adapter->flags & FLAG_IS_ICH) &&
6642 (adapter->flags & FLAG_READ_ONLY_NVM))
6643 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6644
Auke Kokbc7f75f2007-09-17 12:30:59 -07006645 hw->mac.ops.get_bus_info(&adapter->hw);
6646
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006647 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006648
6649 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006650 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006651 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6652 adapter->hw.phy.disable_polarity_correction = 0;
6653 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6654 }
6655
Bruce Allan470a5422012-05-26 06:08:48 +00006656 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006657 dev_info(&pdev->dev,
6658 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006659
Bruce Allandc221292011-08-19 03:23:48 +00006660 /* Set initial default active device features */
6661 netdev->features = (NETIF_F_SG |
6662 NETIF_F_HW_VLAN_RX |
6663 NETIF_F_HW_VLAN_TX |
6664 NETIF_F_TSO |
6665 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006666 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006667 NETIF_F_RXCSUM |
6668 NETIF_F_HW_CSUM);
6669
6670 /* Set user-changeable features (subset of all device features) */
6671 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006672 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006673 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006674 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006675
6676 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6677 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6678
Bruce Allandc221292011-08-19 03:23:48 +00006679 netdev->vlan_features |= (NETIF_F_SG |
6680 NETIF_F_TSO |
6681 NETIF_F_TSO6 |
6682 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006683
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006684 netdev->priv_flags |= IFF_UNICAST_FLT;
6685
Yi Zou7b872a52010-09-22 17:57:58 +00006686 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006687 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006688 netdev->vlan_features |= NETIF_F_HIGHDMA;
6689 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006690
Auke Kokbc7f75f2007-09-17 12:30:59 -07006691 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6692 adapter->flags |= FLAG_MNG_PT_ENABLED;
6693
Bruce Allane921eb12012-11-28 09:28:37 +00006694 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006695 * put the device in a known good starting state
6696 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006697 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6698
Bruce Allane921eb12012-11-28 09:28:37 +00006699 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006700 * attempt. Let's give it a few tries
6701 */
6702 for (i = 0;; i++) {
6703 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6704 break;
6705 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006706 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 err = -EIO;
6708 goto err_eeprom;
6709 }
6710 }
6711
Auke Kok10aa4c02008-08-04 17:21:20 -07006712 e1000_eeprom_checks(adapter);
6713
Bruce Allan608f8a02010-01-13 02:04:58 +00006714 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006715 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006716 dev_err(&pdev->dev,
6717 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006718
6719 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006720
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006721 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006722 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006723 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006724 err = -EIO;
6725 goto err_eeprom;
6726 }
6727
6728 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006729 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006730 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006731
6732 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006733 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006734 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006735
6736 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6737 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006738 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6739 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006740 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006741
Auke Kokbc7f75f2007-09-17 12:30:59 -07006742 /* Initialize link parameters. User can change them with ethtool */
6743 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006744 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006745 adapter->hw.fc.requested_mode = e1000_fc_default;
6746 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006747 adapter->hw.phy.autoneg_advertised = 0x2f;
6748
6749 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006750 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6751 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006752
Bruce Allane921eb12012-11-28 09:28:37 +00006753 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006754 * the EEPROM, enable the ACPI Magic Packet filter
6755 */
6756 if (adapter->flags & FLAG_APME_IN_WUC) {
6757 /* APME bit in EEPROM is mapped to WUC.APME */
6758 eeprom_data = er32(WUC);
6759 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006760 if ((hw->mac.type > e1000_ich10lan) &&
6761 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006762 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006763 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6764 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6765 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006766 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6767 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006768 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006769 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6770 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006771 }
6772
6773 /* fetch WoL from EEPROM */
6774 if (eeprom_data & eeprom_apme_mask)
6775 adapter->eeprom_wol |= E1000_WUFC_MAG;
6776
Bruce Allane921eb12012-11-28 09:28:37 +00006777 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006778 * where the eeprom may be wrong or the board simply won't support
6779 * wake on lan on a particular port
6780 */
6781 if (!(adapter->flags & FLAG_HAS_WOL))
6782 adapter->eeprom_wol = 0;
6783
6784 /* initialize the wol settings based on the eeprom settings */
6785 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006786 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006787
Bruce Allan84527592008-11-21 17:00:22 -08006788 /* save off EEPROM version number */
6789 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6790
Auke Kokbc7f75f2007-09-17 12:30:59 -07006791 /* reset the hardware with the new settings */
6792 e1000e_reset(adapter);
6793
Bruce Allane921eb12012-11-28 09:28:37 +00006794 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006795 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006796 * under the control of the driver.
6797 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006798 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006799 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006800
Bruce Allanf2315bf2011-12-16 00:46:59 +00006801 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006802 err = register_netdev(netdev);
6803 if (err)
6804 goto err_register;
6805
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006806 /* carrier off reporting is important to ethtool even BEFORE open */
6807 netif_carrier_off(netdev);
6808
Bruce Alland89777b2013-01-19 01:09:58 +00006809 /* init PTP hardware clock */
6810 e1000e_ptp_init(adapter);
6811
Auke Kokbc7f75f2007-09-17 12:30:59 -07006812 e1000_print_device_info(adapter);
6813
Alan Sternf3ec4f82010-06-08 15:23:51 -04006814 if (pci_dev_run_wake(pdev))
6815 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006816
Auke Kokbc7f75f2007-09-17 12:30:59 -07006817 return 0;
6818
6819err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006820 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006821 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006822err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006823 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006824 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006825err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006826 kfree(adapter->tx_ring);
6827 kfree(adapter->rx_ring);
6828err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006829 if (adapter->hw.flash_address)
6830 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006831 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006832err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006833 iounmap(adapter->hw.hw_addr);
6834err_ioremap:
6835 free_netdev(netdev);
6836err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006837 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006838 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006839err_pci_reg:
6840err_dma:
6841 pci_disable_device(pdev);
6842 return err;
6843}
6844
6845/**
6846 * e1000_remove - Device Removal Routine
6847 * @pdev: PCI device information struct
6848 *
6849 * e1000_remove is called by the PCI subsystem to alert the driver
6850 * that it should release a PCI device. The could be caused by a
6851 * Hot-Plug event, or because the driver is going to be removed from
6852 * memory.
6853 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006854static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006855{
6856 struct net_device *netdev = pci_get_drvdata(pdev);
6857 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006858 bool down = test_bit(__E1000_DOWN, &adapter->state);
6859
Bruce Alland89777b2013-01-19 01:09:58 +00006860 e1000e_ptp_remove(adapter);
6861
Bruce Allane921eb12012-11-28 09:28:37 +00006862 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006863 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006864 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006865 if (!down)
6866 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006867 del_timer_sync(&adapter->watchdog_timer);
6868 del_timer_sync(&adapter->phy_info_timer);
6869
Bruce Allan41cec6f2009-11-20 23:28:56 +00006870 cancel_work_sync(&adapter->reset_task);
6871 cancel_work_sync(&adapter->watchdog_task);
6872 cancel_work_sync(&adapter->downshift_task);
6873 cancel_work_sync(&adapter->update_phy_task);
6874 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006875
Bruce Allanb67e1912012-12-27 08:32:33 +00006876 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6877 cancel_work_sync(&adapter->tx_hwtstamp_work);
6878 if (adapter->tx_hwtstamp_skb) {
6879 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6880 adapter->tx_hwtstamp_skb = NULL;
6881 }
6882 }
6883
Bruce Allan17f208d2009-12-01 15:47:22 +00006884 if (!(netdev->flags & IFF_UP))
6885 e1000_power_down_phy(adapter);
6886
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006887 /* Don't lie to e1000_close() down the road. */
6888 if (!down)
6889 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006890 unregister_netdev(netdev);
6891
Alan Sternf3ec4f82010-06-08 15:23:51 -04006892 if (pci_dev_run_wake(pdev))
6893 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006894
Bruce Allane921eb12012-11-28 09:28:37 +00006895 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006896 * would have already happened in close and is redundant.
6897 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006898 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006899
Bruce Allan4662e822008-08-26 18:37:06 -07006900 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006901 kfree(adapter->tx_ring);
6902 kfree(adapter->rx_ring);
6903
6904 iounmap(adapter->hw.hw_addr);
6905 if (adapter->hw.flash_address)
6906 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006907 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006908 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006909
6910 free_netdev(netdev);
6911
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006912 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006913 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006914
Auke Kokbc7f75f2007-09-17 12:30:59 -07006915 pci_disable_device(pdev);
6916}
6917
6918/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006919static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006920 .error_detected = e1000_io_error_detected,
6921 .slot_reset = e1000_io_slot_reset,
6922 .resume = e1000_io_resume,
6923};
6924
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006925static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006926 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6927 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6928 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00006929 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
6930 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006931 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6932 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006936
Auke Kokbc7f75f2007-09-17 12:30:59 -07006937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6940 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006941
Auke Kokbc7f75f2007-09-17 12:30:59 -07006942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6944 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006945
Bruce Allan4662e822008-08-26 18:37:06 -07006946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006948 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006949
Auke Kokbc7f75f2007-09-17 12:30:59 -07006950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6951 board_80003es2lan },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6953 board_80003es2lan },
6954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6955 board_80003es2lan },
6956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6957 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006958
Auke Kokbc7f75f2007-09-17 12:30:59 -07006959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006967
Auke Kokbc7f75f2007-09-17 12:30:59 -07006968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6976 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6977
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6980 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006981
Bruce Allanf4187b52008-08-26 18:36:50 -07006982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006984 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006985
Bruce Allana4f58f52009-06-02 11:29:18 +00006986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6989 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6990
Bruce Alland3738bb2010-06-16 13:27:28 +00006991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6992 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6993
Bruce Allan2fbe4522012-04-19 03:21:47 +00006994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6997 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006998
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006999 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07007000};
7001MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7002
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007003#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007004static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007005 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
Bruce Allan17e813e2013-02-20 04:06:01 +00007006 SET_RUNTIME_PM_OPS(e1000_runtime_suspend, e1000_runtime_resume,
7007 e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007008};
David S. Millere50208a2010-03-16 23:36:24 -07007009#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007010
Auke Kokbc7f75f2007-09-17 12:30:59 -07007011/* PCI Device API Driver */
7012static struct pci_driver e1000_driver = {
7013 .name = e1000e_driver_name,
7014 .id_table = e1000_pci_tbl,
7015 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007016 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007017#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007018 .driver = {
7019 .pm = &e1000_pm_ops,
7020 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007021#endif
7022 .shutdown = e1000_shutdown,
7023 .err_handler = &e1000_err_handler
7024};
7025
7026/**
7027 * e1000_init_module - Driver Registration Routine
7028 *
7029 * e1000_init_module is the first routine called when the driver is
7030 * loaded. All it does is register with the PCI subsystem.
7031 **/
7032static int __init e1000_init_module(void)
7033{
7034 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007035 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7036 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007037 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007038 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007039
Auke Kokbc7f75f2007-09-17 12:30:59 -07007040 return ret;
7041}
7042module_init(e1000_init_module);
7043
7044/**
7045 * e1000_exit_module - Driver Exit Cleanup Routine
7046 *
7047 * e1000_exit_module is called just before the driver is removed
7048 * from memory.
7049 **/
7050static void __exit e1000_exit_module(void)
7051{
7052 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007053}
7054module_exit(e1000_exit_module);
7055
7056
7057MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7058MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7059MODULE_LICENSE("GPL");
7060MODULE_VERSION(DRV_VERSION);
7061
Bruce Allan06c24b92012-02-23 03:13:13 +00007062/* netdev.c */