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