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