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