devices/e1000e/netdev-3.16-ethercat.c
changeset 2589 2b9c78543663
equal deleted inserted replaced
2415:af21f0bdc7c9 2589:2b9c78543663
       
     1 /* Intel PRO/1000 Linux driver
       
     2  * Copyright(c) 1999 - 2014 Intel Corporation.
       
     3  *
       
     4  * This program is free software; you can redistribute it and/or modify it
       
     5  * under the terms and conditions of the GNU General Public License,
       
     6  * version 2, as published by the Free Software Foundation.
       
     7  *
       
     8  * This program is distributed in the hope it will be useful, but WITHOUT
       
     9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
       
    11  * more details.
       
    12  *
       
    13  * The full GNU General Public License is included in this distribution in
       
    14  * the file called "COPYING".
       
    15  *
       
    16  * Contact Information:
       
    17  * Linux NICS <linux.nics@intel.com>
       
    18  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
       
    19  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
       
    20  *
       
    21  * vim: noexpandtab
       
    22  */
       
    23 
       
    24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
       
    25 
       
    26 #include <linux/module.h>
       
    27 #include <linux/types.h>
       
    28 #include <linux/init.h>
       
    29 #include <linux/pci.h>
       
    30 #include <linux/vmalloc.h>
       
    31 #include <linux/pagemap.h>
       
    32 #include <linux/delay.h>
       
    33 #include <linux/netdevice.h>
       
    34 #include <linux/interrupt.h>
       
    35 #include <linux/tcp.h>
       
    36 #include <linux/ipv6.h>
       
    37 #include <linux/slab.h>
       
    38 #include <net/checksum.h>
       
    39 #include <net/ip6_checksum.h>
       
    40 #include <linux/ethtool.h>
       
    41 #include <linux/if_vlan.h>
       
    42 #include <linux/cpu.h>
       
    43 #include <linux/smp.h>
       
    44 #include <linux/pm_qos.h>
       
    45 #include <linux/pm_runtime.h>
       
    46 #include <linux/aer.h>
       
    47 #include <linux/prefetch.h>
       
    48 
       
    49 #include "e1000-3.16-ethercat.h"
       
    50 
       
    51 #define DRV_EXTRAVERSION "-k-EtherCAT"
       
    52 
       
    53 #define DRV_VERSION "2.3.2" DRV_EXTRAVERSION
       
    54 char e1000e_driver_name[] = "ec_e1000e";
       
    55 const char e1000e_driver_version[] = DRV_VERSION;
       
    56 
       
    57 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
       
    58 static int debug = -1;
       
    59 module_param(debug, int, 0);
       
    60 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
       
    61 
       
    62 static const struct e1000_info *e1000_info_tbl[] = {
       
    63 	[board_82571]		= &e1000_82571_info,
       
    64 	[board_82572]		= &e1000_82572_info,
       
    65 	[board_82573]		= &e1000_82573_info,
       
    66 	[board_82574]		= &e1000_82574_info,
       
    67 	[board_82583]		= &e1000_82583_info,
       
    68 	[board_80003es2lan]	= &e1000_es2_info,
       
    69 	[board_ich8lan]		= &e1000_ich8_info,
       
    70 	[board_ich9lan]		= &e1000_ich9_info,
       
    71 	[board_ich10lan]	= &e1000_ich10_info,
       
    72 	[board_pchlan]		= &e1000_pch_info,
       
    73 	[board_pch2lan]		= &e1000_pch2_info,
       
    74 	[board_pch_lpt]		= &e1000_pch_lpt_info,
       
    75 };
       
    76 
       
    77 struct e1000_reg_info {
       
    78 	u32 ofs;
       
    79 	char *name;
       
    80 };
       
    81 
       
    82 static const struct e1000_reg_info e1000_reg_info_tbl[] = {
       
    83 	/* General Registers */
       
    84 	{E1000_CTRL, "CTRL"},
       
    85 	{E1000_STATUS, "STATUS"},
       
    86 	{E1000_CTRL_EXT, "CTRL_EXT"},
       
    87 
       
    88 	/* Interrupt Registers */
       
    89 	{E1000_ICR, "ICR"},
       
    90 
       
    91 	/* Rx Registers */
       
    92 	{E1000_RCTL, "RCTL"},
       
    93 	{E1000_RDLEN(0), "RDLEN"},
       
    94 	{E1000_RDH(0), "RDH"},
       
    95 	{E1000_RDT(0), "RDT"},
       
    96 	{E1000_RDTR, "RDTR"},
       
    97 	{E1000_RXDCTL(0), "RXDCTL"},
       
    98 	{E1000_ERT, "ERT"},
       
    99 	{E1000_RDBAL(0), "RDBAL"},
       
   100 	{E1000_RDBAH(0), "RDBAH"},
       
   101 	{E1000_RDFH, "RDFH"},
       
   102 	{E1000_RDFT, "RDFT"},
       
   103 	{E1000_RDFHS, "RDFHS"},
       
   104 	{E1000_RDFTS, "RDFTS"},
       
   105 	{E1000_RDFPC, "RDFPC"},
       
   106 
       
   107 	/* Tx Registers */
       
   108 	{E1000_TCTL, "TCTL"},
       
   109 	{E1000_TDBAL(0), "TDBAL"},
       
   110 	{E1000_TDBAH(0), "TDBAH"},
       
   111 	{E1000_TDLEN(0), "TDLEN"},
       
   112 	{E1000_TDH(0), "TDH"},
       
   113 	{E1000_TDT(0), "TDT"},
       
   114 	{E1000_TIDV, "TIDV"},
       
   115 	{E1000_TXDCTL(0), "TXDCTL"},
       
   116 	{E1000_TADV, "TADV"},
       
   117 	{E1000_TARC(0), "TARC"},
       
   118 	{E1000_TDFH, "TDFH"},
       
   119 	{E1000_TDFT, "TDFT"},
       
   120 	{E1000_TDFHS, "TDFHS"},
       
   121 	{E1000_TDFTS, "TDFTS"},
       
   122 	{E1000_TDFPC, "TDFPC"},
       
   123 
       
   124 	/* List Terminator */
       
   125 	{0, NULL}
       
   126 };
       
   127 
       
   128 /**
       
   129  * __ew32_prepare - prepare to write to MAC CSR register on certain parts
       
   130  * @hw: pointer to the HW structure
       
   131  *
       
   132  * When updating the MAC CSR registers, the Manageability Engine (ME) could
       
   133  * be accessing the registers at the same time.  Normally, this is handled in
       
   134  * h/w by an arbiter but on some parts there is a bug that acknowledges Host
       
   135  * accesses later than it should which could result in the register to have
       
   136  * an incorrect value.  Workaround this by checking the FWSM register which
       
   137  * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
       
   138  * and try again a number of times.
       
   139  **/
       
   140 s32 __ew32_prepare(struct e1000_hw *hw)
       
   141 {
       
   142 	s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
       
   143 
       
   144 	while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
       
   145 		udelay(50);
       
   146 
       
   147 	return i;
       
   148 }
       
   149 
       
   150 void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
       
   151 {
       
   152 	if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
   153 		__ew32_prepare(hw);
       
   154 
       
   155 	writel(val, hw->hw_addr + reg);
       
   156 }
       
   157 
       
   158 /**
       
   159  * e1000_regdump - register printout routine
       
   160  * @hw: pointer to the HW structure
       
   161  * @reginfo: pointer to the register info table
       
   162  **/
       
   163 static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
       
   164 {
       
   165 	int n = 0;
       
   166 	char rname[16];
       
   167 	u32 regs[8];
       
   168 
       
   169 	switch (reginfo->ofs) {
       
   170 	case E1000_RXDCTL(0):
       
   171 		for (n = 0; n < 2; n++)
       
   172 			regs[n] = __er32(hw, E1000_RXDCTL(n));
       
   173 		break;
       
   174 	case E1000_TXDCTL(0):
       
   175 		for (n = 0; n < 2; n++)
       
   176 			regs[n] = __er32(hw, E1000_TXDCTL(n));
       
   177 		break;
       
   178 	case E1000_TARC(0):
       
   179 		for (n = 0; n < 2; n++)
       
   180 			regs[n] = __er32(hw, E1000_TARC(n));
       
   181 		break;
       
   182 	default:
       
   183 		pr_info("%-15s %08x\n",
       
   184 			reginfo->name, __er32(hw, reginfo->ofs));
       
   185 		return;
       
   186 	}
       
   187 
       
   188 	snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
       
   189 	pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
       
   190 }
       
   191 
       
   192 static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
       
   193 				 struct e1000_buffer *bi)
       
   194 {
       
   195 	int i;
       
   196 	struct e1000_ps_page *ps_page;
       
   197 
       
   198 	for (i = 0; i < adapter->rx_ps_pages; i++) {
       
   199 		ps_page = &bi->ps_pages[i];
       
   200 
       
   201 		if (ps_page->page) {
       
   202 			pr_info("packet dump for ps_page %d:\n", i);
       
   203 			print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
       
   204 				       16, 1, page_address(ps_page->page),
       
   205 				       PAGE_SIZE, true);
       
   206 		}
       
   207 	}
       
   208 }
       
   209 
       
   210 /**
       
   211  * e1000e_dump - Print registers, Tx-ring and Rx-ring
       
   212  * @adapter: board private structure
       
   213  **/
       
   214 static void e1000e_dump(struct e1000_adapter *adapter)
       
   215 {
       
   216 	struct net_device *netdev = adapter->netdev;
       
   217 	struct e1000_hw *hw = &adapter->hw;
       
   218 	struct e1000_reg_info *reginfo;
       
   219 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
   220 	struct e1000_tx_desc *tx_desc;
       
   221 	struct my_u0 {
       
   222 		__le64 a;
       
   223 		__le64 b;
       
   224 	} *u0;
       
   225 	struct e1000_buffer *buffer_info;
       
   226 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
   227 	union e1000_rx_desc_packet_split *rx_desc_ps;
       
   228 	union e1000_rx_desc_extended *rx_desc;
       
   229 	struct my_u1 {
       
   230 		__le64 a;
       
   231 		__le64 b;
       
   232 		__le64 c;
       
   233 		__le64 d;
       
   234 	} *u1;
       
   235 	u32 staterr;
       
   236 	int i = 0;
       
   237 
       
   238 	if (!netif_msg_hw(adapter))
       
   239 		return;
       
   240 
       
   241 	/* Print netdevice Info */
       
   242 	if (netdev) {
       
   243 		dev_info(&adapter->pdev->dev, "Net device Info\n");
       
   244 		pr_info("Device Name     state            trans_start      last_rx\n");
       
   245 		pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
       
   246 			netdev->state, netdev->trans_start, netdev->last_rx);
       
   247 	}
       
   248 
       
   249 	/* Print Registers */
       
   250 	dev_info(&adapter->pdev->dev, "Register Dump\n");
       
   251 	pr_info(" Register Name   Value\n");
       
   252 	for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
       
   253 	     reginfo->name; reginfo++) {
       
   254 		e1000_regdump(hw, reginfo);
       
   255 	}
       
   256 
       
   257 	/* Print Tx Ring Summary */
       
   258 	if (!netdev || !netif_running(netdev))
       
   259 		return;
       
   260 
       
   261 	dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
       
   262 	pr_info("Queue [NTU] [NTC] [bi(ntc)->dma  ] leng ntw timestamp\n");
       
   263 	buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
       
   264 	pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
       
   265 		0, tx_ring->next_to_use, tx_ring->next_to_clean,
       
   266 		(unsigned long long)buffer_info->dma,
       
   267 		buffer_info->length,
       
   268 		buffer_info->next_to_watch,
       
   269 		(unsigned long long)buffer_info->time_stamp);
       
   270 
       
   271 	/* Print Tx Ring */
       
   272 	if (!netif_msg_tx_done(adapter))
       
   273 		goto rx_ring_summary;
       
   274 
       
   275 	dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
       
   276 
       
   277 	/* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
       
   278 	 *
       
   279 	 * Legacy Transmit Descriptor
       
   280 	 *   +--------------------------------------------------------------+
       
   281 	 * 0 |         Buffer Address [63:0] (Reserved on Write Back)       |
       
   282 	 *   +--------------------------------------------------------------+
       
   283 	 * 8 | Special  |    CSS     | Status |  CMD    |  CSO   |  Length  |
       
   284 	 *   +--------------------------------------------------------------+
       
   285 	 *   63       48 47        36 35    32 31     24 23    16 15        0
       
   286 	 *
       
   287 	 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
       
   288 	 *   63      48 47    40 39       32 31             16 15    8 7      0
       
   289 	 *   +----------------------------------------------------------------+
       
   290 	 * 0 |  TUCSE  | TUCS0  |   TUCSS   |     IPCSE       | IPCS0 | IPCSS |
       
   291 	 *   +----------------------------------------------------------------+
       
   292 	 * 8 |   MSS   | HDRLEN | RSV | STA | TUCMD | DTYP |      PAYLEN      |
       
   293 	 *   +----------------------------------------------------------------+
       
   294 	 *   63      48 47    40 39 36 35 32 31   24 23  20 19                0
       
   295 	 *
       
   296 	 * Extended Data Descriptor (DTYP=0x1)
       
   297 	 *   +----------------------------------------------------------------+
       
   298 	 * 0 |                     Buffer Address [63:0]                      |
       
   299 	 *   +----------------------------------------------------------------+
       
   300 	 * 8 | VLAN tag |  POPTS  | Rsvd | Status | Command | DTYP |  DTALEN  |
       
   301 	 *   +----------------------------------------------------------------+
       
   302 	 *   63       48 47     40 39  36 35    32 31     24 23  20 19        0
       
   303 	 */
       
   304 	pr_info("Tl[desc]     [address 63:0  ] [SpeCssSCmCsLen] [bi->dma       ] leng  ntw timestamp        bi->skb <-- Legacy format\n");
       
   305 	pr_info("Tc[desc]     [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma       ] leng  ntw timestamp        bi->skb <-- Ext Context format\n");
       
   306 	pr_info("Td[desc]     [address 63:0  ] [VlaPoRSCm1Dlen] [bi->dma       ] leng  ntw timestamp        bi->skb <-- Ext Data format\n");
       
   307 	for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
       
   308 		const char *next_desc;
       
   309 		tx_desc = E1000_TX_DESC(*tx_ring, i);
       
   310 		buffer_info = &tx_ring->buffer_info[i];
       
   311 		u0 = (struct my_u0 *)tx_desc;
       
   312 		if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
       
   313 			next_desc = " NTC/U";
       
   314 		else if (i == tx_ring->next_to_use)
       
   315 			next_desc = " NTU";
       
   316 		else if (i == tx_ring->next_to_clean)
       
   317 			next_desc = " NTC";
       
   318 		else
       
   319 			next_desc = "";
       
   320 		pr_info("T%c[0x%03X]    %016llX %016llX %016llX %04X  %3X %016llX %p%s\n",
       
   321 			(!(le64_to_cpu(u0->b) & (1 << 29)) ? 'l' :
       
   322 			 ((le64_to_cpu(u0->b) & (1 << 20)) ? 'd' : 'c')),
       
   323 			i,
       
   324 			(unsigned long long)le64_to_cpu(u0->a),
       
   325 			(unsigned long long)le64_to_cpu(u0->b),
       
   326 			(unsigned long long)buffer_info->dma,
       
   327 			buffer_info->length, buffer_info->next_to_watch,
       
   328 			(unsigned long long)buffer_info->time_stamp,
       
   329 			buffer_info->skb, next_desc);
       
   330 
       
   331 		if (netif_msg_pktdata(adapter) && buffer_info->skb)
       
   332 			print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
       
   333 				       16, 1, buffer_info->skb->data,
       
   334 				       buffer_info->skb->len, true);
       
   335 	}
       
   336 
       
   337 	/* Print Rx Ring Summary */
       
   338 rx_ring_summary:
       
   339 	dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
       
   340 	pr_info("Queue [NTU] [NTC]\n");
       
   341 	pr_info(" %5d %5X %5X\n",
       
   342 		0, rx_ring->next_to_use, rx_ring->next_to_clean);
       
   343 
       
   344 	/* Print Rx Ring */
       
   345 	if (!netif_msg_rx_status(adapter))
       
   346 		return;
       
   347 
       
   348 	dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
       
   349 	switch (adapter->rx_ps_pages) {
       
   350 	case 1:
       
   351 	case 2:
       
   352 	case 3:
       
   353 		/* [Extended] Packet Split Receive Descriptor Format
       
   354 		 *
       
   355 		 *    +-----------------------------------------------------+
       
   356 		 *  0 |                Buffer Address 0 [63:0]              |
       
   357 		 *    +-----------------------------------------------------+
       
   358 		 *  8 |                Buffer Address 1 [63:0]              |
       
   359 		 *    +-----------------------------------------------------+
       
   360 		 * 16 |                Buffer Address 2 [63:0]              |
       
   361 		 *    +-----------------------------------------------------+
       
   362 		 * 24 |                Buffer Address 3 [63:0]              |
       
   363 		 *    +-----------------------------------------------------+
       
   364 		 */
       
   365 		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");
       
   366 		/* [Extended] Receive Descriptor (Write-Back) Format
       
   367 		 *
       
   368 		 *   63       48 47    32 31     13 12    8 7    4 3        0
       
   369 		 *   +------------------------------------------------------+
       
   370 		 * 0 | Packet   | IP     |  Rsvd   | MRQ   | Rsvd | MRQ RSS |
       
   371 		 *   | Checksum | Ident  |         | Queue |      |  Type   |
       
   372 		 *   +------------------------------------------------------+
       
   373 		 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
       
   374 		 *   +------------------------------------------------------+
       
   375 		 *   63       48 47    32 31            20 19               0
       
   376 		 */
       
   377 		pr_info("RWB[desc]      [ck ipid mrqhsh] [vl   l0 ee  es] [ l3  l2  l1 hs] [reserved      ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
       
   378 		for (i = 0; i < rx_ring->count; i++) {
       
   379 			const char *next_desc;
       
   380 			buffer_info = &rx_ring->buffer_info[i];
       
   381 			rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
       
   382 			u1 = (struct my_u1 *)rx_desc_ps;
       
   383 			staterr =
       
   384 			    le32_to_cpu(rx_desc_ps->wb.middle.status_error);
       
   385 
       
   386 			if (i == rx_ring->next_to_use)
       
   387 				next_desc = " NTU";
       
   388 			else if (i == rx_ring->next_to_clean)
       
   389 				next_desc = " NTC";
       
   390 			else
       
   391 				next_desc = "";
       
   392 
       
   393 			if (staterr & E1000_RXD_STAT_DD) {
       
   394 				/* Descriptor Done */
       
   395 				pr_info("%s[0x%03X]     %016llX %016llX %016llX %016llX ---------------- %p%s\n",
       
   396 					"RWB", i,
       
   397 					(unsigned long long)le64_to_cpu(u1->a),
       
   398 					(unsigned long long)le64_to_cpu(u1->b),
       
   399 					(unsigned long long)le64_to_cpu(u1->c),
       
   400 					(unsigned long long)le64_to_cpu(u1->d),
       
   401 					buffer_info->skb, next_desc);
       
   402 			} else {
       
   403 				pr_info("%s[0x%03X]     %016llX %016llX %016llX %016llX %016llX %p%s\n",
       
   404 					"R  ", i,
       
   405 					(unsigned long long)le64_to_cpu(u1->a),
       
   406 					(unsigned long long)le64_to_cpu(u1->b),
       
   407 					(unsigned long long)le64_to_cpu(u1->c),
       
   408 					(unsigned long long)le64_to_cpu(u1->d),
       
   409 					(unsigned long long)buffer_info->dma,
       
   410 					buffer_info->skb, next_desc);
       
   411 
       
   412 				if (netif_msg_pktdata(adapter))
       
   413 					e1000e_dump_ps_pages(adapter,
       
   414 							     buffer_info);
       
   415 			}
       
   416 		}
       
   417 		break;
       
   418 	default:
       
   419 	case 0:
       
   420 		/* Extended Receive Descriptor (Read) Format
       
   421 		 *
       
   422 		 *   +-----------------------------------------------------+
       
   423 		 * 0 |                Buffer Address [63:0]                |
       
   424 		 *   +-----------------------------------------------------+
       
   425 		 * 8 |                      Reserved                       |
       
   426 		 *   +-----------------------------------------------------+
       
   427 		 */
       
   428 		pr_info("R  [desc]      [buf addr 63:0 ] [reserved 63:0 ] [bi->dma       ] [bi->skb] <-- Ext (Read) format\n");
       
   429 		/* Extended Receive Descriptor (Write-Back) Format
       
   430 		 *
       
   431 		 *   63       48 47    32 31    24 23            4 3        0
       
   432 		 *   +------------------------------------------------------+
       
   433 		 *   |     RSS Hash      |        |               |         |
       
   434 		 * 0 +-------------------+  Rsvd  |   Reserved    | MRQ RSS |
       
   435 		 *   | Packet   | IP     |        |               |  Type   |
       
   436 		 *   | Checksum | Ident  |        |               |         |
       
   437 		 *   +------------------------------------------------------+
       
   438 		 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
       
   439 		 *   +------------------------------------------------------+
       
   440 		 *   63       48 47    32 31            20 19               0
       
   441 		 */
       
   442 		pr_info("RWB[desc]      [cs ipid    mrq] [vt   ln xe  xs] [bi->skb] <-- Ext (Write-Back) format\n");
       
   443 
       
   444 		for (i = 0; i < rx_ring->count; i++) {
       
   445 			const char *next_desc;
       
   446 
       
   447 			buffer_info = &rx_ring->buffer_info[i];
       
   448 			rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
       
   449 			u1 = (struct my_u1 *)rx_desc;
       
   450 			staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
       
   451 
       
   452 			if (i == rx_ring->next_to_use)
       
   453 				next_desc = " NTU";
       
   454 			else if (i == rx_ring->next_to_clean)
       
   455 				next_desc = " NTC";
       
   456 			else
       
   457 				next_desc = "";
       
   458 
       
   459 			if (staterr & E1000_RXD_STAT_DD) {
       
   460 				/* Descriptor Done */
       
   461 				pr_info("%s[0x%03X]     %016llX %016llX ---------------- %p%s\n",
       
   462 					"RWB", i,
       
   463 					(unsigned long long)le64_to_cpu(u1->a),
       
   464 					(unsigned long long)le64_to_cpu(u1->b),
       
   465 					buffer_info->skb, next_desc);
       
   466 			} else {
       
   467 				pr_info("%s[0x%03X]     %016llX %016llX %016llX %p%s\n",
       
   468 					"R  ", i,
       
   469 					(unsigned long long)le64_to_cpu(u1->a),
       
   470 					(unsigned long long)le64_to_cpu(u1->b),
       
   471 					(unsigned long long)buffer_info->dma,
       
   472 					buffer_info->skb, next_desc);
       
   473 
       
   474 				if (netif_msg_pktdata(adapter) &&
       
   475 				    buffer_info->skb)
       
   476 					print_hex_dump(KERN_INFO, "",
       
   477 						       DUMP_PREFIX_ADDRESS, 16,
       
   478 						       1,
       
   479 						       buffer_info->skb->data,
       
   480 						       adapter->rx_buffer_len,
       
   481 						       true);
       
   482 			}
       
   483 		}
       
   484 	}
       
   485 }
       
   486 
       
   487 /**
       
   488  * e1000_desc_unused - calculate if we have unused descriptors
       
   489  **/
       
   490 static int e1000_desc_unused(struct e1000_ring *ring)
       
   491 {
       
   492 	if (ring->next_to_clean > ring->next_to_use)
       
   493 		return ring->next_to_clean - ring->next_to_use - 1;
       
   494 
       
   495 	return ring->count + ring->next_to_clean - ring->next_to_use - 1;
       
   496 }
       
   497 
       
   498 /**
       
   499  * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
       
   500  * @adapter: board private structure
       
   501  * @hwtstamps: time stamp structure to update
       
   502  * @systim: unsigned 64bit system time value.
       
   503  *
       
   504  * Convert the system time value stored in the RX/TXSTMP registers into a
       
   505  * hwtstamp which can be used by the upper level time stamping functions.
       
   506  *
       
   507  * The 'systim_lock' spinlock is used to protect the consistency of the
       
   508  * system time value. This is needed because reading the 64 bit time
       
   509  * value involves reading two 32 bit registers. The first read latches the
       
   510  * value.
       
   511  **/
       
   512 static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
       
   513 				      struct skb_shared_hwtstamps *hwtstamps,
       
   514 				      u64 systim)
       
   515 {
       
   516 	u64 ns;
       
   517 	unsigned long flags;
       
   518 
       
   519 	spin_lock_irqsave(&adapter->systim_lock, flags);
       
   520 	ns = timecounter_cyc2time(&adapter->tc, systim);
       
   521 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
       
   522 
       
   523 	memset(hwtstamps, 0, sizeof(*hwtstamps));
       
   524 	hwtstamps->hwtstamp = ns_to_ktime(ns);
       
   525 }
       
   526 
       
   527 /**
       
   528  * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
       
   529  * @adapter: board private structure
       
   530  * @status: descriptor extended error and status field
       
   531  * @skb: particular skb to include time stamp
       
   532  *
       
   533  * If the time stamp is valid, convert it into the timecounter ns value
       
   534  * and store that result into the shhwtstamps structure which is passed
       
   535  * up the network stack.
       
   536  **/
       
   537 static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
       
   538 			       struct sk_buff *skb)
       
   539 {
       
   540 	struct e1000_hw *hw = &adapter->hw;
       
   541 	u64 rxstmp;
       
   542 
       
   543 	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
       
   544 	    !(status & E1000_RXDEXT_STATERR_TST) ||
       
   545 	    !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
       
   546 		return;
       
   547 
       
   548 	/* The Rx time stamp registers contain the time stamp.  No other
       
   549 	 * received packet will be time stamped until the Rx time stamp
       
   550 	 * registers are read.  Because only one packet can be time stamped
       
   551 	 * at a time, the register values must belong to this packet and
       
   552 	 * therefore none of the other additional attributes need to be
       
   553 	 * compared.
       
   554 	 */
       
   555 	rxstmp = (u64)er32(RXSTMPL);
       
   556 	rxstmp |= (u64)er32(RXSTMPH) << 32;
       
   557 	e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
       
   558 
       
   559 	adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
       
   560 }
       
   561 
       
   562 /**
       
   563  * e1000_receive_skb - helper function to handle Rx indications
       
   564  * @adapter: board private structure
       
   565  * @staterr: descriptor extended error and status field as written by hardware
       
   566  * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
       
   567  * @skb: pointer to sk_buff to be indicated to stack
       
   568  **/
       
   569 static void e1000_receive_skb(struct e1000_adapter *adapter,
       
   570 			      struct net_device *netdev, struct sk_buff *skb,
       
   571 			      u32 staterr, __le16 vlan)
       
   572 {
       
   573 	u16 tag = le16_to_cpu(vlan);
       
   574 
       
   575 	e1000e_rx_hwtstamp(adapter, staterr, skb);
       
   576 
       
   577 	skb->protocol = eth_type_trans(skb, netdev);
       
   578 
       
   579 	if (staterr & E1000_RXD_STAT_VP)
       
   580 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
       
   581 
       
   582 	napi_gro_receive(&adapter->napi, skb);
       
   583 }
       
   584 
       
   585 /**
       
   586  * e1000_rx_checksum - Receive Checksum Offload
       
   587  * @adapter: board private structure
       
   588  * @status_err: receive descriptor status and error fields
       
   589  * @csum: receive descriptor csum field
       
   590  * @sk_buff: socket buffer with received data
       
   591  **/
       
   592 static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
       
   593 			      struct sk_buff *skb)
       
   594 {
       
   595 	u16 status = (u16)status_err;
       
   596 	u8 errors = (u8)(status_err >> 24);
       
   597 
       
   598 	skb_checksum_none_assert(skb);
       
   599 
       
   600 	/* Rx checksum disabled */
       
   601 	if (!(adapter->netdev->features & NETIF_F_RXCSUM))
       
   602 		return;
       
   603 
       
   604 	/* Ignore Checksum bit is set */
       
   605 	if (status & E1000_RXD_STAT_IXSM)
       
   606 		return;
       
   607 
       
   608 	/* TCP/UDP checksum error bit or IP checksum error bit is set */
       
   609 	if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
       
   610 		/* let the stack verify checksum errors */
       
   611 		adapter->hw_csum_err++;
       
   612 		return;
       
   613 	}
       
   614 
       
   615 	/* TCP/UDP Checksum has not been calculated */
       
   616 	if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
       
   617 		return;
       
   618 
       
   619 	/* It must be a TCP or UDP packet with a valid checksum */
       
   620 	skb->ip_summed = CHECKSUM_UNNECESSARY;
       
   621 	adapter->hw_csum_good++;
       
   622 }
       
   623 
       
   624 static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
       
   625 {
       
   626 	struct e1000_adapter *adapter = rx_ring->adapter;
       
   627 	struct e1000_hw *hw = &adapter->hw;
       
   628 	s32 ret_val = __ew32_prepare(hw);
       
   629 
       
   630 	writel(i, rx_ring->tail);
       
   631 
       
   632 	if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
       
   633 		u32 rctl = er32(RCTL);
       
   634 
       
   635 		ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
   636 		e_err("ME firmware caused invalid RDT - resetting\n");
       
   637 		schedule_work(&adapter->reset_task);
       
   638 	}
       
   639 }
       
   640 
       
   641 static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
       
   642 {
       
   643 	struct e1000_adapter *adapter = tx_ring->adapter;
       
   644 	struct e1000_hw *hw = &adapter->hw;
       
   645 	s32 ret_val = __ew32_prepare(hw);
       
   646 
       
   647 	writel(i, tx_ring->tail);
       
   648 
       
   649 	if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
       
   650 		u32 tctl = er32(TCTL);
       
   651 
       
   652 		ew32(TCTL, tctl & ~E1000_TCTL_EN);
       
   653 		e_err("ME firmware caused invalid TDT - resetting\n");
       
   654 		schedule_work(&adapter->reset_task);
       
   655 	}
       
   656 }
       
   657 
       
   658 /**
       
   659  * e1000_alloc_rx_buffers - Replace used receive buffers
       
   660  * @rx_ring: Rx descriptor ring
       
   661  **/
       
   662 static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
       
   663 				   int cleaned_count, gfp_t gfp)
       
   664 {
       
   665 	struct e1000_adapter *adapter = rx_ring->adapter;
       
   666 	struct net_device *netdev = adapter->netdev;
       
   667 	struct pci_dev *pdev = adapter->pdev;
       
   668 	union e1000_rx_desc_extended *rx_desc;
       
   669 	struct e1000_buffer *buffer_info;
       
   670 	struct sk_buff *skb;
       
   671 	unsigned int i;
       
   672 	unsigned int bufsz = adapter->rx_buffer_len;
       
   673 
       
   674 	i = rx_ring->next_to_use;
       
   675 	buffer_info = &rx_ring->buffer_info[i];
       
   676 
       
   677 	while (cleaned_count--) {
       
   678 		skb = buffer_info->skb;
       
   679 		if (skb) {
       
   680 			skb_trim(skb, 0);
       
   681 			goto map_skb;
       
   682 		}
       
   683 
       
   684 		skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
       
   685 		if (!skb) {
       
   686 			/* Better luck next round */
       
   687 			adapter->alloc_rx_buff_failed++;
       
   688 			break;
       
   689 		}
       
   690 
       
   691 		buffer_info->skb = skb;
       
   692 map_skb:
       
   693 		buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
       
   694 						  adapter->rx_buffer_len,
       
   695 						  DMA_FROM_DEVICE);
       
   696 		if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
       
   697 			dev_err(&pdev->dev, "Rx DMA map failed\n");
       
   698 			adapter->rx_dma_failed++;
       
   699 			break;
       
   700 		}
       
   701 
       
   702 		rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
       
   703 		rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
       
   704 
       
   705 		if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
       
   706 			/* Force memory writes to complete before letting h/w
       
   707 			 * know there are new descriptors to fetch.  (Only
       
   708 			 * applicable for weak-ordered memory model archs,
       
   709 			 * such as IA-64).
       
   710 			 */
       
   711 			wmb();
       
   712 			if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
   713 				e1000e_update_rdt_wa(rx_ring, i);
       
   714 			else
       
   715 				writel(i, rx_ring->tail);
       
   716 		}
       
   717 		i++;
       
   718 		if (i == rx_ring->count)
       
   719 			i = 0;
       
   720 		buffer_info = &rx_ring->buffer_info[i];
       
   721 	}
       
   722 
       
   723 	rx_ring->next_to_use = i;
       
   724 }
       
   725 
       
   726 /**
       
   727  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
       
   728  * @rx_ring: Rx descriptor ring
       
   729  **/
       
   730 static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
       
   731 				      int cleaned_count, gfp_t gfp)
       
   732 {
       
   733 	struct e1000_adapter *adapter = rx_ring->adapter;
       
   734 	struct net_device *netdev = adapter->netdev;
       
   735 	struct pci_dev *pdev = adapter->pdev;
       
   736 	union e1000_rx_desc_packet_split *rx_desc;
       
   737 	struct e1000_buffer *buffer_info;
       
   738 	struct e1000_ps_page *ps_page;
       
   739 	struct sk_buff *skb;
       
   740 	unsigned int i, j;
       
   741 
       
   742 	i = rx_ring->next_to_use;
       
   743 	buffer_info = &rx_ring->buffer_info[i];
       
   744 
       
   745 	while (cleaned_count--) {
       
   746 		rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
       
   747 
       
   748 		for (j = 0; j < PS_PAGE_BUFFERS; j++) {
       
   749 			ps_page = &buffer_info->ps_pages[j];
       
   750 			if (j >= adapter->rx_ps_pages) {
       
   751 				/* all unused desc entries get hw null ptr */
       
   752 				rx_desc->read.buffer_addr[j + 1] =
       
   753 				    ~cpu_to_le64(0);
       
   754 				continue;
       
   755 			}
       
   756 			if (!ps_page->page) {
       
   757 				ps_page->page = alloc_page(gfp);
       
   758 				if (!ps_page->page) {
       
   759 					adapter->alloc_rx_buff_failed++;
       
   760 					goto no_buffers;
       
   761 				}
       
   762 				ps_page->dma = dma_map_page(&pdev->dev,
       
   763 							    ps_page->page,
       
   764 							    0, PAGE_SIZE,
       
   765 							    DMA_FROM_DEVICE);
       
   766 				if (dma_mapping_error(&pdev->dev,
       
   767 						      ps_page->dma)) {
       
   768 					dev_err(&adapter->pdev->dev,
       
   769 						"Rx DMA page map failed\n");
       
   770 					adapter->rx_dma_failed++;
       
   771 					goto no_buffers;
       
   772 				}
       
   773 			}
       
   774 			/* Refresh the desc even if buffer_addrs
       
   775 			 * didn't change because each write-back
       
   776 			 * erases this info.
       
   777 			 */
       
   778 			rx_desc->read.buffer_addr[j + 1] =
       
   779 			    cpu_to_le64(ps_page->dma);
       
   780 		}
       
   781 
       
   782 		skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
       
   783 						  gfp);
       
   784 
       
   785 		if (!skb) {
       
   786 			adapter->alloc_rx_buff_failed++;
       
   787 			break;
       
   788 		}
       
   789 
       
   790 		buffer_info->skb = skb;
       
   791 		buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
       
   792 						  adapter->rx_ps_bsize0,
       
   793 						  DMA_FROM_DEVICE);
       
   794 		if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
       
   795 			dev_err(&pdev->dev, "Rx DMA map failed\n");
       
   796 			adapter->rx_dma_failed++;
       
   797 			/* cleanup skb */
       
   798 			dev_kfree_skb_any(skb);
       
   799 			buffer_info->skb = NULL;
       
   800 			break;
       
   801 		}
       
   802 
       
   803 		rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
       
   804 
       
   805 		if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
       
   806 			/* Force memory writes to complete before letting h/w
       
   807 			 * know there are new descriptors to fetch.  (Only
       
   808 			 * applicable for weak-ordered memory model archs,
       
   809 			 * such as IA-64).
       
   810 			 */
       
   811 			wmb();
       
   812 			if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
   813 				e1000e_update_rdt_wa(rx_ring, i << 1);
       
   814 			else
       
   815 				writel(i << 1, rx_ring->tail);
       
   816 		}
       
   817 
       
   818 		i++;
       
   819 		if (i == rx_ring->count)
       
   820 			i = 0;
       
   821 		buffer_info = &rx_ring->buffer_info[i];
       
   822 	}
       
   823 
       
   824 no_buffers:
       
   825 	rx_ring->next_to_use = i;
       
   826 }
       
   827 
       
   828 /**
       
   829  * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
       
   830  * @rx_ring: Rx descriptor ring
       
   831  * @cleaned_count: number of buffers to allocate this pass
       
   832  **/
       
   833 
       
   834 static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
       
   835 					 int cleaned_count, gfp_t gfp)
       
   836 {
       
   837 	struct e1000_adapter *adapter = rx_ring->adapter;
       
   838 	struct net_device *netdev = adapter->netdev;
       
   839 	struct pci_dev *pdev = adapter->pdev;
       
   840 	union e1000_rx_desc_extended *rx_desc;
       
   841 	struct e1000_buffer *buffer_info;
       
   842 	struct sk_buff *skb;
       
   843 	unsigned int i;
       
   844 	unsigned int bufsz = 256 - 16;	/* for skb_reserve */
       
   845 
       
   846 	i = rx_ring->next_to_use;
       
   847 	buffer_info = &rx_ring->buffer_info[i];
       
   848 
       
   849 	while (cleaned_count--) {
       
   850 		skb = buffer_info->skb;
       
   851 		if (skb) {
       
   852 			skb_trim(skb, 0);
       
   853 			goto check_page;
       
   854 		}
       
   855 
       
   856 		skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
       
   857 		if (unlikely(!skb)) {
       
   858 			/* Better luck next round */
       
   859 			adapter->alloc_rx_buff_failed++;
       
   860 			break;
       
   861 		}
       
   862 
       
   863 		buffer_info->skb = skb;
       
   864 check_page:
       
   865 		/* allocate a new page if necessary */
       
   866 		if (!buffer_info->page) {
       
   867 			buffer_info->page = alloc_page(gfp);
       
   868 			if (unlikely(!buffer_info->page)) {
       
   869 				adapter->alloc_rx_buff_failed++;
       
   870 				break;
       
   871 			}
       
   872 		}
       
   873 
       
   874 		if (!buffer_info->dma) {
       
   875 			buffer_info->dma = dma_map_page(&pdev->dev,
       
   876 							buffer_info->page, 0,
       
   877 							PAGE_SIZE,
       
   878 							DMA_FROM_DEVICE);
       
   879 			if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
       
   880 				adapter->alloc_rx_buff_failed++;
       
   881 				break;
       
   882 			}
       
   883 		}
       
   884 
       
   885 		rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
       
   886 		rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
       
   887 
       
   888 		if (unlikely(++i == rx_ring->count))
       
   889 			i = 0;
       
   890 		buffer_info = &rx_ring->buffer_info[i];
       
   891 	}
       
   892 
       
   893 	if (likely(rx_ring->next_to_use != i)) {
       
   894 		rx_ring->next_to_use = i;
       
   895 		if (unlikely(i-- == 0))
       
   896 			i = (rx_ring->count - 1);
       
   897 
       
   898 		/* Force memory writes to complete before letting h/w
       
   899 		 * know there are new descriptors to fetch.  (Only
       
   900 		 * applicable for weak-ordered memory model archs,
       
   901 		 * such as IA-64).
       
   902 		 */
       
   903 		wmb();
       
   904 		if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
   905 			e1000e_update_rdt_wa(rx_ring, i);
       
   906 		else
       
   907 			writel(i, rx_ring->tail);
       
   908 	}
       
   909 }
       
   910 
       
   911 static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
       
   912 				 struct sk_buff *skb)
       
   913 {
       
   914 	if (netdev->features & NETIF_F_RXHASH)
       
   915 		skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
       
   916 }
       
   917 
       
   918 /**
       
   919  * e1000_clean_rx_irq - Send received data up the network stack
       
   920  * @rx_ring: Rx descriptor ring
       
   921  *
       
   922  * the return value indicates whether actual cleaning was done, there
       
   923  * is no guarantee that everything was cleaned
       
   924  **/
       
   925 static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
       
   926 			       int work_to_do)
       
   927 {
       
   928 	struct e1000_adapter *adapter = rx_ring->adapter;
       
   929 	struct net_device *netdev = adapter->netdev;
       
   930 	struct pci_dev *pdev = adapter->pdev;
       
   931 	struct e1000_hw *hw = &adapter->hw;
       
   932 	union e1000_rx_desc_extended *rx_desc, *next_rxd;
       
   933 	struct e1000_buffer *buffer_info, *next_buffer;
       
   934 	u32 length, staterr;
       
   935 	unsigned int i;
       
   936 	int cleaned_count = 0;
       
   937 	bool cleaned = false;
       
   938 	unsigned int total_rx_bytes = 0, total_rx_packets = 0;
       
   939 
       
   940 	i = rx_ring->next_to_clean;
       
   941 	rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
       
   942 	staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
       
   943 	buffer_info = &rx_ring->buffer_info[i];
       
   944 
       
   945 	while (staterr & E1000_RXD_STAT_DD) {
       
   946 		struct sk_buff *skb;
       
   947 
       
   948 		if (*work_done >= work_to_do)
       
   949 			break;
       
   950 		(*work_done)++;
       
   951 		rmb();	/* read descriptor and rx_buffer_info after status DD */
       
   952 
       
   953 		skb = buffer_info->skb;
       
   954 
       
   955 		if (!adapter->ecdev)
       
   956 			buffer_info->skb = NULL;
       
   957 
       
   958 		prefetch(skb->data - NET_IP_ALIGN);
       
   959 
       
   960 		i++;
       
   961 		if (i == rx_ring->count)
       
   962 			i = 0;
       
   963 		next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
       
   964 		prefetch(next_rxd);
       
   965 
       
   966 		next_buffer = &rx_ring->buffer_info[i];
       
   967 
       
   968 		cleaned = true;
       
   969 		cleaned_count++;
       
   970 		dma_unmap_single(&pdev->dev, buffer_info->dma,
       
   971 				 adapter->rx_buffer_len, DMA_FROM_DEVICE);
       
   972 		buffer_info->dma = 0;
       
   973 
       
   974 		length = le16_to_cpu(rx_desc->wb.upper.length);
       
   975 
       
   976 		/* !EOP means multiple descriptors were used to store a single
       
   977 		 * packet, if that's the case we need to toss it.  In fact, we
       
   978 		 * need to toss every packet with the EOP bit clear and the
       
   979 		 * next frame that _does_ have the EOP bit set, as it is by
       
   980 		 * definition only a frame fragment
       
   981 		 */
       
   982 		if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
       
   983 			adapter->flags2 |= FLAG2_IS_DISCARDING;
       
   984 
       
   985 		if (adapter->flags2 & FLAG2_IS_DISCARDING) {
       
   986 			/* All receives must fit into a single buffer */
       
   987 			e_dbg("Receive packet consumed multiple buffers\n");
       
   988 			/* recycle */
       
   989 			buffer_info->skb = skb;
       
   990 			if (staterr & E1000_RXD_STAT_EOP)
       
   991 				adapter->flags2 &= ~FLAG2_IS_DISCARDING;
       
   992 			goto next_desc;
       
   993 		}
       
   994 
       
   995 		if (unlikely(!adapter->ecdev &&
       
   996 					(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
       
   997 			     !(netdev->features & NETIF_F_RXALL))) {
       
   998 			/* recycle */
       
   999 			buffer_info->skb = skb;
       
  1000 			goto next_desc;
       
  1001 		}
       
  1002 
       
  1003 		/* adjust length to remove Ethernet CRC */
       
  1004 		if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
       
  1005 			/* If configured to store CRC, don't subtract FCS,
       
  1006 			 * but keep the FCS bytes out of the total_rx_bytes
       
  1007 			 * counter
       
  1008 			 */
       
  1009 			if (netdev->features & NETIF_F_RXFCS)
       
  1010 				total_rx_bytes -= 4;
       
  1011 			else
       
  1012 				length -= 4;
       
  1013 		}
       
  1014 
       
  1015 		total_rx_bytes += length;
       
  1016 		total_rx_packets++;
       
  1017 
       
  1018 		/* code added for copybreak, this should improve
       
  1019 		 * performance for small packets with large amounts
       
  1020 		 * of reassembly being done in the stack
       
  1021 		 */
       
  1022 		if (!adapter->ecdev && length < copybreak) {
       
  1023 			struct sk_buff *new_skb =
       
  1024 			    netdev_alloc_skb_ip_align(netdev, length);
       
  1025 			if (new_skb) {
       
  1026 				skb_copy_to_linear_data_offset(new_skb,
       
  1027 							       -NET_IP_ALIGN,
       
  1028 							       (skb->data -
       
  1029 								NET_IP_ALIGN),
       
  1030 							       (length +
       
  1031 								NET_IP_ALIGN));
       
  1032 				/* save the skb in buffer_info as good */
       
  1033 				buffer_info->skb = skb;
       
  1034 				skb = new_skb;
       
  1035 			}
       
  1036 			/* else just continue with the old one */
       
  1037 		}
       
  1038 		/* end copybreak code */
       
  1039 		skb_put(skb, length);
       
  1040 
       
  1041 		/* Receive Checksum Offload */
       
  1042 		e1000_rx_checksum(adapter, staterr, skb);
       
  1043 
       
  1044 		e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
       
  1045 
       
  1046 		if (adapter->ecdev) {
       
  1047 			ecdev_receive(adapter->ecdev, skb->data, length);
       
  1048 			adapter->ec_watchdog_jiffies = jiffies;
       
  1049 		} else {
       
  1050 		    e1000_receive_skb(adapter, netdev, skb, staterr,
       
  1051 				      rx_desc->wb.upper.vlan);
       
  1052 		}
       
  1053 
       
  1054 next_desc:
       
  1055 		rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
       
  1056 
       
  1057 		/* return some buffers to hardware, one at a time is too slow */
       
  1058 		if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
       
  1059 			adapter->alloc_rx_buf(rx_ring, cleaned_count,
       
  1060 					      GFP_ATOMIC);
       
  1061 			cleaned_count = 0;
       
  1062 		}
       
  1063 
       
  1064 		/* use prefetched values */
       
  1065 		rx_desc = next_rxd;
       
  1066 		buffer_info = next_buffer;
       
  1067 
       
  1068 		staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
       
  1069 	}
       
  1070 	rx_ring->next_to_clean = i;
       
  1071 
       
  1072 	cleaned_count = e1000_desc_unused(rx_ring);
       
  1073 	if (cleaned_count)
       
  1074 		adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
       
  1075 
       
  1076 	adapter->total_rx_bytes += total_rx_bytes;
       
  1077 	adapter->total_rx_packets += total_rx_packets;
       
  1078 	return cleaned;
       
  1079 }
       
  1080 
       
  1081 static void e1000_put_txbuf(struct e1000_ring *tx_ring,
       
  1082 			    struct e1000_buffer *buffer_info)
       
  1083 {
       
  1084 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  1085 
       
  1086 	if (adapter->ecdev) {
       
  1087 		return;
       
  1088 	}
       
  1089 
       
  1090 	if (buffer_info->dma) {
       
  1091 		if (buffer_info->mapped_as_page)
       
  1092 			dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
       
  1093 				       buffer_info->length, DMA_TO_DEVICE);
       
  1094 		else
       
  1095 			dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
       
  1096 					 buffer_info->length, DMA_TO_DEVICE);
       
  1097 		buffer_info->dma = 0;
       
  1098 	}
       
  1099 	if (buffer_info->skb) {
       
  1100 		dev_kfree_skb_any(buffer_info->skb);
       
  1101 		buffer_info->skb = NULL;
       
  1102 	}
       
  1103 	buffer_info->time_stamp = 0;
       
  1104 }
       
  1105 
       
  1106 static void e1000_print_hw_hang(struct work_struct *work)
       
  1107 {
       
  1108 	struct e1000_adapter *adapter = container_of(work,
       
  1109 						     struct e1000_adapter,
       
  1110 						     print_hang_task);
       
  1111 	struct net_device *netdev = adapter->netdev;
       
  1112 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  1113 	unsigned int i = tx_ring->next_to_clean;
       
  1114 	unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
       
  1115 	struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
       
  1116 	struct e1000_hw *hw = &adapter->hw;
       
  1117 	u16 phy_status, phy_1000t_status, phy_ext_status;
       
  1118 	u16 pci_status;
       
  1119 
       
  1120 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  1121 		return;
       
  1122 
       
  1123 	if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
       
  1124 		/* May be block on write-back, flush and detect again
       
  1125 		 * flush pending descriptor writebacks to memory
       
  1126 		 */
       
  1127 		ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
       
  1128 		/* execute the writes immediately */
       
  1129 		e1e_flush();
       
  1130 		/* Due to rare timing issues, write to TIDV again to ensure
       
  1131 		 * the write is successful
       
  1132 		 */
       
  1133 		ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
       
  1134 		/* execute the writes immediately */
       
  1135 		e1e_flush();
       
  1136 		adapter->tx_hang_recheck = true;
       
  1137 		return;
       
  1138 	}
       
  1139 	adapter->tx_hang_recheck = false;
       
  1140 
       
  1141 	if (er32(TDH(0)) == er32(TDT(0))) {
       
  1142 		e_dbg("false hang detected, ignoring\n");
       
  1143 		return;
       
  1144 	}
       
  1145 
       
  1146 	/* Real hang detected */
       
  1147 	if (adapter->ecdev) {
       
  1148 		ecdev_set_link(adapter->ecdev, 0);
       
  1149 	}
       
  1150 	else {
       
  1151 		netif_stop_queue(netdev);
       
  1152 	}
       
  1153 
       
  1154 	e1e_rphy(hw, MII_BMSR, &phy_status);
       
  1155 	e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
       
  1156 	e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
       
  1157 
       
  1158 	pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
       
  1159 
       
  1160 	/* detected Hardware unit hang */
       
  1161 	e_err("Detected Hardware Unit Hang:\n"
       
  1162 	      "  TDH                  <%x>\n"
       
  1163 	      "  TDT                  <%x>\n"
       
  1164 	      "  next_to_use          <%x>\n"
       
  1165 	      "  next_to_clean        <%x>\n"
       
  1166 	      "buffer_info[next_to_clean]:\n"
       
  1167 	      "  time_stamp           <%lx>\n"
       
  1168 	      "  next_to_watch        <%x>\n"
       
  1169 	      "  jiffies              <%lx>\n"
       
  1170 	      "  next_to_watch.status <%x>\n"
       
  1171 	      "MAC Status             <%x>\n"
       
  1172 	      "PHY Status             <%x>\n"
       
  1173 	      "PHY 1000BASE-T Status  <%x>\n"
       
  1174 	      "PHY Extended Status    <%x>\n"
       
  1175 	      "PCI Status             <%x>\n",
       
  1176 	      readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
       
  1177 	      tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
       
  1178 	      eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
       
  1179 	      phy_status, phy_1000t_status, phy_ext_status, pci_status);
       
  1180 
       
  1181 	e1000e_dump(adapter);
       
  1182 
       
  1183 	/* Suggest workaround for known h/w issue */
       
  1184 	if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
       
  1185 		e_err("Try turning off Tx pause (flow control) via ethtool\n");
       
  1186 }
       
  1187 
       
  1188 /**
       
  1189  * e1000e_tx_hwtstamp_work - check for Tx time stamp
       
  1190  * @work: pointer to work struct
       
  1191  *
       
  1192  * This work function polls the TSYNCTXCTL valid bit to determine when a
       
  1193  * timestamp has been taken for the current stored skb.  The timestamp must
       
  1194  * be for this skb because only one such packet is allowed in the queue.
       
  1195  */
       
  1196 static void e1000e_tx_hwtstamp_work(struct work_struct *work)
       
  1197 {
       
  1198 	struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
       
  1199 						     tx_hwtstamp_work);
       
  1200 	struct e1000_hw *hw = &adapter->hw;
       
  1201 
       
  1202 	if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
       
  1203 		struct skb_shared_hwtstamps shhwtstamps;
       
  1204 		u64 txstmp;
       
  1205 
       
  1206 		txstmp = er32(TXSTMPL);
       
  1207 		txstmp |= (u64)er32(TXSTMPH) << 32;
       
  1208 
       
  1209 		e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
       
  1210 
       
  1211 		skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps);
       
  1212 		dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
       
  1213 		adapter->tx_hwtstamp_skb = NULL;
       
  1214 	} else if (time_after(jiffies, adapter->tx_hwtstamp_start
       
  1215 			      + adapter->tx_timeout_factor * HZ)) {
       
  1216 		dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
       
  1217 		adapter->tx_hwtstamp_skb = NULL;
       
  1218 		adapter->tx_hwtstamp_timeouts++;
       
  1219 		e_warn("clearing Tx timestamp hang\n");
       
  1220 	} else {
       
  1221 		/* reschedule to check later */
       
  1222 		schedule_work(&adapter->tx_hwtstamp_work);
       
  1223 	}
       
  1224 }
       
  1225 
       
  1226 /**
       
  1227  * e1000_clean_tx_irq - Reclaim resources after transmit completes
       
  1228  * @tx_ring: Tx descriptor ring
       
  1229  *
       
  1230  * the return value indicates whether actual cleaning was done, there
       
  1231  * is no guarantee that everything was cleaned
       
  1232  **/
       
  1233 static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
       
  1234 {
       
  1235 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  1236 	struct net_device *netdev = adapter->netdev;
       
  1237 	struct e1000_hw *hw = &adapter->hw;
       
  1238 	struct e1000_tx_desc *tx_desc, *eop_desc;
       
  1239 	struct e1000_buffer *buffer_info;
       
  1240 	unsigned int i, eop;
       
  1241 	unsigned int count = 0;
       
  1242 	unsigned int total_tx_bytes = 0, total_tx_packets = 0;
       
  1243 	unsigned int bytes_compl = 0, pkts_compl = 0;
       
  1244 
       
  1245 	i = tx_ring->next_to_clean;
       
  1246 	eop = tx_ring->buffer_info[i].next_to_watch;
       
  1247 	eop_desc = E1000_TX_DESC(*tx_ring, eop);
       
  1248 
       
  1249 	while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
       
  1250 	       (count < tx_ring->count)) {
       
  1251 		bool cleaned = false;
       
  1252 
       
  1253 		rmb();		/* read buffer_info after eop_desc */
       
  1254 		for (; !cleaned; count++) {
       
  1255 			tx_desc = E1000_TX_DESC(*tx_ring, i);
       
  1256 			buffer_info = &tx_ring->buffer_info[i];
       
  1257 			cleaned = (i == eop);
       
  1258 
       
  1259 			if (cleaned) {
       
  1260 				total_tx_packets += buffer_info->segs;
       
  1261 				total_tx_bytes += buffer_info->bytecount;
       
  1262 				if (buffer_info->skb) {
       
  1263 					bytes_compl += buffer_info->skb->len;
       
  1264 					pkts_compl++;
       
  1265 				}
       
  1266 			}
       
  1267 
       
  1268 			e1000_put_txbuf(tx_ring, buffer_info);
       
  1269 			tx_desc->upper.data = 0;
       
  1270 
       
  1271 			i++;
       
  1272 			if (i == tx_ring->count)
       
  1273 				i = 0;
       
  1274 		}
       
  1275 
       
  1276 		if (i == tx_ring->next_to_use)
       
  1277 			break;
       
  1278 		eop = tx_ring->buffer_info[i].next_to_watch;
       
  1279 		eop_desc = E1000_TX_DESC(*tx_ring, eop);
       
  1280 	}
       
  1281 
       
  1282 	tx_ring->next_to_clean = i;
       
  1283 
       
  1284 	if (!adapter->ecdev) {
       
  1285 		netdev_completed_queue(netdev, pkts_compl, bytes_compl);
       
  1286 	}
       
  1287 
       
  1288 #define TX_WAKE_THRESHOLD 32
       
  1289 	if (!adapter->ecdev && count && netif_carrier_ok(netdev) &&
       
  1290 	    e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
       
  1291 		/* Make sure that anybody stopping the queue after this
       
  1292 		 * sees the new next_to_clean.
       
  1293 		 */
       
  1294 		smp_mb();
       
  1295 
       
  1296 		if (netif_queue_stopped(netdev) &&
       
  1297 		    !(test_bit(__E1000_DOWN, &adapter->state))) {
       
  1298 			netif_wake_queue(netdev);
       
  1299 			++adapter->restart_queue;
       
  1300 		}
       
  1301 	}
       
  1302 
       
  1303 	if (!adapter->ecdev && adapter->detect_tx_hung) {
       
  1304 		/* Detect a transmit hang in hardware, this serializes the
       
  1305 		 * check with the clearing of time_stamp and movement of i
       
  1306 		 */
       
  1307 		adapter->detect_tx_hung = false;
       
  1308 		if (tx_ring->buffer_info[i].time_stamp &&
       
  1309 		    time_after(jiffies, tx_ring->buffer_info[i].time_stamp
       
  1310 			       + (adapter->tx_timeout_factor * HZ)) &&
       
  1311 		    !(er32(STATUS) & E1000_STATUS_TXOFF))
       
  1312 			schedule_work(&adapter->print_hang_task);
       
  1313 		else
       
  1314 			adapter->tx_hang_recheck = false;
       
  1315 	}
       
  1316 	adapter->total_tx_bytes += total_tx_bytes;
       
  1317 	adapter->total_tx_packets += total_tx_packets;
       
  1318 	return count < tx_ring->count;
       
  1319 }
       
  1320 
       
  1321 /**
       
  1322  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
       
  1323  * @rx_ring: Rx descriptor ring
       
  1324  *
       
  1325  * the return value indicates whether actual cleaning was done, there
       
  1326  * is no guarantee that everything was cleaned
       
  1327  **/
       
  1328 static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
       
  1329 				  int work_to_do)
       
  1330 {
       
  1331 	struct e1000_adapter *adapter = rx_ring->adapter;
       
  1332 	struct e1000_hw *hw = &adapter->hw;
       
  1333 	union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
       
  1334 	struct net_device *netdev = adapter->netdev;
       
  1335 	struct pci_dev *pdev = adapter->pdev;
       
  1336 	struct e1000_buffer *buffer_info, *next_buffer;
       
  1337 	struct e1000_ps_page *ps_page;
       
  1338 	struct sk_buff *skb;
       
  1339 	unsigned int i, j;
       
  1340 	u32 length, staterr;
       
  1341 	int cleaned_count = 0;
       
  1342 	bool cleaned = false;
       
  1343 	unsigned int total_rx_bytes = 0, total_rx_packets = 0;
       
  1344 
       
  1345 	i = rx_ring->next_to_clean;
       
  1346 	rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
       
  1347 	staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
       
  1348 	buffer_info = &rx_ring->buffer_info[i];
       
  1349 
       
  1350 	while (staterr & E1000_RXD_STAT_DD) {
       
  1351 		if (*work_done >= work_to_do)
       
  1352 			break;
       
  1353 		(*work_done)++;
       
  1354 		skb = buffer_info->skb;
       
  1355 		rmb();	/* read descriptor and rx_buffer_info after status DD */
       
  1356 
       
  1357 		/* in the packet split case this is header only */
       
  1358 		prefetch(skb->data - NET_IP_ALIGN);
       
  1359 
       
  1360 		i++;
       
  1361 		if (i == rx_ring->count)
       
  1362 			i = 0;
       
  1363 		next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
       
  1364 		prefetch(next_rxd);
       
  1365 
       
  1366 		next_buffer = &rx_ring->buffer_info[i];
       
  1367 
       
  1368 		cleaned = true;
       
  1369 		cleaned_count++;
       
  1370 		dma_unmap_single(&pdev->dev, buffer_info->dma,
       
  1371 				 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
       
  1372 		buffer_info->dma = 0;
       
  1373 
       
  1374 		/* see !EOP comment in other Rx routine */
       
  1375 		if (!(staterr & E1000_RXD_STAT_EOP))
       
  1376 			adapter->flags2 |= FLAG2_IS_DISCARDING;
       
  1377 
       
  1378 		if (adapter->flags2 & FLAG2_IS_DISCARDING) {
       
  1379 			e_dbg("Packet Split buffers didn't pick up the full packet\n");
       
  1380 			if (!adapter->ecdev) {
       
  1381 				dev_kfree_skb_irq(skb);
       
  1382 			}
       
  1383 			if (staterr & E1000_RXD_STAT_EOP)
       
  1384 				adapter->flags2 &= ~FLAG2_IS_DISCARDING;
       
  1385 			goto next_desc;
       
  1386 		}
       
  1387 
       
  1388 		if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
       
  1389 			     !(netdev->features & NETIF_F_RXALL))) {
       
  1390 			if (!adapter->ecdev) {
       
  1391 				dev_kfree_skb_irq(skb);
       
  1392 			}
       
  1393 			goto next_desc;
       
  1394 		}
       
  1395 
       
  1396 		length = le16_to_cpu(rx_desc->wb.middle.length0);
       
  1397 
       
  1398 		if (!length) {
       
  1399 			e_dbg("Last part of the packet spanning multiple descriptors\n");
       
  1400 			if (!adapter->ecdev) {
       
  1401 				dev_kfree_skb_irq(skb);
       
  1402 			}
       
  1403 			goto next_desc;
       
  1404 		}
       
  1405 
       
  1406 		/* Good Receive */
       
  1407 		skb_put(skb, length);
       
  1408 
       
  1409 		{
       
  1410 			/* this looks ugly, but it seems compiler issues make
       
  1411 			 * it more efficient than reusing j
       
  1412 			 */
       
  1413 			int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
       
  1414 
       
  1415 			/* page alloc/put takes too long and effects small
       
  1416 			 * packet throughput, so unsplit small packets and
       
  1417 			 * save the alloc/put only valid in softirq (napi)
       
  1418 			 * context to call kmap_*
       
  1419 			 */
       
  1420 			if (l1 && (l1 <= copybreak) &&
       
  1421 			    ((length + l1) <= adapter->rx_ps_bsize0)) {
       
  1422 				u8 *vaddr;
       
  1423 
       
  1424 				ps_page = &buffer_info->ps_pages[0];
       
  1425 
       
  1426 				/* there is no documentation about how to call
       
  1427 				 * kmap_atomic, so we can't hold the mapping
       
  1428 				 * very long
       
  1429 				 */
       
  1430 				dma_sync_single_for_cpu(&pdev->dev,
       
  1431 							ps_page->dma,
       
  1432 							PAGE_SIZE,
       
  1433 							DMA_FROM_DEVICE);
       
  1434 				vaddr = kmap_atomic(ps_page->page);
       
  1435 				memcpy(skb_tail_pointer(skb), vaddr, l1);
       
  1436 				kunmap_atomic(vaddr);
       
  1437 				dma_sync_single_for_device(&pdev->dev,
       
  1438 							   ps_page->dma,
       
  1439 							   PAGE_SIZE,
       
  1440 							   DMA_FROM_DEVICE);
       
  1441 
       
  1442 				/* remove the CRC */
       
  1443 				if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
       
  1444 					if (!(netdev->features & NETIF_F_RXFCS))
       
  1445 						l1 -= 4;
       
  1446 				}
       
  1447 
       
  1448 				skb_put(skb, l1);
       
  1449 				goto copydone;
       
  1450 			}	/* if */
       
  1451 		}
       
  1452 
       
  1453 		for (j = 0; j < PS_PAGE_BUFFERS; j++) {
       
  1454 			length = le16_to_cpu(rx_desc->wb.upper.length[j]);
       
  1455 			if (!length)
       
  1456 				break;
       
  1457 
       
  1458 			ps_page = &buffer_info->ps_pages[j];
       
  1459 			dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
       
  1460 				       DMA_FROM_DEVICE);
       
  1461 			ps_page->dma = 0;
       
  1462 			skb_fill_page_desc(skb, j, ps_page->page, 0, length);
       
  1463 			ps_page->page = NULL;
       
  1464 			skb->len += length;
       
  1465 			skb->data_len += length;
       
  1466 			skb->truesize += PAGE_SIZE;
       
  1467 		}
       
  1468 
       
  1469 		/* strip the ethernet crc, problem is we're using pages now so
       
  1470 		 * this whole operation can get a little cpu intensive
       
  1471 		 */
       
  1472 		if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
       
  1473 			if (!(netdev->features & NETIF_F_RXFCS))
       
  1474 				pskb_trim(skb, skb->len - 4);
       
  1475 		}
       
  1476 
       
  1477 copydone:
       
  1478 		total_rx_bytes += skb->len;
       
  1479 		total_rx_packets++;
       
  1480 
       
  1481 		e1000_rx_checksum(adapter, staterr, skb);
       
  1482 
       
  1483 		e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
       
  1484 
       
  1485 		if (rx_desc->wb.upper.header_status &
       
  1486 		    cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
       
  1487 			adapter->rx_hdr_split++;
       
  1488 
       
  1489 		if (adapter->ecdev) {
       
  1490 			ecdev_receive(adapter->ecdev, skb->data, length);
       
  1491 			adapter->ec_watchdog_jiffies = jiffies;
       
  1492 		} else {
       
  1493 			e1000_receive_skb(adapter, netdev, skb, staterr,
       
  1494 					rx_desc->wb.middle.vlan);
       
  1495 		}
       
  1496 
       
  1497 next_desc:
       
  1498 		rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
       
  1499 		if (!adapter->ecdev) buffer_info->skb = NULL;
       
  1500 
       
  1501 		/* return some buffers to hardware, one at a time is too slow */
       
  1502 		if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
       
  1503 			adapter->alloc_rx_buf(rx_ring, cleaned_count,
       
  1504 					      GFP_ATOMIC);
       
  1505 			cleaned_count = 0;
       
  1506 		}
       
  1507 
       
  1508 		/* use prefetched values */
       
  1509 		rx_desc = next_rxd;
       
  1510 		buffer_info = next_buffer;
       
  1511 
       
  1512 		staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
       
  1513 	}
       
  1514 	rx_ring->next_to_clean = i;
       
  1515 
       
  1516 	cleaned_count = e1000_desc_unused(rx_ring);
       
  1517 	if (cleaned_count)
       
  1518 		adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
       
  1519 
       
  1520 	adapter->total_rx_bytes += total_rx_bytes;
       
  1521 	adapter->total_rx_packets += total_rx_packets;
       
  1522 	return cleaned;
       
  1523 }
       
  1524 
       
  1525 /**
       
  1526  * e1000_consume_page - helper function
       
  1527  **/
       
  1528 static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
       
  1529 			       u16 length)
       
  1530 {
       
  1531 	bi->page = NULL;
       
  1532 	skb->len += length;
       
  1533 	skb->data_len += length;
       
  1534 	skb->truesize += PAGE_SIZE;
       
  1535 }
       
  1536 
       
  1537 /**
       
  1538  * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
       
  1539  * @adapter: board private structure
       
  1540  *
       
  1541  * the return value indicates whether actual cleaning was done, there
       
  1542  * is no guarantee that everything was cleaned
       
  1543  **/
       
  1544 static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
       
  1545 				     int work_to_do)
       
  1546 {
       
  1547 	struct e1000_adapter *adapter = rx_ring->adapter;
       
  1548 	struct net_device *netdev = adapter->netdev;
       
  1549 	struct pci_dev *pdev = adapter->pdev;
       
  1550 	union e1000_rx_desc_extended *rx_desc, *next_rxd;
       
  1551 	struct e1000_buffer *buffer_info, *next_buffer;
       
  1552 	u32 length, staterr;
       
  1553 	unsigned int i;
       
  1554 	int cleaned_count = 0;
       
  1555 	bool cleaned = false;
       
  1556 	unsigned int total_rx_bytes = 0, total_rx_packets = 0;
       
  1557 	struct skb_shared_info *shinfo;
       
  1558 
       
  1559 	i = rx_ring->next_to_clean;
       
  1560 	rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
       
  1561 	staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
       
  1562 	buffer_info = &rx_ring->buffer_info[i];
       
  1563 
       
  1564 	while (staterr & E1000_RXD_STAT_DD) {
       
  1565 		struct sk_buff *skb;
       
  1566 
       
  1567 		if (*work_done >= work_to_do)
       
  1568 			break;
       
  1569 		(*work_done)++;
       
  1570 		rmb();	/* read descriptor and rx_buffer_info after status DD */
       
  1571 
       
  1572 		skb = buffer_info->skb;
       
  1573 
       
  1574 		if (!adapter->ecdev)
       
  1575 			buffer_info->skb = NULL;
       
  1576 
       
  1577 		++i;
       
  1578 		if (i == rx_ring->count)
       
  1579 			i = 0;
       
  1580 		next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
       
  1581 		prefetch(next_rxd);
       
  1582 
       
  1583 		next_buffer = &rx_ring->buffer_info[i];
       
  1584 
       
  1585 		cleaned = true;
       
  1586 		cleaned_count++;
       
  1587 		dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
       
  1588 			       DMA_FROM_DEVICE);
       
  1589 		buffer_info->dma = 0;
       
  1590 
       
  1591 		length = le16_to_cpu(rx_desc->wb.upper.length);
       
  1592 
       
  1593 		/* errors is only valid for DD + EOP descriptors */
       
  1594 		if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
       
  1595 			     ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
       
  1596 			      !(netdev->features & NETIF_F_RXALL)))) {
       
  1597 			/* recycle both page and skb */
       
  1598 			buffer_info->skb = skb;
       
  1599 			/* an error means any chain goes out the window too */
       
  1600 			if (!adapter->ecdev && rx_ring->rx_skb_top) {
       
  1601 				dev_kfree_skb_irq(rx_ring->rx_skb_top);
       
  1602 			}
       
  1603 			rx_ring->rx_skb_top = NULL;
       
  1604 			goto next_desc;
       
  1605 		}
       
  1606 #define rxtop (rx_ring->rx_skb_top)
       
  1607 		if (!(staterr & E1000_RXD_STAT_EOP)) {
       
  1608 			/* this descriptor is only the beginning (or middle) */
       
  1609 			if (!rxtop) {
       
  1610 				/* this is the beginning of a chain */
       
  1611 				rxtop = skb;
       
  1612 				skb_fill_page_desc(rxtop, 0, buffer_info->page,
       
  1613 						   0, length);
       
  1614 			} else {
       
  1615 				/* this is the middle of a chain */
       
  1616 				shinfo = skb_shinfo(rxtop);
       
  1617 				skb_fill_page_desc(rxtop, shinfo->nr_frags,
       
  1618 						   buffer_info->page, 0,
       
  1619 						   length);
       
  1620 				/* re-use the skb, only consumed the page */
       
  1621 				buffer_info->skb = skb;
       
  1622 			}
       
  1623 			e1000_consume_page(buffer_info, rxtop, length);
       
  1624 			goto next_desc;
       
  1625 		} else {
       
  1626 			if (rxtop) {
       
  1627 				/* end of the chain */
       
  1628 				shinfo = skb_shinfo(rxtop);
       
  1629 				skb_fill_page_desc(rxtop, shinfo->nr_frags,
       
  1630 						   buffer_info->page, 0,
       
  1631 						   length);
       
  1632 				/* re-use the current skb, we only consumed the
       
  1633 				 * page
       
  1634 				 */
       
  1635 				buffer_info->skb = skb;
       
  1636 				skb = rxtop;
       
  1637 				rxtop = NULL;
       
  1638 				e1000_consume_page(buffer_info, skb, length);
       
  1639 			} else {
       
  1640 				/* no chain, got EOP, this buf is the packet
       
  1641 				 * copybreak to save the put_page/alloc_page
       
  1642 				 */
       
  1643 				if (length <= copybreak &&
       
  1644 				    skb_tailroom(skb) >= length) {
       
  1645 					u8 *vaddr;
       
  1646 					vaddr = kmap_atomic(buffer_info->page);
       
  1647 					memcpy(skb_tail_pointer(skb), vaddr,
       
  1648 					       length);
       
  1649 					kunmap_atomic(vaddr);
       
  1650 					/* re-use the page, so don't erase
       
  1651 					 * buffer_info->page
       
  1652 					 */
       
  1653 					skb_put(skb, length);
       
  1654 				} else {
       
  1655 					skb_fill_page_desc(skb, 0,
       
  1656 							   buffer_info->page, 0,
       
  1657 							   length);
       
  1658 					e1000_consume_page(buffer_info, skb,
       
  1659 							   length);
       
  1660 				}
       
  1661 			}
       
  1662 		}
       
  1663 
       
  1664 		/* Receive Checksum Offload */
       
  1665 		e1000_rx_checksum(adapter, staterr, skb);
       
  1666 
       
  1667 		e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
       
  1668 
       
  1669 		/* probably a little skewed due to removing CRC */
       
  1670 		total_rx_bytes += skb->len;
       
  1671 		total_rx_packets++;
       
  1672 
       
  1673 		/* eth type trans needs skb->data to point to something */
       
  1674 		if (!adapter->ecdev && !pskb_may_pull(skb, ETH_HLEN)) {
       
  1675 			e_err("pskb_may_pull failed.\n");
       
  1676 			dev_kfree_skb_irq(skb);
       
  1677 			goto next_desc;
       
  1678 		}
       
  1679 
       
  1680 		if (adapter->ecdev) {
       
  1681 			ecdev_receive(adapter->ecdev, skb->data, length);
       
  1682 			adapter->ec_watchdog_jiffies = jiffies;
       
  1683 		} else {
       
  1684 			e1000_receive_skb(adapter, netdev, skb, staterr,
       
  1685 					  rx_desc->wb.upper.vlan);
       
  1686 		}
       
  1687 
       
  1688 
       
  1689 next_desc:
       
  1690 		rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
       
  1691 
       
  1692 		/* return some buffers to hardware, one at a time is too slow */
       
  1693 		if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
       
  1694 			adapter->alloc_rx_buf(rx_ring, cleaned_count,
       
  1695 					      GFP_ATOMIC);
       
  1696 			cleaned_count = 0;
       
  1697 		}
       
  1698 
       
  1699 		/* use prefetched values */
       
  1700 		rx_desc = next_rxd;
       
  1701 		buffer_info = next_buffer;
       
  1702 
       
  1703 		staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
       
  1704 	}
       
  1705 	rx_ring->next_to_clean = i;
       
  1706 
       
  1707 	cleaned_count = e1000_desc_unused(rx_ring);
       
  1708 	if (cleaned_count)
       
  1709 		adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
       
  1710 
       
  1711 	adapter->total_rx_bytes += total_rx_bytes;
       
  1712 	adapter->total_rx_packets += total_rx_packets;
       
  1713 	return cleaned;
       
  1714 }
       
  1715 
       
  1716 /**
       
  1717  * e1000_clean_rx_ring - Free Rx Buffers per Queue
       
  1718  * @rx_ring: Rx descriptor ring
       
  1719  **/
       
  1720 static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
       
  1721 {
       
  1722 	struct e1000_adapter *adapter = rx_ring->adapter;
       
  1723 	struct e1000_buffer *buffer_info;
       
  1724 	struct e1000_ps_page *ps_page;
       
  1725 	struct pci_dev *pdev = adapter->pdev;
       
  1726 	unsigned int i, j;
       
  1727 
       
  1728 	/* Free all the Rx ring sk_buffs */
       
  1729 	for (i = 0; i < rx_ring->count; i++) {
       
  1730 		buffer_info = &rx_ring->buffer_info[i];
       
  1731 		if (buffer_info->dma) {
       
  1732 			if (adapter->clean_rx == e1000_clean_rx_irq)
       
  1733 				dma_unmap_single(&pdev->dev, buffer_info->dma,
       
  1734 						 adapter->rx_buffer_len,
       
  1735 						 DMA_FROM_DEVICE);
       
  1736 			else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
       
  1737 				dma_unmap_page(&pdev->dev, buffer_info->dma,
       
  1738 					       PAGE_SIZE, DMA_FROM_DEVICE);
       
  1739 			else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
       
  1740 				dma_unmap_single(&pdev->dev, buffer_info->dma,
       
  1741 						 adapter->rx_ps_bsize0,
       
  1742 						 DMA_FROM_DEVICE);
       
  1743 			buffer_info->dma = 0;
       
  1744 		}
       
  1745 
       
  1746 		if (buffer_info->page) {
       
  1747 			put_page(buffer_info->page);
       
  1748 			buffer_info->page = NULL;
       
  1749 		}
       
  1750 
       
  1751 		if (buffer_info->skb) {
       
  1752 			dev_kfree_skb(buffer_info->skb);
       
  1753 			buffer_info->skb = NULL;
       
  1754 		}
       
  1755 
       
  1756 		for (j = 0; j < PS_PAGE_BUFFERS; j++) {
       
  1757 			ps_page = &buffer_info->ps_pages[j];
       
  1758 			if (!ps_page->page)
       
  1759 				break;
       
  1760 			dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
       
  1761 				       DMA_FROM_DEVICE);
       
  1762 			ps_page->dma = 0;
       
  1763 			put_page(ps_page->page);
       
  1764 			ps_page->page = NULL;
       
  1765 		}
       
  1766 	}
       
  1767 
       
  1768 	/* there also may be some cached data from a chained receive */
       
  1769 	if (rx_ring->rx_skb_top) {
       
  1770 		dev_kfree_skb(rx_ring->rx_skb_top);
       
  1771 		rx_ring->rx_skb_top = NULL;
       
  1772 	}
       
  1773 
       
  1774 	/* Zero out the descriptor ring */
       
  1775 	memset(rx_ring->desc, 0, rx_ring->size);
       
  1776 
       
  1777 	rx_ring->next_to_clean = 0;
       
  1778 	rx_ring->next_to_use = 0;
       
  1779 	adapter->flags2 &= ~FLAG2_IS_DISCARDING;
       
  1780 
       
  1781 	writel(0, rx_ring->head);
       
  1782 	if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
  1783 		e1000e_update_rdt_wa(rx_ring, 0);
       
  1784 	else
       
  1785 		writel(0, rx_ring->tail);
       
  1786 }
       
  1787 
       
  1788 static void e1000e_downshift_workaround(struct work_struct *work)
       
  1789 {
       
  1790 	struct e1000_adapter *adapter = container_of(work,
       
  1791 						     struct e1000_adapter,
       
  1792 						     downshift_task);
       
  1793 
       
  1794 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  1795 		return;
       
  1796 
       
  1797 	e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
       
  1798 }
       
  1799 
       
  1800 /**
       
  1801  * e1000_intr_msi - Interrupt Handler
       
  1802  * @irq: interrupt number
       
  1803  * @data: pointer to a network interface device structure
       
  1804  **/
       
  1805 static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
       
  1806 {
       
  1807 	struct net_device *netdev = data;
       
  1808 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1809 	struct e1000_hw *hw = &adapter->hw;
       
  1810 	u32 icr = er32(ICR);
       
  1811 
       
  1812 	if (adapter->ecdev) {
       
  1813 		int ec_work_done = 0;
       
  1814 		adapter->clean_rx(adapter->rx_ring, &ec_work_done, 100);
       
  1815 		e1000_clean_tx_irq(adapter->tx_ring);
       
  1816 		return IRQ_HANDLED;
       
  1817 	}
       
  1818 
       
  1819 	/* read ICR disables interrupts using IAM */
       
  1820 	if (icr & E1000_ICR_LSC) {
       
  1821 		hw->mac.get_link_status = true;
       
  1822 		/* ICH8 workaround-- Call gig speed drop workaround on cable
       
  1823 		 * disconnect (LSC) before accessing any PHY registers
       
  1824 		 */
       
  1825 		if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
       
  1826 		    (!(er32(STATUS) & E1000_STATUS_LU)))
       
  1827 			schedule_work(&adapter->downshift_task);
       
  1828 
       
  1829 		/* 80003ES2LAN workaround-- For packet buffer work-around on
       
  1830 		 * link down event; disable receives here in the ISR and reset
       
  1831 		 * adapter in watchdog
       
  1832 		 */
       
  1833 		if (netif_carrier_ok(netdev) &&
       
  1834 		    adapter->flags & FLAG_RX_NEEDS_RESTART) {
       
  1835 			/* disable receives */
       
  1836 			u32 rctl = er32(RCTL);
       
  1837 
       
  1838 			ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
  1839 			adapter->flags |= FLAG_RESTART_NOW;
       
  1840 		}
       
  1841 		/* guard against interrupt when we're going down */
       
  1842 		if (!test_bit(__E1000_DOWN, &adapter->state))
       
  1843 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
       
  1844 	}
       
  1845 
       
  1846 	/* Reset on uncorrectable ECC error */
       
  1847 	if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
       
  1848 		u32 pbeccsts = er32(PBECCSTS);
       
  1849 
       
  1850 		adapter->corr_errors +=
       
  1851 		    pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
       
  1852 		adapter->uncorr_errors +=
       
  1853 		    (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
       
  1854 		    E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
       
  1855 
       
  1856 		/* Do the reset outside of interrupt context */
       
  1857 		schedule_work(&adapter->reset_task);
       
  1858 
       
  1859 		/* return immediately since reset is imminent */
       
  1860 		return IRQ_HANDLED;
       
  1861 	}
       
  1862 
       
  1863 	if (napi_schedule_prep(&adapter->napi)) {
       
  1864 		adapter->total_tx_bytes = 0;
       
  1865 		adapter->total_tx_packets = 0;
       
  1866 		adapter->total_rx_bytes = 0;
       
  1867 		adapter->total_rx_packets = 0;
       
  1868 		__napi_schedule(&adapter->napi);
       
  1869 	}
       
  1870 
       
  1871 	return IRQ_HANDLED;
       
  1872 }
       
  1873 
       
  1874 /**
       
  1875  * e1000_intr - Interrupt Handler
       
  1876  * @irq: interrupt number
       
  1877  * @data: pointer to a network interface device structure
       
  1878  **/
       
  1879 static irqreturn_t e1000_intr(int __always_unused irq, void *data)
       
  1880 {
       
  1881 	struct net_device *netdev = data;
       
  1882 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1883 	struct e1000_hw *hw = &adapter->hw;
       
  1884 	u32 rctl, icr = er32(ICR);
       
  1885 
       
  1886 	if (adapter->ecdev) {
       
  1887 		int ec_work_done = 0;
       
  1888 		adapter->clean_rx(adapter->rx_ring, &ec_work_done, 100);
       
  1889 		e1000_clean_tx_irq(adapter->tx_ring);
       
  1890 		return IRQ_HANDLED;
       
  1891 	}
       
  1892 
       
  1893 	if (!icr || test_bit(__E1000_DOWN, &adapter->state))
       
  1894 		return IRQ_NONE;	/* Not our interrupt */
       
  1895 
       
  1896 	/* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
       
  1897 	 * not set, then the adapter didn't send an interrupt
       
  1898 	 */
       
  1899 	if (!(icr & E1000_ICR_INT_ASSERTED))
       
  1900 		return IRQ_NONE;
       
  1901 
       
  1902 	/* Interrupt Auto-Mask...upon reading ICR,
       
  1903 	 * interrupts are masked.  No need for the
       
  1904 	 * IMC write
       
  1905 	 */
       
  1906 
       
  1907 	if (icr & E1000_ICR_LSC) {
       
  1908 		hw->mac.get_link_status = true;
       
  1909 		/* ICH8 workaround-- Call gig speed drop workaround on cable
       
  1910 		 * disconnect (LSC) before accessing any PHY registers
       
  1911 		 */
       
  1912 		if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
       
  1913 		    (!(er32(STATUS) & E1000_STATUS_LU)))
       
  1914 			schedule_work(&adapter->downshift_task);
       
  1915 
       
  1916 		/* 80003ES2LAN workaround--
       
  1917 		 * For packet buffer work-around on link down event;
       
  1918 		 * disable receives here in the ISR and
       
  1919 		 * reset adapter in watchdog
       
  1920 		 */
       
  1921 		if (netif_carrier_ok(netdev) &&
       
  1922 		    (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
       
  1923 			/* disable receives */
       
  1924 			rctl = er32(RCTL);
       
  1925 			ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
  1926 			adapter->flags |= FLAG_RESTART_NOW;
       
  1927 		}
       
  1928 		/* guard against interrupt when we're going down */
       
  1929 		if (!test_bit(__E1000_DOWN, &adapter->state))
       
  1930 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
       
  1931 	}
       
  1932 
       
  1933 	/* Reset on uncorrectable ECC error */
       
  1934 	if ((icr & E1000_ICR_ECCER) && (hw->mac.type == e1000_pch_lpt)) {
       
  1935 		u32 pbeccsts = er32(PBECCSTS);
       
  1936 
       
  1937 		adapter->corr_errors +=
       
  1938 		    pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
       
  1939 		adapter->uncorr_errors +=
       
  1940 		    (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
       
  1941 		    E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
       
  1942 
       
  1943 		/* Do the reset outside of interrupt context */
       
  1944 		schedule_work(&adapter->reset_task);
       
  1945 
       
  1946 		/* return immediately since reset is imminent */
       
  1947 		return IRQ_HANDLED;
       
  1948 	}
       
  1949 
       
  1950 	if (napi_schedule_prep(&adapter->napi)) {
       
  1951 		adapter->total_tx_bytes = 0;
       
  1952 		adapter->total_tx_packets = 0;
       
  1953 		adapter->total_rx_bytes = 0;
       
  1954 		adapter->total_rx_packets = 0;
       
  1955 		__napi_schedule(&adapter->napi);
       
  1956 	}
       
  1957 
       
  1958 	return IRQ_HANDLED;
       
  1959 }
       
  1960 
       
  1961 static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
       
  1962 {
       
  1963 	struct net_device *netdev = data;
       
  1964 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1965 	struct e1000_hw *hw = &adapter->hw;
       
  1966 	u32 icr = er32(ICR);
       
  1967 
       
  1968 	if (!(icr & E1000_ICR_INT_ASSERTED)) {
       
  1969 		if (!test_bit(__E1000_DOWN, &adapter->state))
       
  1970 			ew32(IMS, E1000_IMS_OTHER);
       
  1971 		return IRQ_NONE;
       
  1972 	}
       
  1973 
       
  1974 	if (icr & adapter->eiac_mask)
       
  1975 		ew32(ICS, (icr & adapter->eiac_mask));
       
  1976 
       
  1977 	if (icr & E1000_ICR_OTHER) {
       
  1978 		if (!(icr & E1000_ICR_LSC))
       
  1979 			goto no_link_interrupt;
       
  1980 		hw->mac.get_link_status = true;
       
  1981 		/* guard against interrupt when we're going down */
       
  1982 		if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state))
       
  1983 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
       
  1984 	}
       
  1985 
       
  1986 no_link_interrupt:
       
  1987 	if (!test_bit(__E1000_DOWN, &adapter->state))
       
  1988 		ew32(IMS, E1000_IMS_LSC | E1000_IMS_OTHER);
       
  1989 
       
  1990 	return IRQ_HANDLED;
       
  1991 }
       
  1992 
       
  1993 static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
       
  1994 {
       
  1995 	struct net_device *netdev = data;
       
  1996 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1997 	struct e1000_hw *hw = &adapter->hw;
       
  1998 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  1999 
       
  2000 	adapter->total_tx_bytes = 0;
       
  2001 	adapter->total_tx_packets = 0;
       
  2002 
       
  2003 	if (!e1000_clean_tx_irq(tx_ring))
       
  2004 		/* Ring was not completely cleaned, so fire another interrupt */
       
  2005 		ew32(ICS, tx_ring->ims_val);
       
  2006 
       
  2007 	return IRQ_HANDLED;
       
  2008 }
       
  2009 
       
  2010 static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
       
  2011 {
       
  2012 	struct net_device *netdev = data;
       
  2013 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  2014 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
  2015 
       
  2016 	/* Write the ITR value calculated at the end of the
       
  2017 	 * previous interrupt.
       
  2018 	 */
       
  2019 	if (rx_ring->set_itr) {
       
  2020 		writel(1000000000 / (rx_ring->itr_val * 256),
       
  2021 		       rx_ring->itr_register);
       
  2022 		rx_ring->set_itr = 0;
       
  2023 	}
       
  2024 
       
  2025 	if (adapter->ecdev) {
       
  2026 		int ec_work_done = 0;
       
  2027 		adapter->clean_rx(adapter->rx_ring, &ec_work_done, 100);
       
  2028 	} else {
       
  2029 		if (napi_schedule_prep(&adapter->napi)) {
       
  2030 			adapter->total_rx_bytes = 0;
       
  2031 			adapter->total_rx_packets = 0;
       
  2032 			__napi_schedule(&adapter->napi);
       
  2033 		}
       
  2034 	}
       
  2035 	return IRQ_HANDLED;
       
  2036 }
       
  2037 
       
  2038 /**
       
  2039  * e1000_configure_msix - Configure MSI-X hardware
       
  2040  *
       
  2041  * e1000_configure_msix sets up the hardware to properly
       
  2042  * generate MSI-X interrupts.
       
  2043  **/
       
  2044 static void e1000_configure_msix(struct e1000_adapter *adapter)
       
  2045 {
       
  2046 	struct e1000_hw *hw = &adapter->hw;
       
  2047 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
  2048 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  2049 	int vector = 0;
       
  2050 	u32 ctrl_ext, ivar = 0;
       
  2051 
       
  2052 	adapter->eiac_mask = 0;
       
  2053 
       
  2054 	/* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
       
  2055 	if (hw->mac.type == e1000_82574) {
       
  2056 		u32 rfctl = er32(RFCTL);
       
  2057 
       
  2058 		rfctl |= E1000_RFCTL_ACK_DIS;
       
  2059 		ew32(RFCTL, rfctl);
       
  2060 	}
       
  2061 
       
  2062 	/* Configure Rx vector */
       
  2063 	rx_ring->ims_val = E1000_IMS_RXQ0;
       
  2064 	adapter->eiac_mask |= rx_ring->ims_val;
       
  2065 	if (rx_ring->itr_val)
       
  2066 		writel(1000000000 / (rx_ring->itr_val * 256),
       
  2067 		       rx_ring->itr_register);
       
  2068 	else
       
  2069 		writel(1, rx_ring->itr_register);
       
  2070 	ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
       
  2071 
       
  2072 	/* Configure Tx vector */
       
  2073 	tx_ring->ims_val = E1000_IMS_TXQ0;
       
  2074 	vector++;
       
  2075 	if (tx_ring->itr_val)
       
  2076 		writel(1000000000 / (tx_ring->itr_val * 256),
       
  2077 		       tx_ring->itr_register);
       
  2078 	else
       
  2079 		writel(1, tx_ring->itr_register);
       
  2080 	adapter->eiac_mask |= tx_ring->ims_val;
       
  2081 	ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
       
  2082 
       
  2083 	/* set vector for Other Causes, e.g. link changes */
       
  2084 	vector++;
       
  2085 	ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
       
  2086 	if (rx_ring->itr_val)
       
  2087 		writel(1000000000 / (rx_ring->itr_val * 256),
       
  2088 		       hw->hw_addr + E1000_EITR_82574(vector));
       
  2089 	else
       
  2090 		writel(1, hw->hw_addr + E1000_EITR_82574(vector));
       
  2091 
       
  2092 	/* Cause Tx interrupts on every write back */
       
  2093 	ivar |= (1 << 31);
       
  2094 
       
  2095 	ew32(IVAR, ivar);
       
  2096 
       
  2097 	/* enable MSI-X PBA support */
       
  2098 	ctrl_ext = er32(CTRL_EXT);
       
  2099 	ctrl_ext |= E1000_CTRL_EXT_PBA_CLR;
       
  2100 
       
  2101 	/* Auto-Mask Other interrupts upon ICR read */
       
  2102 	ew32(IAM, ~E1000_EIAC_MASK_82574 | E1000_IMS_OTHER);
       
  2103 	ctrl_ext |= E1000_CTRL_EXT_EIAME;
       
  2104 	ew32(CTRL_EXT, ctrl_ext);
       
  2105 	e1e_flush();
       
  2106 }
       
  2107 
       
  2108 void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
       
  2109 {
       
  2110 	if (adapter->msix_entries) {
       
  2111 		pci_disable_msix(adapter->pdev);
       
  2112 		kfree(adapter->msix_entries);
       
  2113 		adapter->msix_entries = NULL;
       
  2114 	} else if (adapter->flags & FLAG_MSI_ENABLED) {
       
  2115 		pci_disable_msi(adapter->pdev);
       
  2116 		adapter->flags &= ~FLAG_MSI_ENABLED;
       
  2117 	}
       
  2118 }
       
  2119 
       
  2120 /**
       
  2121  * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
       
  2122  *
       
  2123  * Attempt to configure interrupts using the best available
       
  2124  * capabilities of the hardware and kernel.
       
  2125  **/
       
  2126 void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
       
  2127 {
       
  2128 	int err;
       
  2129 	int i;
       
  2130 
       
  2131 	switch (adapter->int_mode) {
       
  2132 	case E1000E_INT_MODE_MSIX:
       
  2133 		if (adapter->flags & FLAG_HAS_MSIX) {
       
  2134 			adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
       
  2135 			adapter->msix_entries = kcalloc(adapter->num_vectors,
       
  2136 							sizeof(struct
       
  2137 							       msix_entry),
       
  2138 							GFP_KERNEL);
       
  2139 			if (adapter->msix_entries) {
       
  2140 				struct e1000_adapter *a = adapter;
       
  2141 
       
  2142 				for (i = 0; i < adapter->num_vectors; i++)
       
  2143 					adapter->msix_entries[i].entry = i;
       
  2144 
       
  2145 				err = pci_enable_msix_range(a->pdev,
       
  2146 							    a->msix_entries,
       
  2147 							    a->num_vectors,
       
  2148 							    a->num_vectors);
       
  2149 				if (err > 0)
       
  2150 					return;
       
  2151 			}
       
  2152 			/* MSI-X failed, so fall through and try MSI */
       
  2153 			e_err("Failed to initialize MSI-X interrupts.  Falling back to MSI interrupts.\n");
       
  2154 			e1000e_reset_interrupt_capability(adapter);
       
  2155 		}
       
  2156 		adapter->int_mode = E1000E_INT_MODE_MSI;
       
  2157 		/* Fall through */
       
  2158 	case E1000E_INT_MODE_MSI:
       
  2159 		if (!pci_enable_msi(adapter->pdev)) {
       
  2160 			adapter->flags |= FLAG_MSI_ENABLED;
       
  2161 		} else {
       
  2162 			adapter->int_mode = E1000E_INT_MODE_LEGACY;
       
  2163 			e_err("Failed to initialize MSI interrupts.  Falling back to legacy interrupts.\n");
       
  2164 		}
       
  2165 		/* Fall through */
       
  2166 	case E1000E_INT_MODE_LEGACY:
       
  2167 		/* Don't do anything; this is the system default */
       
  2168 		break;
       
  2169 	}
       
  2170 
       
  2171 	/* store the number of vectors being used */
       
  2172 	adapter->num_vectors = 1;
       
  2173 }
       
  2174 
       
  2175 /**
       
  2176  * e1000_request_msix - Initialize MSI-X interrupts
       
  2177  *
       
  2178  * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
       
  2179  * kernel.
       
  2180  **/
       
  2181 static int e1000_request_msix(struct e1000_adapter *adapter)
       
  2182 {
       
  2183 	struct net_device *netdev = adapter->netdev;
       
  2184 	int err = 0, vector = 0;
       
  2185 
       
  2186 	if (strlen(netdev->name) < (IFNAMSIZ - 5))
       
  2187 		snprintf(adapter->rx_ring->name,
       
  2188 			 sizeof(adapter->rx_ring->name) - 1,
       
  2189 			 "%s-rx-0", netdev->name);
       
  2190 	else
       
  2191 		memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
       
  2192 	err = request_irq(adapter->msix_entries[vector].vector,
       
  2193 			  e1000_intr_msix_rx, 0, adapter->rx_ring->name,
       
  2194 			  netdev);
       
  2195 	if (err)
       
  2196 		return err;
       
  2197 	adapter->rx_ring->itr_register = adapter->hw.hw_addr +
       
  2198 	    E1000_EITR_82574(vector);
       
  2199 	adapter->rx_ring->itr_val = adapter->itr;
       
  2200 	vector++;
       
  2201 
       
  2202 	if (strlen(netdev->name) < (IFNAMSIZ - 5))
       
  2203 		snprintf(adapter->tx_ring->name,
       
  2204 			 sizeof(adapter->tx_ring->name) - 1,
       
  2205 			 "%s-tx-0", netdev->name);
       
  2206 	else
       
  2207 		memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
       
  2208 	err = request_irq(adapter->msix_entries[vector].vector,
       
  2209 			  e1000_intr_msix_tx, 0, adapter->tx_ring->name,
       
  2210 			  netdev);
       
  2211 	if (err)
       
  2212 		return err;
       
  2213 	adapter->tx_ring->itr_register = adapter->hw.hw_addr +
       
  2214 	    E1000_EITR_82574(vector);
       
  2215 	adapter->tx_ring->itr_val = adapter->itr;
       
  2216 	vector++;
       
  2217 
       
  2218 	err = request_irq(adapter->msix_entries[vector].vector,
       
  2219 			  e1000_msix_other, 0, netdev->name, netdev);
       
  2220 	if (err)
       
  2221 		return err;
       
  2222 
       
  2223 	e1000_configure_msix(adapter);
       
  2224 
       
  2225 	return 0;
       
  2226 }
       
  2227 
       
  2228 /**
       
  2229  * e1000_request_irq - initialize interrupts
       
  2230  *
       
  2231  * Attempts to configure interrupts using the best available
       
  2232  * capabilities of the hardware and kernel.
       
  2233  **/
       
  2234 static int e1000_request_irq(struct e1000_adapter *adapter)
       
  2235 {
       
  2236 	struct net_device *netdev = adapter->netdev;
       
  2237 	int err;
       
  2238 
       
  2239 	if (adapter->ecdev)
       
  2240 		return 0;
       
  2241 
       
  2242 	if (adapter->msix_entries) {
       
  2243 		err = e1000_request_msix(adapter);
       
  2244 		if (!err)
       
  2245 			return err;
       
  2246 		/* fall back to MSI */
       
  2247 		e1000e_reset_interrupt_capability(adapter);
       
  2248 		adapter->int_mode = E1000E_INT_MODE_MSI;
       
  2249 		e1000e_set_interrupt_capability(adapter);
       
  2250 	}
       
  2251 	if (adapter->flags & FLAG_MSI_ENABLED) {
       
  2252 		err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
       
  2253 				  netdev->name, netdev);
       
  2254 		if (!err)
       
  2255 			return err;
       
  2256 
       
  2257 		/* fall back to legacy interrupt */
       
  2258 		e1000e_reset_interrupt_capability(adapter);
       
  2259 		adapter->int_mode = E1000E_INT_MODE_LEGACY;
       
  2260 	}
       
  2261 
       
  2262 	err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
       
  2263 			  netdev->name, netdev);
       
  2264 	if (err)
       
  2265 		e_err("Unable to allocate interrupt, Error: %d\n", err);
       
  2266 
       
  2267 	return err;
       
  2268 }
       
  2269 
       
  2270 static void e1000_free_irq(struct e1000_adapter *adapter)
       
  2271 {
       
  2272 	struct net_device *netdev = adapter->netdev;
       
  2273 
       
  2274 	if (adapter->ecdev) {
       
  2275 		return;
       
  2276 	}
       
  2277 
       
  2278 	if (adapter->msix_entries) {
       
  2279 		int vector = 0;
       
  2280 
       
  2281 		free_irq(adapter->msix_entries[vector].vector, netdev);
       
  2282 		vector++;
       
  2283 
       
  2284 		free_irq(adapter->msix_entries[vector].vector, netdev);
       
  2285 		vector++;
       
  2286 
       
  2287 		/* Other Causes interrupt vector */
       
  2288 		free_irq(adapter->msix_entries[vector].vector, netdev);
       
  2289 		return;
       
  2290 	}
       
  2291 
       
  2292 	free_irq(adapter->pdev->irq, netdev);
       
  2293 }
       
  2294 
       
  2295 /**
       
  2296  * e1000_irq_disable - Mask off interrupt generation on the NIC
       
  2297  **/
       
  2298 static void e1000_irq_disable(struct e1000_adapter *adapter)
       
  2299 {
       
  2300 	struct e1000_hw *hw = &adapter->hw;
       
  2301 
       
  2302 	ew32(IMC, ~0);
       
  2303 	if (adapter->msix_entries)
       
  2304 		ew32(EIAC_82574, 0);
       
  2305 	e1e_flush();
       
  2306 
       
  2307 	if (adapter->ecdev) {
       
  2308 		return;
       
  2309 	}
       
  2310 
       
  2311 	if (adapter->msix_entries) {
       
  2312 		int i;
       
  2313 
       
  2314 		for (i = 0; i < adapter->num_vectors; i++)
       
  2315 			synchronize_irq(adapter->msix_entries[i].vector);
       
  2316 	} else {
       
  2317 		synchronize_irq(adapter->pdev->irq);
       
  2318 	}
       
  2319 }
       
  2320 
       
  2321 /**
       
  2322  * e1000_irq_enable - Enable default interrupt generation settings
       
  2323  **/
       
  2324 static void e1000_irq_enable(struct e1000_adapter *adapter)
       
  2325 {
       
  2326 	struct e1000_hw *hw = &adapter->hw;
       
  2327 
       
  2328 	if (adapter->ecdev)
       
  2329 		return;
       
  2330 
       
  2331 	if (adapter->msix_entries) {
       
  2332 		ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
       
  2333 		ew32(IMS, adapter->eiac_mask | E1000_IMS_OTHER | E1000_IMS_LSC);
       
  2334 	} else if (hw->mac.type == e1000_pch_lpt) {
       
  2335 		ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
       
  2336 	} else {
       
  2337 		ew32(IMS, IMS_ENABLE_MASK);
       
  2338 	}
       
  2339 	e1e_flush();
       
  2340 }
       
  2341 
       
  2342 /**
       
  2343  * e1000e_get_hw_control - get control of the h/w from f/w
       
  2344  * @adapter: address of board private structure
       
  2345  *
       
  2346  * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
       
  2347  * For ASF and Pass Through versions of f/w this means that
       
  2348  * the driver is loaded. For AMT version (only with 82573)
       
  2349  * of the f/w this means that the network i/f is open.
       
  2350  **/
       
  2351 void e1000e_get_hw_control(struct e1000_adapter *adapter)
       
  2352 {
       
  2353 	struct e1000_hw *hw = &adapter->hw;
       
  2354 	u32 ctrl_ext;
       
  2355 	u32 swsm;
       
  2356 
       
  2357 	/* Let firmware know the driver has taken over */
       
  2358 	if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
       
  2359 		swsm = er32(SWSM);
       
  2360 		ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
       
  2361 	} else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
       
  2362 		ctrl_ext = er32(CTRL_EXT);
       
  2363 		ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
       
  2364 	}
       
  2365 }
       
  2366 
       
  2367 /**
       
  2368  * e1000e_release_hw_control - release control of the h/w to f/w
       
  2369  * @adapter: address of board private structure
       
  2370  *
       
  2371  * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
       
  2372  * For ASF and Pass Through versions of f/w this means that the
       
  2373  * driver is no longer loaded. For AMT version (only with 82573) i
       
  2374  * of the f/w this means that the network i/f is closed.
       
  2375  *
       
  2376  **/
       
  2377 void e1000e_release_hw_control(struct e1000_adapter *adapter)
       
  2378 {
       
  2379 	struct e1000_hw *hw = &adapter->hw;
       
  2380 	u32 ctrl_ext;
       
  2381 	u32 swsm;
       
  2382 
       
  2383 	/* Let firmware taken over control of h/w */
       
  2384 	if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
       
  2385 		swsm = er32(SWSM);
       
  2386 		ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
       
  2387 	} else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
       
  2388 		ctrl_ext = er32(CTRL_EXT);
       
  2389 		ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
       
  2390 	}
       
  2391 }
       
  2392 
       
  2393 /**
       
  2394  * e1000_alloc_ring_dma - allocate memory for a ring structure
       
  2395  **/
       
  2396 static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
       
  2397 				struct e1000_ring *ring)
       
  2398 {
       
  2399 	struct pci_dev *pdev = adapter->pdev;
       
  2400 
       
  2401 	ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
       
  2402 					GFP_KERNEL);
       
  2403 	if (!ring->desc)
       
  2404 		return -ENOMEM;
       
  2405 
       
  2406 	return 0;
       
  2407 }
       
  2408 
       
  2409 /**
       
  2410  * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
       
  2411  * @tx_ring: Tx descriptor ring
       
  2412  *
       
  2413  * Return 0 on success, negative on failure
       
  2414  **/
       
  2415 int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
       
  2416 {
       
  2417 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  2418 	int err = -ENOMEM, size;
       
  2419 
       
  2420 	size = sizeof(struct e1000_buffer) * tx_ring->count;
       
  2421 	tx_ring->buffer_info = vzalloc(size);
       
  2422 	if (!tx_ring->buffer_info)
       
  2423 		goto err;
       
  2424 
       
  2425 	/* round up to nearest 4K */
       
  2426 	tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
       
  2427 	tx_ring->size = ALIGN(tx_ring->size, 4096);
       
  2428 
       
  2429 	err = e1000_alloc_ring_dma(adapter, tx_ring);
       
  2430 	if (err)
       
  2431 		goto err;
       
  2432 
       
  2433 	tx_ring->next_to_use = 0;
       
  2434 	tx_ring->next_to_clean = 0;
       
  2435 
       
  2436 	return 0;
       
  2437 err:
       
  2438 	vfree(tx_ring->buffer_info);
       
  2439 	e_err("Unable to allocate memory for the transmit descriptor ring\n");
       
  2440 	return err;
       
  2441 }
       
  2442 
       
  2443 /**
       
  2444  * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
       
  2445  * @rx_ring: Rx descriptor ring
       
  2446  *
       
  2447  * Returns 0 on success, negative on failure
       
  2448  **/
       
  2449 int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
       
  2450 {
       
  2451 	struct e1000_adapter *adapter = rx_ring->adapter;
       
  2452 	struct e1000_buffer *buffer_info;
       
  2453 	int i, size, desc_len, err = -ENOMEM;
       
  2454 
       
  2455 	size = sizeof(struct e1000_buffer) * rx_ring->count;
       
  2456 	rx_ring->buffer_info = vzalloc(size);
       
  2457 	if (!rx_ring->buffer_info)
       
  2458 		goto err;
       
  2459 
       
  2460 	for (i = 0; i < rx_ring->count; i++) {
       
  2461 		buffer_info = &rx_ring->buffer_info[i];
       
  2462 		buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
       
  2463 						sizeof(struct e1000_ps_page),
       
  2464 						GFP_KERNEL);
       
  2465 		if (!buffer_info->ps_pages)
       
  2466 			goto err_pages;
       
  2467 	}
       
  2468 
       
  2469 	desc_len = sizeof(union e1000_rx_desc_packet_split);
       
  2470 
       
  2471 	/* Round up to nearest 4K */
       
  2472 	rx_ring->size = rx_ring->count * desc_len;
       
  2473 	rx_ring->size = ALIGN(rx_ring->size, 4096);
       
  2474 
       
  2475 	err = e1000_alloc_ring_dma(adapter, rx_ring);
       
  2476 	if (err)
       
  2477 		goto err_pages;
       
  2478 
       
  2479 	rx_ring->next_to_clean = 0;
       
  2480 	rx_ring->next_to_use = 0;
       
  2481 	rx_ring->rx_skb_top = NULL;
       
  2482 
       
  2483 	return 0;
       
  2484 
       
  2485 err_pages:
       
  2486 	for (i = 0; i < rx_ring->count; i++) {
       
  2487 		buffer_info = &rx_ring->buffer_info[i];
       
  2488 		kfree(buffer_info->ps_pages);
       
  2489 	}
       
  2490 err:
       
  2491 	vfree(rx_ring->buffer_info);
       
  2492 	e_err("Unable to allocate memory for the receive descriptor ring\n");
       
  2493 	return err;
       
  2494 }
       
  2495 
       
  2496 /**
       
  2497  * e1000_clean_tx_ring - Free Tx Buffers
       
  2498  * @tx_ring: Tx descriptor ring
       
  2499  **/
       
  2500 static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
       
  2501 {
       
  2502 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  2503 	struct e1000_buffer *buffer_info;
       
  2504 	unsigned long size;
       
  2505 	unsigned int i;
       
  2506 
       
  2507 	for (i = 0; i < tx_ring->count; i++) {
       
  2508 		buffer_info = &tx_ring->buffer_info[i];
       
  2509 		e1000_put_txbuf(tx_ring, buffer_info);
       
  2510 	}
       
  2511 
       
  2512 	netdev_reset_queue(adapter->netdev);
       
  2513 	size = sizeof(struct e1000_buffer) * tx_ring->count;
       
  2514 	memset(tx_ring->buffer_info, 0, size);
       
  2515 
       
  2516 	memset(tx_ring->desc, 0, tx_ring->size);
       
  2517 
       
  2518 	tx_ring->next_to_use = 0;
       
  2519 	tx_ring->next_to_clean = 0;
       
  2520 
       
  2521 	writel(0, tx_ring->head);
       
  2522 	if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
  2523 		e1000e_update_tdt_wa(tx_ring, 0);
       
  2524 	else
       
  2525 		writel(0, tx_ring->tail);
       
  2526 }
       
  2527 
       
  2528 /**
       
  2529  * e1000e_free_tx_resources - Free Tx Resources per Queue
       
  2530  * @tx_ring: Tx descriptor ring
       
  2531  *
       
  2532  * Free all transmit software resources
       
  2533  **/
       
  2534 void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
       
  2535 {
       
  2536 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  2537 	struct pci_dev *pdev = adapter->pdev;
       
  2538 
       
  2539 	e1000_clean_tx_ring(tx_ring);
       
  2540 
       
  2541 	vfree(tx_ring->buffer_info);
       
  2542 	tx_ring->buffer_info = NULL;
       
  2543 
       
  2544 	dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
       
  2545 			  tx_ring->dma);
       
  2546 	tx_ring->desc = NULL;
       
  2547 }
       
  2548 
       
  2549 /**
       
  2550  * e1000e_free_rx_resources - Free Rx Resources
       
  2551  * @rx_ring: Rx descriptor ring
       
  2552  *
       
  2553  * Free all receive software resources
       
  2554  **/
       
  2555 void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
       
  2556 {
       
  2557 	struct e1000_adapter *adapter = rx_ring->adapter;
       
  2558 	struct pci_dev *pdev = adapter->pdev;
       
  2559 	int i;
       
  2560 
       
  2561 	e1000_clean_rx_ring(rx_ring);
       
  2562 
       
  2563 	for (i = 0; i < rx_ring->count; i++)
       
  2564 		kfree(rx_ring->buffer_info[i].ps_pages);
       
  2565 
       
  2566 	vfree(rx_ring->buffer_info);
       
  2567 	rx_ring->buffer_info = NULL;
       
  2568 
       
  2569 	dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
       
  2570 			  rx_ring->dma);
       
  2571 	rx_ring->desc = NULL;
       
  2572 }
       
  2573 
       
  2574 /**
       
  2575  * e1000_update_itr - update the dynamic ITR value based on statistics
       
  2576  * @adapter: pointer to adapter
       
  2577  * @itr_setting: current adapter->itr
       
  2578  * @packets: the number of packets during this measurement interval
       
  2579  * @bytes: the number of bytes during this measurement interval
       
  2580  *
       
  2581  *      Stores a new ITR value based on packets and byte
       
  2582  *      counts during the last interrupt.  The advantage of per interrupt
       
  2583  *      computation is faster updates and more accurate ITR for the current
       
  2584  *      traffic pattern.  Constants in this function were computed
       
  2585  *      based on theoretical maximum wire speed and thresholds were set based
       
  2586  *      on testing data as well as attempting to minimize response time
       
  2587  *      while increasing bulk throughput.  This functionality is controlled
       
  2588  *      by the InterruptThrottleRate module parameter.
       
  2589  **/
       
  2590 static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
       
  2591 {
       
  2592 	unsigned int retval = itr_setting;
       
  2593 
       
  2594 	if (packets == 0)
       
  2595 		return itr_setting;
       
  2596 
       
  2597 	switch (itr_setting) {
       
  2598 	case lowest_latency:
       
  2599 		/* handle TSO and jumbo frames */
       
  2600 		if (bytes / packets > 8000)
       
  2601 			retval = bulk_latency;
       
  2602 		else if ((packets < 5) && (bytes > 512))
       
  2603 			retval = low_latency;
       
  2604 		break;
       
  2605 	case low_latency:	/* 50 usec aka 20000 ints/s */
       
  2606 		if (bytes > 10000) {
       
  2607 			/* this if handles the TSO accounting */
       
  2608 			if (bytes / packets > 8000)
       
  2609 				retval = bulk_latency;
       
  2610 			else if ((packets < 10) || ((bytes / packets) > 1200))
       
  2611 				retval = bulk_latency;
       
  2612 			else if ((packets > 35))
       
  2613 				retval = lowest_latency;
       
  2614 		} else if (bytes / packets > 2000) {
       
  2615 			retval = bulk_latency;
       
  2616 		} else if (packets <= 2 && bytes < 512) {
       
  2617 			retval = lowest_latency;
       
  2618 		}
       
  2619 		break;
       
  2620 	case bulk_latency:	/* 250 usec aka 4000 ints/s */
       
  2621 		if (bytes > 25000) {
       
  2622 			if (packets > 35)
       
  2623 				retval = low_latency;
       
  2624 		} else if (bytes < 6000) {
       
  2625 			retval = low_latency;
       
  2626 		}
       
  2627 		break;
       
  2628 	}
       
  2629 
       
  2630 	return retval;
       
  2631 }
       
  2632 
       
  2633 static void e1000_set_itr(struct e1000_adapter *adapter)
       
  2634 {
       
  2635 	u16 current_itr;
       
  2636 	u32 new_itr = adapter->itr;
       
  2637 
       
  2638 	/* for non-gigabit speeds, just fix the interrupt rate at 4000 */
       
  2639 	if (adapter->link_speed != SPEED_1000) {
       
  2640 		current_itr = 0;
       
  2641 		new_itr = 4000;
       
  2642 		goto set_itr_now;
       
  2643 	}
       
  2644 
       
  2645 	if (adapter->flags2 & FLAG2_DISABLE_AIM) {
       
  2646 		new_itr = 0;
       
  2647 		goto set_itr_now;
       
  2648 	}
       
  2649 
       
  2650 	adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
       
  2651 					   adapter->total_tx_packets,
       
  2652 					   adapter->total_tx_bytes);
       
  2653 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
       
  2654 	if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
       
  2655 		adapter->tx_itr = low_latency;
       
  2656 
       
  2657 	adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
       
  2658 					   adapter->total_rx_packets,
       
  2659 					   adapter->total_rx_bytes);
       
  2660 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
       
  2661 	if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
       
  2662 		adapter->rx_itr = low_latency;
       
  2663 
       
  2664 	current_itr = max(adapter->rx_itr, adapter->tx_itr);
       
  2665 
       
  2666 	/* counts and packets in update_itr are dependent on these numbers */
       
  2667 	switch (current_itr) {
       
  2668 	case lowest_latency:
       
  2669 		new_itr = 70000;
       
  2670 		break;
       
  2671 	case low_latency:
       
  2672 		new_itr = 20000;	/* aka hwitr = ~200 */
       
  2673 		break;
       
  2674 	case bulk_latency:
       
  2675 		new_itr = 4000;
       
  2676 		break;
       
  2677 	default:
       
  2678 		break;
       
  2679 	}
       
  2680 
       
  2681 set_itr_now:
       
  2682 	if (new_itr != adapter->itr) {
       
  2683 		/* this attempts to bias the interrupt rate towards Bulk
       
  2684 		 * by adding intermediate steps when interrupt rate is
       
  2685 		 * increasing
       
  2686 		 */
       
  2687 		new_itr = new_itr > adapter->itr ?
       
  2688 		    min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
       
  2689 		adapter->itr = new_itr;
       
  2690 		adapter->rx_ring->itr_val = new_itr;
       
  2691 		if (adapter->msix_entries)
       
  2692 			adapter->rx_ring->set_itr = 1;
       
  2693 		else
       
  2694 			e1000e_write_itr(adapter, new_itr);
       
  2695 	}
       
  2696 }
       
  2697 
       
  2698 /**
       
  2699  * e1000e_write_itr - write the ITR value to the appropriate registers
       
  2700  * @adapter: address of board private structure
       
  2701  * @itr: new ITR value to program
       
  2702  *
       
  2703  * e1000e_write_itr determines if the adapter is in MSI-X mode
       
  2704  * and, if so, writes the EITR registers with the ITR value.
       
  2705  * Otherwise, it writes the ITR value into the ITR register.
       
  2706  **/
       
  2707 void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
       
  2708 {
       
  2709 	struct e1000_hw *hw = &adapter->hw;
       
  2710 	u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
       
  2711 
       
  2712 	if (adapter->msix_entries) {
       
  2713 		int vector;
       
  2714 
       
  2715 		for (vector = 0; vector < adapter->num_vectors; vector++)
       
  2716 			writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
       
  2717 	} else {
       
  2718 		ew32(ITR, new_itr);
       
  2719 	}
       
  2720 }
       
  2721 
       
  2722 /**
       
  2723  * e1000_alloc_queues - Allocate memory for all rings
       
  2724  * @adapter: board private structure to initialize
       
  2725  **/
       
  2726 static int e1000_alloc_queues(struct e1000_adapter *adapter)
       
  2727 {
       
  2728 	int size = sizeof(struct e1000_ring);
       
  2729 
       
  2730 	adapter->tx_ring = kzalloc(size, GFP_KERNEL);
       
  2731 	if (!adapter->tx_ring)
       
  2732 		goto err;
       
  2733 	adapter->tx_ring->count = adapter->tx_ring_count;
       
  2734 	adapter->tx_ring->adapter = adapter;
       
  2735 
       
  2736 	adapter->rx_ring = kzalloc(size, GFP_KERNEL);
       
  2737 	if (!adapter->rx_ring)
       
  2738 		goto err;
       
  2739 	adapter->rx_ring->count = adapter->rx_ring_count;
       
  2740 	adapter->rx_ring->adapter = adapter;
       
  2741 
       
  2742 	return 0;
       
  2743 err:
       
  2744 	e_err("Unable to allocate memory for queues\n");
       
  2745 	kfree(adapter->rx_ring);
       
  2746 	kfree(adapter->tx_ring);
       
  2747 	return -ENOMEM;
       
  2748 }
       
  2749 
       
  2750 /**
       
  2751  * e1000e_poll - NAPI Rx polling callback
       
  2752  * @napi: struct associated with this polling callback
       
  2753  * @weight: number of packets driver is allowed to process this poll
       
  2754  **/
       
  2755 static int e1000e_poll(struct napi_struct *napi, int weight)
       
  2756 {
       
  2757 	struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
       
  2758 						     napi);
       
  2759 	struct e1000_hw *hw = &adapter->hw;
       
  2760 	struct net_device *poll_dev = adapter->netdev;
       
  2761 	int tx_cleaned = 1, work_done = 0;
       
  2762 
       
  2763 	adapter = netdev_priv(poll_dev);
       
  2764 
       
  2765 	if (!adapter->msix_entries ||
       
  2766 	    (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
       
  2767 		tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
       
  2768 
       
  2769 	adapter->clean_rx(adapter->rx_ring, &work_done, weight);
       
  2770 
       
  2771 	if (!tx_cleaned)
       
  2772 		work_done = weight;
       
  2773 
       
  2774 	/* If weight not fully consumed, exit the polling mode */
       
  2775 	if (work_done < weight) {
       
  2776 		if (adapter->itr_setting & 3)
       
  2777 			e1000_set_itr(adapter);
       
  2778 		napi_complete(napi);
       
  2779 		if (!test_bit(__E1000_DOWN, &adapter->state)) {
       
  2780 			if (adapter->msix_entries)
       
  2781 				ew32(IMS, adapter->rx_ring->ims_val);
       
  2782 			else
       
  2783 				e1000_irq_enable(adapter);
       
  2784 		}
       
  2785 	}
       
  2786 
       
  2787 	return work_done;
       
  2788 }
       
  2789 
       
  2790 static int e1000_vlan_rx_add_vid(struct net_device *netdev,
       
  2791 				 __always_unused __be16 proto, u16 vid)
       
  2792 {
       
  2793 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  2794 	struct e1000_hw *hw = &adapter->hw;
       
  2795 	u32 vfta, index;
       
  2796 
       
  2797 	/* don't update vlan cookie if already programmed */
       
  2798 	if ((adapter->hw.mng_cookie.status &
       
  2799 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
       
  2800 	    (vid == adapter->mng_vlan_id))
       
  2801 		return 0;
       
  2802 
       
  2803 	/* add VID to filter table */
       
  2804 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
       
  2805 		index = (vid >> 5) & 0x7F;
       
  2806 		vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
       
  2807 		vfta |= (1 << (vid & 0x1F));
       
  2808 		hw->mac.ops.write_vfta(hw, index, vfta);
       
  2809 	}
       
  2810 
       
  2811 	set_bit(vid, adapter->active_vlans);
       
  2812 
       
  2813 	return 0;
       
  2814 }
       
  2815 
       
  2816 static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
       
  2817 				  __always_unused __be16 proto, u16 vid)
       
  2818 {
       
  2819 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  2820 	struct e1000_hw *hw = &adapter->hw;
       
  2821 	u32 vfta, index;
       
  2822 
       
  2823 	if ((adapter->hw.mng_cookie.status &
       
  2824 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
       
  2825 	    (vid == adapter->mng_vlan_id)) {
       
  2826 		/* release control to f/w */
       
  2827 		e1000e_release_hw_control(adapter);
       
  2828 		return 0;
       
  2829 	}
       
  2830 
       
  2831 	/* remove VID from filter table */
       
  2832 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
       
  2833 		index = (vid >> 5) & 0x7F;
       
  2834 		vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
       
  2835 		vfta &= ~(1 << (vid & 0x1F));
       
  2836 		hw->mac.ops.write_vfta(hw, index, vfta);
       
  2837 	}
       
  2838 
       
  2839 	clear_bit(vid, adapter->active_vlans);
       
  2840 
       
  2841 	return 0;
       
  2842 }
       
  2843 
       
  2844 /**
       
  2845  * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
       
  2846  * @adapter: board private structure to initialize
       
  2847  **/
       
  2848 static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
       
  2849 {
       
  2850 	struct net_device *netdev = adapter->netdev;
       
  2851 	struct e1000_hw *hw = &adapter->hw;
       
  2852 	u32 rctl;
       
  2853 
       
  2854 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
       
  2855 		/* disable VLAN receive filtering */
       
  2856 		rctl = er32(RCTL);
       
  2857 		rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
       
  2858 		ew32(RCTL, rctl);
       
  2859 
       
  2860 		if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
       
  2861 			e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
       
  2862 					       adapter->mng_vlan_id);
       
  2863 			adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
       
  2864 		}
       
  2865 	}
       
  2866 }
       
  2867 
       
  2868 /**
       
  2869  * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
       
  2870  * @adapter: board private structure to initialize
       
  2871  **/
       
  2872 static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
       
  2873 {
       
  2874 	struct e1000_hw *hw = &adapter->hw;
       
  2875 	u32 rctl;
       
  2876 
       
  2877 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
       
  2878 		/* enable VLAN receive filtering */
       
  2879 		rctl = er32(RCTL);
       
  2880 		rctl |= E1000_RCTL_VFE;
       
  2881 		rctl &= ~E1000_RCTL_CFIEN;
       
  2882 		ew32(RCTL, rctl);
       
  2883 	}
       
  2884 }
       
  2885 
       
  2886 /**
       
  2887  * e1000e_vlan_strip_enable - helper to disable HW VLAN stripping
       
  2888  * @adapter: board private structure to initialize
       
  2889  **/
       
  2890 static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
       
  2891 {
       
  2892 	struct e1000_hw *hw = &adapter->hw;
       
  2893 	u32 ctrl;
       
  2894 
       
  2895 	/* disable VLAN tag insert/strip */
       
  2896 	ctrl = er32(CTRL);
       
  2897 	ctrl &= ~E1000_CTRL_VME;
       
  2898 	ew32(CTRL, ctrl);
       
  2899 }
       
  2900 
       
  2901 /**
       
  2902  * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
       
  2903  * @adapter: board private structure to initialize
       
  2904  **/
       
  2905 static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
       
  2906 {
       
  2907 	struct e1000_hw *hw = &adapter->hw;
       
  2908 	u32 ctrl;
       
  2909 
       
  2910 	/* enable VLAN tag insert/strip */
       
  2911 	ctrl = er32(CTRL);
       
  2912 	ctrl |= E1000_CTRL_VME;
       
  2913 	ew32(CTRL, ctrl);
       
  2914 }
       
  2915 
       
  2916 static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
       
  2917 {
       
  2918 	struct net_device *netdev = adapter->netdev;
       
  2919 	u16 vid = adapter->hw.mng_cookie.vlan_id;
       
  2920 	u16 old_vid = adapter->mng_vlan_id;
       
  2921 
       
  2922 	if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
       
  2923 		e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
       
  2924 		adapter->mng_vlan_id = vid;
       
  2925 	}
       
  2926 
       
  2927 	if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
       
  2928 		e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
       
  2929 }
       
  2930 
       
  2931 static void e1000_restore_vlan(struct e1000_adapter *adapter)
       
  2932 {
       
  2933 	u16 vid;
       
  2934 
       
  2935 	e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
       
  2936 
       
  2937 	for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
       
  2938 	    e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
       
  2939 }
       
  2940 
       
  2941 static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
       
  2942 {
       
  2943 	struct e1000_hw *hw = &adapter->hw;
       
  2944 	u32 manc, manc2h, mdef, i, j;
       
  2945 
       
  2946 	if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
       
  2947 		return;
       
  2948 
       
  2949 	manc = er32(MANC);
       
  2950 
       
  2951 	/* enable receiving management packets to the host. this will probably
       
  2952 	 * generate destination unreachable messages from the host OS, but
       
  2953 	 * the packets will be handled on SMBUS
       
  2954 	 */
       
  2955 	manc |= E1000_MANC_EN_MNG2HOST;
       
  2956 	manc2h = er32(MANC2H);
       
  2957 
       
  2958 	switch (hw->mac.type) {
       
  2959 	default:
       
  2960 		manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
       
  2961 		break;
       
  2962 	case e1000_82574:
       
  2963 	case e1000_82583:
       
  2964 		/* Check if IPMI pass-through decision filter already exists;
       
  2965 		 * if so, enable it.
       
  2966 		 */
       
  2967 		for (i = 0, j = 0; i < 8; i++) {
       
  2968 			mdef = er32(MDEF(i));
       
  2969 
       
  2970 			/* Ignore filters with anything other than IPMI ports */
       
  2971 			if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
       
  2972 				continue;
       
  2973 
       
  2974 			/* Enable this decision filter in MANC2H */
       
  2975 			if (mdef)
       
  2976 				manc2h |= (1 << i);
       
  2977 
       
  2978 			j |= mdef;
       
  2979 		}
       
  2980 
       
  2981 		if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
       
  2982 			break;
       
  2983 
       
  2984 		/* Create new decision filter in an empty filter */
       
  2985 		for (i = 0, j = 0; i < 8; i++)
       
  2986 			if (er32(MDEF(i)) == 0) {
       
  2987 				ew32(MDEF(i), (E1000_MDEF_PORT_623 |
       
  2988 					       E1000_MDEF_PORT_664));
       
  2989 				manc2h |= (1 << 1);
       
  2990 				j++;
       
  2991 				break;
       
  2992 			}
       
  2993 
       
  2994 		if (!j)
       
  2995 			e_warn("Unable to create IPMI pass-through filter\n");
       
  2996 		break;
       
  2997 	}
       
  2998 
       
  2999 	ew32(MANC2H, manc2h);
       
  3000 	ew32(MANC, manc);
       
  3001 }
       
  3002 
       
  3003 /**
       
  3004  * e1000_configure_tx - Configure Transmit Unit after Reset
       
  3005  * @adapter: board private structure
       
  3006  *
       
  3007  * Configure the Tx unit of the MAC after a reset.
       
  3008  **/
       
  3009 static void e1000_configure_tx(struct e1000_adapter *adapter)
       
  3010 {
       
  3011 	struct e1000_hw *hw = &adapter->hw;
       
  3012 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  3013 	u64 tdba;
       
  3014 	u32 tdlen, tctl, tarc;
       
  3015 
       
  3016 	/* Setup the HW Tx Head and Tail descriptor pointers */
       
  3017 	tdba = tx_ring->dma;
       
  3018 	tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
       
  3019 	ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
       
  3020 	ew32(TDBAH(0), (tdba >> 32));
       
  3021 	ew32(TDLEN(0), tdlen);
       
  3022 	ew32(TDH(0), 0);
       
  3023 	ew32(TDT(0), 0);
       
  3024 	tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
       
  3025 	tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
       
  3026 
       
  3027 	/* Set the Tx Interrupt Delay register */
       
  3028 	ew32(TIDV, adapter->tx_int_delay);
       
  3029 	/* Tx irq moderation */
       
  3030 	ew32(TADV, adapter->tx_abs_int_delay);
       
  3031 
       
  3032 	if (adapter->flags2 & FLAG2_DMA_BURST) {
       
  3033 		u32 txdctl = er32(TXDCTL(0));
       
  3034 
       
  3035 		txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
       
  3036 			    E1000_TXDCTL_WTHRESH);
       
  3037 		/* set up some performance related parameters to encourage the
       
  3038 		 * hardware to use the bus more efficiently in bursts, depends
       
  3039 		 * on the tx_int_delay to be enabled,
       
  3040 		 * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
       
  3041 		 * hthresh = 1 ==> prefetch when one or more available
       
  3042 		 * pthresh = 0x1f ==> prefetch if internal cache 31 or less
       
  3043 		 * BEWARE: this seems to work but should be considered first if
       
  3044 		 * there are Tx hangs or other Tx related bugs
       
  3045 		 */
       
  3046 		txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
       
  3047 		ew32(TXDCTL(0), txdctl);
       
  3048 	}
       
  3049 	/* erratum work around: set txdctl the same for both queues */
       
  3050 	ew32(TXDCTL(1), er32(TXDCTL(0)));
       
  3051 
       
  3052 	/* Program the Transmit Control Register */
       
  3053 	tctl = er32(TCTL);
       
  3054 	tctl &= ~E1000_TCTL_CT;
       
  3055 	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
       
  3056 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
       
  3057 
       
  3058 	if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
       
  3059 		tarc = er32(TARC(0));
       
  3060 		/* set the speed mode bit, we'll clear it if we're not at
       
  3061 		 * gigabit link later
       
  3062 		 */
       
  3063 #define SPEED_MODE_BIT (1 << 21)
       
  3064 		tarc |= SPEED_MODE_BIT;
       
  3065 		ew32(TARC(0), tarc);
       
  3066 	}
       
  3067 
       
  3068 	/* errata: program both queues to unweighted RR */
       
  3069 	if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
       
  3070 		tarc = er32(TARC(0));
       
  3071 		tarc |= 1;
       
  3072 		ew32(TARC(0), tarc);
       
  3073 		tarc = er32(TARC(1));
       
  3074 		tarc |= 1;
       
  3075 		ew32(TARC(1), tarc);
       
  3076 	}
       
  3077 
       
  3078 	/* Setup Transmit Descriptor Settings for eop descriptor */
       
  3079 	adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
       
  3080 
       
  3081 	/* only set IDE if we are delaying interrupts using the timers */
       
  3082 	if (adapter->tx_int_delay)
       
  3083 		adapter->txd_cmd |= E1000_TXD_CMD_IDE;
       
  3084 
       
  3085 	/* enable Report Status bit */
       
  3086 	adapter->txd_cmd |= E1000_TXD_CMD_RS;
       
  3087 
       
  3088 	ew32(TCTL, tctl);
       
  3089 
       
  3090 	hw->mac.ops.config_collision_dist(hw);
       
  3091 }
       
  3092 
       
  3093 /**
       
  3094  * e1000_setup_rctl - configure the receive control registers
       
  3095  * @adapter: Board private structure
       
  3096  **/
       
  3097 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
       
  3098 			   (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
       
  3099 static void e1000_setup_rctl(struct e1000_adapter *adapter)
       
  3100 {
       
  3101 	struct e1000_hw *hw = &adapter->hw;
       
  3102 	u32 rctl, rfctl;
       
  3103 	u32 pages = 0;
       
  3104 
       
  3105 	/* Workaround Si errata on PCHx - configure jumbo frame flow.
       
  3106 	 * If jumbo frames not set, program related MAC/PHY registers
       
  3107 	 * to h/w defaults
       
  3108 	 */
       
  3109 	if (hw->mac.type >= e1000_pch2lan) {
       
  3110 		s32 ret_val;
       
  3111 
       
  3112 		if (adapter->netdev->mtu > ETH_DATA_LEN)
       
  3113 			ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
       
  3114 		else
       
  3115 			ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
       
  3116 
       
  3117 		if (ret_val)
       
  3118 			e_dbg("failed to enable|disable jumbo frame workaround mode\n");
       
  3119 	}
       
  3120 
       
  3121 	/* Program MC offset vector base */
       
  3122 	rctl = er32(RCTL);
       
  3123 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
       
  3124 	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
       
  3125 	    E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
       
  3126 	    (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
       
  3127 
       
  3128 	/* Do not Store bad packets */
       
  3129 	rctl &= ~E1000_RCTL_SBP;
       
  3130 
       
  3131 	/* Enable Long Packet receive */
       
  3132 	if (adapter->netdev->mtu <= ETH_DATA_LEN)
       
  3133 		rctl &= ~E1000_RCTL_LPE;
       
  3134 	else
       
  3135 		rctl |= E1000_RCTL_LPE;
       
  3136 
       
  3137 	/* Some systems expect that the CRC is included in SMBUS traffic. The
       
  3138 	 * hardware strips the CRC before sending to both SMBUS (BMC) and to
       
  3139 	 * host memory when this is enabled
       
  3140 	 */
       
  3141 	if (adapter->flags2 & FLAG2_CRC_STRIPPING)
       
  3142 		rctl |= E1000_RCTL_SECRC;
       
  3143 
       
  3144 	/* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
       
  3145 	if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
       
  3146 		u16 phy_data;
       
  3147 
       
  3148 		e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
       
  3149 		phy_data &= 0xfff8;
       
  3150 		phy_data |= (1 << 2);
       
  3151 		e1e_wphy(hw, PHY_REG(770, 26), phy_data);
       
  3152 
       
  3153 		e1e_rphy(hw, 22, &phy_data);
       
  3154 		phy_data &= 0x0fff;
       
  3155 		phy_data |= (1 << 14);
       
  3156 		e1e_wphy(hw, 0x10, 0x2823);
       
  3157 		e1e_wphy(hw, 0x11, 0x0003);
       
  3158 		e1e_wphy(hw, 22, phy_data);
       
  3159 	}
       
  3160 
       
  3161 	/* Setup buffer sizes */
       
  3162 	rctl &= ~E1000_RCTL_SZ_4096;
       
  3163 	rctl |= E1000_RCTL_BSEX;
       
  3164 	switch (adapter->rx_buffer_len) {
       
  3165 	case 2048:
       
  3166 	default:
       
  3167 		rctl |= E1000_RCTL_SZ_2048;
       
  3168 		rctl &= ~E1000_RCTL_BSEX;
       
  3169 		break;
       
  3170 	case 4096:
       
  3171 		rctl |= E1000_RCTL_SZ_4096;
       
  3172 		break;
       
  3173 	case 8192:
       
  3174 		rctl |= E1000_RCTL_SZ_8192;
       
  3175 		break;
       
  3176 	case 16384:
       
  3177 		rctl |= E1000_RCTL_SZ_16384;
       
  3178 		break;
       
  3179 	}
       
  3180 
       
  3181 	/* Enable Extended Status in all Receive Descriptors */
       
  3182 	rfctl = er32(RFCTL);
       
  3183 	rfctl |= E1000_RFCTL_EXTEN;
       
  3184 	ew32(RFCTL, rfctl);
       
  3185 
       
  3186 	/* 82571 and greater support packet-split where the protocol
       
  3187 	 * header is placed in skb->data and the packet data is
       
  3188 	 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
       
  3189 	 * In the case of a non-split, skb->data is linearly filled,
       
  3190 	 * followed by the page buffers.  Therefore, skb->data is
       
  3191 	 * sized to hold the largest protocol header.
       
  3192 	 *
       
  3193 	 * allocations using alloc_page take too long for regular MTU
       
  3194 	 * so only enable packet split for jumbo frames
       
  3195 	 *
       
  3196 	 * Using pages when the page size is greater than 16k wastes
       
  3197 	 * a lot of memory, since we allocate 3 pages at all times
       
  3198 	 * per packet.
       
  3199 	 */
       
  3200 	pages = PAGE_USE_COUNT(adapter->netdev->mtu);
       
  3201 	if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
       
  3202 		adapter->rx_ps_pages = pages;
       
  3203 	else
       
  3204 		adapter->rx_ps_pages = 0;
       
  3205 
       
  3206 	if (adapter->rx_ps_pages) {
       
  3207 		u32 psrctl = 0;
       
  3208 
       
  3209 		/* Enable Packet split descriptors */
       
  3210 		rctl |= E1000_RCTL_DTYP_PS;
       
  3211 
       
  3212 		psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
       
  3213 
       
  3214 		switch (adapter->rx_ps_pages) {
       
  3215 		case 3:
       
  3216 			psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
       
  3217 			/* fall-through */
       
  3218 		case 2:
       
  3219 			psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
       
  3220 			/* fall-through */
       
  3221 		case 1:
       
  3222 			psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
       
  3223 			break;
       
  3224 		}
       
  3225 
       
  3226 		ew32(PSRCTL, psrctl);
       
  3227 	}
       
  3228 
       
  3229 	/* This is useful for sniffing bad packets. */
       
  3230 	if (adapter->netdev->features & NETIF_F_RXALL) {
       
  3231 		/* UPE and MPE will be handled by normal PROMISC logic
       
  3232 		 * in e1000e_set_rx_mode
       
  3233 		 */
       
  3234 		rctl |= (E1000_RCTL_SBP |	/* Receive bad packets */
       
  3235 			 E1000_RCTL_BAM |	/* RX All Bcast Pkts */
       
  3236 			 E1000_RCTL_PMCF);	/* RX All MAC Ctrl Pkts */
       
  3237 
       
  3238 		rctl &= ~(E1000_RCTL_VFE |	/* Disable VLAN filter */
       
  3239 			  E1000_RCTL_DPF |	/* Allow filtered pause */
       
  3240 			  E1000_RCTL_CFIEN);	/* Dis VLAN CFIEN Filter */
       
  3241 		/* Do not mess with E1000_CTRL_VME, it affects transmit as well,
       
  3242 		 * and that breaks VLANs.
       
  3243 		 */
       
  3244 	}
       
  3245 
       
  3246 	ew32(RCTL, rctl);
       
  3247 	/* just started the receive unit, no need to restart */
       
  3248 	adapter->flags &= ~FLAG_RESTART_NOW;
       
  3249 }
       
  3250 
       
  3251 /**
       
  3252  * e1000_configure_rx - Configure Receive Unit after Reset
       
  3253  * @adapter: board private structure
       
  3254  *
       
  3255  * Configure the Rx unit of the MAC after a reset.
       
  3256  **/
       
  3257 static void e1000_configure_rx(struct e1000_adapter *adapter)
       
  3258 {
       
  3259 	struct e1000_hw *hw = &adapter->hw;
       
  3260 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
  3261 	u64 rdba;
       
  3262 	u32 rdlen, rctl, rxcsum, ctrl_ext;
       
  3263 
       
  3264 	if (adapter->rx_ps_pages) {
       
  3265 		/* this is a 32 byte descriptor */
       
  3266 		rdlen = rx_ring->count *
       
  3267 		    sizeof(union e1000_rx_desc_packet_split);
       
  3268 		adapter->clean_rx = e1000_clean_rx_irq_ps;
       
  3269 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
       
  3270 	} else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
       
  3271 		rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
       
  3272 		adapter->clean_rx = e1000_clean_jumbo_rx_irq;
       
  3273 		adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
       
  3274 	} else {
       
  3275 		rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
       
  3276 		adapter->clean_rx = e1000_clean_rx_irq;
       
  3277 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
       
  3278 	}
       
  3279 
       
  3280 	/* disable receives while setting up the descriptors */
       
  3281 	rctl = er32(RCTL);
       
  3282 	if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
       
  3283 		ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
  3284 	e1e_flush();
       
  3285 	usleep_range(10000, 20000);
       
  3286 
       
  3287 	if (adapter->flags2 & FLAG2_DMA_BURST) {
       
  3288 		/* set the writeback threshold (only takes effect if the RDTR
       
  3289 		 * is set). set GRAN=1 and write back up to 0x4 worth, and
       
  3290 		 * enable prefetching of 0x20 Rx descriptors
       
  3291 		 * granularity = 01
       
  3292 		 * wthresh = 04,
       
  3293 		 * hthresh = 04,
       
  3294 		 * pthresh = 0x20
       
  3295 		 */
       
  3296 		ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
       
  3297 		ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
       
  3298 
       
  3299 		/* override the delay timers for enabling bursting, only if
       
  3300 		 * the value was not set by the user via module options
       
  3301 		 */
       
  3302 		if (adapter->rx_int_delay == DEFAULT_RDTR)
       
  3303 			adapter->rx_int_delay = BURST_RDTR;
       
  3304 		if (adapter->rx_abs_int_delay == DEFAULT_RADV)
       
  3305 			adapter->rx_abs_int_delay = BURST_RADV;
       
  3306 	}
       
  3307 
       
  3308 	/* set the Receive Delay Timer Register */
       
  3309 	ew32(RDTR, adapter->rx_int_delay);
       
  3310 
       
  3311 	/* irq moderation */
       
  3312 	ew32(RADV, adapter->rx_abs_int_delay);
       
  3313 	if ((adapter->itr_setting != 0) && (adapter->itr != 0))
       
  3314 		e1000e_write_itr(adapter, adapter->itr);
       
  3315 
       
  3316 	ctrl_ext = er32(CTRL_EXT);
       
  3317 	/* Auto-Mask interrupts upon ICR access */
       
  3318 	ctrl_ext |= E1000_CTRL_EXT_IAME;
       
  3319 	ew32(IAM, 0xffffffff);
       
  3320 	ew32(CTRL_EXT, ctrl_ext);
       
  3321 	e1e_flush();
       
  3322 
       
  3323 	/* Setup the HW Rx Head and Tail Descriptor Pointers and
       
  3324 	 * the Base and Length of the Rx Descriptor Ring
       
  3325 	 */
       
  3326 	rdba = rx_ring->dma;
       
  3327 	ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
       
  3328 	ew32(RDBAH(0), (rdba >> 32));
       
  3329 	ew32(RDLEN(0), rdlen);
       
  3330 	ew32(RDH(0), 0);
       
  3331 	ew32(RDT(0), 0);
       
  3332 	rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
       
  3333 	rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
       
  3334 
       
  3335 	/* Enable Receive Checksum Offload for TCP and UDP */
       
  3336 	rxcsum = er32(RXCSUM);
       
  3337 	if (adapter->netdev->features & NETIF_F_RXCSUM)
       
  3338 		rxcsum |= E1000_RXCSUM_TUOFL;
       
  3339 	else
       
  3340 		rxcsum &= ~E1000_RXCSUM_TUOFL;
       
  3341 	ew32(RXCSUM, rxcsum);
       
  3342 
       
  3343 	/* With jumbo frames, excessive C-state transition latencies result
       
  3344 	 * in dropped transactions.
       
  3345 	 */
       
  3346 	if (adapter->netdev->mtu > ETH_DATA_LEN) {
       
  3347 		u32 lat =
       
  3348 		    ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
       
  3349 		     adapter->max_frame_size) * 8 / 1000;
       
  3350 
       
  3351 		if (adapter->flags & FLAG_IS_ICH) {
       
  3352 			u32 rxdctl = er32(RXDCTL(0));
       
  3353 
       
  3354 			ew32(RXDCTL(0), rxdctl | 0x3);
       
  3355 		}
       
  3356 
       
  3357 		pm_qos_update_request(&adapter->netdev->pm_qos_req, lat);
       
  3358 	} else {
       
  3359 		pm_qos_update_request(&adapter->netdev->pm_qos_req,
       
  3360 				      PM_QOS_DEFAULT_VALUE);
       
  3361 	}
       
  3362 
       
  3363 	/* Enable Receives */
       
  3364 	ew32(RCTL, rctl);
       
  3365 }
       
  3366 
       
  3367 /**
       
  3368  * e1000e_write_mc_addr_list - write multicast addresses to MTA
       
  3369  * @netdev: network interface device structure
       
  3370  *
       
  3371  * Writes multicast address list to the MTA hash table.
       
  3372  * Returns: -ENOMEM on failure
       
  3373  *                0 on no addresses written
       
  3374  *                X on writing X addresses to MTA
       
  3375  */
       
  3376 static int e1000e_write_mc_addr_list(struct net_device *netdev)
       
  3377 {
       
  3378 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3379 	struct e1000_hw *hw = &adapter->hw;
       
  3380 	struct netdev_hw_addr *ha;
       
  3381 	u8 *mta_list;
       
  3382 	int i;
       
  3383 
       
  3384 	if (netdev_mc_empty(netdev)) {
       
  3385 		/* nothing to program, so clear mc list */
       
  3386 		hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
       
  3387 		return 0;
       
  3388 	}
       
  3389 
       
  3390 	mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
       
  3391 	if (!mta_list)
       
  3392 		return -ENOMEM;
       
  3393 
       
  3394 	/* update_mc_addr_list expects a packed array of only addresses. */
       
  3395 	i = 0;
       
  3396 	netdev_for_each_mc_addr(ha, netdev)
       
  3397 	    memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
       
  3398 
       
  3399 	hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
       
  3400 	kfree(mta_list);
       
  3401 
       
  3402 	return netdev_mc_count(netdev);
       
  3403 }
       
  3404 
       
  3405 /**
       
  3406  * e1000e_write_uc_addr_list - write unicast addresses to RAR table
       
  3407  * @netdev: network interface device structure
       
  3408  *
       
  3409  * Writes unicast address list to the RAR table.
       
  3410  * Returns: -ENOMEM on failure/insufficient address space
       
  3411  *                0 on no addresses written
       
  3412  *                X on writing X addresses to the RAR table
       
  3413  **/
       
  3414 static int e1000e_write_uc_addr_list(struct net_device *netdev)
       
  3415 {
       
  3416 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3417 	struct e1000_hw *hw = &adapter->hw;
       
  3418 	unsigned int rar_entries;
       
  3419 	int count = 0;
       
  3420 
       
  3421 	rar_entries = hw->mac.ops.rar_get_count(hw);
       
  3422 
       
  3423 	/* save a rar entry for our hardware address */
       
  3424 	rar_entries--;
       
  3425 
       
  3426 	/* save a rar entry for the LAA workaround */
       
  3427 	if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
       
  3428 		rar_entries--;
       
  3429 
       
  3430 	/* return ENOMEM indicating insufficient memory for addresses */
       
  3431 	if (netdev_uc_count(netdev) > rar_entries)
       
  3432 		return -ENOMEM;
       
  3433 
       
  3434 	if (!netdev_uc_empty(netdev) && rar_entries) {
       
  3435 		struct netdev_hw_addr *ha;
       
  3436 
       
  3437 		/* write the addresses in reverse order to avoid write
       
  3438 		 * combining
       
  3439 		 */
       
  3440 		netdev_for_each_uc_addr(ha, netdev) {
       
  3441 			int rval;
       
  3442 
       
  3443 			if (!rar_entries)
       
  3444 				break;
       
  3445 			rval = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
       
  3446 			if (rval < 0)
       
  3447 				return -ENOMEM;
       
  3448 			count++;
       
  3449 		}
       
  3450 	}
       
  3451 
       
  3452 	/* zero out the remaining RAR entries not used above */
       
  3453 	for (; rar_entries > 0; rar_entries--) {
       
  3454 		ew32(RAH(rar_entries), 0);
       
  3455 		ew32(RAL(rar_entries), 0);
       
  3456 	}
       
  3457 	e1e_flush();
       
  3458 
       
  3459 	return count;
       
  3460 }
       
  3461 
       
  3462 /**
       
  3463  * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
       
  3464  * @netdev: network interface device structure
       
  3465  *
       
  3466  * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
       
  3467  * address list or the network interface flags are updated.  This routine is
       
  3468  * responsible for configuring the hardware for proper unicast, multicast,
       
  3469  * promiscuous mode, and all-multi behavior.
       
  3470  **/
       
  3471 static void e1000e_set_rx_mode(struct net_device *netdev)
       
  3472 {
       
  3473 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3474 	struct e1000_hw *hw = &adapter->hw;
       
  3475 	u32 rctl;
       
  3476 
       
  3477 	if (pm_runtime_suspended(netdev->dev.parent))
       
  3478 		return;
       
  3479 
       
  3480 	/* Check for Promiscuous and All Multicast modes */
       
  3481 	rctl = er32(RCTL);
       
  3482 
       
  3483 	/* clear the affected bits */
       
  3484 	rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
       
  3485 
       
  3486 	if (netdev->flags & IFF_PROMISC) {
       
  3487 		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
       
  3488 		/* Do not hardware filter VLANs in promisc mode */
       
  3489 		e1000e_vlan_filter_disable(adapter);
       
  3490 	} else {
       
  3491 		int count;
       
  3492 
       
  3493 		if (netdev->flags & IFF_ALLMULTI) {
       
  3494 			rctl |= E1000_RCTL_MPE;
       
  3495 		} else {
       
  3496 			/* Write addresses to the MTA, if the attempt fails
       
  3497 			 * then we should just turn on promiscuous mode so
       
  3498 			 * that we can at least receive multicast traffic
       
  3499 			 */
       
  3500 			count = e1000e_write_mc_addr_list(netdev);
       
  3501 			if (count < 0)
       
  3502 				rctl |= E1000_RCTL_MPE;
       
  3503 		}
       
  3504 		e1000e_vlan_filter_enable(adapter);
       
  3505 		/* Write addresses to available RAR registers, if there is not
       
  3506 		 * sufficient space to store all the addresses then enable
       
  3507 		 * unicast promiscuous mode
       
  3508 		 */
       
  3509 		count = e1000e_write_uc_addr_list(netdev);
       
  3510 		if (count < 0)
       
  3511 			rctl |= E1000_RCTL_UPE;
       
  3512 	}
       
  3513 
       
  3514 	ew32(RCTL, rctl);
       
  3515 
       
  3516 	if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
       
  3517 		e1000e_vlan_strip_enable(adapter);
       
  3518 	else
       
  3519 		e1000e_vlan_strip_disable(adapter);
       
  3520 }
       
  3521 
       
  3522 static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
       
  3523 {
       
  3524 	struct e1000_hw *hw = &adapter->hw;
       
  3525 	u32 mrqc, rxcsum;
       
  3526 	int i;
       
  3527 	static const u32 rsskey[10] = {
       
  3528 		0xda565a6d, 0xc20e5b25, 0x3d256741, 0xb08fa343, 0xcb2bcad0,
       
  3529 		0xb4307bae, 0xa32dcb77, 0x0cf23080, 0x3bb7426a, 0xfa01acbe
       
  3530 	};
       
  3531 
       
  3532 	/* Fill out hash function seed */
       
  3533 	for (i = 0; i < 10; i++)
       
  3534 		ew32(RSSRK(i), rsskey[i]);
       
  3535 
       
  3536 	/* Direct all traffic to queue 0 */
       
  3537 	for (i = 0; i < 32; i++)
       
  3538 		ew32(RETA(i), 0);
       
  3539 
       
  3540 	/* Disable raw packet checksumming so that RSS hash is placed in
       
  3541 	 * descriptor on writeback.
       
  3542 	 */
       
  3543 	rxcsum = er32(RXCSUM);
       
  3544 	rxcsum |= E1000_RXCSUM_PCSD;
       
  3545 
       
  3546 	ew32(RXCSUM, rxcsum);
       
  3547 
       
  3548 	mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
       
  3549 		E1000_MRQC_RSS_FIELD_IPV4_TCP |
       
  3550 		E1000_MRQC_RSS_FIELD_IPV6 |
       
  3551 		E1000_MRQC_RSS_FIELD_IPV6_TCP |
       
  3552 		E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
       
  3553 
       
  3554 	ew32(MRQC, mrqc);
       
  3555 }
       
  3556 
       
  3557 /**
       
  3558  * e1000e_get_base_timinca - get default SYSTIM time increment attributes
       
  3559  * @adapter: board private structure
       
  3560  * @timinca: pointer to returned time increment attributes
       
  3561  *
       
  3562  * Get attributes for incrementing the System Time Register SYSTIML/H at
       
  3563  * the default base frequency, and set the cyclecounter shift value.
       
  3564  **/
       
  3565 s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
       
  3566 {
       
  3567 	struct e1000_hw *hw = &adapter->hw;
       
  3568 	u32 incvalue, incperiod, shift;
       
  3569 
       
  3570 	/* Make sure clock is enabled on I217 before checking the frequency */
       
  3571 	if ((hw->mac.type == e1000_pch_lpt) &&
       
  3572 	    !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
       
  3573 	    !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
       
  3574 		u32 fextnvm7 = er32(FEXTNVM7);
       
  3575 
       
  3576 		if (!(fextnvm7 & (1 << 0))) {
       
  3577 			ew32(FEXTNVM7, fextnvm7 | (1 << 0));
       
  3578 			e1e_flush();
       
  3579 		}
       
  3580 	}
       
  3581 
       
  3582 	switch (hw->mac.type) {
       
  3583 	case e1000_pch2lan:
       
  3584 	case e1000_pch_lpt:
       
  3585 		/* On I217, the clock frequency is 25MHz or 96MHz as
       
  3586 		 * indicated by the System Clock Frequency Indication
       
  3587 		 */
       
  3588 		if ((hw->mac.type != e1000_pch_lpt) ||
       
  3589 		    (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)) {
       
  3590 			/* Stable 96MHz frequency */
       
  3591 			incperiod = INCPERIOD_96MHz;
       
  3592 			incvalue = INCVALUE_96MHz;
       
  3593 			shift = INCVALUE_SHIFT_96MHz;
       
  3594 			adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHz;
       
  3595 			break;
       
  3596 		}
       
  3597 		/* fall-through */
       
  3598 	case e1000_82574:
       
  3599 	case e1000_82583:
       
  3600 		/* Stable 25MHz frequency */
       
  3601 		incperiod = INCPERIOD_25MHz;
       
  3602 		incvalue = INCVALUE_25MHz;
       
  3603 		shift = INCVALUE_SHIFT_25MHz;
       
  3604 		adapter->cc.shift = shift;
       
  3605 		break;
       
  3606 	default:
       
  3607 		return -EINVAL;
       
  3608 	}
       
  3609 
       
  3610 	*timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
       
  3611 		    ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
       
  3612 
       
  3613 	return 0;
       
  3614 }
       
  3615 
       
  3616 /**
       
  3617  * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
       
  3618  * @adapter: board private structure
       
  3619  *
       
  3620  * Outgoing time stamping can be enabled and disabled. Play nice and
       
  3621  * disable it when requested, although it shouldn't cause any overhead
       
  3622  * when no packet needs it. At most one packet in the queue may be
       
  3623  * marked for time stamping, otherwise it would be impossible to tell
       
  3624  * for sure to which packet the hardware time stamp belongs.
       
  3625  *
       
  3626  * Incoming time stamping has to be configured via the hardware filters.
       
  3627  * Not all combinations are supported, in particular event type has to be
       
  3628  * specified. Matching the kind of event packet is not supported, with the
       
  3629  * exception of "all V2 events regardless of level 2 or 4".
       
  3630  **/
       
  3631 static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
       
  3632 				  struct hwtstamp_config *config)
       
  3633 {
       
  3634 	struct e1000_hw *hw = &adapter->hw;
       
  3635 	u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
       
  3636 	u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
       
  3637 	u32 rxmtrl = 0;
       
  3638 	u16 rxudp = 0;
       
  3639 	bool is_l4 = false;
       
  3640 	bool is_l2 = false;
       
  3641 	u32 regval;
       
  3642 	s32 ret_val;
       
  3643 
       
  3644 	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
       
  3645 		return -EINVAL;
       
  3646 
       
  3647 	/* flags reserved for future extensions - must be zero */
       
  3648 	if (config->flags)
       
  3649 		return -EINVAL;
       
  3650 
       
  3651 	switch (config->tx_type) {
       
  3652 	case HWTSTAMP_TX_OFF:
       
  3653 		tsync_tx_ctl = 0;
       
  3654 		break;
       
  3655 	case HWTSTAMP_TX_ON:
       
  3656 		break;
       
  3657 	default:
       
  3658 		return -ERANGE;
       
  3659 	}
       
  3660 
       
  3661 	switch (config->rx_filter) {
       
  3662 	case HWTSTAMP_FILTER_NONE:
       
  3663 		tsync_rx_ctl = 0;
       
  3664 		break;
       
  3665 	case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
       
  3666 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
       
  3667 		rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
       
  3668 		is_l4 = true;
       
  3669 		break;
       
  3670 	case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
       
  3671 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
       
  3672 		rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
       
  3673 		is_l4 = true;
       
  3674 		break;
       
  3675 	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
       
  3676 		/* Also time stamps V2 L2 Path Delay Request/Response */
       
  3677 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
       
  3678 		rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
       
  3679 		is_l2 = true;
       
  3680 		break;
       
  3681 	case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
       
  3682 		/* Also time stamps V2 L2 Path Delay Request/Response. */
       
  3683 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
       
  3684 		rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
       
  3685 		is_l2 = true;
       
  3686 		break;
       
  3687 	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
       
  3688 		/* Hardware cannot filter just V2 L4 Sync messages;
       
  3689 		 * fall-through to V2 (both L2 and L4) Sync.
       
  3690 		 */
       
  3691 	case HWTSTAMP_FILTER_PTP_V2_SYNC:
       
  3692 		/* Also time stamps V2 Path Delay Request/Response. */
       
  3693 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
       
  3694 		rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
       
  3695 		is_l2 = true;
       
  3696 		is_l4 = true;
       
  3697 		break;
       
  3698 	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
       
  3699 		/* Hardware cannot filter just V2 L4 Delay Request messages;
       
  3700 		 * fall-through to V2 (both L2 and L4) Delay Request.
       
  3701 		 */
       
  3702 	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
       
  3703 		/* Also time stamps V2 Path Delay Request/Response. */
       
  3704 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
       
  3705 		rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
       
  3706 		is_l2 = true;
       
  3707 		is_l4 = true;
       
  3708 		break;
       
  3709 	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
       
  3710 	case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
       
  3711 		/* Hardware cannot filter just V2 L4 or L2 Event messages;
       
  3712 		 * fall-through to all V2 (both L2 and L4) Events.
       
  3713 		 */
       
  3714 	case HWTSTAMP_FILTER_PTP_V2_EVENT:
       
  3715 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
       
  3716 		config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
       
  3717 		is_l2 = true;
       
  3718 		is_l4 = true;
       
  3719 		break;
       
  3720 	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
       
  3721 		/* For V1, the hardware can only filter Sync messages or
       
  3722 		 * Delay Request messages but not both so fall-through to
       
  3723 		 * time stamp all packets.
       
  3724 		 */
       
  3725 	case HWTSTAMP_FILTER_ALL:
       
  3726 		is_l2 = true;
       
  3727 		is_l4 = true;
       
  3728 		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
       
  3729 		config->rx_filter = HWTSTAMP_FILTER_ALL;
       
  3730 		break;
       
  3731 	default:
       
  3732 		return -ERANGE;
       
  3733 	}
       
  3734 
       
  3735 	adapter->hwtstamp_config = *config;
       
  3736 
       
  3737 	/* enable/disable Tx h/w time stamping */
       
  3738 	regval = er32(TSYNCTXCTL);
       
  3739 	regval &= ~E1000_TSYNCTXCTL_ENABLED;
       
  3740 	regval |= tsync_tx_ctl;
       
  3741 	ew32(TSYNCTXCTL, regval);
       
  3742 	if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
       
  3743 	    (regval & E1000_TSYNCTXCTL_ENABLED)) {
       
  3744 		e_err("Timesync Tx Control register not set as expected\n");
       
  3745 		return -EAGAIN;
       
  3746 	}
       
  3747 
       
  3748 	/* enable/disable Rx h/w time stamping */
       
  3749 	regval = er32(TSYNCRXCTL);
       
  3750 	regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
       
  3751 	regval |= tsync_rx_ctl;
       
  3752 	ew32(TSYNCRXCTL, regval);
       
  3753 	if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
       
  3754 				 E1000_TSYNCRXCTL_TYPE_MASK)) !=
       
  3755 	    (regval & (E1000_TSYNCRXCTL_ENABLED |
       
  3756 		       E1000_TSYNCRXCTL_TYPE_MASK))) {
       
  3757 		e_err("Timesync Rx Control register not set as expected\n");
       
  3758 		return -EAGAIN;
       
  3759 	}
       
  3760 
       
  3761 	/* L2: define ethertype filter for time stamped packets */
       
  3762 	if (is_l2)
       
  3763 		rxmtrl |= ETH_P_1588;
       
  3764 
       
  3765 	/* define which PTP packets get time stamped */
       
  3766 	ew32(RXMTRL, rxmtrl);
       
  3767 
       
  3768 	/* Filter by destination port */
       
  3769 	if (is_l4) {
       
  3770 		rxudp = PTP_EV_PORT;
       
  3771 		cpu_to_be16s(&rxudp);
       
  3772 	}
       
  3773 	ew32(RXUDP, rxudp);
       
  3774 
       
  3775 	e1e_flush();
       
  3776 
       
  3777 	/* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
       
  3778 	er32(RXSTMPH);
       
  3779 	er32(TXSTMPH);
       
  3780 
       
  3781 	/* Get and set the System Time Register SYSTIM base frequency */
       
  3782 	ret_val = e1000e_get_base_timinca(adapter, &regval);
       
  3783 	if (ret_val)
       
  3784 		return ret_val;
       
  3785 	ew32(TIMINCA, regval);
       
  3786 
       
  3787 	/* reset the ns time counter */
       
  3788 	timecounter_init(&adapter->tc, &adapter->cc,
       
  3789 			 ktime_to_ns(ktime_get_real()));
       
  3790 
       
  3791 	return 0;
       
  3792 }
       
  3793 
       
  3794 /**
       
  3795  * e1000_configure - configure the hardware for Rx and Tx
       
  3796  * @adapter: private board structure
       
  3797  **/
       
  3798 static void e1000_configure(struct e1000_adapter *adapter)
       
  3799 {
       
  3800 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
  3801 
       
  3802 	e1000e_set_rx_mode(adapter->netdev);
       
  3803 
       
  3804 	e1000_restore_vlan(adapter);
       
  3805 	e1000_init_manageability_pt(adapter);
       
  3806 
       
  3807 	e1000_configure_tx(adapter);
       
  3808 
       
  3809 	if (adapter->netdev->features & NETIF_F_RXHASH)
       
  3810 		e1000e_setup_rss_hash(adapter);
       
  3811 	e1000_setup_rctl(adapter);
       
  3812 	e1000_configure_rx(adapter);
       
  3813 	if (adapter->ecdev) {
       
  3814 		adapter->alloc_rx_buf(rx_ring, adapter->rx_ring->count, GFP_KERNEL);
       
  3815 	} else {
       
  3816 		adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring),
       
  3817 				GFP_KERNEL);
       
  3818 	}
       
  3819 }
       
  3820 
       
  3821 /**
       
  3822  * e1000e_power_up_phy - restore link in case the phy was powered down
       
  3823  * @adapter: address of board private structure
       
  3824  *
       
  3825  * The phy may be powered down to save power and turn off link when the
       
  3826  * driver is unloaded and wake on lan is not enabled (among others)
       
  3827  * *** this routine MUST be followed by a call to e1000e_reset ***
       
  3828  **/
       
  3829 void e1000e_power_up_phy(struct e1000_adapter *adapter)
       
  3830 {
       
  3831 	if (adapter->hw.phy.ops.power_up)
       
  3832 		adapter->hw.phy.ops.power_up(&adapter->hw);
       
  3833 
       
  3834 	adapter->hw.mac.ops.setup_link(&adapter->hw);
       
  3835 }
       
  3836 
       
  3837 /**
       
  3838  * e1000_power_down_phy - Power down the PHY
       
  3839  *
       
  3840  * Power down the PHY so no link is implied when interface is down.
       
  3841  * The PHY cannot be powered down if management or WoL is active.
       
  3842  */
       
  3843 static void e1000_power_down_phy(struct e1000_adapter *adapter)
       
  3844 {
       
  3845 	if (adapter->hw.phy.ops.power_down)
       
  3846 		adapter->hw.phy.ops.power_down(&adapter->hw);
       
  3847 }
       
  3848 
       
  3849 /**
       
  3850  * e1000e_reset - bring the hardware into a known good state
       
  3851  *
       
  3852  * This function boots the hardware and enables some settings that
       
  3853  * require a configuration cycle of the hardware - those cannot be
       
  3854  * set/changed during runtime. After reset the device needs to be
       
  3855  * properly configured for Rx, Tx etc.
       
  3856  */
       
  3857 void e1000e_reset(struct e1000_adapter *adapter)
       
  3858 {
       
  3859 	struct e1000_mac_info *mac = &adapter->hw.mac;
       
  3860 	struct e1000_fc_info *fc = &adapter->hw.fc;
       
  3861 	struct e1000_hw *hw = &adapter->hw;
       
  3862 	u32 tx_space, min_tx_space, min_rx_space;
       
  3863 	u32 pba = adapter->pba;
       
  3864 	u16 hwm;
       
  3865 
       
  3866 	/* reset Packet Buffer Allocation to default */
       
  3867 	ew32(PBA, pba);
       
  3868 
       
  3869 	if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
       
  3870 		/* To maintain wire speed transmits, the Tx FIFO should be
       
  3871 		 * large enough to accommodate two full transmit packets,
       
  3872 		 * rounded up to the next 1KB and expressed in KB.  Likewise,
       
  3873 		 * the Rx FIFO should be large enough to accommodate at least
       
  3874 		 * one full receive packet and is similarly rounded up and
       
  3875 		 * expressed in KB.
       
  3876 		 */
       
  3877 		pba = er32(PBA);
       
  3878 		/* upper 16 bits has Tx packet buffer allocation size in KB */
       
  3879 		tx_space = pba >> 16;
       
  3880 		/* lower 16 bits has Rx packet buffer allocation size in KB */
       
  3881 		pba &= 0xffff;
       
  3882 		/* the Tx fifo also stores 16 bytes of information about the Tx
       
  3883 		 * but don't include ethernet FCS because hardware appends it
       
  3884 		 */
       
  3885 		min_tx_space = (adapter->max_frame_size +
       
  3886 				sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
       
  3887 		min_tx_space = ALIGN(min_tx_space, 1024);
       
  3888 		min_tx_space >>= 10;
       
  3889 		/* software strips receive CRC, so leave room for it */
       
  3890 		min_rx_space = adapter->max_frame_size;
       
  3891 		min_rx_space = ALIGN(min_rx_space, 1024);
       
  3892 		min_rx_space >>= 10;
       
  3893 
       
  3894 		/* If current Tx allocation is less than the min Tx FIFO size,
       
  3895 		 * and the min Tx FIFO size is less than the current Rx FIFO
       
  3896 		 * allocation, take space away from current Rx allocation
       
  3897 		 */
       
  3898 		if ((tx_space < min_tx_space) &&
       
  3899 		    ((min_tx_space - tx_space) < pba)) {
       
  3900 			pba -= min_tx_space - tx_space;
       
  3901 
       
  3902 			/* if short on Rx space, Rx wins and must trump Tx
       
  3903 			 * adjustment
       
  3904 			 */
       
  3905 			if (pba < min_rx_space)
       
  3906 				pba = min_rx_space;
       
  3907 		}
       
  3908 
       
  3909 		ew32(PBA, pba);
       
  3910 	}
       
  3911 
       
  3912 	/* flow control settings
       
  3913 	 *
       
  3914 	 * The high water mark must be low enough to fit one full frame
       
  3915 	 * (or the size used for early receive) above it in the Rx FIFO.
       
  3916 	 * Set it to the lower of:
       
  3917 	 * - 90% of the Rx FIFO size, and
       
  3918 	 * - the full Rx FIFO size minus one full frame
       
  3919 	 */
       
  3920 	if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
       
  3921 		fc->pause_time = 0xFFFF;
       
  3922 	else
       
  3923 		fc->pause_time = E1000_FC_PAUSE_TIME;
       
  3924 	fc->send_xon = true;
       
  3925 	fc->current_mode = fc->requested_mode;
       
  3926 
       
  3927 	switch (hw->mac.type) {
       
  3928 	case e1000_ich9lan:
       
  3929 	case e1000_ich10lan:
       
  3930 		if (adapter->netdev->mtu > ETH_DATA_LEN) {
       
  3931 			pba = 14;
       
  3932 			ew32(PBA, pba);
       
  3933 			fc->high_water = 0x2800;
       
  3934 			fc->low_water = fc->high_water - 8;
       
  3935 			break;
       
  3936 		}
       
  3937 		/* fall-through */
       
  3938 	default:
       
  3939 		hwm = min(((pba << 10) * 9 / 10),
       
  3940 			  ((pba << 10) - adapter->max_frame_size));
       
  3941 
       
  3942 		fc->high_water = hwm & E1000_FCRTH_RTH;	/* 8-byte granularity */
       
  3943 		fc->low_water = fc->high_water - 8;
       
  3944 		break;
       
  3945 	case e1000_pchlan:
       
  3946 		/* Workaround PCH LOM adapter hangs with certain network
       
  3947 		 * loads.  If hangs persist, try disabling Tx flow control.
       
  3948 		 */
       
  3949 		if (adapter->netdev->mtu > ETH_DATA_LEN) {
       
  3950 			fc->high_water = 0x3500;
       
  3951 			fc->low_water = 0x1500;
       
  3952 		} else {
       
  3953 			fc->high_water = 0x5000;
       
  3954 			fc->low_water = 0x3000;
       
  3955 		}
       
  3956 		fc->refresh_time = 0x1000;
       
  3957 		break;
       
  3958 	case e1000_pch2lan:
       
  3959 	case e1000_pch_lpt:
       
  3960 		fc->refresh_time = 0x0400;
       
  3961 
       
  3962 		if (adapter->netdev->mtu <= ETH_DATA_LEN) {
       
  3963 			fc->high_water = 0x05C20;
       
  3964 			fc->low_water = 0x05048;
       
  3965 			fc->pause_time = 0x0650;
       
  3966 			break;
       
  3967 		}
       
  3968 
       
  3969 		pba = 14;
       
  3970 		ew32(PBA, pba);
       
  3971 		fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
       
  3972 		fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
       
  3973 		break;
       
  3974 	}
       
  3975 
       
  3976 	/* Alignment of Tx data is on an arbitrary byte boundary with the
       
  3977 	 * maximum size per Tx descriptor limited only to the transmit
       
  3978 	 * allocation of the packet buffer minus 96 bytes with an upper
       
  3979 	 * limit of 24KB due to receive synchronization limitations.
       
  3980 	 */
       
  3981 	adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
       
  3982 				       24 << 10);
       
  3983 
       
  3984 	/* Disable Adaptive Interrupt Moderation if 2 full packets cannot
       
  3985 	 * fit in receive buffer.
       
  3986 	 */
       
  3987 	if (adapter->itr_setting & 0x3) {
       
  3988 		if ((adapter->max_frame_size * 2) > (pba << 10)) {
       
  3989 			if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
       
  3990 				dev_info(&adapter->pdev->dev,
       
  3991 					 "Interrupt Throttle Rate off\n");
       
  3992 				adapter->flags2 |= FLAG2_DISABLE_AIM;
       
  3993 				e1000e_write_itr(adapter, 0);
       
  3994 			}
       
  3995 		} else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
       
  3996 			dev_info(&adapter->pdev->dev,
       
  3997 				 "Interrupt Throttle Rate on\n");
       
  3998 			adapter->flags2 &= ~FLAG2_DISABLE_AIM;
       
  3999 			adapter->itr = 20000;
       
  4000 			e1000e_write_itr(adapter, adapter->itr);
       
  4001 		}
       
  4002 	}
       
  4003 
       
  4004 	/* Allow time for pending master requests to run */
       
  4005 	mac->ops.reset_hw(hw);
       
  4006 
       
  4007 	/* For parts with AMT enabled, let the firmware know
       
  4008 	 * that the network interface is in control
       
  4009 	 */
       
  4010 	if (adapter->flags & FLAG_HAS_AMT)
       
  4011 		e1000e_get_hw_control(adapter);
       
  4012 
       
  4013 	ew32(WUC, 0);
       
  4014 
       
  4015 	if (mac->ops.init_hw(hw))
       
  4016 		e_err("Hardware Error\n");
       
  4017 
       
  4018 	e1000_update_mng_vlan(adapter);
       
  4019 
       
  4020 	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
       
  4021 	ew32(VET, ETH_P_8021Q);
       
  4022 
       
  4023 	e1000e_reset_adaptive(hw);
       
  4024 
       
  4025 	/* initialize systim and reset the ns time counter */
       
  4026 	e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
       
  4027 
       
  4028 	/* Set EEE advertisement as appropriate */
       
  4029 	if (adapter->flags2 & FLAG2_HAS_EEE) {
       
  4030 		s32 ret_val;
       
  4031 		u16 adv_addr;
       
  4032 
       
  4033 		switch (hw->phy.type) {
       
  4034 		case e1000_phy_82579:
       
  4035 			adv_addr = I82579_EEE_ADVERTISEMENT;
       
  4036 			break;
       
  4037 		case e1000_phy_i217:
       
  4038 			adv_addr = I217_EEE_ADVERTISEMENT;
       
  4039 			break;
       
  4040 		default:
       
  4041 			dev_err(&adapter->pdev->dev,
       
  4042 				"Invalid PHY type setting EEE advertisement\n");
       
  4043 			return;
       
  4044 		}
       
  4045 
       
  4046 		ret_val = hw->phy.ops.acquire(hw);
       
  4047 		if (ret_val) {
       
  4048 			dev_err(&adapter->pdev->dev,
       
  4049 				"EEE advertisement - unable to acquire PHY\n");
       
  4050 			return;
       
  4051 		}
       
  4052 
       
  4053 		e1000_write_emi_reg_locked(hw, adv_addr,
       
  4054 					   hw->dev_spec.ich8lan.eee_disable ?
       
  4055 					   0 : adapter->eee_advert);
       
  4056 
       
  4057 		hw->phy.ops.release(hw);
       
  4058 	}
       
  4059 
       
  4060 	if (!netif_running(adapter->netdev) &&
       
  4061 	    !test_bit(__E1000_TESTING, &adapter->state))
       
  4062 		e1000_power_down_phy(adapter);
       
  4063 
       
  4064 	e1000_get_phy_info(hw);
       
  4065 
       
  4066 	if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
       
  4067 	    !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
       
  4068 		u16 phy_data = 0;
       
  4069 		/* speed up time to link by disabling smart power down, ignore
       
  4070 		 * the return value of this function because there is nothing
       
  4071 		 * different we would do if it failed
       
  4072 		 */
       
  4073 		e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
       
  4074 		phy_data &= ~IGP02E1000_PM_SPD;
       
  4075 		e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
       
  4076 	}
       
  4077 }
       
  4078 
       
  4079 int e1000e_up(struct e1000_adapter *adapter)
       
  4080 {
       
  4081 	struct e1000_hw *hw = &adapter->hw;
       
  4082 
       
  4083 	/* hardware has been reset, we need to reload some things */
       
  4084 	e1000_configure(adapter);
       
  4085 
       
  4086 	clear_bit(__E1000_DOWN, &adapter->state);
       
  4087 
       
  4088 	if (!adapter->ecdev) {
       
  4089 		if (adapter->msix_entries)
       
  4090 			e1000_configure_msix(adapter);
       
  4091 
       
  4092 		e1000_irq_enable(adapter);
       
  4093 
       
  4094 		netif_start_queue(adapter->netdev);
       
  4095 
       
  4096 		/* fire a link change interrupt to start the watchdog */
       
  4097 		if (adapter->msix_entries)
       
  4098 			ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
       
  4099 		else
       
  4100 			ew32(ICS, E1000_ICS_LSC);
       
  4101 	}
       
  4102 
       
  4103 	return 0;
       
  4104 }
       
  4105 
       
  4106 static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
       
  4107 {
       
  4108 	struct e1000_hw *hw = &adapter->hw;
       
  4109 
       
  4110 	if (!(adapter->flags2 & FLAG2_DMA_BURST))
       
  4111 		return;
       
  4112 
       
  4113 	/* flush pending descriptor writebacks to memory */
       
  4114 	ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
       
  4115 	ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
       
  4116 
       
  4117 	/* execute the writes immediately */
       
  4118 	e1e_flush();
       
  4119 
       
  4120 	/* due to rare timing issues, write to TIDV/RDTR again to ensure the
       
  4121 	 * write is successful
       
  4122 	 */
       
  4123 	ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
       
  4124 	ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
       
  4125 
       
  4126 	/* execute the writes immediately */
       
  4127 	e1e_flush();
       
  4128 }
       
  4129 
       
  4130 static void e1000e_update_stats(struct e1000_adapter *adapter);
       
  4131 
       
  4132 /**
       
  4133  * e1000e_down - quiesce the device and optionally reset the hardware
       
  4134  * @adapter: board private structure
       
  4135  * @reset: boolean flag to reset the hardware or not
       
  4136  */
       
  4137 void e1000e_down(struct e1000_adapter *adapter, bool reset)
       
  4138 {
       
  4139 	struct net_device *netdev = adapter->netdev;
       
  4140 	struct e1000_hw *hw = &adapter->hw;
       
  4141 	u32 tctl, rctl;
       
  4142 
       
  4143 	/* signal that we're down so the interrupt handler does not
       
  4144 	 * reschedule our watchdog timer
       
  4145 	 */
       
  4146 	set_bit(__E1000_DOWN, &adapter->state);
       
  4147 
       
  4148 	/* disable receives in the hardware */
       
  4149 	rctl = er32(RCTL);
       
  4150 	if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
       
  4151 		ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
  4152 	/* flush and sleep below */
       
  4153 
       
  4154 	if (!adapter->ecdev)
       
  4155 		netif_stop_queue(netdev);
       
  4156 
       
  4157 	/* disable transmits in the hardware */
       
  4158 	tctl = er32(TCTL);
       
  4159 	tctl &= ~E1000_TCTL_EN;
       
  4160 	ew32(TCTL, tctl);
       
  4161 
       
  4162 	/* flush both disables and wait for them to finish */
       
  4163 	e1e_flush();
       
  4164 	usleep_range(10000, 20000);
       
  4165 
       
  4166 	if (adapter->ecdev) {
       
  4167 		ecdev_set_link(adapter->ecdev, 0);
       
  4168 	}
       
  4169 	else {
       
  4170 		e1000_irq_disable(adapter);
       
  4171 
       
  4172 		napi_synchronize(&adapter->napi);
       
  4173 
       
  4174 		del_timer_sync(&adapter->watchdog_timer);
       
  4175 		del_timer_sync(&adapter->phy_info_timer);
       
  4176 
       
  4177 		netif_carrier_off(netdev);
       
  4178 
       
  4179 		spin_lock(&adapter->stats64_lock);
       
  4180 		e1000e_update_stats(adapter);
       
  4181 		spin_unlock(&adapter->stats64_lock);
       
  4182 	}
       
  4183 
       
  4184 	e1000e_flush_descriptors(adapter);
       
  4185 	e1000_clean_tx_ring(adapter->tx_ring);
       
  4186 	e1000_clean_rx_ring(adapter->rx_ring);
       
  4187 
       
  4188 	adapter->link_speed = 0;
       
  4189 	adapter->link_duplex = 0;
       
  4190 
       
  4191 	/* Disable Si errata workaround on PCHx for jumbo frame flow */
       
  4192 	if ((hw->mac.type >= e1000_pch2lan) &&
       
  4193 	    (adapter->netdev->mtu > ETH_DATA_LEN) &&
       
  4194 	    e1000_lv_jumbo_workaround_ich8lan(hw, false))
       
  4195 		e_dbg("failed to disable jumbo frame workaround mode\n");
       
  4196 
       
  4197 	if (reset && !pci_channel_offline(adapter->pdev))
       
  4198 		e1000e_reset(adapter);
       
  4199 }
       
  4200 
       
  4201 void e1000e_reinit_locked(struct e1000_adapter *adapter)
       
  4202 {
       
  4203 	might_sleep();
       
  4204 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
       
  4205 		usleep_range(1000, 2000);
       
  4206 	e1000e_down(adapter, true);
       
  4207 	e1000e_up(adapter);
       
  4208 	clear_bit(__E1000_RESETTING, &adapter->state);
       
  4209 }
       
  4210 
       
  4211 /**
       
  4212  * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
       
  4213  * @cc: cyclecounter structure
       
  4214  **/
       
  4215 static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
       
  4216 {
       
  4217 	struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
       
  4218 						     cc);
       
  4219 	struct e1000_hw *hw = &adapter->hw;
       
  4220 	cycle_t systim, systim_next;
       
  4221 
       
  4222 	/* latch SYSTIMH on read of SYSTIML */
       
  4223 	systim = (cycle_t)er32(SYSTIML);
       
  4224 	systim |= (cycle_t)er32(SYSTIMH) << 32;
       
  4225 
       
  4226 	if ((hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82583)) {
       
  4227 		u64 incvalue, time_delta, rem, temp;
       
  4228 		int i;
       
  4229 
       
  4230 		/* errata for 82574/82583 possible bad bits read from SYSTIMH/L
       
  4231 		 * check to see that the time is incrementing at a reasonable
       
  4232 		 * rate and is a multiple of incvalue
       
  4233 		 */
       
  4234 		incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
       
  4235 		for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
       
  4236 			/* latch SYSTIMH on read of SYSTIML */
       
  4237 			systim_next = (cycle_t)er32(SYSTIML);
       
  4238 			systim_next |= (cycle_t)er32(SYSTIMH) << 32;
       
  4239 
       
  4240 			time_delta = systim_next - systim;
       
  4241 			temp = time_delta;
       
  4242 			rem = do_div(temp, incvalue);
       
  4243 
       
  4244 			systim = systim_next;
       
  4245 
       
  4246 			if ((time_delta < E1000_82574_SYSTIM_EPSILON) &&
       
  4247 			    (rem == 0))
       
  4248 				break;
       
  4249 		}
       
  4250 	}
       
  4251 	return systim;
       
  4252 }
       
  4253 
       
  4254 /**
       
  4255  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
       
  4256  * @adapter: board private structure to initialize
       
  4257  *
       
  4258  * e1000_sw_init initializes the Adapter private data structure.
       
  4259  * Fields are initialized based on PCI device information and
       
  4260  * OS network device settings (MTU size).
       
  4261  **/
       
  4262 static int e1000_sw_init(struct e1000_adapter *adapter)
       
  4263 {
       
  4264 	struct net_device *netdev = adapter->netdev;
       
  4265 
       
  4266 	adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
       
  4267 	adapter->rx_ps_bsize0 = 128;
       
  4268 	adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
       
  4269 	adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
       
  4270 	adapter->tx_ring_count = E1000_DEFAULT_TXD;
       
  4271 	adapter->rx_ring_count = E1000_DEFAULT_RXD;
       
  4272 
       
  4273 	spin_lock_init(&adapter->stats64_lock);
       
  4274 
       
  4275 	e1000e_set_interrupt_capability(adapter);
       
  4276 
       
  4277 	if (e1000_alloc_queues(adapter))
       
  4278 		return -ENOMEM;
       
  4279 
       
  4280 	/* Setup hardware time stamping cyclecounter */
       
  4281 	if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
       
  4282 		adapter->cc.read = e1000e_cyclecounter_read;
       
  4283 		adapter->cc.mask = CLOCKSOURCE_MASK(64);
       
  4284 		adapter->cc.mult = 1;
       
  4285 		/* cc.shift set in e1000e_get_base_tininca() */
       
  4286 
       
  4287 		spin_lock_init(&adapter->systim_lock);
       
  4288 		INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
       
  4289 	}
       
  4290 
       
  4291 	/* Explicitly disable IRQ since the NIC can be in any state. */
       
  4292 	e1000_irq_disable(adapter);
       
  4293 
       
  4294 	set_bit(__E1000_DOWN, &adapter->state);
       
  4295 	return 0;
       
  4296 }
       
  4297 
       
  4298 /**
       
  4299  * e1000_intr_msi_test - Interrupt Handler
       
  4300  * @irq: interrupt number
       
  4301  * @data: pointer to a network interface device structure
       
  4302  **/
       
  4303 static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
       
  4304 {
       
  4305 	struct net_device *netdev = data;
       
  4306 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  4307 	struct e1000_hw *hw = &adapter->hw;
       
  4308 	u32 icr = er32(ICR);
       
  4309 
       
  4310 	e_dbg("icr is %08X\n", icr);
       
  4311 	if (icr & E1000_ICR_RXSEQ) {
       
  4312 		adapter->flags &= ~FLAG_MSI_TEST_FAILED;
       
  4313 		/* Force memory writes to complete before acknowledging the
       
  4314 		 * interrupt is handled.
       
  4315 		 */
       
  4316 		wmb();
       
  4317 	}
       
  4318 
       
  4319 	return IRQ_HANDLED;
       
  4320 }
       
  4321 
       
  4322 /**
       
  4323  * e1000_test_msi_interrupt - Returns 0 for successful test
       
  4324  * @adapter: board private struct
       
  4325  *
       
  4326  * code flow taken from tg3.c
       
  4327  **/
       
  4328 static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
       
  4329 {
       
  4330 	struct net_device *netdev = adapter->netdev;
       
  4331 	struct e1000_hw *hw = &adapter->hw;
       
  4332 	int err;
       
  4333 
       
  4334 	/* poll_enable hasn't been called yet, so don't need disable */
       
  4335 	/* clear any pending events */
       
  4336 	er32(ICR);
       
  4337 
       
  4338 	/* free the real vector and request a test handler */
       
  4339 	e1000_free_irq(adapter);
       
  4340 	e1000e_reset_interrupt_capability(adapter);
       
  4341 
       
  4342 	/* Assume that the test fails, if it succeeds then the test
       
  4343 	 * MSI irq handler will unset this flag
       
  4344 	 */
       
  4345 	adapter->flags |= FLAG_MSI_TEST_FAILED;
       
  4346 
       
  4347 	err = pci_enable_msi(adapter->pdev);
       
  4348 	if (err)
       
  4349 		goto msi_test_failed;
       
  4350 
       
  4351 	err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
       
  4352 			  netdev->name, netdev);
       
  4353 	if (err) {
       
  4354 		pci_disable_msi(adapter->pdev);
       
  4355 		goto msi_test_failed;
       
  4356 	}
       
  4357 
       
  4358 	/* Force memory writes to complete before enabling and firing an
       
  4359 	 * interrupt.
       
  4360 	 */
       
  4361 	wmb();
       
  4362 
       
  4363 	e1000_irq_enable(adapter);
       
  4364 
       
  4365 	/* fire an unusual interrupt on the test handler */
       
  4366 	ew32(ICS, E1000_ICS_RXSEQ);
       
  4367 	e1e_flush();
       
  4368 	msleep(100);
       
  4369 
       
  4370 	e1000_irq_disable(adapter);
       
  4371 
       
  4372 	rmb();			/* read flags after interrupt has been fired */
       
  4373 
       
  4374 	if (adapter->flags & FLAG_MSI_TEST_FAILED) {
       
  4375 		adapter->int_mode = E1000E_INT_MODE_LEGACY;
       
  4376 		e_info("MSI interrupt test failed, using legacy interrupt.\n");
       
  4377 	} else {
       
  4378 		e_dbg("MSI interrupt test succeeded!\n");
       
  4379 	}
       
  4380 
       
  4381 	free_irq(adapter->pdev->irq, netdev);
       
  4382 	pci_disable_msi(adapter->pdev);
       
  4383 
       
  4384 msi_test_failed:
       
  4385 	e1000e_set_interrupt_capability(adapter);
       
  4386 	return e1000_request_irq(adapter);
       
  4387 }
       
  4388 
       
  4389 /**
       
  4390  * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
       
  4391  * @adapter: board private struct
       
  4392  *
       
  4393  * code flow taken from tg3.c, called with e1000 interrupts disabled.
       
  4394  **/
       
  4395 static int e1000_test_msi(struct e1000_adapter *adapter)
       
  4396 {
       
  4397 	int err;
       
  4398 	u16 pci_cmd;
       
  4399 
       
  4400 	if (!(adapter->flags & FLAG_MSI_ENABLED))
       
  4401 		return 0;
       
  4402 
       
  4403 	/* disable SERR in case the MSI write causes a master abort */
       
  4404 	pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
       
  4405 	if (pci_cmd & PCI_COMMAND_SERR)
       
  4406 		pci_write_config_word(adapter->pdev, PCI_COMMAND,
       
  4407 				      pci_cmd & ~PCI_COMMAND_SERR);
       
  4408 
       
  4409 	err = e1000_test_msi_interrupt(adapter);
       
  4410 
       
  4411 	/* re-enable SERR */
       
  4412 	if (pci_cmd & PCI_COMMAND_SERR) {
       
  4413 		pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
       
  4414 		pci_cmd |= PCI_COMMAND_SERR;
       
  4415 		pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
       
  4416 	}
       
  4417 
       
  4418 	return err;
       
  4419 }
       
  4420 
       
  4421 /**
       
  4422  * e1000_open - Called when a network interface is made active
       
  4423  * @netdev: network interface device structure
       
  4424  *
       
  4425  * Returns 0 on success, negative value on failure
       
  4426  *
       
  4427  * The open entry point is called when a network interface is made
       
  4428  * active by the system (IFF_UP).  At this point all resources needed
       
  4429  * for transmit and receive operations are allocated, the interrupt
       
  4430  * handler is registered with the OS, the watchdog timer is started,
       
  4431  * and the stack is notified that the interface is ready.
       
  4432  **/
       
  4433 static int e1000_open(struct net_device *netdev)
       
  4434 {
       
  4435 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  4436 	struct e1000_hw *hw = &adapter->hw;
       
  4437 	struct pci_dev *pdev = adapter->pdev;
       
  4438 	int err;
       
  4439 
       
  4440 	/* disallow open during test */
       
  4441 	if (test_bit(__E1000_TESTING, &adapter->state))
       
  4442 		return -EBUSY;
       
  4443 
       
  4444 	pm_runtime_get_sync(&pdev->dev);
       
  4445 
       
  4446 	if (adapter->ecdev) {
       
  4447 		ecdev_set_link(adapter->ecdev, 0);
       
  4448 	} else {
       
  4449 		netif_carrier_off(netdev);
       
  4450 	}
       
  4451 
       
  4452 	/* allocate transmit descriptors */
       
  4453 	err = e1000e_setup_tx_resources(adapter->tx_ring);
       
  4454 	if (err)
       
  4455 		goto err_setup_tx;
       
  4456 
       
  4457 	/* allocate receive descriptors */
       
  4458 	err = e1000e_setup_rx_resources(adapter->rx_ring);
       
  4459 	if (err)
       
  4460 		goto err_setup_rx;
       
  4461 
       
  4462 	/* If AMT is enabled, let the firmware know that the network
       
  4463 	 * interface is now open and reset the part to a known state.
       
  4464 	 */
       
  4465 	if (adapter->flags & FLAG_HAS_AMT) {
       
  4466 		e1000e_get_hw_control(adapter);
       
  4467 		e1000e_reset(adapter);
       
  4468 	}
       
  4469 
       
  4470 	e1000e_power_up_phy(adapter);
       
  4471 
       
  4472 	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
       
  4473 	if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
       
  4474 		e1000_update_mng_vlan(adapter);
       
  4475 
       
  4476 	/* DMA latency requirement to workaround jumbo issue */
       
  4477 	pm_qos_add_request(&adapter->netdev->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
       
  4478 			   PM_QOS_DEFAULT_VALUE);
       
  4479 
       
  4480 	/* before we allocate an interrupt, we must be ready to handle it.
       
  4481 	 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
       
  4482 	 * as soon as we call pci_request_irq, so we have to setup our
       
  4483 	 * clean_rx handler before we do so.
       
  4484 	 */
       
  4485 	e1000_configure(adapter);
       
  4486 
       
  4487 	err = e1000_request_irq(adapter);
       
  4488 	if (err)
       
  4489 		goto err_req_irq;
       
  4490 
       
  4491 	/* Work around PCIe errata with MSI interrupts causing some chipsets to
       
  4492 	 * ignore e1000e MSI messages, which means we need to test our MSI
       
  4493 	 * interrupt now
       
  4494 	 */
       
  4495 	if (!adapter->ecdev && adapter->int_mode != E1000E_INT_MODE_LEGACY) {
       
  4496 		err = e1000_test_msi(adapter);
       
  4497 		if (err) {
       
  4498 			e_err("Interrupt allocation failed\n");
       
  4499 			goto err_req_irq;
       
  4500 		}
       
  4501 	}
       
  4502 
       
  4503 	/* From here on the code is the same as e1000e_up() */
       
  4504 	clear_bit(__E1000_DOWN, &adapter->state);
       
  4505 
       
  4506 	if (!adapter->ecdev) {
       
  4507 		napi_enable(&adapter->napi);
       
  4508 
       
  4509 		e1000_irq_enable(adapter);
       
  4510 	}
       
  4511 
       
  4512 	adapter->tx_hang_recheck = false;
       
  4513 
       
  4514 	if (!adapter->ecdev) {
       
  4515 		netif_start_queue(netdev);
       
  4516 	}
       
  4517 
       
  4518 	hw->mac.get_link_status = true;
       
  4519 	pm_runtime_put(&pdev->dev);
       
  4520 
       
  4521 	/* fire a link status change interrupt to start the watchdog */
       
  4522 	if (adapter->msix_entries)
       
  4523 		ew32(ICS, E1000_ICS_LSC | E1000_ICR_OTHER);
       
  4524 	else
       
  4525 		ew32(ICS, E1000_ICS_LSC);
       
  4526 
       
  4527 	return 0;
       
  4528 
       
  4529 err_req_irq:
       
  4530 	e1000e_release_hw_control(adapter);
       
  4531 	e1000_power_down_phy(adapter);
       
  4532 	e1000e_free_rx_resources(adapter->rx_ring);
       
  4533 err_setup_rx:
       
  4534 	e1000e_free_tx_resources(adapter->tx_ring);
       
  4535 err_setup_tx:
       
  4536 	e1000e_reset(adapter);
       
  4537 	pm_runtime_put_sync(&pdev->dev);
       
  4538 
       
  4539 	return err;
       
  4540 }
       
  4541 
       
  4542 /**
       
  4543  * e1000_close - Disables a network interface
       
  4544  * @netdev: network interface device structure
       
  4545  *
       
  4546  * Returns 0, this is not allowed to fail
       
  4547  *
       
  4548  * The close entry point is called when an interface is de-activated
       
  4549  * by the OS.  The hardware is still under the drivers control, but
       
  4550  * needs to be disabled.  A global MAC reset is issued to stop the
       
  4551  * hardware, and all transmit and receive resources are freed.
       
  4552  **/
       
  4553 static int e1000_close(struct net_device *netdev)
       
  4554 {
       
  4555 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  4556 	struct pci_dev *pdev = adapter->pdev;
       
  4557 	int count = E1000_CHECK_RESET_COUNT;
       
  4558 
       
  4559 	while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
       
  4560 		usleep_range(10000, 20000);
       
  4561 
       
  4562 	WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
       
  4563 
       
  4564 	pm_runtime_get_sync(&pdev->dev);
       
  4565 
       
  4566 	if (!test_bit(__E1000_DOWN, &adapter->state)) {
       
  4567 		e1000e_down(adapter, true);
       
  4568 		e1000_free_irq(adapter);
       
  4569 
       
  4570 		/* Link status message must follow this format */
       
  4571 		pr_info("%s NIC Link is Down\n", adapter->netdev->name);
       
  4572 	}
       
  4573 
       
  4574 	if (!adapter->ecdev) {
       
  4575 		napi_disable(&adapter->napi);
       
  4576 	}
       
  4577 
       
  4578 	e1000e_free_tx_resources(adapter->tx_ring);
       
  4579 	e1000e_free_rx_resources(adapter->rx_ring);
       
  4580 
       
  4581 	/* kill manageability vlan ID if supported, but not if a vlan with
       
  4582 	 * the same ID is registered on the host OS (let 8021q kill it)
       
  4583 	 */
       
  4584 	if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
       
  4585 		e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
       
  4586 				       adapter->mng_vlan_id);
       
  4587 
       
  4588 	/* If AMT is enabled, let the firmware know that the network
       
  4589 	 * interface is now closed
       
  4590 	 */
       
  4591 	if ((adapter->flags & FLAG_HAS_AMT) &&
       
  4592 	    !test_bit(__E1000_TESTING, &adapter->state))
       
  4593 		e1000e_release_hw_control(adapter);
       
  4594 
       
  4595 	pm_qos_remove_request(&adapter->netdev->pm_qos_req);
       
  4596 
       
  4597 	pm_runtime_put_sync(&pdev->dev);
       
  4598 
       
  4599 	return 0;
       
  4600 }
       
  4601 
       
  4602 /**
       
  4603  * e1000_set_mac - Change the Ethernet Address of the NIC
       
  4604  * @netdev: network interface device structure
       
  4605  * @p: pointer to an address structure
       
  4606  *
       
  4607  * Returns 0 on success, negative on failure
       
  4608  **/
       
  4609 static int e1000_set_mac(struct net_device *netdev, void *p)
       
  4610 {
       
  4611 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  4612 	struct e1000_hw *hw = &adapter->hw;
       
  4613 	struct sockaddr *addr = p;
       
  4614 
       
  4615 	if (!is_valid_ether_addr(addr->sa_data))
       
  4616 		return -EADDRNOTAVAIL;
       
  4617 
       
  4618 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
       
  4619 	memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
       
  4620 
       
  4621 	hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
       
  4622 
       
  4623 	if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
       
  4624 		/* activate the work around */
       
  4625 		e1000e_set_laa_state_82571(&adapter->hw, 1);
       
  4626 
       
  4627 		/* Hold a copy of the LAA in RAR[14] This is done so that
       
  4628 		 * between the time RAR[0] gets clobbered  and the time it
       
  4629 		 * gets fixed (in e1000_watchdog), the actual LAA is in one
       
  4630 		 * of the RARs and no incoming packets directed to this port
       
  4631 		 * are dropped. Eventually the LAA will be in RAR[0] and
       
  4632 		 * RAR[14]
       
  4633 		 */
       
  4634 		hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
       
  4635 				    adapter->hw.mac.rar_entry_count - 1);
       
  4636 	}
       
  4637 
       
  4638 	return 0;
       
  4639 }
       
  4640 
       
  4641 /**
       
  4642  * e1000e_update_phy_task - work thread to update phy
       
  4643  * @work: pointer to our work struct
       
  4644  *
       
  4645  * this worker thread exists because we must acquire a
       
  4646  * semaphore to read the phy, which we could msleep while
       
  4647  * waiting for it, and we can't msleep in a timer.
       
  4648  **/
       
  4649 static void e1000e_update_phy_task(struct work_struct *work)
       
  4650 {
       
  4651 	struct e1000_adapter *adapter = container_of(work,
       
  4652 						     struct e1000_adapter,
       
  4653 						     update_phy_task);
       
  4654 	struct e1000_hw *hw = &adapter->hw;
       
  4655 
       
  4656 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  4657 		return;
       
  4658 
       
  4659 	e1000_get_phy_info(hw);
       
  4660 
       
  4661 	/* Enable EEE on 82579 after link up */
       
  4662 	if (hw->phy.type >= e1000_phy_82579)
       
  4663 		e1000_set_eee_pchlan(hw);
       
  4664 }
       
  4665 
       
  4666 /**
       
  4667  * e1000_update_phy_info - timre call-back to update PHY info
       
  4668  * @data: pointer to adapter cast into an unsigned long
       
  4669  *
       
  4670  * Need to wait a few seconds after link up to get diagnostic information from
       
  4671  * the phy
       
  4672  **/
       
  4673 static void e1000_update_phy_info(unsigned long data)
       
  4674 {
       
  4675 	struct e1000_adapter *adapter = (struct e1000_adapter *)data;
       
  4676 
       
  4677 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  4678 		return;
       
  4679 
       
  4680 	schedule_work(&adapter->update_phy_task);
       
  4681 }
       
  4682 
       
  4683 /**
       
  4684  * e1000e_update_phy_stats - Update the PHY statistics counters
       
  4685  * @adapter: board private structure
       
  4686  *
       
  4687  * Read/clear the upper 16-bit PHY registers and read/accumulate lower
       
  4688  **/
       
  4689 static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
       
  4690 {
       
  4691 	struct e1000_hw *hw = &adapter->hw;
       
  4692 	s32 ret_val;
       
  4693 	u16 phy_data;
       
  4694 
       
  4695 	ret_val = hw->phy.ops.acquire(hw);
       
  4696 	if (ret_val)
       
  4697 		return;
       
  4698 
       
  4699 	/* A page set is expensive so check if already on desired page.
       
  4700 	 * If not, set to the page with the PHY status registers.
       
  4701 	 */
       
  4702 	hw->phy.addr = 1;
       
  4703 	ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
       
  4704 					   &phy_data);
       
  4705 	if (ret_val)
       
  4706 		goto release;
       
  4707 	if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
       
  4708 		ret_val = hw->phy.ops.set_page(hw,
       
  4709 					       HV_STATS_PAGE << IGP_PAGE_SHIFT);
       
  4710 		if (ret_val)
       
  4711 			goto release;
       
  4712 	}
       
  4713 
       
  4714 	/* Single Collision Count */
       
  4715 	hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
       
  4716 	ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
       
  4717 	if (!ret_val)
       
  4718 		adapter->stats.scc += phy_data;
       
  4719 
       
  4720 	/* Excessive Collision Count */
       
  4721 	hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
       
  4722 	ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
       
  4723 	if (!ret_val)
       
  4724 		adapter->stats.ecol += phy_data;
       
  4725 
       
  4726 	/* Multiple Collision Count */
       
  4727 	hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
       
  4728 	ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
       
  4729 	if (!ret_val)
       
  4730 		adapter->stats.mcc += phy_data;
       
  4731 
       
  4732 	/* Late Collision Count */
       
  4733 	hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
       
  4734 	ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
       
  4735 	if (!ret_val)
       
  4736 		adapter->stats.latecol += phy_data;
       
  4737 
       
  4738 	/* Collision Count - also used for adaptive IFS */
       
  4739 	hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
       
  4740 	ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
       
  4741 	if (!ret_val)
       
  4742 		hw->mac.collision_delta = phy_data;
       
  4743 
       
  4744 	/* Defer Count */
       
  4745 	hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
       
  4746 	ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
       
  4747 	if (!ret_val)
       
  4748 		adapter->stats.dc += phy_data;
       
  4749 
       
  4750 	/* Transmit with no CRS */
       
  4751 	hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
       
  4752 	ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
       
  4753 	if (!ret_val)
       
  4754 		adapter->stats.tncrs += phy_data;
       
  4755 
       
  4756 release:
       
  4757 	hw->phy.ops.release(hw);
       
  4758 }
       
  4759 
       
  4760 /**
       
  4761  * e1000e_update_stats - Update the board statistics counters
       
  4762  * @adapter: board private structure
       
  4763  **/
       
  4764 static void e1000e_update_stats(struct e1000_adapter *adapter)
       
  4765 {
       
  4766 	struct net_device *netdev = adapter->netdev;
       
  4767 	struct e1000_hw *hw = &adapter->hw;
       
  4768 	struct pci_dev *pdev = adapter->pdev;
       
  4769 
       
  4770 	/* Prevent stats update while adapter is being reset, or if the pci
       
  4771 	 * connection is down.
       
  4772 	 */
       
  4773 	if (adapter->link_speed == 0)
       
  4774 		return;
       
  4775 	if (pci_channel_offline(pdev))
       
  4776 		return;
       
  4777 
       
  4778 	adapter->stats.crcerrs += er32(CRCERRS);
       
  4779 	adapter->stats.gprc += er32(GPRC);
       
  4780 	adapter->stats.gorc += er32(GORCL);
       
  4781 	er32(GORCH);		/* Clear gorc */
       
  4782 	adapter->stats.bprc += er32(BPRC);
       
  4783 	adapter->stats.mprc += er32(MPRC);
       
  4784 	adapter->stats.roc += er32(ROC);
       
  4785 
       
  4786 	adapter->stats.mpc += er32(MPC);
       
  4787 
       
  4788 	/* Half-duplex statistics */
       
  4789 	if (adapter->link_duplex == HALF_DUPLEX) {
       
  4790 		if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
       
  4791 			e1000e_update_phy_stats(adapter);
       
  4792 		} else {
       
  4793 			adapter->stats.scc += er32(SCC);
       
  4794 			adapter->stats.ecol += er32(ECOL);
       
  4795 			adapter->stats.mcc += er32(MCC);
       
  4796 			adapter->stats.latecol += er32(LATECOL);
       
  4797 			adapter->stats.dc += er32(DC);
       
  4798 
       
  4799 			hw->mac.collision_delta = er32(COLC);
       
  4800 
       
  4801 			if ((hw->mac.type != e1000_82574) &&
       
  4802 			    (hw->mac.type != e1000_82583))
       
  4803 				adapter->stats.tncrs += er32(TNCRS);
       
  4804 		}
       
  4805 		adapter->stats.colc += hw->mac.collision_delta;
       
  4806 	}
       
  4807 
       
  4808 	adapter->stats.xonrxc += er32(XONRXC);
       
  4809 	adapter->stats.xontxc += er32(XONTXC);
       
  4810 	adapter->stats.xoffrxc += er32(XOFFRXC);
       
  4811 	adapter->stats.xofftxc += er32(XOFFTXC);
       
  4812 	adapter->stats.gptc += er32(GPTC);
       
  4813 	adapter->stats.gotc += er32(GOTCL);
       
  4814 	er32(GOTCH);		/* Clear gotc */
       
  4815 	adapter->stats.rnbc += er32(RNBC);
       
  4816 	adapter->stats.ruc += er32(RUC);
       
  4817 
       
  4818 	adapter->stats.mptc += er32(MPTC);
       
  4819 	adapter->stats.bptc += er32(BPTC);
       
  4820 
       
  4821 	/* used for adaptive IFS */
       
  4822 
       
  4823 	hw->mac.tx_packet_delta = er32(TPT);
       
  4824 	adapter->stats.tpt += hw->mac.tx_packet_delta;
       
  4825 
       
  4826 	adapter->stats.algnerrc += er32(ALGNERRC);
       
  4827 	adapter->stats.rxerrc += er32(RXERRC);
       
  4828 	adapter->stats.cexterr += er32(CEXTERR);
       
  4829 	adapter->stats.tsctc += er32(TSCTC);
       
  4830 	adapter->stats.tsctfc += er32(TSCTFC);
       
  4831 
       
  4832 	/* Fill out the OS statistics structure */
       
  4833 	netdev->stats.multicast = adapter->stats.mprc;
       
  4834 	netdev->stats.collisions = adapter->stats.colc;
       
  4835 
       
  4836 	/* Rx Errors */
       
  4837 
       
  4838 	/* RLEC on some newer hardware can be incorrect so build
       
  4839 	 * our own version based on RUC and ROC
       
  4840 	 */
       
  4841 	netdev->stats.rx_errors = adapter->stats.rxerrc +
       
  4842 	    adapter->stats.crcerrs + adapter->stats.algnerrc +
       
  4843 	    adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
       
  4844 	netdev->stats.rx_length_errors = adapter->stats.ruc +
       
  4845 	    adapter->stats.roc;
       
  4846 	netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
       
  4847 	netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
       
  4848 	netdev->stats.rx_missed_errors = adapter->stats.mpc;
       
  4849 
       
  4850 	/* Tx Errors */
       
  4851 	netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
       
  4852 	netdev->stats.tx_aborted_errors = adapter->stats.ecol;
       
  4853 	netdev->stats.tx_window_errors = adapter->stats.latecol;
       
  4854 	netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
       
  4855 
       
  4856 	/* Tx Dropped needs to be maintained elsewhere */
       
  4857 
       
  4858 	/* Management Stats */
       
  4859 	adapter->stats.mgptc += er32(MGTPTC);
       
  4860 	adapter->stats.mgprc += er32(MGTPRC);
       
  4861 	adapter->stats.mgpdc += er32(MGTPDC);
       
  4862 
       
  4863 	/* Correctable ECC Errors */
       
  4864 	if (hw->mac.type == e1000_pch_lpt) {
       
  4865 		u32 pbeccsts = er32(PBECCSTS);
       
  4866 
       
  4867 		adapter->corr_errors +=
       
  4868 		    pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
       
  4869 		adapter->uncorr_errors +=
       
  4870 		    (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
       
  4871 		    E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
       
  4872 	}
       
  4873 }
       
  4874 
       
  4875 /**
       
  4876  * e1000_phy_read_status - Update the PHY register status snapshot
       
  4877  * @adapter: board private structure
       
  4878  **/
       
  4879 static void e1000_phy_read_status(struct e1000_adapter *adapter)
       
  4880 {
       
  4881 	struct e1000_hw *hw = &adapter->hw;
       
  4882 	struct e1000_phy_regs *phy = &adapter->phy_regs;
       
  4883 
       
  4884 	if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
       
  4885 	    (er32(STATUS) & E1000_STATUS_LU) &&
       
  4886 	    (adapter->hw.phy.media_type == e1000_media_type_copper)) {
       
  4887 		int ret_val;
       
  4888 
       
  4889 		ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
       
  4890 		ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
       
  4891 		ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
       
  4892 		ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
       
  4893 		ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
       
  4894 		ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
       
  4895 		ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
       
  4896 		ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
       
  4897 		if (ret_val)
       
  4898 			e_warn("Error reading PHY register\n");
       
  4899 	} else {
       
  4900 		/* Do not read PHY registers if link is not up
       
  4901 		 * Set values to typical power-on defaults
       
  4902 		 */
       
  4903 		phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
       
  4904 		phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
       
  4905 			     BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
       
  4906 			     BMSR_ERCAP);
       
  4907 		phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
       
  4908 				  ADVERTISE_ALL | ADVERTISE_CSMA);
       
  4909 		phy->lpa = 0;
       
  4910 		phy->expansion = EXPANSION_ENABLENPAGE;
       
  4911 		phy->ctrl1000 = ADVERTISE_1000FULL;
       
  4912 		phy->stat1000 = 0;
       
  4913 		phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
       
  4914 	}
       
  4915 }
       
  4916 
       
  4917 static void e1000_print_link_info(struct e1000_adapter *adapter)
       
  4918 {
       
  4919 	struct e1000_hw *hw = &adapter->hw;
       
  4920 	u32 ctrl = er32(CTRL);
       
  4921 
       
  4922 	/* Link status message must follow this format for user tools */
       
  4923 	pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
       
  4924 		adapter->netdev->name, adapter->link_speed,
       
  4925 		adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
       
  4926 		(ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
       
  4927 		(ctrl & E1000_CTRL_RFCE) ? "Rx" :
       
  4928 		(ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
       
  4929 }
       
  4930 
       
  4931 static bool e1000e_has_link(struct e1000_adapter *adapter)
       
  4932 {
       
  4933 	struct e1000_hw *hw = &adapter->hw;
       
  4934 	bool link_active = false;
       
  4935 	s32 ret_val = 0;
       
  4936 
       
  4937 	/* get_link_status is set on LSC (link status) interrupt or
       
  4938 	 * Rx sequence error interrupt.  get_link_status will stay
       
  4939 	 * false until the check_for_link establishes link
       
  4940 	 * for copper adapters ONLY
       
  4941 	 */
       
  4942 	switch (hw->phy.media_type) {
       
  4943 	case e1000_media_type_copper:
       
  4944 		if (hw->mac.get_link_status) {
       
  4945 			ret_val = hw->mac.ops.check_for_link(hw);
       
  4946 			link_active = !hw->mac.get_link_status;
       
  4947 		} else {
       
  4948 			link_active = true;
       
  4949 		}
       
  4950 		break;
       
  4951 	case e1000_media_type_fiber:
       
  4952 		ret_val = hw->mac.ops.check_for_link(hw);
       
  4953 		link_active = !!(er32(STATUS) & E1000_STATUS_LU);
       
  4954 		break;
       
  4955 	case e1000_media_type_internal_serdes:
       
  4956 		ret_val = hw->mac.ops.check_for_link(hw);
       
  4957 		link_active = adapter->hw.mac.serdes_has_link;
       
  4958 		break;
       
  4959 	default:
       
  4960 	case e1000_media_type_unknown:
       
  4961 		break;
       
  4962 	}
       
  4963 
       
  4964 	if ((ret_val == E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
       
  4965 	    (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
       
  4966 		/* See e1000_kmrn_lock_loss_workaround_ich8lan() */
       
  4967 		e_info("Gigabit has been disabled, downgrading speed\n");
       
  4968 	}
       
  4969 
       
  4970 	return link_active;
       
  4971 }
       
  4972 
       
  4973 static void e1000e_enable_receives(struct e1000_adapter *adapter)
       
  4974 {
       
  4975 	/* make sure the receive unit is started */
       
  4976 	if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
       
  4977 	    (adapter->flags & FLAG_RESTART_NOW)) {
       
  4978 		struct e1000_hw *hw = &adapter->hw;
       
  4979 		u32 rctl = er32(RCTL);
       
  4980 
       
  4981 		ew32(RCTL, rctl | E1000_RCTL_EN);
       
  4982 		adapter->flags &= ~FLAG_RESTART_NOW;
       
  4983 	}
       
  4984 }
       
  4985 
       
  4986 static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
       
  4987 {
       
  4988 	struct e1000_hw *hw = &adapter->hw;
       
  4989 
       
  4990 	/* With 82574 controllers, PHY needs to be checked periodically
       
  4991 	 * for hung state and reset, if two calls return true
       
  4992 	 */
       
  4993 	if (e1000_check_phy_82574(hw))
       
  4994 		adapter->phy_hang_count++;
       
  4995 	else
       
  4996 		adapter->phy_hang_count = 0;
       
  4997 
       
  4998 	if (adapter->phy_hang_count > 1) {
       
  4999 		adapter->phy_hang_count = 0;
       
  5000 		e_dbg("PHY appears hung - resetting\n");
       
  5001 		schedule_work(&adapter->reset_task);
       
  5002 	}
       
  5003 }
       
  5004 
       
  5005 /**
       
  5006  * e1000_watchdog - Timer Call-back
       
  5007  * @data: pointer to adapter cast into an unsigned long
       
  5008  **/
       
  5009 static void e1000_watchdog(unsigned long data)
       
  5010 {
       
  5011 	struct e1000_adapter *adapter = (struct e1000_adapter *)data;
       
  5012 
       
  5013 	/* Do the rest outside of interrupt context */
       
  5014 	schedule_work(&adapter->watchdog_task);
       
  5015 
       
  5016 	/* TODO: make this use queue_delayed_work() */
       
  5017 }
       
  5018 
       
  5019 static void e1000_watchdog_task(struct work_struct *work)
       
  5020 {
       
  5021 	struct e1000_adapter *adapter = container_of(work,
       
  5022 						     struct e1000_adapter,
       
  5023 						     watchdog_task);
       
  5024 	struct net_device *netdev = adapter->netdev;
       
  5025 	struct e1000_mac_info *mac = &adapter->hw.mac;
       
  5026 	struct e1000_phy_info *phy = &adapter->hw.phy;
       
  5027 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  5028 	struct e1000_hw *hw = &adapter->hw;
       
  5029 	u32 link, tctl;
       
  5030 
       
  5031 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  5032 		return;
       
  5033 
       
  5034 	link = e1000e_has_link(adapter);
       
  5035 	if ((adapter->ecdev && (ecdev_get_link(adapter->ecdev)) && link)
       
  5036 			|| (!adapter->ecdev && (netif_carrier_ok(netdev)) && link)) {
       
  5037 		if (!adapter->ecdev) {
       
  5038 			/* Cancel scheduled suspend requests. */
       
  5039 			pm_runtime_resume(netdev->dev.parent);
       
  5040 		}
       
  5041 
       
  5042 		e1000e_enable_receives(adapter);
       
  5043 		goto link_up;
       
  5044 	}
       
  5045 
       
  5046 	if ((e1000e_enable_tx_pkt_filtering(hw)) &&
       
  5047 	    (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
       
  5048 		e1000_update_mng_vlan(adapter);
       
  5049 
       
  5050 	if (link) {
       
  5051 		if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev))
       
  5052 				|| (!adapter->ecdev && !netif_carrier_ok(netdev))) {
       
  5053 			bool txb2b = true;
       
  5054 
       
  5055 			/* Cancel scheduled suspend requests. */
       
  5056 			pm_runtime_resume(netdev->dev.parent);
       
  5057 
       
  5058 			/* update snapshot of PHY registers on LSC */
       
  5059 			e1000_phy_read_status(adapter);
       
  5060 			mac->ops.get_link_up_info(&adapter->hw,
       
  5061 						  &adapter->link_speed,
       
  5062 						  &adapter->link_duplex);
       
  5063 			e1000_print_link_info(adapter);
       
  5064 
       
  5065 			/* check if SmartSpeed worked */
       
  5066 			e1000e_check_downshift(hw);
       
  5067 			if (phy->speed_downgraded)
       
  5068 				netdev_warn(netdev,
       
  5069 					    "Link Speed was downgraded by SmartSpeed\n");
       
  5070 
       
  5071 			/* On supported PHYs, check for duplex mismatch only
       
  5072 			 * if link has autonegotiated at 10/100 half
       
  5073 			 */
       
  5074 			if ((hw->phy.type == e1000_phy_igp_3 ||
       
  5075 			     hw->phy.type == e1000_phy_bm) &&
       
  5076 			    hw->mac.autoneg &&
       
  5077 			    (adapter->link_speed == SPEED_10 ||
       
  5078 			     adapter->link_speed == SPEED_100) &&
       
  5079 			    (adapter->link_duplex == HALF_DUPLEX)) {
       
  5080 				u16 autoneg_exp;
       
  5081 
       
  5082 				e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
       
  5083 
       
  5084 				if (!(autoneg_exp & EXPANSION_NWAY))
       
  5085 					e_info("Autonegotiated half duplex but link partner cannot autoneg.  Try forcing full duplex if link gets many collisions.\n");
       
  5086 			}
       
  5087 
       
  5088 			/* adjust timeout factor according to speed/duplex */
       
  5089 			adapter->tx_timeout_factor = 1;
       
  5090 			switch (adapter->link_speed) {
       
  5091 			case SPEED_10:
       
  5092 				txb2b = false;
       
  5093 				adapter->tx_timeout_factor = 16;
       
  5094 				break;
       
  5095 			case SPEED_100:
       
  5096 				txb2b = false;
       
  5097 				adapter->tx_timeout_factor = 10;
       
  5098 				break;
       
  5099 			}
       
  5100 
       
  5101 			/* workaround: re-program speed mode bit after
       
  5102 			 * link-up event
       
  5103 			 */
       
  5104 			if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
       
  5105 			    !txb2b) {
       
  5106 				u32 tarc0;
       
  5107 
       
  5108 				tarc0 = er32(TARC(0));
       
  5109 				tarc0 &= ~SPEED_MODE_BIT;
       
  5110 				ew32(TARC(0), tarc0);
       
  5111 			}
       
  5112 
       
  5113 			/* disable TSO for pcie and 10/100 speeds, to avoid
       
  5114 			 * some hardware issues
       
  5115 			 */
       
  5116 			if (!(adapter->flags & FLAG_TSO_FORCE)) {
       
  5117 				switch (adapter->link_speed) {
       
  5118 				case SPEED_10:
       
  5119 				case SPEED_100:
       
  5120 					e_info("10/100 speed: disabling TSO\n");
       
  5121 					netdev->features &= ~NETIF_F_TSO;
       
  5122 					netdev->features &= ~NETIF_F_TSO6;
       
  5123 					break;
       
  5124 				case SPEED_1000:
       
  5125 					netdev->features |= NETIF_F_TSO;
       
  5126 					netdev->features |= NETIF_F_TSO6;
       
  5127 					break;
       
  5128 				default:
       
  5129 					/* oops */
       
  5130 					break;
       
  5131 				}
       
  5132 			}
       
  5133 
       
  5134 			/* enable transmits in the hardware, need to do this
       
  5135 			 * after setting TARC(0)
       
  5136 			 */
       
  5137 			tctl = er32(TCTL);
       
  5138 			tctl |= E1000_TCTL_EN;
       
  5139 			ew32(TCTL, tctl);
       
  5140 
       
  5141 			/* Perform any post-link-up configuration before
       
  5142 			 * reporting link up.
       
  5143 			 */
       
  5144 			if (phy->ops.cfg_on_link_up)
       
  5145 				phy->ops.cfg_on_link_up(hw);
       
  5146 
       
  5147 			if (adapter->ecdev)
       
  5148 				ecdev_set_link(adapter->ecdev, 1);
       
  5149 			else
       
  5150 				netif_carrier_on(netdev);
       
  5151 
       
  5152 			if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state))
       
  5153 				mod_timer(&adapter->phy_info_timer,
       
  5154 					  round_jiffies(jiffies + 2 * HZ));
       
  5155 		}
       
  5156 	} else {
       
  5157 		if ((adapter->ecdev && ecdev_get_link(adapter->ecdev))
       
  5158 				|| (!adapter->ecdev && netif_carrier_ok(netdev))) {
       
  5159 			adapter->link_speed = 0;
       
  5160 			adapter->link_duplex = 0;
       
  5161 			/* Link status message must follow this format */
       
  5162 			pr_info("%s NIC Link is Down\n", adapter->netdev->name);
       
  5163 			if (adapter->ecdev) {
       
  5164 				ecdev_set_link(adapter->ecdev, 0);
       
  5165 			}
       
  5166 			else {
       
  5167 				netif_carrier_off(netdev);
       
  5168 				if (!test_bit(__E1000_DOWN, &adapter->state))
       
  5169 					mod_timer(&adapter->phy_info_timer,
       
  5170 							round_jiffies(jiffies + 2 * HZ));
       
  5171 			}
       
  5172 
       
  5173 			/* 8000ES2LAN requires a Rx packet buffer work-around
       
  5174 			 * on link down event; reset the controller to flush
       
  5175 			 * the Rx packet buffer.
       
  5176 			 */
       
  5177 			if (adapter->flags & FLAG_RX_NEEDS_RESTART)
       
  5178 				adapter->flags |= FLAG_RESTART_NOW;
       
  5179 			else
       
  5180 				pm_schedule_suspend(netdev->dev.parent,
       
  5181 						    LINK_TIMEOUT);
       
  5182 		}
       
  5183 	}
       
  5184 
       
  5185 link_up:
       
  5186 	spin_lock(&adapter->stats64_lock);
       
  5187 	e1000e_update_stats(adapter);
       
  5188 
       
  5189 	mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
       
  5190 	adapter->tpt_old = adapter->stats.tpt;
       
  5191 	mac->collision_delta = adapter->stats.colc - adapter->colc_old;
       
  5192 	adapter->colc_old = adapter->stats.colc;
       
  5193 
       
  5194 	adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
       
  5195 	adapter->gorc_old = adapter->stats.gorc;
       
  5196 	adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
       
  5197 	adapter->gotc_old = adapter->stats.gotc;
       
  5198 	spin_unlock(&adapter->stats64_lock);
       
  5199 
       
  5200 	/* If the link is lost the controller stops DMA, but
       
  5201 	 * if there is queued Tx work it cannot be done.  So
       
  5202 	 * reset the controller to flush the Tx packet buffers.
       
  5203 	 */
       
  5204 	if (!netif_carrier_ok(netdev) &&
       
  5205 	    (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
       
  5206 		adapter->flags |= FLAG_RESTART_NOW;
       
  5207 
       
  5208 	/* If reset is necessary, do it outside of interrupt context. */
       
  5209 	if (adapter->flags & FLAG_RESTART_NOW) {
       
  5210 		schedule_work(&adapter->reset_task);
       
  5211 		/* return immediately since reset is imminent */
       
  5212 		return;
       
  5213 	}
       
  5214 
       
  5215 	e1000e_update_adaptive(&adapter->hw);
       
  5216 
       
  5217 	/* Simple mode for Interrupt Throttle Rate (ITR) */
       
  5218 	if (adapter->itr_setting == 4) {
       
  5219 		/* Symmetric Tx/Rx gets a reduced ITR=2000;
       
  5220 		 * Total asymmetrical Tx or Rx gets ITR=8000;
       
  5221 		 * everyone else is between 2000-8000.
       
  5222 		 */
       
  5223 		u32 goc = (adapter->gotc + adapter->gorc) / 10000;
       
  5224 		u32 dif = (adapter->gotc > adapter->gorc ?
       
  5225 			   adapter->gotc - adapter->gorc :
       
  5226 			   adapter->gorc - adapter->gotc) / 10000;
       
  5227 		u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
       
  5228 
       
  5229 		e1000e_write_itr(adapter, itr);
       
  5230 	}
       
  5231 
       
  5232 	/* Cause software interrupt to ensure Rx ring is cleaned */
       
  5233 	if (adapter->msix_entries)
       
  5234 		ew32(ICS, adapter->rx_ring->ims_val);
       
  5235 	else
       
  5236 		ew32(ICS, E1000_ICS_RXDMT0);
       
  5237 
       
  5238 	/* flush pending descriptors to memory before detecting Tx hang */
       
  5239 	e1000e_flush_descriptors(adapter);
       
  5240 
       
  5241 	/* Force detection of hung controller every watchdog period */
       
  5242 	adapter->detect_tx_hung = true;
       
  5243 
       
  5244 	/* With 82571 controllers, LAA may be overwritten due to controller
       
  5245 	 * reset from the other port. Set the appropriate LAA in RAR[0]
       
  5246 	 */
       
  5247 	if (e1000e_get_laa_state_82571(hw))
       
  5248 		hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
       
  5249 
       
  5250 	if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
       
  5251 		e1000e_check_82574_phy_workaround(adapter);
       
  5252 
       
  5253 	/* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
       
  5254 	if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
       
  5255 		if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
       
  5256 		    (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
       
  5257 			er32(RXSTMPH);
       
  5258 			adapter->rx_hwtstamp_cleared++;
       
  5259 		} else {
       
  5260 			adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
       
  5261 		}
       
  5262 	}
       
  5263 
       
  5264 	/* Reset the timer */
       
  5265 	if (!adapter->ecdev && !test_bit(__E1000_DOWN, &adapter->state))
       
  5266 		mod_timer(&adapter->watchdog_timer,
       
  5267 			  round_jiffies(jiffies + 2 * HZ));
       
  5268 }
       
  5269 
       
  5270 #define E1000_TX_FLAGS_CSUM		0x00000001
       
  5271 #define E1000_TX_FLAGS_VLAN		0x00000002
       
  5272 #define E1000_TX_FLAGS_TSO		0x00000004
       
  5273 #define E1000_TX_FLAGS_IPV4		0x00000008
       
  5274 #define E1000_TX_FLAGS_NO_FCS		0x00000010
       
  5275 #define E1000_TX_FLAGS_HWTSTAMP		0x00000020
       
  5276 #define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
       
  5277 #define E1000_TX_FLAGS_VLAN_SHIFT	16
       
  5278 
       
  5279 static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb)
       
  5280 {
       
  5281 	struct e1000_context_desc *context_desc;
       
  5282 	struct e1000_buffer *buffer_info;
       
  5283 	unsigned int i;
       
  5284 	u32 cmd_length = 0;
       
  5285 	u16 ipcse = 0, mss;
       
  5286 	u8 ipcss, ipcso, tucss, tucso, hdr_len;
       
  5287 	int err;
       
  5288 
       
  5289 	if (!skb_is_gso(skb))
       
  5290 		return 0;
       
  5291 
       
  5292 	err = skb_cow_head(skb, 0);
       
  5293 	if (err < 0)
       
  5294 		return err;
       
  5295 
       
  5296 	hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
       
  5297 	mss = skb_shinfo(skb)->gso_size;
       
  5298 	if (skb->protocol == htons(ETH_P_IP)) {
       
  5299 		struct iphdr *iph = ip_hdr(skb);
       
  5300 		iph->tot_len = 0;
       
  5301 		iph->check = 0;
       
  5302 		tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
       
  5303 							 0, IPPROTO_TCP, 0);
       
  5304 		cmd_length = E1000_TXD_CMD_IP;
       
  5305 		ipcse = skb_transport_offset(skb) - 1;
       
  5306 	} else if (skb_is_gso_v6(skb)) {
       
  5307 		ipv6_hdr(skb)->payload_len = 0;
       
  5308 		tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
       
  5309 						       &ipv6_hdr(skb)->daddr,
       
  5310 						       0, IPPROTO_TCP, 0);
       
  5311 		ipcse = 0;
       
  5312 	}
       
  5313 	ipcss = skb_network_offset(skb);
       
  5314 	ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
       
  5315 	tucss = skb_transport_offset(skb);
       
  5316 	tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
       
  5317 
       
  5318 	cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
       
  5319 		       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
       
  5320 
       
  5321 	i = tx_ring->next_to_use;
       
  5322 	context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
       
  5323 	buffer_info = &tx_ring->buffer_info[i];
       
  5324 
       
  5325 	context_desc->lower_setup.ip_fields.ipcss = ipcss;
       
  5326 	context_desc->lower_setup.ip_fields.ipcso = ipcso;
       
  5327 	context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
       
  5328 	context_desc->upper_setup.tcp_fields.tucss = tucss;
       
  5329 	context_desc->upper_setup.tcp_fields.tucso = tucso;
       
  5330 	context_desc->upper_setup.tcp_fields.tucse = 0;
       
  5331 	context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
       
  5332 	context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
       
  5333 	context_desc->cmd_and_length = cpu_to_le32(cmd_length);
       
  5334 
       
  5335 	buffer_info->time_stamp = jiffies;
       
  5336 	buffer_info->next_to_watch = i;
       
  5337 
       
  5338 	i++;
       
  5339 	if (i == tx_ring->count)
       
  5340 		i = 0;
       
  5341 	tx_ring->next_to_use = i;
       
  5342 
       
  5343 	return 1;
       
  5344 }
       
  5345 
       
  5346 static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb)
       
  5347 {
       
  5348 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  5349 	struct e1000_context_desc *context_desc;
       
  5350 	struct e1000_buffer *buffer_info;
       
  5351 	unsigned int i;
       
  5352 	u8 css;
       
  5353 	u32 cmd_len = E1000_TXD_CMD_DEXT;
       
  5354 	__be16 protocol;
       
  5355 
       
  5356 	if (skb->ip_summed != CHECKSUM_PARTIAL)
       
  5357 		return false;
       
  5358 
       
  5359 	if (skb->protocol == cpu_to_be16(ETH_P_8021Q))
       
  5360 		protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
       
  5361 	else
       
  5362 		protocol = skb->protocol;
       
  5363 
       
  5364 	switch (protocol) {
       
  5365 	case cpu_to_be16(ETH_P_IP):
       
  5366 		if (ip_hdr(skb)->protocol == IPPROTO_TCP)
       
  5367 			cmd_len |= E1000_TXD_CMD_TCP;
       
  5368 		break;
       
  5369 	case cpu_to_be16(ETH_P_IPV6):
       
  5370 		/* XXX not handling all IPV6 headers */
       
  5371 		if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
       
  5372 			cmd_len |= E1000_TXD_CMD_TCP;
       
  5373 		break;
       
  5374 	default:
       
  5375 		if (unlikely(net_ratelimit()))
       
  5376 			e_warn("checksum_partial proto=%x!\n",
       
  5377 			       be16_to_cpu(protocol));
       
  5378 		break;
       
  5379 	}
       
  5380 
       
  5381 	css = skb_checksum_start_offset(skb);
       
  5382 
       
  5383 	i = tx_ring->next_to_use;
       
  5384 	buffer_info = &tx_ring->buffer_info[i];
       
  5385 	context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
       
  5386 
       
  5387 	context_desc->lower_setup.ip_config = 0;
       
  5388 	context_desc->upper_setup.tcp_fields.tucss = css;
       
  5389 	context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
       
  5390 	context_desc->upper_setup.tcp_fields.tucse = 0;
       
  5391 	context_desc->tcp_seg_setup.data = 0;
       
  5392 	context_desc->cmd_and_length = cpu_to_le32(cmd_len);
       
  5393 
       
  5394 	buffer_info->time_stamp = jiffies;
       
  5395 	buffer_info->next_to_watch = i;
       
  5396 
       
  5397 	i++;
       
  5398 	if (i == tx_ring->count)
       
  5399 		i = 0;
       
  5400 	tx_ring->next_to_use = i;
       
  5401 
       
  5402 	return true;
       
  5403 }
       
  5404 
       
  5405 static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
       
  5406 			unsigned int first, unsigned int max_per_txd,
       
  5407 			unsigned int nr_frags)
       
  5408 {
       
  5409 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  5410 	struct pci_dev *pdev = adapter->pdev;
       
  5411 	struct e1000_buffer *buffer_info;
       
  5412 	unsigned int len = skb_headlen(skb);
       
  5413 	unsigned int offset = 0, size, count = 0, i;
       
  5414 	unsigned int f, bytecount, segs;
       
  5415 
       
  5416 	i = tx_ring->next_to_use;
       
  5417 
       
  5418 	while (len) {
       
  5419 		buffer_info = &tx_ring->buffer_info[i];
       
  5420 		size = min(len, max_per_txd);
       
  5421 
       
  5422 		buffer_info->length = size;
       
  5423 		buffer_info->time_stamp = jiffies;
       
  5424 		buffer_info->next_to_watch = i;
       
  5425 		buffer_info->dma = dma_map_single(&pdev->dev,
       
  5426 						  skb->data + offset,
       
  5427 						  size, DMA_TO_DEVICE);
       
  5428 		buffer_info->mapped_as_page = false;
       
  5429 		if (dma_mapping_error(&pdev->dev, buffer_info->dma))
       
  5430 			goto dma_error;
       
  5431 
       
  5432 		len -= size;
       
  5433 		offset += size;
       
  5434 		count++;
       
  5435 
       
  5436 		if (len) {
       
  5437 			i++;
       
  5438 			if (i == tx_ring->count)
       
  5439 				i = 0;
       
  5440 		}
       
  5441 	}
       
  5442 
       
  5443 	for (f = 0; f < nr_frags; f++) {
       
  5444 		const struct skb_frag_struct *frag;
       
  5445 
       
  5446 		frag = &skb_shinfo(skb)->frags[f];
       
  5447 		len = skb_frag_size(frag);
       
  5448 		offset = 0;
       
  5449 
       
  5450 		while (len) {
       
  5451 			i++;
       
  5452 			if (i == tx_ring->count)
       
  5453 				i = 0;
       
  5454 
       
  5455 			buffer_info = &tx_ring->buffer_info[i];
       
  5456 			size = min(len, max_per_txd);
       
  5457 
       
  5458 			buffer_info->length = size;
       
  5459 			buffer_info->time_stamp = jiffies;
       
  5460 			buffer_info->next_to_watch = i;
       
  5461 			buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
       
  5462 							    offset, size,
       
  5463 							    DMA_TO_DEVICE);
       
  5464 			buffer_info->mapped_as_page = true;
       
  5465 			if (dma_mapping_error(&pdev->dev, buffer_info->dma))
       
  5466 				goto dma_error;
       
  5467 
       
  5468 			len -= size;
       
  5469 			offset += size;
       
  5470 			count++;
       
  5471 		}
       
  5472 	}
       
  5473 
       
  5474 	segs = skb_shinfo(skb)->gso_segs ? : 1;
       
  5475 	/* multiply data chunks by size of headers */
       
  5476 	bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
       
  5477 
       
  5478 	tx_ring->buffer_info[i].skb = skb;
       
  5479 	tx_ring->buffer_info[i].segs = segs;
       
  5480 	tx_ring->buffer_info[i].bytecount = bytecount;
       
  5481 	tx_ring->buffer_info[first].next_to_watch = i;
       
  5482 
       
  5483 	return count;
       
  5484 
       
  5485 dma_error:
       
  5486 	dev_err(&pdev->dev, "Tx DMA map failed\n");
       
  5487 	buffer_info->dma = 0;
       
  5488 	if (count)
       
  5489 		count--;
       
  5490 
       
  5491 	while (count--) {
       
  5492 		if (i == 0)
       
  5493 			i += tx_ring->count;
       
  5494 		i--;
       
  5495 		buffer_info = &tx_ring->buffer_info[i];
       
  5496 		e1000_put_txbuf(tx_ring, buffer_info);
       
  5497 	}
       
  5498 
       
  5499 	return 0;
       
  5500 }
       
  5501 
       
  5502 static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
       
  5503 {
       
  5504 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  5505 	struct e1000_tx_desc *tx_desc = NULL;
       
  5506 	struct e1000_buffer *buffer_info;
       
  5507 	u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
       
  5508 	unsigned int i;
       
  5509 
       
  5510 	if (tx_flags & E1000_TX_FLAGS_TSO) {
       
  5511 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
       
  5512 		    E1000_TXD_CMD_TSE;
       
  5513 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
       
  5514 
       
  5515 		if (tx_flags & E1000_TX_FLAGS_IPV4)
       
  5516 			txd_upper |= E1000_TXD_POPTS_IXSM << 8;
       
  5517 	}
       
  5518 
       
  5519 	if (tx_flags & E1000_TX_FLAGS_CSUM) {
       
  5520 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
       
  5521 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
       
  5522 	}
       
  5523 
       
  5524 	if (tx_flags & E1000_TX_FLAGS_VLAN) {
       
  5525 		txd_lower |= E1000_TXD_CMD_VLE;
       
  5526 		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
       
  5527 	}
       
  5528 
       
  5529 	if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
       
  5530 		txd_lower &= ~(E1000_TXD_CMD_IFCS);
       
  5531 
       
  5532 	if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
       
  5533 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
       
  5534 		txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
       
  5535 	}
       
  5536 
       
  5537 	i = tx_ring->next_to_use;
       
  5538 
       
  5539 	do {
       
  5540 		buffer_info = &tx_ring->buffer_info[i];
       
  5541 		tx_desc = E1000_TX_DESC(*tx_ring, i);
       
  5542 		tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
       
  5543 		tx_desc->lower.data = cpu_to_le32(txd_lower |
       
  5544 						  buffer_info->length);
       
  5545 		tx_desc->upper.data = cpu_to_le32(txd_upper);
       
  5546 
       
  5547 		i++;
       
  5548 		if (i == tx_ring->count)
       
  5549 			i = 0;
       
  5550 	} while (--count > 0);
       
  5551 
       
  5552 	tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
       
  5553 
       
  5554 	/* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
       
  5555 	if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
       
  5556 		tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
       
  5557 
       
  5558 	/* Force memory writes to complete before letting h/w
       
  5559 	 * know there are new descriptors to fetch.  (Only
       
  5560 	 * applicable for weak-ordered memory model archs,
       
  5561 	 * such as IA-64).
       
  5562 	 */
       
  5563 	wmb();
       
  5564 
       
  5565 	tx_ring->next_to_use = i;
       
  5566 
       
  5567 	if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
       
  5568 		e1000e_update_tdt_wa(tx_ring, i);
       
  5569 	else
       
  5570 		writel(i, tx_ring->tail);
       
  5571 
       
  5572 	/* we need this if more than one processor can write to our tail
       
  5573 	 * at a time, it synchronizes IO on IA64/Altix systems
       
  5574 	 */
       
  5575 	mmiowb();
       
  5576 }
       
  5577 
       
  5578 #define MINIMUM_DHCP_PACKET_SIZE 282
       
  5579 static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
       
  5580 				    struct sk_buff *skb)
       
  5581 {
       
  5582 	struct e1000_hw *hw = &adapter->hw;
       
  5583 	u16 length, offset;
       
  5584 
       
  5585 	if (vlan_tx_tag_present(skb) &&
       
  5586 	    !((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
       
  5587 	      (adapter->hw.mng_cookie.status &
       
  5588 	       E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
       
  5589 		return 0;
       
  5590 
       
  5591 	if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
       
  5592 		return 0;
       
  5593 
       
  5594 	if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
       
  5595 		return 0;
       
  5596 
       
  5597 	{
       
  5598 		const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
       
  5599 		struct udphdr *udp;
       
  5600 
       
  5601 		if (ip->protocol != IPPROTO_UDP)
       
  5602 			return 0;
       
  5603 
       
  5604 		udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
       
  5605 		if (ntohs(udp->dest) != 67)
       
  5606 			return 0;
       
  5607 
       
  5608 		offset = (u8 *)udp + 8 - skb->data;
       
  5609 		length = skb->len - offset;
       
  5610 		return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
       
  5611 	}
       
  5612 
       
  5613 	return 0;
       
  5614 }
       
  5615 
       
  5616 static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
       
  5617 {
       
  5618 	struct e1000_adapter *adapter = tx_ring->adapter;
       
  5619 
       
  5620 	netif_stop_queue(adapter->netdev);
       
  5621 	/* Herbert's original patch had:
       
  5622 	 *  smp_mb__after_netif_stop_queue();
       
  5623 	 * but since that doesn't exist yet, just open code it.
       
  5624 	 */
       
  5625 	smp_mb();
       
  5626 
       
  5627 	/* We need to check again in a case another CPU has just
       
  5628 	 * made room available.
       
  5629 	 */
       
  5630 	if (e1000_desc_unused(tx_ring) < size)
       
  5631 		return -EBUSY;
       
  5632 
       
  5633 	/* A reprieve! */
       
  5634 	netif_start_queue(adapter->netdev);
       
  5635 	++adapter->restart_queue;
       
  5636 	return 0;
       
  5637 }
       
  5638 
       
  5639 static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
       
  5640 {
       
  5641 	BUG_ON(size > tx_ring->count);
       
  5642 
       
  5643 	if (e1000_desc_unused(tx_ring) >= size)
       
  5644 		return 0;
       
  5645 	return __e1000_maybe_stop_tx(tx_ring, size);
       
  5646 }
       
  5647 
       
  5648 static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
       
  5649 				    struct net_device *netdev)
       
  5650 {
       
  5651 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5652 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
  5653 	unsigned int first;
       
  5654 	unsigned int tx_flags = 0;
       
  5655 	unsigned int len = skb_headlen(skb);
       
  5656 	unsigned int nr_frags;
       
  5657 	unsigned int mss;
       
  5658 	int count = 0;
       
  5659 	int tso;
       
  5660 	unsigned int f;
       
  5661 
       
  5662 	if (test_bit(__E1000_DOWN, &adapter->state)) {
       
  5663 		if (!adapter->ecdev)
       
  5664 			dev_kfree_skb_any(skb);
       
  5665 		return NETDEV_TX_OK;
       
  5666 	}
       
  5667 
       
  5668 	if (skb->len <= 0) {
       
  5669 		if (!adapter->ecdev)
       
  5670 			dev_kfree_skb_any(skb);
       
  5671 		return NETDEV_TX_OK;
       
  5672 	}
       
  5673 
       
  5674 	/* The minimum packet size with TCTL.PSP set is 17 bytes so
       
  5675 	 * pad skb in order to meet this minimum size requirement
       
  5676 	 */
       
  5677 	if (unlikely(skb->len < 17)) {
       
  5678 		if (skb_pad(skb, 17 - skb->len))
       
  5679 			return NETDEV_TX_OK;
       
  5680 		skb->len = 17;
       
  5681 		skb_set_tail_pointer(skb, 17);
       
  5682 	}
       
  5683 
       
  5684 	mss = skb_shinfo(skb)->gso_size;
       
  5685 	if (mss) {
       
  5686 		u8 hdr_len;
       
  5687 
       
  5688 		/* TSO Workaround for 82571/2/3 Controllers -- if skb->data
       
  5689 		 * points to just header, pull a few bytes of payload from
       
  5690 		 * frags into skb->data
       
  5691 		 */
       
  5692 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
       
  5693 		/* we do this workaround for ES2LAN, but it is un-necessary,
       
  5694 		 * avoiding it could save a lot of cycles
       
  5695 		 */
       
  5696 		if (skb->data_len && (hdr_len == len)) {
       
  5697 			unsigned int pull_size;
       
  5698 
       
  5699 			pull_size = min_t(unsigned int, 4, skb->data_len);
       
  5700 			if (!__pskb_pull_tail(skb, pull_size)) {
       
  5701 				e_err("__pskb_pull_tail failed.\n");
       
  5702 				if (!adapter->ecdev)
       
  5703 					dev_kfree_skb_any(skb);
       
  5704 				return NETDEV_TX_OK;
       
  5705 			}
       
  5706 			len = skb_headlen(skb);
       
  5707 		}
       
  5708 	}
       
  5709 
       
  5710 	/* reserve a descriptor for the offload context */
       
  5711 	if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
       
  5712 		count++;
       
  5713 	count++;
       
  5714 
       
  5715 	count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
       
  5716 
       
  5717 	nr_frags = skb_shinfo(skb)->nr_frags;
       
  5718 	for (f = 0; f < nr_frags; f++)
       
  5719 		count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
       
  5720 				      adapter->tx_fifo_limit);
       
  5721 
       
  5722 	if (adapter->hw.mac.tx_pkt_filtering)
       
  5723 		e1000_transfer_dhcp_info(adapter, skb);
       
  5724 
       
  5725 	/* need: count + 2 desc gap to keep tail from touching
       
  5726 	 * head, otherwise try next time
       
  5727 	 */
       
  5728 	if (!adapter->ecdev && e1000_maybe_stop_tx(tx_ring, count + 2))
       
  5729 		return NETDEV_TX_BUSY;
       
  5730 
       
  5731 	if (vlan_tx_tag_present(skb)) {
       
  5732 		tx_flags |= E1000_TX_FLAGS_VLAN;
       
  5733 		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
       
  5734 	}
       
  5735 
       
  5736 	first = tx_ring->next_to_use;
       
  5737 
       
  5738 	tso = e1000_tso(tx_ring, skb);
       
  5739 	if (tso < 0) {
       
  5740 		if (!adapter->ecdev)
       
  5741 			dev_kfree_skb_any(skb);
       
  5742 		return NETDEV_TX_OK;
       
  5743 	}
       
  5744 
       
  5745 	if (tso)
       
  5746 		tx_flags |= E1000_TX_FLAGS_TSO;
       
  5747 	else if (e1000_tx_csum(tx_ring, skb))
       
  5748 		tx_flags |= E1000_TX_FLAGS_CSUM;
       
  5749 
       
  5750 	/* Old method was to assume IPv4 packet by default if TSO was enabled.
       
  5751 	 * 82571 hardware supports TSO capabilities for IPv6 as well...
       
  5752 	 * no longer assume, we must.
       
  5753 	 */
       
  5754 	if (skb->protocol == htons(ETH_P_IP))
       
  5755 		tx_flags |= E1000_TX_FLAGS_IPV4;
       
  5756 
       
  5757 	if (unlikely(skb->no_fcs))
       
  5758 		tx_flags |= E1000_TX_FLAGS_NO_FCS;
       
  5759 
       
  5760 	/* if count is 0 then mapping error has occurred */
       
  5761 	count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
       
  5762 			     nr_frags);
       
  5763 	if (count) {
       
  5764 		if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
       
  5765 			     !adapter->tx_hwtstamp_skb)) {
       
  5766 			skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
       
  5767 			tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
       
  5768 			adapter->tx_hwtstamp_skb = skb_get(skb);
       
  5769 			adapter->tx_hwtstamp_start = jiffies;
       
  5770 			schedule_work(&adapter->tx_hwtstamp_work);
       
  5771 		} else {
       
  5772 			skb_tx_timestamp(skb);
       
  5773 		}
       
  5774 
       
  5775 		netdev_sent_queue(netdev, skb->len);
       
  5776 		e1000_tx_queue(tx_ring, tx_flags, count);
       
  5777 		/* Make sure there is space in the ring for the next send. */
       
  5778 		if (!adapter->ecdev) {
       
  5779 			e1000_maybe_stop_tx(tx_ring,
       
  5780 					(MAX_SKB_FRAGS *
       
  5781 					 DIV_ROUND_UP(PAGE_SIZE,
       
  5782 						 adapter->tx_fifo_limit) + 2));
       
  5783 		}
       
  5784 	} else {
       
  5785 		if (!adapter->ecdev) {
       
  5786 			dev_kfree_skb_any(skb);
       
  5787 		}
       
  5788 		tx_ring->buffer_info[first].time_stamp = 0;
       
  5789 		tx_ring->next_to_use = first;
       
  5790 	}
       
  5791 
       
  5792 	return NETDEV_TX_OK;
       
  5793 }
       
  5794 
       
  5795 /**
       
  5796  * e1000_tx_timeout - Respond to a Tx Hang
       
  5797  * @netdev: network interface device structure
       
  5798  **/
       
  5799 static void e1000_tx_timeout(struct net_device *netdev)
       
  5800 {
       
  5801 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5802 
       
  5803 	/* Do the reset outside of interrupt context */
       
  5804 	adapter->tx_timeout_count++;
       
  5805 	schedule_work(&adapter->reset_task);
       
  5806 }
       
  5807 
       
  5808 static void e1000_reset_task(struct work_struct *work)
       
  5809 {
       
  5810 	struct e1000_adapter *adapter;
       
  5811 	adapter = container_of(work, struct e1000_adapter, reset_task);
       
  5812 
       
  5813 	/* don't run the task if already down */
       
  5814 	if (test_bit(__E1000_DOWN, &adapter->state))
       
  5815 		return;
       
  5816 
       
  5817 	if (!(adapter->flags & FLAG_RESTART_NOW)) {
       
  5818 		e1000e_dump(adapter);
       
  5819 		e_err("Reset adapter unexpectedly\n");
       
  5820 	}
       
  5821 	e1000e_reinit_locked(adapter);
       
  5822 }
       
  5823 
       
  5824 /**
       
  5825  * e1000_get_stats64 - Get System Network Statistics
       
  5826  * @netdev: network interface device structure
       
  5827  * @stats: rtnl_link_stats64 pointer
       
  5828  *
       
  5829  * Returns the address of the device statistics structure.
       
  5830  **/
       
  5831 struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev,
       
  5832 					     struct rtnl_link_stats64 *stats)
       
  5833 {
       
  5834 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5835 
       
  5836 	memset(stats, 0, sizeof(struct rtnl_link_stats64));
       
  5837 	spin_lock(&adapter->stats64_lock);
       
  5838 	e1000e_update_stats(adapter);
       
  5839 	/* Fill out the OS statistics structure */
       
  5840 	stats->rx_bytes = adapter->stats.gorc;
       
  5841 	stats->rx_packets = adapter->stats.gprc;
       
  5842 	stats->tx_bytes = adapter->stats.gotc;
       
  5843 	stats->tx_packets = adapter->stats.gptc;
       
  5844 	stats->multicast = adapter->stats.mprc;
       
  5845 	stats->collisions = adapter->stats.colc;
       
  5846 
       
  5847 	/* Rx Errors */
       
  5848 
       
  5849 	/* RLEC on some newer hardware can be incorrect so build
       
  5850 	 * our own version based on RUC and ROC
       
  5851 	 */
       
  5852 	stats->rx_errors = adapter->stats.rxerrc +
       
  5853 	    adapter->stats.crcerrs + adapter->stats.algnerrc +
       
  5854 	    adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
       
  5855 	stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
       
  5856 	stats->rx_crc_errors = adapter->stats.crcerrs;
       
  5857 	stats->rx_frame_errors = adapter->stats.algnerrc;
       
  5858 	stats->rx_missed_errors = adapter->stats.mpc;
       
  5859 
       
  5860 	/* Tx Errors */
       
  5861 	stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
       
  5862 	stats->tx_aborted_errors = adapter->stats.ecol;
       
  5863 	stats->tx_window_errors = adapter->stats.latecol;
       
  5864 	stats->tx_carrier_errors = adapter->stats.tncrs;
       
  5865 
       
  5866 	/* Tx Dropped needs to be maintained elsewhere */
       
  5867 
       
  5868 	spin_unlock(&adapter->stats64_lock);
       
  5869 	return stats;
       
  5870 }
       
  5871 
       
  5872 /**
       
  5873  * e1000_change_mtu - Change the Maximum Transfer Unit
       
  5874  * @netdev: network interface device structure
       
  5875  * @new_mtu: new value for maximum frame size
       
  5876  *
       
  5877  * Returns 0 on success, negative on failure
       
  5878  **/
       
  5879 static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
       
  5880 {
       
  5881 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5882 	int max_frame = new_mtu + VLAN_HLEN + ETH_HLEN + ETH_FCS_LEN;
       
  5883 
       
  5884 	if (adapter->ecdev)
       
  5885 		return -EBUSY;
       
  5886 
       
  5887 	/* Jumbo frame support */
       
  5888 	if ((max_frame > ETH_FRAME_LEN + ETH_FCS_LEN) &&
       
  5889 	    !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
       
  5890 		e_err("Jumbo Frames not supported.\n");
       
  5891 		return -EINVAL;
       
  5892 	}
       
  5893 
       
  5894 	/* Supported frame sizes */
       
  5895 	if ((new_mtu < ETH_ZLEN + ETH_FCS_LEN + VLAN_HLEN) ||
       
  5896 	    (max_frame > adapter->max_hw_frame_size)) {
       
  5897 		e_err("Unsupported MTU setting\n");
       
  5898 		return -EINVAL;
       
  5899 	}
       
  5900 
       
  5901 	/* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
       
  5902 	if ((adapter->hw.mac.type >= e1000_pch2lan) &&
       
  5903 	    !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
       
  5904 	    (new_mtu > ETH_DATA_LEN)) {
       
  5905 		e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
       
  5906 		return -EINVAL;
       
  5907 	}
       
  5908 
       
  5909 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
       
  5910 		usleep_range(1000, 2000);
       
  5911 	/* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
       
  5912 	adapter->max_frame_size = max_frame;
       
  5913 	e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
       
  5914 	netdev->mtu = new_mtu;
       
  5915 
       
  5916 	pm_runtime_get_sync(netdev->dev.parent);
       
  5917 
       
  5918 	if (netif_running(netdev))
       
  5919 		e1000e_down(adapter, true);
       
  5920 
       
  5921 	/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
       
  5922 	 * means we reserve 2 more, this pushes us to allocate from the next
       
  5923 	 * larger slab size.
       
  5924 	 * i.e. RXBUFFER_2048 --> size-4096 slab
       
  5925 	 * However with the new *_jumbo_rx* routines, jumbo receives will use
       
  5926 	 * fragmented skbs
       
  5927 	 */
       
  5928 
       
  5929 	if (max_frame <= 2048)
       
  5930 		adapter->rx_buffer_len = 2048;
       
  5931 	else
       
  5932 		adapter->rx_buffer_len = 4096;
       
  5933 
       
  5934 	/* adjust allocation if LPE protects us, and we aren't using SBP */
       
  5935 	if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
       
  5936 	    (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
       
  5937 		adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN
       
  5938 		    + ETH_FCS_LEN;
       
  5939 
       
  5940 	if (netif_running(netdev))
       
  5941 		e1000e_up(adapter);
       
  5942 	else
       
  5943 		e1000e_reset(adapter);
       
  5944 
       
  5945 	pm_runtime_put_sync(netdev->dev.parent);
       
  5946 
       
  5947 	clear_bit(__E1000_RESETTING, &adapter->state);
       
  5948 
       
  5949 	return 0;
       
  5950 }
       
  5951 
       
  5952 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
       
  5953 			   int cmd)
       
  5954 {
       
  5955 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5956 	struct mii_ioctl_data *data = if_mii(ifr);
       
  5957 
       
  5958 	if (adapter->hw.phy.media_type != e1000_media_type_copper)
       
  5959 		return -EOPNOTSUPP;
       
  5960 
       
  5961 	switch (cmd) {
       
  5962 	case SIOCGMIIPHY:
       
  5963 		data->phy_id = adapter->hw.phy.addr;
       
  5964 		break;
       
  5965 	case SIOCGMIIREG:
       
  5966 		e1000_phy_read_status(adapter);
       
  5967 
       
  5968 		switch (data->reg_num & 0x1F) {
       
  5969 		case MII_BMCR:
       
  5970 			data->val_out = adapter->phy_regs.bmcr;
       
  5971 			break;
       
  5972 		case MII_BMSR:
       
  5973 			data->val_out = adapter->phy_regs.bmsr;
       
  5974 			break;
       
  5975 		case MII_PHYSID1:
       
  5976 			data->val_out = (adapter->hw.phy.id >> 16);
       
  5977 			break;
       
  5978 		case MII_PHYSID2:
       
  5979 			data->val_out = (adapter->hw.phy.id & 0xFFFF);
       
  5980 			break;
       
  5981 		case MII_ADVERTISE:
       
  5982 			data->val_out = adapter->phy_regs.advertise;
       
  5983 			break;
       
  5984 		case MII_LPA:
       
  5985 			data->val_out = adapter->phy_regs.lpa;
       
  5986 			break;
       
  5987 		case MII_EXPANSION:
       
  5988 			data->val_out = adapter->phy_regs.expansion;
       
  5989 			break;
       
  5990 		case MII_CTRL1000:
       
  5991 			data->val_out = adapter->phy_regs.ctrl1000;
       
  5992 			break;
       
  5993 		case MII_STAT1000:
       
  5994 			data->val_out = adapter->phy_regs.stat1000;
       
  5995 			break;
       
  5996 		case MII_ESTATUS:
       
  5997 			data->val_out = adapter->phy_regs.estatus;
       
  5998 			break;
       
  5999 		default:
       
  6000 			return -EIO;
       
  6001 		}
       
  6002 		break;
       
  6003 	case SIOCSMIIREG:
       
  6004 	default:
       
  6005 		return -EOPNOTSUPP;
       
  6006 	}
       
  6007 	return 0;
       
  6008 }
       
  6009 
       
  6010 /**
       
  6011  * e1000e_hwtstamp_ioctl - control hardware time stamping
       
  6012  * @netdev: network interface device structure
       
  6013  * @ifreq: interface request
       
  6014  *
       
  6015  * Outgoing time stamping can be enabled and disabled. Play nice and
       
  6016  * disable it when requested, although it shouldn't cause any overhead
       
  6017  * when no packet needs it. At most one packet in the queue may be
       
  6018  * marked for time stamping, otherwise it would be impossible to tell
       
  6019  * for sure to which packet the hardware time stamp belongs.
       
  6020  *
       
  6021  * Incoming time stamping has to be configured via the hardware filters.
       
  6022  * Not all combinations are supported, in particular event type has to be
       
  6023  * specified. Matching the kind of event packet is not supported, with the
       
  6024  * exception of "all V2 events regardless of level 2 or 4".
       
  6025  **/
       
  6026 static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
       
  6027 {
       
  6028 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6029 	struct hwtstamp_config config;
       
  6030 	int ret_val;
       
  6031 
       
  6032 	if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
       
  6033 		return -EFAULT;
       
  6034 
       
  6035 	ret_val = e1000e_config_hwtstamp(adapter, &config);
       
  6036 	if (ret_val)
       
  6037 		return ret_val;
       
  6038 
       
  6039 	switch (config.rx_filter) {
       
  6040 	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
       
  6041 	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
       
  6042 	case HWTSTAMP_FILTER_PTP_V2_SYNC:
       
  6043 	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
       
  6044 	case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
       
  6045 	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
       
  6046 		/* With V2 type filters which specify a Sync or Delay Request,
       
  6047 		 * Path Delay Request/Response messages are also time stamped
       
  6048 		 * by hardware so notify the caller the requested packets plus
       
  6049 		 * some others are time stamped.
       
  6050 		 */
       
  6051 		config.rx_filter = HWTSTAMP_FILTER_SOME;
       
  6052 		break;
       
  6053 	default:
       
  6054 		break;
       
  6055 	}
       
  6056 
       
  6057 	return copy_to_user(ifr->ifr_data, &config,
       
  6058 			    sizeof(config)) ? -EFAULT : 0;
       
  6059 }
       
  6060 
       
  6061 static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
       
  6062 {
       
  6063 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6064 
       
  6065 	return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
       
  6066 			    sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
       
  6067 }
       
  6068 
       
  6069 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
       
  6070 {
       
  6071 	switch (cmd) {
       
  6072 	case SIOCGMIIPHY:
       
  6073 	case SIOCGMIIREG:
       
  6074 	case SIOCSMIIREG:
       
  6075 		return e1000_mii_ioctl(netdev, ifr, cmd);
       
  6076 	case SIOCSHWTSTAMP:
       
  6077 		return e1000e_hwtstamp_set(netdev, ifr);
       
  6078 	case SIOCGHWTSTAMP:
       
  6079 		return e1000e_hwtstamp_get(netdev, ifr);
       
  6080 	default:
       
  6081 		return -EOPNOTSUPP;
       
  6082 	}
       
  6083 }
       
  6084 
       
  6085 static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
       
  6086 {
       
  6087 	struct e1000_hw *hw = &adapter->hw;
       
  6088 	u32 i, mac_reg, wuc;
       
  6089 	u16 phy_reg, wuc_enable;
       
  6090 	int retval;
       
  6091 
       
  6092 	/* copy MAC RARs to PHY RARs */
       
  6093 	e1000_copy_rx_addrs_to_phy_ich8lan(hw);
       
  6094 
       
  6095 	retval = hw->phy.ops.acquire(hw);
       
  6096 	if (retval) {
       
  6097 		e_err("Could not acquire PHY\n");
       
  6098 		return retval;
       
  6099 	}
       
  6100 
       
  6101 	/* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
       
  6102 	retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
       
  6103 	if (retval)
       
  6104 		goto release;
       
  6105 
       
  6106 	/* copy MAC MTA to PHY MTA - only needed for pchlan */
       
  6107 	for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
       
  6108 		mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
       
  6109 		hw->phy.ops.write_reg_page(hw, BM_MTA(i),
       
  6110 					   (u16)(mac_reg & 0xFFFF));
       
  6111 		hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
       
  6112 					   (u16)((mac_reg >> 16) & 0xFFFF));
       
  6113 	}
       
  6114 
       
  6115 	/* configure PHY Rx Control register */
       
  6116 	hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
       
  6117 	mac_reg = er32(RCTL);
       
  6118 	if (mac_reg & E1000_RCTL_UPE)
       
  6119 		phy_reg |= BM_RCTL_UPE;
       
  6120 	if (mac_reg & E1000_RCTL_MPE)
       
  6121 		phy_reg |= BM_RCTL_MPE;
       
  6122 	phy_reg &= ~(BM_RCTL_MO_MASK);
       
  6123 	if (mac_reg & E1000_RCTL_MO_3)
       
  6124 		phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
       
  6125 			    << BM_RCTL_MO_SHIFT);
       
  6126 	if (mac_reg & E1000_RCTL_BAM)
       
  6127 		phy_reg |= BM_RCTL_BAM;
       
  6128 	if (mac_reg & E1000_RCTL_PMCF)
       
  6129 		phy_reg |= BM_RCTL_PMCF;
       
  6130 	mac_reg = er32(CTRL);
       
  6131 	if (mac_reg & E1000_CTRL_RFCE)
       
  6132 		phy_reg |= BM_RCTL_RFCE;
       
  6133 	hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
       
  6134 
       
  6135 	wuc = E1000_WUC_PME_EN;
       
  6136 	if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
       
  6137 		wuc |= E1000_WUC_APME;
       
  6138 
       
  6139 	/* enable PHY wakeup in MAC register */
       
  6140 	ew32(WUFC, wufc);
       
  6141 	ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
       
  6142 		   E1000_WUC_PME_STATUS | wuc));
       
  6143 
       
  6144 	/* configure and enable PHY wakeup in PHY registers */
       
  6145 	hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
       
  6146 	hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
       
  6147 
       
  6148 	/* activate PHY wakeup */
       
  6149 	wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
       
  6150 	retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
       
  6151 	if (retval)
       
  6152 		e_err("Could not set PHY Host Wakeup bit\n");
       
  6153 release:
       
  6154 	hw->phy.ops.release(hw);
       
  6155 
       
  6156 	return retval;
       
  6157 }
       
  6158 
       
  6159 static int e1000e_pm_freeze(struct device *dev)
       
  6160 {
       
  6161 	struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
       
  6162 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6163 
       
  6164 	netif_device_detach(netdev);
       
  6165 
       
  6166 	if (netif_running(netdev)) {
       
  6167 		int count = E1000_CHECK_RESET_COUNT;
       
  6168 
       
  6169 		while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
       
  6170 			usleep_range(10000, 20000);
       
  6171 
       
  6172 		WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
       
  6173 
       
  6174 		/* Quiesce the device without resetting the hardware */
       
  6175 		e1000e_down(adapter, false);
       
  6176 		e1000_free_irq(adapter);
       
  6177 	}
       
  6178 	e1000e_reset_interrupt_capability(adapter);
       
  6179 
       
  6180 	/* Allow time for pending master requests to run */
       
  6181 	e1000e_disable_pcie_master(&adapter->hw);
       
  6182 
       
  6183 	return 0;
       
  6184 }
       
  6185 
       
  6186 static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
       
  6187 {
       
  6188 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6189 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6190 	struct e1000_hw *hw = &adapter->hw;
       
  6191 	u32 ctrl, ctrl_ext, rctl, status;
       
  6192 	/* Runtime suspend should only enable wakeup for link changes */
       
  6193 	u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
       
  6194 	int retval = 0;
       
  6195 
       
  6196 	status = er32(STATUS);
       
  6197 	if (status & E1000_STATUS_LU)
       
  6198 		wufc &= ~E1000_WUFC_LNKC;
       
  6199 
       
  6200 	if (wufc) {
       
  6201 		e1000_setup_rctl(adapter);
       
  6202 		e1000e_set_rx_mode(netdev);
       
  6203 
       
  6204 		/* turn on all-multi mode if wake on multicast is enabled */
       
  6205 		if (wufc & E1000_WUFC_MC) {
       
  6206 			rctl = er32(RCTL);
       
  6207 			rctl |= E1000_RCTL_MPE;
       
  6208 			ew32(RCTL, rctl);
       
  6209 		}
       
  6210 
       
  6211 		ctrl = er32(CTRL);
       
  6212 		ctrl |= E1000_CTRL_ADVD3WUC;
       
  6213 		if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
       
  6214 			ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
       
  6215 		ew32(CTRL, ctrl);
       
  6216 
       
  6217 		if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
       
  6218 		    adapter->hw.phy.media_type ==
       
  6219 		    e1000_media_type_internal_serdes) {
       
  6220 			/* keep the laser running in D3 */
       
  6221 			ctrl_ext = er32(CTRL_EXT);
       
  6222 			ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
       
  6223 			ew32(CTRL_EXT, ctrl_ext);
       
  6224 		}
       
  6225 
       
  6226 		if (!runtime)
       
  6227 			e1000e_power_up_phy(adapter);
       
  6228 
       
  6229 		if (adapter->flags & FLAG_IS_ICH)
       
  6230 			e1000_suspend_workarounds_ich8lan(&adapter->hw);
       
  6231 
       
  6232 		if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
       
  6233 			/* enable wakeup by the PHY */
       
  6234 			retval = e1000_init_phy_wakeup(adapter, wufc);
       
  6235 			if (retval)
       
  6236 				return retval;
       
  6237 		} else {
       
  6238 			/* enable wakeup by the MAC */
       
  6239 			ew32(WUFC, wufc);
       
  6240 			ew32(WUC, E1000_WUC_PME_EN);
       
  6241 		}
       
  6242 	} else {
       
  6243 		ew32(WUC, 0);
       
  6244 		ew32(WUFC, 0);
       
  6245 
       
  6246 		e1000_power_down_phy(adapter);
       
  6247 	}
       
  6248 
       
  6249 	if (adapter->hw.phy.type == e1000_phy_igp_3) {
       
  6250 		e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
       
  6251 	} else if (hw->mac.type == e1000_pch_lpt) {
       
  6252 		if (!(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
       
  6253 			/* ULP does not support wake from unicast, multicast
       
  6254 			 * or broadcast.
       
  6255 			 */
       
  6256 			retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
       
  6257 
       
  6258 		if (retval)
       
  6259 			return retval;
       
  6260 	}
       
  6261 
       
  6262 
       
  6263 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
       
  6264 	 * would have already happened in close and is redundant.
       
  6265 	 */
       
  6266 	e1000e_release_hw_control(adapter);
       
  6267 
       
  6268 	pci_clear_master(pdev);
       
  6269 
       
  6270 	/* The pci-e switch on some quad port adapters will report a
       
  6271 	 * correctable error when the MAC transitions from D0 to D3.  To
       
  6272 	 * prevent this we need to mask off the correctable errors on the
       
  6273 	 * downstream port of the pci-e switch.
       
  6274 	 *
       
  6275 	 * We don't have the associated upstream bridge while assigning
       
  6276 	 * the PCI device into guest. For example, the KVM on power is
       
  6277 	 * one of the cases.
       
  6278 	 */
       
  6279 	if (adapter->flags & FLAG_IS_QUAD_PORT) {
       
  6280 		struct pci_dev *us_dev = pdev->bus->self;
       
  6281 		u16 devctl;
       
  6282 
       
  6283 		if (!us_dev)
       
  6284 			return 0;
       
  6285 
       
  6286 		pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
       
  6287 		pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
       
  6288 					   (devctl & ~PCI_EXP_DEVCTL_CERE));
       
  6289 
       
  6290 		pci_save_state(pdev);
       
  6291 		pci_prepare_to_sleep(pdev);
       
  6292 
       
  6293 		pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
       
  6294 	}
       
  6295 
       
  6296 	return 0;
       
  6297 }
       
  6298 
       
  6299 /**
       
  6300  * e1000e_disable_aspm - Disable ASPM states
       
  6301  * @pdev: pointer to PCI device struct
       
  6302  * @state: bit-mask of ASPM states to disable
       
  6303  *
       
  6304  * Some devices *must* have certain ASPM states disabled per hardware errata.
       
  6305  **/
       
  6306 static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
       
  6307 {
       
  6308 	struct pci_dev *parent = pdev->bus->self;
       
  6309 	u16 aspm_dis_mask = 0;
       
  6310 	u16 pdev_aspmc, parent_aspmc;
       
  6311 
       
  6312 	switch (state) {
       
  6313 	case PCIE_LINK_STATE_L0S:
       
  6314 	case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
       
  6315 		aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
       
  6316 		/* fall-through - can't have L1 without L0s */
       
  6317 	case PCIE_LINK_STATE_L1:
       
  6318 		aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
       
  6319 		break;
       
  6320 	default:
       
  6321 		return;
       
  6322 	}
       
  6323 
       
  6324 	pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
       
  6325 	pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
       
  6326 
       
  6327 	if (parent) {
       
  6328 		pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
       
  6329 					  &parent_aspmc);
       
  6330 		parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
       
  6331 	}
       
  6332 
       
  6333 	/* Nothing to do if the ASPM states to be disabled already are */
       
  6334 	if (!(pdev_aspmc & aspm_dis_mask) &&
       
  6335 	    (!parent || !(parent_aspmc & aspm_dis_mask)))
       
  6336 		return;
       
  6337 
       
  6338 	dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
       
  6339 		 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
       
  6340 		 "L0s" : "",
       
  6341 		 (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
       
  6342 		 "L1" : "");
       
  6343 
       
  6344 #ifdef CONFIG_PCIEASPM
       
  6345 	pci_disable_link_state_locked(pdev, state);
       
  6346 
       
  6347 	/* Double-check ASPM control.  If not disabled by the above, the
       
  6348 	 * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
       
  6349 	 * not enabled); override by writing PCI config space directly.
       
  6350 	 */
       
  6351 	pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
       
  6352 	pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
       
  6353 
       
  6354 	if (!(aspm_dis_mask & pdev_aspmc))
       
  6355 		return;
       
  6356 #endif
       
  6357 
       
  6358 	/* Both device and parent should have the same ASPM setting.
       
  6359 	 * Disable ASPM in downstream component first and then upstream.
       
  6360 	 */
       
  6361 	pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
       
  6362 
       
  6363 	if (parent)
       
  6364 		pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
       
  6365 					   aspm_dis_mask);
       
  6366 }
       
  6367 
       
  6368 #ifdef CONFIG_PM
       
  6369 static int __e1000_resume(struct pci_dev *pdev)
       
  6370 {
       
  6371 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6372 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6373 	struct e1000_hw *hw = &adapter->hw;
       
  6374 	u16 aspm_disable_flag = 0;
       
  6375 
       
  6376 	if (adapter->ecdev)
       
  6377 		return -EBUSY;
       
  6378 
       
  6379 	if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
       
  6380 		aspm_disable_flag = PCIE_LINK_STATE_L0S;
       
  6381 	if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
       
  6382 		aspm_disable_flag |= PCIE_LINK_STATE_L1;
       
  6383 	if (aspm_disable_flag)
       
  6384 		e1000e_disable_aspm(pdev, aspm_disable_flag);
       
  6385 
       
  6386 	pci_set_master(pdev);
       
  6387 
       
  6388 	if (hw->mac.type >= e1000_pch2lan)
       
  6389 		e1000_resume_workarounds_pchlan(&adapter->hw);
       
  6390 
       
  6391 	e1000e_power_up_phy(adapter);
       
  6392 
       
  6393 	/* report the system wakeup cause from S3/S4 */
       
  6394 	if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
       
  6395 		u16 phy_data;
       
  6396 
       
  6397 		e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
       
  6398 		if (phy_data) {
       
  6399 			e_info("PHY Wakeup cause - %s\n",
       
  6400 			       phy_data & E1000_WUS_EX ? "Unicast Packet" :
       
  6401 			       phy_data & E1000_WUS_MC ? "Multicast Packet" :
       
  6402 			       phy_data & E1000_WUS_BC ? "Broadcast Packet" :
       
  6403 			       phy_data & E1000_WUS_MAG ? "Magic Packet" :
       
  6404 			       phy_data & E1000_WUS_LNKC ?
       
  6405 			       "Link Status Change" : "other");
       
  6406 		}
       
  6407 		e1e_wphy(&adapter->hw, BM_WUS, ~0);
       
  6408 	} else {
       
  6409 		u32 wus = er32(WUS);
       
  6410 
       
  6411 		if (wus) {
       
  6412 			e_info("MAC Wakeup cause - %s\n",
       
  6413 			       wus & E1000_WUS_EX ? "Unicast Packet" :
       
  6414 			       wus & E1000_WUS_MC ? "Multicast Packet" :
       
  6415 			       wus & E1000_WUS_BC ? "Broadcast Packet" :
       
  6416 			       wus & E1000_WUS_MAG ? "Magic Packet" :
       
  6417 			       wus & E1000_WUS_LNKC ? "Link Status Change" :
       
  6418 			       "other");
       
  6419 		}
       
  6420 		ew32(WUS, ~0);
       
  6421 	}
       
  6422 
       
  6423 	e1000e_reset(adapter);
       
  6424 
       
  6425 	e1000_init_manageability_pt(adapter);
       
  6426 
       
  6427 	/* If the controller has AMT, do not set DRV_LOAD until the interface
       
  6428 	 * is up.  For all other cases, let the f/w know that the h/w is now
       
  6429 	 * under the control of the driver.
       
  6430 	 */
       
  6431 	if (!(adapter->flags & FLAG_HAS_AMT))
       
  6432 		e1000e_get_hw_control(adapter);
       
  6433 
       
  6434 	return 0;
       
  6435 }
       
  6436 
       
  6437 #ifdef CONFIG_PM_SLEEP
       
  6438 static int e1000e_pm_thaw(struct device *dev)
       
  6439 {
       
  6440 	struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
       
  6441 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6442 
       
  6443 	e1000e_set_interrupt_capability(adapter);
       
  6444 	if (netif_running(netdev)) {
       
  6445 		u32 err = e1000_request_irq(adapter);
       
  6446 
       
  6447 		if (err)
       
  6448 			return err;
       
  6449 
       
  6450 		e1000e_up(adapter);
       
  6451 	}
       
  6452 
       
  6453 	netif_device_attach(netdev);
       
  6454 
       
  6455 	return 0;
       
  6456 }
       
  6457 
       
  6458 static int e1000e_pm_suspend(struct device *dev)
       
  6459 {
       
  6460 	struct pci_dev *pdev = to_pci_dev(dev);
       
  6461 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6462 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6463 
       
  6464 	if (adapter->ecdev)
       
  6465 		return -EBUSY;
       
  6466 
       
  6467 	e1000e_pm_freeze(dev);
       
  6468 
       
  6469 	return __e1000_shutdown(pdev, false);
       
  6470 }
       
  6471 
       
  6472 static int e1000e_pm_resume(struct device *dev)
       
  6473 {
       
  6474 	struct pci_dev *pdev = to_pci_dev(dev);
       
  6475 	int rc;
       
  6476 
       
  6477 	rc = __e1000_resume(pdev);
       
  6478 	if (rc)
       
  6479 		return rc;
       
  6480 
       
  6481 	return e1000e_pm_thaw(dev);
       
  6482 }
       
  6483 #endif /* CONFIG_PM_SLEEP */
       
  6484 
       
  6485 #ifdef CONFIG_PM_RUNTIME
       
  6486 static int e1000e_pm_runtime_idle(struct device *dev)
       
  6487 {
       
  6488 	struct pci_dev *pdev = to_pci_dev(dev);
       
  6489 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6490 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6491 
       
  6492 	if (!e1000e_has_link(adapter))
       
  6493 		pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
       
  6494 
       
  6495 	return -EBUSY;
       
  6496 }
       
  6497 
       
  6498 static int e1000e_pm_runtime_resume(struct device *dev)
       
  6499 {
       
  6500 	struct pci_dev *pdev = to_pci_dev(dev);
       
  6501 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6502 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6503 	int rc;
       
  6504 
       
  6505 	rc = __e1000_resume(pdev);
       
  6506 	if (rc)
       
  6507 		return rc;
       
  6508 
       
  6509 	if (netdev->flags & IFF_UP)
       
  6510 		rc = e1000e_up(adapter);
       
  6511 
       
  6512 	return rc;
       
  6513 }
       
  6514 
       
  6515 static int e1000e_pm_runtime_suspend(struct device *dev)
       
  6516 {
       
  6517 	struct pci_dev *pdev = to_pci_dev(dev);
       
  6518 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6519 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6520 
       
  6521 	if (netdev->flags & IFF_UP) {
       
  6522 		int count = E1000_CHECK_RESET_COUNT;
       
  6523 
       
  6524 		while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
       
  6525 			usleep_range(10000, 20000);
       
  6526 
       
  6527 		WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
       
  6528 
       
  6529 		/* Down the device without resetting the hardware */
       
  6530 		e1000e_down(adapter, false);
       
  6531 	}
       
  6532 
       
  6533 	if (__e1000_shutdown(pdev, true)) {
       
  6534 		e1000e_pm_runtime_resume(dev);
       
  6535 		return -EBUSY;
       
  6536 	}
       
  6537 
       
  6538 	return 0;
       
  6539 }
       
  6540 #endif /* CONFIG_PM_RUNTIME */
       
  6541 #endif /* CONFIG_PM */
       
  6542 
       
  6543 static void e1000_shutdown(struct pci_dev *pdev)
       
  6544 {
       
  6545 	e1000e_pm_freeze(&pdev->dev);
       
  6546 
       
  6547 	__e1000_shutdown(pdev, false);
       
  6548 }
       
  6549 
       
  6550 #ifdef CONFIG_NET_POLL_CONTROLLER
       
  6551 
       
  6552 static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
       
  6553 {
       
  6554 	struct net_device *netdev = data;
       
  6555 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6556 
       
  6557 	if (adapter->msix_entries) {
       
  6558 		int vector, msix_irq;
       
  6559 
       
  6560 		vector = 0;
       
  6561 		msix_irq = adapter->msix_entries[vector].vector;
       
  6562 		disable_irq(msix_irq);
       
  6563 		e1000_intr_msix_rx(msix_irq, netdev);
       
  6564 		enable_irq(msix_irq);
       
  6565 
       
  6566 		vector++;
       
  6567 		msix_irq = adapter->msix_entries[vector].vector;
       
  6568 		disable_irq(msix_irq);
       
  6569 		e1000_intr_msix_tx(msix_irq, netdev);
       
  6570 		enable_irq(msix_irq);
       
  6571 
       
  6572 		vector++;
       
  6573 		msix_irq = adapter->msix_entries[vector].vector;
       
  6574 		disable_irq(msix_irq);
       
  6575 		e1000_msix_other(msix_irq, netdev);
       
  6576 		enable_irq(msix_irq);
       
  6577 	}
       
  6578 
       
  6579 	return IRQ_HANDLED;
       
  6580 }
       
  6581 
       
  6582 /**
       
  6583  * e1000_netpoll
       
  6584  * @netdev: network interface device structure
       
  6585  *
       
  6586  * Polling 'interrupt' - used by things like netconsole to send skbs
       
  6587  * without having to re-enable interrupts. It's not called while
       
  6588  * the interrupt routine is executing.
       
  6589  */
       
  6590 static void e1000_netpoll(struct net_device *netdev)
       
  6591 {
       
  6592 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6593 
       
  6594 	switch (adapter->int_mode) {
       
  6595 	case E1000E_INT_MODE_MSIX:
       
  6596 		e1000_intr_msix(adapter->pdev->irq, netdev);
       
  6597 		break;
       
  6598 	case E1000E_INT_MODE_MSI:
       
  6599 		disable_irq(adapter->pdev->irq);
       
  6600 		e1000_intr_msi(adapter->pdev->irq, netdev);
       
  6601 		enable_irq(adapter->pdev->irq);
       
  6602 		break;
       
  6603 	default:		/* E1000E_INT_MODE_LEGACY */
       
  6604 		disable_irq(adapter->pdev->irq);
       
  6605 		e1000_intr(adapter->pdev->irq, netdev);
       
  6606 		enable_irq(adapter->pdev->irq);
       
  6607 		break;
       
  6608 	}
       
  6609 }
       
  6610 #endif
       
  6611 
       
  6612 /**
       
  6613  * e1000_io_error_detected - called when PCI error is detected
       
  6614  * @pdev: Pointer to PCI device
       
  6615  * @state: The current pci connection state
       
  6616  *
       
  6617  * This function is called after a PCI bus error affecting
       
  6618  * this device has been detected.
       
  6619  */
       
  6620 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
       
  6621 						pci_channel_state_t state)
       
  6622 {
       
  6623 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6624 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6625 
       
  6626 	netif_device_detach(netdev);
       
  6627 
       
  6628 	if (state == pci_channel_io_perm_failure)
       
  6629 		return PCI_ERS_RESULT_DISCONNECT;
       
  6630 
       
  6631 	if (netif_running(netdev))
       
  6632 		e1000e_down(adapter, true);
       
  6633 	pci_disable_device(pdev);
       
  6634 
       
  6635 	/* Request a slot slot reset. */
       
  6636 	return PCI_ERS_RESULT_NEED_RESET;
       
  6637 }
       
  6638 
       
  6639 /**
       
  6640  * e1000_io_slot_reset - called after the pci bus has been reset.
       
  6641  * @pdev: Pointer to PCI device
       
  6642  *
       
  6643  * Restart the card from scratch, as if from a cold-boot. Implementation
       
  6644  * resembles the first-half of the e1000e_pm_resume routine.
       
  6645  */
       
  6646 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
       
  6647 {
       
  6648 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6649 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6650 	struct e1000_hw *hw = &adapter->hw;
       
  6651 	u16 aspm_disable_flag = 0;
       
  6652 	int err;
       
  6653 	pci_ers_result_t result;
       
  6654 
       
  6655 	if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
       
  6656 		aspm_disable_flag = PCIE_LINK_STATE_L0S;
       
  6657 	if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
       
  6658 		aspm_disable_flag |= PCIE_LINK_STATE_L1;
       
  6659 	if (aspm_disable_flag)
       
  6660 		e1000e_disable_aspm(pdev, aspm_disable_flag);
       
  6661 
       
  6662 	err = pci_enable_device_mem(pdev);
       
  6663 	if (err) {
       
  6664 		dev_err(&pdev->dev,
       
  6665 			"Cannot re-enable PCI device after reset.\n");
       
  6666 		result = PCI_ERS_RESULT_DISCONNECT;
       
  6667 	} else {
       
  6668 		pdev->state_saved = true;
       
  6669 		pci_restore_state(pdev);
       
  6670 		pci_set_master(pdev);
       
  6671 
       
  6672 		pci_enable_wake(pdev, PCI_D3hot, 0);
       
  6673 		pci_enable_wake(pdev, PCI_D3cold, 0);
       
  6674 
       
  6675 		e1000e_reset(adapter);
       
  6676 		ew32(WUS, ~0);
       
  6677 		result = PCI_ERS_RESULT_RECOVERED;
       
  6678 	}
       
  6679 
       
  6680 	pci_cleanup_aer_uncorrect_error_status(pdev);
       
  6681 
       
  6682 	return result;
       
  6683 }
       
  6684 
       
  6685 /**
       
  6686  * e1000_io_resume - called when traffic can start flowing again.
       
  6687  * @pdev: Pointer to PCI device
       
  6688  *
       
  6689  * This callback is called when the error recovery driver tells us that
       
  6690  * its OK to resume normal operation. Implementation resembles the
       
  6691  * second-half of the e1000e_pm_resume routine.
       
  6692  */
       
  6693 static void e1000_io_resume(struct pci_dev *pdev)
       
  6694 {
       
  6695 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  6696 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6697 
       
  6698 	e1000_init_manageability_pt(adapter);
       
  6699 
       
  6700 	if (netif_running(netdev)) {
       
  6701 		if (e1000e_up(adapter)) {
       
  6702 			dev_err(&pdev->dev,
       
  6703 				"can't bring device back up after reset\n");
       
  6704 			return;
       
  6705 		}
       
  6706 	}
       
  6707 
       
  6708 	netif_device_attach(netdev);
       
  6709 
       
  6710 	/* If the controller has AMT, do not set DRV_LOAD until the interface
       
  6711 	 * is up.  For all other cases, let the f/w know that the h/w is now
       
  6712 	 * under the control of the driver.
       
  6713 	 */
       
  6714 	if (!(adapter->flags & FLAG_HAS_AMT))
       
  6715 		e1000e_get_hw_control(adapter);
       
  6716 }
       
  6717 
       
  6718 static void e1000_print_device_info(struct e1000_adapter *adapter)
       
  6719 {
       
  6720 	struct e1000_hw *hw = &adapter->hw;
       
  6721 	struct net_device *netdev = adapter->netdev;
       
  6722 	u32 ret_val;
       
  6723 	u8 pba_str[E1000_PBANUM_LENGTH];
       
  6724 
       
  6725 	/* print bus type/speed/width info */
       
  6726 	e_info("(PCI Express:2.5GT/s:%s) %pM\n",
       
  6727 	       /* bus width */
       
  6728 	       ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
       
  6729 		"Width x1"),
       
  6730 	       /* MAC address */
       
  6731 	       netdev->dev_addr);
       
  6732 	e_info("Intel(R) PRO/%s Network Connection\n",
       
  6733 	       (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
       
  6734 	ret_val = e1000_read_pba_string_generic(hw, pba_str,
       
  6735 						E1000_PBANUM_LENGTH);
       
  6736 	if (ret_val)
       
  6737 		strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
       
  6738 	e_info("MAC: %d, PHY: %d, PBA No: %s\n",
       
  6739 	       hw->mac.type, hw->phy.type, pba_str);
       
  6740 }
       
  6741 
       
  6742 static void e1000_eeprom_checks(struct e1000_adapter *adapter)
       
  6743 {
       
  6744 	struct e1000_hw *hw = &adapter->hw;
       
  6745 	int ret_val;
       
  6746 	u16 buf = 0;
       
  6747 
       
  6748 	if (hw->mac.type != e1000_82573)
       
  6749 		return;
       
  6750 
       
  6751 	ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
       
  6752 	le16_to_cpus(&buf);
       
  6753 	if (!ret_val && (!(buf & (1 << 0)))) {
       
  6754 		/* Deep Smart Power Down (DSPD) */
       
  6755 		dev_warn(&adapter->pdev->dev,
       
  6756 			 "Warning: detected DSPD enabled in EEPROM\n");
       
  6757 	}
       
  6758 }
       
  6759 
       
  6760 static int e1000_set_features(struct net_device *netdev,
       
  6761 			      netdev_features_t features)
       
  6762 {
       
  6763 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6764 	netdev_features_t changed = features ^ netdev->features;
       
  6765 
       
  6766 	if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
       
  6767 		adapter->flags |= FLAG_TSO_FORCE;
       
  6768 
       
  6769 	if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
       
  6770 			 NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
       
  6771 			 NETIF_F_RXALL)))
       
  6772 		return 0;
       
  6773 
       
  6774 	if (changed & NETIF_F_RXFCS) {
       
  6775 		if (features & NETIF_F_RXFCS) {
       
  6776 			adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
       
  6777 		} else {
       
  6778 			/* We need to take it back to defaults, which might mean
       
  6779 			 * stripping is still disabled at the adapter level.
       
  6780 			 */
       
  6781 			if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
       
  6782 				adapter->flags2 |= FLAG2_CRC_STRIPPING;
       
  6783 			else
       
  6784 				adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
       
  6785 		}
       
  6786 	}
       
  6787 
       
  6788 	netdev->features = features;
       
  6789 
       
  6790 	if (netif_running(netdev))
       
  6791 		e1000e_reinit_locked(adapter);
       
  6792 	else
       
  6793 		e1000e_reset(adapter);
       
  6794 
       
  6795 	return 0;
       
  6796 }
       
  6797 
       
  6798 static const struct net_device_ops e1000e_netdev_ops = {
       
  6799 	.ndo_open		= e1000_open,
       
  6800 	.ndo_stop		= e1000_close,
       
  6801 	.ndo_start_xmit		= e1000_xmit_frame,
       
  6802 	.ndo_get_stats64	= e1000e_get_stats64,
       
  6803 	.ndo_set_rx_mode	= e1000e_set_rx_mode,
       
  6804 	.ndo_set_mac_address	= e1000_set_mac,
       
  6805 	.ndo_change_mtu		= e1000_change_mtu,
       
  6806 	.ndo_do_ioctl		= e1000_ioctl,
       
  6807 	.ndo_tx_timeout		= e1000_tx_timeout,
       
  6808 	.ndo_validate_addr	= eth_validate_addr,
       
  6809 
       
  6810 	.ndo_vlan_rx_add_vid	= e1000_vlan_rx_add_vid,
       
  6811 	.ndo_vlan_rx_kill_vid	= e1000_vlan_rx_kill_vid,
       
  6812 #ifdef CONFIG_NET_POLL_CONTROLLER
       
  6813 	.ndo_poll_controller	= e1000_netpoll,
       
  6814 #endif
       
  6815 	.ndo_set_features = e1000_set_features,
       
  6816 };
       
  6817 
       
  6818 /**
       
  6819  * ec_poll - Ethercat poll Routine
       
  6820  * @netdev: net device structure
       
  6821  *
       
  6822  * This function can never fail.
       
  6823  *
       
  6824  **/
       
  6825 void ec_poll(struct net_device *netdev)
       
  6826 {
       
  6827 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  6828 
       
  6829 	if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) {
       
  6830 		struct e1000_hw *hw = &adapter->hw;
       
  6831 		hw->mac.get_link_status = true;
       
  6832 		e1000_watchdog_task(&adapter->watchdog_task);
       
  6833 		adapter->ec_watchdog_jiffies = jiffies;
       
  6834 	}
       
  6835 
       
  6836 #ifdef CONFIG_PCI_MSI
       
  6837 	e1000_intr_msi(0, netdev);
       
  6838 #else
       
  6839 	e1000_intr(0, netdev);
       
  6840 #endif
       
  6841 }
       
  6842 
       
  6843 /**
       
  6844  * e1000_probe - Device Initialization Routine
       
  6845  * @pdev: PCI device information struct
       
  6846  * @ent: entry in e1000_pci_tbl
       
  6847  *
       
  6848  * Returns 0 on success, negative on failure
       
  6849  *
       
  6850  * e1000_probe initializes an adapter identified by a pci_dev structure.
       
  6851  * The OS initialization, configuring of the adapter private structure,
       
  6852  * and a hardware reset occur.
       
  6853  **/
       
  6854 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
       
  6855 {
       
  6856 	struct net_device *netdev;
       
  6857 	struct e1000_adapter *adapter;
       
  6858 	struct e1000_hw *hw;
       
  6859 	const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
       
  6860 	resource_size_t mmio_start, mmio_len;
       
  6861 	resource_size_t flash_start, flash_len;
       
  6862 	static int cards_found;
       
  6863 	u16 aspm_disable_flag = 0;
       
  6864 	int bars, i, err, pci_using_dac;
       
  6865 	u16 eeprom_data = 0;
       
  6866 	u16 eeprom_apme_mask = E1000_EEPROM_APME;
       
  6867 
       
  6868 	if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
       
  6869 		aspm_disable_flag = PCIE_LINK_STATE_L0S;
       
  6870 	if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
       
  6871 		aspm_disable_flag |= PCIE_LINK_STATE_L1;
       
  6872 	if (aspm_disable_flag)
       
  6873 		e1000e_disable_aspm(pdev, aspm_disable_flag);
       
  6874 
       
  6875 	err = pci_enable_device_mem(pdev);
       
  6876 	if (err)
       
  6877 		return err;
       
  6878 
       
  6879 	pci_using_dac = 0;
       
  6880 	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
       
  6881 	if (!err) {
       
  6882 		pci_using_dac = 1;
       
  6883 	} else {
       
  6884 		err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
       
  6885 		if (err) {
       
  6886 			dev_err(&pdev->dev,
       
  6887 				"No usable DMA configuration, aborting\n");
       
  6888 			goto err_dma;
       
  6889 		}
       
  6890 	}
       
  6891 
       
  6892 	bars = pci_select_bars(pdev, IORESOURCE_MEM);
       
  6893 	err = pci_request_selected_regions_exclusive(pdev, bars,
       
  6894 						     e1000e_driver_name);
       
  6895 	if (err)
       
  6896 		goto err_pci_reg;
       
  6897 
       
  6898 	/* AER (Advanced Error Reporting) hooks */
       
  6899 	pci_enable_pcie_error_reporting(pdev);
       
  6900 
       
  6901 	pci_set_master(pdev);
       
  6902 	/* PCI config space info */
       
  6903 	err = pci_save_state(pdev);
       
  6904 	if (err)
       
  6905 		goto err_alloc_etherdev;
       
  6906 
       
  6907 	err = -ENOMEM;
       
  6908 	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
       
  6909 	if (!netdev)
       
  6910 		goto err_alloc_etherdev;
       
  6911 
       
  6912 	SET_NETDEV_DEV(netdev, &pdev->dev);
       
  6913 
       
  6914 	netdev->irq = pdev->irq;
       
  6915 
       
  6916 	pci_set_drvdata(pdev, netdev);
       
  6917 	adapter = netdev_priv(netdev);
       
  6918 	hw = &adapter->hw;
       
  6919 	adapter->netdev = netdev;
       
  6920 	adapter->pdev = pdev;
       
  6921 	adapter->ei = ei;
       
  6922 	adapter->pba = ei->pba;
       
  6923 	adapter->flags = ei->flags;
       
  6924 	adapter->flags2 = ei->flags2;
       
  6925 	adapter->hw.adapter = adapter;
       
  6926 	adapter->hw.mac.type = ei->mac;
       
  6927 	adapter->max_hw_frame_size = ei->max_hw_frame_size;
       
  6928 	adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
       
  6929 
       
  6930 	mmio_start = pci_resource_start(pdev, 0);
       
  6931 	mmio_len = pci_resource_len(pdev, 0);
       
  6932 
       
  6933 	err = -EIO;
       
  6934 	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
       
  6935 	if (!adapter->hw.hw_addr)
       
  6936 		goto err_ioremap;
       
  6937 
       
  6938 	if ((adapter->flags & FLAG_HAS_FLASH) &&
       
  6939 	    (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
       
  6940 		flash_start = pci_resource_start(pdev, 1);
       
  6941 		flash_len = pci_resource_len(pdev, 1);
       
  6942 		adapter->hw.flash_address = ioremap(flash_start, flash_len);
       
  6943 		if (!adapter->hw.flash_address)
       
  6944 			goto err_flashmap;
       
  6945 	}
       
  6946 
       
  6947 	/* Set default EEE advertisement */
       
  6948 	if (adapter->flags2 & FLAG2_HAS_EEE)
       
  6949 		adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
       
  6950 
       
  6951 	/* construct the net_device struct */
       
  6952 	netdev->netdev_ops = &e1000e_netdev_ops;
       
  6953 	e1000e_set_ethtool_ops(netdev);
       
  6954 	netdev->watchdog_timeo = 5 * HZ;
       
  6955 	netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
       
  6956 	strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
       
  6957 
       
  6958 	netdev->mem_start = mmio_start;
       
  6959 	netdev->mem_end = mmio_start + mmio_len;
       
  6960 
       
  6961 	adapter->bd_number = cards_found++;
       
  6962 
       
  6963 	e1000e_check_options(adapter);
       
  6964 
       
  6965 	/* setup adapter struct */
       
  6966 	err = e1000_sw_init(adapter);
       
  6967 	if (err)
       
  6968 		goto err_sw_init;
       
  6969 
       
  6970 	memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
       
  6971 	memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
       
  6972 	memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
       
  6973 
       
  6974 	err = ei->get_variants(adapter);
       
  6975 	if (err)
       
  6976 		goto err_hw_init;
       
  6977 
       
  6978 	if ((adapter->flags & FLAG_IS_ICH) &&
       
  6979 	    (adapter->flags & FLAG_READ_ONLY_NVM))
       
  6980 		e1000e_write_protect_nvm_ich8lan(&adapter->hw);
       
  6981 
       
  6982 	hw->mac.ops.get_bus_info(&adapter->hw);
       
  6983 
       
  6984 	adapter->hw.phy.autoneg_wait_to_complete = 0;
       
  6985 
       
  6986 	/* Copper options */
       
  6987 	if (adapter->hw.phy.media_type == e1000_media_type_copper) {
       
  6988 		adapter->hw.phy.mdix = AUTO_ALL_MODES;
       
  6989 		adapter->hw.phy.disable_polarity_correction = 0;
       
  6990 		adapter->hw.phy.ms_type = e1000_ms_hw_default;
       
  6991 	}
       
  6992 
       
  6993 	if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
       
  6994 		dev_info(&pdev->dev,
       
  6995 			 "PHY reset is blocked due to SOL/IDER session.\n");
       
  6996 
       
  6997 	/* Set initial default active device features */
       
  6998 	netdev->features = (NETIF_F_SG |
       
  6999 			    NETIF_F_HW_VLAN_CTAG_RX |
       
  7000 			    NETIF_F_HW_VLAN_CTAG_TX |
       
  7001 			    NETIF_F_TSO |
       
  7002 			    NETIF_F_TSO6 |
       
  7003 			    NETIF_F_RXHASH |
       
  7004 			    NETIF_F_RXCSUM |
       
  7005 			    NETIF_F_HW_CSUM);
       
  7006 
       
  7007 	/* Set user-changeable features (subset of all device features) */
       
  7008 	netdev->hw_features = netdev->features;
       
  7009 	netdev->hw_features |= NETIF_F_RXFCS;
       
  7010 	netdev->priv_flags |= IFF_SUPP_NOFCS;
       
  7011 	netdev->hw_features |= NETIF_F_RXALL;
       
  7012 
       
  7013 	if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
       
  7014 		netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
       
  7015 
       
  7016 	netdev->vlan_features |= (NETIF_F_SG |
       
  7017 				  NETIF_F_TSO |
       
  7018 				  NETIF_F_TSO6 |
       
  7019 				  NETIF_F_HW_CSUM);
       
  7020 
       
  7021 	netdev->priv_flags |= IFF_UNICAST_FLT;
       
  7022 
       
  7023 	if (pci_using_dac) {
       
  7024 		netdev->features |= NETIF_F_HIGHDMA;
       
  7025 		netdev->vlan_features |= NETIF_F_HIGHDMA;
       
  7026 	}
       
  7027 
       
  7028 	if (e1000e_enable_mng_pass_thru(&adapter->hw))
       
  7029 		adapter->flags |= FLAG_MNG_PT_ENABLED;
       
  7030 
       
  7031 	/* before reading the NVM, reset the controller to
       
  7032 	 * put the device in a known good starting state
       
  7033 	 */
       
  7034 	adapter->hw.mac.ops.reset_hw(&adapter->hw);
       
  7035 
       
  7036 	/* systems with ASPM and others may see the checksum fail on the first
       
  7037 	 * attempt. Let's give it a few tries
       
  7038 	 */
       
  7039 	for (i = 0;; i++) {
       
  7040 		if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
       
  7041 			break;
       
  7042 		if (i == 2) {
       
  7043 			dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
       
  7044 			err = -EIO;
       
  7045 			goto err_eeprom;
       
  7046 		}
       
  7047 	}
       
  7048 
       
  7049 	e1000_eeprom_checks(adapter);
       
  7050 
       
  7051 	/* copy the MAC address */
       
  7052 	if (e1000e_read_mac_addr(&adapter->hw))
       
  7053 		dev_err(&pdev->dev,
       
  7054 			"NVM Read Error while reading MAC address\n");
       
  7055 
       
  7056 	memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
       
  7057 
       
  7058 	if (!is_valid_ether_addr(netdev->dev_addr)) {
       
  7059 		dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
       
  7060 			netdev->dev_addr);
       
  7061 		err = -EIO;
       
  7062 		goto err_eeprom;
       
  7063 	}
       
  7064 
       
  7065 	init_timer(&adapter->watchdog_timer);
       
  7066 	adapter->watchdog_timer.function = e1000_watchdog;
       
  7067 	adapter->watchdog_timer.data = (unsigned long)adapter;
       
  7068 
       
  7069 	init_timer(&adapter->phy_info_timer);
       
  7070 	adapter->phy_info_timer.function = e1000_update_phy_info;
       
  7071 	adapter->phy_info_timer.data = (unsigned long)adapter;
       
  7072 
       
  7073 	INIT_WORK(&adapter->reset_task, e1000_reset_task);
       
  7074 	INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
       
  7075 	INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
       
  7076 	INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
       
  7077 	INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
       
  7078 
       
  7079 	/* Initialize link parameters. User can change them with ethtool */
       
  7080 	adapter->hw.mac.autoneg = 1;
       
  7081 	adapter->fc_autoneg = true;
       
  7082 	adapter->hw.fc.requested_mode = e1000_fc_default;
       
  7083 	adapter->hw.fc.current_mode = e1000_fc_default;
       
  7084 	adapter->hw.phy.autoneg_advertised = 0x2f;
       
  7085 
       
  7086 	/* Initial Wake on LAN setting - If APM wake is enabled in
       
  7087 	 * the EEPROM, enable the ACPI Magic Packet filter
       
  7088 	 */
       
  7089 	if (adapter->flags & FLAG_APME_IN_WUC) {
       
  7090 		/* APME bit in EEPROM is mapped to WUC.APME */
       
  7091 		eeprom_data = er32(WUC);
       
  7092 		eeprom_apme_mask = E1000_WUC_APME;
       
  7093 		if ((hw->mac.type > e1000_ich10lan) &&
       
  7094 		    (eeprom_data & E1000_WUC_PHY_WAKE))
       
  7095 			adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
       
  7096 	} else if (adapter->flags & FLAG_APME_IN_CTRL3) {
       
  7097 		if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
       
  7098 		    (adapter->hw.bus.func == 1))
       
  7099 			e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_B,
       
  7100 				       1, &eeprom_data);
       
  7101 		else
       
  7102 			e1000_read_nvm(&adapter->hw, NVM_INIT_CONTROL3_PORT_A,
       
  7103 				       1, &eeprom_data);
       
  7104 	}
       
  7105 
       
  7106 	/* fetch WoL from EEPROM */
       
  7107 	if (eeprom_data & eeprom_apme_mask)
       
  7108 		adapter->eeprom_wol |= E1000_WUFC_MAG;
       
  7109 
       
  7110 	/* now that we have the eeprom settings, apply the special cases
       
  7111 	 * where the eeprom may be wrong or the board simply won't support
       
  7112 	 * wake on lan on a particular port
       
  7113 	 */
       
  7114 	if (!(adapter->flags & FLAG_HAS_WOL))
       
  7115 		adapter->eeprom_wol = 0;
       
  7116 
       
  7117 	/* initialize the wol settings based on the eeprom settings */
       
  7118 	adapter->wol = adapter->eeprom_wol;
       
  7119 
       
  7120 	/* make sure adapter isn't asleep if manageability is enabled */
       
  7121 	if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
       
  7122 	    (hw->mac.ops.check_mng_mode(hw)))
       
  7123 		device_wakeup_enable(&pdev->dev);
       
  7124 
       
  7125 	/* save off EEPROM version number */
       
  7126 	e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
       
  7127 
       
  7128 	/* reset the hardware with the new settings */
       
  7129 	e1000e_reset(adapter);
       
  7130 
       
  7131 	/* If the controller has AMT, do not set DRV_LOAD until the interface
       
  7132 	 * is up.  For all other cases, let the f/w know that the h/w is now
       
  7133 	 * under the control of the driver.
       
  7134 	 */
       
  7135 	if (!(adapter->flags & FLAG_HAS_AMT))
       
  7136 		e1000e_get_hw_control(adapter);
       
  7137 
       
  7138 	adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE);
       
  7139 	if (adapter->ecdev) {
       
  7140 		err = ecdev_open(adapter->ecdev);
       
  7141 		if (err) {
       
  7142 			ecdev_withdraw(adapter->ecdev);
       
  7143 			goto err_register;
       
  7144 		}
       
  7145 		adapter->ec_watchdog_jiffies = jiffies;
       
  7146 	} else {
       
  7147 		strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
       
  7148 		err = register_netdev(netdev);
       
  7149 		if (err)
       
  7150 			goto err_register;
       
  7151 
       
  7152 		/* carrier off reporting is important to ethtool even BEFORE open */
       
  7153 		netif_carrier_off(netdev);
       
  7154 	}
       
  7155 
       
  7156 	/* init PTP hardware clock */
       
  7157 	e1000e_ptp_init(adapter);
       
  7158 
       
  7159 	e1000_print_device_info(adapter);
       
  7160 
       
  7161 	if (pci_dev_run_wake(pdev))
       
  7162 		pm_runtime_put_noidle(&pdev->dev);
       
  7163 
       
  7164 	return 0;
       
  7165 
       
  7166 err_register:
       
  7167 	if (!(adapter->flags & FLAG_HAS_AMT))
       
  7168 		e1000e_release_hw_control(adapter);
       
  7169 err_eeprom:
       
  7170 	if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
       
  7171 		e1000_phy_hw_reset(&adapter->hw);
       
  7172 err_hw_init:
       
  7173 	kfree(adapter->tx_ring);
       
  7174 	kfree(adapter->rx_ring);
       
  7175 err_sw_init:
       
  7176 	if (adapter->hw.flash_address)
       
  7177 		iounmap(adapter->hw.flash_address);
       
  7178 	e1000e_reset_interrupt_capability(adapter);
       
  7179 err_flashmap:
       
  7180 	iounmap(adapter->hw.hw_addr);
       
  7181 err_ioremap:
       
  7182 	free_netdev(netdev);
       
  7183 err_alloc_etherdev:
       
  7184 	pci_release_selected_regions(pdev,
       
  7185 				     pci_select_bars(pdev, IORESOURCE_MEM));
       
  7186 err_pci_reg:
       
  7187 err_dma:
       
  7188 	pci_disable_device(pdev);
       
  7189 	return err;
       
  7190 }
       
  7191 
       
  7192 /**
       
  7193  * e1000_remove - Device Removal Routine
       
  7194  * @pdev: PCI device information struct
       
  7195  *
       
  7196  * e1000_remove is called by the PCI subsystem to alert the driver
       
  7197  * that it should release a PCI device.  The could be caused by a
       
  7198  * Hot-Plug event, or because the driver is going to be removed from
       
  7199  * memory.
       
  7200  **/
       
  7201 static void e1000_remove(struct pci_dev *pdev)
       
  7202 {
       
  7203 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  7204 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  7205 	bool down = test_bit(__E1000_DOWN, &adapter->state);
       
  7206 
       
  7207 	e1000e_ptp_remove(adapter);
       
  7208 
       
  7209 	if (adapter->ecdev) {
       
  7210 		ecdev_close(adapter->ecdev);
       
  7211 		ecdev_withdraw(adapter->ecdev);
       
  7212 	}
       
  7213 
       
  7214 	/* The timers may be rescheduled, so explicitly disable them
       
  7215 	 * from being rescheduled.
       
  7216 	 */
       
  7217 	if (!down)
       
  7218 		set_bit(__E1000_DOWN, &adapter->state);
       
  7219 	del_timer_sync(&adapter->watchdog_timer);
       
  7220 	del_timer_sync(&adapter->phy_info_timer);
       
  7221 
       
  7222 	cancel_work_sync(&adapter->reset_task);
       
  7223 	cancel_work_sync(&adapter->watchdog_task);
       
  7224 	cancel_work_sync(&adapter->downshift_task);
       
  7225 	cancel_work_sync(&adapter->update_phy_task);
       
  7226 	cancel_work_sync(&adapter->print_hang_task);
       
  7227 
       
  7228 	if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
       
  7229 		cancel_work_sync(&adapter->tx_hwtstamp_work);
       
  7230 		if (adapter->tx_hwtstamp_skb) {
       
  7231 			dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
       
  7232 			adapter->tx_hwtstamp_skb = NULL;
       
  7233 		}
       
  7234 	}
       
  7235 
       
  7236 	/* Don't lie to e1000_close() down the road. */
       
  7237 	if (!down)
       
  7238 		clear_bit(__E1000_DOWN, &adapter->state);
       
  7239 
       
  7240 	if (!adapter->ecdev) {
       
  7241 		unregister_netdev(netdev);
       
  7242 	}
       
  7243 
       
  7244 	if (pci_dev_run_wake(pdev))
       
  7245 		pm_runtime_get_noresume(&pdev->dev);
       
  7246 
       
  7247 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
       
  7248 	 * would have already happened in close and is redundant.
       
  7249 	 */
       
  7250 	e1000e_release_hw_control(adapter);
       
  7251 
       
  7252 	e1000e_reset_interrupt_capability(adapter);
       
  7253 	kfree(adapter->tx_ring);
       
  7254 	kfree(adapter->rx_ring);
       
  7255 
       
  7256 	iounmap(adapter->hw.hw_addr);
       
  7257 	if (adapter->hw.flash_address)
       
  7258 		iounmap(adapter->hw.flash_address);
       
  7259 	pci_release_selected_regions(pdev,
       
  7260 				     pci_select_bars(pdev, IORESOURCE_MEM));
       
  7261 
       
  7262 	free_netdev(netdev);
       
  7263 
       
  7264 	/* AER disable */
       
  7265 	pci_disable_pcie_error_reporting(pdev);
       
  7266 
       
  7267 	pci_disable_device(pdev);
       
  7268 }
       
  7269 
       
  7270 /* PCI Error Recovery (ERS) */
       
  7271 static const struct pci_error_handlers e1000_err_handler = {
       
  7272 	.error_detected = e1000_io_error_detected,
       
  7273 	.slot_reset = e1000_io_slot_reset,
       
  7274 	.resume = e1000_io_resume,
       
  7275 };
       
  7276 
       
  7277 static const struct pci_device_id e1000_pci_tbl[] = {
       
  7278 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
       
  7279 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
       
  7280 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
       
  7281 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
       
  7282 	  board_82571 },
       
  7283 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
       
  7284 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
       
  7285 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
       
  7286 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
       
  7287 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
       
  7288 
       
  7289 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
       
  7290 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
       
  7291 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
       
  7292 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
       
  7293 
       
  7294 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
       
  7295 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
       
  7296 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
       
  7297 
       
  7298 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
       
  7299 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
       
  7300 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
       
  7301 
       
  7302 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
       
  7303 	  board_80003es2lan },
       
  7304 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
       
  7305 	  board_80003es2lan },
       
  7306 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
       
  7307 	  board_80003es2lan },
       
  7308 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
       
  7309 	  board_80003es2lan },
       
  7310 
       
  7311 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
       
  7312 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
       
  7313 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
       
  7314 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
       
  7315 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
       
  7316 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
       
  7317 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
       
  7318 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
       
  7319 
       
  7320 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
       
  7321 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
       
  7322 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
       
  7323 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
       
  7324 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
       
  7325 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
       
  7326 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
       
  7327 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
       
  7328 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
       
  7329 
       
  7330 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
       
  7331 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
       
  7332 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
       
  7333 
       
  7334 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
       
  7335 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
       
  7336 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
       
  7337 
       
  7338 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
       
  7339 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
       
  7340 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
       
  7341 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
       
  7342 
       
  7343 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
       
  7344 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
       
  7345 
       
  7346 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
       
  7347 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
       
  7348 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
       
  7349 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
       
  7350 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
       
  7351 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
       
  7352 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
       
  7353 	{ PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
       
  7354 
       
  7355 	{ 0, 0, 0, 0, 0, 0, 0 }	/* terminate list */
       
  7356 };
       
  7357 //MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
       
  7358 
       
  7359 static const struct dev_pm_ops e1000_pm_ops = {
       
  7360 #ifdef CONFIG_PM_SLEEP
       
  7361 	.suspend	= e1000e_pm_suspend,
       
  7362 	.resume		= e1000e_pm_resume,
       
  7363 	.freeze		= e1000e_pm_freeze,
       
  7364 	.thaw		= e1000e_pm_thaw,
       
  7365 	.poweroff	= e1000e_pm_suspend,
       
  7366 	.restore	= e1000e_pm_resume,
       
  7367 #endif
       
  7368 	SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
       
  7369 			   e1000e_pm_runtime_idle)
       
  7370 };
       
  7371 
       
  7372 /* PCI Device API Driver */
       
  7373 static struct pci_driver e1000_driver = {
       
  7374 	.name     = e1000e_driver_name,
       
  7375 	.id_table = e1000_pci_tbl,
       
  7376 	.probe    = e1000_probe,
       
  7377 	.remove   = e1000_remove,
       
  7378 	.driver   = {
       
  7379 		.pm = &e1000_pm_ops,
       
  7380 	},
       
  7381 	.shutdown = e1000_shutdown,
       
  7382 	.err_handler = &e1000_err_handler
       
  7383 };
       
  7384 
       
  7385 /**
       
  7386  * e1000_init_module - Driver Registration Routine
       
  7387  *
       
  7388  * e1000_init_module is the first routine called when the driver is
       
  7389  * loaded. All it does is register with the PCI subsystem.
       
  7390  **/
       
  7391 static int __init e1000_init_module(void)
       
  7392 {
       
  7393 	int ret;
       
  7394 
       
  7395 	pr_info("EtherCAT-capable Intel(R) PRO/1000 Network Driver - %s\n",
       
  7396 		e1000e_driver_version);
       
  7397 	pr_info("Copyright(c) 1999 - 2014 Intel Corporation.\n");
       
  7398 	ret = pci_register_driver(&e1000_driver);
       
  7399 
       
  7400 	return ret;
       
  7401 }
       
  7402 module_init(e1000_init_module);
       
  7403 
       
  7404 /**
       
  7405  * e1000_exit_module - Driver Exit Cleanup Routine
       
  7406  *
       
  7407  * e1000_exit_module is called just before the driver is removed
       
  7408  * from memory.
       
  7409  **/
       
  7410 static void __exit e1000_exit_module(void)
       
  7411 {
       
  7412 	pci_unregister_driver(&e1000_driver);
       
  7413 }
       
  7414 module_exit(e1000_exit_module);
       
  7415 
       
  7416 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
       
  7417 MODULE_DESCRIPTION("Ethercat-capable Intel(R) PRO/1000 Network Driver");
       
  7418 MODULE_LICENSE("GPL");
       
  7419 MODULE_VERSION(DRV_VERSION);
       
  7420 
       
  7421 /* netdev.c */