blob: 533713740c585b5c8ff06ad119cf9b816029f6ab [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 }
Bruce Allanf0f1a172010-12-11 05:53:32 +00001545#define rxtop (rx_ring->rx_skb_top)
Bruce Allan5f450212011-07-22 06:21:46 +00001546 if (!(staterr & E1000_RXD_STAT_EOP)) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001547 /* this descriptor is only the beginning (or middle) */
1548 if (!rxtop) {
1549 /* this is the beginning of a chain */
1550 rxtop = skb;
1551 skb_fill_page_desc(rxtop, 0, buffer_info->page,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001552 0, length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001553 } else {
1554 /* this is the middle of a chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001555 shinfo = skb_shinfo(rxtop);
1556 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1557 buffer_info->page, 0,
1558 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001559 /* re-use the skb, only consumed the page */
1560 buffer_info->skb = skb;
1561 }
1562 e1000_consume_page(buffer_info, rxtop, length);
1563 goto next_desc;
1564 } else {
1565 if (rxtop) {
1566 /* end of the chain */
Bruce Allan17e813e2013-02-20 04:06:01 +00001567 shinfo = skb_shinfo(rxtop);
1568 skb_fill_page_desc(rxtop, shinfo->nr_frags,
1569 buffer_info->page, 0,
1570 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001571 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001572 * page
1573 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001574 buffer_info->skb = skb;
1575 skb = rxtop;
1576 rxtop = NULL;
1577 e1000_consume_page(buffer_info, skb, length);
1578 } else {
1579 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001580 * copybreak to save the put_page/alloc_page
1581 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001582 if (length <= copybreak &&
1583 skb_tailroom(skb) >= length) {
1584 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001585 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001586 memcpy(skb_tail_pointer(skb), vaddr,
1587 length);
Cong Wang46790262011-11-25 23:14:23 +08001588 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001589 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001590 * buffer_info->page
1591 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001592 skb_put(skb, length);
1593 } else {
1594 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001595 buffer_info->page, 0,
1596 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001597 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001598 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001599 }
1600 }
1601 }
1602
Bruce Allan2e1706f2012-06-30 20:02:42 +00001603 /* Receive Checksum Offload */
1604 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001605
Bruce Allan70495a52012-01-11 01:26:50 +00001606 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1607
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001608 /* probably a little skewed due to removing CRC */
1609 total_rx_bytes += skb->len;
1610 total_rx_packets++;
1611
1612 /* eth type trans needs skb->data to point to something */
1613 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001614 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001615 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001616 goto next_desc;
1617 }
1618
Bruce Allan5f450212011-07-22 06:21:46 +00001619 e1000_receive_skb(adapter, netdev, skb, staterr,
1620 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001621
1622next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001623 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001624
1625 /* return some buffers to hardware, one at a time is too slow */
1626 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001627 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001628 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001629 cleaned_count = 0;
1630 }
1631
1632 /* use prefetched values */
1633 rx_desc = next_rxd;
1634 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001635
1636 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001637 }
1638 rx_ring->next_to_clean = i;
1639
1640 cleaned_count = e1000_desc_unused(rx_ring);
1641 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001642 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001643
1644 adapter->total_rx_bytes += total_rx_bytes;
1645 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001646 return cleaned;
1647}
1648
1649/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001651 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001653static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654{
Bruce Allan55aa6982011-12-16 00:45:45 +00001655 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656 struct e1000_buffer *buffer_info;
1657 struct e1000_ps_page *ps_page;
1658 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659 unsigned int i, j;
1660
1661 /* Free all the Rx ring sk_buffs */
1662 for (i = 0; i < rx_ring->count; i++) {
1663 buffer_info = &rx_ring->buffer_info[i];
1664 if (buffer_info->dma) {
1665 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001666 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001667 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001668 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001669 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001670 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001671 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001673 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001675 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001676 buffer_info->dma = 0;
1677 }
1678
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001679 if (buffer_info->page) {
1680 put_page(buffer_info->page);
1681 buffer_info->page = NULL;
1682 }
1683
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 if (buffer_info->skb) {
1685 dev_kfree_skb(buffer_info->skb);
1686 buffer_info->skb = NULL;
1687 }
1688
1689 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001690 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001691 if (!ps_page->page)
1692 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001693 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1694 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695 ps_page->dma = 0;
1696 put_page(ps_page->page);
1697 ps_page->page = NULL;
1698 }
1699 }
1700
1701 /* there also may be some cached data from a chained receive */
1702 if (rx_ring->rx_skb_top) {
1703 dev_kfree_skb(rx_ring->rx_skb_top);
1704 rx_ring->rx_skb_top = NULL;
1705 }
1706
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 /* Zero out the descriptor ring */
1708 memset(rx_ring->desc, 0, rx_ring->size);
1709
1710 rx_ring->next_to_clean = 0;
1711 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001712 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713
Bruce Allanc5083cf2011-12-16 00:45:40 +00001714 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001715 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1716 e1000e_update_rdt_wa(rx_ring, 0);
1717 else
1718 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719}
1720
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001721static void e1000e_downshift_workaround(struct work_struct *work)
1722{
1723 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00001724 struct e1000_adapter,
1725 downshift_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001726
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001727 if (test_bit(__E1000_DOWN, &adapter->state))
1728 return;
1729
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001730 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1731}
1732
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733/**
1734 * e1000_intr_msi - Interrupt Handler
1735 * @irq: interrupt number
1736 * @data: pointer to a network interface device structure
1737 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001738static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739{
1740 struct net_device *netdev = data;
1741 struct e1000_adapter *adapter = netdev_priv(netdev);
1742 struct e1000_hw *hw = &adapter->hw;
1743 u32 icr = er32(ICR);
1744
Bruce Allane921eb12012-11-28 09:28:37 +00001745 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001746 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001747 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001748 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001749 * disconnect (LSC) before accessing any PHY registers
1750 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1752 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001753 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754
Bruce Allane921eb12012-11-28 09:28:37 +00001755 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001757 * adapter in watchdog
1758 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759 if (netif_carrier_ok(netdev) &&
1760 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1761 /* disable receives */
1762 u32 rctl = er32(RCTL);
1763 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001764 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765 }
1766 /* guard against interrupt when we're going down */
1767 if (!test_bit(__E1000_DOWN, &adapter->state))
1768 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1769 }
1770
Bruce Allan94fb8482013-01-23 09:00:03 +00001771 /* Reset on uncorrectable ECC error */
1772 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1773 u32 pbeccsts = er32(PBECCSTS);
1774
1775 adapter->corr_errors +=
1776 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1777 adapter->uncorr_errors +=
1778 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1779 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1780
1781 /* Do the reset outside of interrupt context */
1782 schedule_work(&adapter->reset_task);
1783
1784 /* return immediately since reset is imminent */
1785 return IRQ_HANDLED;
1786 }
1787
Ben Hutchings288379f2009-01-19 16:43:59 -08001788 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001789 adapter->total_tx_bytes = 0;
1790 adapter->total_tx_packets = 0;
1791 adapter->total_rx_bytes = 0;
1792 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001793 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794 }
1795
1796 return IRQ_HANDLED;
1797}
1798
1799/**
1800 * e1000_intr - Interrupt Handler
1801 * @irq: interrupt number
1802 * @data: pointer to a network interface device structure
1803 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001804static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001805{
1806 struct net_device *netdev = data;
1807 struct e1000_adapter *adapter = netdev_priv(netdev);
1808 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001810
Bruce Allana68ea772009-11-20 23:23:16 +00001811 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 return IRQ_NONE; /* Not our interrupt */
1813
Bruce Allane921eb12012-11-28 09:28:37 +00001814 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001815 * not set, then the adapter didn't send an interrupt
1816 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 if (!(icr & E1000_ICR_INT_ASSERTED))
1818 return IRQ_NONE;
1819
Bruce Allane921eb12012-11-28 09:28:37 +00001820 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001821 * interrupts are masked. No need for the
1822 * IMC write
1823 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001824
dave graham573cca82009-02-10 12:52:05 +00001825 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001826 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001827 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001828 * disconnect (LSC) before accessing any PHY registers
1829 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1831 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001832 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833
Bruce Allane921eb12012-11-28 09:28:37 +00001834 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835 * For packet buffer work-around on link down event;
1836 * disable receives here in the ISR and
1837 * reset adapter in watchdog
1838 */
1839 if (netif_carrier_ok(netdev) &&
1840 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1841 /* disable receives */
1842 rctl = er32(RCTL);
1843 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001844 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845 }
1846 /* guard against interrupt when we're going down */
1847 if (!test_bit(__E1000_DOWN, &adapter->state))
1848 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1849 }
1850
Bruce Allan94fb8482013-01-23 09:00:03 +00001851 /* Reset on uncorrectable ECC error */
1852 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1853 u32 pbeccsts = er32(PBECCSTS);
1854
1855 adapter->corr_errors +=
1856 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1857 adapter->uncorr_errors +=
1858 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1859 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1860
1861 /* Do the reset outside of interrupt context */
1862 schedule_work(&adapter->reset_task);
1863
1864 /* return immediately since reset is imminent */
1865 return IRQ_HANDLED;
1866 }
1867
Ben Hutchings288379f2009-01-19 16:43:59 -08001868 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869 adapter->total_tx_bytes = 0;
1870 adapter->total_tx_packets = 0;
1871 adapter->total_rx_bytes = 0;
1872 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001873 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001874 }
1875
1876 return IRQ_HANDLED;
1877}
1878
Bruce Allan8bb62862013-01-16 08:46:49 +00001879static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001880{
1881 struct net_device *netdev = data;
1882 struct e1000_adapter *adapter = netdev_priv(netdev);
1883 struct e1000_hw *hw = &adapter->hw;
1884 u32 icr = er32(ICR);
1885
1886 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001887 if (!test_bit(__E1000_DOWN, &adapter->state))
1888 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001889 return IRQ_NONE;
1890 }
1891
1892 if (icr & adapter->eiac_mask)
1893 ew32(ICS, (icr & adapter->eiac_mask));
1894
1895 if (icr & E1000_ICR_OTHER) {
1896 if (!(icr & E1000_ICR_LSC))
1897 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001898 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001899 /* guard against interrupt when we're going down */
1900 if (!test_bit(__E1000_DOWN, &adapter->state))
1901 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1902 }
1903
1904no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001905 if (!test_bit(__E1000_DOWN, &adapter->state))
1906 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001907
1908 return IRQ_HANDLED;
1909}
1910
Bruce Allan8bb62862013-01-16 08:46:49 +00001911static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001912{
1913 struct net_device *netdev = data;
1914 struct e1000_adapter *adapter = netdev_priv(netdev);
1915 struct e1000_hw *hw = &adapter->hw;
1916 struct e1000_ring *tx_ring = adapter->tx_ring;
1917
Bruce Allan4662e822008-08-26 18:37:06 -07001918 adapter->total_tx_bytes = 0;
1919 adapter->total_tx_packets = 0;
1920
Bruce Allan55aa6982011-12-16 00:45:45 +00001921 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001922 /* Ring was not completely cleaned, so fire another interrupt */
1923 ew32(ICS, tx_ring->ims_val);
1924
1925 return IRQ_HANDLED;
1926}
1927
Bruce Allan8bb62862013-01-16 08:46:49 +00001928static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001929{
1930 struct net_device *netdev = data;
1931 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001932 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001933
1934 /* Write the ITR value calculated at the end of the
1935 * previous interrupt.
1936 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001937 if (rx_ring->set_itr) {
1938 writel(1000000000 / (rx_ring->itr_val * 256),
1939 rx_ring->itr_register);
1940 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001941 }
1942
Ben Hutchings288379f2009-01-19 16:43:59 -08001943 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001944 adapter->total_rx_bytes = 0;
1945 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001946 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001947 }
1948 return IRQ_HANDLED;
1949}
1950
1951/**
1952 * e1000_configure_msix - Configure MSI-X hardware
1953 *
1954 * e1000_configure_msix sets up the hardware to properly
1955 * generate MSI-X interrupts.
1956 **/
1957static void e1000_configure_msix(struct e1000_adapter *adapter)
1958{
1959 struct e1000_hw *hw = &adapter->hw;
1960 struct e1000_ring *rx_ring = adapter->rx_ring;
1961 struct e1000_ring *tx_ring = adapter->tx_ring;
1962 int vector = 0;
1963 u32 ctrl_ext, ivar = 0;
1964
1965 adapter->eiac_mask = 0;
1966
1967 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1968 if (hw->mac.type == e1000_82574) {
1969 u32 rfctl = er32(RFCTL);
1970 rfctl |= E1000_RFCTL_ACK_DIS;
1971 ew32(RFCTL, rfctl);
1972 }
1973
1974#define E1000_IVAR_INT_ALLOC_VALID 0x8
1975 /* Configure Rx vector */
1976 rx_ring->ims_val = E1000_IMS_RXQ0;
1977 adapter->eiac_mask |= rx_ring->ims_val;
1978 if (rx_ring->itr_val)
1979 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001980 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001981 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001982 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001983 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1984
1985 /* Configure Tx vector */
1986 tx_ring->ims_val = E1000_IMS_TXQ0;
1987 vector++;
1988 if (tx_ring->itr_val)
1989 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001990 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001991 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001992 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001993 adapter->eiac_mask |= tx_ring->ims_val;
1994 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1995
1996 /* set vector for Other Causes, e.g. link changes */
1997 vector++;
1998 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1999 if (rx_ring->itr_val)
2000 writel(1000000000 / (rx_ring->itr_val * 256),
2001 hw->hw_addr + E1000_EITR_82574(vector));
2002 else
2003 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2004
2005 /* Cause Tx interrupts on every write back */
2006 ivar |= (1 << 31);
2007
2008 ew32(IVAR, ivar);
2009
2010 /* enable MSI-X PBA support */
2011 ctrl_ext = er32(CTRL_EXT);
2012 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2013
2014 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07002015 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2016 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2017 ew32(CTRL_EXT, ctrl_ext);
2018 e1e_flush();
2019}
2020
2021void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2022{
2023 if (adapter->msix_entries) {
2024 pci_disable_msix(adapter->pdev);
2025 kfree(adapter->msix_entries);
2026 adapter->msix_entries = NULL;
2027 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2028 pci_disable_msi(adapter->pdev);
2029 adapter->flags &= ~FLAG_MSI_ENABLED;
2030 }
Bruce Allan4662e822008-08-26 18:37:06 -07002031}
2032
2033/**
2034 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2035 *
2036 * Attempt to configure interrupts using the best available
2037 * capabilities of the hardware and kernel.
2038 **/
2039void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2040{
2041 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002042 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002043
2044 switch (adapter->int_mode) {
2045 case E1000E_INT_MODE_MSIX:
2046 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002047 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2048 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan17e813e2013-02-20 04:06:01 +00002049 sizeof(struct
2050 msix_entry),
2051 GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002052 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002053 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002054 adapter->msix_entries[i].entry = i;
2055
2056 err = pci_enable_msix(adapter->pdev,
2057 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002058 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002059 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002060 return;
2061 }
2062 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002063 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002064 e1000e_reset_interrupt_capability(adapter);
2065 }
2066 adapter->int_mode = E1000E_INT_MODE_MSI;
2067 /* Fall through */
2068 case E1000E_INT_MODE_MSI:
2069 if (!pci_enable_msi(adapter->pdev)) {
2070 adapter->flags |= FLAG_MSI_ENABLED;
2071 } else {
2072 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002073 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002074 }
2075 /* Fall through */
2076 case E1000E_INT_MODE_LEGACY:
2077 /* Don't do anything; this is the system default */
2078 break;
2079 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002080
2081 /* store the number of vectors being used */
2082 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002083}
2084
2085/**
2086 * e1000_request_msix - Initialize MSI-X interrupts
2087 *
2088 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2089 * kernel.
2090 **/
2091static int e1000_request_msix(struct e1000_adapter *adapter)
2092{
2093 struct net_device *netdev = adapter->netdev;
2094 int err = 0, vector = 0;
2095
2096 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002097 snprintf(adapter->rx_ring->name,
2098 sizeof(adapter->rx_ring->name) - 1,
2099 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002100 else
2101 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2102 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002103 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002104 netdev);
2105 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002106 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002107 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2108 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002109 adapter->rx_ring->itr_val = adapter->itr;
2110 vector++;
2111
2112 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002113 snprintf(adapter->tx_ring->name,
2114 sizeof(adapter->tx_ring->name) - 1,
2115 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002116 else
2117 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2118 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002119 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002120 netdev);
2121 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002122 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002123 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2124 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002125 adapter->tx_ring->itr_val = adapter->itr;
2126 vector++;
2127
2128 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002129 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002130 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002131 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002132
2133 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002134
Bruce Allan4662e822008-08-26 18:37:06 -07002135 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002136}
2137
Bruce Allanf8d59f72008-08-08 18:36:11 -07002138/**
2139 * e1000_request_irq - initialize interrupts
2140 *
2141 * Attempts to configure interrupts using the best available
2142 * capabilities of the hardware and kernel.
2143 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144static int e1000_request_irq(struct e1000_adapter *adapter)
2145{
2146 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 int err;
2148
Bruce Allan4662e822008-08-26 18:37:06 -07002149 if (adapter->msix_entries) {
2150 err = e1000_request_msix(adapter);
2151 if (!err)
2152 return err;
2153 /* fall back to MSI */
2154 e1000e_reset_interrupt_capability(adapter);
2155 adapter->int_mode = E1000E_INT_MODE_MSI;
2156 e1000e_set_interrupt_capability(adapter);
2157 }
2158 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002159 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002160 netdev->name, netdev);
2161 if (!err)
2162 return err;
2163
2164 /* fall back to legacy interrupt */
2165 e1000e_reset_interrupt_capability(adapter);
2166 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002167 }
2168
Joe Perchesa0607fd2009-11-18 23:29:17 -08002169 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002170 netdev->name, netdev);
2171 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002172 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002173
2174 return err;
2175}
2176
2177static void e1000_free_irq(struct e1000_adapter *adapter)
2178{
2179 struct net_device *netdev = adapter->netdev;
2180
Bruce Allan4662e822008-08-26 18:37:06 -07002181 if (adapter->msix_entries) {
2182 int vector = 0;
2183
2184 free_irq(adapter->msix_entries[vector].vector, netdev);
2185 vector++;
2186
2187 free_irq(adapter->msix_entries[vector].vector, netdev);
2188 vector++;
2189
2190 /* Other Causes interrupt vector */
2191 free_irq(adapter->msix_entries[vector].vector, netdev);
2192 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193 }
Bruce Allan4662e822008-08-26 18:37:06 -07002194
2195 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002196}
2197
2198/**
2199 * e1000_irq_disable - Mask off interrupt generation on the NIC
2200 **/
2201static void e1000_irq_disable(struct e1000_adapter *adapter)
2202{
2203 struct e1000_hw *hw = &adapter->hw;
2204
Auke Kokbc7f75f2007-09-17 12:30:59 -07002205 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002206 if (adapter->msix_entries)
2207 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002209
2210 if (adapter->msix_entries) {
2211 int i;
2212 for (i = 0; i < adapter->num_vectors; i++)
2213 synchronize_irq(adapter->msix_entries[i].vector);
2214 } else {
2215 synchronize_irq(adapter->pdev->irq);
2216 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002217}
2218
2219/**
2220 * e1000_irq_enable - Enable default interrupt generation settings
2221 **/
2222static void e1000_irq_enable(struct e1000_adapter *adapter)
2223{
2224 struct e1000_hw *hw = &adapter->hw;
2225
Bruce Allan4662e822008-08-26 18:37:06 -07002226 if (adapter->msix_entries) {
2227 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2228 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002229 } else if (hw->mac.type == e1000_pch_lpt) {
2230 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002231 } else {
2232 ew32(IMS, IMS_ENABLE_MASK);
2233 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002234 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002235}
2236
2237/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002238 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239 * @adapter: address of board private structure
2240 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002241 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002242 * For ASF and Pass Through versions of f/w this means that
2243 * the driver is loaded. For AMT version (only with 82573)
2244 * of the f/w this means that the network i/f is open.
2245 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002246void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002247{
2248 struct e1000_hw *hw = &adapter->hw;
2249 u32 ctrl_ext;
2250 u32 swsm;
2251
2252 /* Let firmware know the driver has taken over */
2253 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2254 swsm = er32(SWSM);
2255 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2256 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2257 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002258 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259 }
2260}
2261
2262/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002263 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002264 * @adapter: address of board private structure
2265 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002266 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 * For ASF and Pass Through versions of f/w this means that the
2268 * driver is no longer loaded. For AMT version (only with 82573) i
2269 * of the f/w this means that the network i/f is closed.
2270 *
2271 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002272void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273{
2274 struct e1000_hw *hw = &adapter->hw;
2275 u32 ctrl_ext;
2276 u32 swsm;
2277
2278 /* Let firmware taken over control of h/w */
2279 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2280 swsm = er32(SWSM);
2281 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2282 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2283 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002284 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285 }
2286}
2287
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002289 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002290 **/
2291static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2292 struct e1000_ring *ring)
2293{
2294 struct pci_dev *pdev = adapter->pdev;
2295
2296 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2297 GFP_KERNEL);
2298 if (!ring->desc)
2299 return -ENOMEM;
2300
2301 return 0;
2302}
2303
2304/**
2305 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002306 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002307 *
2308 * Return 0 on success, negative on failure
2309 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002310int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311{
Bruce Allan55aa6982011-12-16 00:45:45 +00002312 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 int err = -ENOMEM, size;
2314
2315 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002316 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002317 if (!tx_ring->buffer_info)
2318 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319
2320 /* round up to nearest 4K */
2321 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2322 tx_ring->size = ALIGN(tx_ring->size, 4096);
2323
2324 err = e1000_alloc_ring_dma(adapter, tx_ring);
2325 if (err)
2326 goto err;
2327
2328 tx_ring->next_to_use = 0;
2329 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330
2331 return 0;
2332err:
2333 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002334 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002335 return err;
2336}
2337
2338/**
2339 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002340 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 *
2342 * Returns 0 on success, negative on failure
2343 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002344int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002345{
Bruce Allan55aa6982011-12-16 00:45:45 +00002346 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002347 struct e1000_buffer *buffer_info;
2348 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002349
2350 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002351 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002352 if (!rx_ring->buffer_info)
2353 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354
Auke Kok47f44e42007-10-25 13:57:44 -07002355 for (i = 0; i < rx_ring->count; i++) {
2356 buffer_info = &rx_ring->buffer_info[i];
2357 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2358 sizeof(struct e1000_ps_page),
2359 GFP_KERNEL);
2360 if (!buffer_info->ps_pages)
2361 goto err_pages;
2362 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363
2364 desc_len = sizeof(union e1000_rx_desc_packet_split);
2365
2366 /* Round up to nearest 4K */
2367 rx_ring->size = rx_ring->count * desc_len;
2368 rx_ring->size = ALIGN(rx_ring->size, 4096);
2369
2370 err = e1000_alloc_ring_dma(adapter, rx_ring);
2371 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002372 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373
2374 rx_ring->next_to_clean = 0;
2375 rx_ring->next_to_use = 0;
2376 rx_ring->rx_skb_top = NULL;
2377
2378 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002379
2380err_pages:
2381 for (i = 0; i < rx_ring->count; i++) {
2382 buffer_info = &rx_ring->buffer_info[i];
2383 kfree(buffer_info->ps_pages);
2384 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385err:
2386 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002387 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388 return err;
2389}
2390
2391/**
2392 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002393 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002395static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396{
Bruce Allan55aa6982011-12-16 00:45:45 +00002397 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398 struct e1000_buffer *buffer_info;
2399 unsigned long size;
2400 unsigned int i;
2401
2402 for (i = 0; i < tx_ring->count; i++) {
2403 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002404 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405 }
2406
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002407 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002408 size = sizeof(struct e1000_buffer) * tx_ring->count;
2409 memset(tx_ring->buffer_info, 0, size);
2410
2411 memset(tx_ring->desc, 0, tx_ring->size);
2412
2413 tx_ring->next_to_use = 0;
2414 tx_ring->next_to_clean = 0;
2415
Bruce Allanc5083cf2011-12-16 00:45:40 +00002416 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002417 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2418 e1000e_update_tdt_wa(tx_ring, 0);
2419 else
2420 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421}
2422
2423/**
2424 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002425 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426 *
2427 * Free all transmit software resources
2428 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002429void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002430{
Bruce Allan55aa6982011-12-16 00:45:45 +00002431 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002433
Bruce Allan55aa6982011-12-16 00:45:45 +00002434 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435
2436 vfree(tx_ring->buffer_info);
2437 tx_ring->buffer_info = NULL;
2438
2439 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2440 tx_ring->dma);
2441 tx_ring->desc = NULL;
2442}
2443
2444/**
2445 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002446 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447 *
2448 * Free all receive software resources
2449 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002450void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002451{
Bruce Allan55aa6982011-12-16 00:45:45 +00002452 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002454 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002455
Bruce Allan55aa6982011-12-16 00:45:45 +00002456 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002457
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002458 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002459 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002460
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 vfree(rx_ring->buffer_info);
2462 rx_ring->buffer_info = NULL;
2463
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2465 rx_ring->dma);
2466 rx_ring->desc = NULL;
2467}
2468
2469/**
2470 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002471 * @adapter: pointer to adapter
2472 * @itr_setting: current adapter->itr
2473 * @packets: the number of packets during this measurement interval
2474 * @bytes: the number of bytes during this measurement interval
2475 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476 * Stores a new ITR value based on packets and byte
2477 * counts during the last interrupt. The advantage of per interrupt
2478 * computation is faster updates and more accurate ITR for the current
2479 * traffic pattern. Constants in this function were computed
2480 * based on theoretical maximum wire speed and thresholds were set based
2481 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002482 * while increasing bulk throughput. This functionality is controlled
2483 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002485static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002486{
2487 unsigned int retval = itr_setting;
2488
2489 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002490 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002491
2492 switch (itr_setting) {
2493 case lowest_latency:
2494 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002495 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002497 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002498 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002499 break;
2500 case low_latency: /* 50 usec aka 20000 ints/s */
2501 if (bytes > 10000) {
2502 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002503 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002505 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002506 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002507 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002508 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002509 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 retval = bulk_latency;
2511 } else if (packets <= 2 && bytes < 512) {
2512 retval = lowest_latency;
2513 }
2514 break;
2515 case bulk_latency: /* 250 usec aka 4000 ints/s */
2516 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002517 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 } else if (bytes < 6000) {
2520 retval = low_latency;
2521 }
2522 break;
2523 }
2524
Auke Kokbc7f75f2007-09-17 12:30:59 -07002525 return retval;
2526}
2527
2528static void e1000_set_itr(struct e1000_adapter *adapter)
2529{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 u16 current_itr;
2531 u32 new_itr = adapter->itr;
2532
2533 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2534 if (adapter->link_speed != SPEED_1000) {
2535 current_itr = 0;
2536 new_itr = 4000;
2537 goto set_itr_now;
2538 }
2539
Bruce Allan828bac82010-09-29 21:39:37 +00002540 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2541 new_itr = 0;
2542 goto set_itr_now;
2543 }
2544
Bruce Allan8bb62862013-01-16 08:46:49 +00002545 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2546 adapter->total_tx_packets,
2547 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2549 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2550 adapter->tx_itr = low_latency;
2551
Bruce Allan8bb62862013-01-16 08:46:49 +00002552 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2553 adapter->total_rx_packets,
2554 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2556 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2557 adapter->rx_itr = low_latency;
2558
2559 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2560
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 /* counts and packets in update_itr are dependent on these numbers */
Bruce Allan33550ce2013-02-20 04:06:16 +00002562 switch (current_itr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 case lowest_latency:
2564 new_itr = 70000;
2565 break;
2566 case low_latency:
2567 new_itr = 20000; /* aka hwitr = ~200 */
2568 break;
2569 case bulk_latency:
2570 new_itr = 4000;
2571 break;
2572 default:
2573 break;
2574 }
2575
2576set_itr_now:
2577 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002578 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002579 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002580 * increasing
2581 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002583 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002584 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002585 adapter->rx_ring->itr_val = new_itr;
2586 if (adapter->msix_entries)
2587 adapter->rx_ring->set_itr = 1;
2588 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002589 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002590 }
2591}
2592
2593/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002594 * e1000e_write_itr - write the ITR value to the appropriate registers
2595 * @adapter: address of board private structure
2596 * @itr: new ITR value to program
2597 *
2598 * e1000e_write_itr determines if the adapter is in MSI-X mode
2599 * and, if so, writes the EITR registers with the ITR value.
2600 * Otherwise, it writes the ITR value into the ITR register.
2601 **/
2602void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2603{
2604 struct e1000_hw *hw = &adapter->hw;
2605 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2606
2607 if (adapter->msix_entries) {
2608 int vector;
2609
2610 for (vector = 0; vector < adapter->num_vectors; vector++)
2611 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2612 } else {
2613 ew32(ITR, new_itr);
2614 }
2615}
2616
2617/**
Bruce Allan4662e822008-08-26 18:37:06 -07002618 * e1000_alloc_queues - Allocate memory for all rings
2619 * @adapter: board private structure to initialize
2620 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002621static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002622{
Bruce Allan55aa6982011-12-16 00:45:45 +00002623 int size = sizeof(struct e1000_ring);
2624
2625 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002626 if (!adapter->tx_ring)
2627 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002628 adapter->tx_ring->count = adapter->tx_ring_count;
2629 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002630
Bruce Allan55aa6982011-12-16 00:45:45 +00002631 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002632 if (!adapter->rx_ring)
2633 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002634 adapter->rx_ring->count = adapter->rx_ring_count;
2635 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002636
2637 return 0;
2638err:
2639 e_err("Unable to allocate memory for queues\n");
2640 kfree(adapter->rx_ring);
2641 kfree(adapter->tx_ring);
2642 return -ENOMEM;
2643}
2644
2645/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002646 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002647 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002648 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002650static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002652 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2653 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002654 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002656 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657
Wang Chen4cf16532008-11-12 23:38:14 -08002658 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659
Bruce Allanc58c8a72012-03-20 03:48:19 +00002660 if (!adapter->msix_entries ||
2661 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2662 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002663
Bruce Allanc58c8a72012-03-20 03:48:19 +00002664 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002665
Alexander Duyck12d04a32009-03-25 22:05:03 +00002666 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002667 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002668
Bruce Allanc58c8a72012-03-20 03:48:19 +00002669 /* If weight not fully consumed, exit the polling mode */
2670 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671 if (adapter->itr_setting & 3)
2672 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002673 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002674 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2675 if (adapter->msix_entries)
2676 ew32(IMS, adapter->rx_ring->ims_val);
2677 else
2678 e1000_irq_enable(adapter);
2679 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002680 }
2681
2682 return work_done;
2683}
2684
Jiri Pirko8e586132011-12-08 19:52:37 -05002685static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686{
2687 struct e1000_adapter *adapter = netdev_priv(netdev);
2688 struct e1000_hw *hw = &adapter->hw;
2689 u32 vfta, index;
2690
2691 /* don't update vlan cookie if already programmed */
2692 if ((adapter->hw.mng_cookie.status &
2693 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2694 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002695 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002696
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002698 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2699 index = (vid >> 5) & 0x7F;
2700 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2701 vfta |= (1 << (vid & 0x1F));
2702 hw->mac.ops.write_vfta(hw, index, vfta);
2703 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002704
2705 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002706
2707 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708}
2709
Jiri Pirko8e586132011-12-08 19:52:37 -05002710static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711{
2712 struct e1000_adapter *adapter = netdev_priv(netdev);
2713 struct e1000_hw *hw = &adapter->hw;
2714 u32 vfta, index;
2715
Auke Kokbc7f75f2007-09-17 12:30:59 -07002716 if ((adapter->hw.mng_cookie.status &
2717 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2718 (vid == adapter->mng_vlan_id)) {
2719 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002720 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002721 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002722 }
2723
2724 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002725 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2726 index = (vid >> 5) & 0x7F;
2727 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2728 vfta &= ~(1 << (vid & 0x1F));
2729 hw->mac.ops.write_vfta(hw, index, vfta);
2730 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002731
2732 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002733
2734 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002735}
2736
2737/**
2738 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2739 * @adapter: board private structure to initialize
2740 **/
2741static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2742{
2743 struct net_device *netdev = adapter->netdev;
2744 struct e1000_hw *hw = &adapter->hw;
2745 u32 rctl;
2746
2747 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2748 /* disable VLAN receive filtering */
2749 rctl = er32(RCTL);
2750 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2751 ew32(RCTL, rctl);
2752
2753 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2754 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2755 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2756 }
2757 }
2758}
2759
2760/**
2761 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2762 * @adapter: board private structure to initialize
2763 **/
2764static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2765{
2766 struct e1000_hw *hw = &adapter->hw;
2767 u32 rctl;
2768
2769 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2770 /* enable VLAN receive filtering */
2771 rctl = er32(RCTL);
2772 rctl |= E1000_RCTL_VFE;
2773 rctl &= ~E1000_RCTL_CFIEN;
2774 ew32(RCTL, rctl);
2775 }
2776}
2777
2778/**
2779 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2780 * @adapter: board private structure to initialize
2781 **/
2782static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2783{
2784 struct e1000_hw *hw = &adapter->hw;
2785 u32 ctrl;
2786
2787 /* disable VLAN tag insert/strip */
2788 ctrl = er32(CTRL);
2789 ctrl &= ~E1000_CTRL_VME;
2790 ew32(CTRL, ctrl);
2791}
2792
2793/**
2794 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2795 * @adapter: board private structure to initialize
2796 **/
2797static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2798{
2799 struct e1000_hw *hw = &adapter->hw;
2800 u32 ctrl;
2801
2802 /* enable VLAN tag insert/strip */
2803 ctrl = er32(CTRL);
2804 ctrl |= E1000_CTRL_VME;
2805 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806}
2807
2808static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2809{
2810 struct net_device *netdev = adapter->netdev;
2811 u16 vid = adapter->hw.mng_cookie.vlan_id;
2812 u16 old_vid = adapter->mng_vlan_id;
2813
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002814 if (adapter->hw.mng_cookie.status &
2815 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2816 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 adapter->mng_vlan_id = vid;
2818 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002820 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2821 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822}
2823
2824static void e1000_restore_vlan(struct e1000_adapter *adapter)
2825{
2826 u16 vid;
2827
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002828 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002830 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Bruce Allanf0ff4392013-02-20 04:05:39 +00002831 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832}
2833
Bruce Allancd791612010-05-10 14:59:51 +00002834static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835{
2836 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002837 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838
2839 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2840 return;
2841
2842 manc = er32(MANC);
2843
Bruce Allane921eb12012-11-28 09:28:37 +00002844 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002846 * the packets will be handled on SMBUS
2847 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848 manc |= E1000_MANC_EN_MNG2HOST;
2849 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002850
2851 switch (hw->mac.type) {
2852 default:
2853 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2854 break;
2855 case e1000_82574:
2856 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002857 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002858 * if so, enable it.
2859 */
2860 for (i = 0, j = 0; i < 8; i++) {
2861 mdef = er32(MDEF(i));
2862
2863 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002864 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002865 continue;
2866
2867 /* Enable this decision filter in MANC2H */
2868 if (mdef)
2869 manc2h |= (1 << i);
2870
2871 j |= mdef;
2872 }
2873
2874 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2875 break;
2876
2877 /* Create new decision filter in an empty filter */
2878 for (i = 0, j = 0; i < 8; i++)
2879 if (er32(MDEF(i)) == 0) {
2880 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2881 E1000_MDEF_PORT_664));
2882 manc2h |= (1 << 1);
2883 j++;
2884 break;
2885 }
2886
2887 if (!j)
2888 e_warn("Unable to create IPMI pass-through filter\n");
2889 break;
2890 }
2891
Auke Kokbc7f75f2007-09-17 12:30:59 -07002892 ew32(MANC2H, manc2h);
2893 ew32(MANC, manc);
2894}
2895
2896/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002897 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002898 * @adapter: board private structure
2899 *
2900 * Configure the Tx unit of the MAC after a reset.
2901 **/
2902static void e1000_configure_tx(struct e1000_adapter *adapter)
2903{
2904 struct e1000_hw *hw = &adapter->hw;
2905 struct e1000_ring *tx_ring = adapter->tx_ring;
2906 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002907 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002908
2909 /* Setup the HW Tx Head and Tail descriptor pointers */
2910 tdba = tx_ring->dma;
2911 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002912 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2913 ew32(TDBAH(0), (tdba >> 32));
2914 ew32(TDLEN(0), tdlen);
2915 ew32(TDH(0), 0);
2916 ew32(TDT(0), 0);
2917 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2918 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920 /* Set the Tx Interrupt Delay register */
2921 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002922 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923 ew32(TADV, adapter->tx_abs_int_delay);
2924
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002925 if (adapter->flags2 & FLAG2_DMA_BURST) {
2926 u32 txdctl = er32(TXDCTL(0));
2927 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2928 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002929 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002930 * hardware to use the bus more efficiently in bursts, depends
2931 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002932 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002933 * hthresh = 1 ==> prefetch when one or more available
2934 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2935 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002936 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002937 */
2938 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2939 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002940 }
Bruce Allan56032be2011-12-16 00:46:01 +00002941 /* erratum work around: set txdctl the same for both queues */
2942 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002943
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002945 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002946 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002947 * gigabit link later
2948 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949#define SPEED_MODE_BIT (1 << 21)
2950 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002951 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 }
2953
2954 /* errata: program both queues to unweighted RR */
2955 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002956 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002958 ew32(TARC(0), tarc);
2959 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002960 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002961 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 }
2963
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964 /* Setup Transmit Descriptor Settings for eop descriptor */
2965 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2966
2967 /* only set IDE if we are delaying interrupts using the timers */
2968 if (adapter->tx_int_delay)
2969 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2970
2971 /* enable Report Status bit */
2972 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2973
Bruce Allan57cde762012-02-22 09:02:58 +00002974 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975}
2976
2977/**
2978 * e1000_setup_rctl - configure the receive control registers
2979 * @adapter: Board private structure
2980 **/
2981#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2982 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2983static void e1000_setup_rctl(struct e1000_adapter *adapter)
2984{
2985 struct e1000_hw *hw = &adapter->hw;
2986 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987 u32 pages = 0;
2988
Bruce Allan2fbe4522012-04-19 03:21:47 +00002989 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2990 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002991 s32 ret_val;
2992
2993 if (adapter->netdev->mtu > ETH_DATA_LEN)
2994 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2995 else
2996 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002997
2998 if (ret_val)
2999 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00003000 }
3001
Auke Kokbc7f75f2007-09-17 12:30:59 -07003002 /* Program MC offset vector base */
3003 rctl = er32(RCTL);
3004 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3005 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003006 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3007 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008
3009 /* Do not Store bad packets */
3010 rctl &= ~E1000_RCTL_SBP;
3011
3012 /* Enable Long Packet receive */
3013 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3014 rctl &= ~E1000_RCTL_LPE;
3015 else
3016 rctl |= E1000_RCTL_LPE;
3017
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003018 /* Some systems expect that the CRC is included in SMBUS traffic. The
3019 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3020 * host memory when this is enabled
3021 */
3022 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3023 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003024
Bruce Allana4f58f52009-06-02 11:29:18 +00003025 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3026 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3027 u16 phy_data;
3028
3029 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3030 phy_data &= 0xfff8;
3031 phy_data |= (1 << 2);
3032 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3033
3034 e1e_rphy(hw, 22, &phy_data);
3035 phy_data &= 0x0fff;
3036 phy_data |= (1 << 14);
3037 e1e_wphy(hw, 0x10, 0x2823);
3038 e1e_wphy(hw, 0x11, 0x0003);
3039 e1e_wphy(hw, 22, phy_data);
3040 }
3041
Auke Kokbc7f75f2007-09-17 12:30:59 -07003042 /* Setup buffer sizes */
3043 rctl &= ~E1000_RCTL_SZ_4096;
3044 rctl |= E1000_RCTL_BSEX;
3045 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003046 case 2048:
3047 default:
3048 rctl |= E1000_RCTL_SZ_2048;
3049 rctl &= ~E1000_RCTL_BSEX;
3050 break;
3051 case 4096:
3052 rctl |= E1000_RCTL_SZ_4096;
3053 break;
3054 case 8192:
3055 rctl |= E1000_RCTL_SZ_8192;
3056 break;
3057 case 16384:
3058 rctl |= E1000_RCTL_SZ_16384;
3059 break;
3060 }
3061
Bruce Allan5f450212011-07-22 06:21:46 +00003062 /* Enable Extended Status in all Receive Descriptors */
3063 rfctl = er32(RFCTL);
3064 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003065 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003066
Bruce Allane921eb12012-11-28 09:28:37 +00003067 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 * header is placed in skb->data and the packet data is
3069 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3070 * In the case of a non-split, skb->data is linearly filled,
3071 * followed by the page buffers. Therefore, skb->data is
3072 * sized to hold the largest protocol header.
3073 *
3074 * allocations using alloc_page take too long for regular MTU
3075 * so only enable packet split for jumbo frames
3076 *
3077 * Using pages when the page size is greater than 16k wastes
3078 * a lot of memory, since we allocate 3 pages at all times
3079 * per packet.
3080 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003082 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003084 else
3085 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003086
3087 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003088 u32 psrctl = 0;
3089
Auke Kok140a7482007-10-25 13:57:58 -07003090 /* Enable Packet split descriptors */
3091 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092
3093 psrctl |= adapter->rx_ps_bsize0 >>
3094 E1000_PSRCTL_BSIZE0_SHIFT;
3095
3096 switch (adapter->rx_ps_pages) {
3097 case 3:
3098 psrctl |= PAGE_SIZE <<
3099 E1000_PSRCTL_BSIZE3_SHIFT;
3100 case 2:
3101 psrctl |= PAGE_SIZE <<
3102 E1000_PSRCTL_BSIZE2_SHIFT;
3103 case 1:
3104 psrctl |= PAGE_SIZE >>
3105 E1000_PSRCTL_BSIZE1_SHIFT;
3106 break;
3107 }
3108
3109 ew32(PSRCTL, psrctl);
3110 }
3111
Ben Greearcf955e62012-02-11 15:39:51 +00003112 /* This is useful for sniffing bad packets. */
3113 if (adapter->netdev->features & NETIF_F_RXALL) {
3114 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003115 * in e1000e_set_rx_mode
3116 */
Ben Greearcf955e62012-02-11 15:39:51 +00003117 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3118 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3119 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3120
3121 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3122 E1000_RCTL_DPF | /* Allow filtered pause */
3123 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3124 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3125 * and that breaks VLANs.
3126 */
3127 }
3128
Auke Kokbc7f75f2007-09-17 12:30:59 -07003129 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003130 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003131 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003132}
3133
3134/**
3135 * e1000_configure_rx - Configure Receive Unit after Reset
3136 * @adapter: board private structure
3137 *
3138 * Configure the Rx unit of the MAC after a reset.
3139 **/
3140static void e1000_configure_rx(struct e1000_adapter *adapter)
3141{
3142 struct e1000_hw *hw = &adapter->hw;
3143 struct e1000_ring *rx_ring = adapter->rx_ring;
3144 u64 rdba;
3145 u32 rdlen, rctl, rxcsum, ctrl_ext;
3146
3147 if (adapter->rx_ps_pages) {
3148 /* this is a 32 byte descriptor */
3149 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003150 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151 adapter->clean_rx = e1000_clean_rx_irq_ps;
3152 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003153 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003154 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003155 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3156 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003157 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003158 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159 adapter->clean_rx = e1000_clean_rx_irq;
3160 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3161 }
3162
3163 /* disable receives while setting up the descriptors */
3164 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003165 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3166 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003167 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003168 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003169
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003170 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003171 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003172 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003173 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003174 * granularity = 01
3175 * wthresh = 04,
3176 * hthresh = 04,
3177 * pthresh = 0x20
3178 */
3179 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3180 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3181
Bruce Allane921eb12012-11-28 09:28:37 +00003182 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003183 * the value was not set by the user via module options
3184 */
3185 if (adapter->rx_int_delay == DEFAULT_RDTR)
3186 adapter->rx_int_delay = BURST_RDTR;
3187 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3188 adapter->rx_abs_int_delay = BURST_RADV;
3189 }
3190
Auke Kokbc7f75f2007-09-17 12:30:59 -07003191 /* set the Receive Delay Timer Register */
3192 ew32(RDTR, adapter->rx_int_delay);
3193
3194 /* irq moderation */
3195 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003196 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003197 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198
3199 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003200 /* Auto-Mask interrupts upon ICR access */
3201 ctrl_ext |= E1000_CTRL_EXT_IAME;
3202 ew32(IAM, 0xffffffff);
3203 ew32(CTRL_EXT, ctrl_ext);
3204 e1e_flush();
3205
Bruce Allane921eb12012-11-28 09:28:37 +00003206 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003207 * the Base and Length of the Rx Descriptor Ring
3208 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003209 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003210 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3211 ew32(RDBAH(0), (rdba >> 32));
3212 ew32(RDLEN(0), rdlen);
3213 ew32(RDH(0), 0);
3214 ew32(RDT(0), 0);
3215 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3216 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003217
3218 /* Enable Receive Checksum Offload for TCP and UDP */
3219 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003220 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003222 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003224 ew32(RXCSUM, rxcsum);
3225
Bruce Allan3e35d992013-01-12 07:25:22 +00003226 /* With jumbo frames, excessive C-state transition latencies result
3227 * in dropped transactions.
3228 */
3229 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3230 u32 lat =
3231 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3232 adapter->max_frame_size) * 8 / 1000;
3233
3234 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003235 u32 rxdctl = er32(RXDCTL(0));
3236 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003237 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003238
3239 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3240 } else {
3241 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3242 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003243 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244
3245 /* Enable Receives */
3246 ew32(RCTL, rctl);
3247}
3248
3249/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003250 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003251 * @netdev: network interface device structure
3252 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003253 * Writes multicast address list to the MTA hash table.
3254 * Returns: -ENOMEM on failure
3255 * 0 on no addresses written
3256 * X on writing X addresses to MTA
3257 */
3258static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259{
3260 struct e1000_adapter *adapter = netdev_priv(netdev);
3261 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003262 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003263 u8 *mta_list;
3264 int i;
3265
3266 if (netdev_mc_empty(netdev)) {
3267 /* nothing to program, so clear mc list */
3268 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3269 return 0;
3270 }
3271
3272 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3273 if (!mta_list)
3274 return -ENOMEM;
3275
3276 /* update_mc_addr_list expects a packed array of only addresses. */
3277 i = 0;
3278 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003279 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003280
3281 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3282 kfree(mta_list);
3283
3284 return netdev_mc_count(netdev);
3285}
3286
3287/**
3288 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3289 * @netdev: network interface device structure
3290 *
3291 * Writes unicast address list to the RAR table.
3292 * Returns: -ENOMEM on failure/insufficient address space
3293 * 0 on no addresses written
3294 * X on writing X addresses to the RAR table
3295 **/
3296static int e1000e_write_uc_addr_list(struct net_device *netdev)
3297{
3298 struct e1000_adapter *adapter = netdev_priv(netdev);
3299 struct e1000_hw *hw = &adapter->hw;
3300 unsigned int rar_entries = hw->mac.rar_entry_count;
3301 int count = 0;
3302
3303 /* save a rar entry for our hardware address */
3304 rar_entries--;
3305
3306 /* save a rar entry for the LAA workaround */
3307 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3308 rar_entries--;
3309
3310 /* return ENOMEM indicating insufficient memory for addresses */
3311 if (netdev_uc_count(netdev) > rar_entries)
3312 return -ENOMEM;
3313
3314 if (!netdev_uc_empty(netdev) && rar_entries) {
3315 struct netdev_hw_addr *ha;
3316
Bruce Allane921eb12012-11-28 09:28:37 +00003317 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003318 * combining
3319 */
3320 netdev_for_each_uc_addr(ha, netdev) {
3321 if (!rar_entries)
3322 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003323 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003324 count++;
3325 }
3326 }
3327
3328 /* zero out the remaining RAR entries not used above */
3329 for (; rar_entries > 0; rar_entries--) {
3330 ew32(RAH(rar_entries), 0);
3331 ew32(RAL(rar_entries), 0);
3332 }
3333 e1e_flush();
3334
3335 return count;
3336}
3337
3338/**
3339 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3340 * @netdev: network interface device structure
3341 *
3342 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3343 * address list or the network interface flags are updated. This routine is
3344 * responsible for configuring the hardware for proper unicast, multicast,
3345 * promiscuous mode, and all-multi behavior.
3346 **/
3347static void e1000e_set_rx_mode(struct net_device *netdev)
3348{
3349 struct e1000_adapter *adapter = netdev_priv(netdev);
3350 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003352
3353 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003354 rctl = er32(RCTL);
3355
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003356 /* clear the affected bits */
3357 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3358
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 if (netdev->flags & IFF_PROMISC) {
3360 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003361 /* Do not hardware filter VLANs in promisc mode */
3362 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003364 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003365
Patrick McHardy746b9f02008-07-16 20:15:45 -07003366 if (netdev->flags & IFF_ALLMULTI) {
3367 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003368 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003369 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003370 * then we should just turn on promiscuous mode so
3371 * that we can at least receive multicast traffic
3372 */
3373 count = e1000e_write_mc_addr_list(netdev);
3374 if (count < 0)
3375 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003376 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003377 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003378 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003379 * sufficient space to store all the addresses then enable
3380 * unicast promiscuous mode
3381 */
3382 count = e1000e_write_uc_addr_list(netdev);
3383 if (count < 0)
3384 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003385 }
3386
3387 ew32(RCTL, rctl);
3388
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003389 if (netdev->features & NETIF_F_HW_VLAN_RX)
3390 e1000e_vlan_strip_enable(adapter);
3391 else
3392 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393}
3394
Bruce Allan70495a52012-01-11 01:26:50 +00003395static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3396{
3397 struct e1000_hw *hw = &adapter->hw;
3398 u32 mrqc, rxcsum;
3399 int i;
3400 static const u32 rsskey[10] = {
3401 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3402 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3403 };
3404
3405 /* Fill out hash function seed */
3406 for (i = 0; i < 10; i++)
3407 ew32(RSSRK(i), rsskey[i]);
3408
3409 /* Direct all traffic to queue 0 */
3410 for (i = 0; i < 32; i++)
3411 ew32(RETA(i), 0);
3412
Bruce Allane921eb12012-11-28 09:28:37 +00003413 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003414 * descriptor on writeback.
3415 */
3416 rxcsum = er32(RXCSUM);
3417 rxcsum |= E1000_RXCSUM_PCSD;
3418
3419 ew32(RXCSUM, rxcsum);
3420
3421 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3422 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3423 E1000_MRQC_RSS_FIELD_IPV6 |
3424 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3425 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3426
3427 ew32(MRQC, mrqc);
3428}
3429
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003431 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3432 * @adapter: board private structure
3433 * @timinca: pointer to returned time increment attributes
3434 *
3435 * Get attributes for incrementing the System Time Register SYSTIML/H at
3436 * the default base frequency, and set the cyclecounter shift value.
3437 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003438s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003439{
3440 struct e1000_hw *hw = &adapter->hw;
3441 u32 incvalue, incperiod, shift;
3442
3443 /* Make sure clock is enabled on I217 before checking the frequency */
3444 if ((hw->mac.type == e1000_pch_lpt) &&
3445 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3446 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3447 u32 fextnvm7 = er32(FEXTNVM7);
3448
3449 if (!(fextnvm7 & (1 << 0))) {
3450 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3451 e1e_flush();
3452 }
3453 }
3454
3455 switch (hw->mac.type) {
3456 case e1000_pch2lan:
3457 case e1000_pch_lpt:
3458 /* On I217, the clock frequency is 25MHz or 96MHz as
3459 * indicated by the System Clock Frequency Indication
3460 */
3461 if ((hw->mac.type != e1000_pch_lpt) ||
3462 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3463 /* Stable 96MHz frequency */
3464 incperiod = INCPERIOD_96MHz;
3465 incvalue = INCVALUE_96MHz;
3466 shift = INCVALUE_SHIFT_96MHz;
3467 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3468 break;
3469 }
3470 /* fall-through */
3471 case e1000_82574:
3472 case e1000_82583:
3473 /* Stable 25MHz frequency */
3474 incperiod = INCPERIOD_25MHz;
3475 incvalue = INCVALUE_25MHz;
3476 shift = INCVALUE_SHIFT_25MHz;
3477 adapter->cc.shift = shift;
3478 break;
3479 default:
3480 return -EINVAL;
3481 }
3482
3483 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3484 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3485
3486 return 0;
3487}
3488
3489/**
3490 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3491 * @adapter: board private structure
3492 *
3493 * Outgoing time stamping can be enabled and disabled. Play nice and
3494 * disable it when requested, although it shouldn't cause any overhead
3495 * when no packet needs it. At most one packet in the queue may be
3496 * marked for time stamping, otherwise it would be impossible to tell
3497 * for sure to which packet the hardware time stamp belongs.
3498 *
3499 * Incoming time stamping has to be configured via the hardware filters.
3500 * Not all combinations are supported, in particular event type has to be
3501 * specified. Matching the kind of event packet is not supported, with the
3502 * exception of "all V2 events regardless of level 2 or 4".
3503 **/
3504static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3505{
3506 struct e1000_hw *hw = &adapter->hw;
3507 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3508 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3509 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003510 u32 rxmtrl = 0;
3511 u16 rxudp = 0;
3512 bool is_l4 = false;
3513 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003514 u32 regval;
3515 s32 ret_val;
3516
3517 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3518 return -EINVAL;
3519
3520 /* flags reserved for future extensions - must be zero */
3521 if (config->flags)
3522 return -EINVAL;
3523
3524 switch (config->tx_type) {
3525 case HWTSTAMP_TX_OFF:
3526 tsync_tx_ctl = 0;
3527 break;
3528 case HWTSTAMP_TX_ON:
3529 break;
3530 default:
3531 return -ERANGE;
3532 }
3533
3534 switch (config->rx_filter) {
3535 case HWTSTAMP_FILTER_NONE:
3536 tsync_rx_ctl = 0;
3537 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003538 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3539 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3540 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3541 is_l4 = true;
3542 break;
3543 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3544 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3545 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3546 is_l4 = true;
3547 break;
3548 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3549 /* Also time stamps V2 L2 Path Delay Request/Response */
3550 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3551 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3552 is_l2 = true;
3553 break;
3554 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3555 /* Also time stamps V2 L2 Path Delay Request/Response. */
3556 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3557 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3558 is_l2 = true;
3559 break;
3560 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3561 /* Hardware cannot filter just V2 L4 Sync messages;
3562 * fall-through to V2 (both L2 and L4) Sync.
3563 */
3564 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3565 /* Also time stamps V2 Path Delay Request/Response. */
3566 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3567 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3568 is_l2 = true;
3569 is_l4 = true;
3570 break;
3571 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3572 /* Hardware cannot filter just V2 L4 Delay Request messages;
3573 * fall-through to V2 (both L2 and L4) Delay Request.
3574 */
3575 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3576 /* Also time stamps V2 Path Delay Request/Response. */
3577 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3578 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3579 is_l2 = true;
3580 is_l4 = true;
3581 break;
3582 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3583 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3584 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3585 * fall-through to all V2 (both L2 and L4) Events.
3586 */
3587 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3588 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3589 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3590 is_l2 = true;
3591 is_l4 = true;
3592 break;
3593 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3594 /* For V1, the hardware can only filter Sync messages or
3595 * Delay Request messages but not both so fall-through to
3596 * time stamp all packets.
3597 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003598 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003599 is_l2 = true;
3600 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003601 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3602 config->rx_filter = HWTSTAMP_FILTER_ALL;
3603 break;
3604 default:
3605 return -ERANGE;
3606 }
3607
3608 /* enable/disable Tx h/w time stamping */
3609 regval = er32(TSYNCTXCTL);
3610 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3611 regval |= tsync_tx_ctl;
3612 ew32(TSYNCTXCTL, regval);
3613 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3614 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3615 e_err("Timesync Tx Control register not set as expected\n");
3616 return -EAGAIN;
3617 }
3618
3619 /* enable/disable Rx h/w time stamping */
3620 regval = er32(TSYNCRXCTL);
3621 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3622 regval |= tsync_rx_ctl;
3623 ew32(TSYNCRXCTL, regval);
3624 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3625 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3626 (regval & (E1000_TSYNCRXCTL_ENABLED |
3627 E1000_TSYNCRXCTL_TYPE_MASK))) {
3628 e_err("Timesync Rx Control register not set as expected\n");
3629 return -EAGAIN;
3630 }
3631
Bruce Alland89777b2013-01-19 01:09:58 +00003632 /* L2: define ethertype filter for time stamped packets */
3633 if (is_l2)
3634 rxmtrl |= ETH_P_1588;
3635
3636 /* define which PTP packets get time stamped */
3637 ew32(RXMTRL, rxmtrl);
3638
3639 /* Filter by destination port */
3640 if (is_l4) {
3641 rxudp = PTP_EV_PORT;
3642 cpu_to_be16s(&rxudp);
3643 }
3644 ew32(RXUDP, rxudp);
3645
3646 e1e_flush();
3647
Bruce Allanb67e1912012-12-27 08:32:33 +00003648 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003649 er32(RXSTMPH);
3650 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003651
3652 /* Get and set the System Time Register SYSTIM base frequency */
3653 ret_val = e1000e_get_base_timinca(adapter, &regval);
3654 if (ret_val)
3655 return ret_val;
3656 ew32(TIMINCA, regval);
3657
3658 /* reset the ns time counter */
3659 timecounter_init(&adapter->tc, &adapter->cc,
3660 ktime_to_ns(ktime_get_real()));
3661
3662 return 0;
3663}
3664
3665/**
Bruce Allanad680762008-03-28 09:15:03 -07003666 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003667 * @adapter: private board structure
3668 **/
3669static void e1000_configure(struct e1000_adapter *adapter)
3670{
Bruce Allan55aa6982011-12-16 00:45:45 +00003671 struct e1000_ring *rx_ring = adapter->rx_ring;
3672
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003673 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003674
3675 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003676 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677
3678 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003679
3680 if (adapter->netdev->features & NETIF_F_RXHASH)
3681 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 e1000_setup_rctl(adapter);
3683 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003684 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685}
3686
3687/**
3688 * e1000e_power_up_phy - restore link in case the phy was powered down
3689 * @adapter: address of board private structure
3690 *
3691 * The phy may be powered down to save power and turn off link when the
3692 * driver is unloaded and wake on lan is not enabled (among others)
3693 * *** this routine MUST be followed by a call to e1000e_reset ***
3694 **/
3695void e1000e_power_up_phy(struct e1000_adapter *adapter)
3696{
Bruce Allan17f208d2009-12-01 15:47:22 +00003697 if (adapter->hw.phy.ops.power_up)
3698 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699
3700 adapter->hw.mac.ops.setup_link(&adapter->hw);
3701}
3702
3703/**
3704 * e1000_power_down_phy - Power down the PHY
3705 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003706 * Power down the PHY so no link is implied when interface is down.
3707 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003708 */
3709static void e1000_power_down_phy(struct e1000_adapter *adapter)
3710{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003711 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003712 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003713 return;
3714
Bruce Allan17f208d2009-12-01 15:47:22 +00003715 if (adapter->hw.phy.ops.power_down)
3716 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003717}
3718
3719/**
3720 * e1000e_reset - bring the hardware into a known good state
3721 *
3722 * This function boots the hardware and enables some settings that
3723 * require a configuration cycle of the hardware - those cannot be
3724 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003725 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726 */
3727void e1000e_reset(struct e1000_adapter *adapter)
3728{
3729 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003730 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731 struct e1000_hw *hw = &adapter->hw;
3732 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003733 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003734 u16 hwm;
3735
Bruce Allanad680762008-03-28 09:15:03 -07003736 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003737 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003738
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003739 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003740 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003741 * large enough to accommodate two full transmit packets,
3742 * rounded up to the next 1KB and expressed in KB. Likewise,
3743 * the Rx FIFO should be large enough to accommodate at least
3744 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003745 * expressed in KB.
3746 */
Auke Kokdf762462007-10-25 13:57:53 -07003747 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003749 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003751 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003752 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003753 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003754 */
3755 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756 sizeof(struct e1000_tx_desc) -
3757 ETH_FCS_LEN) * 2;
3758 min_tx_space = ALIGN(min_tx_space, 1024);
3759 min_tx_space >>= 10;
3760 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003761 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762 min_rx_space = ALIGN(min_rx_space, 1024);
3763 min_rx_space >>= 10;
3764
Bruce Allane921eb12012-11-28 09:28:37 +00003765 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003766 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003767 * allocation, take space away from current Rx allocation
3768 */
Auke Kokdf762462007-10-25 13:57:53 -07003769 if ((tx_space < min_tx_space) &&
3770 ((min_tx_space - tx_space) < pba)) {
3771 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003772
Bruce Allane921eb12012-11-28 09:28:37 +00003773 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003774 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003775 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003776 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003777 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 }
Auke Kokdf762462007-10-25 13:57:53 -07003779
3780 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781 }
3782
Bruce Allane921eb12012-11-28 09:28:37 +00003783 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003784 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003785 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003786 * (or the size used for early receive) above it in the Rx FIFO.
3787 * Set it to the lower of:
3788 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003789 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003790 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003791 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3792 fc->pause_time = 0xFFFF;
3793 else
3794 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003795 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003796 fc->current_mode = fc->requested_mode;
3797
3798 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003799 case e1000_ich9lan:
3800 case e1000_ich10lan:
3801 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3802 pba = 14;
3803 ew32(PBA, pba);
3804 fc->high_water = 0x2800;
3805 fc->low_water = fc->high_water - 8;
3806 break;
3807 }
3808 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003809 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003810 hwm = min(((pba << 10) * 9 / 10),
3811 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003812
3813 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3814 fc->low_water = fc->high_water - 8;
3815 break;
3816 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003817 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003818 * loads. If hangs persist, try disabling Tx flow control.
3819 */
3820 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3821 fc->high_water = 0x3500;
3822 fc->low_water = 0x1500;
3823 } else {
3824 fc->high_water = 0x5000;
3825 fc->low_water = 0x3000;
3826 }
Bruce Allana3055952010-05-10 15:02:12 +00003827 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003828 break;
3829 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003830 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003831 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003832
3833 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3834 fc->high_water = 0x05C20;
3835 fc->low_water = 0x05048;
3836 fc->pause_time = 0x0650;
3837 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003838 }
Bruce Allan347b5202012-12-08 00:35:35 +00003839
3840 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3841 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003842 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003843 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003844
Bruce Allane921eb12012-11-28 09:28:37 +00003845 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003846 * maximum size per Tx descriptor limited only to the transmit
3847 * allocation of the packet buffer minus 96 bytes with an upper
3848 * limit of 24KB due to receive synchronization limitations.
3849 */
3850 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3851 24 << 10);
3852
Bruce Allane921eb12012-11-28 09:28:37 +00003853 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003854 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003855 */
3856 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003857 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003858 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3859 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003860 "Interrupt Throttle Rate off\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003861 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003862 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003863 }
3864 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3865 dev_info(&adapter->pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00003866 "Interrupt Throttle Rate on\n");
Bruce Allan828bac82010-09-29 21:39:37 +00003867 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3868 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003869 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003870 }
3871 }
3872
Auke Kokbc7f75f2007-09-17 12:30:59 -07003873 /* Allow time for pending master requests to run */
3874 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003875
Bruce Allane921eb12012-11-28 09:28:37 +00003876 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003877 * that the network interface is in control
3878 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003879 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003880 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003881
Auke Kokbc7f75f2007-09-17 12:30:59 -07003882 ew32(WUC, 0);
3883
3884 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003885 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003886
3887 e1000_update_mng_vlan(adapter);
3888
3889 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3890 ew32(VET, ETH_P_8021Q);
3891
3892 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003893
Bruce Allanb67e1912012-12-27 08:32:33 +00003894 /* initialize systim and reset the ns time counter */
3895 e1000e_config_hwtstamp(adapter);
3896
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003897 if (!netif_running(adapter->netdev) &&
3898 !test_bit(__E1000_TESTING, &adapter->state)) {
3899 e1000_power_down_phy(adapter);
3900 return;
3901 }
3902
Auke Kokbc7f75f2007-09-17 12:30:59 -07003903 e1000_get_phy_info(hw);
3904
Bruce Allan918d7192009-06-02 11:28:20 +00003905 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3906 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003907 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003908 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003909 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003910 * different we would do if it failed
3911 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003912 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3913 phy_data &= ~IGP02E1000_PM_SPD;
3914 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3915 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916}
3917
3918int e1000e_up(struct e1000_adapter *adapter)
3919{
3920 struct e1000_hw *hw = &adapter->hw;
3921
3922 /* hardware has been reset, we need to reload some things */
3923 e1000_configure(adapter);
3924
3925 clear_bit(__E1000_DOWN, &adapter->state);
3926
Bruce Allan4662e822008-08-26 18:37:06 -07003927 if (adapter->msix_entries)
3928 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003929 e1000_irq_enable(adapter);
3930
Bruce Allan400484f2011-05-13 07:20:03 +00003931 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003932
Auke Kokbc7f75f2007-09-17 12:30:59 -07003933 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003934 if (adapter->msix_entries)
3935 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3936 else
3937 ew32(ICS, E1000_ICS_LSC);
3938
Auke Kokbc7f75f2007-09-17 12:30:59 -07003939 return 0;
3940}
3941
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003942static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3943{
3944 struct e1000_hw *hw = &adapter->hw;
3945
3946 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3947 return;
3948
3949 /* flush pending descriptor writebacks to memory */
3950 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3951 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3952
3953 /* execute the writes immediately */
3954 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003955
Bruce Allane921eb12012-11-28 09:28:37 +00003956 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003957 * write is successful
3958 */
3959 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3960 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3961
3962 /* execute the writes immediately */
3963 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003964}
3965
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003966static void e1000e_update_stats(struct e1000_adapter *adapter);
3967
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968void e1000e_down(struct e1000_adapter *adapter)
3969{
3970 struct net_device *netdev = adapter->netdev;
3971 struct e1000_hw *hw = &adapter->hw;
3972 u32 tctl, rctl;
3973
Bruce Allane921eb12012-11-28 09:28:37 +00003974 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003975 * reschedule our watchdog timer
3976 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003977 set_bit(__E1000_DOWN, &adapter->state);
3978
3979 /* disable receives in the hardware */
3980 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003981 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3982 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 /* flush and sleep below */
3984
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003985 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986
3987 /* disable transmits in the hardware */
3988 tctl = er32(TCTL);
3989 tctl &= ~E1000_TCTL_EN;
3990 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003991
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992 /* flush both disables and wait for them to finish */
3993 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003994 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003995
Auke Kokbc7f75f2007-09-17 12:30:59 -07003996 e1000_irq_disable(adapter);
3997
3998 del_timer_sync(&adapter->watchdog_timer);
3999 del_timer_sync(&adapter->phy_info_timer);
4000
Auke Kokbc7f75f2007-09-17 12:30:59 -07004001 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004002
4003 spin_lock(&adapter->stats64_lock);
4004 e1000e_update_stats(adapter);
4005 spin_unlock(&adapter->stats64_lock);
4006
Bruce Allan400484f2011-05-13 07:20:03 +00004007 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004008 e1000_clean_tx_ring(adapter->tx_ring);
4009 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004010
Auke Kokbc7f75f2007-09-17 12:30:59 -07004011 adapter->link_speed = 0;
4012 adapter->link_duplex = 0;
4013
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004014 if (!pci_channel_offline(adapter->pdev))
4015 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004016
Bruce Allane921eb12012-11-28 09:28:37 +00004017 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004018 * pci_disable_device here.
4019 */
4020}
4021
4022void e1000e_reinit_locked(struct e1000_adapter *adapter)
4023{
4024 might_sleep();
4025 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004026 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027 e1000e_down(adapter);
4028 e1000e_up(adapter);
4029 clear_bit(__E1000_RESETTING, &adapter->state);
4030}
4031
4032/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004033 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4034 * @cc: cyclecounter structure
4035 **/
4036static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4037{
4038 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4039 cc);
4040 struct e1000_hw *hw = &adapter->hw;
4041 cycle_t systim;
4042
4043 /* latch SYSTIMH on read of SYSTIML */
4044 systim = (cycle_t)er32(SYSTIML);
4045 systim |= (cycle_t)er32(SYSTIMH) << 32;
4046
4047 return systim;
4048}
4049
4050/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004051 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4052 * @adapter: board private structure to initialize
4053 *
4054 * e1000_sw_init initializes the Adapter private data structure.
4055 * Fields are initialized based on PCI device information and
4056 * OS network device settings (MTU size).
4057 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004058static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004059{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004060 struct net_device *netdev = adapter->netdev;
4061
4062 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4063 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004064 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4065 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004066 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4067 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004069 spin_lock_init(&adapter->stats64_lock);
4070
Bruce Allan4662e822008-08-26 18:37:06 -07004071 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072
Bruce Allan4662e822008-08-26 18:37:06 -07004073 if (e1000_alloc_queues(adapter))
4074 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004075
Bruce Allanb67e1912012-12-27 08:32:33 +00004076 /* Setup hardware time stamping cyclecounter */
4077 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4078 adapter->cc.read = e1000e_cyclecounter_read;
4079 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4080 adapter->cc.mult = 1;
4081 /* cc.shift set in e1000e_get_base_tininca() */
4082
4083 spin_lock_init(&adapter->systim_lock);
4084 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4085 }
4086
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 e1000_irq_disable(adapter);
4089
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 set_bit(__E1000_DOWN, &adapter->state);
4091 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092}
4093
4094/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004095 * e1000_intr_msi_test - Interrupt Handler
4096 * @irq: interrupt number
4097 * @data: pointer to a network interface device structure
4098 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004099static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004100{
4101 struct net_device *netdev = data;
4102 struct e1000_adapter *adapter = netdev_priv(netdev);
4103 struct e1000_hw *hw = &adapter->hw;
4104 u32 icr = er32(ICR);
4105
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004106 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004107 if (icr & E1000_ICR_RXSEQ) {
4108 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004109 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004110 * interrupt is handled.
4111 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004112 wmb();
4113 }
4114
4115 return IRQ_HANDLED;
4116}
4117
4118/**
4119 * e1000_test_msi_interrupt - Returns 0 for successful test
4120 * @adapter: board private struct
4121 *
4122 * code flow taken from tg3.c
4123 **/
4124static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4125{
4126 struct net_device *netdev = adapter->netdev;
4127 struct e1000_hw *hw = &adapter->hw;
4128 int err;
4129
4130 /* poll_enable hasn't been called yet, so don't need disable */
4131 /* clear any pending events */
4132 er32(ICR);
4133
4134 /* free the real vector and request a test handler */
4135 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004136 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004137
4138 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004139 * MSI irq handler will unset this flag
4140 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004141 adapter->flags |= FLAG_MSI_TEST_FAILED;
4142
4143 err = pci_enable_msi(adapter->pdev);
4144 if (err)
4145 goto msi_test_failed;
4146
Joe Perchesa0607fd2009-11-18 23:29:17 -08004147 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004148 netdev->name, netdev);
4149 if (err) {
4150 pci_disable_msi(adapter->pdev);
4151 goto msi_test_failed;
4152 }
4153
Bruce Allane921eb12012-11-28 09:28:37 +00004154 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004155 * interrupt.
4156 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004157 wmb();
4158
4159 e1000_irq_enable(adapter);
4160
4161 /* fire an unusual interrupt on the test handler */
4162 ew32(ICS, E1000_ICS_RXSEQ);
4163 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004164 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004165
4166 e1000_irq_disable(adapter);
4167
Bruce Allanbc763292012-08-17 06:18:07 +00004168 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004169
4170 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004171 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004172 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004173 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004174 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004175 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004176
4177 free_irq(adapter->pdev->irq, netdev);
4178 pci_disable_msi(adapter->pdev);
4179
Bruce Allanf8d59f72008-08-08 18:36:11 -07004180msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004181 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004182 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004183}
4184
4185/**
4186 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4187 * @adapter: board private struct
4188 *
4189 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4190 **/
4191static int e1000_test_msi(struct e1000_adapter *adapter)
4192{
4193 int err;
4194 u16 pci_cmd;
4195
4196 if (!(adapter->flags & FLAG_MSI_ENABLED))
4197 return 0;
4198
4199 /* disable SERR in case the MSI write causes a master abort */
4200 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004201 if (pci_cmd & PCI_COMMAND_SERR)
4202 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4203 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004204
4205 err = e1000_test_msi_interrupt(adapter);
4206
Dean Nelson36f24072010-06-29 18:12:05 +00004207 /* re-enable SERR */
4208 if (pci_cmd & PCI_COMMAND_SERR) {
4209 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4210 pci_cmd |= PCI_COMMAND_SERR;
4211 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4212 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004213
Bruce Allanf8d59f72008-08-08 18:36:11 -07004214 return err;
4215}
4216
4217/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 * e1000_open - Called when a network interface is made active
4219 * @netdev: network interface device structure
4220 *
4221 * Returns 0 on success, negative value on failure
4222 *
4223 * The open entry point is called when a network interface is made
4224 * active by the system (IFF_UP). At this point all resources needed
4225 * for transmit and receive operations are allocated, the interrupt
4226 * handler is registered with the OS, the watchdog timer is started,
4227 * and the stack is notified that the interface is ready.
4228 **/
4229static int e1000_open(struct net_device *netdev)
4230{
4231 struct e1000_adapter *adapter = netdev_priv(netdev);
4232 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004233 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004234 int err;
4235
4236 /* disallow open during test */
4237 if (test_bit(__E1000_TESTING, &adapter->state))
4238 return -EBUSY;
4239
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004240 pm_runtime_get_sync(&pdev->dev);
4241
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004242 netif_carrier_off(netdev);
4243
Auke Kokbc7f75f2007-09-17 12:30:59 -07004244 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004245 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 if (err)
4247 goto err_setup_tx;
4248
4249 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004250 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004251 if (err)
4252 goto err_setup_rx;
4253
Bruce Allane921eb12012-11-28 09:28:37 +00004254 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004255 * interface is now open and reset the part to a known state.
4256 */
4257 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004258 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004259 e1000e_reset(adapter);
4260 }
4261
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 e1000e_power_up_phy(adapter);
4263
4264 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4265 if ((adapter->hw.mng_cookie.status &
4266 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4267 e1000_update_mng_vlan(adapter);
4268
Bruce Allan79d4e902011-12-16 00:46:27 +00004269 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004270 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4271 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004272
Bruce Allane921eb12012-11-28 09:28:37 +00004273 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004274 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4275 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004276 * clean_rx handler before we do so.
4277 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 e1000_configure(adapter);
4279
4280 err = e1000_request_irq(adapter);
4281 if (err)
4282 goto err_req_irq;
4283
Bruce Allane921eb12012-11-28 09:28:37 +00004284 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004285 * ignore e1000e MSI messages, which means we need to test our MSI
4286 * interrupt now
4287 */
Bruce Allan4662e822008-08-26 18:37:06 -07004288 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004289 err = e1000_test_msi(adapter);
4290 if (err) {
4291 e_err("Interrupt allocation failed\n");
4292 goto err_req_irq;
4293 }
4294 }
4295
Auke Kokbc7f75f2007-09-17 12:30:59 -07004296 /* From here on the code is the same as e1000e_up() */
4297 clear_bit(__E1000_DOWN, &adapter->state);
4298
4299 napi_enable(&adapter->napi);
4300
4301 e1000_irq_enable(adapter);
4302
Jeff Kirsher09357b02011-11-18 14:25:00 +00004303 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004304 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004305
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004306 adapter->idle_check = true;
4307 pm_runtime_put(&pdev->dev);
4308
Auke Kokbc7f75f2007-09-17 12:30:59 -07004309 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004310 if (adapter->msix_entries)
4311 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4312 else
4313 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004314
4315 return 0;
4316
4317err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004318 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004319 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004320 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004321err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004322 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323err_setup_tx:
4324 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004325 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004326
4327 return err;
4328}
4329
4330/**
4331 * e1000_close - Disables a network interface
4332 * @netdev: network interface device structure
4333 *
4334 * Returns 0, this is not allowed to fail
4335 *
4336 * The close entry point is called when an interface is de-activated
4337 * by the OS. The hardware is still under the drivers control, but
4338 * needs to be disabled. A global MAC reset is issued to stop the
4339 * hardware, and all transmit and receive resources are freed.
4340 **/
4341static int e1000_close(struct net_device *netdev)
4342{
4343 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004344 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004345 int count = E1000_CHECK_RESET_COUNT;
4346
4347 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4348 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004349
4350 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004351
4352 pm_runtime_get_sync(&pdev->dev);
4353
Bruce Allan5f4a7802011-11-29 08:09:19 +00004354 napi_disable(&adapter->napi);
4355
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004356 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4357 e1000e_down(adapter);
4358 e1000_free_irq(adapter);
4359 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004360 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004361
Bruce Allan55aa6982011-12-16 00:45:45 +00004362 e1000e_free_tx_resources(adapter->tx_ring);
4363 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004364
Bruce Allane921eb12012-11-28 09:28:37 +00004365 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004366 * the same ID is registered on the host OS (let 8021q kill it)
4367 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004368 if (adapter->hw.mng_cookie.status &
4369 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004370 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4371
Bruce Allane921eb12012-11-28 09:28:37 +00004372 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004373 * interface is now closed
4374 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004375 if ((adapter->flags & FLAG_HAS_AMT) &&
4376 !test_bit(__E1000_TESTING, &adapter->state))
4377 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004378
Bruce Allan3e35d992013-01-12 07:25:22 +00004379 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004380
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004381 pm_runtime_put_sync(&pdev->dev);
4382
Auke Kokbc7f75f2007-09-17 12:30:59 -07004383 return 0;
4384}
Bruce Allanfc830b72013-02-20 04:06:11 +00004385
Auke Kokbc7f75f2007-09-17 12:30:59 -07004386/**
4387 * e1000_set_mac - Change the Ethernet Address of the NIC
4388 * @netdev: network interface device structure
4389 * @p: pointer to an address structure
4390 *
4391 * Returns 0 on success, negative on failure
4392 **/
4393static int e1000_set_mac(struct net_device *netdev, void *p)
4394{
4395 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004396 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004397 struct sockaddr *addr = p;
4398
4399 if (!is_valid_ether_addr(addr->sa_data))
4400 return -EADDRNOTAVAIL;
4401
4402 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4403 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4404
Bruce Allan69e1e012012-04-14 03:28:50 +00004405 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406
4407 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4408 /* activate the work around */
4409 e1000e_set_laa_state_82571(&adapter->hw, 1);
4410
Bruce Allane921eb12012-11-28 09:28:37 +00004411 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004412 * between the time RAR[0] gets clobbered and the time it
4413 * gets fixed (in e1000_watchdog), the actual LAA is in one
4414 * of the RARs and no incoming packets directed to this port
4415 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004416 * RAR[14]
4417 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004418 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4419 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004420 }
4421
4422 return 0;
4423}
4424
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004425/**
4426 * e1000e_update_phy_task - work thread to update phy
4427 * @work: pointer to our work struct
4428 *
4429 * this worker thread exists because we must acquire a
4430 * semaphore to read the phy, which we could msleep while
4431 * waiting for it, and we can't msleep in a timer.
4432 **/
4433static void e1000e_update_phy_task(struct work_struct *work)
4434{
4435 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004436 struct e1000_adapter,
4437 update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004438
4439 if (test_bit(__E1000_DOWN, &adapter->state))
4440 return;
4441
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004442 e1000_get_phy_info(&adapter->hw);
4443}
4444
Bruce Allane921eb12012-11-28 09:28:37 +00004445/**
4446 * e1000_update_phy_info - timre call-back to update PHY info
4447 * @data: pointer to adapter cast into an unsigned long
4448 *
Bruce Allanad680762008-03-28 09:15:03 -07004449 * Need to wait a few seconds after link up to get diagnostic information from
4450 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004451 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004452static void e1000_update_phy_info(unsigned long data)
4453{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004454 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004455
4456 if (test_bit(__E1000_DOWN, &adapter->state))
4457 return;
4458
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004459 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004460}
4461
4462/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004463 * e1000e_update_phy_stats - Update the PHY statistics counters
4464 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004465 *
4466 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004467 **/
4468static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4469{
4470 struct e1000_hw *hw = &adapter->hw;
4471 s32 ret_val;
4472 u16 phy_data;
4473
4474 ret_val = hw->phy.ops.acquire(hw);
4475 if (ret_val)
4476 return;
4477
Bruce Allane921eb12012-11-28 09:28:37 +00004478 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004479 * If not, set to the page with the PHY status registers.
4480 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004481 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004482 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4483 &phy_data);
4484 if (ret_val)
4485 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004486 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4487 ret_val = hw->phy.ops.set_page(hw,
4488 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004489 if (ret_val)
4490 goto release;
4491 }
4492
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004493 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004494 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4495 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004496 if (!ret_val)
4497 adapter->stats.scc += phy_data;
4498
4499 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004500 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4501 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004502 if (!ret_val)
4503 adapter->stats.ecol += phy_data;
4504
4505 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004506 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4507 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004508 if (!ret_val)
4509 adapter->stats.mcc += phy_data;
4510
4511 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004512 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4513 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004514 if (!ret_val)
4515 adapter->stats.latecol += phy_data;
4516
4517 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004518 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4519 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004520 if (!ret_val)
4521 hw->mac.collision_delta = phy_data;
4522
4523 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004524 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4525 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004526 if (!ret_val)
4527 adapter->stats.dc += phy_data;
4528
4529 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004530 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4531 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004532 if (!ret_val)
4533 adapter->stats.tncrs += phy_data;
4534
4535release:
4536 hw->phy.ops.release(hw);
4537}
4538
4539/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540 * e1000e_update_stats - Update the board statistics counters
4541 * @adapter: board private structure
4542 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004543static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004544{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004545 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546 struct e1000_hw *hw = &adapter->hw;
4547 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548
Bruce Allane921eb12012-11-28 09:28:37 +00004549 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004550 * connection is down.
4551 */
4552 if (adapter->link_speed == 0)
4553 return;
4554 if (pci_channel_offline(pdev))
4555 return;
4556
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 adapter->stats.crcerrs += er32(CRCERRS);
4558 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004559 adapter->stats.gorc += er32(GORCL);
4560 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004561 adapter->stats.bprc += er32(BPRC);
4562 adapter->stats.mprc += er32(MPRC);
4563 adapter->stats.roc += er32(ROC);
4564
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004566
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004567 /* Half-duplex statistics */
4568 if (adapter->link_duplex == HALF_DUPLEX) {
4569 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4570 e1000e_update_phy_stats(adapter);
4571 } else {
4572 adapter->stats.scc += er32(SCC);
4573 adapter->stats.ecol += er32(ECOL);
4574 adapter->stats.mcc += er32(MCC);
4575 adapter->stats.latecol += er32(LATECOL);
4576 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004577
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004578 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004579
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004580 if ((hw->mac.type != e1000_82574) &&
4581 (hw->mac.type != e1000_82583))
4582 adapter->stats.tncrs += er32(TNCRS);
4583 }
4584 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004585 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004586
Auke Kokbc7f75f2007-09-17 12:30:59 -07004587 adapter->stats.xonrxc += er32(XONRXC);
4588 adapter->stats.xontxc += er32(XONTXC);
4589 adapter->stats.xoffrxc += er32(XOFFRXC);
4590 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004591 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004592 adapter->stats.gotc += er32(GOTCL);
4593 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004594 adapter->stats.rnbc += er32(RNBC);
4595 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004596
4597 adapter->stats.mptc += er32(MPTC);
4598 adapter->stats.bptc += er32(BPTC);
4599
4600 /* used for adaptive IFS */
4601
4602 hw->mac.tx_packet_delta = er32(TPT);
4603 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004604
4605 adapter->stats.algnerrc += er32(ALGNERRC);
4606 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004607 adapter->stats.cexterr += er32(CEXTERR);
4608 adapter->stats.tsctc += er32(TSCTC);
4609 adapter->stats.tsctfc += er32(TSCTFC);
4610
Auke Kokbc7f75f2007-09-17 12:30:59 -07004611 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004612 netdev->stats.multicast = adapter->stats.mprc;
4613 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004614
4615 /* Rx Errors */
4616
Bruce Allane921eb12012-11-28 09:28:37 +00004617 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004618 * our own version based on RUC and ROC
4619 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004620 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004621 adapter->stats.crcerrs + adapter->stats.algnerrc +
4622 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004623 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004624 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004625 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4626 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4627 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004628
4629 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004630 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004631 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4632 netdev->stats.tx_window_errors = adapter->stats.latecol;
4633 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004634
4635 /* Tx Dropped needs to be maintained elsewhere */
4636
Auke Kokbc7f75f2007-09-17 12:30:59 -07004637 /* Management Stats */
4638 adapter->stats.mgptc += er32(MGTPTC);
4639 adapter->stats.mgprc += er32(MGTPRC);
4640 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004641
4642 /* Correctable ECC Errors */
4643 if (hw->mac.type == e1000_pch_lpt) {
4644 u32 pbeccsts = er32(PBECCSTS);
4645 adapter->corr_errors +=
4646 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4647 adapter->uncorr_errors +=
4648 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4649 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4650 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004651}
4652
Bruce Allan7c257692008-04-23 11:09:00 -07004653/**
4654 * e1000_phy_read_status - Update the PHY register status snapshot
4655 * @adapter: board private structure
4656 **/
4657static void e1000_phy_read_status(struct e1000_adapter *adapter)
4658{
4659 struct e1000_hw *hw = &adapter->hw;
4660 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004661
4662 if ((er32(STATUS) & E1000_STATUS_LU) &&
4663 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004664 int ret_val;
4665
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004666 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4667 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4668 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4669 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4670 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4671 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4672 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4673 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004674 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004675 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004676 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004677 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004678 * Set values to typical power-on defaults
4679 */
4680 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4681 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4682 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4683 BMSR_ERCAP);
4684 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4685 ADVERTISE_ALL | ADVERTISE_CSMA);
4686 phy->lpa = 0;
4687 phy->expansion = EXPANSION_ENABLENPAGE;
4688 phy->ctrl1000 = ADVERTISE_1000FULL;
4689 phy->stat1000 = 0;
4690 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4691 }
Bruce Allan7c257692008-04-23 11:09:00 -07004692}
4693
Auke Kokbc7f75f2007-09-17 12:30:59 -07004694static void e1000_print_link_info(struct e1000_adapter *adapter)
4695{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004696 struct e1000_hw *hw = &adapter->hw;
4697 u32 ctrl = er32(CTRL);
4698
Bruce Allan8f12fe82008-11-21 16:54:43 -08004699 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004700 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4701 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004702 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4703 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4704 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4705 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004706}
4707
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004708static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004709{
4710 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004711 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004712 s32 ret_val = 0;
4713
Bruce Allane921eb12012-11-28 09:28:37 +00004714 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004715 * Rx sequence error interrupt. get_link_status will stay
4716 * false until the check_for_link establishes link
4717 * for copper adapters ONLY
4718 */
4719 switch (hw->phy.media_type) {
4720 case e1000_media_type_copper:
4721 if (hw->mac.get_link_status) {
4722 ret_val = hw->mac.ops.check_for_link(hw);
4723 link_active = !hw->mac.get_link_status;
4724 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004725 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004726 }
4727 break;
4728 case e1000_media_type_fiber:
4729 ret_val = hw->mac.ops.check_for_link(hw);
4730 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4731 break;
4732 case e1000_media_type_internal_serdes:
4733 ret_val = hw->mac.ops.check_for_link(hw);
4734 link_active = adapter->hw.mac.serdes_has_link;
4735 break;
4736 default:
4737 case e1000_media_type_unknown:
4738 break;
4739 }
4740
4741 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4742 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4743 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004744 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004745 }
4746
4747 return link_active;
4748}
4749
4750static void e1000e_enable_receives(struct e1000_adapter *adapter)
4751{
4752 /* make sure the receive unit is started */
4753 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004754 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004755 struct e1000_hw *hw = &adapter->hw;
4756 u32 rctl = er32(RCTL);
4757 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004758 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004759 }
4760}
4761
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004762static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4763{
4764 struct e1000_hw *hw = &adapter->hw;
4765
Bruce Allane921eb12012-11-28 09:28:37 +00004766 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004767 * for hung state and reset, if two calls return true
4768 */
4769 if (e1000_check_phy_82574(hw))
4770 adapter->phy_hang_count++;
4771 else
4772 adapter->phy_hang_count = 0;
4773
4774 if (adapter->phy_hang_count > 1) {
4775 adapter->phy_hang_count = 0;
4776 schedule_work(&adapter->reset_task);
4777 }
4778}
4779
Auke Kokbc7f75f2007-09-17 12:30:59 -07004780/**
4781 * e1000_watchdog - Timer Call-back
4782 * @data: pointer to adapter cast into an unsigned long
4783 **/
4784static void e1000_watchdog(unsigned long data)
4785{
Bruce Allan53aa82d2013-02-20 04:06:06 +00004786 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004787
4788 /* Do the rest outside of interrupt context */
4789 schedule_work(&adapter->watchdog_task);
4790
4791 /* TODO: make this use queue_delayed_work() */
4792}
4793
4794static void e1000_watchdog_task(struct work_struct *work)
4795{
4796 struct e1000_adapter *adapter = container_of(work,
Bruce Allan17e813e2013-02-20 04:06:01 +00004797 struct e1000_adapter,
4798 watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799 struct net_device *netdev = adapter->netdev;
4800 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004801 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004802 struct e1000_ring *tx_ring = adapter->tx_ring;
4803 struct e1000_hw *hw = &adapter->hw;
4804 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004805
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004806 if (test_bit(__E1000_DOWN, &adapter->state))
4807 return;
4808
David S. Millerb405e8d2010-02-04 22:31:41 -08004809 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004810 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004811 /* Cancel scheduled suspend requests. */
4812 pm_runtime_resume(netdev->dev.parent);
4813
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004814 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004815 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816 }
4817
4818 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4819 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4820 e1000_update_mng_vlan(adapter);
4821
Auke Kokbc7f75f2007-09-17 12:30:59 -07004822 if (link) {
4823 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004824 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004825
4826 /* Cancel scheduled suspend requests. */
4827 pm_runtime_resume(netdev->dev.parent);
4828
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004829 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004830 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004831 mac->ops.get_link_up_info(&adapter->hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004832 &adapter->link_speed,
4833 &adapter->link_duplex);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004834 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004835
4836 /* check if SmartSpeed worked */
4837 e1000e_check_downshift(hw);
4838 if (phy->speed_downgraded)
4839 netdev_warn(netdev,
4840 "Link Speed was downgraded by SmartSpeed\n");
4841
Bruce Allane921eb12012-11-28 09:28:37 +00004842 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004843 * if link has autonegotiated at 10/100 half
4844 */
4845 if ((hw->phy.type == e1000_phy_igp_3 ||
4846 hw->phy.type == e1000_phy_bm) &&
4847 (hw->mac.autoneg == true) &&
4848 (adapter->link_speed == SPEED_10 ||
4849 adapter->link_speed == SPEED_100) &&
4850 (adapter->link_duplex == HALF_DUPLEX)) {
4851 u16 autoneg_exp;
4852
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004853 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004854
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004855 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004856 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 -07004857 }
4858
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004859 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004860 adapter->tx_timeout_factor = 1;
4861 switch (adapter->link_speed) {
4862 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004863 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004864 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004865 break;
4866 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004867 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004868 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 break;
4870 }
4871
Bruce Allane921eb12012-11-28 09:28:37 +00004872 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004873 * link-up event
4874 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4876 !txb2b) {
4877 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004878 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004879 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004880 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004881 }
4882
Bruce Allane921eb12012-11-28 09:28:37 +00004883 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004884 * some hardware issues
4885 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004886 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4887 switch (adapter->link_speed) {
4888 case SPEED_10:
4889 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004890 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004891 netdev->features &= ~NETIF_F_TSO;
4892 netdev->features &= ~NETIF_F_TSO6;
4893 break;
4894 case SPEED_1000:
4895 netdev->features |= NETIF_F_TSO;
4896 netdev->features |= NETIF_F_TSO6;
4897 break;
4898 default:
4899 /* oops */
4900 break;
4901 }
4902 }
4903
Bruce Allane921eb12012-11-28 09:28:37 +00004904 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004905 * after setting TARC(0)
4906 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004907 tctl = er32(TCTL);
4908 tctl |= E1000_TCTL_EN;
4909 ew32(TCTL, tctl);
4910
Bruce Allane921eb12012-11-28 09:28:37 +00004911 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004912 * reporting link up.
4913 */
4914 if (phy->ops.cfg_on_link_up)
4915 phy->ops.cfg_on_link_up(hw);
4916
Auke Kokbc7f75f2007-09-17 12:30:59 -07004917 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004918
4919 if (!test_bit(__E1000_DOWN, &adapter->state))
4920 mod_timer(&adapter->phy_info_timer,
4921 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004922 }
4923 } else {
4924 if (netif_carrier_ok(netdev)) {
4925 adapter->link_speed = 0;
4926 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004927 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004928 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004929 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004930 if (!test_bit(__E1000_DOWN, &adapter->state))
4931 mod_timer(&adapter->phy_info_timer,
4932 round_jiffies(jiffies + 2 * HZ));
4933
Bruce Allan12d43f72012-12-05 06:26:14 +00004934 /* The link is lost so the controller stops DMA.
4935 * If there is queued Tx work that cannot be done
4936 * or if on an 8000ES2LAN which requires a Rx packet
4937 * buffer work-around on link down event, reset the
4938 * controller to flush the Tx/Rx packet buffers.
4939 * (Do the reset outside of interrupt context).
4940 */
4941 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4942 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4943 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004944 else
4945 pm_schedule_suspend(netdev->dev.parent,
Bruce Allan17e813e2013-02-20 04:06:01 +00004946 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004947 }
4948 }
4949
4950link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004951 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 e1000e_update_stats(adapter);
4953
4954 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4955 adapter->tpt_old = adapter->stats.tpt;
4956 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4957 adapter->colc_old = adapter->stats.colc;
4958
Bruce Allan7c257692008-04-23 11:09:00 -07004959 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4960 adapter->gorc_old = adapter->stats.gorc;
4961 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4962 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004963 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004964
Bruce Allan12d43f72012-12-05 06:26:14 +00004965 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004966 schedule_work(&adapter->reset_task);
4967 /* return immediately since reset is imminent */
4968 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004969 }
4970
Bruce Allan12d43f72012-12-05 06:26:14 +00004971 e1000e_update_adaptive(&adapter->hw);
4972
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004973 /* Simple mode for Interrupt Throttle Rate (ITR) */
4974 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004975 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004976 * Total asymmetrical Tx or Rx gets ITR=8000;
4977 * everyone else is between 2000-8000.
4978 */
4979 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4980 u32 dif = (adapter->gotc > adapter->gorc ?
Bruce Allan17e813e2013-02-20 04:06:01 +00004981 adapter->gotc - adapter->gorc :
4982 adapter->gorc - adapter->gotc) / 10000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004983 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4984
Matthew Vick22a4cca2012-07-12 00:02:42 +00004985 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004986 }
4987
Bruce Allanad680762008-03-28 09:15:03 -07004988 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004989 if (adapter->msix_entries)
4990 ew32(ICS, adapter->rx_ring->ims_val);
4991 else
4992 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004994 /* flush pending descriptors to memory before detecting Tx hang */
4995 e1000e_flush_descriptors(adapter);
4996
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004998 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999
Bruce Allane921eb12012-11-28 09:28:37 +00005000 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07005001 * reset from the other port. Set the appropriate LAA in RAR[0]
5002 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005003 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00005004 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005005
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005006 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5007 e1000e_check_82574_phy_workaround(adapter);
5008
Bruce Allanb67e1912012-12-27 08:32:33 +00005009 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5010 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5011 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5012 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5013 er32(RXSTMPH);
5014 adapter->rx_hwtstamp_cleared++;
5015 } else {
5016 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5017 }
5018 }
5019
Auke Kokbc7f75f2007-09-17 12:30:59 -07005020 /* Reset the timer */
5021 if (!test_bit(__E1000_DOWN, &adapter->state))
5022 mod_timer(&adapter->watchdog_timer,
5023 round_jiffies(jiffies + 2 * HZ));
5024}
5025
5026#define E1000_TX_FLAGS_CSUM 0x00000001
5027#define E1000_TX_FLAGS_VLAN 0x00000002
5028#define E1000_TX_FLAGS_TSO 0x00000004
5029#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005030#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005031#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005032#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5033#define E1000_TX_FLAGS_VLAN_SHIFT 16
5034
Bruce Allan55aa6982011-12-16 00:45:45 +00005035static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005036{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037 struct e1000_context_desc *context_desc;
5038 struct e1000_buffer *buffer_info;
5039 unsigned int i;
5040 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005041 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005042 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005044 if (!skb_is_gso(skb))
5045 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005047 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005048 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5049
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005050 if (err)
5051 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 }
5053
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005054 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5055 mss = skb_shinfo(skb)->gso_size;
5056 if (skb->protocol == htons(ETH_P_IP)) {
5057 struct iphdr *iph = ip_hdr(skb);
5058 iph->tot_len = 0;
5059 iph->check = 0;
5060 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005061 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005062 cmd_length = E1000_TXD_CMD_IP;
5063 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005064 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005065 ipv6_hdr(skb)->payload_len = 0;
5066 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005067 &ipv6_hdr(skb)->daddr,
5068 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005069 ipcse = 0;
5070 }
5071 ipcss = skb_network_offset(skb);
5072 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5073 tucss = skb_transport_offset(skb);
5074 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005075
5076 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005077 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005078
5079 i = tx_ring->next_to_use;
5080 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5081 buffer_info = &tx_ring->buffer_info[i];
5082
5083 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5084 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5085 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5086 context_desc->upper_setup.tcp_fields.tucss = tucss;
5087 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005088 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005089 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5090 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5091 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5092
5093 buffer_info->time_stamp = jiffies;
5094 buffer_info->next_to_watch = i;
5095
5096 i++;
5097 if (i == tx_ring->count)
5098 i = 0;
5099 tx_ring->next_to_use = i;
5100
5101 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005102}
5103
Bruce Allan55aa6982011-12-16 00:45:45 +00005104static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005105{
Bruce Allan55aa6982011-12-16 00:45:45 +00005106 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107 struct e1000_context_desc *context_desc;
5108 struct e1000_buffer *buffer_info;
5109 unsigned int i;
5110 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005111 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005112 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005113
Dave Grahamaf807c82008-10-09 14:28:58 -07005114 if (skb->ip_summed != CHECKSUM_PARTIAL)
5115 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005116
Arthur Jones5f66f202009-03-19 01:13:08 +00005117 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5118 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5119 else
5120 protocol = skb->protocol;
5121
Arthur Jones3f518392009-03-20 15:56:35 -07005122 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005123 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005124 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5125 cmd_len |= E1000_TXD_CMD_TCP;
5126 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005127 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005128 /* XXX not handling all IPV6 headers */
5129 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5130 cmd_len |= E1000_TXD_CMD_TCP;
5131 break;
5132 default:
5133 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005134 e_warn("checksum_partial proto=%x!\n",
5135 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005136 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005137 }
5138
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005139 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005140
5141 i = tx_ring->next_to_use;
5142 buffer_info = &tx_ring->buffer_info[i];
5143 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5144
5145 context_desc->lower_setup.ip_config = 0;
5146 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005147 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005148 context_desc->upper_setup.tcp_fields.tucse = 0;
5149 context_desc->tcp_seg_setup.data = 0;
5150 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5151
5152 buffer_info->time_stamp = jiffies;
5153 buffer_info->next_to_watch = i;
5154
5155 i++;
5156 if (i == tx_ring->count)
5157 i = 0;
5158 tx_ring->next_to_use = i;
5159
5160 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005161}
5162
Bruce Allan55aa6982011-12-16 00:45:45 +00005163static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5164 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005165 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005166{
Bruce Allan55aa6982011-12-16 00:45:45 +00005167 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005168 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005169 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005170 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005171 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005172 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005173
5174 i = tx_ring->next_to_use;
5175
5176 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005177 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005178 size = min(len, max_per_txd);
5179
Auke Kokbc7f75f2007-09-17 12:30:59 -07005180 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005181 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005182 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005183 buffer_info->dma = dma_map_single(&pdev->dev,
5184 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005185 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005186 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005187 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005188 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005189
5190 len -= size;
5191 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005192 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005193
5194 if (len) {
5195 i++;
5196 if (i == tx_ring->count)
5197 i = 0;
5198 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005199 }
5200
5201 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005202 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005203
5204 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005205 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005206 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207
5208 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005209 i++;
5210 if (i == tx_ring->count)
5211 i = 0;
5212
Auke Kokbc7f75f2007-09-17 12:30:59 -07005213 buffer_info = &tx_ring->buffer_info[i];
5214 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005215
5216 buffer_info->length = size;
5217 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005218 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005219 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
Bruce Allan17e813e2013-02-20 04:06:01 +00005220 offset, size,
5221 DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005222 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005223 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005224 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005225
5226 len -= size;
5227 offset += size;
5228 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 }
5230 }
5231
Bruce Allanaf667a22010-12-31 06:10:01 +00005232 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005233 /* multiply data chunks by size of headers */
5234 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5235
Auke Kokbc7f75f2007-09-17 12:30:59 -07005236 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005237 tx_ring->buffer_info[i].segs = segs;
5238 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005239 tx_ring->buffer_info[first].next_to_watch = i;
5240
5241 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005242
5243dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005244 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005245 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005246 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005247 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005248
5249 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005250 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005251 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005252 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005253 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005254 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005255 }
5256
5257 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005258}
5259
Bruce Allan55aa6982011-12-16 00:45:45 +00005260static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005261{
Bruce Allan55aa6982011-12-16 00:45:45 +00005262 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005263 struct e1000_tx_desc *tx_desc = NULL;
5264 struct e1000_buffer *buffer_info;
5265 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5266 unsigned int i;
5267
5268 if (tx_flags & E1000_TX_FLAGS_TSO) {
5269 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005270 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005271 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5272
5273 if (tx_flags & E1000_TX_FLAGS_IPV4)
5274 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5275 }
5276
5277 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5278 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5279 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5280 }
5281
5282 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5283 txd_lower |= E1000_TXD_CMD_VLE;
5284 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5285 }
5286
Ben Greear943146d2012-02-11 15:39:40 +00005287 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5288 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5289
Bruce Allanb67e1912012-12-27 08:32:33 +00005290 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5291 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5292 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5293 }
5294
Auke Kokbc7f75f2007-09-17 12:30:59 -07005295 i = tx_ring->next_to_use;
5296
Bruce Allan36b973d2010-11-24 07:42:43 +00005297 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005298 buffer_info = &tx_ring->buffer_info[i];
5299 tx_desc = E1000_TX_DESC(*tx_ring, i);
5300 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005301 tx_desc->lower.data = cpu_to_le32(txd_lower |
5302 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005303 tx_desc->upper.data = cpu_to_le32(txd_upper);
5304
5305 i++;
5306 if (i == tx_ring->count)
5307 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005308 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005309
5310 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5311
Ben Greear943146d2012-02-11 15:39:40 +00005312 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5313 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5314 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5315
Bruce Allane921eb12012-11-28 09:28:37 +00005316 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005317 * know there are new descriptors to fetch. (Only
5318 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005319 * such as IA-64).
5320 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005321 wmb();
5322
5323 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005324
5325 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005326 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005327 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005328 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005329
Bruce Allane921eb12012-11-28 09:28:37 +00005330 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005331 * at a time, it synchronizes IO on IA64/Altix systems
5332 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005333 mmiowb();
5334}
5335
5336#define MINIMUM_DHCP_PACKET_SIZE 282
5337static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5338 struct sk_buff *skb)
5339{
5340 struct e1000_hw *hw = &adapter->hw;
5341 u16 length, offset;
5342
Bruce Alland60923c2012-12-05 06:26:56 +00005343 if (vlan_tx_tag_present(skb) &&
5344 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5345 (adapter->hw.mng_cookie.status &
5346 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5347 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005348
5349 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5350 return 0;
5351
Bruce Allan53aa82d2013-02-20 04:06:06 +00005352 if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005353 return 0;
5354
5355 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005356 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005357 struct udphdr *udp;
5358
5359 if (ip->protocol != IPPROTO_UDP)
5360 return 0;
5361
5362 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5363 if (ntohs(udp->dest) != 67)
5364 return 0;
5365
5366 offset = (u8 *)udp + 8 - skb->data;
5367 length = skb->len - offset;
5368 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5369 }
5370
5371 return 0;
5372}
5373
Bruce Allan55aa6982011-12-16 00:45:45 +00005374static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005375{
Bruce Allan55aa6982011-12-16 00:45:45 +00005376 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005377
Bruce Allan55aa6982011-12-16 00:45:45 +00005378 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005379 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005380 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005381 * but since that doesn't exist yet, just open code it.
5382 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005383 smp_mb();
5384
Bruce Allane921eb12012-11-28 09:28:37 +00005385 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005386 * made room available.
5387 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005388 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005389 return -EBUSY;
5390
5391 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005392 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005393 ++adapter->restart_queue;
5394 return 0;
5395}
5396
Bruce Allan55aa6982011-12-16 00:45:45 +00005397static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005398{
Bruce Alland821a4c2012-08-24 20:38:11 +00005399 BUG_ON(size > tx_ring->count);
5400
Bruce Allan55aa6982011-12-16 00:45:45 +00005401 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005402 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005403 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005404}
5405
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005406static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5407 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005408{
5409 struct e1000_adapter *adapter = netdev_priv(netdev);
5410 struct e1000_ring *tx_ring = adapter->tx_ring;
5411 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005412 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005413 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005414 unsigned int nr_frags;
5415 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005416 int count = 0;
5417 int tso;
5418 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005419
5420 if (test_bit(__E1000_DOWN, &adapter->state)) {
5421 dev_kfree_skb_any(skb);
5422 return NETDEV_TX_OK;
5423 }
5424
5425 if (skb->len <= 0) {
5426 dev_kfree_skb_any(skb);
5427 return NETDEV_TX_OK;
5428 }
5429
Bruce Allane921eb12012-11-28 09:28:37 +00005430 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005431 * pad skb in order to meet this minimum size requirement
5432 */
5433 if (unlikely(skb->len < 17)) {
5434 if (skb_pad(skb, 17 - skb->len))
5435 return NETDEV_TX_OK;
5436 skb->len = 17;
5437 skb_set_tail_pointer(skb, 17);
5438 }
5439
Auke Kokbc7f75f2007-09-17 12:30:59 -07005440 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005441 if (mss) {
5442 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005443
Bruce Allane921eb12012-11-28 09:28:37 +00005444 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005445 * points to just header, pull a few bytes of payload from
5446 * frags into skb->data
5447 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005448 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005449 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005450 * avoiding it could save a lot of cycles
5451 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005452 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005453 unsigned int pull_size;
5454
Bruce Allana2a5b322012-01-31 06:37:17 +00005455 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005456 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005457 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005458 dev_kfree_skb_any(skb);
5459 return NETDEV_TX_OK;
5460 }
Eric Dumazete743d312010-04-14 15:59:40 -07005461 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005462 }
5463 }
5464
5465 /* reserve a descriptor for the offload context */
5466 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5467 count++;
5468 count++;
5469
Bruce Alland821a4c2012-08-24 20:38:11 +00005470 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005471
5472 nr_frags = skb_shinfo(skb)->nr_frags;
5473 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005474 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5475 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005476
5477 if (adapter->hw.mac.tx_pkt_filtering)
5478 e1000_transfer_dhcp_info(adapter, skb);
5479
Bruce Allane921eb12012-11-28 09:28:37 +00005480 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005481 * head, otherwise try next time
5482 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005483 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005484 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005485
Jesse Grosseab6d182010-10-20 13:56:03 +00005486 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005487 tx_flags |= E1000_TX_FLAGS_VLAN;
5488 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5489 }
5490
5491 first = tx_ring->next_to_use;
5492
Bruce Allan55aa6982011-12-16 00:45:45 +00005493 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005494 if (tso < 0) {
5495 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005496 return NETDEV_TX_OK;
5497 }
5498
5499 if (tso)
5500 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005501 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005502 tx_flags |= E1000_TX_FLAGS_CSUM;
5503
Bruce Allane921eb12012-11-28 09:28:37 +00005504 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005505 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005506 * no longer assume, we must.
5507 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005508 if (skb->protocol == htons(ETH_P_IP))
5509 tx_flags |= E1000_TX_FLAGS_IPV4;
5510
Ben Greear943146d2012-02-11 15:39:40 +00005511 if (unlikely(skb->no_fcs))
5512 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5513
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005514 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005515 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5516 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005517 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005518 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5519 !adapter->tx_hwtstamp_skb)) {
5520 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5521 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5522 adapter->tx_hwtstamp_skb = skb_get(skb);
5523 schedule_work(&adapter->tx_hwtstamp_work);
5524 } else {
5525 skb_tx_timestamp(skb);
5526 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005527
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005528 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005529 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005530 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005531 e1000_maybe_stop_tx(tx_ring,
5532 (MAX_SKB_FRAGS *
5533 DIV_ROUND_UP(PAGE_SIZE,
5534 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005535 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005536 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005537 tx_ring->buffer_info[first].time_stamp = 0;
5538 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005539 }
5540
Auke Kokbc7f75f2007-09-17 12:30:59 -07005541 return NETDEV_TX_OK;
5542}
5543
5544/**
5545 * e1000_tx_timeout - Respond to a Tx Hang
5546 * @netdev: network interface device structure
5547 **/
5548static void e1000_tx_timeout(struct net_device *netdev)
5549{
5550 struct e1000_adapter *adapter = netdev_priv(netdev);
5551
5552 /* Do the reset outside of interrupt context */
5553 adapter->tx_timeout_count++;
5554 schedule_work(&adapter->reset_task);
5555}
5556
5557static void e1000_reset_task(struct work_struct *work)
5558{
5559 struct e1000_adapter *adapter;
5560 adapter = container_of(work, struct e1000_adapter, reset_task);
5561
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005562 /* don't run the task if already down */
5563 if (test_bit(__E1000_DOWN, &adapter->state))
5564 return;
5565
Bruce Allan12d43f72012-12-05 06:26:14 +00005566 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005567 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005568 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005569 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005570 e1000e_reinit_locked(adapter);
5571}
5572
5573/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005574 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005575 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005576 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005577 *
5578 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005579 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005580struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
Bruce Allan66501f52013-02-20 04:05:55 +00005581 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005582{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005583 struct e1000_adapter *adapter = netdev_priv(netdev);
5584
5585 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5586 spin_lock(&adapter->stats64_lock);
5587 e1000e_update_stats(adapter);
5588 /* Fill out the OS statistics structure */
5589 stats->rx_bytes = adapter->stats.gorc;
5590 stats->rx_packets = adapter->stats.gprc;
5591 stats->tx_bytes = adapter->stats.gotc;
5592 stats->tx_packets = adapter->stats.gptc;
5593 stats->multicast = adapter->stats.mprc;
5594 stats->collisions = adapter->stats.colc;
5595
5596 /* Rx Errors */
5597
Bruce Allane921eb12012-11-28 09:28:37 +00005598 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005599 * our own version based on RUC and ROC
5600 */
5601 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005602 adapter->stats.crcerrs + adapter->stats.algnerrc +
5603 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5604 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005605 stats->rx_crc_errors = adapter->stats.crcerrs;
5606 stats->rx_frame_errors = adapter->stats.algnerrc;
5607 stats->rx_missed_errors = adapter->stats.mpc;
5608
5609 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005610 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005611 stats->tx_aborted_errors = adapter->stats.ecol;
5612 stats->tx_window_errors = adapter->stats.latecol;
5613 stats->tx_carrier_errors = adapter->stats.tncrs;
5614
5615 /* Tx Dropped needs to be maintained elsewhere */
5616
5617 spin_unlock(&adapter->stats64_lock);
5618 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005619}
5620
5621/**
5622 * e1000_change_mtu - Change the Maximum Transfer Unit
5623 * @netdev: network interface device structure
5624 * @new_mtu: new value for maximum frame size
5625 *
5626 * Returns 0 on success, negative on failure
5627 **/
5628static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5629{
5630 struct e1000_adapter *adapter = netdev_priv(netdev);
5631 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5632
Bruce Allan2adc55c2009-06-02 11:28:58 +00005633 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005634 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5635 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5636 e_err("Jumbo Frames not supported.\n");
5637 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005638 }
5639
Bruce Allan2adc55c2009-06-02 11:28:58 +00005640 /* Supported frame sizes */
5641 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5642 (max_frame > adapter->max_hw_frame_size)) {
5643 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005644 return -EINVAL;
5645 }
5646
Bruce Allan2fbe4522012-04-19 03:21:47 +00005647 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5648 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005649 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5650 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005651 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005652 return -EINVAL;
5653 }
5654
Auke Kokbc7f75f2007-09-17 12:30:59 -07005655 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005656 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005657 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005658 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005659 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5660 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005661 if (netif_running(netdev))
5662 e1000e_down(adapter);
5663
Bruce Allane921eb12012-11-28 09:28:37 +00005664 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005665 * means we reserve 2 more, this pushes us to allocate from the next
5666 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005667 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005668 * However with the new *_jumbo_rx* routines, jumbo receives will use
5669 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005670 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005671
Jesse Brandeburg99261462010-01-22 22:56:16 +00005672 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005673 adapter->rx_buffer_len = 2048;
5674 else
5675 adapter->rx_buffer_len = 4096;
5676
5677 /* adjust allocation if LPE protects us, and we aren't using SBP */
5678 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
Bruce Allan17e813e2013-02-20 04:06:01 +00005679 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005680 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allan17e813e2013-02-20 04:06:01 +00005681 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005682
Auke Kokbc7f75f2007-09-17 12:30:59 -07005683 if (netif_running(netdev))
5684 e1000e_up(adapter);
5685 else
5686 e1000e_reset(adapter);
5687
5688 clear_bit(__E1000_RESETTING, &adapter->state);
5689
5690 return 0;
5691}
5692
5693static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5694 int cmd)
5695{
5696 struct e1000_adapter *adapter = netdev_priv(netdev);
5697 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005698
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005699 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005700 return -EOPNOTSUPP;
5701
5702 switch (cmd) {
5703 case SIOCGMIIPHY:
5704 data->phy_id = adapter->hw.phy.addr;
5705 break;
5706 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005707 e1000_phy_read_status(adapter);
5708
Bruce Allan7c257692008-04-23 11:09:00 -07005709 switch (data->reg_num & 0x1F) {
5710 case MII_BMCR:
5711 data->val_out = adapter->phy_regs.bmcr;
5712 break;
5713 case MII_BMSR:
5714 data->val_out = adapter->phy_regs.bmsr;
5715 break;
5716 case MII_PHYSID1:
5717 data->val_out = (adapter->hw.phy.id >> 16);
5718 break;
5719 case MII_PHYSID2:
5720 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5721 break;
5722 case MII_ADVERTISE:
5723 data->val_out = adapter->phy_regs.advertise;
5724 break;
5725 case MII_LPA:
5726 data->val_out = adapter->phy_regs.lpa;
5727 break;
5728 case MII_EXPANSION:
5729 data->val_out = adapter->phy_regs.expansion;
5730 break;
5731 case MII_CTRL1000:
5732 data->val_out = adapter->phy_regs.ctrl1000;
5733 break;
5734 case MII_STAT1000:
5735 data->val_out = adapter->phy_regs.stat1000;
5736 break;
5737 case MII_ESTATUS:
5738 data->val_out = adapter->phy_regs.estatus;
5739 break;
5740 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005741 return -EIO;
5742 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005743 break;
5744 case SIOCSMIIREG:
5745 default:
5746 return -EOPNOTSUPP;
5747 }
5748 return 0;
5749}
5750
Bruce Allanb67e1912012-12-27 08:32:33 +00005751/**
5752 * e1000e_hwtstamp_ioctl - control hardware time stamping
5753 * @netdev: network interface device structure
5754 * @ifreq: interface request
5755 *
5756 * Outgoing time stamping can be enabled and disabled. Play nice and
5757 * disable it when requested, although it shouldn't cause any overhead
5758 * when no packet needs it. At most one packet in the queue may be
5759 * marked for time stamping, otherwise it would be impossible to tell
5760 * for sure to which packet the hardware time stamp belongs.
5761 *
5762 * Incoming time stamping has to be configured via the hardware filters.
5763 * Not all combinations are supported, in particular event type has to be
5764 * specified. Matching the kind of event packet is not supported, with the
5765 * exception of "all V2 events regardless of level 2 or 4".
5766 **/
5767static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5768{
5769 struct e1000_adapter *adapter = netdev_priv(netdev);
5770 struct hwtstamp_config config;
5771 int ret_val;
5772
5773 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5774 return -EFAULT;
5775
5776 adapter->hwtstamp_config = config;
5777
5778 ret_val = e1000e_config_hwtstamp(adapter);
5779 if (ret_val)
5780 return ret_val;
5781
5782 config = adapter->hwtstamp_config;
5783
Bruce Alland89777b2013-01-19 01:09:58 +00005784 switch (config.rx_filter) {
5785 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5786 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5787 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5788 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5789 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5790 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5791 /* With V2 type filters which specify a Sync or Delay Request,
5792 * Path Delay Request/Response messages are also time stamped
5793 * by hardware so notify the caller the requested packets plus
5794 * some others are time stamped.
5795 */
5796 config.rx_filter = HWTSTAMP_FILTER_SOME;
5797 break;
5798 default:
5799 break;
5800 }
5801
Bruce Allanb67e1912012-12-27 08:32:33 +00005802 return copy_to_user(ifr->ifr_data, &config,
5803 sizeof(config)) ? -EFAULT : 0;
5804}
5805
Auke Kokbc7f75f2007-09-17 12:30:59 -07005806static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5807{
5808 switch (cmd) {
5809 case SIOCGMIIPHY:
5810 case SIOCGMIIREG:
5811 case SIOCSMIIREG:
5812 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005813 case SIOCSHWTSTAMP:
5814 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005815 default:
5816 return -EOPNOTSUPP;
5817 }
5818}
5819
Bruce Allana4f58f52009-06-02 11:29:18 +00005820static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5821{
5822 struct e1000_hw *hw = &adapter->hw;
5823 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005824 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005825 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005826
5827 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005828 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005829
Bruce Allan2b6b1682011-05-13 07:20:09 +00005830 retval = hw->phy.ops.acquire(hw);
5831 if (retval) {
5832 e_err("Could not acquire PHY\n");
5833 return retval;
5834 }
5835
5836 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5837 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5838 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005839 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005840
5841 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005842 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5843 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005844 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5845 (u16)(mac_reg & 0xFFFF));
5846 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5847 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005848 }
5849
5850 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005851 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005852 mac_reg = er32(RCTL);
5853 if (mac_reg & E1000_RCTL_UPE)
5854 phy_reg |= BM_RCTL_UPE;
5855 if (mac_reg & E1000_RCTL_MPE)
5856 phy_reg |= BM_RCTL_MPE;
5857 phy_reg &= ~(BM_RCTL_MO_MASK);
5858 if (mac_reg & E1000_RCTL_MO_3)
5859 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
Bruce Allan17e813e2013-02-20 04:06:01 +00005860 << BM_RCTL_MO_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00005861 if (mac_reg & E1000_RCTL_BAM)
5862 phy_reg |= BM_RCTL_BAM;
5863 if (mac_reg & E1000_RCTL_PMCF)
5864 phy_reg |= BM_RCTL_PMCF;
5865 mac_reg = er32(CTRL);
5866 if (mac_reg & E1000_CTRL_RFCE)
5867 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005868 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005869
5870 /* enable PHY wakeup in MAC register */
5871 ew32(WUFC, wufc);
5872 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5873
5874 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005875 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5876 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005877
5878 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005879 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5880 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005881 if (retval)
5882 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005883release:
Bruce Allan94d81862009-11-20 23:25:26 +00005884 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005885
5886 return retval;
5887}
5888
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005889static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5890 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891{
5892 struct net_device *netdev = pci_get_drvdata(pdev);
5893 struct e1000_adapter *adapter = netdev_priv(netdev);
5894 struct e1000_hw *hw = &adapter->hw;
5895 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005896 /* Runtime suspend should only enable wakeup for link changes */
5897 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005898 int retval = 0;
5899
5900 netif_device_detach(netdev);
5901
5902 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005903 int count = E1000_CHECK_RESET_COUNT;
5904
5905 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5906 usleep_range(10000, 20000);
5907
Auke Kokbc7f75f2007-09-17 12:30:59 -07005908 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5909 e1000e_down(adapter);
5910 e1000_free_irq(adapter);
5911 }
Bruce Allan4662e822008-08-26 18:37:06 -07005912 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005913
5914 retval = pci_save_state(pdev);
5915 if (retval)
5916 return retval;
5917
5918 status = er32(STATUS);
5919 if (status & E1000_STATUS_LU)
5920 wufc &= ~E1000_WUFC_LNKC;
5921
5922 if (wufc) {
5923 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005924 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005925
5926 /* turn on all-multi mode if wake on multicast is enabled */
5927 if (wufc & E1000_WUFC_MC) {
5928 rctl = er32(RCTL);
5929 rctl |= E1000_RCTL_MPE;
5930 ew32(RCTL, rctl);
5931 }
5932
5933 ctrl = er32(CTRL);
5934 /* advertise wake from D3Cold */
5935 #define E1000_CTRL_ADVD3WUC 0x00100000
5936 /* phy power management enable */
5937 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005938 ctrl |= E1000_CTRL_ADVD3WUC;
5939 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5940 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005941 ew32(CTRL, ctrl);
5942
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005943 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5944 adapter->hw.phy.media_type ==
5945 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005946 /* keep the laser running in D3 */
5947 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005948 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005949 ew32(CTRL_EXT, ctrl_ext);
5950 }
5951
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005952 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005953 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005954
Auke Kokbc7f75f2007-09-17 12:30:59 -07005955 /* Allow time for pending master requests to run */
5956 e1000e_disable_pcie_master(&adapter->hw);
5957
Bruce Allan82776a42009-08-14 14:35:33 +00005958 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005959 /* enable wakeup by the PHY */
5960 retval = e1000_init_phy_wakeup(adapter, wufc);
5961 if (retval)
5962 return retval;
5963 } else {
5964 /* enable wakeup by the MAC */
5965 ew32(WUFC, wufc);
5966 ew32(WUC, E1000_WUC_PME_EN);
5967 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 } else {
5969 ew32(WUC, 0);
5970 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005971 }
5972
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005973 *enable_wake = !!wufc;
5974
Auke Kokbc7f75f2007-09-17 12:30:59 -07005975 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005976 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5977 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005978 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005979
5980 if (adapter->hw.phy.type == e1000_phy_igp_3)
5981 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5982
Bruce Allane921eb12012-11-28 09:28:37 +00005983 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005984 * would have already happened in close and is redundant.
5985 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005986 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005987
5988 pci_disable_device(pdev);
5989
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005990 return 0;
5991}
5992
5993static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5994{
5995 if (sleep && wake) {
5996 pci_prepare_to_sleep(pdev);
5997 return;
5998 }
5999
6000 pci_wake_from_d3(pdev, wake);
6001 pci_set_power_state(pdev, PCI_D3hot);
6002}
6003
Bruce Allanf0ff4392013-02-20 04:05:39 +00006004static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, bool wake)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006005{
6006 struct net_device *netdev = pci_get_drvdata(pdev);
6007 struct e1000_adapter *adapter = netdev_priv(netdev);
6008
Bruce Allane921eb12012-11-28 09:28:37 +00006009 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006010 * correctable error when the MAC transitions from D0 to D3. To
6011 * prevent this we need to mask off the correctable errors on the
6012 * downstream port of the pci-e switch.
6013 */
6014 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6015 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006016 u16 devctl;
6017
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006018 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6019 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6020 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006021
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006022 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006023
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006024 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006025 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006026 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006027 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006028}
6029
Bruce Allan6f461f62010-04-27 03:33:04 +00006030#ifdef CONFIG_PCIEASPM
6031static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6032{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006033 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006034}
6035#else
6036static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006037{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006038 u16 aspm_ctl = 0;
6039
6040 if (state & PCIE_LINK_STATE_L0S)
6041 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6042 if (state & PCIE_LINK_STATE_L1)
6043 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6044
Bruce Allane921eb12012-11-28 09:28:37 +00006045 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006046 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006047 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006048 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006049
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006050 if (pdev->bus->self)
6051 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006052 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006053}
6054#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006055static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006056{
6057 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6058 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6059 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6060
6061 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006062}
6063
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006064#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006065static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006066{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006067 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006068}
6069
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006070static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006071{
6072 struct net_device *netdev = pci_get_drvdata(pdev);
6073 struct e1000_adapter *adapter = netdev_priv(netdev);
6074 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006075 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006076 u32 err;
6077
Bruce Allan78cd29d2011-03-24 03:09:03 +00006078 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6079 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6080 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6081 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6082 if (aspm_disable_flag)
6083 e1000e_disable_aspm(pdev, aspm_disable_flag);
6084
Auke Kokbc7f75f2007-09-17 12:30:59 -07006085 pci_set_power_state(pdev, PCI_D0);
6086 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006087 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006088
Bruce Allan4662e822008-08-26 18:37:06 -07006089 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006090 if (netif_running(netdev)) {
6091 err = e1000_request_irq(adapter);
6092 if (err)
6093 return err;
6094 }
6095
Bruce Allan2fbe4522012-04-19 03:21:47 +00006096 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006097 e1000_resume_workarounds_pchlan(&adapter->hw);
6098
Auke Kokbc7f75f2007-09-17 12:30:59 -07006099 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006100
6101 /* report the system wakeup cause from S3/S4 */
6102 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6103 u16 phy_data;
6104
6105 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6106 if (phy_data) {
6107 e_info("PHY Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006108 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6109 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6110 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6111 phy_data & E1000_WUS_MAG ? "Magic Packet" :
6112 phy_data & E1000_WUS_LNKC ?
6113 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006114 }
6115 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6116 } else {
6117 u32 wus = er32(WUS);
6118 if (wus) {
6119 e_info("MAC Wakeup cause - %s\n",
Bruce Allan17e813e2013-02-20 04:06:01 +00006120 wus & E1000_WUS_EX ? "Unicast Packet" :
6121 wus & E1000_WUS_MC ? "Multicast Packet" :
6122 wus & E1000_WUS_BC ? "Broadcast Packet" :
6123 wus & E1000_WUS_MAG ? "Magic Packet" :
6124 wus & E1000_WUS_LNKC ? "Link Status Change" :
6125 "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006126 }
6127 ew32(WUS, ~0);
6128 }
6129
Auke Kokbc7f75f2007-09-17 12:30:59 -07006130 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006131
Bruce Allancd791612010-05-10 14:59:51 +00006132 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006133
6134 if (netif_running(netdev))
6135 e1000e_up(adapter);
6136
6137 netif_device_attach(netdev);
6138
Bruce Allane921eb12012-11-28 09:28:37 +00006139 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006140 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006141 * under the control of the driver.
6142 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006143 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006144 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006145
6146 return 0;
6147}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006148
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006149#ifdef CONFIG_PM_SLEEP
6150static int e1000_suspend(struct device *dev)
6151{
6152 struct pci_dev *pdev = to_pci_dev(dev);
6153 int retval;
6154 bool wake;
6155
6156 retval = __e1000_shutdown(pdev, &wake, false);
6157 if (!retval)
6158 e1000_complete_shutdown(pdev, true, wake);
6159
6160 return retval;
6161}
6162
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006163static int e1000_resume(struct device *dev)
6164{
6165 struct pci_dev *pdev = to_pci_dev(dev);
6166 struct net_device *netdev = pci_get_drvdata(pdev);
6167 struct e1000_adapter *adapter = netdev_priv(netdev);
6168
6169 if (e1000e_pm_ready(adapter))
6170 adapter->idle_check = true;
6171
6172 return __e1000_resume(pdev);
6173}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006174#endif /* CONFIG_PM_SLEEP */
6175
6176#ifdef CONFIG_PM_RUNTIME
6177static int e1000_runtime_suspend(struct device *dev)
6178{
6179 struct pci_dev *pdev = to_pci_dev(dev);
6180 struct net_device *netdev = pci_get_drvdata(pdev);
6181 struct e1000_adapter *adapter = netdev_priv(netdev);
6182
6183 if (e1000e_pm_ready(adapter)) {
6184 bool wake;
6185
6186 __e1000_shutdown(pdev, &wake, true);
6187 }
6188
6189 return 0;
6190}
6191
6192static int e1000_idle(struct device *dev)
6193{
6194 struct pci_dev *pdev = to_pci_dev(dev);
6195 struct net_device *netdev = pci_get_drvdata(pdev);
6196 struct e1000_adapter *adapter = netdev_priv(netdev);
6197
6198 if (!e1000e_pm_ready(adapter))
6199 return 0;
6200
6201 if (adapter->idle_check) {
6202 adapter->idle_check = false;
6203 if (!e1000e_has_link(adapter))
6204 pm_schedule_suspend(dev, MSEC_PER_SEC);
6205 }
6206
6207 return -EBUSY;
6208}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006209
6210static int e1000_runtime_resume(struct device *dev)
6211{
6212 struct pci_dev *pdev = to_pci_dev(dev);
6213 struct net_device *netdev = pci_get_drvdata(pdev);
6214 struct e1000_adapter *adapter = netdev_priv(netdev);
6215
6216 if (!e1000e_pm_ready(adapter))
6217 return 0;
6218
6219 adapter->idle_check = !dev->power.runtime_auto;
6220 return __e1000_resume(pdev);
6221}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006222#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006223#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006224
6225static void e1000_shutdown(struct pci_dev *pdev)
6226{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006227 bool wake = false;
6228
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006229 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006230
6231 if (system_state == SYSTEM_POWER_OFF)
6232 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006233}
6234
6235#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006236
Bruce Allan8bb62862013-01-16 08:46:49 +00006237static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006238{
6239 struct net_device *netdev = data;
6240 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006241
6242 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006243 int vector, msix_irq;
6244
Dongdong Deng147b2c82010-11-16 19:50:15 -08006245 vector = 0;
6246 msix_irq = adapter->msix_entries[vector].vector;
6247 disable_irq(msix_irq);
6248 e1000_intr_msix_rx(msix_irq, netdev);
6249 enable_irq(msix_irq);
6250
6251 vector++;
6252 msix_irq = adapter->msix_entries[vector].vector;
6253 disable_irq(msix_irq);
6254 e1000_intr_msix_tx(msix_irq, netdev);
6255 enable_irq(msix_irq);
6256
6257 vector++;
6258 msix_irq = adapter->msix_entries[vector].vector;
6259 disable_irq(msix_irq);
6260 e1000_msix_other(msix_irq, netdev);
6261 enable_irq(msix_irq);
6262 }
6263
6264 return IRQ_HANDLED;
6265}
6266
Bruce Allane921eb12012-11-28 09:28:37 +00006267/**
6268 * e1000_netpoll
6269 * @netdev: network interface device structure
6270 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006271 * Polling 'interrupt' - used by things like netconsole to send skbs
6272 * without having to re-enable interrupts. It's not called while
6273 * the interrupt routine is executing.
6274 */
6275static void e1000_netpoll(struct net_device *netdev)
6276{
6277 struct e1000_adapter *adapter = netdev_priv(netdev);
6278
Dongdong Deng147b2c82010-11-16 19:50:15 -08006279 switch (adapter->int_mode) {
6280 case E1000E_INT_MODE_MSIX:
6281 e1000_intr_msix(adapter->pdev->irq, netdev);
6282 break;
6283 case E1000E_INT_MODE_MSI:
6284 disable_irq(adapter->pdev->irq);
6285 e1000_intr_msi(adapter->pdev->irq, netdev);
6286 enable_irq(adapter->pdev->irq);
6287 break;
6288 default: /* E1000E_INT_MODE_LEGACY */
6289 disable_irq(adapter->pdev->irq);
6290 e1000_intr(adapter->pdev->irq, netdev);
6291 enable_irq(adapter->pdev->irq);
6292 break;
6293 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006294}
6295#endif
6296
6297/**
6298 * e1000_io_error_detected - called when PCI error is detected
6299 * @pdev: Pointer to PCI device
6300 * @state: The current pci connection state
6301 *
6302 * This function is called after a PCI bus error affecting
6303 * this device has been detected.
6304 */
6305static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6306 pci_channel_state_t state)
6307{
6308 struct net_device *netdev = pci_get_drvdata(pdev);
6309 struct e1000_adapter *adapter = netdev_priv(netdev);
6310
6311 netif_device_detach(netdev);
6312
Mike Masonc93b5a72009-06-30 12:45:53 +00006313 if (state == pci_channel_io_perm_failure)
6314 return PCI_ERS_RESULT_DISCONNECT;
6315
Auke Kokbc7f75f2007-09-17 12:30:59 -07006316 if (netif_running(netdev))
6317 e1000e_down(adapter);
6318 pci_disable_device(pdev);
6319
6320 /* Request a slot slot reset. */
6321 return PCI_ERS_RESULT_NEED_RESET;
6322}
6323
6324/**
6325 * e1000_io_slot_reset - called after the pci bus has been reset.
6326 * @pdev: Pointer to PCI device
6327 *
6328 * Restart the card from scratch, as if from a cold-boot. Implementation
6329 * resembles the first-half of the e1000_resume routine.
6330 */
6331static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6332{
6333 struct net_device *netdev = pci_get_drvdata(pdev);
6334 struct e1000_adapter *adapter = netdev_priv(netdev);
6335 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006336 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006337 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006338 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006339
Bruce Allan78cd29d2011-03-24 03:09:03 +00006340 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6341 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006342 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006343 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6344 if (aspm_disable_flag)
6345 e1000e_disable_aspm(pdev, aspm_disable_flag);
6346
Bruce Allanf0f422e2008-08-04 17:21:53 -07006347 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006348 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006349 dev_err(&pdev->dev,
6350 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006351 result = PCI_ERS_RESULT_DISCONNECT;
6352 } else {
6353 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006354 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006355 pci_restore_state(pdev);
6356
6357 pci_enable_wake(pdev, PCI_D3hot, 0);
6358 pci_enable_wake(pdev, PCI_D3cold, 0);
6359
6360 e1000e_reset(adapter);
6361 ew32(WUS, ~0);
6362 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006363 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006364
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006365 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006366
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006367 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006368}
6369
6370/**
6371 * e1000_io_resume - called when traffic can start flowing again.
6372 * @pdev: Pointer to PCI device
6373 *
6374 * This callback is called when the error recovery driver tells us that
6375 * its OK to resume normal operation. Implementation resembles the
6376 * second-half of the e1000_resume routine.
6377 */
6378static void e1000_io_resume(struct pci_dev *pdev)
6379{
6380 struct net_device *netdev = pci_get_drvdata(pdev);
6381 struct e1000_adapter *adapter = netdev_priv(netdev);
6382
Bruce Allancd791612010-05-10 14:59:51 +00006383 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006384
6385 if (netif_running(netdev)) {
6386 if (e1000e_up(adapter)) {
6387 dev_err(&pdev->dev,
6388 "can't bring device back up after reset\n");
6389 return;
6390 }
6391 }
6392
6393 netif_device_attach(netdev);
6394
Bruce Allane921eb12012-11-28 09:28:37 +00006395 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006396 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006397 * under the control of the driver.
6398 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006399 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006400 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006401}
6402
6403static void e1000_print_device_info(struct e1000_adapter *adapter)
6404{
6405 struct e1000_hw *hw = &adapter->hw;
6406 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006407 u32 ret_val;
6408 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006409
6410 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006411 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006412 /* bus width */
6413 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006414 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006415 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006416 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006417 e_info("Intel(R) PRO/%s Network Connection\n",
6418 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006419 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6420 E1000_PBANUM_LENGTH);
6421 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006422 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006423 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6424 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006425}
6426
Auke Kok10aa4c02008-08-04 17:21:20 -07006427static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6428{
6429 struct e1000_hw *hw = &adapter->hw;
6430 int ret_val;
6431 u16 buf = 0;
6432
6433 if (hw->mac.type != e1000_82573)
6434 return;
6435
6436 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006437 le16_to_cpus(&buf);
6438 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006439 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006440 dev_warn(&adapter->pdev->dev,
6441 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006442 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006443}
6444
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006445static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006446 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006447{
6448 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006449 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006450
6451 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6452 adapter->flags |= FLAG_TSO_FORCE;
6453
6454 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006455 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6456 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006457 return 0;
6458
Ben Greear01840392012-02-11 15:39:25 +00006459 if (changed & NETIF_F_RXFCS) {
6460 if (features & NETIF_F_RXFCS) {
6461 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6462 } else {
6463 /* We need to take it back to defaults, which might mean
6464 * stripping is still disabled at the adapter level.
6465 */
6466 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6467 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6468 else
6469 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6470 }
6471 }
6472
Bruce Allan70495a52012-01-11 01:26:50 +00006473 netdev->features = features;
6474
Bruce Allandc221292011-08-19 03:23:48 +00006475 if (netif_running(netdev))
6476 e1000e_reinit_locked(adapter);
6477 else
6478 e1000e_reset(adapter);
6479
6480 return 0;
6481}
6482
Stephen Hemminger651c2462008-11-19 21:57:48 -08006483static const struct net_device_ops e1000e_netdev_ops = {
6484 .ndo_open = e1000_open,
6485 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006486 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006487 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006488 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006489 .ndo_set_mac_address = e1000_set_mac,
6490 .ndo_change_mtu = e1000_change_mtu,
6491 .ndo_do_ioctl = e1000_ioctl,
6492 .ndo_tx_timeout = e1000_tx_timeout,
6493 .ndo_validate_addr = eth_validate_addr,
6494
Stephen Hemminger651c2462008-11-19 21:57:48 -08006495 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6496 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6497#ifdef CONFIG_NET_POLL_CONTROLLER
6498 .ndo_poll_controller = e1000_netpoll,
6499#endif
Bruce Allandc221292011-08-19 03:23:48 +00006500 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006501};
6502
Auke Kokbc7f75f2007-09-17 12:30:59 -07006503/**
6504 * e1000_probe - Device Initialization Routine
6505 * @pdev: PCI device information struct
6506 * @ent: entry in e1000_pci_tbl
6507 *
6508 * Returns 0 on success, negative on failure
6509 *
6510 * e1000_probe initializes an adapter identified by a pci_dev structure.
6511 * The OS initialization, configuring of the adapter private structure,
6512 * and a hardware reset occur.
6513 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006514static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006515{
6516 struct net_device *netdev;
6517 struct e1000_adapter *adapter;
6518 struct e1000_hw *hw;
6519 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006520 resource_size_t mmio_start, mmio_len;
6521 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006522 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006523 u16 aspm_disable_flag = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00006524 int bars, i, err, pci_using_dac;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006525 u16 eeprom_data = 0;
6526 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6527
Bruce Allan78cd29d2011-03-24 03:09:03 +00006528 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6529 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006530 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006531 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6532 if (aspm_disable_flag)
6533 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006534
Bruce Allanf0f422e2008-08-04 17:21:53 -07006535 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006536 if (err)
6537 return err;
6538
6539 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006540 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006541 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006542 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006543 if (!err)
6544 pci_using_dac = 1;
6545 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006546 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006547 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006548 err = dma_set_coherent_mask(&pdev->dev,
6549 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006550 if (err) {
Bruce Allanf0ff4392013-02-20 04:05:39 +00006551 dev_err(&pdev->dev,
6552 "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006553 goto err_dma;
6554 }
6555 }
6556 }
6557
Bruce Allan17e813e2013-02-20 04:06:01 +00006558 bars = pci_select_bars(pdev, IORESOURCE_MEM);
6559 err = pci_request_selected_regions_exclusive(pdev, bars,
6560 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006561 if (err)
6562 goto err_pci_reg;
6563
Xiaotian Feng68eac462009-08-14 14:35:52 +00006564 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006565 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006566
Auke Kokbc7f75f2007-09-17 12:30:59 -07006567 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006568 /* PCI config space info */
6569 err = pci_save_state(pdev);
6570 if (err)
6571 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006572
6573 err = -ENOMEM;
6574 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6575 if (!netdev)
6576 goto err_alloc_etherdev;
6577
Auke Kokbc7f75f2007-09-17 12:30:59 -07006578 SET_NETDEV_DEV(netdev, &pdev->dev);
6579
Tom Herbertf85e4df2010-05-05 14:03:32 +00006580 netdev->irq = pdev->irq;
6581
Auke Kokbc7f75f2007-09-17 12:30:59 -07006582 pci_set_drvdata(pdev, netdev);
6583 adapter = netdev_priv(netdev);
6584 hw = &adapter->hw;
6585 adapter->netdev = netdev;
6586 adapter->pdev = pdev;
6587 adapter->ei = ei;
6588 adapter->pba = ei->pba;
6589 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006590 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006591 adapter->hw.adapter = adapter;
6592 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006593 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006594 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006595
6596 mmio_start = pci_resource_start(pdev, 0);
6597 mmio_len = pci_resource_len(pdev, 0);
6598
6599 err = -EIO;
6600 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6601 if (!adapter->hw.hw_addr)
6602 goto err_ioremap;
6603
6604 if ((adapter->flags & FLAG_HAS_FLASH) &&
6605 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6606 flash_start = pci_resource_start(pdev, 1);
6607 flash_len = pci_resource_len(pdev, 1);
6608 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6609 if (!adapter->hw.flash_address)
6610 goto err_flashmap;
6611 }
6612
6613 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006614 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006615 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006616 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006617 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006618 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006619
6620 netdev->mem_start = mmio_start;
6621 netdev->mem_end = mmio_start + mmio_len;
6622
6623 adapter->bd_number = cards_found++;
6624
Bruce Allan4662e822008-08-26 18:37:06 -07006625 e1000e_check_options(adapter);
6626
Auke Kokbc7f75f2007-09-17 12:30:59 -07006627 /* setup adapter struct */
6628 err = e1000_sw_init(adapter);
6629 if (err)
6630 goto err_sw_init;
6631
Auke Kokbc7f75f2007-09-17 12:30:59 -07006632 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6633 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6634 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6635
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006636 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006637 if (err)
6638 goto err_hw_init;
6639
Bruce Allan4a770352008-10-01 17:18:35 -07006640 if ((adapter->flags & FLAG_IS_ICH) &&
6641 (adapter->flags & FLAG_READ_ONLY_NVM))
6642 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6643
Auke Kokbc7f75f2007-09-17 12:30:59 -07006644 hw->mac.ops.get_bus_info(&adapter->hw);
6645
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006646 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006647
6648 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006649 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006650 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6651 adapter->hw.phy.disable_polarity_correction = 0;
6652 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6653 }
6654
Bruce Allan470a5422012-05-26 06:08:48 +00006655 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006656 dev_info(&pdev->dev,
6657 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006658
Bruce Allandc221292011-08-19 03:23:48 +00006659 /* Set initial default active device features */
6660 netdev->features = (NETIF_F_SG |
6661 NETIF_F_HW_VLAN_RX |
6662 NETIF_F_HW_VLAN_TX |
6663 NETIF_F_TSO |
6664 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006665 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006666 NETIF_F_RXCSUM |
6667 NETIF_F_HW_CSUM);
6668
6669 /* Set user-changeable features (subset of all device features) */
6670 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006671 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006672 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006673 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006674
6675 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6676 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6677
Bruce Allandc221292011-08-19 03:23:48 +00006678 netdev->vlan_features |= (NETIF_F_SG |
6679 NETIF_F_TSO |
6680 NETIF_F_TSO6 |
6681 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006682
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006683 netdev->priv_flags |= IFF_UNICAST_FLT;
6684
Yi Zou7b872a52010-09-22 17:57:58 +00006685 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006686 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006687 netdev->vlan_features |= NETIF_F_HIGHDMA;
6688 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006689
Auke Kokbc7f75f2007-09-17 12:30:59 -07006690 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6691 adapter->flags |= FLAG_MNG_PT_ENABLED;
6692
Bruce Allane921eb12012-11-28 09:28:37 +00006693 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006694 * put the device in a known good starting state
6695 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006696 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6697
Bruce Allane921eb12012-11-28 09:28:37 +00006698 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006699 * attempt. Let's give it a few tries
6700 */
6701 for (i = 0;; i++) {
6702 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6703 break;
6704 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006705 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006706 err = -EIO;
6707 goto err_eeprom;
6708 }
6709 }
6710
Auke Kok10aa4c02008-08-04 17:21:20 -07006711 e1000_eeprom_checks(adapter);
6712
Bruce Allan608f8a02010-01-13 02:04:58 +00006713 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006714 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006715 dev_err(&pdev->dev,
6716 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006717
6718 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006719
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006720 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006721 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006722 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006723 err = -EIO;
6724 goto err_eeprom;
6725 }
6726
6727 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006728 adapter->watchdog_timer.function = e1000_watchdog;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006729 adapter->watchdog_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006730
6731 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006732 adapter->phy_info_timer.function = e1000_update_phy_info;
Bruce Allan53aa82d2013-02-20 04:06:06 +00006733 adapter->phy_info_timer.data = (unsigned long)adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006734
6735 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6736 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006737 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6738 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006739 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006740
Auke Kokbc7f75f2007-09-17 12:30:59 -07006741 /* Initialize link parameters. User can change them with ethtool */
6742 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006743 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006744 adapter->hw.fc.requested_mode = e1000_fc_default;
6745 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006746 adapter->hw.phy.autoneg_advertised = 0x2f;
6747
6748 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006749 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6750 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006751
Bruce Allane921eb12012-11-28 09:28:37 +00006752 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006753 * the EEPROM, enable the ACPI Magic Packet filter
6754 */
6755 if (adapter->flags & FLAG_APME_IN_WUC) {
6756 /* APME bit in EEPROM is mapped to WUC.APME */
6757 eeprom_data = er32(WUC);
6758 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006759 if ((hw->mac.type > e1000_ich10lan) &&
6760 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006761 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006762 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6763 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6764 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006765 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6766 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006767 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006768 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6769 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006770 }
6771
6772 /* fetch WoL from EEPROM */
6773 if (eeprom_data & eeprom_apme_mask)
6774 adapter->eeprom_wol |= E1000_WUFC_MAG;
6775
Bruce Allane921eb12012-11-28 09:28:37 +00006776 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006777 * where the eeprom may be wrong or the board simply won't support
6778 * wake on lan on a particular port
6779 */
6780 if (!(adapter->flags & FLAG_HAS_WOL))
6781 adapter->eeprom_wol = 0;
6782
6783 /* initialize the wol settings based on the eeprom settings */
6784 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006785 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006786
Bruce Allan84527592008-11-21 17:00:22 -08006787 /* save off EEPROM version number */
6788 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6789
Auke Kokbc7f75f2007-09-17 12:30:59 -07006790 /* reset the hardware with the new settings */
6791 e1000e_reset(adapter);
6792
Bruce Allane921eb12012-11-28 09:28:37 +00006793 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006794 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006795 * under the control of the driver.
6796 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006797 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006798 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006799
Bruce Allanf2315bf2011-12-16 00:46:59 +00006800 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006801 err = register_netdev(netdev);
6802 if (err)
6803 goto err_register;
6804
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006805 /* carrier off reporting is important to ethtool even BEFORE open */
6806 netif_carrier_off(netdev);
6807
Bruce Alland89777b2013-01-19 01:09:58 +00006808 /* init PTP hardware clock */
6809 e1000e_ptp_init(adapter);
6810
Auke Kokbc7f75f2007-09-17 12:30:59 -07006811 e1000_print_device_info(adapter);
6812
Alan Sternf3ec4f82010-06-08 15:23:51 -04006813 if (pci_dev_run_wake(pdev))
6814 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006815
Auke Kokbc7f75f2007-09-17 12:30:59 -07006816 return 0;
6817
6818err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006819 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006820 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006821err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006822 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006823 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006824err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006825 kfree(adapter->tx_ring);
6826 kfree(adapter->rx_ring);
6827err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006828 if (adapter->hw.flash_address)
6829 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006830 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006831err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006832 iounmap(adapter->hw.hw_addr);
6833err_ioremap:
6834 free_netdev(netdev);
6835err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006836 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006837 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006838err_pci_reg:
6839err_dma:
6840 pci_disable_device(pdev);
6841 return err;
6842}
6843
6844/**
6845 * e1000_remove - Device Removal Routine
6846 * @pdev: PCI device information struct
6847 *
6848 * e1000_remove is called by the PCI subsystem to alert the driver
6849 * that it should release a PCI device. The could be caused by a
6850 * Hot-Plug event, or because the driver is going to be removed from
6851 * memory.
6852 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006853static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006854{
6855 struct net_device *netdev = pci_get_drvdata(pdev);
6856 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006857 bool down = test_bit(__E1000_DOWN, &adapter->state);
6858
Bruce Alland89777b2013-01-19 01:09:58 +00006859 e1000e_ptp_remove(adapter);
6860
Bruce Allane921eb12012-11-28 09:28:37 +00006861 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006862 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006863 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006864 if (!down)
6865 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006866 del_timer_sync(&adapter->watchdog_timer);
6867 del_timer_sync(&adapter->phy_info_timer);
6868
Bruce Allan41cec6f2009-11-20 23:28:56 +00006869 cancel_work_sync(&adapter->reset_task);
6870 cancel_work_sync(&adapter->watchdog_task);
6871 cancel_work_sync(&adapter->downshift_task);
6872 cancel_work_sync(&adapter->update_phy_task);
6873 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006874
Bruce Allanb67e1912012-12-27 08:32:33 +00006875 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6876 cancel_work_sync(&adapter->tx_hwtstamp_work);
6877 if (adapter->tx_hwtstamp_skb) {
6878 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6879 adapter->tx_hwtstamp_skb = NULL;
6880 }
6881 }
6882
Bruce Allan17f208d2009-12-01 15:47:22 +00006883 if (!(netdev->flags & IFF_UP))
6884 e1000_power_down_phy(adapter);
6885
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006886 /* Don't lie to e1000_close() down the road. */
6887 if (!down)
6888 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006889 unregister_netdev(netdev);
6890
Alan Sternf3ec4f82010-06-08 15:23:51 -04006891 if (pci_dev_run_wake(pdev))
6892 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006893
Bruce Allane921eb12012-11-28 09:28:37 +00006894 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006895 * would have already happened in close and is redundant.
6896 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006897 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006898
Bruce Allan4662e822008-08-26 18:37:06 -07006899 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006900 kfree(adapter->tx_ring);
6901 kfree(adapter->rx_ring);
6902
6903 iounmap(adapter->hw.hw_addr);
6904 if (adapter->hw.flash_address)
6905 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006906 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006907 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006908
6909 free_netdev(netdev);
6910
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006911 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006912 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006913
Auke Kokbc7f75f2007-09-17 12:30:59 -07006914 pci_disable_device(pdev);
6915}
6916
6917/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006918static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006919 .error_detected = e1000_io_error_detected,
6920 .slot_reset = e1000_io_slot_reset,
6921 .resume = e1000_io_resume,
6922};
6923
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006924static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006925 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6926 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6927 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
Bruce Allanc29c3ba2013-02-20 04:05:50 +00006928 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
6929 board_82571 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006930 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6931 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006932 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006935
Auke Kokbc7f75f2007-09-17 12:30:59 -07006936 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006940
Auke Kokbc7f75f2007-09-17 12:30:59 -07006941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6942 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006944
Bruce Allan4662e822008-08-26 18:37:06 -07006945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006946 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006948
Auke Kokbc7f75f2007-09-17 12:30:59 -07006949 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6950 board_80003es2lan },
6951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6952 board_80003es2lan },
6953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6954 board_80003es2lan },
6955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6956 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006957
Auke Kokbc7f75f2007-09-17 12:30:59 -07006958 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006966
Auke Kokbc7f75f2007-09-17 12:30:59 -07006967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6968 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006972 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6976
6977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006980
Bruce Allanf4187b52008-08-26 18:36:50 -07006981 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006984
Bruce Allana4f58f52009-06-02 11:29:18 +00006985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6989
Bruce Alland3738bb2010-06-16 13:27:28 +00006990 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6991 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6992
Bruce Allan2fbe4522012-04-19 03:21:47 +00006993 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6994 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006995 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6996 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006997
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006998 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006999};
7000MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
7001
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007002#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007003static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07007004 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
Bruce Allan17e813e2013-02-20 04:06:01 +00007005 SET_RUNTIME_PM_OPS(e1000_runtime_suspend, e1000_runtime_resume,
7006 e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007007};
David S. Millere50208a2010-03-16 23:36:24 -07007008#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007009
Auke Kokbc7f75f2007-09-17 12:30:59 -07007010/* PCI Device API Driver */
7011static struct pci_driver e1000_driver = {
7012 .name = e1000e_driver_name,
7013 .id_table = e1000_pci_tbl,
7014 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007015 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007016#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007017 .driver = {
7018 .pm = &e1000_pm_ops,
7019 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007020#endif
7021 .shutdown = e1000_shutdown,
7022 .err_handler = &e1000_err_handler
7023};
7024
7025/**
7026 * e1000_init_module - Driver Registration Routine
7027 *
7028 * e1000_init_module is the first routine called when the driver is
7029 * loaded. All it does is register with the PCI subsystem.
7030 **/
7031static int __init e1000_init_module(void)
7032{
7033 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007034 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7035 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007036 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007037 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007038
Auke Kokbc7f75f2007-09-17 12:30:59 -07007039 return ret;
7040}
7041module_init(e1000_init_module);
7042
7043/**
7044 * e1000_exit_module - Driver Exit Cleanup Routine
7045 *
7046 * e1000_exit_module is called just before the driver is removed
7047 * from memory.
7048 **/
7049static void __exit e1000_exit_module(void)
7050{
7051 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007052}
7053module_exit(e1000_exit_module);
7054
7055
7056MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7057MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7058MODULE_LICENSE("GPL");
7059MODULE_VERSION(DRV_VERSION);
7060
Bruce Allan06c24b92012-02-23 03:13:13 +00007061/* netdev.c */