blob: 247f61f77e5df3f9e0d6b98b194966ccbe91d4de [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 &
1433 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
1434 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,
1471 u16 length)
1472{
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 Allan97ac8ca2008-04-29 09:16:05 -07001499
1500 i = rx_ring->next_to_clean;
Bruce Allan5f450212011-07-22 06:21:46 +00001501 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1502 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001503 buffer_info = &rx_ring->buffer_info[i];
1504
Bruce Allan5f450212011-07-22 06:21:46 +00001505 while (staterr & E1000_RXD_STAT_DD) {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001506 struct sk_buff *skb;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001507
1508 if (*work_done >= work_to_do)
1509 break;
1510 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00001511 rmb(); /* read descriptor and rx_buffer_info after status DD */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001512
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001513 skb = buffer_info->skb;
1514 buffer_info->skb = NULL;
1515
1516 ++i;
1517 if (i == rx_ring->count)
1518 i = 0;
Bruce Allan5f450212011-07-22 06:21:46 +00001519 next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001520 prefetch(next_rxd);
1521
1522 next_buffer = &rx_ring->buffer_info[i];
1523
1524 cleaned = true;
1525 cleaned_count++;
Nick Nunley0be3f552010-04-27 13:09:05 +00001526 dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
1527 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001528 buffer_info->dma = 0;
1529
Bruce Allan5f450212011-07-22 06:21:46 +00001530 length = le16_to_cpu(rx_desc->wb.upper.length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001531
1532 /* errors is only valid for DD + EOP descriptors */
Bruce Allan5f450212011-07-22 06:21:46 +00001533 if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
Ben Greearcf955e62012-02-11 15:39:51 +00001534 ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
1535 !(netdev->features & NETIF_F_RXALL)))) {
Bruce Allan5f450212011-07-22 06:21:46 +00001536 /* recycle both page and skb */
1537 buffer_info->skb = skb;
1538 /* an error means any chain goes out the window too */
1539 if (rx_ring->rx_skb_top)
1540 dev_kfree_skb_irq(rx_ring->rx_skb_top);
1541 rx_ring->rx_skb_top = NULL;
1542 goto next_desc;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001543 }
1544
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 */
1555 skb_fill_page_desc(rxtop,
1556 skb_shinfo(rxtop)->nr_frags,
1557 buffer_info->page, 0, length);
1558 /* re-use the skb, only consumed the page */
1559 buffer_info->skb = skb;
1560 }
1561 e1000_consume_page(buffer_info, rxtop, length);
1562 goto next_desc;
1563 } else {
1564 if (rxtop) {
1565 /* end of the chain */
1566 skb_fill_page_desc(rxtop,
1567 skb_shinfo(rxtop)->nr_frags,
1568 buffer_info->page, 0, length);
1569 /* re-use the current skb, we only consumed the
Bruce Allane921eb12012-11-28 09:28:37 +00001570 * page
1571 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001572 buffer_info->skb = skb;
1573 skb = rxtop;
1574 rxtop = NULL;
1575 e1000_consume_page(buffer_info, skb, length);
1576 } else {
1577 /* no chain, got EOP, this buf is the packet
Bruce Allane921eb12012-11-28 09:28:37 +00001578 * copybreak to save the put_page/alloc_page
1579 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001580 if (length <= copybreak &&
1581 skb_tailroom(skb) >= length) {
1582 u8 *vaddr;
Cong Wang46790262011-11-25 23:14:23 +08001583 vaddr = kmap_atomic(buffer_info->page);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001584 memcpy(skb_tail_pointer(skb), vaddr,
1585 length);
Cong Wang46790262011-11-25 23:14:23 +08001586 kunmap_atomic(vaddr);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001587 /* re-use the page, so don't erase
Bruce Allane921eb12012-11-28 09:28:37 +00001588 * buffer_info->page
1589 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001590 skb_put(skb, length);
1591 } else {
1592 skb_fill_page_desc(skb, 0,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001593 buffer_info->page, 0,
1594 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001595 e1000_consume_page(buffer_info, skb,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001596 length);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001597 }
1598 }
1599 }
1600
Bruce Allan2e1706f2012-06-30 20:02:42 +00001601 /* Receive Checksum Offload */
1602 e1000_rx_checksum(adapter, staterr, skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001603
Bruce Allan70495a52012-01-11 01:26:50 +00001604 e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
1605
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001606 /* probably a little skewed due to removing CRC */
1607 total_rx_bytes += skb->len;
1608 total_rx_packets++;
1609
1610 /* eth type trans needs skb->data to point to something */
1611 if (!pskb_may_pull(skb, ETH_HLEN)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001612 e_err("pskb_may_pull failed.\n");
Bruce Allanef5ab892011-02-10 08:17:21 +00001613 dev_kfree_skb_irq(skb);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001614 goto next_desc;
1615 }
1616
Bruce Allan5f450212011-07-22 06:21:46 +00001617 e1000_receive_skb(adapter, netdev, skb, staterr,
1618 rx_desc->wb.upper.vlan);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001619
1620next_desc:
Bruce Allan5f450212011-07-22 06:21:46 +00001621 rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001622
1623 /* return some buffers to hardware, one at a time is too slow */
1624 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
Bruce Allan55aa6982011-12-16 00:45:45 +00001625 adapter->alloc_rx_buf(rx_ring, cleaned_count,
Jeff Kirsherc2fed992011-07-12 16:10:12 +00001626 GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001627 cleaned_count = 0;
1628 }
1629
1630 /* use prefetched values */
1631 rx_desc = next_rxd;
1632 buffer_info = next_buffer;
Bruce Allan5f450212011-07-22 06:21:46 +00001633
1634 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001635 }
1636 rx_ring->next_to_clean = i;
1637
1638 cleaned_count = e1000_desc_unused(rx_ring);
1639 if (cleaned_count)
Bruce Allan55aa6982011-12-16 00:45:45 +00001640 adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001641
1642 adapter->total_rx_bytes += total_rx_bytes;
1643 adapter->total_rx_packets += total_rx_packets;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001644 return cleaned;
1645}
1646
1647/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001648 * e1000_clean_rx_ring - Free Rx Buffers per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00001649 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00001651static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652{
Bruce Allan55aa6982011-12-16 00:45:45 +00001653 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 struct e1000_buffer *buffer_info;
1655 struct e1000_ps_page *ps_page;
1656 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657 unsigned int i, j;
1658
1659 /* Free all the Rx ring sk_buffs */
1660 for (i = 0; i < rx_ring->count; i++) {
1661 buffer_info = &rx_ring->buffer_info[i];
1662 if (buffer_info->dma) {
1663 if (adapter->clean_rx == e1000_clean_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001664 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001665 adapter->rx_buffer_len,
Nick Nunley0be3f552010-04-27 13:09:05 +00001666 DMA_FROM_DEVICE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001667 else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
Nick Nunley0be3f552010-04-27 13:09:05 +00001668 dma_unmap_page(&pdev->dev, buffer_info->dma,
Bruce Allanf0ff4392013-02-20 04:05:39 +00001669 PAGE_SIZE, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670 else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
Nick Nunley0be3f552010-04-27 13:09:05 +00001671 dma_unmap_single(&pdev->dev, buffer_info->dma,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 adapter->rx_ps_bsize0,
Nick Nunley0be3f552010-04-27 13:09:05 +00001673 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674 buffer_info->dma = 0;
1675 }
1676
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001677 if (buffer_info->page) {
1678 put_page(buffer_info->page);
1679 buffer_info->page = NULL;
1680 }
1681
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 if (buffer_info->skb) {
1683 dev_kfree_skb(buffer_info->skb);
1684 buffer_info->skb = NULL;
1685 }
1686
1687 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Auke Kok47f44e42007-10-25 13:57:44 -07001688 ps_page = &buffer_info->ps_pages[j];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 if (!ps_page->page)
1690 break;
Nick Nunley0be3f552010-04-27 13:09:05 +00001691 dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
1692 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693 ps_page->dma = 0;
1694 put_page(ps_page->page);
1695 ps_page->page = NULL;
1696 }
1697 }
1698
1699 /* there also may be some cached data from a chained receive */
1700 if (rx_ring->rx_skb_top) {
1701 dev_kfree_skb(rx_ring->rx_skb_top);
1702 rx_ring->rx_skb_top = NULL;
1703 }
1704
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 /* Zero out the descriptor ring */
1706 memset(rx_ring->desc, 0, rx_ring->size);
1707
1708 rx_ring->next_to_clean = 0;
1709 rx_ring->next_to_use = 0;
Jesse Brandeburgb94b5022010-01-19 14:15:59 +00001710 adapter->flags2 &= ~FLAG2_IS_DISCARDING;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711
Bruce Allanc5083cf2011-12-16 00:45:40 +00001712 writel(0, rx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00001713 if (rx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
1714 e1000e_update_rdt_wa(rx_ring, 0);
1715 else
1716 writel(0, rx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717}
1718
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001719static void e1000e_downshift_workaround(struct work_struct *work)
1720{
1721 struct e1000_adapter *adapter = container_of(work,
1722 struct e1000_adapter, downshift_task);
1723
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00001724 if (test_bit(__E1000_DOWN, &adapter->state))
1725 return;
1726
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001727 e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
1728}
1729
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730/**
1731 * e1000_intr_msi - Interrupt Handler
1732 * @irq: interrupt number
1733 * @data: pointer to a network interface device structure
1734 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001735static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736{
1737 struct net_device *netdev = data;
1738 struct e1000_adapter *adapter = netdev_priv(netdev);
1739 struct e1000_hw *hw = &adapter->hw;
1740 u32 icr = er32(ICR);
1741
Bruce Allane921eb12012-11-28 09:28:37 +00001742 /* read ICR disables interrupts using IAM */
dave graham573cca82009-02-10 12:52:05 +00001743 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001744 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001745 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001746 * disconnect (LSC) before accessing any PHY registers
1747 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1749 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001750 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751
Bruce Allane921eb12012-11-28 09:28:37 +00001752 /* 80003ES2LAN workaround-- For packet buffer work-around on
Auke Kokbc7f75f2007-09-17 12:30:59 -07001753 * link down event; disable receives here in the ISR and reset
Bruce Allanad680762008-03-28 09:15:03 -07001754 * adapter in watchdog
1755 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756 if (netif_carrier_ok(netdev) &&
1757 adapter->flags & FLAG_RX_NEEDS_RESTART) {
1758 /* disable receives */
1759 u32 rctl = er32(RCTL);
1760 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001761 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 }
1763 /* guard against interrupt when we're going down */
1764 if (!test_bit(__E1000_DOWN, &adapter->state))
1765 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1766 }
1767
Bruce Allan94fb8482013-01-23 09:00:03 +00001768 /* Reset on uncorrectable ECC error */
1769 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1770 u32 pbeccsts = er32(PBECCSTS);
1771
1772 adapter->corr_errors +=
1773 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1774 adapter->uncorr_errors +=
1775 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1776 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1777
1778 /* Do the reset outside of interrupt context */
1779 schedule_work(&adapter->reset_task);
1780
1781 /* return immediately since reset is imminent */
1782 return IRQ_HANDLED;
1783 }
1784
Ben Hutchings288379f2009-01-19 16:43:59 -08001785 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001786 adapter->total_tx_bytes = 0;
1787 adapter->total_tx_packets = 0;
1788 adapter->total_rx_bytes = 0;
1789 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001790 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 }
1792
1793 return IRQ_HANDLED;
1794}
1795
1796/**
1797 * e1000_intr - Interrupt Handler
1798 * @irq: interrupt number
1799 * @data: pointer to a network interface device structure
1800 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001801static irqreturn_t e1000_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802{
1803 struct net_device *netdev = data;
1804 struct e1000_adapter *adapter = netdev_priv(netdev);
1805 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806 u32 rctl, icr = er32(ICR);
Bruce Allan4662e822008-08-26 18:37:06 -07001807
Bruce Allana68ea772009-11-20 23:23:16 +00001808 if (!icr || test_bit(__E1000_DOWN, &adapter->state))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809 return IRQ_NONE; /* Not our interrupt */
1810
Bruce Allane921eb12012-11-28 09:28:37 +00001811 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
Bruce Allanad680762008-03-28 09:15:03 -07001812 * not set, then the adapter didn't send an interrupt
1813 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001814 if (!(icr & E1000_ICR_INT_ASSERTED))
1815 return IRQ_NONE;
1816
Bruce Allane921eb12012-11-28 09:28:37 +00001817 /* Interrupt Auto-Mask...upon reading ICR,
Bruce Allanad680762008-03-28 09:15:03 -07001818 * interrupts are masked. No need for the
1819 * IMC write
1820 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821
dave graham573cca82009-02-10 12:52:05 +00001822 if (icr & E1000_ICR_LSC) {
Bruce Allanf92518d2012-02-01 11:16:42 +00001823 hw->mac.get_link_status = true;
Bruce Allane921eb12012-11-28 09:28:37 +00001824 /* ICH8 workaround-- Call gig speed drop workaround on cable
Bruce Allanad680762008-03-28 09:15:03 -07001825 * disconnect (LSC) before accessing any PHY registers
1826 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001827 if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
1828 (!(er32(STATUS) & E1000_STATUS_LU)))
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07001829 schedule_work(&adapter->downshift_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830
Bruce Allane921eb12012-11-28 09:28:37 +00001831 /* 80003ES2LAN workaround--
Auke Kokbc7f75f2007-09-17 12:30:59 -07001832 * For packet buffer work-around on link down event;
1833 * disable receives here in the ISR and
1834 * reset adapter in watchdog
1835 */
1836 if (netif_carrier_ok(netdev) &&
1837 (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
1838 /* disable receives */
1839 rctl = er32(RCTL);
1840 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00001841 adapter->flags |= FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 }
1843 /* guard against interrupt when we're going down */
1844 if (!test_bit(__E1000_DOWN, &adapter->state))
1845 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1846 }
1847
Bruce Allan94fb8482013-01-23 09:00:03 +00001848 /* Reset on uncorrectable ECC error */
1849 if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
1850 u32 pbeccsts = er32(PBECCSTS);
1851
1852 adapter->corr_errors +=
1853 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
1854 adapter->uncorr_errors +=
1855 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
1856 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
1857
1858 /* Do the reset outside of interrupt context */
1859 schedule_work(&adapter->reset_task);
1860
1861 /* return immediately since reset is imminent */
1862 return IRQ_HANDLED;
1863 }
1864
Ben Hutchings288379f2009-01-19 16:43:59 -08001865 if (napi_schedule_prep(&adapter->napi)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866 adapter->total_tx_bytes = 0;
1867 adapter->total_tx_packets = 0;
1868 adapter->total_rx_bytes = 0;
1869 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001870 __napi_schedule(&adapter->napi);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001871 }
1872
1873 return IRQ_HANDLED;
1874}
1875
Bruce Allan8bb62862013-01-16 08:46:49 +00001876static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001877{
1878 struct net_device *netdev = data;
1879 struct e1000_adapter *adapter = netdev_priv(netdev);
1880 struct e1000_hw *hw = &adapter->hw;
1881 u32 icr = er32(ICR);
1882
1883 if (!(icr & E1000_ICR_INT_ASSERTED)) {
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001884 if (!test_bit(__E1000_DOWN, &adapter->state))
1885 ew32(IMS, E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001886 return IRQ_NONE;
1887 }
1888
1889 if (icr & adapter->eiac_mask)
1890 ew32(ICS, (icr & adapter->eiac_mask));
1891
1892 if (icr & E1000_ICR_OTHER) {
1893 if (!(icr & E1000_ICR_LSC))
1894 goto no_link_interrupt;
Bruce Allanf92518d2012-02-01 11:16:42 +00001895 hw->mac.get_link_status = true;
Bruce Allan4662e822008-08-26 18:37:06 -07001896 /* guard against interrupt when we're going down */
1897 if (!test_bit(__E1000_DOWN, &adapter->state))
1898 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1899 }
1900
1901no_link_interrupt:
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00001902 if (!test_bit(__E1000_DOWN, &adapter->state))
1903 ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
Bruce Allan4662e822008-08-26 18:37:06 -07001904
1905 return IRQ_HANDLED;
1906}
1907
Bruce Allan8bb62862013-01-16 08:46:49 +00001908static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001909{
1910 struct net_device *netdev = data;
1911 struct e1000_adapter *adapter = netdev_priv(netdev);
1912 struct e1000_hw *hw = &adapter->hw;
1913 struct e1000_ring *tx_ring = adapter->tx_ring;
1914
1915
1916 adapter->total_tx_bytes = 0;
1917 adapter->total_tx_packets = 0;
1918
Bruce Allan55aa6982011-12-16 00:45:45 +00001919 if (!e1000_clean_tx_irq(tx_ring))
Bruce Allan4662e822008-08-26 18:37:06 -07001920 /* Ring was not completely cleaned, so fire another interrupt */
1921 ew32(ICS, tx_ring->ims_val);
1922
1923 return IRQ_HANDLED;
1924}
1925
Bruce Allan8bb62862013-01-16 08:46:49 +00001926static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
Bruce Allan4662e822008-08-26 18:37:06 -07001927{
1928 struct net_device *netdev = data;
1929 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan55aa6982011-12-16 00:45:45 +00001930 struct e1000_ring *rx_ring = adapter->rx_ring;
Bruce Allan4662e822008-08-26 18:37:06 -07001931
1932 /* Write the ITR value calculated at the end of the
1933 * previous interrupt.
1934 */
Bruce Allan55aa6982011-12-16 00:45:45 +00001935 if (rx_ring->set_itr) {
1936 writel(1000000000 / (rx_ring->itr_val * 256),
1937 rx_ring->itr_register);
1938 rx_ring->set_itr = 0;
Bruce Allan4662e822008-08-26 18:37:06 -07001939 }
1940
Ben Hutchings288379f2009-01-19 16:43:59 -08001941 if (napi_schedule_prep(&adapter->napi)) {
Bruce Allan4662e822008-08-26 18:37:06 -07001942 adapter->total_rx_bytes = 0;
1943 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08001944 __napi_schedule(&adapter->napi);
Bruce Allan4662e822008-08-26 18:37:06 -07001945 }
1946 return IRQ_HANDLED;
1947}
1948
1949/**
1950 * e1000_configure_msix - Configure MSI-X hardware
1951 *
1952 * e1000_configure_msix sets up the hardware to properly
1953 * generate MSI-X interrupts.
1954 **/
1955static void e1000_configure_msix(struct e1000_adapter *adapter)
1956{
1957 struct e1000_hw *hw = &adapter->hw;
1958 struct e1000_ring *rx_ring = adapter->rx_ring;
1959 struct e1000_ring *tx_ring = adapter->tx_ring;
1960 int vector = 0;
1961 u32 ctrl_ext, ivar = 0;
1962
1963 adapter->eiac_mask = 0;
1964
1965 /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
1966 if (hw->mac.type == e1000_82574) {
1967 u32 rfctl = er32(RFCTL);
1968 rfctl |= E1000_RFCTL_ACK_DIS;
1969 ew32(RFCTL, rfctl);
1970 }
1971
1972#define E1000_IVAR_INT_ALLOC_VALID 0x8
1973 /* Configure Rx vector */
1974 rx_ring->ims_val = E1000_IMS_RXQ0;
1975 adapter->eiac_mask |= rx_ring->ims_val;
1976 if (rx_ring->itr_val)
1977 writel(1000000000 / (rx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001978 rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001979 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001980 writel(1, rx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001981 ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
1982
1983 /* Configure Tx vector */
1984 tx_ring->ims_val = E1000_IMS_TXQ0;
1985 vector++;
1986 if (tx_ring->itr_val)
1987 writel(1000000000 / (tx_ring->itr_val * 256),
Bruce Allanc5083cf2011-12-16 00:45:40 +00001988 tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001989 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00001990 writel(1, tx_ring->itr_register);
Bruce Allan4662e822008-08-26 18:37:06 -07001991 adapter->eiac_mask |= tx_ring->ims_val;
1992 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
1993
1994 /* set vector for Other Causes, e.g. link changes */
1995 vector++;
1996 ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
1997 if (rx_ring->itr_val)
1998 writel(1000000000 / (rx_ring->itr_val * 256),
1999 hw->hw_addr + E1000_EITR_82574(vector));
2000 else
2001 writel(1, hw->hw_addr + E1000_EITR_82574(vector));
2002
2003 /* Cause Tx interrupts on every write back */
2004 ivar |= (1 << 31);
2005
2006 ew32(IVAR, ivar);
2007
2008 /* enable MSI-X PBA support */
2009 ctrl_ext = er32(CTRL_EXT);
2010 ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
2011
2012 /* Auto-Mask Other interrupts upon ICR read */
Bruce Allan4662e822008-08-26 18:37:06 -07002013 ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
2014 ctrl_ext |= E1000_CTRL_EXT_EIAME;
2015 ew32(CTRL_EXT, ctrl_ext);
2016 e1e_flush();
2017}
2018
2019void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
2020{
2021 if (adapter->msix_entries) {
2022 pci_disable_msix(adapter->pdev);
2023 kfree(adapter->msix_entries);
2024 adapter->msix_entries = NULL;
2025 } else if (adapter->flags & FLAG_MSI_ENABLED) {
2026 pci_disable_msi(adapter->pdev);
2027 adapter->flags &= ~FLAG_MSI_ENABLED;
2028 }
Bruce Allan4662e822008-08-26 18:37:06 -07002029}
2030
2031/**
2032 * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
2033 *
2034 * Attempt to configure interrupts using the best available
2035 * capabilities of the hardware and kernel.
2036 **/
2037void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
2038{
2039 int err;
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002040 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07002041
2042 switch (adapter->int_mode) {
2043 case E1000E_INT_MODE_MSIX:
2044 if (adapter->flags & FLAG_HAS_MSIX) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002045 adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
2046 adapter->msix_entries = kcalloc(adapter->num_vectors,
Bruce Allan4662e822008-08-26 18:37:06 -07002047 sizeof(struct msix_entry),
2048 GFP_KERNEL);
2049 if (adapter->msix_entries) {
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002050 for (i = 0; i < adapter->num_vectors; i++)
Bruce Allan4662e822008-08-26 18:37:06 -07002051 adapter->msix_entries[i].entry = i;
2052
2053 err = pci_enable_msix(adapter->pdev,
2054 adapter->msix_entries,
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002055 adapter->num_vectors);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002056 if (err == 0)
Bruce Allan4662e822008-08-26 18:37:06 -07002057 return;
2058 }
2059 /* MSI-X failed, so fall through and try MSI */
Jeff Kirsheref456f82011-11-03 11:40:28 +00002060 e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002061 e1000e_reset_interrupt_capability(adapter);
2062 }
2063 adapter->int_mode = E1000E_INT_MODE_MSI;
2064 /* Fall through */
2065 case E1000E_INT_MODE_MSI:
2066 if (!pci_enable_msi(adapter->pdev)) {
2067 adapter->flags |= FLAG_MSI_ENABLED;
2068 } else {
2069 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jeff Kirsheref456f82011-11-03 11:40:28 +00002070 e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
Bruce Allan4662e822008-08-26 18:37:06 -07002071 }
2072 /* Fall through */
2073 case E1000E_INT_MODE_LEGACY:
2074 /* Don't do anything; this is the system default */
2075 break;
2076 }
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002077
2078 /* store the number of vectors being used */
2079 adapter->num_vectors = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07002080}
2081
2082/**
2083 * e1000_request_msix - Initialize MSI-X interrupts
2084 *
2085 * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
2086 * kernel.
2087 **/
2088static int e1000_request_msix(struct e1000_adapter *adapter)
2089{
2090 struct net_device *netdev = adapter->netdev;
2091 int err = 0, vector = 0;
2092
2093 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002094 snprintf(adapter->rx_ring->name,
2095 sizeof(adapter->rx_ring->name) - 1,
2096 "%s-rx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002097 else
2098 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
2099 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002100 e1000_intr_msix_rx, 0, adapter->rx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002101 netdev);
2102 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002103 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002104 adapter->rx_ring->itr_register = adapter->hw.hw_addr +
2105 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002106 adapter->rx_ring->itr_val = adapter->itr;
2107 vector++;
2108
2109 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Bruce Allan79f5e842011-01-19 04:20:59 +00002110 snprintf(adapter->tx_ring->name,
2111 sizeof(adapter->tx_ring->name) - 1,
2112 "%s-tx-0", netdev->name);
Bruce Allan4662e822008-08-26 18:37:06 -07002113 else
2114 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
2115 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002116 e1000_intr_msix_tx, 0, adapter->tx_ring->name,
Bruce Allan4662e822008-08-26 18:37:06 -07002117 netdev);
2118 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002119 return err;
Bruce Allanc5083cf2011-12-16 00:45:40 +00002120 adapter->tx_ring->itr_register = adapter->hw.hw_addr +
2121 E1000_EITR_82574(vector);
Bruce Allan4662e822008-08-26 18:37:06 -07002122 adapter->tx_ring->itr_val = adapter->itr;
2123 vector++;
2124
2125 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08002126 e1000_msix_other, 0, netdev->name, netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07002127 if (err)
Bruce Allan5015e532012-02-08 02:55:56 +00002128 return err;
Bruce Allan4662e822008-08-26 18:37:06 -07002129
2130 e1000_configure_msix(adapter);
Bruce Allan5015e532012-02-08 02:55:56 +00002131
Bruce Allan4662e822008-08-26 18:37:06 -07002132 return 0;
Bruce Allan4662e822008-08-26 18:37:06 -07002133}
2134
Bruce Allanf8d59f72008-08-08 18:36:11 -07002135/**
2136 * e1000_request_irq - initialize interrupts
2137 *
2138 * Attempts to configure interrupts using the best available
2139 * capabilities of the hardware and kernel.
2140 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141static int e1000_request_irq(struct e1000_adapter *adapter)
2142{
2143 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 int err;
2145
Bruce Allan4662e822008-08-26 18:37:06 -07002146 if (adapter->msix_entries) {
2147 err = e1000_request_msix(adapter);
2148 if (!err)
2149 return err;
2150 /* fall back to MSI */
2151 e1000e_reset_interrupt_capability(adapter);
2152 adapter->int_mode = E1000E_INT_MODE_MSI;
2153 e1000e_set_interrupt_capability(adapter);
2154 }
2155 if (adapter->flags & FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002156 err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
Bruce Allan4662e822008-08-26 18:37:06 -07002157 netdev->name, netdev);
2158 if (!err)
2159 return err;
2160
2161 /* fall back to legacy interrupt */
2162 e1000e_reset_interrupt_capability(adapter);
2163 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002164 }
2165
Joe Perchesa0607fd2009-11-18 23:29:17 -08002166 err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
Bruce Allan4662e822008-08-26 18:37:06 -07002167 netdev->name, netdev);
2168 if (err)
Bruce Allanf8d59f72008-08-08 18:36:11 -07002169 e_err("Unable to allocate interrupt, Error: %d\n", err);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002170
2171 return err;
2172}
2173
2174static void e1000_free_irq(struct e1000_adapter *adapter)
2175{
2176 struct net_device *netdev = adapter->netdev;
2177
Bruce Allan4662e822008-08-26 18:37:06 -07002178 if (adapter->msix_entries) {
2179 int vector = 0;
2180
2181 free_irq(adapter->msix_entries[vector].vector, netdev);
2182 vector++;
2183
2184 free_irq(adapter->msix_entries[vector].vector, netdev);
2185 vector++;
2186
2187 /* Other Causes interrupt vector */
2188 free_irq(adapter->msix_entries[vector].vector, netdev);
2189 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 }
Bruce Allan4662e822008-08-26 18:37:06 -07002191
2192 free_irq(adapter->pdev->irq, netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193}
2194
2195/**
2196 * e1000_irq_disable - Mask off interrupt generation on the NIC
2197 **/
2198static void e1000_irq_disable(struct e1000_adapter *adapter)
2199{
2200 struct e1000_hw *hw = &adapter->hw;
2201
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202 ew32(IMC, ~0);
Bruce Allan4662e822008-08-26 18:37:06 -07002203 if (adapter->msix_entries)
2204 ew32(EIAC_82574, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002205 e1e_flush();
Jeff Kirsher8e86acd2010-08-02 14:27:23 +00002206
2207 if (adapter->msix_entries) {
2208 int i;
2209 for (i = 0; i < adapter->num_vectors; i++)
2210 synchronize_irq(adapter->msix_entries[i].vector);
2211 } else {
2212 synchronize_irq(adapter->pdev->irq);
2213 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002214}
2215
2216/**
2217 * e1000_irq_enable - Enable default interrupt generation settings
2218 **/
2219static void e1000_irq_enable(struct e1000_adapter *adapter)
2220{
2221 struct e1000_hw *hw = &adapter->hw;
2222
Bruce Allan4662e822008-08-26 18:37:06 -07002223 if (adapter->msix_entries) {
2224 ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
2225 ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
Bruce Allan94fb8482013-01-23 09:00:03 +00002226 } else if (hw->mac.type == e1000_pch_lpt) {
2227 ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
Bruce Allan4662e822008-08-26 18:37:06 -07002228 } else {
2229 ew32(IMS, IMS_ENABLE_MASK);
2230 }
Jesse Brandeburg74ef9c32008-03-21 11:06:52 -07002231 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232}
2233
2234/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002235 * e1000e_get_hw_control - get control of the h/w from f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002236 * @adapter: address of board private structure
2237 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002238 * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002239 * For ASF and Pass Through versions of f/w this means that
2240 * the driver is loaded. For AMT version (only with 82573)
2241 * of the f/w this means that the network i/f is open.
2242 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002243void e1000e_get_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244{
2245 struct e1000_hw *hw = &adapter->hw;
2246 u32 ctrl_ext;
2247 u32 swsm;
2248
2249 /* Let firmware know the driver has taken over */
2250 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2251 swsm = er32(SWSM);
2252 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
2253 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2254 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002255 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002256 }
2257}
2258
2259/**
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002260 * e1000e_release_hw_control - release control of the h/w to f/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261 * @adapter: address of board private structure
2262 *
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002263 * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002264 * For ASF and Pass Through versions of f/w this means that the
2265 * driver is no longer loaded. For AMT version (only with 82573) i
2266 * of the f/w this means that the network i/f is closed.
2267 *
2268 **/
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002269void e1000e_release_hw_control(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270{
2271 struct e1000_hw *hw = &adapter->hw;
2272 u32 ctrl_ext;
2273 u32 swsm;
2274
2275 /* Let firmware taken over control of h/w */
2276 if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
2277 swsm = er32(SWSM);
2278 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
2279 } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
2280 ctrl_ext = er32(CTRL_EXT);
Bruce Allanad680762008-03-28 09:15:03 -07002281 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002282 }
2283}
2284
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002286 * e1000_alloc_ring_dma - allocate memory for a ring structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002287 **/
2288static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
2289 struct e1000_ring *ring)
2290{
2291 struct pci_dev *pdev = adapter->pdev;
2292
2293 ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
2294 GFP_KERNEL);
2295 if (!ring->desc)
2296 return -ENOMEM;
2297
2298 return 0;
2299}
2300
2301/**
2302 * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002303 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002304 *
2305 * Return 0 on success, negative on failure
2306 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002307int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308{
Bruce Allan55aa6982011-12-16 00:45:45 +00002309 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002310 int err = -ENOMEM, size;
2311
2312 size = sizeof(struct e1000_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002313 tx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314 if (!tx_ring->buffer_info)
2315 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316
2317 /* round up to nearest 4K */
2318 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
2319 tx_ring->size = ALIGN(tx_ring->size, 4096);
2320
2321 err = e1000_alloc_ring_dma(adapter, tx_ring);
2322 if (err)
2323 goto err;
2324
2325 tx_ring->next_to_use = 0;
2326 tx_ring->next_to_clean = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327
2328 return 0;
2329err:
2330 vfree(tx_ring->buffer_info);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07002331 e_err("Unable to allocate memory for the transmit descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332 return err;
2333}
2334
2335/**
2336 * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
Bruce Allan55aa6982011-12-16 00:45:45 +00002337 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338 *
2339 * Returns 0 on success, negative on failure
2340 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002341int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342{
Bruce Allan55aa6982011-12-16 00:45:45 +00002343 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kok47f44e42007-10-25 13:57:44 -07002344 struct e1000_buffer *buffer_info;
2345 int i, size, desc_len, err = -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002346
2347 size = sizeof(struct e1000_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002348 rx_ring->buffer_info = vzalloc(size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002349 if (!rx_ring->buffer_info)
2350 goto err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351
Auke Kok47f44e42007-10-25 13:57:44 -07002352 for (i = 0; i < rx_ring->count; i++) {
2353 buffer_info = &rx_ring->buffer_info[i];
2354 buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
2355 sizeof(struct e1000_ps_page),
2356 GFP_KERNEL);
2357 if (!buffer_info->ps_pages)
2358 goto err_pages;
2359 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360
2361 desc_len = sizeof(union e1000_rx_desc_packet_split);
2362
2363 /* Round up to nearest 4K */
2364 rx_ring->size = rx_ring->count * desc_len;
2365 rx_ring->size = ALIGN(rx_ring->size, 4096);
2366
2367 err = e1000_alloc_ring_dma(adapter, rx_ring);
2368 if (err)
Auke Kok47f44e42007-10-25 13:57:44 -07002369 goto err_pages;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370
2371 rx_ring->next_to_clean = 0;
2372 rx_ring->next_to_use = 0;
2373 rx_ring->rx_skb_top = NULL;
2374
2375 return 0;
Auke Kok47f44e42007-10-25 13:57:44 -07002376
2377err_pages:
2378 for (i = 0; i < rx_ring->count; i++) {
2379 buffer_info = &rx_ring->buffer_info[i];
2380 kfree(buffer_info->ps_pages);
2381 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382err:
2383 vfree(rx_ring->buffer_info);
Bruce Allane9262442010-11-24 06:02:06 +00002384 e_err("Unable to allocate memory for the receive descriptor ring\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385 return err;
2386}
2387
2388/**
2389 * e1000_clean_tx_ring - Free Tx Buffers
Bruce Allan55aa6982011-12-16 00:45:45 +00002390 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002391 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002392static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393{
Bruce Allan55aa6982011-12-16 00:45:45 +00002394 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002395 struct e1000_buffer *buffer_info;
2396 unsigned long size;
2397 unsigned int i;
2398
2399 for (i = 0; i < tx_ring->count; i++) {
2400 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00002401 e1000_put_txbuf(tx_ring, buffer_info);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 }
2403
Tom Herbert3f0cfa32011-11-28 16:33:16 +00002404 netdev_reset_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405 size = sizeof(struct e1000_buffer) * tx_ring->count;
2406 memset(tx_ring->buffer_info, 0, size);
2407
2408 memset(tx_ring->desc, 0, tx_ring->size);
2409
2410 tx_ring->next_to_use = 0;
2411 tx_ring->next_to_clean = 0;
2412
Bruce Allanc5083cf2011-12-16 00:45:40 +00002413 writel(0, tx_ring->head);
Bruce Allanbdc125f2012-03-20 03:47:52 +00002414 if (tx_ring->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
2415 e1000e_update_tdt_wa(tx_ring, 0);
2416 else
2417 writel(0, tx_ring->tail);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418}
2419
2420/**
2421 * e1000e_free_tx_resources - Free Tx Resources per Queue
Bruce Allan55aa6982011-12-16 00:45:45 +00002422 * @tx_ring: Tx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423 *
2424 * Free all transmit software resources
2425 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002426void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002427{
Bruce Allan55aa6982011-12-16 00:45:45 +00002428 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002430
Bruce Allan55aa6982011-12-16 00:45:45 +00002431 e1000_clean_tx_ring(tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432
2433 vfree(tx_ring->buffer_info);
2434 tx_ring->buffer_info = NULL;
2435
2436 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2437 tx_ring->dma);
2438 tx_ring->desc = NULL;
2439}
2440
2441/**
2442 * e1000e_free_rx_resources - Free Rx Resources
Bruce Allan55aa6982011-12-16 00:45:45 +00002443 * @rx_ring: Rx descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 *
2445 * Free all receive software resources
2446 **/
Bruce Allan55aa6982011-12-16 00:45:45 +00002447void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002448{
Bruce Allan55aa6982011-12-16 00:45:45 +00002449 struct e1000_adapter *adapter = rx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450 struct pci_dev *pdev = adapter->pdev;
Auke Kok47f44e42007-10-25 13:57:44 -07002451 int i;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002452
Bruce Allan55aa6982011-12-16 00:45:45 +00002453 e1000_clean_rx_ring(rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002455 for (i = 0; i < rx_ring->count; i++)
Auke Kok47f44e42007-10-25 13:57:44 -07002456 kfree(rx_ring->buffer_info[i].ps_pages);
Auke Kok47f44e42007-10-25 13:57:44 -07002457
Auke Kokbc7f75f2007-09-17 12:30:59 -07002458 vfree(rx_ring->buffer_info);
2459 rx_ring->buffer_info = NULL;
2460
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2462 rx_ring->dma);
2463 rx_ring->desc = NULL;
2464}
2465
2466/**
2467 * e1000_update_itr - update the dynamic ITR value based on statistics
Auke Kok489815c2008-02-21 15:11:07 -08002468 * @adapter: pointer to adapter
2469 * @itr_setting: current adapter->itr
2470 * @packets: the number of packets during this measurement interval
2471 * @bytes: the number of bytes during this measurement interval
2472 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473 * Stores a new ITR value based on packets and byte
2474 * counts during the last interrupt. The advantage of per interrupt
2475 * computation is faster updates and more accurate ITR for the current
2476 * traffic pattern. Constants in this function were computed
2477 * based on theoretical maximum wire speed and thresholds were set based
2478 * on testing data as well as attempting to minimize response time
Bruce Allan4662e822008-08-26 18:37:06 -07002479 * while increasing bulk throughput. This functionality is controlled
2480 * by the InterruptThrottleRate module parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002481 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002482static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483{
2484 unsigned int retval = itr_setting;
2485
2486 if (packets == 0)
Bruce Allan5015e532012-02-08 02:55:56 +00002487 return itr_setting;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488
2489 switch (itr_setting) {
2490 case lowest_latency:
2491 /* handle TSO and jumbo frames */
Bruce Allan362e20c2013-02-20 04:05:45 +00002492 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002493 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002494 else if ((packets < 5) && (bytes > 512))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 break;
2497 case low_latency: /* 50 usec aka 20000 ints/s */
2498 if (bytes > 10000) {
2499 /* this if handles the TSO accounting */
Bruce Allan362e20c2013-02-20 04:05:45 +00002500 if (bytes / packets > 8000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501 retval = bulk_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002502 else if ((packets < 10) || ((bytes / packets) > 1200))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 retval = bulk_latency;
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002504 else if ((packets > 35))
Auke Kokbc7f75f2007-09-17 12:30:59 -07002505 retval = lowest_latency;
Bruce Allan362e20c2013-02-20 04:05:45 +00002506 } else if (bytes / packets > 2000) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002507 retval = bulk_latency;
2508 } else if (packets <= 2 && bytes < 512) {
2509 retval = lowest_latency;
2510 }
2511 break;
2512 case bulk_latency: /* 250 usec aka 4000 ints/s */
2513 if (bytes > 25000) {
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002514 if (packets > 35)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 retval = low_latency;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002516 } else if (bytes < 6000) {
2517 retval = low_latency;
2518 }
2519 break;
2520 }
2521
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522 return retval;
2523}
2524
2525static void e1000_set_itr(struct e1000_adapter *adapter)
2526{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 u16 current_itr;
2528 u32 new_itr = adapter->itr;
2529
2530 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2531 if (adapter->link_speed != SPEED_1000) {
2532 current_itr = 0;
2533 new_itr = 4000;
2534 goto set_itr_now;
2535 }
2536
Bruce Allan828bac82010-09-29 21:39:37 +00002537 if (adapter->flags2 & FLAG2_DISABLE_AIM) {
2538 new_itr = 0;
2539 goto set_itr_now;
2540 }
2541
Bruce Allan8bb62862013-01-16 08:46:49 +00002542 adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
2543 adapter->total_tx_packets,
2544 adapter->total_tx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002545 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2546 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2547 adapter->tx_itr = low_latency;
2548
Bruce Allan8bb62862013-01-16 08:46:49 +00002549 adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
2550 adapter->total_rx_packets,
2551 adapter->total_rx_bytes);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2553 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2554 adapter->rx_itr = low_latency;
2555
2556 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2557
2558 switch (current_itr) {
2559 /* counts and packets in update_itr are dependent on these numbers */
2560 case lowest_latency:
2561 new_itr = 70000;
2562 break;
2563 case low_latency:
2564 new_itr = 20000; /* aka hwitr = ~200 */
2565 break;
2566 case bulk_latency:
2567 new_itr = 4000;
2568 break;
2569 default:
2570 break;
2571 }
2572
2573set_itr_now:
2574 if (new_itr != adapter->itr) {
Bruce Allane921eb12012-11-28 09:28:37 +00002575 /* this attempts to bias the interrupt rate towards Bulk
Auke Kokbc7f75f2007-09-17 12:30:59 -07002576 * by adding intermediate steps when interrupt rate is
Bruce Allanad680762008-03-28 09:15:03 -07002577 * increasing
2578 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002579 new_itr = new_itr > adapter->itr ?
Bruce Allanf0ff4392013-02-20 04:05:39 +00002580 min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002581 adapter->itr = new_itr;
Bruce Allan4662e822008-08-26 18:37:06 -07002582 adapter->rx_ring->itr_val = new_itr;
2583 if (adapter->msix_entries)
2584 adapter->rx_ring->set_itr = 1;
2585 else
Bruce Allane3d14b02012-12-05 06:26:51 +00002586 e1000e_write_itr(adapter, new_itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002587 }
2588}
2589
2590/**
Matthew Vick22a4cca2012-07-12 00:02:42 +00002591 * e1000e_write_itr - write the ITR value to the appropriate registers
2592 * @adapter: address of board private structure
2593 * @itr: new ITR value to program
2594 *
2595 * e1000e_write_itr determines if the adapter is in MSI-X mode
2596 * and, if so, writes the EITR registers with the ITR value.
2597 * Otherwise, it writes the ITR value into the ITR register.
2598 **/
2599void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
2600{
2601 struct e1000_hw *hw = &adapter->hw;
2602 u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
2603
2604 if (adapter->msix_entries) {
2605 int vector;
2606
2607 for (vector = 0; vector < adapter->num_vectors; vector++)
2608 writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
2609 } else {
2610 ew32(ITR, new_itr);
2611 }
2612}
2613
2614/**
Bruce Allan4662e822008-08-26 18:37:06 -07002615 * e1000_alloc_queues - Allocate memory for all rings
2616 * @adapter: board private structure to initialize
2617 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002618static int e1000_alloc_queues(struct e1000_adapter *adapter)
Bruce Allan4662e822008-08-26 18:37:06 -07002619{
Bruce Allan55aa6982011-12-16 00:45:45 +00002620 int size = sizeof(struct e1000_ring);
2621
2622 adapter->tx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002623 if (!adapter->tx_ring)
2624 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002625 adapter->tx_ring->count = adapter->tx_ring_count;
2626 adapter->tx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002627
Bruce Allan55aa6982011-12-16 00:45:45 +00002628 adapter->rx_ring = kzalloc(size, GFP_KERNEL);
Bruce Allan4662e822008-08-26 18:37:06 -07002629 if (!adapter->rx_ring)
2630 goto err;
Bruce Allan55aa6982011-12-16 00:45:45 +00002631 adapter->rx_ring->count = adapter->rx_ring_count;
2632 adapter->rx_ring->adapter = adapter;
Bruce Allan4662e822008-08-26 18:37:06 -07002633
2634 return 0;
2635err:
2636 e_err("Unable to allocate memory for queues\n");
2637 kfree(adapter->rx_ring);
2638 kfree(adapter->tx_ring);
2639 return -ENOMEM;
2640}
2641
2642/**
Bruce Allanc58c8a72012-03-20 03:48:19 +00002643 * e1000e_poll - NAPI Rx polling callback
Bruce Allanad680762008-03-28 09:15:03 -07002644 * @napi: struct associated with this polling callback
Bruce Allanc58c8a72012-03-20 03:48:19 +00002645 * @weight: number of packets driver is allowed to process this poll
Auke Kokbc7f75f2007-09-17 12:30:59 -07002646 **/
Bruce Allanc58c8a72012-03-20 03:48:19 +00002647static int e1000e_poll(struct napi_struct *napi, int weight)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002648{
Bruce Allanc58c8a72012-03-20 03:48:19 +00002649 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
2650 napi);
Bruce Allan4662e822008-08-26 18:37:06 -07002651 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 struct net_device *poll_dev = adapter->netdev;
Andy Gospodarek679e8a02009-06-18 11:57:37 +00002653 int tx_cleaned = 1, work_done = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002654
Wang Chen4cf16532008-11-12 23:38:14 -08002655 adapter = netdev_priv(poll_dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656
Bruce Allanc58c8a72012-03-20 03:48:19 +00002657 if (!adapter->msix_entries ||
2658 (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
2659 tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
Bruce Allan4662e822008-08-26 18:37:06 -07002660
Bruce Allanc58c8a72012-03-20 03:48:19 +00002661 adapter->clean_rx(adapter->rx_ring, &work_done, weight);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002662
Alexander Duyck12d04a32009-03-25 22:05:03 +00002663 if (!tx_cleaned)
Bruce Allanc58c8a72012-03-20 03:48:19 +00002664 work_done = weight;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002665
Bruce Allanc58c8a72012-03-20 03:48:19 +00002666 /* If weight not fully consumed, exit the polling mode */
2667 if (work_done < weight) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002668 if (adapter->itr_setting & 3)
2669 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08002670 napi_complete(napi);
Jesse Brandeburga3c69fe2009-03-25 22:05:41 +00002671 if (!test_bit(__E1000_DOWN, &adapter->state)) {
2672 if (adapter->msix_entries)
2673 ew32(IMS, adapter->rx_ring->ims_val);
2674 else
2675 e1000_irq_enable(adapter);
2676 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677 }
2678
2679 return work_done;
2680}
2681
Jiri Pirko8e586132011-12-08 19:52:37 -05002682static int e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683{
2684 struct e1000_adapter *adapter = netdev_priv(netdev);
2685 struct e1000_hw *hw = &adapter->hw;
2686 u32 vfta, index;
2687
2688 /* don't update vlan cookie if already programmed */
2689 if ((adapter->hw.mng_cookie.status &
2690 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2691 (vid == adapter->mng_vlan_id))
Jiri Pirko8e586132011-12-08 19:52:37 -05002692 return 0;
Bruce Allancaaddaf2009-12-01 15:46:43 +00002693
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 /* add VID to filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002695 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2696 index = (vid >> 5) & 0x7F;
2697 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2698 vfta |= (1 << (vid & 0x1F));
2699 hw->mac.ops.write_vfta(hw, index, vfta);
2700 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002701
2702 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002703
2704 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705}
2706
Jiri Pirko8e586132011-12-08 19:52:37 -05002707static int e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002708{
2709 struct e1000_adapter *adapter = netdev_priv(netdev);
2710 struct e1000_hw *hw = &adapter->hw;
2711 u32 vfta, index;
2712
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713 if ((adapter->hw.mng_cookie.status &
2714 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
2715 (vid == adapter->mng_vlan_id)) {
2716 /* release control to f/w */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00002717 e1000e_release_hw_control(adapter);
Jiri Pirko8e586132011-12-08 19:52:37 -05002718 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002719 }
2720
2721 /* remove VID from filter table */
Bruce Allancaaddaf2009-12-01 15:46:43 +00002722 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2723 index = (vid >> 5) & 0x7F;
2724 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
2725 vfta &= ~(1 << (vid & 0x1F));
2726 hw->mac.ops.write_vfta(hw, index, vfta);
2727 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002728
2729 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05002730
2731 return 0;
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002732}
2733
2734/**
2735 * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
2736 * @adapter: board private structure to initialize
2737 **/
2738static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
2739{
2740 struct net_device *netdev = adapter->netdev;
2741 struct e1000_hw *hw = &adapter->hw;
2742 u32 rctl;
2743
2744 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2745 /* disable VLAN receive filtering */
2746 rctl = er32(RCTL);
2747 rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
2748 ew32(RCTL, rctl);
2749
2750 if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
2751 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
2752 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
2753 }
2754 }
2755}
2756
2757/**
2758 * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
2759 * @adapter: board private structure to initialize
2760 **/
2761static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
2762{
2763 struct e1000_hw *hw = &adapter->hw;
2764 u32 rctl;
2765
2766 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
2767 /* enable VLAN receive filtering */
2768 rctl = er32(RCTL);
2769 rctl |= E1000_RCTL_VFE;
2770 rctl &= ~E1000_RCTL_CFIEN;
2771 ew32(RCTL, rctl);
2772 }
2773}
2774
2775/**
2776 * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
2777 * @adapter: board private structure to initialize
2778 **/
2779static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
2780{
2781 struct e1000_hw *hw = &adapter->hw;
2782 u32 ctrl;
2783
2784 /* disable VLAN tag insert/strip */
2785 ctrl = er32(CTRL);
2786 ctrl &= ~E1000_CTRL_VME;
2787 ew32(CTRL, ctrl);
2788}
2789
2790/**
2791 * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
2792 * @adapter: board private structure to initialize
2793 **/
2794static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
2795{
2796 struct e1000_hw *hw = &adapter->hw;
2797 u32 ctrl;
2798
2799 /* enable VLAN tag insert/strip */
2800 ctrl = er32(CTRL);
2801 ctrl |= E1000_CTRL_VME;
2802 ew32(CTRL, ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803}
2804
2805static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
2806{
2807 struct net_device *netdev = adapter->netdev;
2808 u16 vid = adapter->hw.mng_cookie.vlan_id;
2809 u16 old_vid = adapter->mng_vlan_id;
2810
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002811 if (adapter->hw.mng_cookie.status &
2812 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
2813 e1000_vlan_rx_add_vid(netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002814 adapter->mng_vlan_id = vid;
2815 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002816
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002817 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
2818 e1000_vlan_rx_kill_vid(netdev, old_vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819}
2820
2821static void e1000_restore_vlan(struct e1000_adapter *adapter)
2822{
2823 u16 vid;
2824
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002825 e1000_vlan_rx_add_vid(adapter->netdev, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002826
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002827 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Bruce Allanf0ff4392013-02-20 04:05:39 +00002828 e1000_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829}
2830
Bruce Allancd791612010-05-10 14:59:51 +00002831static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832{
2833 struct e1000_hw *hw = &adapter->hw;
Bruce Allancd791612010-05-10 14:59:51 +00002834 u32 manc, manc2h, mdef, i, j;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835
2836 if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
2837 return;
2838
2839 manc = er32(MANC);
2840
Bruce Allane921eb12012-11-28 09:28:37 +00002841 /* enable receiving management packets to the host. this will probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 * generate destination unreachable messages from the host OS, but
Bruce Allanad680762008-03-28 09:15:03 -07002843 * the packets will be handled on SMBUS
2844 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 manc |= E1000_MANC_EN_MNG2HOST;
2846 manc2h = er32(MANC2H);
Bruce Allancd791612010-05-10 14:59:51 +00002847
2848 switch (hw->mac.type) {
2849 default:
2850 manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
2851 break;
2852 case e1000_82574:
2853 case e1000_82583:
Bruce Allane921eb12012-11-28 09:28:37 +00002854 /* Check if IPMI pass-through decision filter already exists;
Bruce Allancd791612010-05-10 14:59:51 +00002855 * if so, enable it.
2856 */
2857 for (i = 0, j = 0; i < 8; i++) {
2858 mdef = er32(MDEF(i));
2859
2860 /* Ignore filters with anything other than IPMI ports */
Dan Carpenter3b21b502010-06-02 13:43:15 +00002861 if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
Bruce Allancd791612010-05-10 14:59:51 +00002862 continue;
2863
2864 /* Enable this decision filter in MANC2H */
2865 if (mdef)
2866 manc2h |= (1 << i);
2867
2868 j |= mdef;
2869 }
2870
2871 if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
2872 break;
2873
2874 /* Create new decision filter in an empty filter */
2875 for (i = 0, j = 0; i < 8; i++)
2876 if (er32(MDEF(i)) == 0) {
2877 ew32(MDEF(i), (E1000_MDEF_PORT_623 |
2878 E1000_MDEF_PORT_664));
2879 manc2h |= (1 << 1);
2880 j++;
2881 break;
2882 }
2883
2884 if (!j)
2885 e_warn("Unable to create IPMI pass-through filter\n");
2886 break;
2887 }
2888
Auke Kokbc7f75f2007-09-17 12:30:59 -07002889 ew32(MANC2H, manc2h);
2890 ew32(MANC, manc);
2891}
2892
2893/**
Bruce Allanaf667a22010-12-31 06:10:01 +00002894 * e1000_configure_tx - Configure Transmit Unit after Reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002895 * @adapter: board private structure
2896 *
2897 * Configure the Tx unit of the MAC after a reset.
2898 **/
2899static void e1000_configure_tx(struct e1000_adapter *adapter)
2900{
2901 struct e1000_hw *hw = &adapter->hw;
2902 struct e1000_ring *tx_ring = adapter->tx_ring;
2903 u64 tdba;
Bruce Allanc550b122011-12-16 00:46:17 +00002904 u32 tdlen, tarc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905
2906 /* Setup the HW Tx Head and Tail descriptor pointers */
2907 tdba = tx_ring->dma;
2908 tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
Bruce Allan1e360522012-03-20 03:48:13 +00002909 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
2910 ew32(TDBAH(0), (tdba >> 32));
2911 ew32(TDLEN(0), tdlen);
2912 ew32(TDH(0), 0);
2913 ew32(TDT(0), 0);
2914 tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
2915 tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 /* Set the Tx Interrupt Delay register */
2918 ew32(TIDV, adapter->tx_int_delay);
Bruce Allanad680762008-03-28 09:15:03 -07002919 /* Tx irq moderation */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920 ew32(TADV, adapter->tx_abs_int_delay);
2921
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002922 if (adapter->flags2 & FLAG2_DMA_BURST) {
2923 u32 txdctl = er32(TXDCTL(0));
2924 txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
2925 E1000_TXDCTL_WTHRESH);
Bruce Allane921eb12012-11-28 09:28:37 +00002926 /* set up some performance related parameters to encourage the
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002927 * hardware to use the bus more efficiently in bursts, depends
2928 * on the tx_int_delay to be enabled,
Hiroaki SHIMODA8edc0e62012-10-10 15:34:20 +00002929 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002930 * hthresh = 1 ==> prefetch when one or more available
2931 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
2932 * BEWARE: this seems to work but should be considered first if
Bruce Allanaf667a22010-12-31 06:10:01 +00002933 * there are Tx hangs or other Tx related bugs
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002934 */
2935 txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
2936 ew32(TXDCTL(0), txdctl);
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002937 }
Bruce Allan56032be2011-12-16 00:46:01 +00002938 /* erratum work around: set txdctl the same for both queues */
2939 ew32(TXDCTL(1), er32(TXDCTL(0)));
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00002940
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002942 tarc = er32(TARC(0));
Bruce Allane921eb12012-11-28 09:28:37 +00002943 /* set the speed mode bit, we'll clear it if we're not at
Bruce Allanad680762008-03-28 09:15:03 -07002944 * gigabit link later
2945 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946#define SPEED_MODE_BIT (1 << 21)
2947 tarc |= SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002948 ew32(TARC(0), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949 }
2950
2951 /* errata: program both queues to unweighted RR */
2952 if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002953 tarc = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002955 ew32(TARC(0), tarc);
2956 tarc = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 tarc |= 1;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002958 ew32(TARC(1), tarc);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002959 }
2960
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 /* Setup Transmit Descriptor Settings for eop descriptor */
2962 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
2963
2964 /* only set IDE if we are delaying interrupts using the timers */
2965 if (adapter->tx_int_delay)
2966 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
2967
2968 /* enable Report Status bit */
2969 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2970
Bruce Allan57cde762012-02-22 09:02:58 +00002971 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972}
2973
2974/**
2975 * e1000_setup_rctl - configure the receive control registers
2976 * @adapter: Board private structure
2977 **/
2978#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
2979 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
2980static void e1000_setup_rctl(struct e1000_adapter *adapter)
2981{
2982 struct e1000_hw *hw = &adapter->hw;
2983 u32 rctl, rfctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 u32 pages = 0;
2985
Bruce Allan2fbe4522012-04-19 03:21:47 +00002986 /* Workaround Si errata on PCHx - configure jumbo frame flow */
2987 if (hw->mac.type >= e1000_pch2lan) {
Bruce Allana1ce6472010-09-22 17:16:40 +00002988 s32 ret_val;
2989
2990 if (adapter->netdev->mtu > ETH_DATA_LEN)
2991 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2992 else
2993 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
Bruce Allandd93f952011-01-06 14:29:48 +00002994
2995 if (ret_val)
2996 e_dbg("failed to enable jumbo frame workaround mode\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00002997 }
2998
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 /* Program MC offset vector base */
3000 rctl = er32(RCTL);
3001 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3002 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
Bruce Allanf0ff4392013-02-20 04:05:39 +00003003 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3004 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005
3006 /* Do not Store bad packets */
3007 rctl &= ~E1000_RCTL_SBP;
3008
3009 /* Enable Long Packet receive */
3010 if (adapter->netdev->mtu <= ETH_DATA_LEN)
3011 rctl &= ~E1000_RCTL_LPE;
3012 else
3013 rctl |= E1000_RCTL_LPE;
3014
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00003015 /* Some systems expect that the CRC is included in SMBUS traffic. The
3016 * hardware strips the CRC before sending to both SMBUS (BMC) and to
3017 * host memory when this is enabled
3018 */
3019 if (adapter->flags2 & FLAG2_CRC_STRIPPING)
3020 rctl |= E1000_RCTL_SECRC;
Auke Kok5918bd82008-02-12 15:20:24 -08003021
Bruce Allana4f58f52009-06-02 11:29:18 +00003022 /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
3023 if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
3024 u16 phy_data;
3025
3026 e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
3027 phy_data &= 0xfff8;
3028 phy_data |= (1 << 2);
3029 e1e_wphy(hw, PHY_REG(770, 26), phy_data);
3030
3031 e1e_rphy(hw, 22, &phy_data);
3032 phy_data &= 0x0fff;
3033 phy_data |= (1 << 14);
3034 e1e_wphy(hw, 0x10, 0x2823);
3035 e1e_wphy(hw, 0x11, 0x0003);
3036 e1e_wphy(hw, 22, phy_data);
3037 }
3038
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 /* Setup buffer sizes */
3040 rctl &= ~E1000_RCTL_SZ_4096;
3041 rctl |= E1000_RCTL_BSEX;
3042 switch (adapter->rx_buffer_len) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003043 case 2048:
3044 default:
3045 rctl |= E1000_RCTL_SZ_2048;
3046 rctl &= ~E1000_RCTL_BSEX;
3047 break;
3048 case 4096:
3049 rctl |= E1000_RCTL_SZ_4096;
3050 break;
3051 case 8192:
3052 rctl |= E1000_RCTL_SZ_8192;
3053 break;
3054 case 16384:
3055 rctl |= E1000_RCTL_SZ_16384;
3056 break;
3057 }
3058
Bruce Allan5f450212011-07-22 06:21:46 +00003059 /* Enable Extended Status in all Receive Descriptors */
3060 rfctl = er32(RFCTL);
3061 rfctl |= E1000_RFCTL_EXTEN;
Matthew Vickf6bd5572012-04-25 08:01:05 +00003062 ew32(RFCTL, rfctl);
Bruce Allan5f450212011-07-22 06:21:46 +00003063
Bruce Allane921eb12012-11-28 09:28:37 +00003064 /* 82571 and greater support packet-split where the protocol
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 * header is placed in skb->data and the packet data is
3066 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
3067 * In the case of a non-split, skb->data is linearly filled,
3068 * followed by the page buffers. Therefore, skb->data is
3069 * sized to hold the largest protocol header.
3070 *
3071 * allocations using alloc_page take too long for regular MTU
3072 * so only enable packet split for jumbo frames
3073 *
3074 * Using pages when the page size is greater than 16k wastes
3075 * a lot of memory, since we allocate 3 pages at all times
3076 * per packet.
3077 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Bruce Allan79d4e902011-12-16 00:46:27 +00003079 if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 adapter->rx_ps_pages = pages;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003081 else
3082 adapter->rx_ps_pages = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003083
3084 if (adapter->rx_ps_pages) {
Bruce Allan90da0662011-01-06 07:02:53 +00003085 u32 psrctl = 0;
3086
Auke Kok140a7482007-10-25 13:57:58 -07003087 /* Enable Packet split descriptors */
3088 rctl |= E1000_RCTL_DTYP_PS;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003089
3090 psrctl |= adapter->rx_ps_bsize0 >>
3091 E1000_PSRCTL_BSIZE0_SHIFT;
3092
3093 switch (adapter->rx_ps_pages) {
3094 case 3:
3095 psrctl |= PAGE_SIZE <<
3096 E1000_PSRCTL_BSIZE3_SHIFT;
3097 case 2:
3098 psrctl |= PAGE_SIZE <<
3099 E1000_PSRCTL_BSIZE2_SHIFT;
3100 case 1:
3101 psrctl |= PAGE_SIZE >>
3102 E1000_PSRCTL_BSIZE1_SHIFT;
3103 break;
3104 }
3105
3106 ew32(PSRCTL, psrctl);
3107 }
3108
Ben Greearcf955e62012-02-11 15:39:51 +00003109 /* This is useful for sniffing bad packets. */
3110 if (adapter->netdev->features & NETIF_F_RXALL) {
3111 /* UPE and MPE will be handled by normal PROMISC logic
Bruce Allane921eb12012-11-28 09:28:37 +00003112 * in e1000e_set_rx_mode
3113 */
Ben Greearcf955e62012-02-11 15:39:51 +00003114 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3115 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3116 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3117
3118 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
3119 E1000_RCTL_DPF | /* Allow filtered pause */
3120 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3121 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3122 * and that breaks VLANs.
3123 */
3124 }
3125
Auke Kokbc7f75f2007-09-17 12:30:59 -07003126 ew32(RCTL, rctl);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003127 /* just started the receive unit, no need to restart */
Bruce Allan12d43f72012-12-05 06:26:14 +00003128 adapter->flags &= ~FLAG_RESTART_NOW;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003129}
3130
3131/**
3132 * e1000_configure_rx - Configure Receive Unit after Reset
3133 * @adapter: board private structure
3134 *
3135 * Configure the Rx unit of the MAC after a reset.
3136 **/
3137static void e1000_configure_rx(struct e1000_adapter *adapter)
3138{
3139 struct e1000_hw *hw = &adapter->hw;
3140 struct e1000_ring *rx_ring = adapter->rx_ring;
3141 u64 rdba;
3142 u32 rdlen, rctl, rxcsum, ctrl_ext;
3143
3144 if (adapter->rx_ps_pages) {
3145 /* this is a 32 byte descriptor */
3146 rdlen = rx_ring->count *
Bruce Allanaf667a22010-12-31 06:10:01 +00003147 sizeof(union e1000_rx_desc_packet_split);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003148 adapter->clean_rx = e1000_clean_rx_irq_ps;
3149 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003150 } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan5f450212011-07-22 06:21:46 +00003151 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003152 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
3153 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003154 } else {
Bruce Allan5f450212011-07-22 06:21:46 +00003155 rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003156 adapter->clean_rx = e1000_clean_rx_irq;
3157 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
3158 }
3159
3160 /* disable receives while setting up the descriptors */
3161 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003162 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3163 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003165 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003166
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003167 if (adapter->flags2 & FLAG2_DMA_BURST) {
Bruce Allane921eb12012-11-28 09:28:37 +00003168 /* set the writeback threshold (only takes effect if the RDTR
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003169 * is set). set GRAN=1 and write back up to 0x4 worth, and
Bruce Allanaf667a22010-12-31 06:10:01 +00003170 * enable prefetching of 0x20 Rx descriptors
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003171 * granularity = 01
3172 * wthresh = 04,
3173 * hthresh = 04,
3174 * pthresh = 0x20
3175 */
3176 ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
3177 ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
3178
Bruce Allane921eb12012-11-28 09:28:37 +00003179 /* override the delay timers for enabling bursting, only if
Jesse Brandeburg3a3b7582010-09-29 21:38:49 +00003180 * the value was not set by the user via module options
3181 */
3182 if (adapter->rx_int_delay == DEFAULT_RDTR)
3183 adapter->rx_int_delay = BURST_RDTR;
3184 if (adapter->rx_abs_int_delay == DEFAULT_RADV)
3185 adapter->rx_abs_int_delay = BURST_RADV;
3186 }
3187
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188 /* set the Receive Delay Timer Register */
3189 ew32(RDTR, adapter->rx_int_delay);
3190
3191 /* irq moderation */
3192 ew32(RADV, adapter->rx_abs_int_delay);
Bruce Allan828bac82010-09-29 21:39:37 +00003193 if ((adapter->itr_setting != 0) && (adapter->itr != 0))
Matthew Vick22a4cca2012-07-12 00:02:42 +00003194 e1000e_write_itr(adapter, adapter->itr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003195
3196 ctrl_ext = er32(CTRL_EXT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197 /* Auto-Mask interrupts upon ICR access */
3198 ctrl_ext |= E1000_CTRL_EXT_IAME;
3199 ew32(IAM, 0xffffffff);
3200 ew32(CTRL_EXT, ctrl_ext);
3201 e1e_flush();
3202
Bruce Allane921eb12012-11-28 09:28:37 +00003203 /* Setup the HW Rx Head and Tail Descriptor Pointers and
Bruce Allanad680762008-03-28 09:15:03 -07003204 * the Base and Length of the Rx Descriptor Ring
3205 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 rdba = rx_ring->dma;
Bruce Allan1e360522012-03-20 03:48:13 +00003207 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
3208 ew32(RDBAH(0), (rdba >> 32));
3209 ew32(RDLEN(0), rdlen);
3210 ew32(RDH(0), 0);
3211 ew32(RDT(0), 0);
3212 rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
3213 rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214
3215 /* Enable Receive Checksum Offload for TCP and UDP */
3216 rxcsum = er32(RXCSUM);
Bruce Allan2e1706f2012-06-30 20:02:42 +00003217 if (adapter->netdev->features & NETIF_F_RXCSUM)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003218 rxcsum |= E1000_RXCSUM_TUOFL;
Bruce Allan2e1706f2012-06-30 20:02:42 +00003219 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07003220 rxcsum &= ~E1000_RXCSUM_TUOFL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003221 ew32(RXCSUM, rxcsum);
3222
Bruce Allan3e35d992013-01-12 07:25:22 +00003223 /* With jumbo frames, excessive C-state transition latencies result
3224 * in dropped transactions.
3225 */
3226 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3227 u32 lat =
3228 ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
3229 adapter->max_frame_size) * 8 / 1000;
3230
3231 if (adapter->flags & FLAG_IS_ICH) {
Bruce Allan53ec5492009-11-20 23:27:40 +00003232 u32 rxdctl = er32(RXDCTL(0));
3233 ew32(RXDCTL(0), rxdctl | 0x3);
Bruce Allan53ec5492009-11-20 23:27:40 +00003234 }
Bruce Allan3e35d992013-01-12 07:25:22 +00003235
3236 pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
3237 } else {
3238 pm_qos_update_request(&adapter->netdev->pm_qos_req,
3239 PM_QOS_DEFAULT_VALUE);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003240 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241
3242 /* Enable Receives */
3243 ew32(RCTL, rctl);
3244}
3245
3246/**
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003247 * e1000e_write_mc_addr_list - write multicast addresses to MTA
Auke Kokbc7f75f2007-09-17 12:30:59 -07003248 * @netdev: network interface device structure
3249 *
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003250 * Writes multicast address list to the MTA hash table.
3251 * Returns: -ENOMEM on failure
3252 * 0 on no addresses written
3253 * X on writing X addresses to MTA
3254 */
3255static int e1000e_write_mc_addr_list(struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003256{
3257 struct e1000_adapter *adapter = netdev_priv(netdev);
3258 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003259 struct netdev_hw_addr *ha;
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003260 u8 *mta_list;
3261 int i;
3262
3263 if (netdev_mc_empty(netdev)) {
3264 /* nothing to program, so clear mc list */
3265 hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
3266 return 0;
3267 }
3268
3269 mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
3270 if (!mta_list)
3271 return -ENOMEM;
3272
3273 /* update_mc_addr_list expects a packed array of only addresses. */
3274 i = 0;
3275 netdev_for_each_mc_addr(ha, netdev)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003276 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003277
3278 hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
3279 kfree(mta_list);
3280
3281 return netdev_mc_count(netdev);
3282}
3283
3284/**
3285 * e1000e_write_uc_addr_list - write unicast addresses to RAR table
3286 * @netdev: network interface device structure
3287 *
3288 * Writes unicast address list to the RAR table.
3289 * Returns: -ENOMEM on failure/insufficient address space
3290 * 0 on no addresses written
3291 * X on writing X addresses to the RAR table
3292 **/
3293static int e1000e_write_uc_addr_list(struct net_device *netdev)
3294{
3295 struct e1000_adapter *adapter = netdev_priv(netdev);
3296 struct e1000_hw *hw = &adapter->hw;
3297 unsigned int rar_entries = hw->mac.rar_entry_count;
3298 int count = 0;
3299
3300 /* save a rar entry for our hardware address */
3301 rar_entries--;
3302
3303 /* save a rar entry for the LAA workaround */
3304 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
3305 rar_entries--;
3306
3307 /* return ENOMEM indicating insufficient memory for addresses */
3308 if (netdev_uc_count(netdev) > rar_entries)
3309 return -ENOMEM;
3310
3311 if (!netdev_uc_empty(netdev) && rar_entries) {
3312 struct netdev_hw_addr *ha;
3313
Bruce Allane921eb12012-11-28 09:28:37 +00003314 /* write the addresses in reverse order to avoid write
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003315 * combining
3316 */
3317 netdev_for_each_uc_addr(ha, netdev) {
3318 if (!rar_entries)
3319 break;
Bruce Allan69e1e012012-04-14 03:28:50 +00003320 hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003321 count++;
3322 }
3323 }
3324
3325 /* zero out the remaining RAR entries not used above */
3326 for (; rar_entries > 0; rar_entries--) {
3327 ew32(RAH(rar_entries), 0);
3328 ew32(RAL(rar_entries), 0);
3329 }
3330 e1e_flush();
3331
3332 return count;
3333}
3334
3335/**
3336 * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
3337 * @netdev: network interface device structure
3338 *
3339 * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
3340 * address list or the network interface flags are updated. This routine is
3341 * responsible for configuring the hardware for proper unicast, multicast,
3342 * promiscuous mode, and all-multi behavior.
3343 **/
3344static void e1000e_set_rx_mode(struct net_device *netdev)
3345{
3346 struct e1000_adapter *adapter = netdev_priv(netdev);
3347 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003348 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349
3350 /* Check for Promiscuous and All Multicast modes */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 rctl = er32(RCTL);
3352
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003353 /* clear the affected bits */
3354 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
3355
Auke Kokbc7f75f2007-09-17 12:30:59 -07003356 if (netdev->flags & IFF_PROMISC) {
3357 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003358 /* Do not hardware filter VLANs in promisc mode */
3359 e1000e_vlan_filter_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003360 } else {
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003361 int count;
Bruce Allan3d3a1672012-02-23 03:13:18 +00003362
Patrick McHardy746b9f02008-07-16 20:15:45 -07003363 if (netdev->flags & IFF_ALLMULTI) {
3364 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003365 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003366 /* Write addresses to the MTA, if the attempt fails
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003367 * then we should just turn on promiscuous mode so
3368 * that we can at least receive multicast traffic
3369 */
3370 count = e1000e_write_mc_addr_list(netdev);
3371 if (count < 0)
3372 rctl |= E1000_RCTL_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003373 }
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003374 e1000e_vlan_filter_enable(adapter);
Bruce Allane921eb12012-11-28 09:28:37 +00003375 /* Write addresses to available RAR registers, if there is not
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003376 * sufficient space to store all the addresses then enable
3377 * unicast promiscuous mode
3378 */
3379 count = e1000e_write_uc_addr_list(netdev);
3380 if (count < 0)
3381 rctl |= E1000_RCTL_UPE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 }
3383
3384 ew32(RCTL, rctl);
3385
Jeff Kirsher86d70e52011-03-25 16:01:01 +00003386 if (netdev->features & NETIF_F_HW_VLAN_RX)
3387 e1000e_vlan_strip_enable(adapter);
3388 else
3389 e1000e_vlan_strip_disable(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003390}
3391
Bruce Allan70495a52012-01-11 01:26:50 +00003392static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
3393{
3394 struct e1000_hw *hw = &adapter->hw;
3395 u32 mrqc, rxcsum;
3396 int i;
3397 static const u32 rsskey[10] = {
3398 0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
3399 0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
3400 };
3401
3402 /* Fill out hash function seed */
3403 for (i = 0; i < 10; i++)
3404 ew32(RSSRK(i), rsskey[i]);
3405
3406 /* Direct all traffic to queue 0 */
3407 for (i = 0; i < 32; i++)
3408 ew32(RETA(i), 0);
3409
Bruce Allane921eb12012-11-28 09:28:37 +00003410 /* Disable raw packet checksumming so that RSS hash is placed in
Bruce Allan70495a52012-01-11 01:26:50 +00003411 * descriptor on writeback.
3412 */
3413 rxcsum = er32(RXCSUM);
3414 rxcsum |= E1000_RXCSUM_PCSD;
3415
3416 ew32(RXCSUM, rxcsum);
3417
3418 mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
3419 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3420 E1000_MRQC_RSS_FIELD_IPV6 |
3421 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3422 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
3423
3424 ew32(MRQC, mrqc);
3425}
3426
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427/**
Bruce Allanb67e1912012-12-27 08:32:33 +00003428 * e1000e_get_base_timinca - get default SYSTIM time increment attributes
3429 * @adapter: board private structure
3430 * @timinca: pointer to returned time increment attributes
3431 *
3432 * Get attributes for incrementing the System Time Register SYSTIML/H at
3433 * the default base frequency, and set the cyclecounter shift value.
3434 **/
Bruce Alland89777b2013-01-19 01:09:58 +00003435s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
Bruce Allanb67e1912012-12-27 08:32:33 +00003436{
3437 struct e1000_hw *hw = &adapter->hw;
3438 u32 incvalue, incperiod, shift;
3439
3440 /* Make sure clock is enabled on I217 before checking the frequency */
3441 if ((hw->mac.type == e1000_pch_lpt) &&
3442 !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
3443 !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
3444 u32 fextnvm7 = er32(FEXTNVM7);
3445
3446 if (!(fextnvm7 & (1 << 0))) {
3447 ew32(FEXTNVM7, fextnvm7 | (1 << 0));
3448 e1e_flush();
3449 }
3450 }
3451
3452 switch (hw->mac.type) {
3453 case e1000_pch2lan:
3454 case e1000_pch_lpt:
3455 /* On I217, the clock frequency is 25MHz or 96MHz as
3456 * indicated by the System Clock Frequency Indication
3457 */
3458 if ((hw->mac.type != e1000_pch_lpt) ||
3459 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
3460 /* Stable 96MHz frequency */
3461 incperiod = INCPERIOD_96MHz;
3462 incvalue = INCVALUE_96MHz;
3463 shift = INCVALUE_SHIFT_96MHz;
3464 adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
3465 break;
3466 }
3467 /* fall-through */
3468 case e1000_82574:
3469 case e1000_82583:
3470 /* Stable 25MHz frequency */
3471 incperiod = INCPERIOD_25MHz;
3472 incvalue = INCVALUE_25MHz;
3473 shift = INCVALUE_SHIFT_25MHz;
3474 adapter->cc.shift = shift;
3475 break;
3476 default:
3477 return -EINVAL;
3478 }
3479
3480 *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
3481 ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
3482
3483 return 0;
3484}
3485
3486/**
3487 * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
3488 * @adapter: board private structure
3489 *
3490 * Outgoing time stamping can be enabled and disabled. Play nice and
3491 * disable it when requested, although it shouldn't cause any overhead
3492 * when no packet needs it. At most one packet in the queue may be
3493 * marked for time stamping, otherwise it would be impossible to tell
3494 * for sure to which packet the hardware time stamp belongs.
3495 *
3496 * Incoming time stamping has to be configured via the hardware filters.
3497 * Not all combinations are supported, in particular event type has to be
3498 * specified. Matching the kind of event packet is not supported, with the
3499 * exception of "all V2 events regardless of level 2 or 4".
3500 **/
3501static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
3502{
3503 struct e1000_hw *hw = &adapter->hw;
3504 struct hwtstamp_config *config = &adapter->hwtstamp_config;
3505 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
3506 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Bruce Alland89777b2013-01-19 01:09:58 +00003507 u32 rxmtrl = 0;
3508 u16 rxudp = 0;
3509 bool is_l4 = false;
3510 bool is_l2 = false;
Bruce Allanb67e1912012-12-27 08:32:33 +00003511 u32 regval;
3512 s32 ret_val;
3513
3514 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3515 return -EINVAL;
3516
3517 /* flags reserved for future extensions - must be zero */
3518 if (config->flags)
3519 return -EINVAL;
3520
3521 switch (config->tx_type) {
3522 case HWTSTAMP_TX_OFF:
3523 tsync_tx_ctl = 0;
3524 break;
3525 case HWTSTAMP_TX_ON:
3526 break;
3527 default:
3528 return -ERANGE;
3529 }
3530
3531 switch (config->rx_filter) {
3532 case HWTSTAMP_FILTER_NONE:
3533 tsync_rx_ctl = 0;
3534 break;
Bruce Alland89777b2013-01-19 01:09:58 +00003535 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3536 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3537 rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
3538 is_l4 = true;
3539 break;
3540 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3541 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
3542 rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
3543 is_l4 = true;
3544 break;
3545 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3546 /* Also time stamps V2 L2 Path Delay Request/Response */
3547 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3548 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3549 is_l2 = true;
3550 break;
3551 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3552 /* Also time stamps V2 L2 Path Delay Request/Response. */
3553 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
3554 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3555 is_l2 = true;
3556 break;
3557 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3558 /* Hardware cannot filter just V2 L4 Sync messages;
3559 * fall-through to V2 (both L2 and L4) Sync.
3560 */
3561 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3562 /* Also time stamps V2 Path Delay Request/Response. */
3563 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3564 rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
3565 is_l2 = true;
3566 is_l4 = true;
3567 break;
3568 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3569 /* Hardware cannot filter just V2 L4 Delay Request messages;
3570 * fall-through to V2 (both L2 and L4) Delay Request.
3571 */
3572 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3573 /* Also time stamps V2 Path Delay Request/Response. */
3574 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
3575 rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
3576 is_l2 = true;
3577 is_l4 = true;
3578 break;
3579 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3580 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3581 /* Hardware cannot filter just V2 L4 or L2 Event messages;
3582 * fall-through to all V2 (both L2 and L4) Events.
3583 */
3584 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3585 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
3586 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
3587 is_l2 = true;
3588 is_l4 = true;
3589 break;
3590 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3591 /* For V1, the hardware can only filter Sync messages or
3592 * Delay Request messages but not both so fall-through to
3593 * time stamp all packets.
3594 */
Bruce Allanb67e1912012-12-27 08:32:33 +00003595 case HWTSTAMP_FILTER_ALL:
Bruce Alland89777b2013-01-19 01:09:58 +00003596 is_l2 = true;
3597 is_l4 = true;
Bruce Allanb67e1912012-12-27 08:32:33 +00003598 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
3599 config->rx_filter = HWTSTAMP_FILTER_ALL;
3600 break;
3601 default:
3602 return -ERANGE;
3603 }
3604
3605 /* enable/disable Tx h/w time stamping */
3606 regval = er32(TSYNCTXCTL);
3607 regval &= ~E1000_TSYNCTXCTL_ENABLED;
3608 regval |= tsync_tx_ctl;
3609 ew32(TSYNCTXCTL, regval);
3610 if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
3611 (regval & E1000_TSYNCTXCTL_ENABLED)) {
3612 e_err("Timesync Tx Control register not set as expected\n");
3613 return -EAGAIN;
3614 }
3615
3616 /* enable/disable Rx h/w time stamping */
3617 regval = er32(TSYNCRXCTL);
3618 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
3619 regval |= tsync_rx_ctl;
3620 ew32(TSYNCRXCTL, regval);
3621 if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
3622 E1000_TSYNCRXCTL_TYPE_MASK)) !=
3623 (regval & (E1000_TSYNCRXCTL_ENABLED |
3624 E1000_TSYNCRXCTL_TYPE_MASK))) {
3625 e_err("Timesync Rx Control register not set as expected\n");
3626 return -EAGAIN;
3627 }
3628
Bruce Alland89777b2013-01-19 01:09:58 +00003629 /* L2: define ethertype filter for time stamped packets */
3630 if (is_l2)
3631 rxmtrl |= ETH_P_1588;
3632
3633 /* define which PTP packets get time stamped */
3634 ew32(RXMTRL, rxmtrl);
3635
3636 /* Filter by destination port */
3637 if (is_l4) {
3638 rxudp = PTP_EV_PORT;
3639 cpu_to_be16s(&rxudp);
3640 }
3641 ew32(RXUDP, rxudp);
3642
3643 e1e_flush();
3644
Bruce Allanb67e1912012-12-27 08:32:33 +00003645 /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
Bruce Allan70806a72013-01-05 05:08:37 +00003646 er32(RXSTMPH);
3647 er32(TXSTMPH);
Bruce Allanb67e1912012-12-27 08:32:33 +00003648
3649 /* Get and set the System Time Register SYSTIM base frequency */
3650 ret_val = e1000e_get_base_timinca(adapter, &regval);
3651 if (ret_val)
3652 return ret_val;
3653 ew32(TIMINCA, regval);
3654
3655 /* reset the ns time counter */
3656 timecounter_init(&adapter->tc, &adapter->cc,
3657 ktime_to_ns(ktime_get_real()));
3658
3659 return 0;
3660}
3661
3662/**
Bruce Allanad680762008-03-28 09:15:03 -07003663 * e1000_configure - configure the hardware for Rx and Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664 * @adapter: private board structure
3665 **/
3666static void e1000_configure(struct e1000_adapter *adapter)
3667{
Bruce Allan55aa6982011-12-16 00:45:45 +00003668 struct e1000_ring *rx_ring = adapter->rx_ring;
3669
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00003670 e1000e_set_rx_mode(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003671
3672 e1000_restore_vlan(adapter);
Bruce Allancd791612010-05-10 14:59:51 +00003673 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003674
3675 e1000_configure_tx(adapter);
Bruce Allan70495a52012-01-11 01:26:50 +00003676
3677 if (adapter->netdev->features & NETIF_F_RXHASH)
3678 e1000e_setup_rss_hash(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679 e1000_setup_rctl(adapter);
3680 e1000_configure_rx(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00003681 adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682}
3683
3684/**
3685 * e1000e_power_up_phy - restore link in case the phy was powered down
3686 * @adapter: address of board private structure
3687 *
3688 * The phy may be powered down to save power and turn off link when the
3689 * driver is unloaded and wake on lan is not enabled (among others)
3690 * *** this routine MUST be followed by a call to e1000e_reset ***
3691 **/
3692void e1000e_power_up_phy(struct e1000_adapter *adapter)
3693{
Bruce Allan17f208d2009-12-01 15:47:22 +00003694 if (adapter->hw.phy.ops.power_up)
3695 adapter->hw.phy.ops.power_up(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696
3697 adapter->hw.mac.ops.setup_link(&adapter->hw);
3698}
3699
3700/**
3701 * e1000_power_down_phy - Power down the PHY
3702 *
Bruce Allan17f208d2009-12-01 15:47:22 +00003703 * Power down the PHY so no link is implied when interface is down.
3704 * The PHY cannot be powered down if management or WoL is active.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003705 */
3706static void e1000_power_down_phy(struct e1000_adapter *adapter)
3707{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003708 /* WoL is enabled */
Auke Kok23b66e22008-02-11 09:25:51 -08003709 if (adapter->wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710 return;
3711
Bruce Allan17f208d2009-12-01 15:47:22 +00003712 if (adapter->hw.phy.ops.power_down)
3713 adapter->hw.phy.ops.power_down(&adapter->hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003714}
3715
3716/**
3717 * e1000e_reset - bring the hardware into a known good state
3718 *
3719 * This function boots the hardware and enables some settings that
3720 * require a configuration cycle of the hardware - those cannot be
3721 * set/changed during runtime. After reset the device needs to be
Bruce Allanad680762008-03-28 09:15:03 -07003722 * properly configured for Rx, Tx etc.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003723 */
3724void e1000e_reset(struct e1000_adapter *adapter)
3725{
3726 struct e1000_mac_info *mac = &adapter->hw.mac;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003727 struct e1000_fc_info *fc = &adapter->hw.fc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 struct e1000_hw *hw = &adapter->hw;
3729 u32 tx_space, min_tx_space, min_rx_space;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003730 u32 pba = adapter->pba;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731 u16 hwm;
3732
Bruce Allanad680762008-03-28 09:15:03 -07003733 /* reset Packet Buffer Allocation to default */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003734 ew32(PBA, pba);
Auke Kokdf762462007-10-25 13:57:53 -07003735
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003736 if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allane921eb12012-11-28 09:28:37 +00003737 /* To maintain wire speed transmits, the Tx FIFO should be
Auke Kokbc7f75f2007-09-17 12:30:59 -07003738 * large enough to accommodate two full transmit packets,
3739 * rounded up to the next 1KB and expressed in KB. Likewise,
3740 * the Rx FIFO should be large enough to accommodate at least
3741 * one full receive packet and is similarly rounded up and
Bruce Allanad680762008-03-28 09:15:03 -07003742 * expressed in KB.
3743 */
Auke Kokdf762462007-10-25 13:57:53 -07003744 pba = er32(PBA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003745 /* upper 16 bits has Tx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003746 tx_space = pba >> 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003747 /* lower 16 bits has Rx packet buffer allocation size in KB */
Auke Kokdf762462007-10-25 13:57:53 -07003748 pba &= 0xffff;
Bruce Allane921eb12012-11-28 09:28:37 +00003749 /* the Tx fifo also stores 16 bytes of information about the Tx
Bruce Allanad680762008-03-28 09:15:03 -07003750 * but don't include ethernet FCS because hardware appends it
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003751 */
3752 min_tx_space = (adapter->max_frame_size +
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753 sizeof(struct e1000_tx_desc) -
3754 ETH_FCS_LEN) * 2;
3755 min_tx_space = ALIGN(min_tx_space, 1024);
3756 min_tx_space >>= 10;
3757 /* software strips receive CRC, so leave room for it */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003758 min_rx_space = adapter->max_frame_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 min_rx_space = ALIGN(min_rx_space, 1024);
3760 min_rx_space >>= 10;
3761
Bruce Allane921eb12012-11-28 09:28:37 +00003762 /* If current Tx allocation is less than the min Tx FIFO size,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 * and the min Tx FIFO size is less than the current Rx FIFO
Bruce Allanad680762008-03-28 09:15:03 -07003764 * allocation, take space away from current Rx allocation
3765 */
Auke Kokdf762462007-10-25 13:57:53 -07003766 if ((tx_space < min_tx_space) &&
3767 ((min_tx_space - tx_space) < pba)) {
3768 pba -= min_tx_space - tx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769
Bruce Allane921eb12012-11-28 09:28:37 +00003770 /* if short on Rx space, Rx wins and must trump Tx
Bruce Allan419e5512012-08-17 06:18:02 +00003771 * adjustment
Bruce Allanad680762008-03-28 09:15:03 -07003772 */
Bruce Allan79d4e902011-12-16 00:46:27 +00003773 if (pba < min_rx_space)
Auke Kokdf762462007-10-25 13:57:53 -07003774 pba = min_rx_space;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775 }
Auke Kokdf762462007-10-25 13:57:53 -07003776
3777 ew32(PBA, pba);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 }
3779
Bruce Allane921eb12012-11-28 09:28:37 +00003780 /* flow control settings
Bruce Allanad680762008-03-28 09:15:03 -07003781 *
Bruce Allan38eb3942009-11-19 12:34:20 +00003782 * The high water mark must be low enough to fit one full frame
Auke Kokbc7f75f2007-09-17 12:30:59 -07003783 * (or the size used for early receive) above it in the Rx FIFO.
3784 * Set it to the lower of:
3785 * - 90% of the Rx FIFO size, and
Bruce Allan38eb3942009-11-19 12:34:20 +00003786 * - the full Rx FIFO size minus one full frame
Bruce Allanad680762008-03-28 09:15:03 -07003787 */
Bruce Alland3738bb2010-06-16 13:27:28 +00003788 if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
3789 fc->pause_time = 0xFFFF;
3790 else
3791 fc->pause_time = E1000_FC_PAUSE_TIME;
Bruce Allanb20caa82012-02-22 09:03:03 +00003792 fc->send_xon = true;
Bruce Alland3738bb2010-06-16 13:27:28 +00003793 fc->current_mode = fc->requested_mode;
3794
3795 switch (hw->mac.type) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003796 case e1000_ich9lan:
3797 case e1000_ich10lan:
3798 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3799 pba = 14;
3800 ew32(PBA, pba);
3801 fc->high_water = 0x2800;
3802 fc->low_water = fc->high_water - 8;
3803 break;
3804 }
3805 /* fall-through */
Bruce Alland3738bb2010-06-16 13:27:28 +00003806 default:
Bruce Allan79d4e902011-12-16 00:46:27 +00003807 hwm = min(((pba << 10) * 9 / 10),
3808 ((pba << 10) - adapter->max_frame_size));
Bruce Alland3738bb2010-06-16 13:27:28 +00003809
3810 fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
3811 fc->low_water = fc->high_water - 8;
3812 break;
3813 case e1000_pchlan:
Bruce Allane921eb12012-11-28 09:28:37 +00003814 /* Workaround PCH LOM adapter hangs with certain network
Bruce Allan38eb3942009-11-19 12:34:20 +00003815 * loads. If hangs persist, try disabling Tx flow control.
3816 */
3817 if (adapter->netdev->mtu > ETH_DATA_LEN) {
3818 fc->high_water = 0x3500;
3819 fc->low_water = 0x1500;
3820 } else {
3821 fc->high_water = 0x5000;
3822 fc->low_water = 0x3000;
3823 }
Bruce Allana3055952010-05-10 15:02:12 +00003824 fc->refresh_time = 0x1000;
Bruce Alland3738bb2010-06-16 13:27:28 +00003825 break;
3826 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003827 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00003828 fc->refresh_time = 0x0400;
Bruce Allan347b5202012-12-08 00:35:35 +00003829
3830 if (adapter->netdev->mtu <= ETH_DATA_LEN) {
3831 fc->high_water = 0x05C20;
3832 fc->low_water = 0x05048;
3833 fc->pause_time = 0x0650;
3834 break;
Bruce Allan828bac82010-09-29 21:39:37 +00003835 }
Bruce Allan347b5202012-12-08 00:35:35 +00003836
3837 fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
3838 fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
Bruce Alland3738bb2010-06-16 13:27:28 +00003839 break;
Bruce Allan38eb3942009-11-19 12:34:20 +00003840 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003841
Bruce Allane921eb12012-11-28 09:28:37 +00003842 /* Alignment of Tx data is on an arbitrary byte boundary with the
Bruce Alland821a4c2012-08-24 20:38:11 +00003843 * maximum size per Tx descriptor limited only to the transmit
3844 * allocation of the packet buffer minus 96 bytes with an upper
3845 * limit of 24KB due to receive synchronization limitations.
3846 */
3847 adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
3848 24 << 10);
3849
Bruce Allane921eb12012-11-28 09:28:37 +00003850 /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
Bruce Allan79d4e902011-12-16 00:46:27 +00003851 * fit in receive buffer.
Bruce Allan828bac82010-09-29 21:39:37 +00003852 */
3853 if (adapter->itr_setting & 0x3) {
Bruce Allan79d4e902011-12-16 00:46:27 +00003854 if ((adapter->max_frame_size * 2) > (pba << 10)) {
Bruce Allan828bac82010-09-29 21:39:37 +00003855 if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
3856 dev_info(&adapter->pdev->dev,
3857 "Interrupt Throttle Rate turned off\n");
3858 adapter->flags2 |= FLAG2_DISABLE_AIM;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003859 e1000e_write_itr(adapter, 0);
Bruce Allan828bac82010-09-29 21:39:37 +00003860 }
3861 } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
3862 dev_info(&adapter->pdev->dev,
3863 "Interrupt Throttle Rate turned on\n");
3864 adapter->flags2 &= ~FLAG2_DISABLE_AIM;
3865 adapter->itr = 20000;
Matthew Vick22a4cca2012-07-12 00:02:42 +00003866 e1000e_write_itr(adapter, adapter->itr);
Bruce Allan828bac82010-09-29 21:39:37 +00003867 }
3868 }
3869
Auke Kokbc7f75f2007-09-17 12:30:59 -07003870 /* Allow time for pending master requests to run */
3871 mac->ops.reset_hw(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003872
Bruce Allane921eb12012-11-28 09:28:37 +00003873 /* For parts with AMT enabled, let the firmware know
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003874 * that the network interface is in control
3875 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07003876 if (adapter->flags & FLAG_HAS_AMT)
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003877 e1000e_get_hw_control(adapter);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003878
Auke Kokbc7f75f2007-09-17 12:30:59 -07003879 ew32(WUC, 0);
3880
3881 if (mac->ops.init_hw(hw))
Jeff Kirsher44defeb2008-08-04 17:20:41 -07003882 e_err("Hardware Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003883
3884 e1000_update_mng_vlan(adapter);
3885
3886 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
3887 ew32(VET, ETH_P_8021Q);
3888
3889 e1000e_reset_adaptive(hw);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003890
Bruce Allanb67e1912012-12-27 08:32:33 +00003891 /* initialize systim and reset the ns time counter */
3892 e1000e_config_hwtstamp(adapter);
3893
Bruce Allan31dbe5b2011-01-06 14:29:52 +00003894 if (!netif_running(adapter->netdev) &&
3895 !test_bit(__E1000_TESTING, &adapter->state)) {
3896 e1000_power_down_phy(adapter);
3897 return;
3898 }
3899
Auke Kokbc7f75f2007-09-17 12:30:59 -07003900 e1000_get_phy_info(hw);
3901
Bruce Allan918d7192009-06-02 11:28:20 +00003902 if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
3903 !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003904 u16 phy_data = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00003905 /* speed up time to link by disabling smart power down, ignore
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 * the return value of this function because there is nothing
Bruce Allanad680762008-03-28 09:15:03 -07003907 * different we would do if it failed
3908 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003909 e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
3910 phy_data &= ~IGP02E1000_PM_SPD;
3911 e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
3912 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913}
3914
3915int e1000e_up(struct e1000_adapter *adapter)
3916{
3917 struct e1000_hw *hw = &adapter->hw;
3918
3919 /* hardware has been reset, we need to reload some things */
3920 e1000_configure(adapter);
3921
3922 clear_bit(__E1000_DOWN, &adapter->state);
3923
Bruce Allan4662e822008-08-26 18:37:06 -07003924 if (adapter->msix_entries)
3925 e1000_configure_msix(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003926 e1000_irq_enable(adapter);
3927
Bruce Allan400484f2011-05-13 07:20:03 +00003928 netif_start_queue(adapter->netdev);
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003929
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930 /* fire a link change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00003931 if (adapter->msix_entries)
3932 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
3933 else
3934 ew32(ICS, E1000_ICS_LSC);
3935
Auke Kokbc7f75f2007-09-17 12:30:59 -07003936 return 0;
3937}
3938
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003939static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
3940{
3941 struct e1000_hw *hw = &adapter->hw;
3942
3943 if (!(adapter->flags2 & FLAG2_DMA_BURST))
3944 return;
3945
3946 /* flush pending descriptor writebacks to memory */
3947 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3948 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3949
3950 /* execute the writes immediately */
3951 e1e_flush();
Matthew Vickbf030852012-03-16 09:03:00 +00003952
Bruce Allane921eb12012-11-28 09:28:37 +00003953 /* due to rare timing issues, write to TIDV/RDTR again to ensure the
Matthew Vickbf030852012-03-16 09:03:00 +00003954 * write is successful
3955 */
3956 ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
3957 ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
3958
3959 /* execute the writes immediately */
3960 e1e_flush();
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00003961}
3962
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003963static void e1000e_update_stats(struct e1000_adapter *adapter);
3964
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965void e1000e_down(struct e1000_adapter *adapter)
3966{
3967 struct net_device *netdev = adapter->netdev;
3968 struct e1000_hw *hw = &adapter->hw;
3969 u32 tctl, rctl;
3970
Bruce Allane921eb12012-11-28 09:28:37 +00003971 /* signal that we're down so the interrupt handler does not
Bruce Allanad680762008-03-28 09:15:03 -07003972 * reschedule our watchdog timer
3973 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974 set_bit(__E1000_DOWN, &adapter->state);
3975
3976 /* disable receives in the hardware */
3977 rctl = er32(RCTL);
David S. Miller823dcd22011-08-20 10:39:12 -07003978 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
3979 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003980 /* flush and sleep below */
3981
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00003982 netif_stop_queue(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983
3984 /* disable transmits in the hardware */
3985 tctl = er32(TCTL);
3986 tctl &= ~E1000_TCTL_EN;
3987 ew32(TCTL, tctl);
David S. Miller823dcd22011-08-20 10:39:12 -07003988
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 /* flush both disables and wait for them to finish */
3990 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00003991 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992
Auke Kokbc7f75f2007-09-17 12:30:59 -07003993 e1000_irq_disable(adapter);
3994
3995 del_timer_sync(&adapter->watchdog_timer);
3996 del_timer_sync(&adapter->phy_info_timer);
3997
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998 netif_carrier_off(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00003999
4000 spin_lock(&adapter->stats64_lock);
4001 e1000e_update_stats(adapter);
4002 spin_unlock(&adapter->stats64_lock);
4003
Bruce Allan400484f2011-05-13 07:20:03 +00004004 e1000e_flush_descriptors(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004005 e1000_clean_tx_ring(adapter->tx_ring);
4006 e1000_clean_rx_ring(adapter->rx_ring);
Bruce Allan400484f2011-05-13 07:20:03 +00004007
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 adapter->link_speed = 0;
4009 adapter->link_duplex = 0;
4010
Jeff Kirsher52cc3082008-06-24 17:01:29 -07004011 if (!pci_channel_offline(adapter->pdev))
4012 e1000e_reset(adapter);
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004013
Bruce Allane921eb12012-11-28 09:28:37 +00004014 /* TODO: for power management, we could drop the link and
Auke Kokbc7f75f2007-09-17 12:30:59 -07004015 * pci_disable_device here.
4016 */
4017}
4018
4019void e1000e_reinit_locked(struct e1000_adapter *adapter)
4020{
4021 might_sleep();
4022 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00004023 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 e1000e_down(adapter);
4025 e1000e_up(adapter);
4026 clear_bit(__E1000_RESETTING, &adapter->state);
4027}
4028
4029/**
Bruce Allanb67e1912012-12-27 08:32:33 +00004030 * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
4031 * @cc: cyclecounter structure
4032 **/
4033static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
4034{
4035 struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
4036 cc);
4037 struct e1000_hw *hw = &adapter->hw;
4038 cycle_t systim;
4039
4040 /* latch SYSTIMH on read of SYSTIML */
4041 systim = (cycle_t)er32(SYSTIML);
4042 systim |= (cycle_t)er32(SYSTIMH) << 32;
4043
4044 return systim;
4045}
4046
4047/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4049 * @adapter: board private structure to initialize
4050 *
4051 * e1000_sw_init initializes the Adapter private data structure.
4052 * Fields are initialized based on PCI device information and
4053 * OS network device settings (MTU size).
4054 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004055static int e1000_sw_init(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004056{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004057 struct net_device *netdev = adapter->netdev;
4058
4059 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
4060 adapter->rx_ps_bsize0 = 128;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004061 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4062 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
Bruce Allan55aa6982011-12-16 00:45:45 +00004063 adapter->tx_ring_count = E1000_DEFAULT_TXD;
4064 adapter->rx_ring_count = E1000_DEFAULT_RXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004065
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004066 spin_lock_init(&adapter->stats64_lock);
4067
Bruce Allan4662e822008-08-26 18:37:06 -07004068 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004069
Bruce Allan4662e822008-08-26 18:37:06 -07004070 if (e1000_alloc_queues(adapter))
4071 return -ENOMEM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004072
Bruce Allanb67e1912012-12-27 08:32:33 +00004073 /* Setup hardware time stamping cyclecounter */
4074 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
4075 adapter->cc.read = e1000e_cyclecounter_read;
4076 adapter->cc.mask = CLOCKSOURCE_MASK(64);
4077 adapter->cc.mult = 1;
4078 /* cc.shift set in e1000e_get_base_tininca() */
4079
4080 spin_lock_init(&adapter->systim_lock);
4081 INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
4082 }
4083
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 /* Explicitly disable IRQ since the NIC can be in any state. */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085 e1000_irq_disable(adapter);
4086
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087 set_bit(__E1000_DOWN, &adapter->state);
4088 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004089}
4090
4091/**
Bruce Allanf8d59f72008-08-08 18:36:11 -07004092 * e1000_intr_msi_test - Interrupt Handler
4093 * @irq: interrupt number
4094 * @data: pointer to a network interface device structure
4095 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00004096static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
Bruce Allanf8d59f72008-08-08 18:36:11 -07004097{
4098 struct net_device *netdev = data;
4099 struct e1000_adapter *adapter = netdev_priv(netdev);
4100 struct e1000_hw *hw = &adapter->hw;
4101 u32 icr = er32(ICR);
4102
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004103 e_dbg("icr is %08X\n", icr);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004104 if (icr & E1000_ICR_RXSEQ) {
4105 adapter->flags &= ~FLAG_MSI_TEST_FAILED;
Bruce Allane921eb12012-11-28 09:28:37 +00004106 /* Force memory writes to complete before acknowledging the
Bruce Allanbc763292012-08-17 06:18:07 +00004107 * interrupt is handled.
4108 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004109 wmb();
4110 }
4111
4112 return IRQ_HANDLED;
4113}
4114
4115/**
4116 * e1000_test_msi_interrupt - Returns 0 for successful test
4117 * @adapter: board private struct
4118 *
4119 * code flow taken from tg3.c
4120 **/
4121static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
4122{
4123 struct net_device *netdev = adapter->netdev;
4124 struct e1000_hw *hw = &adapter->hw;
4125 int err;
4126
4127 /* poll_enable hasn't been called yet, so don't need disable */
4128 /* clear any pending events */
4129 er32(ICR);
4130
4131 /* free the real vector and request a test handler */
4132 e1000_free_irq(adapter);
Bruce Allan4662e822008-08-26 18:37:06 -07004133 e1000e_reset_interrupt_capability(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004134
4135 /* Assume that the test fails, if it succeeds then the test
Bruce Allane921eb12012-11-28 09:28:37 +00004136 * MSI irq handler will unset this flag
4137 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004138 adapter->flags |= FLAG_MSI_TEST_FAILED;
4139
4140 err = pci_enable_msi(adapter->pdev);
4141 if (err)
4142 goto msi_test_failed;
4143
Joe Perchesa0607fd2009-11-18 23:29:17 -08004144 err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
Bruce Allanf8d59f72008-08-08 18:36:11 -07004145 netdev->name, netdev);
4146 if (err) {
4147 pci_disable_msi(adapter->pdev);
4148 goto msi_test_failed;
4149 }
4150
Bruce Allane921eb12012-11-28 09:28:37 +00004151 /* Force memory writes to complete before enabling and firing an
Bruce Allanbc763292012-08-17 06:18:07 +00004152 * interrupt.
4153 */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004154 wmb();
4155
4156 e1000_irq_enable(adapter);
4157
4158 /* fire an unusual interrupt on the test handler */
4159 ew32(ICS, E1000_ICS_RXSEQ);
4160 e1e_flush();
Prasanna S Panchamukhi569a3af2012-04-19 17:01:00 +00004161 msleep(100);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004162
4163 e1000_irq_disable(adapter);
4164
Bruce Allanbc763292012-08-17 06:18:07 +00004165 rmb(); /* read flags after interrupt has been fired */
Bruce Allanf8d59f72008-08-08 18:36:11 -07004166
4167 if (adapter->flags & FLAG_MSI_TEST_FAILED) {
Bruce Allan4662e822008-08-26 18:37:06 -07004168 adapter->int_mode = E1000E_INT_MODE_LEGACY;
Jean Delvare068e8a32010-09-12 22:45:39 +00004169 e_info("MSI interrupt test failed, using legacy interrupt.\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004170 } else {
Jean Delvare068e8a32010-09-12 22:45:39 +00004171 e_dbg("MSI interrupt test succeeded!\n");
Bruce Allan24b706b2012-01-31 06:37:22 +00004172 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004173
4174 free_irq(adapter->pdev->irq, netdev);
4175 pci_disable_msi(adapter->pdev);
4176
Bruce Allanf8d59f72008-08-08 18:36:11 -07004177msi_test_failed:
Bruce Allan4662e822008-08-26 18:37:06 -07004178 e1000e_set_interrupt_capability(adapter);
Jean Delvare068e8a32010-09-12 22:45:39 +00004179 return e1000_request_irq(adapter);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004180}
4181
4182/**
4183 * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
4184 * @adapter: board private struct
4185 *
4186 * code flow taken from tg3.c, called with e1000 interrupts disabled.
4187 **/
4188static int e1000_test_msi(struct e1000_adapter *adapter)
4189{
4190 int err;
4191 u16 pci_cmd;
4192
4193 if (!(adapter->flags & FLAG_MSI_ENABLED))
4194 return 0;
4195
4196 /* disable SERR in case the MSI write causes a master abort */
4197 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
Dean Nelson36f24072010-06-29 18:12:05 +00004198 if (pci_cmd & PCI_COMMAND_SERR)
4199 pci_write_config_word(adapter->pdev, PCI_COMMAND,
4200 pci_cmd & ~PCI_COMMAND_SERR);
Bruce Allanf8d59f72008-08-08 18:36:11 -07004201
4202 err = e1000_test_msi_interrupt(adapter);
4203
Dean Nelson36f24072010-06-29 18:12:05 +00004204 /* re-enable SERR */
4205 if (pci_cmd & PCI_COMMAND_SERR) {
4206 pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
4207 pci_cmd |= PCI_COMMAND_SERR;
4208 pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
4209 }
Bruce Allanf8d59f72008-08-08 18:36:11 -07004210
Bruce Allanf8d59f72008-08-08 18:36:11 -07004211 return err;
4212}
4213
4214/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004215 * e1000_open - Called when a network interface is made active
4216 * @netdev: network interface device structure
4217 *
4218 * Returns 0 on success, negative value on failure
4219 *
4220 * The open entry point is called when a network interface is made
4221 * active by the system (IFF_UP). At this point all resources needed
4222 * for transmit and receive operations are allocated, the interrupt
4223 * handler is registered with the OS, the watchdog timer is started,
4224 * and the stack is notified that the interface is ready.
4225 **/
4226static int e1000_open(struct net_device *netdev)
4227{
4228 struct e1000_adapter *adapter = netdev_priv(netdev);
4229 struct e1000_hw *hw = &adapter->hw;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004230 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231 int err;
4232
4233 /* disallow open during test */
4234 if (test_bit(__E1000_TESTING, &adapter->state))
4235 return -EBUSY;
4236
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004237 pm_runtime_get_sync(&pdev->dev);
4238
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00004239 netif_carrier_off(netdev);
4240
Auke Kokbc7f75f2007-09-17 12:30:59 -07004241 /* allocate transmit descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004242 err = e1000e_setup_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004243 if (err)
4244 goto err_setup_tx;
4245
4246 /* allocate receive descriptors */
Bruce Allan55aa6982011-12-16 00:45:45 +00004247 err = e1000e_setup_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004248 if (err)
4249 goto err_setup_rx;
4250
Bruce Allane921eb12012-11-28 09:28:37 +00004251 /* If AMT is enabled, let the firmware know that the network
Bruce Allan11b08be2010-05-10 14:59:31 +00004252 * interface is now open and reset the part to a known state.
4253 */
4254 if (adapter->flags & FLAG_HAS_AMT) {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004255 e1000e_get_hw_control(adapter);
Bruce Allan11b08be2010-05-10 14:59:31 +00004256 e1000e_reset(adapter);
4257 }
4258
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 e1000e_power_up_phy(adapter);
4260
4261 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4262 if ((adapter->hw.mng_cookie.status &
4263 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
4264 e1000_update_mng_vlan(adapter);
4265
Bruce Allan79d4e902011-12-16 00:46:27 +00004266 /* DMA latency requirement to workaround jumbo issue */
Bruce Allan3e35d992013-01-12 07:25:22 +00004267 pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
4268 PM_QOS_DEFAULT_VALUE);
Florian Micklerc128ec22010-08-02 14:27:00 +00004269
Bruce Allane921eb12012-11-28 09:28:37 +00004270 /* before we allocate an interrupt, we must be ready to handle it.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004271 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
4272 * as soon as we call pci_request_irq, so we have to setup our
Bruce Allanad680762008-03-28 09:15:03 -07004273 * clean_rx handler before we do so.
4274 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004275 e1000_configure(adapter);
4276
4277 err = e1000_request_irq(adapter);
4278 if (err)
4279 goto err_req_irq;
4280
Bruce Allane921eb12012-11-28 09:28:37 +00004281 /* Work around PCIe errata with MSI interrupts causing some chipsets to
Bruce Allanf8d59f72008-08-08 18:36:11 -07004282 * ignore e1000e MSI messages, which means we need to test our MSI
4283 * interrupt now
4284 */
Bruce Allan4662e822008-08-26 18:37:06 -07004285 if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
Bruce Allanf8d59f72008-08-08 18:36:11 -07004286 err = e1000_test_msi(adapter);
4287 if (err) {
4288 e_err("Interrupt allocation failed\n");
4289 goto err_req_irq;
4290 }
4291 }
4292
Auke Kokbc7f75f2007-09-17 12:30:59 -07004293 /* From here on the code is the same as e1000e_up() */
4294 clear_bit(__E1000_DOWN, &adapter->state);
4295
4296 napi_enable(&adapter->napi);
4297
4298 e1000_irq_enable(adapter);
4299
Jeff Kirsher09357b02011-11-18 14:25:00 +00004300 adapter->tx_hang_recheck = false;
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00004301 netif_start_queue(netdev);
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004302
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004303 adapter->idle_check = true;
4304 pm_runtime_put(&pdev->dev);
4305
Auke Kokbc7f75f2007-09-17 12:30:59 -07004306 /* fire a link status change interrupt to start the watchdog */
Bruce Allan52a9b232010-05-10 15:00:10 +00004307 if (adapter->msix_entries)
4308 ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
4309 else
4310 ew32(ICS, E1000_ICS_LSC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004311
4312 return 0;
4313
4314err_req_irq:
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004315 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004316 e1000_power_down_phy(adapter);
Bruce Allan55aa6982011-12-16 00:45:45 +00004317 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004318err_setup_rx:
Bruce Allan55aa6982011-12-16 00:45:45 +00004319 e1000e_free_tx_resources(adapter->tx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004320err_setup_tx:
4321 e1000e_reset(adapter);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004322 pm_runtime_put_sync(&pdev->dev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004323
4324 return err;
4325}
4326
4327/**
4328 * e1000_close - Disables a network interface
4329 * @netdev: network interface device structure
4330 *
4331 * Returns 0, this is not allowed to fail
4332 *
4333 * The close entry point is called when an interface is de-activated
4334 * by the OS. The hardware is still under the drivers control, but
4335 * needs to be disabled. A global MAC reset is issued to stop the
4336 * hardware, and all transmit and receive resources are freed.
4337 **/
4338static int e1000_close(struct net_device *netdev)
4339{
4340 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004341 struct pci_dev *pdev = adapter->pdev;
Bruce Allanbb9e44d2012-03-21 00:39:12 +00004342 int count = E1000_CHECK_RESET_COUNT;
4343
4344 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
4345 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004346
4347 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004348
4349 pm_runtime_get_sync(&pdev->dev);
4350
Bruce Allan5f4a7802011-11-29 08:09:19 +00004351 napi_disable(&adapter->napi);
4352
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004353 if (!test_bit(__E1000_DOWN, &adapter->state)) {
4354 e1000e_down(adapter);
4355 e1000_free_irq(adapter);
4356 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004357 e1000_power_down_phy(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004358
Bruce Allan55aa6982011-12-16 00:45:45 +00004359 e1000e_free_tx_resources(adapter->tx_ring);
4360 e1000e_free_rx_resources(adapter->rx_ring);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004361
Bruce Allane921eb12012-11-28 09:28:37 +00004362 /* kill manageability vlan ID if supported, but not if a vlan with
Bruce Allanad680762008-03-28 09:15:03 -07004363 * the same ID is registered on the host OS (let 8021q kill it)
4364 */
Jeff Kirsher86d70e52011-03-25 16:01:01 +00004365 if (adapter->hw.mng_cookie.status &
4366 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004367 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4368
Bruce Allane921eb12012-11-28 09:28:37 +00004369 /* If AMT is enabled, let the firmware know that the network
Bruce Allanad680762008-03-28 09:15:03 -07004370 * interface is now closed
4371 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00004372 if ((adapter->flags & FLAG_HAS_AMT) &&
4373 !test_bit(__E1000_TESTING, &adapter->state))
4374 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375
Bruce Allan3e35d992013-01-12 07:25:22 +00004376 pm_qos_remove_request(&adapter->netdev->pm_qos_req);
Florian Micklerc128ec22010-08-02 14:27:00 +00004377
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004378 pm_runtime_put_sync(&pdev->dev);
4379
Auke Kokbc7f75f2007-09-17 12:30:59 -07004380 return 0;
4381}
4382/**
4383 * e1000_set_mac - Change the Ethernet Address of the NIC
4384 * @netdev: network interface device structure
4385 * @p: pointer to an address structure
4386 *
4387 * Returns 0 on success, negative on failure
4388 **/
4389static int e1000_set_mac(struct net_device *netdev, void *p)
4390{
4391 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan69e1e012012-04-14 03:28:50 +00004392 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004393 struct sockaddr *addr = p;
4394
4395 if (!is_valid_ether_addr(addr->sa_data))
4396 return -EADDRNOTAVAIL;
4397
4398 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4399 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
4400
Bruce Allan69e1e012012-04-14 03:28:50 +00004401 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004402
4403 if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
4404 /* activate the work around */
4405 e1000e_set_laa_state_82571(&adapter->hw, 1);
4406
Bruce Allane921eb12012-11-28 09:28:37 +00004407 /* Hold a copy of the LAA in RAR[14] This is done so that
Auke Kokbc7f75f2007-09-17 12:30:59 -07004408 * between the time RAR[0] gets clobbered and the time it
4409 * gets fixed (in e1000_watchdog), the actual LAA is in one
4410 * of the RARs and no incoming packets directed to this port
4411 * are dropped. Eventually the LAA will be in RAR[0] and
Bruce Allanad680762008-03-28 09:15:03 -07004412 * RAR[14]
4413 */
Bruce Allan69e1e012012-04-14 03:28:50 +00004414 hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
4415 adapter->hw.mac.rar_entry_count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 }
4417
4418 return 0;
4419}
4420
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004421/**
4422 * e1000e_update_phy_task - work thread to update phy
4423 * @work: pointer to our work struct
4424 *
4425 * this worker thread exists because we must acquire a
4426 * semaphore to read the phy, which we could msleep while
4427 * waiting for it, and we can't msleep in a timer.
4428 **/
4429static void e1000e_update_phy_task(struct work_struct *work)
4430{
4431 struct e1000_adapter *adapter = container_of(work,
4432 struct e1000_adapter, update_phy_task);
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004433
4434 if (test_bit(__E1000_DOWN, &adapter->state))
4435 return;
4436
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004437 e1000_get_phy_info(&adapter->hw);
4438}
4439
Bruce Allane921eb12012-11-28 09:28:37 +00004440/**
4441 * e1000_update_phy_info - timre call-back to update PHY info
4442 * @data: pointer to adapter cast into an unsigned long
4443 *
Bruce Allanad680762008-03-28 09:15:03 -07004444 * Need to wait a few seconds after link up to get diagnostic information from
4445 * the phy
Bruce Allane921eb12012-11-28 09:28:37 +00004446 **/
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447static void e1000_update_phy_info(unsigned long data)
4448{
4449 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004450
4451 if (test_bit(__E1000_DOWN, &adapter->state))
4452 return;
4453
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07004454 schedule_work(&adapter->update_phy_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004455}
4456
4457/**
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004458 * e1000e_update_phy_stats - Update the PHY statistics counters
4459 * @adapter: board private structure
Bruce Allan2b6b1682011-05-13 07:20:09 +00004460 *
4461 * Read/clear the upper 16-bit PHY registers and read/accumulate lower
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004462 **/
4463static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
4464{
4465 struct e1000_hw *hw = &adapter->hw;
4466 s32 ret_val;
4467 u16 phy_data;
4468
4469 ret_val = hw->phy.ops.acquire(hw);
4470 if (ret_val)
4471 return;
4472
Bruce Allane921eb12012-11-28 09:28:37 +00004473 /* A page set is expensive so check if already on desired page.
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004474 * If not, set to the page with the PHY status registers.
4475 */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004476 hw->phy.addr = 1;
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004477 ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
4478 &phy_data);
4479 if (ret_val)
4480 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004481 if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
4482 ret_val = hw->phy.ops.set_page(hw,
4483 HV_STATS_PAGE << IGP_PAGE_SHIFT);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004484 if (ret_val)
4485 goto release;
4486 }
4487
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004488 /* Single Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004489 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4490 ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004491 if (!ret_val)
4492 adapter->stats.scc += phy_data;
4493
4494 /* Excessive Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004495 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4496 ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004497 if (!ret_val)
4498 adapter->stats.ecol += phy_data;
4499
4500 /* Multiple Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004501 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4502 ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004503 if (!ret_val)
4504 adapter->stats.mcc += phy_data;
4505
4506 /* Late Collision Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004507 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4508 ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004509 if (!ret_val)
4510 adapter->stats.latecol += phy_data;
4511
4512 /* Collision Count - also used for adaptive IFS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004513 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4514 ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004515 if (!ret_val)
4516 hw->mac.collision_delta = phy_data;
4517
4518 /* Defer Count */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004519 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4520 ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004521 if (!ret_val)
4522 adapter->stats.dc += phy_data;
4523
4524 /* Transmit with no CRS */
Bruce Allan2b6b1682011-05-13 07:20:09 +00004525 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4526 ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004527 if (!ret_val)
4528 adapter->stats.tncrs += phy_data;
4529
4530release:
4531 hw->phy.ops.release(hw);
4532}
4533
4534/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535 * e1000e_update_stats - Update the board statistics counters
4536 * @adapter: board private structure
4537 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004538static void e1000e_update_stats(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004539{
Ajit Khaparde7274c202009-10-07 02:44:26 +00004540 struct net_device *netdev = adapter->netdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004541 struct e1000_hw *hw = &adapter->hw;
4542 struct pci_dev *pdev = adapter->pdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004543
Bruce Allane921eb12012-11-28 09:28:37 +00004544 /* Prevent stats update while adapter is being reset, or if the pci
Auke Kokbc7f75f2007-09-17 12:30:59 -07004545 * connection is down.
4546 */
4547 if (adapter->link_speed == 0)
4548 return;
4549 if (pci_channel_offline(pdev))
4550 return;
4551
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552 adapter->stats.crcerrs += er32(CRCERRS);
4553 adapter->stats.gprc += er32(GPRC);
Bruce Allan7c257692008-04-23 11:09:00 -07004554 adapter->stats.gorc += er32(GORCL);
4555 er32(GORCH); /* Clear gorc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556 adapter->stats.bprc += er32(BPRC);
4557 adapter->stats.mprc += er32(MPRC);
4558 adapter->stats.roc += er32(ROC);
4559
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560 adapter->stats.mpc += er32(MPC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004561
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004562 /* Half-duplex statistics */
4563 if (adapter->link_duplex == HALF_DUPLEX) {
4564 if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
4565 e1000e_update_phy_stats(adapter);
4566 } else {
4567 adapter->stats.scc += er32(SCC);
4568 adapter->stats.ecol += er32(ECOL);
4569 adapter->stats.mcc += er32(MCC);
4570 adapter->stats.latecol += er32(LATECOL);
4571 adapter->stats.dc += er32(DC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004572
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004573 hw->mac.collision_delta = er32(COLC);
Bruce Allana4f58f52009-06-02 11:29:18 +00004574
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004575 if ((hw->mac.type != e1000_82574) &&
4576 (hw->mac.type != e1000_82583))
4577 adapter->stats.tncrs += er32(TNCRS);
4578 }
4579 adapter->stats.colc += hw->mac.collision_delta;
Bruce Allana4f58f52009-06-02 11:29:18 +00004580 }
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004581
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582 adapter->stats.xonrxc += er32(XONRXC);
4583 adapter->stats.xontxc += er32(XONTXC);
4584 adapter->stats.xoffrxc += er32(XOFFRXC);
4585 adapter->stats.xofftxc += er32(XOFFTXC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586 adapter->stats.gptc += er32(GPTC);
Bruce Allan7c257692008-04-23 11:09:00 -07004587 adapter->stats.gotc += er32(GOTCL);
4588 er32(GOTCH); /* Clear gotc */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589 adapter->stats.rnbc += er32(RNBC);
4590 adapter->stats.ruc += er32(RUC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004591
4592 adapter->stats.mptc += er32(MPTC);
4593 adapter->stats.bptc += er32(BPTC);
4594
4595 /* used for adaptive IFS */
4596
4597 hw->mac.tx_packet_delta = er32(TPT);
4598 adapter->stats.tpt += hw->mac.tx_packet_delta;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004599
4600 adapter->stats.algnerrc += er32(ALGNERRC);
4601 adapter->stats.rxerrc += er32(RXERRC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004602 adapter->stats.cexterr += er32(CEXTERR);
4603 adapter->stats.tsctc += er32(TSCTC);
4604 adapter->stats.tsctfc += er32(TSCTFC);
4605
Auke Kokbc7f75f2007-09-17 12:30:59 -07004606 /* Fill out the OS statistics structure */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004607 netdev->stats.multicast = adapter->stats.mprc;
4608 netdev->stats.collisions = adapter->stats.colc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609
4610 /* Rx Errors */
4611
Bruce Allane921eb12012-11-28 09:28:37 +00004612 /* RLEC on some newer hardware can be incorrect so build
Bruce Allanad680762008-03-28 09:15:03 -07004613 * our own version based on RUC and ROC
4614 */
Ajit Khaparde7274c202009-10-07 02:44:26 +00004615 netdev->stats.rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004616 adapter->stats.crcerrs + adapter->stats.algnerrc +
4617 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004618 netdev->stats.rx_length_errors = adapter->stats.ruc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00004619 adapter->stats.roc;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004620 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4621 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
4622 netdev->stats.rx_missed_errors = adapter->stats.mpc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004623
4624 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00004625 netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Ajit Khaparde7274c202009-10-07 02:44:26 +00004626 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
4627 netdev->stats.tx_window_errors = adapter->stats.latecol;
4628 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629
4630 /* Tx Dropped needs to be maintained elsewhere */
4631
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 /* Management Stats */
4633 adapter->stats.mgptc += er32(MGTPTC);
4634 adapter->stats.mgprc += er32(MGTPRC);
4635 adapter->stats.mgpdc += er32(MGTPDC);
Bruce Allan94fb8482013-01-23 09:00:03 +00004636
4637 /* Correctable ECC Errors */
4638 if (hw->mac.type == e1000_pch_lpt) {
4639 u32 pbeccsts = er32(PBECCSTS);
4640 adapter->corr_errors +=
4641 pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
4642 adapter->uncorr_errors +=
4643 (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
4644 E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
4645 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004646}
4647
Bruce Allan7c257692008-04-23 11:09:00 -07004648/**
4649 * e1000_phy_read_status - Update the PHY register status snapshot
4650 * @adapter: board private structure
4651 **/
4652static void e1000_phy_read_status(struct e1000_adapter *adapter)
4653{
4654 struct e1000_hw *hw = &adapter->hw;
4655 struct e1000_phy_regs *phy = &adapter->phy_regs;
Bruce Allan7c257692008-04-23 11:09:00 -07004656
4657 if ((er32(STATUS) & E1000_STATUS_LU) &&
4658 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
Bruce Allan90da0662011-01-06 07:02:53 +00004659 int ret_val;
4660
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004661 ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
4662 ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
4663 ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
4664 ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
4665 ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
4666 ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
4667 ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
4668 ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
Bruce Allan7c257692008-04-23 11:09:00 -07004669 if (ret_val)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004670 e_warn("Error reading PHY register\n");
Bruce Allan7c257692008-04-23 11:09:00 -07004671 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00004672 /* Do not read PHY registers if link is not up
Bruce Allan7c257692008-04-23 11:09:00 -07004673 * Set values to typical power-on defaults
4674 */
4675 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
4676 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
4677 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
4678 BMSR_ERCAP);
4679 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
4680 ADVERTISE_ALL | ADVERTISE_CSMA);
4681 phy->lpa = 0;
4682 phy->expansion = EXPANSION_ENABLENPAGE;
4683 phy->ctrl1000 = ADVERTISE_1000FULL;
4684 phy->stat1000 = 0;
4685 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
4686 }
Bruce Allan7c257692008-04-23 11:09:00 -07004687}
4688
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689static void e1000_print_link_info(struct e1000_adapter *adapter)
4690{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004691 struct e1000_hw *hw = &adapter->hw;
4692 u32 ctrl = er32(CTRL);
4693
Bruce Allan8f12fe82008-11-21 16:54:43 -08004694 /* Link status message must follow this format for user tools */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004695 pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4696 adapter->netdev->name, adapter->link_speed,
Jeff Kirsheref456f82011-11-03 11:40:28 +00004697 adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
4698 (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
4699 (ctrl & E1000_CTRL_RFCE) ? "Rx" :
4700 (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004701}
4702
Bruce Allan0c6bdb32010-06-17 18:58:43 +00004703static bool e1000e_has_link(struct e1000_adapter *adapter)
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004704{
4705 struct e1000_hw *hw = &adapter->hw;
Rusty Russell3db1cd52011-12-19 13:56:45 +00004706 bool link_active = false;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004707 s32 ret_val = 0;
4708
Bruce Allane921eb12012-11-28 09:28:37 +00004709 /* get_link_status is set on LSC (link status) interrupt or
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004710 * Rx sequence error interrupt. get_link_status will stay
4711 * false until the check_for_link establishes link
4712 * for copper adapters ONLY
4713 */
4714 switch (hw->phy.media_type) {
4715 case e1000_media_type_copper:
4716 if (hw->mac.get_link_status) {
4717 ret_val = hw->mac.ops.check_for_link(hw);
4718 link_active = !hw->mac.get_link_status;
4719 } else {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004720 link_active = true;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004721 }
4722 break;
4723 case e1000_media_type_fiber:
4724 ret_val = hw->mac.ops.check_for_link(hw);
4725 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
4726 break;
4727 case e1000_media_type_internal_serdes:
4728 ret_val = hw->mac.ops.check_for_link(hw);
4729 link_active = adapter->hw.mac.serdes_has_link;
4730 break;
4731 default:
4732 case e1000_media_type_unknown:
4733 break;
4734 }
4735
4736 if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
4737 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
4738 /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004739 e_info("Gigabit has been disabled, downgrading speed\n");
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004740 }
4741
4742 return link_active;
4743}
4744
4745static void e1000e_enable_receives(struct e1000_adapter *adapter)
4746{
4747 /* make sure the receive unit is started */
4748 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
Bruce Allan12d43f72012-12-05 06:26:14 +00004749 (adapter->flags & FLAG_RESTART_NOW)) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004750 struct e1000_hw *hw = &adapter->hw;
4751 u32 rctl = er32(RCTL);
4752 ew32(RCTL, rctl | E1000_RCTL_EN);
Bruce Allan12d43f72012-12-05 06:26:14 +00004753 adapter->flags &= ~FLAG_RESTART_NOW;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004754 }
4755}
4756
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004757static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
4758{
4759 struct e1000_hw *hw = &adapter->hw;
4760
Bruce Allane921eb12012-11-28 09:28:37 +00004761 /* With 82574 controllers, PHY needs to be checked periodically
Carolyn Wybornyff10e132010-10-28 00:59:53 +00004762 * for hung state and reset, if two calls return true
4763 */
4764 if (e1000_check_phy_82574(hw))
4765 adapter->phy_hang_count++;
4766 else
4767 adapter->phy_hang_count = 0;
4768
4769 if (adapter->phy_hang_count > 1) {
4770 adapter->phy_hang_count = 0;
4771 schedule_work(&adapter->reset_task);
4772 }
4773}
4774
Auke Kokbc7f75f2007-09-17 12:30:59 -07004775/**
4776 * e1000_watchdog - Timer Call-back
4777 * @data: pointer to adapter cast into an unsigned long
4778 **/
4779static void e1000_watchdog(unsigned long data)
4780{
4781 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
4782
4783 /* Do the rest outside of interrupt context */
4784 schedule_work(&adapter->watchdog_task);
4785
4786 /* TODO: make this use queue_delayed_work() */
4787}
4788
4789static void e1000_watchdog_task(struct work_struct *work)
4790{
4791 struct e1000_adapter *adapter = container_of(work,
4792 struct e1000_adapter, watchdog_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004793 struct net_device *netdev = adapter->netdev;
4794 struct e1000_mac_info *mac = &adapter->hw.mac;
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004795 struct e1000_phy_info *phy = &adapter->hw.phy;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004796 struct e1000_ring *tx_ring = adapter->tx_ring;
4797 struct e1000_hw *hw = &adapter->hw;
4798 u32 link, tctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004799
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00004800 if (test_bit(__E1000_DOWN, &adapter->state))
4801 return;
4802
David S. Millerb405e8d2010-02-04 22:31:41 -08004803 link = e1000e_has_link(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004804 if ((netif_carrier_ok(netdev)) && link) {
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004805 /* Cancel scheduled suspend requests. */
4806 pm_runtime_resume(netdev->dev.parent);
4807
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004808 e1000e_enable_receives(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004809 goto link_up;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004810 }
4811
4812 if ((e1000e_enable_tx_pkt_filtering(hw)) &&
4813 (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
4814 e1000_update_mng_vlan(adapter);
4815
Auke Kokbc7f75f2007-09-17 12:30:59 -07004816 if (link) {
4817 if (!netif_carrier_ok(netdev)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +00004818 bool txb2b = true;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004819
4820 /* Cancel scheduled suspend requests. */
4821 pm_runtime_resume(netdev->dev.parent);
4822
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004823 /* update snapshot of PHY registers on LSC */
Bruce Allan7c257692008-04-23 11:09:00 -07004824 e1000_phy_read_status(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004825 mac->ops.get_link_up_info(&adapter->hw,
4826 &adapter->link_speed,
4827 &adapter->link_duplex);
4828 e1000_print_link_info(adapter);
Koki Sanagie792cd92013-02-03 14:03:55 +00004829
4830 /* check if SmartSpeed worked */
4831 e1000e_check_downshift(hw);
4832 if (phy->speed_downgraded)
4833 netdev_warn(netdev,
4834 "Link Speed was downgraded by SmartSpeed\n");
4835
Bruce Allane921eb12012-11-28 09:28:37 +00004836 /* On supported PHYs, check for duplex mismatch only
Bruce Allanf4187b52008-08-26 18:36:50 -07004837 * if link has autonegotiated at 10/100 half
4838 */
4839 if ((hw->phy.type == e1000_phy_igp_3 ||
4840 hw->phy.type == e1000_phy_bm) &&
4841 (hw->mac.autoneg == true) &&
4842 (adapter->link_speed == SPEED_10 ||
4843 adapter->link_speed == SPEED_100) &&
4844 (adapter->link_duplex == HALF_DUPLEX)) {
4845 u16 autoneg_exp;
4846
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004847 e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
Bruce Allanf4187b52008-08-26 18:36:50 -07004848
Bruce Allanc2ade1a2013-01-16 08:54:35 +00004849 if (!(autoneg_exp & EXPANSION_NWAY))
Jeff Kirsheref456f82011-11-03 11:40:28 +00004850 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 -07004851 }
4852
Emil Tantilovf49c57e2010-03-24 12:55:02 +00004853 /* adjust timeout factor according to speed/duplex */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004854 adapter->tx_timeout_factor = 1;
4855 switch (adapter->link_speed) {
4856 case SPEED_10:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004857 txb2b = false;
Bruce Allan10f1b492008-08-08 18:36:01 -07004858 adapter->tx_timeout_factor = 16;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004859 break;
4860 case SPEED_100:
Rusty Russell3db1cd52011-12-19 13:56:45 +00004861 txb2b = false;
Bruce Allan4c86e0b2009-11-19 12:35:26 +00004862 adapter->tx_timeout_factor = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004863 break;
4864 }
4865
Bruce Allane921eb12012-11-28 09:28:37 +00004866 /* workaround: re-program speed mode bit after
Bruce Allanad680762008-03-28 09:15:03 -07004867 * link-up event
4868 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004869 if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
4870 !txb2b) {
4871 u32 tarc0;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004872 tarc0 = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004873 tarc0 &= ~SPEED_MODE_BIT;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004874 ew32(TARC(0), tarc0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004875 }
4876
Bruce Allane921eb12012-11-28 09:28:37 +00004877 /* disable TSO for pcie and 10/100 speeds, to avoid
Bruce Allanad680762008-03-28 09:15:03 -07004878 * some hardware issues
4879 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004880 if (!(adapter->flags & FLAG_TSO_FORCE)) {
4881 switch (adapter->link_speed) {
4882 case SPEED_10:
4883 case SPEED_100:
Jeff Kirsher44defeb2008-08-04 17:20:41 -07004884 e_info("10/100 speed: disabling TSO\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004885 netdev->features &= ~NETIF_F_TSO;
4886 netdev->features &= ~NETIF_F_TSO6;
4887 break;
4888 case SPEED_1000:
4889 netdev->features |= NETIF_F_TSO;
4890 netdev->features |= NETIF_F_TSO6;
4891 break;
4892 default:
4893 /* oops */
4894 break;
4895 }
4896 }
4897
Bruce Allane921eb12012-11-28 09:28:37 +00004898 /* enable transmits in the hardware, need to do this
Bruce Allanad680762008-03-28 09:15:03 -07004899 * after setting TARC(0)
4900 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004901 tctl = er32(TCTL);
4902 tctl |= E1000_TCTL_EN;
4903 ew32(TCTL, tctl);
4904
Bruce Allane921eb12012-11-28 09:28:37 +00004905 /* Perform any post-link-up configuration before
Bruce Allan75eb0fa2008-11-21 16:53:51 -08004906 * reporting link up.
4907 */
4908 if (phy->ops.cfg_on_link_up)
4909 phy->ops.cfg_on_link_up(hw);
4910
Auke Kokbc7f75f2007-09-17 12:30:59 -07004911 netif_carrier_on(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004912
4913 if (!test_bit(__E1000_DOWN, &adapter->state))
4914 mod_timer(&adapter->phy_info_timer,
4915 round_jiffies(jiffies + 2 * HZ));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916 }
4917 } else {
4918 if (netif_carrier_ok(netdev)) {
4919 adapter->link_speed = 0;
4920 adapter->link_duplex = 0;
Bruce Allan8f12fe82008-11-21 16:54:43 -08004921 /* Link status message must follow this format */
Bruce Allan7dbc1672013-01-12 03:11:25 +00004922 pr_info("%s NIC Link is Down\n", adapter->netdev->name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004923 netif_carrier_off(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004924 if (!test_bit(__E1000_DOWN, &adapter->state))
4925 mod_timer(&adapter->phy_info_timer,
4926 round_jiffies(jiffies + 2 * HZ));
4927
Bruce Allan12d43f72012-12-05 06:26:14 +00004928 /* The link is lost so the controller stops DMA.
4929 * If there is queued Tx work that cannot be done
4930 * or if on an 8000ES2LAN which requires a Rx packet
4931 * buffer work-around on link down event, reset the
4932 * controller to flush the Tx/Rx packet buffers.
4933 * (Do the reset outside of interrupt context).
4934 */
4935 if ((adapter->flags & FLAG_RX_NEEDS_RESTART) ||
4936 (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
4937 adapter->flags |= FLAG_RESTART_NOW;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00004938 else
4939 pm_schedule_suspend(netdev->dev.parent,
4940 LINK_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004941 }
4942 }
4943
4944link_up:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00004945 spin_lock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004946 e1000e_update_stats(adapter);
4947
4948 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
4949 adapter->tpt_old = adapter->stats.tpt;
4950 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
4951 adapter->colc_old = adapter->stats.colc;
4952
Bruce Allan7c257692008-04-23 11:09:00 -07004953 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
4954 adapter->gorc_old = adapter->stats.gorc;
4955 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
4956 adapter->gotc_old = adapter->stats.gotc;
Flavio Leitner2084b112011-04-05 04:27:43 +00004957 spin_unlock(&adapter->stats64_lock);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004958
Bruce Allan12d43f72012-12-05 06:26:14 +00004959 if (adapter->flags & FLAG_RESTART_NOW) {
Bruce Allan90da0662011-01-06 07:02:53 +00004960 schedule_work(&adapter->reset_task);
4961 /* return immediately since reset is imminent */
4962 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004963 }
4964
Bruce Allan12d43f72012-12-05 06:26:14 +00004965 e1000e_update_adaptive(&adapter->hw);
4966
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004967 /* Simple mode for Interrupt Throttle Rate (ITR) */
4968 if (adapter->itr_setting == 4) {
Bruce Allane921eb12012-11-28 09:28:37 +00004969 /* Symmetric Tx/Rx gets a reduced ITR=2000;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004970 * Total asymmetrical Tx or Rx gets ITR=8000;
4971 * everyone else is between 2000-8000.
4972 */
4973 u32 goc = (adapter->gotc + adapter->gorc) / 10000;
4974 u32 dif = (adapter->gotc > adapter->gorc ?
4975 adapter->gotc - adapter->gorc :
4976 adapter->gorc - adapter->gotc) / 10000;
4977 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
4978
Matthew Vick22a4cca2012-07-12 00:02:42 +00004979 e1000e_write_itr(adapter, itr);
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00004980 }
4981
Bruce Allanad680762008-03-28 09:15:03 -07004982 /* Cause software interrupt to ensure Rx ring is cleaned */
Bruce Allan4662e822008-08-26 18:37:06 -07004983 if (adapter->msix_entries)
4984 ew32(ICS, adapter->rx_ring->ims_val);
4985 else
4986 ew32(ICS, E1000_ICS_RXDMT0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004987
Jesse Brandeburg713b3c92011-02-02 10:19:50 +00004988 /* flush pending descriptors to memory before detecting Tx hang */
4989 e1000e_flush_descriptors(adapter);
4990
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991 /* Force detection of hung controller every watchdog period */
Rusty Russell3db1cd52011-12-19 13:56:45 +00004992 adapter->detect_tx_hung = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004993
Bruce Allane921eb12012-11-28 09:28:37 +00004994 /* With 82571 controllers, LAA may be overwritten due to controller
Bruce Allanad680762008-03-28 09:15:03 -07004995 * reset from the other port. Set the appropriate LAA in RAR[0]
4996 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997 if (e1000e_get_laa_state_82571(hw))
Bruce Allan69e1e012012-04-14 03:28:50 +00004998 hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004999
Carolyn Wybornyff10e132010-10-28 00:59:53 +00005000 if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
5001 e1000e_check_82574_phy_workaround(adapter);
5002
Bruce Allanb67e1912012-12-27 08:32:33 +00005003 /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
5004 if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
5005 if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
5006 (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
5007 er32(RXSTMPH);
5008 adapter->rx_hwtstamp_cleared++;
5009 } else {
5010 adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
5011 }
5012 }
5013
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014 /* Reset the timer */
5015 if (!test_bit(__E1000_DOWN, &adapter->state))
5016 mod_timer(&adapter->watchdog_timer,
5017 round_jiffies(jiffies + 2 * HZ));
5018}
5019
5020#define E1000_TX_FLAGS_CSUM 0x00000001
5021#define E1000_TX_FLAGS_VLAN 0x00000002
5022#define E1000_TX_FLAGS_TSO 0x00000004
5023#define E1000_TX_FLAGS_IPV4 0x00000008
Ben Greear943146d2012-02-11 15:39:40 +00005024#define E1000_TX_FLAGS_NO_FCS 0x00000010
Bruce Allanb67e1912012-12-27 08:32:33 +00005025#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
Auke Kokbc7f75f2007-09-17 12:30:59 -07005026#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
5027#define E1000_TX_FLAGS_VLAN_SHIFT 16
5028
Bruce Allan55aa6982011-12-16 00:45:45 +00005029static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005030{
Auke Kokbc7f75f2007-09-17 12:30:59 -07005031 struct e1000_context_desc *context_desc;
5032 struct e1000_buffer *buffer_info;
5033 unsigned int i;
5034 u32 cmd_length = 0;
Bruce Allan70443ae2012-08-17 06:18:13 +00005035 u16 ipcse = 0, mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005036 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005037
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005038 if (!skb_is_gso(skb))
5039 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005040
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005041 if (skb_header_cloned(skb)) {
Bruce Allan90da0662011-01-06 07:02:53 +00005042 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5043
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005044 if (err)
5045 return err;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046 }
5047
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005048 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
5049 mss = skb_shinfo(skb)->gso_size;
5050 if (skb->protocol == htons(ETH_P_IP)) {
5051 struct iphdr *iph = ip_hdr(skb);
5052 iph->tot_len = 0;
5053 iph->check = 0;
5054 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005055 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005056 cmd_length = E1000_TXD_CMD_IP;
5057 ipcse = skb_transport_offset(skb) - 1;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08005058 } else if (skb_is_gso_v6(skb)) {
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005059 ipv6_hdr(skb)->payload_len = 0;
5060 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Bruce Allanf0ff4392013-02-20 04:05:39 +00005061 &ipv6_hdr(skb)->daddr,
5062 0, IPPROTO_TCP, 0);
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005063 ipcse = 0;
5064 }
5065 ipcss = skb_network_offset(skb);
5066 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
5067 tucss = skb_transport_offset(skb);
5068 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005069
5070 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005071 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005072
5073 i = tx_ring->next_to_use;
5074 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5075 buffer_info = &tx_ring->buffer_info[i];
5076
5077 context_desc->lower_setup.ip_fields.ipcss = ipcss;
5078 context_desc->lower_setup.ip_fields.ipcso = ipcso;
5079 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
5080 context_desc->upper_setup.tcp_fields.tucss = tucss;
5081 context_desc->upper_setup.tcp_fields.tucso = tucso;
Bruce Allan70443ae2012-08-17 06:18:13 +00005082 context_desc->upper_setup.tcp_fields.tucse = 0;
Bruce Allan3d5e33c2009-11-20 23:27:03 +00005083 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
5084 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
5085 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
5086
5087 buffer_info->time_stamp = jiffies;
5088 buffer_info->next_to_watch = i;
5089
5090 i++;
5091 if (i == tx_ring->count)
5092 i = 0;
5093 tx_ring->next_to_use = i;
5094
5095 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005096}
5097
Bruce Allan55aa6982011-12-16 00:45:45 +00005098static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005099{
Bruce Allan55aa6982011-12-16 00:45:45 +00005100 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005101 struct e1000_context_desc *context_desc;
5102 struct e1000_buffer *buffer_info;
5103 unsigned int i;
5104 u8 css;
Dave Grahamaf807c82008-10-09 14:28:58 -07005105 u32 cmd_len = E1000_TXD_CMD_DEXT;
Arthur Jones5f66f202009-03-19 01:13:08 +00005106 __be16 protocol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005107
Dave Grahamaf807c82008-10-09 14:28:58 -07005108 if (skb->ip_summed != CHECKSUM_PARTIAL)
5109 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005110
Arthur Jones5f66f202009-03-19 01:13:08 +00005111 if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
5112 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
5113 else
5114 protocol = skb->protocol;
5115
Arthur Jones3f518392009-03-20 15:56:35 -07005116 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005117 case cpu_to_be16(ETH_P_IP):
Dave Grahamaf807c82008-10-09 14:28:58 -07005118 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5119 cmd_len |= E1000_TXD_CMD_TCP;
5120 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005121 case cpu_to_be16(ETH_P_IPV6):
Dave Grahamaf807c82008-10-09 14:28:58 -07005122 /* XXX not handling all IPV6 headers */
5123 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5124 cmd_len |= E1000_TXD_CMD_TCP;
5125 break;
5126 default:
5127 if (unlikely(net_ratelimit()))
Arthur Jones5f66f202009-03-19 01:13:08 +00005128 e_warn("checksum_partial proto=%x!\n",
5129 be16_to_cpu(protocol));
Dave Grahamaf807c82008-10-09 14:28:58 -07005130 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005131 }
5132
Michał Mirosław0d0b1672010-12-14 15:24:08 +00005133 css = skb_checksum_start_offset(skb);
Dave Grahamaf807c82008-10-09 14:28:58 -07005134
5135 i = tx_ring->next_to_use;
5136 buffer_info = &tx_ring->buffer_info[i];
5137 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
5138
5139 context_desc->lower_setup.ip_config = 0;
5140 context_desc->upper_setup.tcp_fields.tucss = css;
Bruce Allanf0ff4392013-02-20 04:05:39 +00005141 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Dave Grahamaf807c82008-10-09 14:28:58 -07005142 context_desc->upper_setup.tcp_fields.tucse = 0;
5143 context_desc->tcp_seg_setup.data = 0;
5144 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
5145
5146 buffer_info->time_stamp = jiffies;
5147 buffer_info->next_to_watch = i;
5148
5149 i++;
5150 if (i == tx_ring->count)
5151 i = 0;
5152 tx_ring->next_to_use = i;
5153
5154 return 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005155}
5156
Bruce Allan55aa6982011-12-16 00:45:45 +00005157static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
5158 unsigned int first, unsigned int max_per_txd,
Bruce Alland821a4c2012-08-24 20:38:11 +00005159 unsigned int nr_frags)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005160{
Bruce Allan55aa6982011-12-16 00:45:45 +00005161 struct e1000_adapter *adapter = tx_ring->adapter;
Alexander Duyck03b13202009-12-02 16:45:31 +00005162 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005163 struct e1000_buffer *buffer_info;
Jesse Brandeburg8ddc9512009-03-02 16:02:53 -08005164 unsigned int len = skb_headlen(skb);
Alexander Duyck03b13202009-12-02 16:45:31 +00005165 unsigned int offset = 0, size, count = 0, i;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005166 unsigned int f, bytecount, segs;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005167
5168 i = tx_ring->next_to_use;
5169
5170 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005171 buffer_info = &tx_ring->buffer_info[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07005172 size = min(len, max_per_txd);
5173
Auke Kokbc7f75f2007-09-17 12:30:59 -07005174 buffer_info->length = size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005175 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005176 buffer_info->next_to_watch = i;
Nick Nunley0be3f552010-04-27 13:09:05 +00005177 buffer_info->dma = dma_map_single(&pdev->dev,
5178 skb->data + offset,
Bruce Allanaf667a22010-12-31 06:10:01 +00005179 size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005180 buffer_info->mapped_as_page = false;
Nick Nunley0be3f552010-04-27 13:09:05 +00005181 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005182 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005183
5184 len -= size;
5185 offset += size;
Alexander Duyck03b13202009-12-02 16:45:31 +00005186 count++;
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005187
5188 if (len) {
5189 i++;
5190 if (i == tx_ring->count)
5191 i = 0;
5192 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005193 }
5194
5195 for (f = 0; f < nr_frags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00005196 const struct skb_frag_struct *frag;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005197
5198 frag = &skb_shinfo(skb)->frags[f];
Eric Dumazet9e903e02011-10-18 21:00:24 +00005199 len = skb_frag_size(frag);
Ian Campbell877749b2011-08-29 23:18:26 +00005200 offset = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005201
5202 while (len) {
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005203 i++;
5204 if (i == tx_ring->count)
5205 i = 0;
5206
Auke Kokbc7f75f2007-09-17 12:30:59 -07005207 buffer_info = &tx_ring->buffer_info[i];
5208 size = min(len, max_per_txd);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005209
5210 buffer_info->length = size;
5211 buffer_info->time_stamp = jiffies;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005212 buffer_info->next_to_watch = i;
Ian Campbell877749b2011-08-29 23:18:26 +00005213 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
5214 offset, size, DMA_TO_DEVICE);
Alexander Duyck03b13202009-12-02 16:45:31 +00005215 buffer_info->mapped_as_page = true;
Nick Nunley0be3f552010-04-27 13:09:05 +00005216 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duyck03b13202009-12-02 16:45:31 +00005217 goto dma_error;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005218
5219 len -= size;
5220 offset += size;
5221 count++;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005222 }
5223 }
5224
Bruce Allanaf667a22010-12-31 06:10:01 +00005225 segs = skb_shinfo(skb)->gso_segs ? : 1;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005226 /* multiply data chunks by size of headers */
5227 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
5228
Auke Kokbc7f75f2007-09-17 12:30:59 -07005229 tx_ring->buffer_info[i].skb = skb;
Tom Herbert9ed318d2010-05-05 14:02:27 +00005230 tx_ring->buffer_info[i].segs = segs;
5231 tx_ring->buffer_info[i].bytecount = bytecount;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005232 tx_ring->buffer_info[first].next_to_watch = i;
5233
5234 return count;
Alexander Duyck03b13202009-12-02 16:45:31 +00005235
5236dma_error:
Bruce Allanaf667a22010-12-31 06:10:01 +00005237 dev_err(&pdev->dev, "Tx DMA map failed\n");
Alexander Duyck03b13202009-12-02 16:45:31 +00005238 buffer_info->dma = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005239 if (count)
Alexander Duyck03b13202009-12-02 16:45:31 +00005240 count--;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005241
5242 while (count--) {
Bruce Allanaf667a22010-12-31 06:10:01 +00005243 if (i == 0)
Alexander Duyck03b13202009-12-02 16:45:31 +00005244 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00005245 i--;
Alexander Duyck03b13202009-12-02 16:45:31 +00005246 buffer_info = &tx_ring->buffer_info[i];
Bruce Allan55aa6982011-12-16 00:45:45 +00005247 e1000_put_txbuf(tx_ring, buffer_info);
Alexander Duyck03b13202009-12-02 16:45:31 +00005248 }
5249
5250 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005251}
5252
Bruce Allan55aa6982011-12-16 00:45:45 +00005253static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005254{
Bruce Allan55aa6982011-12-16 00:45:45 +00005255 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005256 struct e1000_tx_desc *tx_desc = NULL;
5257 struct e1000_buffer *buffer_info;
5258 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
5259 unsigned int i;
5260
5261 if (tx_flags & E1000_TX_FLAGS_TSO) {
5262 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
Bruce Allanf0ff4392013-02-20 04:05:39 +00005263 E1000_TXD_CMD_TSE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005264 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5265
5266 if (tx_flags & E1000_TX_FLAGS_IPV4)
5267 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
5268 }
5269
5270 if (tx_flags & E1000_TX_FLAGS_CSUM) {
5271 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5272 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
5273 }
5274
5275 if (tx_flags & E1000_TX_FLAGS_VLAN) {
5276 txd_lower |= E1000_TXD_CMD_VLE;
5277 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
5278 }
5279
Ben Greear943146d2012-02-11 15:39:40 +00005280 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5281 txd_lower &= ~(E1000_TXD_CMD_IFCS);
5282
Bruce Allanb67e1912012-12-27 08:32:33 +00005283 if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
5284 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
5285 txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
5286 }
5287
Auke Kokbc7f75f2007-09-17 12:30:59 -07005288 i = tx_ring->next_to_use;
5289
Bruce Allan36b973d2010-11-24 07:42:43 +00005290 do {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005291 buffer_info = &tx_ring->buffer_info[i];
5292 tx_desc = E1000_TX_DESC(*tx_ring, i);
5293 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
Bruce Allanf0ff4392013-02-20 04:05:39 +00005294 tx_desc->lower.data = cpu_to_le32(txd_lower |
5295 buffer_info->length);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005296 tx_desc->upper.data = cpu_to_le32(txd_upper);
5297
5298 i++;
5299 if (i == tx_ring->count)
5300 i = 0;
Bruce Allan36b973d2010-11-24 07:42:43 +00005301 } while (--count > 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005302
5303 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
5304
Ben Greear943146d2012-02-11 15:39:40 +00005305 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
5306 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
5307 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
5308
Bruce Allane921eb12012-11-28 09:28:37 +00005309 /* Force memory writes to complete before letting h/w
Auke Kokbc7f75f2007-09-17 12:30:59 -07005310 * know there are new descriptors to fetch. (Only
5311 * applicable for weak-ordered memory model archs,
Bruce Allanad680762008-03-28 09:15:03 -07005312 * such as IA-64).
5313 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005314 wmb();
5315
5316 tx_ring->next_to_use = i;
David S. Miller823dcd22011-08-20 10:39:12 -07005317
5318 if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
Bruce Allan55aa6982011-12-16 00:45:45 +00005319 e1000e_update_tdt_wa(tx_ring, i);
David S. Miller823dcd22011-08-20 10:39:12 -07005320 else
Bruce Allanc5083cf2011-12-16 00:45:40 +00005321 writel(i, tx_ring->tail);
David S. Miller823dcd22011-08-20 10:39:12 -07005322
Bruce Allane921eb12012-11-28 09:28:37 +00005323 /* we need this if more than one processor can write to our tail
Bruce Allanad680762008-03-28 09:15:03 -07005324 * at a time, it synchronizes IO on IA64/Altix systems
5325 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005326 mmiowb();
5327}
5328
5329#define MINIMUM_DHCP_PACKET_SIZE 282
5330static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
5331 struct sk_buff *skb)
5332{
5333 struct e1000_hw *hw = &adapter->hw;
5334 u16 length, offset;
5335
Bruce Alland60923c2012-12-05 06:26:56 +00005336 if (vlan_tx_tag_present(skb) &&
5337 !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
5338 (adapter->hw.mng_cookie.status &
5339 E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
5340 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005341
5342 if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
5343 return 0;
5344
5345 if (((struct ethhdr *) skb->data)->h_proto != htons(ETH_P_IP))
5346 return 0;
5347
5348 {
Bruce Allan362e20c2013-02-20 04:05:45 +00005349 const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005350 struct udphdr *udp;
5351
5352 if (ip->protocol != IPPROTO_UDP)
5353 return 0;
5354
5355 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
5356 if (ntohs(udp->dest) != 67)
5357 return 0;
5358
5359 offset = (u8 *)udp + 8 - skb->data;
5360 length = skb->len - offset;
5361 return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
5362 }
5363
5364 return 0;
5365}
5366
Bruce Allan55aa6982011-12-16 00:45:45 +00005367static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005368{
Bruce Allan55aa6982011-12-16 00:45:45 +00005369 struct e1000_adapter *adapter = tx_ring->adapter;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005370
Bruce Allan55aa6982011-12-16 00:45:45 +00005371 netif_stop_queue(adapter->netdev);
Bruce Allane921eb12012-11-28 09:28:37 +00005372 /* Herbert's original patch had:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005373 * smp_mb__after_netif_stop_queue();
Bruce Allanad680762008-03-28 09:15:03 -07005374 * but since that doesn't exist yet, just open code it.
5375 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005376 smp_mb();
5377
Bruce Allane921eb12012-11-28 09:28:37 +00005378 /* We need to check again in a case another CPU has just
Bruce Allanad680762008-03-28 09:15:03 -07005379 * made room available.
5380 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005381 if (e1000_desc_unused(tx_ring) < size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005382 return -EBUSY;
5383
5384 /* A reprieve! */
Bruce Allan55aa6982011-12-16 00:45:45 +00005385 netif_start_queue(adapter->netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005386 ++adapter->restart_queue;
5387 return 0;
5388}
5389
Bruce Allan55aa6982011-12-16 00:45:45 +00005390static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005391{
Bruce Alland821a4c2012-08-24 20:38:11 +00005392 BUG_ON(size > tx_ring->count);
5393
Bruce Allan55aa6982011-12-16 00:45:45 +00005394 if (e1000_desc_unused(tx_ring) >= size)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005395 return 0;
Bruce Allan55aa6982011-12-16 00:45:45 +00005396 return __e1000_maybe_stop_tx(tx_ring, size);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005397}
5398
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005399static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
5400 struct net_device *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005401{
5402 struct e1000_adapter *adapter = netdev_priv(netdev);
5403 struct e1000_ring *tx_ring = adapter->tx_ring;
5404 unsigned int first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005405 unsigned int tx_flags = 0;
Eric Dumazete743d312010-04-14 15:59:40 -07005406 unsigned int len = skb_headlen(skb);
Auke Kok4e6c7092007-10-05 14:15:23 -07005407 unsigned int nr_frags;
5408 unsigned int mss;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005409 int count = 0;
5410 int tso;
5411 unsigned int f;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005412
5413 if (test_bit(__E1000_DOWN, &adapter->state)) {
5414 dev_kfree_skb_any(skb);
5415 return NETDEV_TX_OK;
5416 }
5417
5418 if (skb->len <= 0) {
5419 dev_kfree_skb_any(skb);
5420 return NETDEV_TX_OK;
5421 }
5422
Bruce Allane921eb12012-11-28 09:28:37 +00005423 /* The minimum packet size with TCTL.PSP set is 17 bytes so
Tushar Dave6e97c172012-09-14 02:21:37 +00005424 * pad skb in order to meet this minimum size requirement
5425 */
5426 if (unlikely(skb->len < 17)) {
5427 if (skb_pad(skb, 17 - skb->len))
5428 return NETDEV_TX_OK;
5429 skb->len = 17;
5430 skb_set_tail_pointer(skb, 17);
5431 }
5432
Auke Kokbc7f75f2007-09-17 12:30:59 -07005433 mss = skb_shinfo(skb)->gso_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005434 if (mss) {
5435 u8 hdr_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005436
Bruce Allane921eb12012-11-28 09:28:37 +00005437 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Bruce Allanad680762008-03-28 09:15:03 -07005438 * points to just header, pull a few bytes of payload from
5439 * frags into skb->data
5440 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005441 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Bruce Allane921eb12012-11-28 09:28:37 +00005442 /* we do this workaround for ES2LAN, but it is un-necessary,
Bruce Allanad680762008-03-28 09:15:03 -07005443 * avoiding it could save a lot of cycles
5444 */
Auke Kok4e6c7092007-10-05 14:15:23 -07005445 if (skb->data_len && (hdr_len == len)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005446 unsigned int pull_size;
5447
Bruce Allana2a5b322012-01-31 06:37:17 +00005448 pull_size = min_t(unsigned int, 4, skb->data_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005449 if (!__pskb_pull_tail(skb, pull_size)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07005450 e_err("__pskb_pull_tail failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005451 dev_kfree_skb_any(skb);
5452 return NETDEV_TX_OK;
5453 }
Eric Dumazete743d312010-04-14 15:59:40 -07005454 len = skb_headlen(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005455 }
5456 }
5457
5458 /* reserve a descriptor for the offload context */
5459 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
5460 count++;
5461 count++;
5462
Bruce Alland821a4c2012-08-24 20:38:11 +00005463 count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005464
5465 nr_frags = skb_shinfo(skb)->nr_frags;
5466 for (f = 0; f < nr_frags; f++)
Bruce Alland821a4c2012-08-24 20:38:11 +00005467 count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
5468 adapter->tx_fifo_limit);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005469
5470 if (adapter->hw.mac.tx_pkt_filtering)
5471 e1000_transfer_dhcp_info(adapter, skb);
5472
Bruce Allane921eb12012-11-28 09:28:37 +00005473 /* need: count + 2 desc gap to keep tail from touching
Bruce Allanad680762008-03-28 09:15:03 -07005474 * head, otherwise try next time
5475 */
Bruce Allan55aa6982011-12-16 00:45:45 +00005476 if (e1000_maybe_stop_tx(tx_ring, count + 2))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005477 return NETDEV_TX_BUSY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005478
Jesse Grosseab6d182010-10-20 13:56:03 +00005479 if (vlan_tx_tag_present(skb)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005480 tx_flags |= E1000_TX_FLAGS_VLAN;
5481 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
5482 }
5483
5484 first = tx_ring->next_to_use;
5485
Bruce Allan55aa6982011-12-16 00:45:45 +00005486 tso = e1000_tso(tx_ring, skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005487 if (tso < 0) {
5488 dev_kfree_skb_any(skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005489 return NETDEV_TX_OK;
5490 }
5491
5492 if (tso)
5493 tx_flags |= E1000_TX_FLAGS_TSO;
Bruce Allan55aa6982011-12-16 00:45:45 +00005494 else if (e1000_tx_csum(tx_ring, skb))
Auke Kokbc7f75f2007-09-17 12:30:59 -07005495 tx_flags |= E1000_TX_FLAGS_CSUM;
5496
Bruce Allane921eb12012-11-28 09:28:37 +00005497 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005498 * 82571 hardware supports TSO capabilities for IPv6 as well...
Bruce Allanad680762008-03-28 09:15:03 -07005499 * no longer assume, we must.
5500 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005501 if (skb->protocol == htons(ETH_P_IP))
5502 tx_flags |= E1000_TX_FLAGS_IPV4;
5503
Ben Greear943146d2012-02-11 15:39:40 +00005504 if (unlikely(skb->no_fcs))
5505 tx_flags |= E1000_TX_FLAGS_NO_FCS;
5506
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005507 /* if count is 0 then mapping error has occurred */
Bruce Alland821a4c2012-08-24 20:38:11 +00005508 count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
5509 nr_frags);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005510 if (count) {
Bruce Allanb67e1912012-12-27 08:32:33 +00005511 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
5512 !adapter->tx_hwtstamp_skb)) {
5513 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5514 tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
5515 adapter->tx_hwtstamp_skb = skb_get(skb);
5516 schedule_work(&adapter->tx_hwtstamp_work);
5517 } else {
5518 skb_tx_timestamp(skb);
5519 }
Willem de Bruijn80be3122012-04-27 09:04:05 +00005520
Tom Herbert3f0cfa32011-11-28 16:33:16 +00005521 netdev_sent_queue(netdev, skb->len);
Bruce Allan55aa6982011-12-16 00:45:45 +00005522 e1000_tx_queue(tx_ring, tx_flags, count);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005523 /* Make sure there is space in the ring for the next send. */
Bruce Alland821a4c2012-08-24 20:38:11 +00005524 e1000_maybe_stop_tx(tx_ring,
5525 (MAX_SKB_FRAGS *
5526 DIV_ROUND_UP(PAGE_SIZE,
5527 adapter->tx_fifo_limit) + 2));
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005528 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005529 dev_kfree_skb_any(skb);
Alexander Duyck1b7719c2009-03-19 01:12:50 +00005530 tx_ring->buffer_info[first].time_stamp = 0;
5531 tx_ring->next_to_use = first;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005532 }
5533
Auke Kokbc7f75f2007-09-17 12:30:59 -07005534 return NETDEV_TX_OK;
5535}
5536
5537/**
5538 * e1000_tx_timeout - Respond to a Tx Hang
5539 * @netdev: network interface device structure
5540 **/
5541static void e1000_tx_timeout(struct net_device *netdev)
5542{
5543 struct e1000_adapter *adapter = netdev_priv(netdev);
5544
5545 /* Do the reset outside of interrupt context */
5546 adapter->tx_timeout_count++;
5547 schedule_work(&adapter->reset_task);
5548}
5549
5550static void e1000_reset_task(struct work_struct *work)
5551{
5552 struct e1000_adapter *adapter;
5553 adapter = container_of(work, struct e1000_adapter, reset_task);
5554
Jesse Brandeburg615b32a2011-02-02 10:19:45 +00005555 /* don't run the task if already down */
5556 if (test_bit(__E1000_DOWN, &adapter->state))
5557 return;
5558
Bruce Allan12d43f72012-12-05 06:26:14 +00005559 if (!(adapter->flags & FLAG_RESTART_NOW)) {
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005560 e1000e_dump(adapter);
Bruce Allan12d43f72012-12-05 06:26:14 +00005561 e_err("Reset adapter unexpectedly\n");
Carolyn Wybornyaffa9df2010-10-28 00:59:55 +00005562 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005563 e1000e_reinit_locked(adapter);
5564}
5565
5566/**
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005567 * e1000_get_stats64 - Get System Network Statistics
Auke Kokbc7f75f2007-09-17 12:30:59 -07005568 * @netdev: network interface device structure
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005569 * @stats: rtnl_link_stats64 pointer
Auke Kokbc7f75f2007-09-17 12:30:59 -07005570 *
5571 * Returns the address of the device statistics structure.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005572 **/
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005573struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
5574 struct rtnl_link_stats64 *stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005575{
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005576 struct e1000_adapter *adapter = netdev_priv(netdev);
5577
5578 memset(stats, 0, sizeof(struct rtnl_link_stats64));
5579 spin_lock(&adapter->stats64_lock);
5580 e1000e_update_stats(adapter);
5581 /* Fill out the OS statistics structure */
5582 stats->rx_bytes = adapter->stats.gorc;
5583 stats->rx_packets = adapter->stats.gprc;
5584 stats->tx_bytes = adapter->stats.gotc;
5585 stats->tx_packets = adapter->stats.gptc;
5586 stats->multicast = adapter->stats.mprc;
5587 stats->collisions = adapter->stats.colc;
5588
5589 /* Rx Errors */
5590
Bruce Allane921eb12012-11-28 09:28:37 +00005591 /* RLEC on some newer hardware can be incorrect so build
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005592 * our own version based on RUC and ROC
5593 */
5594 stats->rx_errors = adapter->stats.rxerrc +
Bruce Allanf0ff4392013-02-20 04:05:39 +00005595 adapter->stats.crcerrs + adapter->stats.algnerrc +
5596 adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
5597 stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005598 stats->rx_crc_errors = adapter->stats.crcerrs;
5599 stats->rx_frame_errors = adapter->stats.algnerrc;
5600 stats->rx_missed_errors = adapter->stats.mpc;
5601
5602 /* Tx Errors */
Bruce Allanf0ff4392013-02-20 04:05:39 +00005603 stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00005604 stats->tx_aborted_errors = adapter->stats.ecol;
5605 stats->tx_window_errors = adapter->stats.latecol;
5606 stats->tx_carrier_errors = adapter->stats.tncrs;
5607
5608 /* Tx Dropped needs to be maintained elsewhere */
5609
5610 spin_unlock(&adapter->stats64_lock);
5611 return stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005612}
5613
5614/**
5615 * e1000_change_mtu - Change the Maximum Transfer Unit
5616 * @netdev: network interface device structure
5617 * @new_mtu: new value for maximum frame size
5618 *
5619 * Returns 0 on success, negative on failure
5620 **/
5621static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
5622{
5623 struct e1000_adapter *adapter = netdev_priv(netdev);
5624 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5625
Bruce Allan2adc55c2009-06-02 11:28:58 +00005626 /* Jumbo frame support */
Bruce Allan2e1706f2012-06-30 20:02:42 +00005627 if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
5628 !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
5629 e_err("Jumbo Frames not supported.\n");
5630 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005631 }
5632
Bruce Allan2adc55c2009-06-02 11:28:58 +00005633 /* Supported frame sizes */
5634 if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
5635 (max_frame > adapter->max_hw_frame_size)) {
5636 e_err("Unsupported MTU setting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07005637 return -EINVAL;
5638 }
5639
Bruce Allan2fbe4522012-04-19 03:21:47 +00005640 /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
5641 if ((adapter->hw.mac.type >= e1000_pch2lan) &&
Bruce Allana1ce6472010-09-22 17:16:40 +00005642 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
5643 (new_mtu > ETH_DATA_LEN)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00005644 e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
Bruce Allana1ce6472010-09-22 17:16:40 +00005645 return -EINVAL;
5646 }
5647
Auke Kokbc7f75f2007-09-17 12:30:59 -07005648 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +00005649 usleep_range(1000, 2000);
Bruce Allan610c9922009-11-19 12:35:45 +00005650 /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005651 adapter->max_frame_size = max_frame;
Bruce Allan610c9922009-11-19 12:35:45 +00005652 e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5653 netdev->mtu = new_mtu;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005654 if (netif_running(netdev))
5655 e1000e_down(adapter);
5656
Bruce Allane921eb12012-11-28 09:28:37 +00005657 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kokbc7f75f2007-09-17 12:30:59 -07005658 * means we reserve 2 more, this pushes us to allocate from the next
5659 * larger slab size.
Bruce Allanad680762008-03-28 09:15:03 -07005660 * i.e. RXBUFFER_2048 --> size-4096 slab
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005661 * However with the new *_jumbo_rx* routines, jumbo receives will use
5662 * fragmented skbs
Bruce Allanad680762008-03-28 09:15:03 -07005663 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005664
Jesse Brandeburg99261462010-01-22 22:56:16 +00005665 if (max_frame <= 2048)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005666 adapter->rx_buffer_len = 2048;
5667 else
5668 adapter->rx_buffer_len = 4096;
5669
5670 /* adjust allocation if LPE protects us, and we aren't using SBP */
5671 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
5672 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
5673 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
Bruce Allanad680762008-03-28 09:15:03 -07005674 + ETH_FCS_LEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005675
Auke Kokbc7f75f2007-09-17 12:30:59 -07005676 if (netif_running(netdev))
5677 e1000e_up(adapter);
5678 else
5679 e1000e_reset(adapter);
5680
5681 clear_bit(__E1000_RESETTING, &adapter->state);
5682
5683 return 0;
5684}
5685
5686static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
5687 int cmd)
5688{
5689 struct e1000_adapter *adapter = netdev_priv(netdev);
5690 struct mii_ioctl_data *data = if_mii(ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005691
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005692 if (adapter->hw.phy.media_type != e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005693 return -EOPNOTSUPP;
5694
5695 switch (cmd) {
5696 case SIOCGMIIPHY:
5697 data->phy_id = adapter->hw.phy.addr;
5698 break;
5699 case SIOCGMIIREG:
Bruce Allanb16a0022009-11-20 23:24:30 +00005700 e1000_phy_read_status(adapter);
5701
Bruce Allan7c257692008-04-23 11:09:00 -07005702 switch (data->reg_num & 0x1F) {
5703 case MII_BMCR:
5704 data->val_out = adapter->phy_regs.bmcr;
5705 break;
5706 case MII_BMSR:
5707 data->val_out = adapter->phy_regs.bmsr;
5708 break;
5709 case MII_PHYSID1:
5710 data->val_out = (adapter->hw.phy.id >> 16);
5711 break;
5712 case MII_PHYSID2:
5713 data->val_out = (adapter->hw.phy.id & 0xFFFF);
5714 break;
5715 case MII_ADVERTISE:
5716 data->val_out = adapter->phy_regs.advertise;
5717 break;
5718 case MII_LPA:
5719 data->val_out = adapter->phy_regs.lpa;
5720 break;
5721 case MII_EXPANSION:
5722 data->val_out = adapter->phy_regs.expansion;
5723 break;
5724 case MII_CTRL1000:
5725 data->val_out = adapter->phy_regs.ctrl1000;
5726 break;
5727 case MII_STAT1000:
5728 data->val_out = adapter->phy_regs.stat1000;
5729 break;
5730 case MII_ESTATUS:
5731 data->val_out = adapter->phy_regs.estatus;
5732 break;
5733 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07005734 return -EIO;
5735 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005736 break;
5737 case SIOCSMIIREG:
5738 default:
5739 return -EOPNOTSUPP;
5740 }
5741 return 0;
5742}
5743
Bruce Allanb67e1912012-12-27 08:32:33 +00005744/**
5745 * e1000e_hwtstamp_ioctl - control hardware time stamping
5746 * @netdev: network interface device structure
5747 * @ifreq: interface request
5748 *
5749 * Outgoing time stamping can be enabled and disabled. Play nice and
5750 * disable it when requested, although it shouldn't cause any overhead
5751 * when no packet needs it. At most one packet in the queue may be
5752 * marked for time stamping, otherwise it would be impossible to tell
5753 * for sure to which packet the hardware time stamp belongs.
5754 *
5755 * Incoming time stamping has to be configured via the hardware filters.
5756 * Not all combinations are supported, in particular event type has to be
5757 * specified. Matching the kind of event packet is not supported, with the
5758 * exception of "all V2 events regardless of level 2 or 4".
5759 **/
5760static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
5761{
5762 struct e1000_adapter *adapter = netdev_priv(netdev);
5763 struct hwtstamp_config config;
5764 int ret_val;
5765
5766 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
5767 return -EFAULT;
5768
5769 adapter->hwtstamp_config = config;
5770
5771 ret_val = e1000e_config_hwtstamp(adapter);
5772 if (ret_val)
5773 return ret_val;
5774
5775 config = adapter->hwtstamp_config;
5776
Bruce Alland89777b2013-01-19 01:09:58 +00005777 switch (config.rx_filter) {
5778 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
5779 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
5780 case HWTSTAMP_FILTER_PTP_V2_SYNC:
5781 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
5782 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
5783 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
5784 /* With V2 type filters which specify a Sync or Delay Request,
5785 * Path Delay Request/Response messages are also time stamped
5786 * by hardware so notify the caller the requested packets plus
5787 * some others are time stamped.
5788 */
5789 config.rx_filter = HWTSTAMP_FILTER_SOME;
5790 break;
5791 default:
5792 break;
5793 }
5794
Bruce Allanb67e1912012-12-27 08:32:33 +00005795 return copy_to_user(ifr->ifr_data, &config,
5796 sizeof(config)) ? -EFAULT : 0;
5797}
5798
Auke Kokbc7f75f2007-09-17 12:30:59 -07005799static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
5800{
5801 switch (cmd) {
5802 case SIOCGMIIPHY:
5803 case SIOCGMIIREG:
5804 case SIOCSMIIREG:
5805 return e1000_mii_ioctl(netdev, ifr, cmd);
Bruce Allanb67e1912012-12-27 08:32:33 +00005806 case SIOCSHWTSTAMP:
5807 return e1000e_hwtstamp_ioctl(netdev, ifr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005808 default:
5809 return -EOPNOTSUPP;
5810 }
5811}
5812
Bruce Allana4f58f52009-06-02 11:29:18 +00005813static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
5814{
5815 struct e1000_hw *hw = &adapter->hw;
5816 u32 i, mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005817 u16 phy_reg, wuc_enable;
Bruce Allan70806a72013-01-05 05:08:37 +00005818 int retval;
Bruce Allana4f58f52009-06-02 11:29:18 +00005819
5820 /* copy MAC RARs to PHY RARs */
Bruce Alland3738bb2010-06-16 13:27:28 +00005821 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005822
Bruce Allan2b6b1682011-05-13 07:20:09 +00005823 retval = hw->phy.ops.acquire(hw);
5824 if (retval) {
5825 e_err("Could not acquire PHY\n");
5826 return retval;
5827 }
5828
5829 /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
5830 retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
5831 if (retval)
Bruce Allan75ce1532012-02-08 02:54:48 +00005832 goto release;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005833
5834 /* copy MAC MTA to PHY MTA - only needed for pchlan */
Bruce Allana4f58f52009-06-02 11:29:18 +00005835 for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
5836 mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
Bruce Allan2b6b1682011-05-13 07:20:09 +00005837 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
5838 (u16)(mac_reg & 0xFFFF));
5839 hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
5840 (u16)((mac_reg >> 16) & 0xFFFF));
Bruce Allana4f58f52009-06-02 11:29:18 +00005841 }
5842
5843 /* configure PHY Rx Control register */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005844 hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005845 mac_reg = er32(RCTL);
5846 if (mac_reg & E1000_RCTL_UPE)
5847 phy_reg |= BM_RCTL_UPE;
5848 if (mac_reg & E1000_RCTL_MPE)
5849 phy_reg |= BM_RCTL_MPE;
5850 phy_reg &= ~(BM_RCTL_MO_MASK);
5851 if (mac_reg & E1000_RCTL_MO_3)
5852 phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
5853 << BM_RCTL_MO_SHIFT);
5854 if (mac_reg & E1000_RCTL_BAM)
5855 phy_reg |= BM_RCTL_BAM;
5856 if (mac_reg & E1000_RCTL_PMCF)
5857 phy_reg |= BM_RCTL_PMCF;
5858 mac_reg = er32(CTRL);
5859 if (mac_reg & E1000_CTRL_RFCE)
5860 phy_reg |= BM_RCTL_RFCE;
Bruce Allan2b6b1682011-05-13 07:20:09 +00005861 hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00005862
5863 /* enable PHY wakeup in MAC register */
5864 ew32(WUFC, wufc);
5865 ew32(WUC, E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN);
5866
5867 /* configure and enable PHY wakeup in PHY registers */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005868 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
5869 hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, E1000_WUC_PME_EN);
Bruce Allana4f58f52009-06-02 11:29:18 +00005870
5871 /* activate PHY wakeup */
Bruce Allan2b6b1682011-05-13 07:20:09 +00005872 wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
5873 retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
Bruce Allana4f58f52009-06-02 11:29:18 +00005874 if (retval)
5875 e_err("Could not set PHY Host Wakeup bit\n");
Bruce Allan75ce1532012-02-08 02:54:48 +00005876release:
Bruce Allan94d81862009-11-20 23:25:26 +00005877 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00005878
5879 return retval;
5880}
5881
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005882static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
5883 bool runtime)
Auke Kokbc7f75f2007-09-17 12:30:59 -07005884{
5885 struct net_device *netdev = pci_get_drvdata(pdev);
5886 struct e1000_adapter *adapter = netdev_priv(netdev);
5887 struct e1000_hw *hw = &adapter->hw;
5888 u32 ctrl, ctrl_ext, rctl, status;
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00005889 /* Runtime suspend should only enable wakeup for link changes */
5890 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005891 int retval = 0;
5892
5893 netif_device_detach(netdev);
5894
5895 if (netif_running(netdev)) {
Bruce Allanbb9e44d2012-03-21 00:39:12 +00005896 int count = E1000_CHECK_RESET_COUNT;
5897
5898 while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
5899 usleep_range(10000, 20000);
5900
Auke Kokbc7f75f2007-09-17 12:30:59 -07005901 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
5902 e1000e_down(adapter);
5903 e1000_free_irq(adapter);
5904 }
Bruce Allan4662e822008-08-26 18:37:06 -07005905 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005906
5907 retval = pci_save_state(pdev);
5908 if (retval)
5909 return retval;
5910
5911 status = er32(STATUS);
5912 if (status & E1000_STATUS_LU)
5913 wufc &= ~E1000_WUFC_LNKC;
5914
5915 if (wufc) {
5916 e1000_setup_rctl(adapter);
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00005917 e1000e_set_rx_mode(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005918
5919 /* turn on all-multi mode if wake on multicast is enabled */
5920 if (wufc & E1000_WUFC_MC) {
5921 rctl = er32(RCTL);
5922 rctl |= E1000_RCTL_MPE;
5923 ew32(RCTL, rctl);
5924 }
5925
5926 ctrl = er32(CTRL);
5927 /* advertise wake from D3Cold */
5928 #define E1000_CTRL_ADVD3WUC 0x00100000
5929 /* phy power management enable */
5930 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
Bruce Allana4f58f52009-06-02 11:29:18 +00005931 ctrl |= E1000_CTRL_ADVD3WUC;
5932 if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
5933 ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005934 ew32(CTRL, ctrl);
5935
Jeff Kirsher318a94d2008-03-28 09:15:16 -07005936 if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
5937 adapter->hw.phy.media_type ==
5938 e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005939 /* keep the laser running in D3 */
5940 ctrl_ext = er32(CTRL_EXT);
Bruce Allan93a23f42009-12-08 07:27:41 +00005941 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005942 ew32(CTRL_EXT, ctrl_ext);
5943 }
5944
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005945 if (adapter->flags & FLAG_IS_ICH)
Bruce Allan99730e42011-05-13 07:19:48 +00005946 e1000_suspend_workarounds_ich8lan(&adapter->hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005947
Auke Kokbc7f75f2007-09-17 12:30:59 -07005948 /* Allow time for pending master requests to run */
5949 e1000e_disable_pcie_master(&adapter->hw);
5950
Bruce Allan82776a42009-08-14 14:35:33 +00005951 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
Bruce Allana4f58f52009-06-02 11:29:18 +00005952 /* enable wakeup by the PHY */
5953 retval = e1000_init_phy_wakeup(adapter, wufc);
5954 if (retval)
5955 return retval;
5956 } else {
5957 /* enable wakeup by the MAC */
5958 ew32(WUFC, wufc);
5959 ew32(WUC, E1000_WUC_PME_EN);
5960 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005961 } else {
5962 ew32(WUC, 0);
5963 ew32(WUFC, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005964 }
5965
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005966 *enable_wake = !!wufc;
5967
Auke Kokbc7f75f2007-09-17 12:30:59 -07005968 /* make sure adapter isn't asleep if manageability is enabled */
Bruce Allan82776a42009-08-14 14:35:33 +00005969 if ((adapter->flags & FLAG_MNG_PT_ENABLED) ||
5970 (hw->mac.ops.check_mng_mode(hw)))
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005971 *enable_wake = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07005972
5973 if (adapter->hw.phy.type == e1000_phy_igp_3)
5974 e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
5975
Bruce Allane921eb12012-11-28 09:28:37 +00005976 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07005977 * would have already happened in close and is redundant.
5978 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00005979 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07005980
5981 pci_disable_device(pdev);
5982
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005983 return 0;
5984}
5985
5986static void e1000_power_off(struct pci_dev *pdev, bool sleep, bool wake)
5987{
5988 if (sleep && wake) {
5989 pci_prepare_to_sleep(pdev);
5990 return;
5991 }
5992
5993 pci_wake_from_d3(pdev, wake);
5994 pci_set_power_state(pdev, PCI_D3hot);
5995}
5996
Bruce Allanf0ff4392013-02-20 04:05:39 +00005997static void e1000_complete_shutdown(struct pci_dev *pdev, bool sleep, bool wake)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00005998{
5999 struct net_device *netdev = pci_get_drvdata(pdev);
6000 struct e1000_adapter *adapter = netdev_priv(netdev);
6001
Bruce Allane921eb12012-11-28 09:28:37 +00006002 /* The pci-e switch on some quad port adapters will report a
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006003 * correctable error when the MAC transitions from D0 to D3. To
6004 * prevent this we need to mask off the correctable errors on the
6005 * downstream port of the pci-e switch.
6006 */
6007 if (adapter->flags & FLAG_IS_QUAD_PORT) {
6008 struct pci_dev *us_dev = pdev->bus->self;
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006009 u16 devctl;
6010
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006011 pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
6012 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
6013 (devctl & ~PCI_EXP_DEVCTL_CERE));
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006014
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006015 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006016
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006017 pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006018 } else {
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006019 e1000_power_off(pdev, sleep, wake);
Alexander Duyck005cbdf2008-11-21 16:49:10 -08006020 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006021}
6022
Bruce Allan6f461f62010-04-27 03:33:04 +00006023#ifdef CONFIG_PCIEASPM
6024static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
6025{
Yinghai Lu9f728f52011-05-12 17:11:47 -07006026 pci_disable_link_state_locked(pdev, state);
Bruce Allan6f461f62010-04-27 03:33:04 +00006027}
6028#else
6029static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Auke Kok1eae4eb2007-10-31 15:22:00 -07006030{
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006031 u16 aspm_ctl = 0;
6032
6033 if (state & PCIE_LINK_STATE_L0S)
6034 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L0S;
6035 if (state & PCIE_LINK_STATE_L1)
6036 aspm_ctl |= PCI_EXP_LNKCTL_ASPM_L1;
6037
Bruce Allane921eb12012-11-28 09:28:37 +00006038 /* Both device and parent should have the same ASPM setting.
Bruce Allan6f461f62010-04-27 03:33:04 +00006039 * Disable ASPM in downstream component first and then upstream.
Auke Kok1eae4eb2007-10-31 15:22:00 -07006040 */
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006041 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006042
Jiang Liuf8c0fca2012-08-20 13:30:43 -06006043 if (pdev->bus->self)
6044 pcie_capability_clear_word(pdev->bus->self, PCI_EXP_LNKCTL,
Bjorn Helgaasffe0b2ff2012-12-06 06:40:07 +00006045 aspm_ctl);
Bruce Allan6f461f62010-04-27 03:33:04 +00006046}
6047#endif
Bruce Allan78cd29d2011-03-24 03:09:03 +00006048static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
Bruce Allan6f461f62010-04-27 03:33:04 +00006049{
6050 dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
6051 (state & PCIE_LINK_STATE_L0S) ? "L0s" : "",
6052 (state & PCIE_LINK_STATE_L1) ? "L1" : "");
6053
6054 __e1000e_disable_aspm(pdev, state);
Auke Kok1eae4eb2007-10-31 15:22:00 -07006055}
6056
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006057#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006058static bool e1000e_pm_ready(struct e1000_adapter *adapter)
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006059{
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006060 return !!adapter->tx_ring->buffer_info;
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006061}
6062
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006063static int __e1000_resume(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006064{
6065 struct net_device *netdev = pci_get_drvdata(pdev);
6066 struct e1000_adapter *adapter = netdev_priv(netdev);
6067 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006068 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006069 u32 err;
6070
Bruce Allan78cd29d2011-03-24 03:09:03 +00006071 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6072 aspm_disable_flag = PCIE_LINK_STATE_L0S;
6073 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
6074 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6075 if (aspm_disable_flag)
6076 e1000e_disable_aspm(pdev, aspm_disable_flag);
6077
Auke Kokbc7f75f2007-09-17 12:30:59 -07006078 pci_set_power_state(pdev, PCI_D0);
6079 pci_restore_state(pdev);
Bruce Allan28b8f042010-01-07 16:30:56 +00006080 pci_save_state(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006081
Bruce Allan4662e822008-08-26 18:37:06 -07006082 e1000e_set_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006083 if (netif_running(netdev)) {
6084 err = e1000_request_irq(adapter);
6085 if (err)
6086 return err;
6087 }
6088
Bruce Allan2fbe4522012-04-19 03:21:47 +00006089 if (hw->mac.type >= e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00006090 e1000_resume_workarounds_pchlan(&adapter->hw);
6091
Auke Kokbc7f75f2007-09-17 12:30:59 -07006092 e1000e_power_up_phy(adapter);
Bruce Allana4f58f52009-06-02 11:29:18 +00006093
6094 /* report the system wakeup cause from S3/S4 */
6095 if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
6096 u16 phy_data;
6097
6098 e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
6099 if (phy_data) {
6100 e_info("PHY Wakeup cause - %s\n",
6101 phy_data & E1000_WUS_EX ? "Unicast Packet" :
6102 phy_data & E1000_WUS_MC ? "Multicast Packet" :
6103 phy_data & E1000_WUS_BC ? "Broadcast Packet" :
6104 phy_data & E1000_WUS_MAG ? "Magic Packet" :
Jeff Kirsheref456f82011-11-03 11:40:28 +00006105 phy_data & E1000_WUS_LNKC ?
6106 "Link Status Change" : "other");
Bruce Allana4f58f52009-06-02 11:29:18 +00006107 }
6108 e1e_wphy(&adapter->hw, BM_WUS, ~0);
6109 } else {
6110 u32 wus = er32(WUS);
6111 if (wus) {
6112 e_info("MAC Wakeup cause - %s\n",
6113 wus & E1000_WUS_EX ? "Unicast Packet" :
6114 wus & E1000_WUS_MC ? "Multicast Packet" :
6115 wus & E1000_WUS_BC ? "Broadcast Packet" :
6116 wus & E1000_WUS_MAG ? "Magic Packet" :
6117 wus & E1000_WUS_LNKC ? "Link Status Change" :
6118 "other");
6119 }
6120 ew32(WUS, ~0);
6121 }
6122
Auke Kokbc7f75f2007-09-17 12:30:59 -07006123 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006124
Bruce Allancd791612010-05-10 14:59:51 +00006125 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006126
6127 if (netif_running(netdev))
6128 e1000e_up(adapter);
6129
6130 netif_device_attach(netdev);
6131
Bruce Allane921eb12012-11-28 09:28:37 +00006132 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006133 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006134 * under the control of the driver.
6135 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006136 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006137 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006138
6139 return 0;
6140}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006141
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006142#ifdef CONFIG_PM_SLEEP
6143static int e1000_suspend(struct device *dev)
6144{
6145 struct pci_dev *pdev = to_pci_dev(dev);
6146 int retval;
6147 bool wake;
6148
6149 retval = __e1000_shutdown(pdev, &wake, false);
6150 if (!retval)
6151 e1000_complete_shutdown(pdev, true, wake);
6152
6153 return retval;
6154}
6155
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006156static int e1000_resume(struct device *dev)
6157{
6158 struct pci_dev *pdev = to_pci_dev(dev);
6159 struct net_device *netdev = pci_get_drvdata(pdev);
6160 struct e1000_adapter *adapter = netdev_priv(netdev);
6161
6162 if (e1000e_pm_ready(adapter))
6163 adapter->idle_check = true;
6164
6165 return __e1000_resume(pdev);
6166}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006167#endif /* CONFIG_PM_SLEEP */
6168
6169#ifdef CONFIG_PM_RUNTIME
6170static int e1000_runtime_suspend(struct device *dev)
6171{
6172 struct pci_dev *pdev = to_pci_dev(dev);
6173 struct net_device *netdev = pci_get_drvdata(pdev);
6174 struct e1000_adapter *adapter = netdev_priv(netdev);
6175
6176 if (e1000e_pm_ready(adapter)) {
6177 bool wake;
6178
6179 __e1000_shutdown(pdev, &wake, true);
6180 }
6181
6182 return 0;
6183}
6184
6185static int e1000_idle(struct device *dev)
6186{
6187 struct pci_dev *pdev = to_pci_dev(dev);
6188 struct net_device *netdev = pci_get_drvdata(pdev);
6189 struct e1000_adapter *adapter = netdev_priv(netdev);
6190
6191 if (!e1000e_pm_ready(adapter))
6192 return 0;
6193
6194 if (adapter->idle_check) {
6195 adapter->idle_check = false;
6196 if (!e1000e_has_link(adapter))
6197 pm_schedule_suspend(dev, MSEC_PER_SEC);
6198 }
6199
6200 return -EBUSY;
6201}
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006202
6203static int e1000_runtime_resume(struct device *dev)
6204{
6205 struct pci_dev *pdev = to_pci_dev(dev);
6206 struct net_device *netdev = pci_get_drvdata(pdev);
6207 struct e1000_adapter *adapter = netdev_priv(netdev);
6208
6209 if (!e1000e_pm_ready(adapter))
6210 return 0;
6211
6212 adapter->idle_check = !dev->power.runtime_auto;
6213 return __e1000_resume(pdev);
6214}
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006215#endif /* CONFIG_PM_RUNTIME */
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006216#endif /* CONFIG_PM */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006217
6218static void e1000_shutdown(struct pci_dev *pdev)
6219{
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006220 bool wake = false;
6221
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006222 __e1000_shutdown(pdev, &wake, false);
Rafael J. Wysocki4f9de722009-04-15 17:43:43 +00006223
6224 if (system_state == SYSTEM_POWER_OFF)
6225 e1000_complete_shutdown(pdev, false, wake);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006226}
6227
6228#ifdef CONFIG_NET_POLL_CONTROLLER
Dongdong Deng147b2c82010-11-16 19:50:15 -08006229
Bruce Allan8bb62862013-01-16 08:46:49 +00006230static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
Dongdong Deng147b2c82010-11-16 19:50:15 -08006231{
6232 struct net_device *netdev = data;
6233 struct e1000_adapter *adapter = netdev_priv(netdev);
Dongdong Deng147b2c82010-11-16 19:50:15 -08006234
6235 if (adapter->msix_entries) {
Bruce Allan90da0662011-01-06 07:02:53 +00006236 int vector, msix_irq;
6237
Dongdong Deng147b2c82010-11-16 19:50:15 -08006238 vector = 0;
6239 msix_irq = adapter->msix_entries[vector].vector;
6240 disable_irq(msix_irq);
6241 e1000_intr_msix_rx(msix_irq, netdev);
6242 enable_irq(msix_irq);
6243
6244 vector++;
6245 msix_irq = adapter->msix_entries[vector].vector;
6246 disable_irq(msix_irq);
6247 e1000_intr_msix_tx(msix_irq, netdev);
6248 enable_irq(msix_irq);
6249
6250 vector++;
6251 msix_irq = adapter->msix_entries[vector].vector;
6252 disable_irq(msix_irq);
6253 e1000_msix_other(msix_irq, netdev);
6254 enable_irq(msix_irq);
6255 }
6256
6257 return IRQ_HANDLED;
6258}
6259
Bruce Allane921eb12012-11-28 09:28:37 +00006260/**
6261 * e1000_netpoll
6262 * @netdev: network interface device structure
6263 *
Auke Kokbc7f75f2007-09-17 12:30:59 -07006264 * Polling 'interrupt' - used by things like netconsole to send skbs
6265 * without having to re-enable interrupts. It's not called while
6266 * the interrupt routine is executing.
6267 */
6268static void e1000_netpoll(struct net_device *netdev)
6269{
6270 struct e1000_adapter *adapter = netdev_priv(netdev);
6271
Dongdong Deng147b2c82010-11-16 19:50:15 -08006272 switch (adapter->int_mode) {
6273 case E1000E_INT_MODE_MSIX:
6274 e1000_intr_msix(adapter->pdev->irq, netdev);
6275 break;
6276 case E1000E_INT_MODE_MSI:
6277 disable_irq(adapter->pdev->irq);
6278 e1000_intr_msi(adapter->pdev->irq, netdev);
6279 enable_irq(adapter->pdev->irq);
6280 break;
6281 default: /* E1000E_INT_MODE_LEGACY */
6282 disable_irq(adapter->pdev->irq);
6283 e1000_intr(adapter->pdev->irq, netdev);
6284 enable_irq(adapter->pdev->irq);
6285 break;
6286 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006287}
6288#endif
6289
6290/**
6291 * e1000_io_error_detected - called when PCI error is detected
6292 * @pdev: Pointer to PCI device
6293 * @state: The current pci connection state
6294 *
6295 * This function is called after a PCI bus error affecting
6296 * this device has been detected.
6297 */
6298static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
6299 pci_channel_state_t state)
6300{
6301 struct net_device *netdev = pci_get_drvdata(pdev);
6302 struct e1000_adapter *adapter = netdev_priv(netdev);
6303
6304 netif_device_detach(netdev);
6305
Mike Masonc93b5a72009-06-30 12:45:53 +00006306 if (state == pci_channel_io_perm_failure)
6307 return PCI_ERS_RESULT_DISCONNECT;
6308
Auke Kokbc7f75f2007-09-17 12:30:59 -07006309 if (netif_running(netdev))
6310 e1000e_down(adapter);
6311 pci_disable_device(pdev);
6312
6313 /* Request a slot slot reset. */
6314 return PCI_ERS_RESULT_NEED_RESET;
6315}
6316
6317/**
6318 * e1000_io_slot_reset - called after the pci bus has been reset.
6319 * @pdev: Pointer to PCI device
6320 *
6321 * Restart the card from scratch, as if from a cold-boot. Implementation
6322 * resembles the first-half of the e1000_resume routine.
6323 */
6324static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
6325{
6326 struct net_device *netdev = pci_get_drvdata(pdev);
6327 struct e1000_adapter *adapter = netdev_priv(netdev);
6328 struct e1000_hw *hw = &adapter->hw;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006329 u16 aspm_disable_flag = 0;
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006330 int err;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006331 pci_ers_result_t result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006332
Bruce Allan78cd29d2011-03-24 03:09:03 +00006333 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
6334 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006335 if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006336 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6337 if (aspm_disable_flag)
6338 e1000e_disable_aspm(pdev, aspm_disable_flag);
6339
Bruce Allanf0f422e2008-08-04 17:21:53 -07006340 err = pci_enable_device_mem(pdev);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006341 if (err) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006342 dev_err(&pdev->dev,
6343 "Cannot re-enable PCI device after reset.\n");
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006344 result = PCI_ERS_RESULT_DISCONNECT;
6345 } else {
6346 pci_set_master(pdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006347 pdev->state_saved = true;
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006348 pci_restore_state(pdev);
6349
6350 pci_enable_wake(pdev, PCI_D3hot, 0);
6351 pci_enable_wake(pdev, PCI_D3cold, 0);
6352
6353 e1000e_reset(adapter);
6354 ew32(WUS, ~0);
6355 result = PCI_ERS_RESULT_RECOVERED;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006356 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006357
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006358 pci_cleanup_aer_uncorrect_error_status(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006359
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006360 return result;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006361}
6362
6363/**
6364 * e1000_io_resume - called when traffic can start flowing again.
6365 * @pdev: Pointer to PCI device
6366 *
6367 * This callback is called when the error recovery driver tells us that
6368 * its OK to resume normal operation. Implementation resembles the
6369 * second-half of the e1000_resume routine.
6370 */
6371static void e1000_io_resume(struct pci_dev *pdev)
6372{
6373 struct net_device *netdev = pci_get_drvdata(pdev);
6374 struct e1000_adapter *adapter = netdev_priv(netdev);
6375
Bruce Allancd791612010-05-10 14:59:51 +00006376 e1000_init_manageability_pt(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006377
6378 if (netif_running(netdev)) {
6379 if (e1000e_up(adapter)) {
6380 dev_err(&pdev->dev,
6381 "can't bring device back up after reset\n");
6382 return;
6383 }
6384 }
6385
6386 netif_device_attach(netdev);
6387
Bruce Allane921eb12012-11-28 09:28:37 +00006388 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006389 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006390 * under the control of the driver.
6391 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006392 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006393 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006394}
6395
6396static void e1000_print_device_info(struct e1000_adapter *adapter)
6397{
6398 struct e1000_hw *hw = &adapter->hw;
6399 struct net_device *netdev = adapter->netdev;
Bruce Allan073287c2010-11-24 06:01:51 +00006400 u32 ret_val;
6401 u8 pba_str[E1000_PBANUM_LENGTH];
Auke Kokbc7f75f2007-09-17 12:30:59 -07006402
6403 /* print bus type/speed/width info */
Bruce Allana5cc7642011-03-19 00:31:23 +00006404 e_info("(PCI Express:2.5GT/s:%s) %pM\n",
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006405 /* bus width */
6406 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
Bruce Allanf0ff4392013-02-20 04:05:39 +00006407 "Width x1"),
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006408 /* MAC address */
Johannes Berg7c510e42008-10-27 17:47:26 -07006409 netdev->dev_addr);
Jeff Kirsher44defeb2008-08-04 17:20:41 -07006410 e_info("Intel(R) PRO/%s Network Connection\n",
6411 (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
Bruce Allan073287c2010-11-24 06:01:51 +00006412 ret_val = e1000_read_pba_string_generic(hw, pba_str,
6413 E1000_PBANUM_LENGTH);
6414 if (ret_val)
Bruce Allanf2315bf2011-12-16 00:46:59 +00006415 strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
Bruce Allan073287c2010-11-24 06:01:51 +00006416 e_info("MAC: %d, PHY: %d, PBA No: %s\n",
6417 hw->mac.type, hw->phy.type, pba_str);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006418}
6419
Auke Kok10aa4c02008-08-04 17:21:20 -07006420static void e1000_eeprom_checks(struct e1000_adapter *adapter)
6421{
6422 struct e1000_hw *hw = &adapter->hw;
6423 int ret_val;
6424 u16 buf = 0;
6425
6426 if (hw->mac.type != e1000_82573)
6427 return;
6428
6429 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
Bruce Allane885d762012-01-31 06:37:32 +00006430 le16_to_cpus(&buf);
6431 if (!ret_val && (!(buf & (1 << 0)))) {
Auke Kok10aa4c02008-08-04 17:21:20 -07006432 /* Deep Smart Power Down (DSPD) */
Frans Pop6c2a9ef2008-09-22 14:52:22 -07006433 dev_warn(&adapter->pdev->dev,
6434 "Warning: detected DSPD enabled in EEPROM\n");
Auke Kok10aa4c02008-08-04 17:21:20 -07006435 }
Auke Kok10aa4c02008-08-04 17:21:20 -07006436}
6437
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006438static int e1000_set_features(struct net_device *netdev,
Bruce Allan70495a52012-01-11 01:26:50 +00006439 netdev_features_t features)
Bruce Allandc221292011-08-19 03:23:48 +00006440{
6441 struct e1000_adapter *adapter = netdev_priv(netdev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006442 netdev_features_t changed = features ^ netdev->features;
Bruce Allandc221292011-08-19 03:23:48 +00006443
6444 if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
6445 adapter->flags |= FLAG_TSO_FORCE;
6446
6447 if (!(changed & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX |
Ben Greearcf955e62012-02-11 15:39:51 +00006448 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
6449 NETIF_F_RXALL)))
Bruce Allandc221292011-08-19 03:23:48 +00006450 return 0;
6451
Ben Greear01840392012-02-11 15:39:25 +00006452 if (changed & NETIF_F_RXFCS) {
6453 if (features & NETIF_F_RXFCS) {
6454 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6455 } else {
6456 /* We need to take it back to defaults, which might mean
6457 * stripping is still disabled at the adapter level.
6458 */
6459 if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
6460 adapter->flags2 |= FLAG2_CRC_STRIPPING;
6461 else
6462 adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
6463 }
6464 }
6465
Bruce Allan70495a52012-01-11 01:26:50 +00006466 netdev->features = features;
6467
Bruce Allandc221292011-08-19 03:23:48 +00006468 if (netif_running(netdev))
6469 e1000e_reinit_locked(adapter);
6470 else
6471 e1000e_reset(adapter);
6472
6473 return 0;
6474}
6475
Stephen Hemminger651c2462008-11-19 21:57:48 -08006476static const struct net_device_ops e1000e_netdev_ops = {
6477 .ndo_open = e1000_open,
6478 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006479 .ndo_start_xmit = e1000_xmit_frame,
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00006480 .ndo_get_stats64 = e1000e_get_stats64,
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006481 .ndo_set_rx_mode = e1000e_set_rx_mode,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006482 .ndo_set_mac_address = e1000_set_mac,
6483 .ndo_change_mtu = e1000_change_mtu,
6484 .ndo_do_ioctl = e1000_ioctl,
6485 .ndo_tx_timeout = e1000_tx_timeout,
6486 .ndo_validate_addr = eth_validate_addr,
6487
Stephen Hemminger651c2462008-11-19 21:57:48 -08006488 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
6489 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
6490#ifdef CONFIG_NET_POLL_CONTROLLER
6491 .ndo_poll_controller = e1000_netpoll,
6492#endif
Bruce Allandc221292011-08-19 03:23:48 +00006493 .ndo_set_features = e1000_set_features,
Stephen Hemminger651c2462008-11-19 21:57:48 -08006494};
6495
Auke Kokbc7f75f2007-09-17 12:30:59 -07006496/**
6497 * e1000_probe - Device Initialization Routine
6498 * @pdev: PCI device information struct
6499 * @ent: entry in e1000_pci_tbl
6500 *
6501 * Returns 0 on success, negative on failure
6502 *
6503 * e1000_probe initializes an adapter identified by a pci_dev structure.
6504 * The OS initialization, configuring of the adapter private structure,
6505 * and a hardware reset occur.
6506 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00006507static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006508{
6509 struct net_device *netdev;
6510 struct e1000_adapter *adapter;
6511 struct e1000_hw *hw;
6512 const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
Becky Brucef47e81f2008-05-01 18:03:11 -05006513 resource_size_t mmio_start, mmio_len;
6514 resource_size_t flash_start, flash_len;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006515 static int cards_found;
Bruce Allan78cd29d2011-03-24 03:09:03 +00006516 u16 aspm_disable_flag = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006517 int i, err, pci_using_dac;
6518 u16 eeprom_data = 0;
6519 u16 eeprom_apme_mask = E1000_EEPROM_APME;
6520
Bruce Allan78cd29d2011-03-24 03:09:03 +00006521 if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
6522 aspm_disable_flag = PCIE_LINK_STATE_L0S;
Bruce Allan6f461f62010-04-27 03:33:04 +00006523 if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
Bruce Allan78cd29d2011-03-24 03:09:03 +00006524 aspm_disable_flag |= PCIE_LINK_STATE_L1;
6525 if (aspm_disable_flag)
6526 e1000e_disable_aspm(pdev, aspm_disable_flag);
Taku Izumi6e4f6f62008-06-20 11:57:02 +09006527
Bruce Allanf0f422e2008-08-04 17:21:53 -07006528 err = pci_enable_device_mem(pdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006529 if (err)
6530 return err;
6531
6532 pci_using_dac = 0;
Nick Nunley0be3f552010-04-27 13:09:05 +00006533 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006534 if (!err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006535 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006536 if (!err)
6537 pci_using_dac = 1;
6538 } else {
Nick Nunley0be3f552010-04-27 13:09:05 +00006539 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006540 if (err) {
Nick Nunley0be3f552010-04-27 13:09:05 +00006541 err = dma_set_coherent_mask(&pdev->dev,
6542 DMA_BIT_MASK(32));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006543 if (err) {
Bruce Allanf0ff4392013-02-20 04:05:39 +00006544 dev_err(&pdev->dev,
6545 "No usable DMA configuration, aborting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006546 goto err_dma;
6547 }
6548 }
6549 }
6550
Arjan van de Vene8de1482008-10-22 19:55:31 -07006551 err = pci_request_selected_regions_exclusive(pdev,
Bruce Allan55c5f552013-01-12 07:28:24 +00006552 pci_select_bars(pdev, IORESOURCE_MEM),
6553 e1000e_driver_name);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006554 if (err)
6555 goto err_pci_reg;
6556
Xiaotian Feng68eac462009-08-14 14:35:52 +00006557 /* AER (Advanced Error Reporting) hooks */
Frans Pop19d5afd2009-10-02 10:04:12 -07006558 pci_enable_pcie_error_reporting(pdev);
Xiaotian Feng68eac462009-08-14 14:35:52 +00006559
Auke Kokbc7f75f2007-09-17 12:30:59 -07006560 pci_set_master(pdev);
Bruce Allan438b3652008-11-21 16:51:33 -08006561 /* PCI config space info */
6562 err = pci_save_state(pdev);
6563 if (err)
6564 goto err_alloc_etherdev;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006565
6566 err = -ENOMEM;
6567 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
6568 if (!netdev)
6569 goto err_alloc_etherdev;
6570
Auke Kokbc7f75f2007-09-17 12:30:59 -07006571 SET_NETDEV_DEV(netdev, &pdev->dev);
6572
Tom Herbertf85e4df2010-05-05 14:03:32 +00006573 netdev->irq = pdev->irq;
6574
Auke Kokbc7f75f2007-09-17 12:30:59 -07006575 pci_set_drvdata(pdev, netdev);
6576 adapter = netdev_priv(netdev);
6577 hw = &adapter->hw;
6578 adapter->netdev = netdev;
6579 adapter->pdev = pdev;
6580 adapter->ei = ei;
6581 adapter->pba = ei->pba;
6582 adapter->flags = ei->flags;
Jeff Kirshereb7c3ad2008-11-14 06:45:23 +00006583 adapter->flags2 = ei->flags2;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006584 adapter->hw.adapter = adapter;
6585 adapter->hw.mac.type = ei->mac;
Bruce Allan2adc55c2009-06-02 11:28:58 +00006586 adapter->max_hw_frame_size = ei->max_hw_frame_size;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006587 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006588
6589 mmio_start = pci_resource_start(pdev, 0);
6590 mmio_len = pci_resource_len(pdev, 0);
6591
6592 err = -EIO;
6593 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
6594 if (!adapter->hw.hw_addr)
6595 goto err_ioremap;
6596
6597 if ((adapter->flags & FLAG_HAS_FLASH) &&
6598 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
6599 flash_start = pci_resource_start(pdev, 1);
6600 flash_len = pci_resource_len(pdev, 1);
6601 adapter->hw.flash_address = ioremap(flash_start, flash_len);
6602 if (!adapter->hw.flash_address)
6603 goto err_flashmap;
6604 }
6605
6606 /* construct the net_device struct */
Stephen Hemminger651c2462008-11-19 21:57:48 -08006607 netdev->netdev_ops = &e1000e_netdev_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006608 e1000e_set_ethtool_ops(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006609 netdev->watchdog_timeo = 5 * HZ;
Bruce Allanc58c8a72012-03-20 03:48:19 +00006610 netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
Bruce Allanf2315bf2011-12-16 00:46:59 +00006611 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006612
6613 netdev->mem_start = mmio_start;
6614 netdev->mem_end = mmio_start + mmio_len;
6615
6616 adapter->bd_number = cards_found++;
6617
Bruce Allan4662e822008-08-26 18:37:06 -07006618 e1000e_check_options(adapter);
6619
Auke Kokbc7f75f2007-09-17 12:30:59 -07006620 /* setup adapter struct */
6621 err = e1000_sw_init(adapter);
6622 if (err)
6623 goto err_sw_init;
6624
Auke Kokbc7f75f2007-09-17 12:30:59 -07006625 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
6626 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
6627 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
6628
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07006629 err = ei->get_variants(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006630 if (err)
6631 goto err_hw_init;
6632
Bruce Allan4a770352008-10-01 17:18:35 -07006633 if ((adapter->flags & FLAG_IS_ICH) &&
6634 (adapter->flags & FLAG_READ_ONLY_NVM))
6635 e1000e_write_protect_nvm_ich8lan(&adapter->hw);
6636
Auke Kokbc7f75f2007-09-17 12:30:59 -07006637 hw->mac.ops.get_bus_info(&adapter->hw);
6638
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006639 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006640
6641 /* Copper options */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07006642 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006643 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6644 adapter->hw.phy.disable_polarity_correction = 0;
6645 adapter->hw.phy.ms_type = e1000_ms_hw_default;
6646 }
6647
Bruce Allan470a5422012-05-26 06:08:48 +00006648 if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006649 dev_info(&pdev->dev,
6650 "PHY reset is blocked due to SOL/IDER session.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006651
Bruce Allandc221292011-08-19 03:23:48 +00006652 /* Set initial default active device features */
6653 netdev->features = (NETIF_F_SG |
6654 NETIF_F_HW_VLAN_RX |
6655 NETIF_F_HW_VLAN_TX |
6656 NETIF_F_TSO |
6657 NETIF_F_TSO6 |
Bruce Allan70495a52012-01-11 01:26:50 +00006658 NETIF_F_RXHASH |
Bruce Allandc221292011-08-19 03:23:48 +00006659 NETIF_F_RXCSUM |
6660 NETIF_F_HW_CSUM);
6661
6662 /* Set user-changeable features (subset of all device features) */
6663 netdev->hw_features = netdev->features;
Ben Greear01840392012-02-11 15:39:25 +00006664 netdev->hw_features |= NETIF_F_RXFCS;
Ben Greear943146d2012-02-11 15:39:40 +00006665 netdev->priv_flags |= IFF_SUPP_NOFCS;
Ben Greearcf955e62012-02-11 15:39:51 +00006666 netdev->hw_features |= NETIF_F_RXALL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006667
6668 if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
6669 netdev->features |= NETIF_F_HW_VLAN_FILTER;
6670
Bruce Allandc221292011-08-19 03:23:48 +00006671 netdev->vlan_features |= (NETIF_F_SG |
6672 NETIF_F_TSO |
6673 NETIF_F_TSO6 |
6674 NETIF_F_HW_CSUM);
Jeff Kirshera5136e22008-06-05 04:07:28 -07006675
Jesse Brandeburgef9b9652011-11-04 05:47:06 +00006676 netdev->priv_flags |= IFF_UNICAST_FLT;
6677
Yi Zou7b872a52010-09-22 17:57:58 +00006678 if (pci_using_dac) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006679 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006680 netdev->vlan_features |= NETIF_F_HIGHDMA;
6681 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07006682
Auke Kokbc7f75f2007-09-17 12:30:59 -07006683 if (e1000e_enable_mng_pass_thru(&adapter->hw))
6684 adapter->flags |= FLAG_MNG_PT_ENABLED;
6685
Bruce Allane921eb12012-11-28 09:28:37 +00006686 /* before reading the NVM, reset the controller to
Bruce Allanad680762008-03-28 09:15:03 -07006687 * put the device in a known good starting state
6688 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006689 adapter->hw.mac.ops.reset_hw(&adapter->hw);
6690
Bruce Allane921eb12012-11-28 09:28:37 +00006691 /* systems with ASPM and others may see the checksum fail on the first
Auke Kokbc7f75f2007-09-17 12:30:59 -07006692 * attempt. Let's give it a few tries
6693 */
6694 for (i = 0;; i++) {
6695 if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
6696 break;
6697 if (i == 2) {
Bruce Allan185095f2012-06-07 02:23:37 +00006698 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006699 err = -EIO;
6700 goto err_eeprom;
6701 }
6702 }
6703
Auke Kok10aa4c02008-08-04 17:21:20 -07006704 e1000_eeprom_checks(adapter);
6705
Bruce Allan608f8a02010-01-13 02:04:58 +00006706 /* copy the MAC address */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006707 if (e1000e_read_mac_addr(&adapter->hw))
Bruce Allan185095f2012-06-07 02:23:37 +00006708 dev_err(&pdev->dev,
6709 "NVM Read Error while reading MAC address\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07006710
6711 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006712
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006713 if (!is_valid_ether_addr(netdev->dev_addr)) {
Bruce Allan185095f2012-06-07 02:23:37 +00006714 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00006715 netdev->dev_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006716 err = -EIO;
6717 goto err_eeprom;
6718 }
6719
6720 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006721 adapter->watchdog_timer.function = e1000_watchdog;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006722 adapter->watchdog_timer.data = (unsigned long) adapter;
6723
6724 init_timer(&adapter->phy_info_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00006725 adapter->phy_info_timer.function = e1000_update_phy_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006726 adapter->phy_info_timer.data = (unsigned long) adapter;
6727
6728 INIT_WORK(&adapter->reset_task, e1000_reset_task);
6729 INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
Jesse Brandeburga8f88ff2008-10-02 16:33:25 -07006730 INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
6731 INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
Bruce Allan41cec6f2009-11-20 23:28:56 +00006732 INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006733
Auke Kokbc7f75f2007-09-17 12:30:59 -07006734 /* Initialize link parameters. User can change them with ethtool */
6735 adapter->hw.mac.autoneg = 1;
Rusty Russell3db1cd52011-12-19 13:56:45 +00006736 adapter->fc_autoneg = true;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08006737 adapter->hw.fc.requested_mode = e1000_fc_default;
6738 adapter->hw.fc.current_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006739 adapter->hw.phy.autoneg_advertised = 0x2f;
6740
6741 /* ring size defaults */
Bruce Alland821a4c2012-08-24 20:38:11 +00006742 adapter->rx_ring->count = E1000_DEFAULT_RXD;
6743 adapter->tx_ring->count = E1000_DEFAULT_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006744
Bruce Allane921eb12012-11-28 09:28:37 +00006745 /* Initial Wake on LAN setting - If APM wake is enabled in
Auke Kokbc7f75f2007-09-17 12:30:59 -07006746 * the EEPROM, enable the ACPI Magic Packet filter
6747 */
6748 if (adapter->flags & FLAG_APME_IN_WUC) {
6749 /* APME bit in EEPROM is mapped to WUC.APME */
6750 eeprom_data = er32(WUC);
6751 eeprom_apme_mask = E1000_WUC_APME;
Bruce Allan4def99b2011-02-02 09:30:36 +00006752 if ((hw->mac.type > e1000_ich10lan) &&
6753 (eeprom_data & E1000_WUC_PHY_WAKE))
Bruce Allana4f58f52009-06-02 11:29:18 +00006754 adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07006755 } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
6756 if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
6757 (adapter->hw.bus.func == 1))
Bruce Allan3d3a1672012-02-23 03:13:18 +00006758 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
6759 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006760 else
Bruce Allan3d3a1672012-02-23 03:13:18 +00006761 e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
6762 1, &eeprom_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006763 }
6764
6765 /* fetch WoL from EEPROM */
6766 if (eeprom_data & eeprom_apme_mask)
6767 adapter->eeprom_wol |= E1000_WUFC_MAG;
6768
Bruce Allane921eb12012-11-28 09:28:37 +00006769 /* now that we have the eeprom settings, apply the special cases
Auke Kokbc7f75f2007-09-17 12:30:59 -07006770 * where the eeprom may be wrong or the board simply won't support
6771 * wake on lan on a particular port
6772 */
6773 if (!(adapter->flags & FLAG_HAS_WOL))
6774 adapter->eeprom_wol = 0;
6775
6776 /* initialize the wol settings based on the eeprom settings */
6777 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00006778 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006779
Bruce Allan84527592008-11-21 17:00:22 -08006780 /* save off EEPROM version number */
6781 e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
6782
Auke Kokbc7f75f2007-09-17 12:30:59 -07006783 /* reset the hardware with the new settings */
6784 e1000e_reset(adapter);
6785
Bruce Allane921eb12012-11-28 09:28:37 +00006786 /* If the controller has AMT, do not set DRV_LOAD until the interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07006787 * is up. For all other cases, let the f/w know that the h/w is now
Bruce Allanad680762008-03-28 09:15:03 -07006788 * under the control of the driver.
6789 */
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006790 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006791 e1000e_get_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006792
Bruce Allanf2315bf2011-12-16 00:46:59 +00006793 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006794 err = register_netdev(netdev);
6795 if (err)
6796 goto err_register;
6797
Jesse Brandeburg9c563d22009-04-17 20:44:34 +00006798 /* carrier off reporting is important to ethtool even BEFORE open */
6799 netif_carrier_off(netdev);
6800
Bruce Alland89777b2013-01-19 01:09:58 +00006801 /* init PTP hardware clock */
6802 e1000e_ptp_init(adapter);
6803
Auke Kokbc7f75f2007-09-17 12:30:59 -07006804 e1000_print_device_info(adapter);
6805
Alan Sternf3ec4f82010-06-08 15:23:51 -04006806 if (pci_dev_run_wake(pdev))
6807 pm_runtime_put_noidle(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006808
Auke Kokbc7f75f2007-09-17 12:30:59 -07006809 return 0;
6810
6811err_register:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006812 if (!(adapter->flags & FLAG_HAS_AMT))
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006813 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006814err_eeprom:
Bruce Allan470a5422012-05-26 06:08:48 +00006815 if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07006816 e1000_phy_hw_reset(&adapter->hw);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006817err_hw_init:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006818 kfree(adapter->tx_ring);
6819 kfree(adapter->rx_ring);
6820err_sw_init:
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006821 if (adapter->hw.flash_address)
6822 iounmap(adapter->hw.flash_address);
Jeff Kirshere82f54b2008-11-14 06:45:07 +00006823 e1000e_reset_interrupt_capability(adapter);
Jesse Brandeburgc43bc57e2008-08-04 17:21:40 -07006824err_flashmap:
Auke Kokbc7f75f2007-09-17 12:30:59 -07006825 iounmap(adapter->hw.hw_addr);
6826err_ioremap:
6827 free_netdev(netdev);
6828err_alloc_etherdev:
Bruce Allanf0f422e2008-08-04 17:21:53 -07006829 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006830 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006831err_pci_reg:
6832err_dma:
6833 pci_disable_device(pdev);
6834 return err;
6835}
6836
6837/**
6838 * e1000_remove - Device Removal Routine
6839 * @pdev: PCI device information struct
6840 *
6841 * e1000_remove is called by the PCI subsystem to alert the driver
6842 * that it should release a PCI device. The could be caused by a
6843 * Hot-Plug event, or because the driver is going to be removed from
6844 * memory.
6845 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05006846static void e1000_remove(struct pci_dev *pdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -07006847{
6848 struct net_device *netdev = pci_get_drvdata(pdev);
6849 struct e1000_adapter *adapter = netdev_priv(netdev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006850 bool down = test_bit(__E1000_DOWN, &adapter->state);
6851
Bruce Alland89777b2013-01-19 01:09:58 +00006852 e1000e_ptp_remove(adapter);
6853
Bruce Allane921eb12012-11-28 09:28:37 +00006854 /* The timers may be rescheduled, so explicitly disable them
Tejun Heo23f333a2010-12-12 16:45:14 +01006855 * from being rescheduled.
Bruce Allanad680762008-03-28 09:15:03 -07006856 */
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006857 if (!down)
6858 set_bit(__E1000_DOWN, &adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006859 del_timer_sync(&adapter->watchdog_timer);
6860 del_timer_sync(&adapter->phy_info_timer);
6861
Bruce Allan41cec6f2009-11-20 23:28:56 +00006862 cancel_work_sync(&adapter->reset_task);
6863 cancel_work_sync(&adapter->watchdog_task);
6864 cancel_work_sync(&adapter->downshift_task);
6865 cancel_work_sync(&adapter->update_phy_task);
6866 cancel_work_sync(&adapter->print_hang_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006867
Bruce Allanb67e1912012-12-27 08:32:33 +00006868 if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
6869 cancel_work_sync(&adapter->tx_hwtstamp_work);
6870 if (adapter->tx_hwtstamp_skb) {
6871 dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
6872 adapter->tx_hwtstamp_skb = NULL;
6873 }
6874 }
6875
Bruce Allan17f208d2009-12-01 15:47:22 +00006876 if (!(netdev->flags & IFF_UP))
6877 e1000_power_down_phy(adapter);
6878
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006879 /* Don't lie to e1000_close() down the road. */
6880 if (!down)
6881 clear_bit(__E1000_DOWN, &adapter->state);
Bruce Allan17f208d2009-12-01 15:47:22 +00006882 unregister_netdev(netdev);
6883
Alan Sternf3ec4f82010-06-08 15:23:51 -04006884 if (pci_dev_run_wake(pdev))
6885 pm_runtime_get_noresume(&pdev->dev);
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006886
Bruce Allane921eb12012-11-28 09:28:37 +00006887 /* Release control of h/w to f/w. If f/w is AMT enabled, this
Bruce Allanad680762008-03-28 09:15:03 -07006888 * would have already happened in close and is redundant.
6889 */
Bruce Allan31dbe5b2011-01-06 14:29:52 +00006890 e1000e_release_hw_control(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006891
Bruce Allan4662e822008-08-26 18:37:06 -07006892 e1000e_reset_interrupt_capability(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07006893 kfree(adapter->tx_ring);
6894 kfree(adapter->rx_ring);
6895
6896 iounmap(adapter->hw.hw_addr);
6897 if (adapter->hw.flash_address)
6898 iounmap(adapter->hw.flash_address);
Bruce Allanf0f422e2008-08-04 17:21:53 -07006899 pci_release_selected_regions(pdev,
Bruce Allanf0ff4392013-02-20 04:05:39 +00006900 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kokbc7f75f2007-09-17 12:30:59 -07006901
6902 free_netdev(netdev);
6903
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006904 /* AER disable */
Frans Pop19d5afd2009-10-02 10:04:12 -07006905 pci_disable_pcie_error_reporting(pdev);
Jesse Brandeburg111b9dc2009-02-10 12:51:20 +00006906
Auke Kokbc7f75f2007-09-17 12:30:59 -07006907 pci_disable_device(pdev);
6908}
6909
6910/* PCI Error Recovery (ERS) */
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07006911static const struct pci_error_handlers e1000_err_handler = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006912 .error_detected = e1000_io_error_detected,
6913 .slot_reset = e1000_io_slot_reset,
6914 .resume = e1000_io_resume,
6915};
6916
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006917static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07006918 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
6919 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
6920 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
6921 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP), board_82571 },
6922 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
6923 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
Auke Kok040babf2007-10-31 15:22:05 -07006924 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
6925 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
6926 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
Bruce Allanad680762008-03-28 09:15:03 -07006927
Auke Kokbc7f75f2007-09-17 12:30:59 -07006928 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
6929 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
6930 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
6931 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
Bruce Allanad680762008-03-28 09:15:03 -07006932
Auke Kokbc7f75f2007-09-17 12:30:59 -07006933 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
6934 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
6935 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
Bruce Allanad680762008-03-28 09:15:03 -07006936
Bruce Allan4662e822008-08-26 18:37:06 -07006937 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
Bruce Allanbef28b12009-03-24 23:28:02 -07006938 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
Alexander Duyck8c81c9c2009-03-19 01:12:27 +00006939 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
Bruce Allan4662e822008-08-26 18:37:06 -07006940
Auke Kokbc7f75f2007-09-17 12:30:59 -07006941 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
6942 board_80003es2lan },
6943 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
6944 board_80003es2lan },
6945 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
6946 board_80003es2lan },
6947 { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
6948 board_80003es2lan },
Bruce Allanad680762008-03-28 09:15:03 -07006949
Auke Kokbc7f75f2007-09-17 12:30:59 -07006950 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
6951 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
6952 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
6953 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
6954 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
6955 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
6956 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
Bruce Allan9e135a22009-12-01 15:50:31 +00006957 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
Bruce Allanad680762008-03-28 09:15:03 -07006958
Auke Kokbc7f75f2007-09-17 12:30:59 -07006959 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
6960 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
6961 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
6962 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
6963 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
Bruce Allan2f15f9d2008-08-26 18:36:36 -07006964 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
Bruce Allan97ac8ca2008-04-29 09:16:05 -07006965 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
6966 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
6967 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
6968
6969 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
6970 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
6971 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
Auke Kokbc7f75f2007-09-17 12:30:59 -07006972
Bruce Allanf4187b52008-08-26 18:36:50 -07006973 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
6974 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
Bruce Allan10df0b92010-05-10 15:02:52 +00006975 { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
Bruce Allanf4187b52008-08-26 18:36:50 -07006976
Bruce Allana4f58f52009-06-02 11:29:18 +00006977 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
6978 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
6979 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
6980 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
6981
Bruce Alland3738bb2010-06-16 13:27:28 +00006982 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
6983 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
6984
Bruce Allan2fbe4522012-04-19 03:21:47 +00006985 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
6986 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
Bruce Allan16e310a2012-10-09 01:11:26 +00006987 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
6988 { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
Bruce Allan2fbe4522012-04-19 03:21:47 +00006989
Bruce Allanf36bb6c2012-01-31 06:38:04 +00006990 { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
Auke Kokbc7f75f2007-09-17 12:30:59 -07006991};
6992MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
6993
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01006994#ifdef CONFIG_PM
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006995static const struct dev_pm_ops e1000_pm_ops = {
Rafael J. Wysockia0340162010-03-17 23:12:24 -07006996 SET_SYSTEM_SLEEP_PM_OPS(e1000_suspend, e1000_resume)
6997 SET_RUNTIME_PM_OPS(e1000_runtime_suspend,
6998 e1000_runtime_resume, e1000_idle)
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00006999};
David S. Millere50208a2010-03-16 23:36:24 -07007000#endif
Rafael J. Wysocki23606cf2010-03-14 14:35:17 +00007001
Auke Kokbc7f75f2007-09-17 12:30:59 -07007002/* PCI Device API Driver */
7003static struct pci_driver e1000_driver = {
7004 .name = e1000e_driver_name,
7005 .id_table = e1000_pci_tbl,
7006 .probe = e1000_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007007 .remove = e1000_remove,
Rafael J. Wysockiaa338602011-02-11 00:06:54 +01007008#ifdef CONFIG_PM
Bruce Allanf36bb6c2012-01-31 06:38:04 +00007009 .driver = {
7010 .pm = &e1000_pm_ops,
7011 },
Auke Kokbc7f75f2007-09-17 12:30:59 -07007012#endif
7013 .shutdown = e1000_shutdown,
7014 .err_handler = &e1000_err_handler
7015};
7016
7017/**
7018 * e1000_init_module - Driver Registration Routine
7019 *
7020 * e1000_init_module is the first routine called when the driver is
7021 * loaded. All it does is register with the PCI subsystem.
7022 **/
7023static int __init e1000_init_module(void)
7024{
7025 int ret;
Bruce Allan8544b9f2010-03-24 12:55:30 +00007026 pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
7027 e1000e_driver_version);
Bruce Allanbf670442013-01-01 16:00:01 +00007028 pr_info("Copyright(c) 1999 - 2013 Intel Corporation.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07007029 ret = pci_register_driver(&e1000_driver);
Bruce Allan53ec5492009-11-20 23:27:40 +00007030
Auke Kokbc7f75f2007-09-17 12:30:59 -07007031 return ret;
7032}
7033module_init(e1000_init_module);
7034
7035/**
7036 * e1000_exit_module - Driver Exit Cleanup Routine
7037 *
7038 * e1000_exit_module is called just before the driver is removed
7039 * from memory.
7040 **/
7041static void __exit e1000_exit_module(void)
7042{
7043 pci_unregister_driver(&e1000_driver);
Auke Kokbc7f75f2007-09-17 12:30:59 -07007044}
7045module_exit(e1000_exit_module);
7046
7047
7048MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
7049MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
7050MODULE_LICENSE("GPL");
7051MODULE_VERSION(DRV_VERSION);
7052
Bruce Allan06c24b92012-02-23 03:13:13 +00007053/* netdev.c */