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