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