devices/e1000/e1000_main-2.6.22-ethercat.c
branchstable-1.3
changeset 1754 e750b37597ad
child 1756 dbe4a4219aa5
equal deleted inserted replaced
1753:124eb40a2818 1754:e750b37597ad
       
     1 /*******************************************************************************
       
     2 
       
     3   Intel PRO/1000 Linux driver
       
     4   Copyright(c) 1999 - 2006 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 #include "e1000-2.6.22-ethercat.h"
       
    30 #include <net/ip6_checksum.h>
       
    31 
       
    32 char e1000_driver_name[] = "ec_e1000";
       
    33 static char e1000_driver_string[] = "EtherCAT Intel(R) PRO/1000 Network Driver";
       
    34 #ifndef CONFIG_E1000_NAPI
       
    35 #define DRIVERNAPI
       
    36 #else
       
    37 #define DRIVERNAPI "-NAPI"
       
    38 #endif
       
    39 #define DRV_VERSION "7.3.20-k2"DRIVERNAPI
       
    40 char e1000_driver_version[] = DRV_VERSION;
       
    41 static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
       
    42 
       
    43 /* e1000_pci_tbl - PCI Device ID Table
       
    44  *
       
    45  * Last entry must be all 0s
       
    46  *
       
    47  * Macro expands to...
       
    48  *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
       
    49  */
       
    50 static struct pci_device_id e1000_pci_tbl[] = {
       
    51 	INTEL_E1000_ETHERNET_DEVICE(0x1000),
       
    52 	INTEL_E1000_ETHERNET_DEVICE(0x1001),
       
    53 	INTEL_E1000_ETHERNET_DEVICE(0x1004),
       
    54 	INTEL_E1000_ETHERNET_DEVICE(0x1008),
       
    55 	INTEL_E1000_ETHERNET_DEVICE(0x1009),
       
    56 	INTEL_E1000_ETHERNET_DEVICE(0x100C),
       
    57 	INTEL_E1000_ETHERNET_DEVICE(0x100D),
       
    58 	INTEL_E1000_ETHERNET_DEVICE(0x100E),
       
    59 	INTEL_E1000_ETHERNET_DEVICE(0x100F),
       
    60 	INTEL_E1000_ETHERNET_DEVICE(0x1010),
       
    61 	INTEL_E1000_ETHERNET_DEVICE(0x1011),
       
    62 	INTEL_E1000_ETHERNET_DEVICE(0x1012),
       
    63 	INTEL_E1000_ETHERNET_DEVICE(0x1013),
       
    64 	INTEL_E1000_ETHERNET_DEVICE(0x1014),
       
    65 	INTEL_E1000_ETHERNET_DEVICE(0x1015),
       
    66 	INTEL_E1000_ETHERNET_DEVICE(0x1016),
       
    67 	INTEL_E1000_ETHERNET_DEVICE(0x1017),
       
    68 	INTEL_E1000_ETHERNET_DEVICE(0x1018),
       
    69 	INTEL_E1000_ETHERNET_DEVICE(0x1019),
       
    70 	INTEL_E1000_ETHERNET_DEVICE(0x101A),
       
    71 	INTEL_E1000_ETHERNET_DEVICE(0x101D),
       
    72 	INTEL_E1000_ETHERNET_DEVICE(0x101E),
       
    73 	INTEL_E1000_ETHERNET_DEVICE(0x1026),
       
    74 	INTEL_E1000_ETHERNET_DEVICE(0x1027),
       
    75 	INTEL_E1000_ETHERNET_DEVICE(0x1028),
       
    76 	INTEL_E1000_ETHERNET_DEVICE(0x1049),
       
    77 	INTEL_E1000_ETHERNET_DEVICE(0x104A),
       
    78 	INTEL_E1000_ETHERNET_DEVICE(0x104B),
       
    79 	INTEL_E1000_ETHERNET_DEVICE(0x104C),
       
    80 	INTEL_E1000_ETHERNET_DEVICE(0x104D),
       
    81 	INTEL_E1000_ETHERNET_DEVICE(0x105E),
       
    82 	INTEL_E1000_ETHERNET_DEVICE(0x105F),
       
    83 	INTEL_E1000_ETHERNET_DEVICE(0x1060),
       
    84 	INTEL_E1000_ETHERNET_DEVICE(0x1075),
       
    85 	INTEL_E1000_ETHERNET_DEVICE(0x1076),
       
    86 	INTEL_E1000_ETHERNET_DEVICE(0x1077),
       
    87 	INTEL_E1000_ETHERNET_DEVICE(0x1078),
       
    88 	INTEL_E1000_ETHERNET_DEVICE(0x1079),
       
    89 	INTEL_E1000_ETHERNET_DEVICE(0x107A),
       
    90 	INTEL_E1000_ETHERNET_DEVICE(0x107B),
       
    91 	INTEL_E1000_ETHERNET_DEVICE(0x107C),
       
    92 	INTEL_E1000_ETHERNET_DEVICE(0x107D),
       
    93 	INTEL_E1000_ETHERNET_DEVICE(0x107E),
       
    94 	INTEL_E1000_ETHERNET_DEVICE(0x107F),
       
    95 	INTEL_E1000_ETHERNET_DEVICE(0x108A),
       
    96 	INTEL_E1000_ETHERNET_DEVICE(0x108B),
       
    97 	INTEL_E1000_ETHERNET_DEVICE(0x108C),
       
    98 	INTEL_E1000_ETHERNET_DEVICE(0x1096),
       
    99 	INTEL_E1000_ETHERNET_DEVICE(0x1098),
       
   100 	INTEL_E1000_ETHERNET_DEVICE(0x1099),
       
   101 	INTEL_E1000_ETHERNET_DEVICE(0x109A),
       
   102 	INTEL_E1000_ETHERNET_DEVICE(0x10A4),
       
   103 	INTEL_E1000_ETHERNET_DEVICE(0x10B5),
       
   104 	INTEL_E1000_ETHERNET_DEVICE(0x10B9),
       
   105 	INTEL_E1000_ETHERNET_DEVICE(0x10BA),
       
   106 	INTEL_E1000_ETHERNET_DEVICE(0x10BB),
       
   107 	INTEL_E1000_ETHERNET_DEVICE(0x10BC),
       
   108 	INTEL_E1000_ETHERNET_DEVICE(0x10C4),
       
   109 	INTEL_E1000_ETHERNET_DEVICE(0x10C5),
       
   110 	/* required last entry */
       
   111 	{0,}
       
   112 };
       
   113 
       
   114 // do not auto-load driver
       
   115 // MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
       
   116 
       
   117 int e1000_up(struct e1000_adapter *adapter);
       
   118 void e1000_down(struct e1000_adapter *adapter);
       
   119 void e1000_reinit_locked(struct e1000_adapter *adapter);
       
   120 void e1000_reset(struct e1000_adapter *adapter);
       
   121 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
       
   122 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
       
   123 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
       
   124 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
       
   125 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
       
   126 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
       
   127                              struct e1000_tx_ring *txdr);
       
   128 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
       
   129                              struct e1000_rx_ring *rxdr);
       
   130 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
       
   131                              struct e1000_tx_ring *tx_ring);
       
   132 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
       
   133                              struct e1000_rx_ring *rx_ring);
       
   134 void e1000_update_stats(struct e1000_adapter *adapter);
       
   135 
       
   136 static int e1000_init_module(void);
       
   137 static void e1000_exit_module(void);
       
   138 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
       
   139 static void __devexit e1000_remove(struct pci_dev *pdev);
       
   140 static int e1000_alloc_queues(struct e1000_adapter *adapter);
       
   141 static int e1000_sw_init(struct e1000_adapter *adapter);
       
   142 static int e1000_open(struct net_device *netdev);
       
   143 static int e1000_close(struct net_device *netdev);
       
   144 static void e1000_configure_tx(struct e1000_adapter *adapter);
       
   145 static void e1000_configure_rx(struct e1000_adapter *adapter);
       
   146 static void e1000_setup_rctl(struct e1000_adapter *adapter);
       
   147 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
       
   148 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
       
   149 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
       
   150                                 struct e1000_tx_ring *tx_ring);
       
   151 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
       
   152                                 struct e1000_rx_ring *rx_ring);
       
   153 static void e1000_set_multi(struct net_device *netdev);
       
   154 static void e1000_update_phy_info(unsigned long data);
       
   155 static void e1000_watchdog(unsigned long data);
       
   156 static void e1000_82547_tx_fifo_stall(unsigned long data);
       
   157 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
       
   158 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
       
   159 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
       
   160 static int e1000_set_mac(struct net_device *netdev, void *p);
       
   161 void ec_poll(struct net_device *);
       
   162 static irqreturn_t e1000_intr(int irq, void *data);
       
   163 static irqreturn_t e1000_intr_msi(int irq, void *data);
       
   164 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
       
   165                                     struct e1000_tx_ring *tx_ring);
       
   166 #ifdef CONFIG_E1000_NAPI
       
   167 static int e1000_clean(struct net_device *poll_dev, int *budget);
       
   168 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
       
   169                                     struct e1000_rx_ring *rx_ring,
       
   170                                     int *work_done, int work_to_do);
       
   171 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
       
   172                                        struct e1000_rx_ring *rx_ring,
       
   173                                        int *work_done, int work_to_do);
       
   174 #else
       
   175 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
       
   176                                     struct e1000_rx_ring *rx_ring);
       
   177 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
       
   178                                        struct e1000_rx_ring *rx_ring);
       
   179 #endif
       
   180 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
       
   181                                    struct e1000_rx_ring *rx_ring,
       
   182 				   int cleaned_count);
       
   183 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
       
   184                                       struct e1000_rx_ring *rx_ring,
       
   185 				      int cleaned_count);
       
   186 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
       
   187 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
       
   188 			   int cmd);
       
   189 void e1000_set_ethtool_ops(struct net_device *netdev);
       
   190 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
       
   191 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
       
   192 static void e1000_tx_timeout(struct net_device *dev);
       
   193 static void e1000_reset_task(struct work_struct *work);
       
   194 static void e1000_smartspeed(struct e1000_adapter *adapter);
       
   195 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
       
   196                                        struct sk_buff *skb);
       
   197 
       
   198 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
       
   199 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
       
   200 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
       
   201 static void e1000_restore_vlan(struct e1000_adapter *adapter);
       
   202 
       
   203 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
       
   204 #ifdef CONFIG_PM
       
   205 static int e1000_resume(struct pci_dev *pdev);
       
   206 #endif
       
   207 static void e1000_shutdown(struct pci_dev *pdev);
       
   208 
       
   209 #ifdef CONFIG_NET_POLL_CONTROLLER
       
   210 /* for netdump / net console */
       
   211 static void e1000_netpoll (struct net_device *netdev);
       
   212 #endif
       
   213 
       
   214 extern void e1000_check_options(struct e1000_adapter *adapter);
       
   215 
       
   216 #define COPYBREAK_DEFAULT 256
       
   217 static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
       
   218 module_param(copybreak, uint, 0644);
       
   219 MODULE_PARM_DESC(copybreak,
       
   220 	"Maximum size of packet that is copied to a new buffer on receive");
       
   221 
       
   222 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
       
   223                      pci_channel_state_t state);
       
   224 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
       
   225 static void e1000_io_resume(struct pci_dev *pdev);
       
   226 
       
   227 static struct pci_error_handlers e1000_err_handler = {
       
   228 	.error_detected = e1000_io_error_detected,
       
   229 	.slot_reset = e1000_io_slot_reset,
       
   230 	.resume = e1000_io_resume,
       
   231 };
       
   232 
       
   233 static struct pci_driver e1000_driver = {
       
   234 	.name     = e1000_driver_name,
       
   235 	.id_table = e1000_pci_tbl,
       
   236 	.probe    = e1000_probe,
       
   237 	.remove   = __devexit_p(e1000_remove),
       
   238 #ifdef CONFIG_PM
       
   239 	/* Power Managment Hooks */
       
   240 	.suspend  = e1000_suspend,
       
   241 	.resume   = e1000_resume,
       
   242 #endif
       
   243 	.shutdown = e1000_shutdown,
       
   244 	.err_handler = &e1000_err_handler
       
   245 };
       
   246 
       
   247 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
       
   248 MODULE_DESCRIPTION("EtherCAT-capable Intel(R) PRO/1000 Network Driver");
       
   249 MODULE_LICENSE("GPL");
       
   250 MODULE_VERSION(DRV_VERSION);
       
   251 
       
   252 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
       
   253 module_param(debug, int, 0);
       
   254 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
       
   255 
       
   256 /**
       
   257  * e1000_init_module - Driver Registration Routine
       
   258  *
       
   259  * e1000_init_module is the first routine called when the driver is
       
   260  * loaded. All it does is register with the PCI subsystem.
       
   261  **/
       
   262 
       
   263 static int __init
       
   264 e1000_init_module(void)
       
   265 {
       
   266 	int ret;
       
   267 	printk(KERN_INFO "%s - version %s\n",
       
   268 	       e1000_driver_string, e1000_driver_version);
       
   269 
       
   270 	printk(KERN_INFO "%s\n", e1000_copyright);
       
   271 
       
   272 	ret = pci_register_driver(&e1000_driver);
       
   273 	if (copybreak != COPYBREAK_DEFAULT) {
       
   274 		if (copybreak == 0)
       
   275 			printk(KERN_INFO "e1000: copybreak disabled\n");
       
   276 		else
       
   277 			printk(KERN_INFO "e1000: copybreak enabled for "
       
   278 			       "packets <= %u bytes\n", copybreak);
       
   279 	}
       
   280 	return ret;
       
   281 }
       
   282 
       
   283 module_init(e1000_init_module);
       
   284 
       
   285 /**
       
   286  * e1000_exit_module - Driver Exit Cleanup Routine
       
   287  *
       
   288  * e1000_exit_module is called just before the driver is removed
       
   289  * from memory.
       
   290  **/
       
   291 
       
   292 static void __exit
       
   293 e1000_exit_module(void)
       
   294 {
       
   295 	pci_unregister_driver(&e1000_driver);
       
   296 }
       
   297 
       
   298 module_exit(e1000_exit_module);
       
   299 
       
   300 static int e1000_request_irq(struct e1000_adapter *adapter)
       
   301 {
       
   302 	struct net_device *netdev = adapter->netdev;
       
   303 	void (*handler) = &e1000_intr;
       
   304 	int irq_flags = IRQF_SHARED;
       
   305 	int err;
       
   306 
       
   307 	if (adapter->ecdev)
       
   308 		return 0;
       
   309 
       
   310 	if (adapter->hw.mac_type >= e1000_82571) {
       
   311 		adapter->have_msi = !pci_enable_msi(adapter->pdev);
       
   312 		if (adapter->have_msi) {
       
   313 			handler = &e1000_intr_msi;
       
   314 			irq_flags = 0;
       
   315 		}
       
   316 	}
       
   317 
       
   318 	err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
       
   319 	                  netdev);
       
   320 	if (err) {
       
   321 		if (adapter->have_msi)
       
   322 			pci_disable_msi(adapter->pdev);
       
   323 		DPRINTK(PROBE, ERR,
       
   324 		        "Unable to allocate interrupt Error: %d\n", err);
       
   325 	}
       
   326 
       
   327 	return err;
       
   328 }
       
   329 
       
   330 static void e1000_free_irq(struct e1000_adapter *adapter)
       
   331 {
       
   332 	struct net_device *netdev = adapter->netdev;
       
   333 
       
   334 	if (adapter->ecdev)
       
   335 		return;
       
   336 
       
   337 	free_irq(adapter->pdev->irq, netdev);
       
   338 
       
   339 	if (adapter->have_msi)
       
   340 		pci_disable_msi(adapter->pdev);
       
   341 }
       
   342 
       
   343 /**
       
   344  * e1000_irq_disable - Mask off interrupt generation on the NIC
       
   345  * @adapter: board private structure
       
   346  **/
       
   347 
       
   348 static void
       
   349 e1000_irq_disable(struct e1000_adapter *adapter)
       
   350 {
       
   351     if (adapter->ecdev)
       
   352         return;
       
   353 
       
   354 	atomic_inc(&adapter->irq_sem);
       
   355 	E1000_WRITE_REG(&adapter->hw, IMC, ~0);
       
   356 	E1000_WRITE_FLUSH(&adapter->hw);
       
   357 	synchronize_irq(adapter->pdev->irq);
       
   358 }
       
   359 
       
   360 /**
       
   361  * e1000_irq_enable - Enable default interrupt generation settings
       
   362  * @adapter: board private structure
       
   363  **/
       
   364 
       
   365 static void
       
   366 e1000_irq_enable(struct e1000_adapter *adapter)
       
   367 {
       
   368     if (adapter->ecdev)
       
   369         return;
       
   370 
       
   371 	if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
       
   372 		E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
       
   373 		E1000_WRITE_FLUSH(&adapter->hw);
       
   374 	}
       
   375 }
       
   376 
       
   377 static void
       
   378 e1000_update_mng_vlan(struct e1000_adapter *adapter)
       
   379 {
       
   380 	struct net_device *netdev = adapter->netdev;
       
   381 	uint16_t vid = adapter->hw.mng_cookie.vlan_id;
       
   382 	uint16_t old_vid = adapter->mng_vlan_id;
       
   383 	if (adapter->vlgrp) {
       
   384 		if (!vlan_group_get_device(adapter->vlgrp, vid)) {
       
   385 			if (adapter->hw.mng_cookie.status &
       
   386 				E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
       
   387 				e1000_vlan_rx_add_vid(netdev, vid);
       
   388 				adapter->mng_vlan_id = vid;
       
   389 			} else
       
   390 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
       
   391 
       
   392 			if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
       
   393 					(vid != old_vid) &&
       
   394 			    !vlan_group_get_device(adapter->vlgrp, old_vid))
       
   395 				e1000_vlan_rx_kill_vid(netdev, old_vid);
       
   396 		} else
       
   397 			adapter->mng_vlan_id = vid;
       
   398 	}
       
   399 }
       
   400 
       
   401 /**
       
   402  * e1000_release_hw_control - release control of the h/w to f/w
       
   403  * @adapter: address of board private structure
       
   404  *
       
   405  * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
       
   406  * For ASF and Pass Through versions of f/w this means that the
       
   407  * driver is no longer loaded. For AMT version (only with 82573) i
       
   408  * of the f/w this means that the network i/f is closed.
       
   409  *
       
   410  **/
       
   411 
       
   412 static void
       
   413 e1000_release_hw_control(struct e1000_adapter *adapter)
       
   414 {
       
   415 	uint32_t ctrl_ext;
       
   416 	uint32_t swsm;
       
   417 
       
   418 	/* Let firmware taken over control of h/w */
       
   419 	switch (adapter->hw.mac_type) {
       
   420 	case e1000_82573:
       
   421 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
       
   422 		E1000_WRITE_REG(&adapter->hw, SWSM,
       
   423 				swsm & ~E1000_SWSM_DRV_LOAD);
       
   424 		break;
       
   425 	case e1000_82571:
       
   426 	case e1000_82572:
       
   427 	case e1000_80003es2lan:
       
   428 	case e1000_ich8lan:
       
   429 		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
       
   430 		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
       
   431 				ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
       
   432 		break;
       
   433 	default:
       
   434 		break;
       
   435 	}
       
   436 }
       
   437 
       
   438 /**
       
   439  * e1000_get_hw_control - get control of the h/w from f/w
       
   440  * @adapter: address of board private structure
       
   441  *
       
   442  * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
       
   443  * For ASF and Pass Through versions of f/w this means that
       
   444  * the driver is loaded. For AMT version (only with 82573)
       
   445  * of the f/w this means that the network i/f is open.
       
   446  *
       
   447  **/
       
   448 
       
   449 static void
       
   450 e1000_get_hw_control(struct e1000_adapter *adapter)
       
   451 {
       
   452 	uint32_t ctrl_ext;
       
   453 	uint32_t swsm;
       
   454 
       
   455 	/* Let firmware know the driver has taken over */
       
   456 	switch (adapter->hw.mac_type) {
       
   457 	case e1000_82573:
       
   458 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
       
   459 		E1000_WRITE_REG(&adapter->hw, SWSM,
       
   460 				swsm | E1000_SWSM_DRV_LOAD);
       
   461 		break;
       
   462 	case e1000_82571:
       
   463 	case e1000_82572:
       
   464 	case e1000_80003es2lan:
       
   465 	case e1000_ich8lan:
       
   466 		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
       
   467 		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
       
   468 				ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
       
   469 		break;
       
   470 	default:
       
   471 		break;
       
   472 	}
       
   473 }
       
   474 
       
   475 static void
       
   476 e1000_init_manageability(struct e1000_adapter *adapter)
       
   477 {
       
   478 	if (adapter->en_mng_pt) {
       
   479 		uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
       
   480 
       
   481 		/* disable hardware interception of ARP */
       
   482 		manc &= ~(E1000_MANC_ARP_EN);
       
   483 
       
   484 		/* enable receiving management packets to the host */
       
   485 		/* this will probably generate destination unreachable messages
       
   486 		 * from the host OS, but the packets will be handled on SMBUS */
       
   487 		if (adapter->hw.has_manc2h) {
       
   488 			uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
       
   489 
       
   490 			manc |= E1000_MANC_EN_MNG2HOST;
       
   491 #define E1000_MNG2HOST_PORT_623 (1 << 5)
       
   492 #define E1000_MNG2HOST_PORT_664 (1 << 6)
       
   493 			manc2h |= E1000_MNG2HOST_PORT_623;
       
   494 			manc2h |= E1000_MNG2HOST_PORT_664;
       
   495 			E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
       
   496 		}
       
   497 
       
   498 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
       
   499 	}
       
   500 }
       
   501 
       
   502 static void
       
   503 e1000_release_manageability(struct e1000_adapter *adapter)
       
   504 {
       
   505 	if (adapter->en_mng_pt) {
       
   506 		uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
       
   507 
       
   508 		/* re-enable hardware interception of ARP */
       
   509 		manc |= E1000_MANC_ARP_EN;
       
   510 
       
   511 		if (adapter->hw.has_manc2h)
       
   512 			manc &= ~E1000_MANC_EN_MNG2HOST;
       
   513 
       
   514 		/* don't explicitly have to mess with MANC2H since
       
   515 		 * MANC has an enable disable that gates MANC2H */
       
   516 
       
   517 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
       
   518 	}
       
   519 }
       
   520 
       
   521 /**
       
   522  * e1000_configure - configure the hardware for RX and TX
       
   523  * @adapter = private board structure
       
   524  **/
       
   525 static void e1000_configure(struct e1000_adapter *adapter)
       
   526 {
       
   527 	struct net_device *netdev = adapter->netdev;
       
   528 	int i;
       
   529 
       
   530 	e1000_set_multi(netdev);
       
   531 
       
   532 	e1000_restore_vlan(adapter);
       
   533 	e1000_init_manageability(adapter);
       
   534 
       
   535 	e1000_configure_tx(adapter);
       
   536 	e1000_setup_rctl(adapter);
       
   537 	e1000_configure_rx(adapter);
       
   538 	/* call E1000_DESC_UNUSED which always leaves
       
   539 	 * at least 1 descriptor unused to make sure
       
   540 	 * next_to_use != next_to_clean */
       
   541 	for (i = 0; i < adapter->num_rx_queues; i++) {
       
   542 		struct e1000_rx_ring *ring = &adapter->rx_ring[i];
       
   543 		adapter->alloc_rx_buf(adapter, ring,
       
   544 		                      E1000_DESC_UNUSED(ring));
       
   545 	}
       
   546 
       
   547 	adapter->tx_queue_len = netdev->tx_queue_len;
       
   548 }
       
   549 
       
   550 int e1000_up(struct e1000_adapter *adapter)
       
   551 {
       
   552 	/* hardware has been reset, we need to reload some things */
       
   553 	e1000_configure(adapter);
       
   554 
       
   555 	clear_bit(__E1000_DOWN, &adapter->flags);
       
   556 
       
   557 	if (!adapter->ecdev) {
       
   558 #ifdef CONFIG_E1000_NAPI
       
   559 		netif_poll_enable(adapter->netdev);
       
   560 #endif
       
   561         e1000_irq_enable(adapter);
       
   562 
       
   563 		/* fire a link change interrupt to start the watchdog */
       
   564 		E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
       
   565     }
       
   566 	return 0;
       
   567 }
       
   568 
       
   569 /**
       
   570  * e1000_power_up_phy - restore link in case the phy was powered down
       
   571  * @adapter: address of board private structure
       
   572  *
       
   573  * The phy may be powered down to save power and turn off link when the
       
   574  * driver is unloaded and wake on lan is not enabled (among others)
       
   575  * *** this routine MUST be followed by a call to e1000_reset ***
       
   576  *
       
   577  **/
       
   578 
       
   579 void e1000_power_up_phy(struct e1000_adapter *adapter)
       
   580 {
       
   581 	uint16_t mii_reg = 0;
       
   582 
       
   583 	/* Just clear the power down bit to wake the phy back up */
       
   584 	if (adapter->hw.media_type == e1000_media_type_copper) {
       
   585 		/* according to the manual, the phy will retain its
       
   586 		 * settings across a power-down/up cycle */
       
   587 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
       
   588 		mii_reg &= ~MII_CR_POWER_DOWN;
       
   589 		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
       
   590 	}
       
   591 }
       
   592 
       
   593 static void e1000_power_down_phy(struct e1000_adapter *adapter)
       
   594 {
       
   595 	/* Power down the PHY so no link is implied when interface is down *
       
   596 	 * The PHY cannot be powered down if any of the following is TRUE *
       
   597 	 * (a) WoL is enabled
       
   598 	 * (b) AMT is active
       
   599 	 * (c) SoL/IDER session is active */
       
   600 	if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
       
   601 	   adapter->hw.media_type == e1000_media_type_copper) {
       
   602 		uint16_t mii_reg = 0;
       
   603 
       
   604 		switch (adapter->hw.mac_type) {
       
   605 		case e1000_82540:
       
   606 		case e1000_82545:
       
   607 		case e1000_82545_rev_3:
       
   608 		case e1000_82546:
       
   609 		case e1000_82546_rev_3:
       
   610 		case e1000_82541:
       
   611 		case e1000_82541_rev_2:
       
   612 		case e1000_82547:
       
   613 		case e1000_82547_rev_2:
       
   614 			if (E1000_READ_REG(&adapter->hw, MANC) &
       
   615 			    E1000_MANC_SMBUS_EN)
       
   616 				goto out;
       
   617 			break;
       
   618 		case e1000_82571:
       
   619 		case e1000_82572:
       
   620 		case e1000_82573:
       
   621 		case e1000_80003es2lan:
       
   622 		case e1000_ich8lan:
       
   623 			if (e1000_check_mng_mode(&adapter->hw) ||
       
   624 			    e1000_check_phy_reset_block(&adapter->hw))
       
   625 				goto out;
       
   626 			break;
       
   627 		default:
       
   628 			goto out;
       
   629 		}
       
   630 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
       
   631 		mii_reg |= MII_CR_POWER_DOWN;
       
   632 		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
       
   633 		mdelay(1);
       
   634 	}
       
   635 out:
       
   636 	return;
       
   637 }
       
   638 
       
   639 void
       
   640 e1000_down(struct e1000_adapter *adapter)
       
   641 {
       
   642 	struct net_device *netdev = adapter->netdev;
       
   643 
       
   644 	/* signal that we're down so the interrupt handler does not
       
   645 	 * reschedule our watchdog timer */
       
   646 	set_bit(__E1000_DOWN, &adapter->flags);
       
   647 
       
   648     if (!adapter->ecdev) {
       
   649 #ifdef CONFIG_E1000_NAPI
       
   650 		netif_poll_disable(netdev);
       
   651 #endif
       
   652 		e1000_irq_disable(adapter);
       
   653 
       
   654         del_timer_sync(&adapter->tx_fifo_stall_timer);
       
   655         del_timer_sync(&adapter->watchdog_timer);
       
   656         del_timer_sync(&adapter->phy_info_timer);
       
   657 	}
       
   658 
       
   659 	netdev->tx_queue_len = adapter->tx_queue_len;
       
   660 	adapter->link_speed = 0;
       
   661 	adapter->link_duplex = 0;
       
   662 	if (!adapter->ecdev) {
       
   663 		netif_carrier_off(netdev);
       
   664 		netif_stop_queue(netdev);
       
   665 	}
       
   666 
       
   667 	e1000_reset(adapter);
       
   668 	e1000_clean_all_tx_rings(adapter);
       
   669 	e1000_clean_all_rx_rings(adapter);
       
   670 }
       
   671 
       
   672 void
       
   673 e1000_reinit_locked(struct e1000_adapter *adapter)
       
   674 {
       
   675 	WARN_ON(in_interrupt());
       
   676 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
       
   677 		msleep(1);
       
   678 	e1000_down(adapter);
       
   679 	e1000_up(adapter);
       
   680 	clear_bit(__E1000_RESETTING, &adapter->flags);
       
   681 }
       
   682 
       
   683 void
       
   684 e1000_reset(struct e1000_adapter *adapter)
       
   685 {
       
   686 	uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
       
   687 	uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
       
   688 	boolean_t legacy_pba_adjust = FALSE;
       
   689 
       
   690 	/* Repartition Pba for greater than 9k mtu
       
   691 	 * To take effect CTRL.RST is required.
       
   692 	 */
       
   693 
       
   694 	switch (adapter->hw.mac_type) {
       
   695 	case e1000_82542_rev2_0:
       
   696 	case e1000_82542_rev2_1:
       
   697 	case e1000_82543:
       
   698 	case e1000_82544:
       
   699 	case e1000_82540:
       
   700 	case e1000_82541:
       
   701 	case e1000_82541_rev_2:
       
   702 		legacy_pba_adjust = TRUE;
       
   703 		pba = E1000_PBA_48K;
       
   704 		break;
       
   705 	case e1000_82545:
       
   706 	case e1000_82545_rev_3:
       
   707 	case e1000_82546:
       
   708 	case e1000_82546_rev_3:
       
   709 		pba = E1000_PBA_48K;
       
   710 		break;
       
   711 	case e1000_82547:
       
   712 	case e1000_82547_rev_2:
       
   713 		legacy_pba_adjust = TRUE;
       
   714 		pba = E1000_PBA_30K;
       
   715 		break;
       
   716 	case e1000_82571:
       
   717 	case e1000_82572:
       
   718 	case e1000_80003es2lan:
       
   719 		pba = E1000_PBA_38K;
       
   720 		break;
       
   721 	case e1000_82573:
       
   722 		pba = E1000_PBA_20K;
       
   723 		break;
       
   724 	case e1000_ich8lan:
       
   725 		pba = E1000_PBA_8K;
       
   726 	case e1000_undefined:
       
   727 	case e1000_num_macs:
       
   728 		break;
       
   729 	}
       
   730 
       
   731 	if (legacy_pba_adjust == TRUE) {
       
   732 		if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
       
   733 			pba -= 8; /* allocate more FIFO for Tx */
       
   734 
       
   735 		if (adapter->hw.mac_type == e1000_82547) {
       
   736 			adapter->tx_fifo_head = 0;
       
   737 			adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
       
   738 			adapter->tx_fifo_size =
       
   739 				(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
       
   740 			atomic_set(&adapter->tx_fifo_stall, 0);
       
   741 		}
       
   742 	} else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
       
   743 		/* adjust PBA for jumbo frames */
       
   744 		E1000_WRITE_REG(&adapter->hw, PBA, pba);
       
   745 
       
   746 		/* To maintain wire speed transmits, the Tx FIFO should be
       
   747 		 * large enough to accomodate two full transmit packets,
       
   748 		 * rounded up to the next 1KB and expressed in KB.  Likewise,
       
   749 		 * the Rx FIFO should be large enough to accomodate at least
       
   750 		 * one full receive packet and is similarly rounded up and
       
   751 		 * expressed in KB. */
       
   752 		pba = E1000_READ_REG(&adapter->hw, PBA);
       
   753 		/* upper 16 bits has Tx packet buffer allocation size in KB */
       
   754 		tx_space = pba >> 16;
       
   755 		/* lower 16 bits has Rx packet buffer allocation size in KB */
       
   756 		pba &= 0xffff;
       
   757 		/* don't include ethernet FCS because hardware appends/strips */
       
   758 		min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
       
   759 		               VLAN_TAG_SIZE;
       
   760 		min_tx_space = min_rx_space;
       
   761 		min_tx_space *= 2;
       
   762 		min_tx_space = ALIGN(min_tx_space, 1024);
       
   763 		min_tx_space >>= 10;
       
   764 		min_rx_space = ALIGN(min_rx_space, 1024);
       
   765 		min_rx_space >>= 10;
       
   766 
       
   767 		/* If current Tx allocation is less than the min Tx FIFO size,
       
   768 		 * and the min Tx FIFO size is less than the current Rx FIFO
       
   769 		 * allocation, take space away from current Rx allocation */
       
   770 		if (tx_space < min_tx_space &&
       
   771 		    ((min_tx_space - tx_space) < pba)) {
       
   772 			pba = pba - (min_tx_space - tx_space);
       
   773 
       
   774 			/* PCI/PCIx hardware has PBA alignment constraints */
       
   775 			switch (adapter->hw.mac_type) {
       
   776 			case e1000_82545 ... e1000_82546_rev_3:
       
   777 				pba &= ~(E1000_PBA_8K - 1);
       
   778 				break;
       
   779 			default:
       
   780 				break;
       
   781 			}
       
   782 
       
   783 			/* if short on rx space, rx wins and must trump tx
       
   784 			 * adjustment or use Early Receive if available */
       
   785 			if (pba < min_rx_space) {
       
   786 				switch (adapter->hw.mac_type) {
       
   787 				case e1000_82573:
       
   788 					/* ERT enabled in e1000_configure_rx */
       
   789 					break;
       
   790 				default:
       
   791 					pba = min_rx_space;
       
   792 					break;
       
   793 				}
       
   794 			}
       
   795 		}
       
   796 	}
       
   797 
       
   798 	E1000_WRITE_REG(&adapter->hw, PBA, pba);
       
   799 
       
   800 	/* flow control settings */
       
   801 	/* Set the FC high water mark to 90% of the FIFO size.
       
   802 	 * Required to clear last 3 LSB */
       
   803 	fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
       
   804 	/* We can't use 90% on small FIFOs because the remainder
       
   805 	 * would be less than 1 full frame.  In this case, we size
       
   806 	 * it to allow at least a full frame above the high water
       
   807 	 *  mark. */
       
   808 	if (pba < E1000_PBA_16K)
       
   809 		fc_high_water_mark = (pba * 1024) - 1600;
       
   810 
       
   811 	adapter->hw.fc_high_water = fc_high_water_mark;
       
   812 	adapter->hw.fc_low_water = fc_high_water_mark - 8;
       
   813 	if (adapter->hw.mac_type == e1000_80003es2lan)
       
   814 		adapter->hw.fc_pause_time = 0xFFFF;
       
   815 	else
       
   816 		adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
       
   817 	adapter->hw.fc_send_xon = 1;
       
   818 	adapter->hw.fc = adapter->hw.original_fc;
       
   819 
       
   820 	/* Allow time for pending master requests to run */
       
   821 	e1000_reset_hw(&adapter->hw);
       
   822 	if (adapter->hw.mac_type >= e1000_82544)
       
   823 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
       
   824 
       
   825 	if (e1000_init_hw(&adapter->hw))
       
   826 		DPRINTK(PROBE, ERR, "Hardware Error\n");
       
   827 	e1000_update_mng_vlan(adapter);
       
   828 
       
   829 	/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
       
   830 	if (adapter->hw.mac_type >= e1000_82544 &&
       
   831 	    adapter->hw.mac_type <= e1000_82547_rev_2 &&
       
   832 	    adapter->hw.autoneg == 1 &&
       
   833 	    adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
       
   834 		uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
       
   835 		/* clear phy power management bit if we are in gig only mode,
       
   836 		 * which if enabled will attempt negotiation to 100Mb, which
       
   837 		 * can cause a loss of link at power off or driver unload */
       
   838 		ctrl &= ~E1000_CTRL_SWDPIN3;
       
   839 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
       
   840 	}
       
   841 
       
   842 	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
       
   843 	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
       
   844 
       
   845 	e1000_reset_adaptive(&adapter->hw);
       
   846 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
       
   847 
       
   848 	if (!adapter->smart_power_down &&
       
   849 	    (adapter->hw.mac_type == e1000_82571 ||
       
   850 	     adapter->hw.mac_type == e1000_82572)) {
       
   851 		uint16_t phy_data = 0;
       
   852 		/* speed up time to link by disabling smart power down, ignore
       
   853 		 * the return value of this function because there is nothing
       
   854 		 * different we would do if it failed */
       
   855 		e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
       
   856 		                   &phy_data);
       
   857 		phy_data &= ~IGP02E1000_PM_SPD;
       
   858 		e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
       
   859 		                    phy_data);
       
   860 	}
       
   861 
       
   862 	e1000_release_manageability(adapter);
       
   863 }
       
   864 
       
   865 /**
       
   866  * e1000_probe - Device Initialization Routine
       
   867  * @pdev: PCI device information struct
       
   868  * @ent: entry in e1000_pci_tbl
       
   869  *
       
   870  * Returns 0 on success, negative on failure
       
   871  *
       
   872  * e1000_probe initializes an adapter identified by a pci_dev structure.
       
   873  * The OS initialization, configuring of the adapter private structure,
       
   874  * and a hardware reset occur.
       
   875  **/
       
   876 
       
   877 static int __devinit
       
   878 e1000_probe(struct pci_dev *pdev,
       
   879             const struct pci_device_id *ent)
       
   880 {
       
   881 	struct net_device *netdev;
       
   882 	struct e1000_adapter *adapter;
       
   883 	unsigned long mmio_start, mmio_len;
       
   884 	unsigned long flash_start, flash_len;
       
   885 
       
   886 	static int cards_found = 0;
       
   887 	static int global_quad_port_a = 0; /* global ksp3 port a indication */
       
   888 	int i, err, pci_using_dac;
       
   889 	uint16_t eeprom_data = 0;
       
   890 	uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
       
   891 	if ((err = pci_enable_device(pdev)))
       
   892 		return err;
       
   893 
       
   894 	if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
       
   895 	    !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
       
   896 		pci_using_dac = 1;
       
   897 	} else {
       
   898 		if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
       
   899 		    (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
       
   900 			E1000_ERR("No usable DMA configuration, aborting\n");
       
   901 			goto err_dma;
       
   902 		}
       
   903 		pci_using_dac = 0;
       
   904 	}
       
   905 
       
   906 	if ((err = pci_request_regions(pdev, e1000_driver_name)))
       
   907 		goto err_pci_reg;
       
   908 
       
   909 	pci_set_master(pdev);
       
   910 
       
   911 	err = -ENOMEM;
       
   912 	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
       
   913 	if (!netdev)
       
   914 		goto err_alloc_etherdev;
       
   915 
       
   916 	SET_MODULE_OWNER(netdev);
       
   917 	SET_NETDEV_DEV(netdev, &pdev->dev);
       
   918 
       
   919 	pci_set_drvdata(pdev, netdev);
       
   920 	adapter = netdev_priv(netdev);
       
   921 	adapter->netdev = netdev;
       
   922 	adapter->pdev = pdev;
       
   923 	adapter->hw.back = adapter;
       
   924 	adapter->msg_enable = (1 << debug) - 1;
       
   925 
       
   926 	mmio_start = pci_resource_start(pdev, BAR_0);
       
   927 	mmio_len = pci_resource_len(pdev, BAR_0);
       
   928 
       
   929 	err = -EIO;
       
   930 	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
       
   931 	if (!adapter->hw.hw_addr)
       
   932 		goto err_ioremap;
       
   933 
       
   934 	for (i = BAR_1; i <= BAR_5; i++) {
       
   935 		if (pci_resource_len(pdev, i) == 0)
       
   936 			continue;
       
   937 		if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
       
   938 			adapter->hw.io_base = pci_resource_start(pdev, i);
       
   939 			break;
       
   940 		}
       
   941 	}
       
   942 
       
   943 	netdev->open = &e1000_open;
       
   944 	netdev->stop = &e1000_close;
       
   945 	netdev->hard_start_xmit = &e1000_xmit_frame;
       
   946 	netdev->get_stats = &e1000_get_stats;
       
   947 	netdev->set_multicast_list = &e1000_set_multi;
       
   948 	netdev->set_mac_address = &e1000_set_mac;
       
   949 	netdev->change_mtu = &e1000_change_mtu;
       
   950 	netdev->do_ioctl = &e1000_ioctl;
       
   951 	e1000_set_ethtool_ops(netdev);
       
   952 	netdev->tx_timeout = &e1000_tx_timeout;
       
   953 	netdev->watchdog_timeo = 5 * HZ;
       
   954 #ifdef CONFIG_E1000_NAPI
       
   955 	netdev->poll = &e1000_clean;
       
   956 	netdev->weight = 64;
       
   957 #endif
       
   958 	netdev->vlan_rx_register = e1000_vlan_rx_register;
       
   959 	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
       
   960 	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
       
   961 #ifdef CONFIG_NET_POLL_CONTROLLER
       
   962 	netdev->poll_controller = e1000_netpoll;
       
   963 #endif
       
   964 	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
       
   965 
       
   966 	netdev->mem_start = mmio_start;
       
   967 	netdev->mem_end = mmio_start + mmio_len;
       
   968 	netdev->base_addr = adapter->hw.io_base;
       
   969 
       
   970 	adapter->bd_number = cards_found;
       
   971 
       
   972 	/* setup the private structure */
       
   973 
       
   974 	if ((err = e1000_sw_init(adapter)))
       
   975 		goto err_sw_init;
       
   976 
       
   977 	err = -EIO;
       
   978 	/* Flash BAR mapping must happen after e1000_sw_init
       
   979 	 * because it depends on mac_type */
       
   980 	if ((adapter->hw.mac_type == e1000_ich8lan) &&
       
   981 	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
       
   982 		flash_start = pci_resource_start(pdev, 1);
       
   983 		flash_len = pci_resource_len(pdev, 1);
       
   984 		adapter->hw.flash_address = ioremap(flash_start, flash_len);
       
   985 		if (!adapter->hw.flash_address)
       
   986 			goto err_flashmap;
       
   987 	}
       
   988 
       
   989 	if (e1000_check_phy_reset_block(&adapter->hw))
       
   990 		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
       
   991 
       
   992 	if (adapter->hw.mac_type >= e1000_82543) {
       
   993 		netdev->features = NETIF_F_SG |
       
   994 				   NETIF_F_HW_CSUM |
       
   995 				   NETIF_F_HW_VLAN_TX |
       
   996 				   NETIF_F_HW_VLAN_RX |
       
   997 				   NETIF_F_HW_VLAN_FILTER;
       
   998 		if (adapter->hw.mac_type == e1000_ich8lan)
       
   999 			netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
       
  1000 	}
       
  1001 
       
  1002 	if ((adapter->hw.mac_type >= e1000_82544) &&
       
  1003 	   (adapter->hw.mac_type != e1000_82547))
       
  1004 		netdev->features |= NETIF_F_TSO;
       
  1005 
       
  1006 	if (adapter->hw.mac_type > e1000_82547_rev_2)
       
  1007 		netdev->features |= NETIF_F_TSO6;
       
  1008 	if (pci_using_dac)
       
  1009 		netdev->features |= NETIF_F_HIGHDMA;
       
  1010 
       
  1011 	netdev->features |= NETIF_F_LLTX;
       
  1012 
       
  1013 	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
       
  1014 
       
  1015 	/* initialize eeprom parameters */
       
  1016 
       
  1017 	if (e1000_init_eeprom_params(&adapter->hw)) {
       
  1018 		E1000_ERR("EEPROM initialization failed\n");
       
  1019 		goto err_eeprom;
       
  1020 	}
       
  1021 
       
  1022 	/* before reading the EEPROM, reset the controller to
       
  1023 	 * put the device in a known good starting state */
       
  1024 
       
  1025 	e1000_reset_hw(&adapter->hw);
       
  1026 
       
  1027 	/* make sure the EEPROM is good */
       
  1028 
       
  1029 	if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
       
  1030 		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
       
  1031 		goto err_eeprom;
       
  1032 	}
       
  1033 
       
  1034 	/* copy the MAC address out of the EEPROM */
       
  1035 
       
  1036 	if (e1000_read_mac_addr(&adapter->hw))
       
  1037 		DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
       
  1038 	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
       
  1039 	memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
       
  1040 
       
  1041 	if (!is_valid_ether_addr(netdev->perm_addr)) {
       
  1042 		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
       
  1043 		goto err_eeprom;
       
  1044 	}
       
  1045 
       
  1046 	e1000_get_bus_info(&adapter->hw);
       
  1047 
       
  1048 	init_timer(&adapter->tx_fifo_stall_timer);
       
  1049 	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
       
  1050 	adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
       
  1051 
       
  1052 	init_timer(&adapter->watchdog_timer);
       
  1053 	adapter->watchdog_timer.function = &e1000_watchdog;
       
  1054 	adapter->watchdog_timer.data = (unsigned long) adapter;
       
  1055 
       
  1056 	init_timer(&adapter->phy_info_timer);
       
  1057 	adapter->phy_info_timer.function = &e1000_update_phy_info;
       
  1058 	adapter->phy_info_timer.data = (unsigned long) adapter;
       
  1059 
       
  1060 	INIT_WORK(&adapter->reset_task, e1000_reset_task);
       
  1061 
       
  1062 	e1000_check_options(adapter);
       
  1063 
       
  1064 	/* Initial Wake on LAN setting
       
  1065 	 * If APM wake is enabled in the EEPROM,
       
  1066 	 * enable the ACPI Magic Packet filter
       
  1067 	 */
       
  1068 
       
  1069 	switch (adapter->hw.mac_type) {
       
  1070 	case e1000_82542_rev2_0:
       
  1071 	case e1000_82542_rev2_1:
       
  1072 	case e1000_82543:
       
  1073 		break;
       
  1074 	case e1000_82544:
       
  1075 		e1000_read_eeprom(&adapter->hw,
       
  1076 			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
       
  1077 		eeprom_apme_mask = E1000_EEPROM_82544_APM;
       
  1078 		break;
       
  1079 	case e1000_ich8lan:
       
  1080 		e1000_read_eeprom(&adapter->hw,
       
  1081 			EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
       
  1082 		eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
       
  1083 		break;
       
  1084 	case e1000_82546:
       
  1085 	case e1000_82546_rev_3:
       
  1086 	case e1000_82571:
       
  1087 	case e1000_80003es2lan:
       
  1088 		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
       
  1089 			e1000_read_eeprom(&adapter->hw,
       
  1090 				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
       
  1091 			break;
       
  1092 		}
       
  1093 		/* Fall Through */
       
  1094 	default:
       
  1095 		e1000_read_eeprom(&adapter->hw,
       
  1096 			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
       
  1097 		break;
       
  1098 	}
       
  1099 	if (eeprom_data & eeprom_apme_mask)
       
  1100 		adapter->eeprom_wol |= E1000_WUFC_MAG;
       
  1101 
       
  1102 	/* now that we have the eeprom settings, apply the special cases
       
  1103 	 * where the eeprom may be wrong or the board simply won't support
       
  1104 	 * wake on lan on a particular port */
       
  1105 	switch (pdev->device) {
       
  1106 	case E1000_DEV_ID_82546GB_PCIE:
       
  1107 		adapter->eeprom_wol = 0;
       
  1108 		break;
       
  1109 	case E1000_DEV_ID_82546EB_FIBER:
       
  1110 	case E1000_DEV_ID_82546GB_FIBER:
       
  1111 	case E1000_DEV_ID_82571EB_FIBER:
       
  1112 		/* Wake events only supported on port A for dual fiber
       
  1113 		 * regardless of eeprom setting */
       
  1114 		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
       
  1115 			adapter->eeprom_wol = 0;
       
  1116 		break;
       
  1117 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
       
  1118 	case E1000_DEV_ID_82571EB_QUAD_COPPER:
       
  1119 	case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
       
  1120 		/* if quad port adapter, disable WoL on all but port A */
       
  1121 		if (global_quad_port_a != 0)
       
  1122 			adapter->eeprom_wol = 0;
       
  1123 		else
       
  1124 			adapter->quad_port_a = 1;
       
  1125 		/* Reset for multiple quad port adapters */
       
  1126 		if (++global_quad_port_a == 4)
       
  1127 			global_quad_port_a = 0;
       
  1128 		break;
       
  1129 	}
       
  1130 
       
  1131 	/* initialize the wol settings based on the eeprom settings */
       
  1132 	adapter->wol = adapter->eeprom_wol;
       
  1133 
       
  1134 	/* print bus type/speed/width info */
       
  1135 	{
       
  1136 	struct e1000_hw *hw = &adapter->hw;
       
  1137 	DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
       
  1138 		((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
       
  1139 		 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
       
  1140 		((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
       
  1141 		 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
       
  1142 		 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
       
  1143 		 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
       
  1144 		 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
       
  1145 		((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
       
  1146 		 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
       
  1147 		 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
       
  1148 		 "32-bit"));
       
  1149 	}
       
  1150 
       
  1151 	for (i = 0; i < 6; i++)
       
  1152 		printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
       
  1153 
       
  1154 	/* reset the hardware with the new settings */
       
  1155 	e1000_reset(adapter);
       
  1156 
       
  1157 	/* If the controller is 82573 and f/w is AMT, do not set
       
  1158 	 * DRV_LOAD until the interface is up.  For all other cases,
       
  1159 	 * let the f/w know that the h/w is now under the control
       
  1160 	 * of the driver. */
       
  1161 	if (adapter->hw.mac_type != e1000_82573 ||
       
  1162 	    !e1000_check_mng_mode(&adapter->hw))
       
  1163 		e1000_get_hw_control(adapter);
       
  1164 
       
  1165 	// offer device to EtherCAT master module
       
  1166 	if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) {
       
  1167 		DPRINTK(PROBE, ERR, "Failed to offer device.\n");
       
  1168 		goto err_register;
       
  1169 	}
       
  1170 
       
  1171 	if (adapter->ecdev) {
       
  1172 		if (ecdev_open(adapter->ecdev)) {
       
  1173 			ecdev_withdraw(adapter->ecdev);
       
  1174 			goto err_register;
       
  1175 		}
       
  1176 	} else {
       
  1177 		/* tell the stack to leave us alone until e1000_open() is called */
       
  1178 		netif_carrier_off(netdev);
       
  1179 		netif_stop_queue(netdev);
       
  1180 #ifdef CONFIG_E1000_NAPI
       
  1181 		netif_poll_disable(netdev);
       
  1182 #endif
       
  1183 
       
  1184 		strcpy(netdev->name, "eth%d");
       
  1185 		if ((err = register_netdev(netdev)))
       
  1186 			goto err_register;
       
  1187 	}
       
  1188 
       
  1189 	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
       
  1190 
       
  1191 	cards_found++;
       
  1192 	return 0;
       
  1193 
       
  1194 err_register:
       
  1195 	e1000_release_hw_control(adapter);
       
  1196 err_eeprom:
       
  1197 	if (!e1000_check_phy_reset_block(&adapter->hw))
       
  1198 		e1000_phy_hw_reset(&adapter->hw);
       
  1199 
       
  1200 	if (adapter->hw.flash_address)
       
  1201 		iounmap(adapter->hw.flash_address);
       
  1202 err_flashmap:
       
  1203 #ifdef CONFIG_E1000_NAPI
       
  1204 	for (i = 0; i < adapter->num_rx_queues; i++)
       
  1205 		dev_put(&adapter->polling_netdev[i]);
       
  1206 #endif
       
  1207 
       
  1208 	kfree(adapter->tx_ring);
       
  1209 	kfree(adapter->rx_ring);
       
  1210 #ifdef CONFIG_E1000_NAPI
       
  1211 	kfree(adapter->polling_netdev);
       
  1212 #endif
       
  1213 err_sw_init:
       
  1214 	iounmap(adapter->hw.hw_addr);
       
  1215 err_ioremap:
       
  1216 	free_netdev(netdev);
       
  1217 err_alloc_etherdev:
       
  1218 	pci_release_regions(pdev);
       
  1219 err_pci_reg:
       
  1220 err_dma:
       
  1221 	pci_disable_device(pdev);
       
  1222 	return err;
       
  1223 }
       
  1224 
       
  1225 /**
       
  1226  * e1000_remove - Device Removal Routine
       
  1227  * @pdev: PCI device information struct
       
  1228  *
       
  1229  * e1000_remove is called by the PCI subsystem to alert the driver
       
  1230  * that it should release a PCI device.  The could be caused by a
       
  1231  * Hot-Plug event, or because the driver is going to be removed from
       
  1232  * memory.
       
  1233  **/
       
  1234 
       
  1235 static void __devexit
       
  1236 e1000_remove(struct pci_dev *pdev)
       
  1237 {
       
  1238 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  1239 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1240 #ifdef CONFIG_E1000_NAPI
       
  1241 	int i;
       
  1242 #endif
       
  1243 
       
  1244 	cancel_work_sync(&adapter->reset_task);
       
  1245 
       
  1246 	e1000_release_manageability(adapter);
       
  1247 
       
  1248 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
       
  1249 	 * would have already happened in close and is redundant. */
       
  1250 	e1000_release_hw_control(adapter);
       
  1251 
       
  1252 	if (adapter->ecdev) {
       
  1253 		ecdev_close(adapter->ecdev);
       
  1254 		ecdev_withdraw(adapter->ecdev);
       
  1255 	} else {
       
  1256 		unregister_netdev(netdev);
       
  1257 	}
       
  1258 #ifdef CONFIG_E1000_NAPI
       
  1259 	for (i = 0; i < adapter->num_rx_queues; i++)
       
  1260 		dev_put(&adapter->polling_netdev[i]);
       
  1261 #endif
       
  1262 
       
  1263 	if (!e1000_check_phy_reset_block(&adapter->hw))
       
  1264 		e1000_phy_hw_reset(&adapter->hw);
       
  1265 
       
  1266 	kfree(adapter->tx_ring);
       
  1267 	kfree(adapter->rx_ring);
       
  1268 #ifdef CONFIG_E1000_NAPI
       
  1269 	kfree(adapter->polling_netdev);
       
  1270 #endif
       
  1271 
       
  1272 	iounmap(adapter->hw.hw_addr);
       
  1273 	if (adapter->hw.flash_address)
       
  1274 		iounmap(adapter->hw.flash_address);
       
  1275 	pci_release_regions(pdev);
       
  1276 
       
  1277 	free_netdev(netdev);
       
  1278 
       
  1279 	pci_disable_device(pdev);
       
  1280 }
       
  1281 
       
  1282 /**
       
  1283  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
       
  1284  * @adapter: board private structure to initialize
       
  1285  *
       
  1286  * e1000_sw_init initializes the Adapter private data structure.
       
  1287  * Fields are initialized based on PCI device information and
       
  1288  * OS network device settings (MTU size).
       
  1289  **/
       
  1290 
       
  1291 static int __devinit
       
  1292 e1000_sw_init(struct e1000_adapter *adapter)
       
  1293 {
       
  1294 	struct e1000_hw *hw = &adapter->hw;
       
  1295 	struct net_device *netdev = adapter->netdev;
       
  1296 	struct pci_dev *pdev = adapter->pdev;
       
  1297 #ifdef CONFIG_E1000_NAPI
       
  1298 	int i;
       
  1299 #endif
       
  1300 
       
  1301 	/* PCI config space info */
       
  1302 
       
  1303 	hw->vendor_id = pdev->vendor;
       
  1304 	hw->device_id = pdev->device;
       
  1305 	hw->subsystem_vendor_id = pdev->subsystem_vendor;
       
  1306 	hw->subsystem_id = pdev->subsystem_device;
       
  1307 
       
  1308 	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
       
  1309 
       
  1310 	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
       
  1311 
       
  1312 	adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
       
  1313 	adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
       
  1314 	hw->max_frame_size = netdev->mtu +
       
  1315 			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
       
  1316 	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
       
  1317 
       
  1318 	/* identify the MAC */
       
  1319 
       
  1320 	if (e1000_set_mac_type(hw)) {
       
  1321 		DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
       
  1322 		return -EIO;
       
  1323 	}
       
  1324 
       
  1325 	switch (hw->mac_type) {
       
  1326 	default:
       
  1327 		break;
       
  1328 	case e1000_82541:
       
  1329 	case e1000_82547:
       
  1330 	case e1000_82541_rev_2:
       
  1331 	case e1000_82547_rev_2:
       
  1332 		hw->phy_init_script = 1;
       
  1333 		break;
       
  1334 	}
       
  1335 
       
  1336 	e1000_set_media_type(hw);
       
  1337 
       
  1338 	hw->wait_autoneg_complete = FALSE;
       
  1339 	hw->tbi_compatibility_en = TRUE;
       
  1340 	hw->adaptive_ifs = TRUE;
       
  1341 
       
  1342 	/* Copper options */
       
  1343 
       
  1344 	if (hw->media_type == e1000_media_type_copper) {
       
  1345 		hw->mdix = AUTO_ALL_MODES;
       
  1346 		hw->disable_polarity_correction = FALSE;
       
  1347 		hw->master_slave = E1000_MASTER_SLAVE;
       
  1348 	}
       
  1349 
       
  1350 	adapter->num_tx_queues = 1;
       
  1351 	adapter->num_rx_queues = 1;
       
  1352 
       
  1353 	if (e1000_alloc_queues(adapter)) {
       
  1354 		DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
       
  1355 		return -ENOMEM;
       
  1356 	}
       
  1357 
       
  1358 #ifdef CONFIG_E1000_NAPI
       
  1359 	for (i = 0; i < adapter->num_rx_queues; i++) {
       
  1360 		adapter->polling_netdev[i].priv = adapter;
       
  1361 		adapter->polling_netdev[i].poll = &e1000_clean;
       
  1362 		adapter->polling_netdev[i].weight = 64;
       
  1363 		dev_hold(&adapter->polling_netdev[i]);
       
  1364 		set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
       
  1365 	}
       
  1366 	spin_lock_init(&adapter->tx_queue_lock);
       
  1367 #endif
       
  1368 
       
  1369 	/* Explicitly disable IRQ since the NIC can be in any state. */
       
  1370 	atomic_set(&adapter->irq_sem, 0);
       
  1371 	e1000_irq_disable(adapter);
       
  1372 
       
  1373 	spin_lock_init(&adapter->stats_lock);
       
  1374 
       
  1375 	set_bit(__E1000_DOWN, &adapter->flags);
       
  1376 
       
  1377 	return 0;
       
  1378 }
       
  1379 
       
  1380 /**
       
  1381  * e1000_alloc_queues - Allocate memory for all rings
       
  1382  * @adapter: board private structure to initialize
       
  1383  *
       
  1384  * We allocate one ring per queue at run-time since we don't know the
       
  1385  * number of queues at compile-time.  The polling_netdev array is
       
  1386  * intended for Multiqueue, but should work fine with a single queue.
       
  1387  **/
       
  1388 
       
  1389 static int __devinit
       
  1390 e1000_alloc_queues(struct e1000_adapter *adapter)
       
  1391 {
       
  1392 	adapter->tx_ring = kcalloc(adapter->num_tx_queues,
       
  1393 	                           sizeof(struct e1000_tx_ring), GFP_KERNEL);
       
  1394 	if (!adapter->tx_ring)
       
  1395 		return -ENOMEM;
       
  1396 
       
  1397 	adapter->rx_ring = kcalloc(adapter->num_rx_queues,
       
  1398 	                           sizeof(struct e1000_rx_ring), GFP_KERNEL);
       
  1399 	if (!adapter->rx_ring) {
       
  1400 		kfree(adapter->tx_ring);
       
  1401 		return -ENOMEM;
       
  1402 	}
       
  1403 
       
  1404 #ifdef CONFIG_E1000_NAPI
       
  1405 	adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
       
  1406 	                                  sizeof(struct net_device),
       
  1407 	                                  GFP_KERNEL);
       
  1408 	if (!adapter->polling_netdev) {
       
  1409 		kfree(adapter->tx_ring);
       
  1410 		kfree(adapter->rx_ring);
       
  1411 		return -ENOMEM;
       
  1412 	}
       
  1413 #endif
       
  1414 
       
  1415 	return E1000_SUCCESS;
       
  1416 }
       
  1417 
       
  1418 /**
       
  1419  * e1000_open - Called when a network interface is made active
       
  1420  * @netdev: network interface device structure
       
  1421  *
       
  1422  * Returns 0 on success, negative value on failure
       
  1423  *
       
  1424  * The open entry point is called when a network interface is made
       
  1425  * active by the system (IFF_UP).  At this point all resources needed
       
  1426  * for transmit and receive operations are allocated, the interrupt
       
  1427  * handler is registered with the OS, the watchdog timer is started,
       
  1428  * and the stack is notified that the interface is ready.
       
  1429  **/
       
  1430 
       
  1431 static int
       
  1432 e1000_open(struct net_device *netdev)
       
  1433 {
       
  1434 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1435 	int err;
       
  1436 
       
  1437 	/* disallow open during test */
       
  1438 	if (test_bit(__E1000_TESTING, &adapter->flags))
       
  1439 		return -EBUSY;
       
  1440 
       
  1441 	/* allocate transmit descriptors */
       
  1442 	err = e1000_setup_all_tx_resources(adapter);
       
  1443 	if (err)
       
  1444 		goto err_setup_tx;
       
  1445 
       
  1446 	/* allocate receive descriptors */
       
  1447 	err = e1000_setup_all_rx_resources(adapter);
       
  1448 	if (err)
       
  1449 		goto err_setup_rx;
       
  1450 
       
  1451 	e1000_power_up_phy(adapter);
       
  1452 
       
  1453 	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
       
  1454 	if ((adapter->hw.mng_cookie.status &
       
  1455 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
       
  1456 		e1000_update_mng_vlan(adapter);
       
  1457 	}
       
  1458 
       
  1459 	/* If AMT is enabled, let the firmware know that the network
       
  1460 	 * interface is now open */
       
  1461 	if (adapter->hw.mac_type == e1000_82573 &&
       
  1462 	    e1000_check_mng_mode(&adapter->hw))
       
  1463 		e1000_get_hw_control(adapter);
       
  1464 
       
  1465 	/* before we allocate an interrupt, we must be ready to handle it.
       
  1466 	 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
       
  1467 	 * as soon as we call pci_request_irq, so we have to setup our
       
  1468 	 * clean_rx handler before we do so.  */
       
  1469 	e1000_configure(adapter);
       
  1470 
       
  1471 	err = e1000_request_irq(adapter);
       
  1472 	if (err)
       
  1473 		goto err_req_irq;
       
  1474 
       
  1475 	/* From here on the code is the same as e1000_up() */
       
  1476 	clear_bit(__E1000_DOWN, &adapter->flags);
       
  1477 
       
  1478 #ifdef CONFIG_E1000_NAPI
       
  1479     if (!adapter->ecdev)
       
  1480 		netif_poll_enable(netdev);
       
  1481 #endif
       
  1482 
       
  1483 	e1000_irq_enable(adapter);
       
  1484 
       
  1485 	/* fire a link status change interrupt to start the watchdog */
       
  1486 	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
       
  1487 
       
  1488 	return E1000_SUCCESS;
       
  1489 
       
  1490 err_req_irq:
       
  1491 	e1000_release_hw_control(adapter);
       
  1492 	e1000_power_down_phy(adapter);
       
  1493 	e1000_free_all_rx_resources(adapter);
       
  1494 err_setup_rx:
       
  1495 	e1000_free_all_tx_resources(adapter);
       
  1496 err_setup_tx:
       
  1497 	e1000_reset(adapter);
       
  1498 
       
  1499 	return err;
       
  1500 }
       
  1501 
       
  1502 /**
       
  1503  * e1000_close - Disables a network interface
       
  1504  * @netdev: network interface device structure
       
  1505  *
       
  1506  * Returns 0, this is not allowed to fail
       
  1507  *
       
  1508  * The close entry point is called when an interface is de-activated
       
  1509  * by the OS.  The hardware is still under the drivers control, but
       
  1510  * needs to be disabled.  A global MAC reset is issued to stop the
       
  1511  * hardware, and all transmit and receive resources are freed.
       
  1512  **/
       
  1513 
       
  1514 static int
       
  1515 e1000_close(struct net_device *netdev)
       
  1516 {
       
  1517 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1518 
       
  1519 	WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
       
  1520 	e1000_down(adapter);
       
  1521 	e1000_power_down_phy(adapter);
       
  1522 	e1000_free_irq(adapter);
       
  1523 
       
  1524 	e1000_free_all_tx_resources(adapter);
       
  1525 	e1000_free_all_rx_resources(adapter);
       
  1526 
       
  1527 	/* kill manageability vlan ID if supported, but not if a vlan with
       
  1528 	 * the same ID is registered on the host OS (let 8021q kill it) */
       
  1529 	if ((adapter->hw.mng_cookie.status &
       
  1530 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
       
  1531 	     !(adapter->vlgrp &&
       
  1532 	       vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
       
  1533 		e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
       
  1534 	}
       
  1535 
       
  1536 	/* If AMT is enabled, let the firmware know that the network
       
  1537 	 * interface is now closed */
       
  1538 	if (adapter->hw.mac_type == e1000_82573 &&
       
  1539 	    e1000_check_mng_mode(&adapter->hw))
       
  1540 		e1000_release_hw_control(adapter);
       
  1541 
       
  1542 	return 0;
       
  1543 }
       
  1544 
       
  1545 /**
       
  1546  * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
       
  1547  * @adapter: address of board private structure
       
  1548  * @start: address of beginning of memory
       
  1549  * @len: length of memory
       
  1550  **/
       
  1551 static boolean_t
       
  1552 e1000_check_64k_bound(struct e1000_adapter *adapter,
       
  1553 		      void *start, unsigned long len)
       
  1554 {
       
  1555 	unsigned long begin = (unsigned long) start;
       
  1556 	unsigned long end = begin + len;
       
  1557 
       
  1558 	/* First rev 82545 and 82546 need to not allow any memory
       
  1559 	 * write location to cross 64k boundary due to errata 23 */
       
  1560 	if (adapter->hw.mac_type == e1000_82545 ||
       
  1561 	    adapter->hw.mac_type == e1000_82546) {
       
  1562 		return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
       
  1563 	}
       
  1564 
       
  1565 	return TRUE;
       
  1566 }
       
  1567 
       
  1568 /**
       
  1569  * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
       
  1570  * @adapter: board private structure
       
  1571  * @txdr:    tx descriptor ring (for a specific queue) to setup
       
  1572  *
       
  1573  * Return 0 on success, negative on failure
       
  1574  **/
       
  1575 
       
  1576 static int
       
  1577 e1000_setup_tx_resources(struct e1000_adapter *adapter,
       
  1578                          struct e1000_tx_ring *txdr)
       
  1579 {
       
  1580 	struct pci_dev *pdev = adapter->pdev;
       
  1581 	int size;
       
  1582 
       
  1583 	size = sizeof(struct e1000_buffer) * txdr->count;
       
  1584 	txdr->buffer_info = vmalloc(size);
       
  1585 	if (!txdr->buffer_info) {
       
  1586 		DPRINTK(PROBE, ERR,
       
  1587 		"Unable to allocate memory for the transmit descriptor ring\n");
       
  1588 		return -ENOMEM;
       
  1589 	}
       
  1590 	memset(txdr->buffer_info, 0, size);
       
  1591 
       
  1592 	/* round up to nearest 4K */
       
  1593 
       
  1594 	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
       
  1595 	txdr->size = ALIGN(txdr->size, 4096);
       
  1596 
       
  1597 	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
       
  1598 	if (!txdr->desc) {
       
  1599 setup_tx_desc_die:
       
  1600 		vfree(txdr->buffer_info);
       
  1601 		DPRINTK(PROBE, ERR,
       
  1602 		"Unable to allocate memory for the transmit descriptor ring\n");
       
  1603 		return -ENOMEM;
       
  1604 	}
       
  1605 
       
  1606 	/* Fix for errata 23, can't cross 64kB boundary */
       
  1607 	if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
       
  1608 		void *olddesc = txdr->desc;
       
  1609 		dma_addr_t olddma = txdr->dma;
       
  1610 		DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
       
  1611 				     "at %p\n", txdr->size, txdr->desc);
       
  1612 		/* Try again, without freeing the previous */
       
  1613 		txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
       
  1614 		/* Failed allocation, critical failure */
       
  1615 		if (!txdr->desc) {
       
  1616 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
       
  1617 			goto setup_tx_desc_die;
       
  1618 		}
       
  1619 
       
  1620 		if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
       
  1621 			/* give up */
       
  1622 			pci_free_consistent(pdev, txdr->size, txdr->desc,
       
  1623 					    txdr->dma);
       
  1624 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
       
  1625 			DPRINTK(PROBE, ERR,
       
  1626 				"Unable to allocate aligned memory "
       
  1627 				"for the transmit descriptor ring\n");
       
  1628 			vfree(txdr->buffer_info);
       
  1629 			return -ENOMEM;
       
  1630 		} else {
       
  1631 			/* Free old allocation, new allocation was successful */
       
  1632 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
       
  1633 		}
       
  1634 	}
       
  1635 	memset(txdr->desc, 0, txdr->size);
       
  1636 
       
  1637 	txdr->next_to_use = 0;
       
  1638 	txdr->next_to_clean = 0;
       
  1639 	spin_lock_init(&txdr->tx_lock);
       
  1640 
       
  1641 	return 0;
       
  1642 }
       
  1643 
       
  1644 /**
       
  1645  * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
       
  1646  * 				  (Descriptors) for all queues
       
  1647  * @adapter: board private structure
       
  1648  *
       
  1649  * Return 0 on success, negative on failure
       
  1650  **/
       
  1651 
       
  1652 int
       
  1653 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
       
  1654 {
       
  1655 	int i, err = 0;
       
  1656 
       
  1657 	for (i = 0; i < adapter->num_tx_queues; i++) {
       
  1658 		err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
       
  1659 		if (err) {
       
  1660 			DPRINTK(PROBE, ERR,
       
  1661 				"Allocation for Tx Queue %u failed\n", i);
       
  1662 			for (i-- ; i >= 0; i--)
       
  1663 				e1000_free_tx_resources(adapter,
       
  1664 							&adapter->tx_ring[i]);
       
  1665 			break;
       
  1666 		}
       
  1667 	}
       
  1668 
       
  1669 	return err;
       
  1670 }
       
  1671 
       
  1672 /**
       
  1673  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
       
  1674  * @adapter: board private structure
       
  1675  *
       
  1676  * Configure the Tx unit of the MAC after a reset.
       
  1677  **/
       
  1678 
       
  1679 static void
       
  1680 e1000_configure_tx(struct e1000_adapter *adapter)
       
  1681 {
       
  1682 	uint64_t tdba;
       
  1683 	struct e1000_hw *hw = &adapter->hw;
       
  1684 	uint32_t tdlen, tctl, tipg, tarc;
       
  1685 	uint32_t ipgr1, ipgr2;
       
  1686 
       
  1687 	/* Setup the HW Tx Head and Tail descriptor pointers */
       
  1688 
       
  1689 	switch (adapter->num_tx_queues) {
       
  1690 	case 1:
       
  1691 	default:
       
  1692 		tdba = adapter->tx_ring[0].dma;
       
  1693 		tdlen = adapter->tx_ring[0].count *
       
  1694 			sizeof(struct e1000_tx_desc);
       
  1695 		E1000_WRITE_REG(hw, TDLEN, tdlen);
       
  1696 		E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
       
  1697 		E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
       
  1698 		E1000_WRITE_REG(hw, TDT, 0);
       
  1699 		E1000_WRITE_REG(hw, TDH, 0);
       
  1700 		adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
       
  1701 		adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
       
  1702 		break;
       
  1703 	}
       
  1704 
       
  1705 	/* Set the default values for the Tx Inter Packet Gap timer */
       
  1706 	if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
       
  1707 	    (hw->media_type == e1000_media_type_fiber ||
       
  1708 	     hw->media_type == e1000_media_type_internal_serdes))
       
  1709 		tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
       
  1710 	else
       
  1711 		tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
       
  1712 
       
  1713 	switch (hw->mac_type) {
       
  1714 	case e1000_82542_rev2_0:
       
  1715 	case e1000_82542_rev2_1:
       
  1716 		tipg = DEFAULT_82542_TIPG_IPGT;
       
  1717 		ipgr1 = DEFAULT_82542_TIPG_IPGR1;
       
  1718 		ipgr2 = DEFAULT_82542_TIPG_IPGR2;
       
  1719 		break;
       
  1720 	case e1000_80003es2lan:
       
  1721 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
       
  1722 		ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
       
  1723 		break;
       
  1724 	default:
       
  1725 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
       
  1726 		ipgr2 = DEFAULT_82543_TIPG_IPGR2;
       
  1727 		break;
       
  1728 	}
       
  1729 	tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
       
  1730 	tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
       
  1731 	E1000_WRITE_REG(hw, TIPG, tipg);
       
  1732 
       
  1733 	/* Set the Tx Interrupt Delay register */
       
  1734 
       
  1735 	E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
       
  1736 	if (hw->mac_type >= e1000_82540)
       
  1737 		E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
       
  1738 
       
  1739 	/* Program the Transmit Control Register */
       
  1740 
       
  1741 	tctl = E1000_READ_REG(hw, TCTL);
       
  1742 	tctl &= ~E1000_TCTL_CT;
       
  1743 	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
       
  1744 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
       
  1745 
       
  1746 	if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
       
  1747 		tarc = E1000_READ_REG(hw, TARC0);
       
  1748 		/* set the speed mode bit, we'll clear it if we're not at
       
  1749 		 * gigabit link later */
       
  1750 		tarc |= (1 << 21);
       
  1751 		E1000_WRITE_REG(hw, TARC0, tarc);
       
  1752 	} else if (hw->mac_type == e1000_80003es2lan) {
       
  1753 		tarc = E1000_READ_REG(hw, TARC0);
       
  1754 		tarc |= 1;
       
  1755 		E1000_WRITE_REG(hw, TARC0, tarc);
       
  1756 		tarc = E1000_READ_REG(hw, TARC1);
       
  1757 		tarc |= 1;
       
  1758 		E1000_WRITE_REG(hw, TARC1, tarc);
       
  1759 	}
       
  1760 
       
  1761 	e1000_config_collision_dist(hw);
       
  1762 
       
  1763 	/* Setup Transmit Descriptor Settings for eop descriptor */
       
  1764 	adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
       
  1765 
       
  1766 	/* only set IDE if we are delaying interrupts using the timers */
       
  1767 	if (adapter->tx_int_delay)
       
  1768 		adapter->txd_cmd |= E1000_TXD_CMD_IDE;
       
  1769 
       
  1770 	if (hw->mac_type < e1000_82543)
       
  1771 		adapter->txd_cmd |= E1000_TXD_CMD_RPS;
       
  1772 	else
       
  1773 		adapter->txd_cmd |= E1000_TXD_CMD_RS;
       
  1774 
       
  1775 	/* Cache if we're 82544 running in PCI-X because we'll
       
  1776 	 * need this to apply a workaround later in the send path. */
       
  1777 	if (hw->mac_type == e1000_82544 &&
       
  1778 	    hw->bus_type == e1000_bus_type_pcix)
       
  1779 		adapter->pcix_82544 = 1;
       
  1780 
       
  1781 	E1000_WRITE_REG(hw, TCTL, tctl);
       
  1782 
       
  1783 }
       
  1784 
       
  1785 /**
       
  1786  * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
       
  1787  * @adapter: board private structure
       
  1788  * @rxdr:    rx descriptor ring (for a specific queue) to setup
       
  1789  *
       
  1790  * Returns 0 on success, negative on failure
       
  1791  **/
       
  1792 
       
  1793 static int
       
  1794 e1000_setup_rx_resources(struct e1000_adapter *adapter,
       
  1795                          struct e1000_rx_ring *rxdr)
       
  1796 {
       
  1797 	struct pci_dev *pdev = adapter->pdev;
       
  1798 	int size, desc_len;
       
  1799 
       
  1800 	size = sizeof(struct e1000_buffer) * rxdr->count;
       
  1801 	rxdr->buffer_info = vmalloc(size);
       
  1802 	if (!rxdr->buffer_info) {
       
  1803 		DPRINTK(PROBE, ERR,
       
  1804 		"Unable to allocate memory for the receive descriptor ring\n");
       
  1805 		return -ENOMEM;
       
  1806 	}
       
  1807 	memset(rxdr->buffer_info, 0, size);
       
  1808 
       
  1809 	rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
       
  1810 	                        GFP_KERNEL);
       
  1811 	if (!rxdr->ps_page) {
       
  1812 		vfree(rxdr->buffer_info);
       
  1813 		DPRINTK(PROBE, ERR,
       
  1814 		"Unable to allocate memory for the receive descriptor ring\n");
       
  1815 		return -ENOMEM;
       
  1816 	}
       
  1817 
       
  1818 	rxdr->ps_page_dma = kcalloc(rxdr->count,
       
  1819 	                            sizeof(struct e1000_ps_page_dma),
       
  1820 	                            GFP_KERNEL);
       
  1821 	if (!rxdr->ps_page_dma) {
       
  1822 		vfree(rxdr->buffer_info);
       
  1823 		kfree(rxdr->ps_page);
       
  1824 		DPRINTK(PROBE, ERR,
       
  1825 		"Unable to allocate memory for the receive descriptor ring\n");
       
  1826 		return -ENOMEM;
       
  1827 	}
       
  1828 
       
  1829 	if (adapter->hw.mac_type <= e1000_82547_rev_2)
       
  1830 		desc_len = sizeof(struct e1000_rx_desc);
       
  1831 	else
       
  1832 		desc_len = sizeof(union e1000_rx_desc_packet_split);
       
  1833 
       
  1834 	/* Round up to nearest 4K */
       
  1835 
       
  1836 	rxdr->size = rxdr->count * desc_len;
       
  1837 	rxdr->size = ALIGN(rxdr->size, 4096);
       
  1838 
       
  1839 	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
       
  1840 
       
  1841 	if (!rxdr->desc) {
       
  1842 		DPRINTK(PROBE, ERR,
       
  1843 		"Unable to allocate memory for the receive descriptor ring\n");
       
  1844 setup_rx_desc_die:
       
  1845 		vfree(rxdr->buffer_info);
       
  1846 		kfree(rxdr->ps_page);
       
  1847 		kfree(rxdr->ps_page_dma);
       
  1848 		return -ENOMEM;
       
  1849 	}
       
  1850 
       
  1851 	/* Fix for errata 23, can't cross 64kB boundary */
       
  1852 	if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
       
  1853 		void *olddesc = rxdr->desc;
       
  1854 		dma_addr_t olddma = rxdr->dma;
       
  1855 		DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
       
  1856 				     "at %p\n", rxdr->size, rxdr->desc);
       
  1857 		/* Try again, without freeing the previous */
       
  1858 		rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
       
  1859 		/* Failed allocation, critical failure */
       
  1860 		if (!rxdr->desc) {
       
  1861 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
       
  1862 			DPRINTK(PROBE, ERR,
       
  1863 				"Unable to allocate memory "
       
  1864 				"for the receive descriptor ring\n");
       
  1865 			goto setup_rx_desc_die;
       
  1866 		}
       
  1867 
       
  1868 		if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
       
  1869 			/* give up */
       
  1870 			pci_free_consistent(pdev, rxdr->size, rxdr->desc,
       
  1871 					    rxdr->dma);
       
  1872 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
       
  1873 			DPRINTK(PROBE, ERR,
       
  1874 				"Unable to allocate aligned memory "
       
  1875 				"for the receive descriptor ring\n");
       
  1876 			goto setup_rx_desc_die;
       
  1877 		} else {
       
  1878 			/* Free old allocation, new allocation was successful */
       
  1879 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
       
  1880 		}
       
  1881 	}
       
  1882 	memset(rxdr->desc, 0, rxdr->size);
       
  1883 
       
  1884 	rxdr->next_to_clean = 0;
       
  1885 	rxdr->next_to_use = 0;
       
  1886 
       
  1887 	return 0;
       
  1888 }
       
  1889 
       
  1890 /**
       
  1891  * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
       
  1892  * 				  (Descriptors) for all queues
       
  1893  * @adapter: board private structure
       
  1894  *
       
  1895  * Return 0 on success, negative on failure
       
  1896  **/
       
  1897 
       
  1898 int
       
  1899 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
       
  1900 {
       
  1901 	int i, err = 0;
       
  1902 
       
  1903 	for (i = 0; i < adapter->num_rx_queues; i++) {
       
  1904 		err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
       
  1905 		if (err) {
       
  1906 			DPRINTK(PROBE, ERR,
       
  1907 				"Allocation for Rx Queue %u failed\n", i);
       
  1908 			for (i-- ; i >= 0; i--)
       
  1909 				e1000_free_rx_resources(adapter,
       
  1910 							&adapter->rx_ring[i]);
       
  1911 			break;
       
  1912 		}
       
  1913 	}
       
  1914 
       
  1915 	return err;
       
  1916 }
       
  1917 
       
  1918 /**
       
  1919  * e1000_setup_rctl - configure the receive control registers
       
  1920  * @adapter: Board private structure
       
  1921  **/
       
  1922 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
       
  1923 			(((S) & (PAGE_SIZE - 1)) ? 1 : 0))
       
  1924 static void
       
  1925 e1000_setup_rctl(struct e1000_adapter *adapter)
       
  1926 {
       
  1927 	uint32_t rctl, rfctl;
       
  1928 	uint32_t psrctl = 0;
       
  1929 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
       
  1930 	uint32_t pages = 0;
       
  1931 #endif
       
  1932 
       
  1933 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  1934 
       
  1935 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
       
  1936 
       
  1937 	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
       
  1938 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
       
  1939 		(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
       
  1940 
       
  1941 	if (adapter->hw.tbi_compatibility_on == 1)
       
  1942 		rctl |= E1000_RCTL_SBP;
       
  1943 	else
       
  1944 		rctl &= ~E1000_RCTL_SBP;
       
  1945 
       
  1946 	if (adapter->netdev->mtu <= ETH_DATA_LEN)
       
  1947 		rctl &= ~E1000_RCTL_LPE;
       
  1948 	else
       
  1949 		rctl |= E1000_RCTL_LPE;
       
  1950 
       
  1951 	/* Setup buffer sizes */
       
  1952 	rctl &= ~E1000_RCTL_SZ_4096;
       
  1953 	rctl |= E1000_RCTL_BSEX;
       
  1954 	switch (adapter->rx_buffer_len) {
       
  1955 		case E1000_RXBUFFER_256:
       
  1956 			rctl |= E1000_RCTL_SZ_256;
       
  1957 			rctl &= ~E1000_RCTL_BSEX;
       
  1958 			break;
       
  1959 		case E1000_RXBUFFER_512:
       
  1960 			rctl |= E1000_RCTL_SZ_512;
       
  1961 			rctl &= ~E1000_RCTL_BSEX;
       
  1962 			break;
       
  1963 		case E1000_RXBUFFER_1024:
       
  1964 			rctl |= E1000_RCTL_SZ_1024;
       
  1965 			rctl &= ~E1000_RCTL_BSEX;
       
  1966 			break;
       
  1967 		case E1000_RXBUFFER_2048:
       
  1968 		default:
       
  1969 			rctl |= E1000_RCTL_SZ_2048;
       
  1970 			rctl &= ~E1000_RCTL_BSEX;
       
  1971 			break;
       
  1972 		case E1000_RXBUFFER_4096:
       
  1973 			rctl |= E1000_RCTL_SZ_4096;
       
  1974 			break;
       
  1975 		case E1000_RXBUFFER_8192:
       
  1976 			rctl |= E1000_RCTL_SZ_8192;
       
  1977 			break;
       
  1978 		case E1000_RXBUFFER_16384:
       
  1979 			rctl |= E1000_RCTL_SZ_16384;
       
  1980 			break;
       
  1981 	}
       
  1982 
       
  1983 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
       
  1984 	/* 82571 and greater support packet-split where the protocol
       
  1985 	 * header is placed in skb->data and the packet data is
       
  1986 	 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
       
  1987 	 * In the case of a non-split, skb->data is linearly filled,
       
  1988 	 * followed by the page buffers.  Therefore, skb->data is
       
  1989 	 * sized to hold the largest protocol header.
       
  1990 	 */
       
  1991 	/* allocations using alloc_page take too long for regular MTU
       
  1992 	 * so only enable packet split for jumbo frames */
       
  1993 	pages = PAGE_USE_COUNT(adapter->netdev->mtu);
       
  1994 	if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
       
  1995 	    PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
       
  1996 		adapter->rx_ps_pages = pages;
       
  1997 	else
       
  1998 		adapter->rx_ps_pages = 0;
       
  1999 #endif
       
  2000 	if (adapter->rx_ps_pages) {
       
  2001 		/* Configure extra packet-split registers */
       
  2002 		rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
       
  2003 		rfctl |= E1000_RFCTL_EXTEN;
       
  2004 		/* disable packet split support for IPv6 extension headers,
       
  2005 		 * because some malformed IPv6 headers can hang the RX */
       
  2006 		rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
       
  2007 		          E1000_RFCTL_NEW_IPV6_EXT_DIS);
       
  2008 
       
  2009 		E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
       
  2010 
       
  2011 		rctl |= E1000_RCTL_DTYP_PS;
       
  2012 
       
  2013 		psrctl |= adapter->rx_ps_bsize0 >>
       
  2014 			E1000_PSRCTL_BSIZE0_SHIFT;
       
  2015 
       
  2016 		switch (adapter->rx_ps_pages) {
       
  2017 		case 3:
       
  2018 			psrctl |= PAGE_SIZE <<
       
  2019 				E1000_PSRCTL_BSIZE3_SHIFT;
       
  2020 		case 2:
       
  2021 			psrctl |= PAGE_SIZE <<
       
  2022 				E1000_PSRCTL_BSIZE2_SHIFT;
       
  2023 		case 1:
       
  2024 			psrctl |= PAGE_SIZE >>
       
  2025 				E1000_PSRCTL_BSIZE1_SHIFT;
       
  2026 			break;
       
  2027 		}
       
  2028 
       
  2029 		E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
       
  2030 	}
       
  2031 
       
  2032 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  2033 }
       
  2034 
       
  2035 /**
       
  2036  * e1000_configure_rx - Configure 8254x Receive Unit after Reset
       
  2037  * @adapter: board private structure
       
  2038  *
       
  2039  * Configure the Rx unit of the MAC after a reset.
       
  2040  **/
       
  2041 
       
  2042 static void
       
  2043 e1000_configure_rx(struct e1000_adapter *adapter)
       
  2044 {
       
  2045 	uint64_t rdba;
       
  2046 	struct e1000_hw *hw = &adapter->hw;
       
  2047 	uint32_t rdlen, rctl, rxcsum, ctrl_ext;
       
  2048 
       
  2049 	if (adapter->rx_ps_pages) {
       
  2050 		/* this is a 32 byte descriptor */
       
  2051 		rdlen = adapter->rx_ring[0].count *
       
  2052 			sizeof(union e1000_rx_desc_packet_split);
       
  2053 		adapter->clean_rx = e1000_clean_rx_irq_ps;
       
  2054 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
       
  2055 	} else {
       
  2056 		rdlen = adapter->rx_ring[0].count *
       
  2057 			sizeof(struct e1000_rx_desc);
       
  2058 		adapter->clean_rx = e1000_clean_rx_irq;
       
  2059 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
       
  2060 	}
       
  2061 
       
  2062 	/* disable receives while setting up the descriptors */
       
  2063 	rctl = E1000_READ_REG(hw, RCTL);
       
  2064 	E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
       
  2065 
       
  2066 	/* set the Receive Delay Timer Register */
       
  2067 	E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
       
  2068 
       
  2069 	if (hw->mac_type >= e1000_82540) {
       
  2070 		E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
       
  2071 		if (adapter->itr_setting != 0)
       
  2072 			E1000_WRITE_REG(hw, ITR,
       
  2073 				1000000000 / (adapter->itr * 256));
       
  2074 	}
       
  2075 
       
  2076 	if (hw->mac_type >= e1000_82571) {
       
  2077 		ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
       
  2078 		/* Reset delay timers after every interrupt */
       
  2079 		ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
       
  2080 #ifdef CONFIG_E1000_NAPI
       
  2081 		/* Auto-Mask interrupts upon ICR access */
       
  2082 		ctrl_ext |= E1000_CTRL_EXT_IAME;
       
  2083 		E1000_WRITE_REG(hw, IAM, 0xffffffff);
       
  2084 #endif
       
  2085 		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
       
  2086 		E1000_WRITE_FLUSH(hw);
       
  2087 	}
       
  2088 
       
  2089 	/* Setup the HW Rx Head and Tail Descriptor Pointers and
       
  2090 	 * the Base and Length of the Rx Descriptor Ring */
       
  2091 	switch (adapter->num_rx_queues) {
       
  2092 	case 1:
       
  2093 	default:
       
  2094 		rdba = adapter->rx_ring[0].dma;
       
  2095 		E1000_WRITE_REG(hw, RDLEN, rdlen);
       
  2096 		E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
       
  2097 		E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
       
  2098 		E1000_WRITE_REG(hw, RDT, 0);
       
  2099 		E1000_WRITE_REG(hw, RDH, 0);
       
  2100 		adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
       
  2101 		adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
       
  2102 		break;
       
  2103 	}
       
  2104 
       
  2105 	/* Enable 82543 Receive Checksum Offload for TCP and UDP */
       
  2106 	if (hw->mac_type >= e1000_82543) {
       
  2107 		rxcsum = E1000_READ_REG(hw, RXCSUM);
       
  2108 		if (adapter->rx_csum == TRUE) {
       
  2109 			rxcsum |= E1000_RXCSUM_TUOFL;
       
  2110 
       
  2111 			/* Enable 82571 IPv4 payload checksum for UDP fragments
       
  2112 			 * Must be used in conjunction with packet-split. */
       
  2113 			if ((hw->mac_type >= e1000_82571) &&
       
  2114 			    (adapter->rx_ps_pages)) {
       
  2115 				rxcsum |= E1000_RXCSUM_IPPCSE;
       
  2116 			}
       
  2117 		} else {
       
  2118 			rxcsum &= ~E1000_RXCSUM_TUOFL;
       
  2119 			/* don't need to clear IPPCSE as it defaults to 0 */
       
  2120 		}
       
  2121 		E1000_WRITE_REG(hw, RXCSUM, rxcsum);
       
  2122 	}
       
  2123 
       
  2124 	/* enable early receives on 82573, only takes effect if using > 2048
       
  2125 	 * byte total frame size.  for example only for jumbo frames */
       
  2126 #define E1000_ERT_2048 0x100
       
  2127 	if (hw->mac_type == e1000_82573)
       
  2128 		E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
       
  2129 
       
  2130 	/* Enable Receives */
       
  2131 	E1000_WRITE_REG(hw, RCTL, rctl);
       
  2132 }
       
  2133 
       
  2134 /**
       
  2135  * e1000_free_tx_resources - Free Tx Resources per Queue
       
  2136  * @adapter: board private structure
       
  2137  * @tx_ring: Tx descriptor ring for a specific queue
       
  2138  *
       
  2139  * Free all transmit software resources
       
  2140  **/
       
  2141 
       
  2142 static void
       
  2143 e1000_free_tx_resources(struct e1000_adapter *adapter,
       
  2144                         struct e1000_tx_ring *tx_ring)
       
  2145 {
       
  2146 	struct pci_dev *pdev = adapter->pdev;
       
  2147 
       
  2148 	e1000_clean_tx_ring(adapter, tx_ring);
       
  2149 
       
  2150 	vfree(tx_ring->buffer_info);
       
  2151 	tx_ring->buffer_info = NULL;
       
  2152 
       
  2153 	pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
       
  2154 
       
  2155 	tx_ring->desc = NULL;
       
  2156 }
       
  2157 
       
  2158 /**
       
  2159  * e1000_free_all_tx_resources - Free Tx Resources for All Queues
       
  2160  * @adapter: board private structure
       
  2161  *
       
  2162  * Free all transmit software resources
       
  2163  **/
       
  2164 
       
  2165 void
       
  2166 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
       
  2167 {
       
  2168 	int i;
       
  2169 
       
  2170 	for (i = 0; i < adapter->num_tx_queues; i++)
       
  2171 		e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
       
  2172 }
       
  2173 
       
  2174 static void
       
  2175 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
       
  2176 			struct e1000_buffer *buffer_info)
       
  2177 {
       
  2178 	if (adapter->ecdev)
       
  2179 		return;
       
  2180 
       
  2181 	if (buffer_info->dma) {
       
  2182 		pci_unmap_page(adapter->pdev,
       
  2183 				buffer_info->dma,
       
  2184 				buffer_info->length,
       
  2185 				PCI_DMA_TODEVICE);
       
  2186 		buffer_info->dma = 0;
       
  2187 	}
       
  2188 	if (buffer_info->skb) {
       
  2189 		dev_kfree_skb_any(buffer_info->skb);
       
  2190 		buffer_info->skb = NULL;
       
  2191 	}
       
  2192 	/* buffer_info must be completely set up in the transmit path */
       
  2193 }
       
  2194 
       
  2195 /**
       
  2196  * e1000_clean_tx_ring - Free Tx Buffers
       
  2197  * @adapter: board private structure
       
  2198  * @tx_ring: ring to be cleaned
       
  2199  **/
       
  2200 
       
  2201 static void
       
  2202 e1000_clean_tx_ring(struct e1000_adapter *adapter,
       
  2203                     struct e1000_tx_ring *tx_ring)
       
  2204 {
       
  2205 	struct e1000_buffer *buffer_info;
       
  2206 	unsigned long size;
       
  2207 	unsigned int i;
       
  2208 
       
  2209 	/* Free all the Tx ring sk_buffs */
       
  2210 
       
  2211 	for (i = 0; i < tx_ring->count; i++) {
       
  2212 		buffer_info = &tx_ring->buffer_info[i];
       
  2213 		e1000_unmap_and_free_tx_resource(adapter, buffer_info);
       
  2214 	}
       
  2215 
       
  2216 	size = sizeof(struct e1000_buffer) * tx_ring->count;
       
  2217 	memset(tx_ring->buffer_info, 0, size);
       
  2218 
       
  2219 	/* Zero out the descriptor ring */
       
  2220 
       
  2221 	memset(tx_ring->desc, 0, tx_ring->size);
       
  2222 
       
  2223 	tx_ring->next_to_use = 0;
       
  2224 	tx_ring->next_to_clean = 0;
       
  2225 	tx_ring->last_tx_tso = 0;
       
  2226 
       
  2227 	writel(0, adapter->hw.hw_addr + tx_ring->tdh);
       
  2228 	writel(0, adapter->hw.hw_addr + tx_ring->tdt);
       
  2229 }
       
  2230 
       
  2231 /**
       
  2232  * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
       
  2233  * @adapter: board private structure
       
  2234  **/
       
  2235 
       
  2236 static void
       
  2237 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
       
  2238 {
       
  2239 	int i;
       
  2240 
       
  2241 	for (i = 0; i < adapter->num_tx_queues; i++)
       
  2242 		e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
       
  2243 }
       
  2244 
       
  2245 /**
       
  2246  * e1000_free_rx_resources - Free Rx Resources
       
  2247  * @adapter: board private structure
       
  2248  * @rx_ring: ring to clean the resources from
       
  2249  *
       
  2250  * Free all receive software resources
       
  2251  **/
       
  2252 
       
  2253 static void
       
  2254 e1000_free_rx_resources(struct e1000_adapter *adapter,
       
  2255                         struct e1000_rx_ring *rx_ring)
       
  2256 {
       
  2257 	struct pci_dev *pdev = adapter->pdev;
       
  2258 
       
  2259 	e1000_clean_rx_ring(adapter, rx_ring);
       
  2260 
       
  2261 	vfree(rx_ring->buffer_info);
       
  2262 	rx_ring->buffer_info = NULL;
       
  2263 	kfree(rx_ring->ps_page);
       
  2264 	rx_ring->ps_page = NULL;
       
  2265 	kfree(rx_ring->ps_page_dma);
       
  2266 	rx_ring->ps_page_dma = NULL;
       
  2267 
       
  2268 	pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
       
  2269 
       
  2270 	rx_ring->desc = NULL;
       
  2271 }
       
  2272 
       
  2273 /**
       
  2274  * e1000_free_all_rx_resources - Free Rx Resources for All Queues
       
  2275  * @adapter: board private structure
       
  2276  *
       
  2277  * Free all receive software resources
       
  2278  **/
       
  2279 
       
  2280 void
       
  2281 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
       
  2282 {
       
  2283 	int i;
       
  2284 
       
  2285 	for (i = 0; i < adapter->num_rx_queues; i++)
       
  2286 		e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
       
  2287 }
       
  2288 
       
  2289 /**
       
  2290  * e1000_clean_rx_ring - Free Rx Buffers per Queue
       
  2291  * @adapter: board private structure
       
  2292  * @rx_ring: ring to free buffers from
       
  2293  **/
       
  2294 
       
  2295 static void
       
  2296 e1000_clean_rx_ring(struct e1000_adapter *adapter,
       
  2297                     struct e1000_rx_ring *rx_ring)
       
  2298 {
       
  2299 	struct e1000_buffer *buffer_info;
       
  2300 	struct e1000_ps_page *ps_page;
       
  2301 	struct e1000_ps_page_dma *ps_page_dma;
       
  2302 	struct pci_dev *pdev = adapter->pdev;
       
  2303 	unsigned long size;
       
  2304 	unsigned int i, j;
       
  2305 
       
  2306 	/* Free all the Rx ring sk_buffs */
       
  2307 	for (i = 0; i < rx_ring->count; i++) {
       
  2308 		buffer_info = &rx_ring->buffer_info[i];
       
  2309 		if (buffer_info->skb) {
       
  2310 			pci_unmap_single(pdev,
       
  2311 					 buffer_info->dma,
       
  2312 					 buffer_info->length,
       
  2313 					 PCI_DMA_FROMDEVICE);
       
  2314 
       
  2315 			dev_kfree_skb(buffer_info->skb);
       
  2316 			buffer_info->skb = NULL;
       
  2317 		}
       
  2318 		ps_page = &rx_ring->ps_page[i];
       
  2319 		ps_page_dma = &rx_ring->ps_page_dma[i];
       
  2320 		for (j = 0; j < adapter->rx_ps_pages; j++) {
       
  2321 			if (!ps_page->ps_page[j]) break;
       
  2322 			pci_unmap_page(pdev,
       
  2323 				       ps_page_dma->ps_page_dma[j],
       
  2324 				       PAGE_SIZE, PCI_DMA_FROMDEVICE);
       
  2325 			ps_page_dma->ps_page_dma[j] = 0;
       
  2326 			put_page(ps_page->ps_page[j]);
       
  2327 			ps_page->ps_page[j] = NULL;
       
  2328 		}
       
  2329 	}
       
  2330 
       
  2331 	size = sizeof(struct e1000_buffer) * rx_ring->count;
       
  2332 	memset(rx_ring->buffer_info, 0, size);
       
  2333 	size = sizeof(struct e1000_ps_page) * rx_ring->count;
       
  2334 	memset(rx_ring->ps_page, 0, size);
       
  2335 	size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
       
  2336 	memset(rx_ring->ps_page_dma, 0, size);
       
  2337 
       
  2338 	/* Zero out the descriptor ring */
       
  2339 
       
  2340 	memset(rx_ring->desc, 0, rx_ring->size);
       
  2341 
       
  2342 	rx_ring->next_to_clean = 0;
       
  2343 	rx_ring->next_to_use = 0;
       
  2344 
       
  2345 	writel(0, adapter->hw.hw_addr + rx_ring->rdh);
       
  2346 	writel(0, adapter->hw.hw_addr + rx_ring->rdt);
       
  2347 }
       
  2348 
       
  2349 /**
       
  2350  * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
       
  2351  * @adapter: board private structure
       
  2352  **/
       
  2353 
       
  2354 static void
       
  2355 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
       
  2356 {
       
  2357 	int i;
       
  2358 
       
  2359 	for (i = 0; i < adapter->num_rx_queues; i++)
       
  2360 		e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
       
  2361 }
       
  2362 
       
  2363 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
       
  2364  * and memory write and invalidate disabled for certain operations
       
  2365  */
       
  2366 static void
       
  2367 e1000_enter_82542_rst(struct e1000_adapter *adapter)
       
  2368 {
       
  2369 	struct net_device *netdev = adapter->netdev;
       
  2370 	uint32_t rctl;
       
  2371 
       
  2372 	e1000_pci_clear_mwi(&adapter->hw);
       
  2373 
       
  2374 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  2375 	rctl |= E1000_RCTL_RST;
       
  2376 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  2377 	E1000_WRITE_FLUSH(&adapter->hw);
       
  2378 	mdelay(5);
       
  2379 
       
  2380 	if (!adapter->ecdev && netif_running(netdev))
       
  2381 		e1000_clean_all_rx_rings(adapter);
       
  2382 }
       
  2383 
       
  2384 static void
       
  2385 e1000_leave_82542_rst(struct e1000_adapter *adapter)
       
  2386 {
       
  2387 	struct net_device *netdev = adapter->netdev;
       
  2388 	uint32_t rctl;
       
  2389 
       
  2390 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  2391 	rctl &= ~E1000_RCTL_RST;
       
  2392 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  2393 	E1000_WRITE_FLUSH(&adapter->hw);
       
  2394 	mdelay(5);
       
  2395 
       
  2396 	if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
       
  2397 		e1000_pci_set_mwi(&adapter->hw);
       
  2398 
       
  2399 	if (!adapter->netdev && netif_running(netdev)) {
       
  2400 		/* No need to loop, because 82542 supports only 1 queue */
       
  2401 		struct e1000_rx_ring *ring = &adapter->rx_ring[0];
       
  2402 		e1000_configure_rx(adapter);
       
  2403 		adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
       
  2404 	}
       
  2405 }
       
  2406 
       
  2407 /**
       
  2408  * e1000_set_mac - Change the Ethernet Address of the NIC
       
  2409  * @netdev: network interface device structure
       
  2410  * @p: pointer to an address structure
       
  2411  *
       
  2412  * Returns 0 on success, negative on failure
       
  2413  **/
       
  2414 
       
  2415 static int
       
  2416 e1000_set_mac(struct net_device *netdev, void *p)
       
  2417 {
       
  2418 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  2419 	struct sockaddr *addr = p;
       
  2420 
       
  2421 	if (!is_valid_ether_addr(addr->sa_data))
       
  2422 		return -EADDRNOTAVAIL;
       
  2423 
       
  2424 	/* 82542 2.0 needs to be in reset to write receive address registers */
       
  2425 
       
  2426 	if (adapter->hw.mac_type == e1000_82542_rev2_0)
       
  2427 		e1000_enter_82542_rst(adapter);
       
  2428 
       
  2429 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
       
  2430 	memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
       
  2431 
       
  2432 	e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
       
  2433 
       
  2434 	/* With 82571 controllers, LAA may be overwritten (with the default)
       
  2435 	 * due to controller reset from the other port. */
       
  2436 	if (adapter->hw.mac_type == e1000_82571) {
       
  2437 		/* activate the work around */
       
  2438 		adapter->hw.laa_is_present = 1;
       
  2439 
       
  2440 		/* Hold a copy of the LAA in RAR[14] This is done so that
       
  2441 		 * between the time RAR[0] gets clobbered  and the time it
       
  2442 		 * gets fixed (in e1000_watchdog), the actual LAA is in one
       
  2443 		 * of the RARs and no incoming packets directed to this port
       
  2444 		 * are dropped. Eventaully the LAA will be in RAR[0] and
       
  2445 		 * RAR[14] */
       
  2446 		e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
       
  2447 					E1000_RAR_ENTRIES - 1);
       
  2448 	}
       
  2449 
       
  2450 	if (adapter->hw.mac_type == e1000_82542_rev2_0)
       
  2451 		e1000_leave_82542_rst(adapter);
       
  2452 
       
  2453 	return 0;
       
  2454 }
       
  2455 
       
  2456 /**
       
  2457  * e1000_set_multi - Multicast and Promiscuous mode set
       
  2458  * @netdev: network interface device structure
       
  2459  *
       
  2460  * The set_multi entry point is called whenever the multicast address
       
  2461  * list or the network interface flags are updated.  This routine is
       
  2462  * responsible for configuring the hardware for proper multicast,
       
  2463  * promiscuous mode, and all-multi behavior.
       
  2464  **/
       
  2465 
       
  2466 static void
       
  2467 e1000_set_multi(struct net_device *netdev)
       
  2468 {
       
  2469 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  2470 	struct e1000_hw *hw = &adapter->hw;
       
  2471 	struct dev_mc_list *mc_ptr;
       
  2472 	uint32_t rctl;
       
  2473 	uint32_t hash_value;
       
  2474 	int i, rar_entries = E1000_RAR_ENTRIES;
       
  2475 	int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
       
  2476 				E1000_NUM_MTA_REGISTERS_ICH8LAN :
       
  2477 				E1000_NUM_MTA_REGISTERS;
       
  2478 
       
  2479 	if (adapter->hw.mac_type == e1000_ich8lan)
       
  2480 		rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
       
  2481 
       
  2482 	/* reserve RAR[14] for LAA over-write work-around */
       
  2483 	if (adapter->hw.mac_type == e1000_82571)
       
  2484 		rar_entries--;
       
  2485 
       
  2486 	/* Check for Promiscuous and All Multicast modes */
       
  2487 
       
  2488 	rctl = E1000_READ_REG(hw, RCTL);
       
  2489 
       
  2490 	if (netdev->flags & IFF_PROMISC) {
       
  2491 		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
       
  2492 	} else if (netdev->flags & IFF_ALLMULTI) {
       
  2493 		rctl |= E1000_RCTL_MPE;
       
  2494 		rctl &= ~E1000_RCTL_UPE;
       
  2495 	} else {
       
  2496 		rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
       
  2497 	}
       
  2498 
       
  2499 	E1000_WRITE_REG(hw, RCTL, rctl);
       
  2500 
       
  2501 	/* 82542 2.0 needs to be in reset to write receive address registers */
       
  2502 
       
  2503 	if (hw->mac_type == e1000_82542_rev2_0)
       
  2504 		e1000_enter_82542_rst(adapter);
       
  2505 
       
  2506 	/* load the first 14 multicast address into the exact filters 1-14
       
  2507 	 * RAR 0 is used for the station MAC adddress
       
  2508 	 * if there are not 14 addresses, go ahead and clear the filters
       
  2509 	 * -- with 82571 controllers only 0-13 entries are filled here
       
  2510 	 */
       
  2511 	mc_ptr = netdev->mc_list;
       
  2512 
       
  2513 	for (i = 1; i < rar_entries; i++) {
       
  2514 		if (mc_ptr) {
       
  2515 			e1000_rar_set(hw, mc_ptr->dmi_addr, i);
       
  2516 			mc_ptr = mc_ptr->next;
       
  2517 		} else {
       
  2518 			E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
       
  2519 			E1000_WRITE_FLUSH(hw);
       
  2520 			E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
       
  2521 			E1000_WRITE_FLUSH(hw);
       
  2522 		}
       
  2523 	}
       
  2524 
       
  2525 	/* clear the old settings from the multicast hash table */
       
  2526 
       
  2527 	for (i = 0; i < mta_reg_count; i++) {
       
  2528 		E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
       
  2529 		E1000_WRITE_FLUSH(hw);
       
  2530 	}
       
  2531 
       
  2532 	/* load any remaining addresses into the hash table */
       
  2533 
       
  2534 	for (; mc_ptr; mc_ptr = mc_ptr->next) {
       
  2535 		hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
       
  2536 		e1000_mta_set(hw, hash_value);
       
  2537 	}
       
  2538 
       
  2539 	if (hw->mac_type == e1000_82542_rev2_0)
       
  2540 		e1000_leave_82542_rst(adapter);
       
  2541 }
       
  2542 
       
  2543 /* Need to wait a few seconds after link up to get diagnostic information from
       
  2544  * the phy */
       
  2545 
       
  2546 static void
       
  2547 e1000_update_phy_info(unsigned long data)
       
  2548 {
       
  2549 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
       
  2550 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
       
  2551 }
       
  2552 
       
  2553 /**
       
  2554  * e1000_82547_tx_fifo_stall - Timer Call-back
       
  2555  * @data: pointer to adapter cast into an unsigned long
       
  2556  **/
       
  2557 
       
  2558 static void
       
  2559 e1000_82547_tx_fifo_stall(unsigned long data)
       
  2560 {
       
  2561 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
       
  2562 	struct net_device *netdev = adapter->netdev;
       
  2563 	uint32_t tctl;
       
  2564 
       
  2565 	if (atomic_read(&adapter->tx_fifo_stall)) {
       
  2566 		if ((E1000_READ_REG(&adapter->hw, TDT) ==
       
  2567 		    E1000_READ_REG(&adapter->hw, TDH)) &&
       
  2568 		   (E1000_READ_REG(&adapter->hw, TDFT) ==
       
  2569 		    E1000_READ_REG(&adapter->hw, TDFH)) &&
       
  2570 		   (E1000_READ_REG(&adapter->hw, TDFTS) ==
       
  2571 		    E1000_READ_REG(&adapter->hw, TDFHS))) {
       
  2572 			tctl = E1000_READ_REG(&adapter->hw, TCTL);
       
  2573 			E1000_WRITE_REG(&adapter->hw, TCTL,
       
  2574 					tctl & ~E1000_TCTL_EN);
       
  2575 			E1000_WRITE_REG(&adapter->hw, TDFT,
       
  2576 					adapter->tx_head_addr);
       
  2577 			E1000_WRITE_REG(&adapter->hw, TDFH,
       
  2578 					adapter->tx_head_addr);
       
  2579 			E1000_WRITE_REG(&adapter->hw, TDFTS,
       
  2580 					adapter->tx_head_addr);
       
  2581 			E1000_WRITE_REG(&adapter->hw, TDFHS,
       
  2582 					adapter->tx_head_addr);
       
  2583 			E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
       
  2584 			E1000_WRITE_FLUSH(&adapter->hw);
       
  2585 
       
  2586 			adapter->tx_fifo_head = 0;
       
  2587 			atomic_set(&adapter->tx_fifo_stall, 0);
       
  2588 			if (!adapter->ecdev) netif_wake_queue(netdev);
       
  2589 		} else {
       
  2590 			if (!adapter->ecdev)
       
  2591 				mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
       
  2592 		}
       
  2593 	}
       
  2594 }
       
  2595 
       
  2596 /**
       
  2597  * e1000_watchdog - Timer Call-back
       
  2598  * @data: pointer to adapter cast into an unsigned long
       
  2599  **/
       
  2600 static void
       
  2601 e1000_watchdog(unsigned long data)
       
  2602 {
       
  2603 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
       
  2604 	struct net_device *netdev = adapter->netdev;
       
  2605 	struct e1000_tx_ring *txdr = adapter->tx_ring;
       
  2606 	uint32_t link, tctl;
       
  2607 	int32_t ret_val;
       
  2608 
       
  2609 	ret_val = e1000_check_for_link(&adapter->hw);
       
  2610 	if ((ret_val == E1000_ERR_PHY) &&
       
  2611 	    (adapter->hw.phy_type == e1000_phy_igp_3) &&
       
  2612 	    (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
       
  2613 		/* See e1000_kumeran_lock_loss_workaround() */
       
  2614 		DPRINTK(LINK, INFO,
       
  2615 			"Gigabit has been disabled, downgrading speed\n");
       
  2616 	}
       
  2617 
       
  2618 	if (adapter->hw.mac_type == e1000_82573) {
       
  2619 		e1000_enable_tx_pkt_filtering(&adapter->hw);
       
  2620 		if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
       
  2621 			e1000_update_mng_vlan(adapter);
       
  2622 	}
       
  2623 
       
  2624 	if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
       
  2625 	   !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
       
  2626 		link = !adapter->hw.serdes_link_down;
       
  2627 	else
       
  2628 		link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
       
  2629 
       
  2630 	if (link) {
       
  2631 		if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev))
       
  2632 				|| (!adapter->ecdev && !netif_carrier_ok(netdev))) {
       
  2633 			uint32_t ctrl;
       
  2634 			boolean_t txb2b = 1;
       
  2635 			e1000_get_speed_and_duplex(&adapter->hw,
       
  2636 			                           &adapter->link_speed,
       
  2637 			                           &adapter->link_duplex);
       
  2638 
       
  2639 			ctrl = E1000_READ_REG(&adapter->hw, CTRL);
       
  2640 			DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
       
  2641 			        "Flow Control: %s\n",
       
  2642 			        adapter->link_speed,
       
  2643 			        adapter->link_duplex == FULL_DUPLEX ?
       
  2644 			        "Full Duplex" : "Half Duplex",
       
  2645 			        ((ctrl & E1000_CTRL_TFCE) && (ctrl &
       
  2646 			        E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
       
  2647 			        E1000_CTRL_RFCE) ? "RX" : ((ctrl &
       
  2648 			        E1000_CTRL_TFCE) ? "TX" : "None" )));
       
  2649 
       
  2650 			/* tweak tx_queue_len according to speed/duplex
       
  2651 			 * and adjust the timeout factor */
       
  2652 			netdev->tx_queue_len = adapter->tx_queue_len;
       
  2653 			adapter->tx_timeout_factor = 1;
       
  2654 			switch (adapter->link_speed) {
       
  2655 			case SPEED_10:
       
  2656 				txb2b = 0;
       
  2657 				netdev->tx_queue_len = 10;
       
  2658 				adapter->tx_timeout_factor = 8;
       
  2659 				break;
       
  2660 			case SPEED_100:
       
  2661 				txb2b = 0;
       
  2662 				netdev->tx_queue_len = 100;
       
  2663 				/* maybe add some timeout factor ? */
       
  2664 				break;
       
  2665 			}
       
  2666 
       
  2667 			if ((adapter->hw.mac_type == e1000_82571 ||
       
  2668 			     adapter->hw.mac_type == e1000_82572) &&
       
  2669 			    txb2b == 0) {
       
  2670 				uint32_t tarc0;
       
  2671 				tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
       
  2672 				tarc0 &= ~(1 << 21);
       
  2673 				E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
       
  2674 			}
       
  2675 
       
  2676 			/* disable TSO for pcie and 10/100 speeds, to avoid
       
  2677 			 * some hardware issues */
       
  2678 			if (!adapter->tso_force &&
       
  2679 			    adapter->hw.bus_type == e1000_bus_type_pci_express){
       
  2680 				switch (adapter->link_speed) {
       
  2681 				case SPEED_10:
       
  2682 				case SPEED_100:
       
  2683 					DPRINTK(PROBE,INFO,
       
  2684 				        "10/100 speed: disabling TSO\n");
       
  2685 					netdev->features &= ~NETIF_F_TSO;
       
  2686 					netdev->features &= ~NETIF_F_TSO6;
       
  2687 					break;
       
  2688 				case SPEED_1000:
       
  2689 					netdev->features |= NETIF_F_TSO;
       
  2690 					netdev->features |= NETIF_F_TSO6;
       
  2691 					break;
       
  2692 				default:
       
  2693 					/* oops */
       
  2694 					break;
       
  2695 				}
       
  2696 			}
       
  2697 
       
  2698 			/* enable transmits in the hardware, need to do this
       
  2699 			 * after setting TARC0 */
       
  2700 			tctl = E1000_READ_REG(&adapter->hw, TCTL);
       
  2701 			tctl |= E1000_TCTL_EN;
       
  2702 			E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
       
  2703 
       
  2704 			if (adapter->ecdev) {
       
  2705 				ecdev_set_link(adapter->ecdev, 1);
       
  2706 			} else {
       
  2707 				netif_carrier_on(netdev);
       
  2708 				netif_wake_queue(netdev);
       
  2709 				mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
       
  2710 			}
       
  2711 			adapter->smartspeed = 0;
       
  2712 		} else {
       
  2713 			/* make sure the receive unit is started */
       
  2714 			if (adapter->hw.rx_needs_kicking) {
       
  2715 				struct e1000_hw *hw = &adapter->hw;
       
  2716 				uint32_t rctl = E1000_READ_REG(hw, RCTL);
       
  2717 				E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
       
  2718 			}
       
  2719 		}
       
  2720 	} else {
       
  2721 		if ((adapter->ecdev && ecdev_get_link(adapter->ecdev))
       
  2722 				|| (!adapter->ecdev && netif_carrier_ok(netdev))) {
       
  2723 			adapter->link_speed = 0;
       
  2724 			adapter->link_duplex = 0;
       
  2725 			DPRINTK(LINK, INFO, "NIC Link is Down\n");
       
  2726 			if (adapter->ecdev) {
       
  2727 				ecdev_set_link(adapter->ecdev, 0);
       
  2728 			} else {
       
  2729 				netif_carrier_off(netdev);
       
  2730 				netif_stop_queue(netdev);
       
  2731 				mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
       
  2732 			}
       
  2733 
       
  2734 			/* 80003ES2LAN workaround--
       
  2735 			 * For packet buffer work-around on link down event;
       
  2736 			 * disable receives in the ISR and
       
  2737 			 * reset device here in the watchdog
       
  2738 			 */
       
  2739 			if (adapter->hw.mac_type == e1000_80003es2lan)
       
  2740 				/* reset device */
       
  2741 				schedule_work(&adapter->reset_task);
       
  2742 		}
       
  2743 
       
  2744 		e1000_smartspeed(adapter);
       
  2745 	}
       
  2746 
       
  2747 	e1000_update_stats(adapter);
       
  2748 
       
  2749 	adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
       
  2750 	adapter->tpt_old = adapter->stats.tpt;
       
  2751 	adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
       
  2752 	adapter->colc_old = adapter->stats.colc;
       
  2753 
       
  2754 	adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
       
  2755 	adapter->gorcl_old = adapter->stats.gorcl;
       
  2756 	adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
       
  2757 	adapter->gotcl_old = adapter->stats.gotcl;
       
  2758 
       
  2759 	e1000_update_adaptive(&adapter->hw);
       
  2760 
       
  2761 	if (!adapter->ecdev && !netif_carrier_ok(netdev)) {
       
  2762 		if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
       
  2763 			/* We've lost link, so the controller stops DMA,
       
  2764 			 * but we've got queued Tx work that's never going
       
  2765 			 * to get done, so reset controller to flush Tx.
       
  2766 			 * (Do the reset outside of interrupt context). */
       
  2767 			adapter->tx_timeout_count++;
       
  2768 			schedule_work(&adapter->reset_task);
       
  2769 		}
       
  2770 	}
       
  2771 
       
  2772 	/* Cause software interrupt to ensure rx ring is cleaned */
       
  2773 	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
       
  2774 
       
  2775 	/* Force detection of hung controller every watchdog period */
       
  2776 	if (!adapter->ecdev) adapter->detect_tx_hung = TRUE;
       
  2777 
       
  2778 	/* With 82571 controllers, LAA may be overwritten due to controller
       
  2779 	 * reset from the other port. Set the appropriate LAA in RAR[0] */
       
  2780 	if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
       
  2781 		e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
       
  2782 
       
  2783 	/* Reset the timer */
       
  2784 	if (!adapter->ecdev)
       
  2785 		mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
       
  2786 }
       
  2787 
       
  2788 enum latency_range {
       
  2789 	lowest_latency = 0,
       
  2790 	low_latency = 1,
       
  2791 	bulk_latency = 2,
       
  2792 	latency_invalid = 255
       
  2793 };
       
  2794 
       
  2795 /**
       
  2796  * e1000_update_itr - update the dynamic ITR value based on statistics
       
  2797  *      Stores a new ITR value based on packets and byte
       
  2798  *      counts during the last interrupt.  The advantage of per interrupt
       
  2799  *      computation is faster updates and more accurate ITR for the current
       
  2800  *      traffic pattern.  Constants in this function were computed
       
  2801  *      based on theoretical maximum wire speed and thresholds were set based
       
  2802  *      on testing data as well as attempting to minimize response time
       
  2803  *      while increasing bulk throughput.
       
  2804  *      this functionality is controlled by the InterruptThrottleRate module
       
  2805  *      parameter (see e1000_param.c)
       
  2806  * @adapter: pointer to adapter
       
  2807  * @itr_setting: current adapter->itr
       
  2808  * @packets: the number of packets during this measurement interval
       
  2809  * @bytes: the number of bytes during this measurement interval
       
  2810  **/
       
  2811 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
       
  2812                                    uint16_t itr_setting,
       
  2813                                    int packets,
       
  2814                                    int bytes)
       
  2815 {
       
  2816 	unsigned int retval = itr_setting;
       
  2817 	struct e1000_hw *hw = &adapter->hw;
       
  2818 
       
  2819 	if (unlikely(hw->mac_type < e1000_82540))
       
  2820 		goto update_itr_done;
       
  2821 
       
  2822 	if (packets == 0)
       
  2823 		goto update_itr_done;
       
  2824 
       
  2825 	switch (itr_setting) {
       
  2826 	case lowest_latency:
       
  2827 		/* jumbo frames get bulk treatment*/
       
  2828 		if (bytes/packets > 8000)
       
  2829 			retval = bulk_latency;
       
  2830 		else if ((packets < 5) && (bytes > 512))
       
  2831 			retval = low_latency;
       
  2832 		break;
       
  2833 	case low_latency:  /* 50 usec aka 20000 ints/s */
       
  2834 		if (bytes > 10000) {
       
  2835 			/* jumbo frames need bulk latency setting */
       
  2836 			if (bytes/packets > 8000)
       
  2837 				retval = bulk_latency;
       
  2838 			else if ((packets < 10) || ((bytes/packets) > 1200))
       
  2839 				retval = bulk_latency;
       
  2840 			else if ((packets > 35))
       
  2841 				retval = lowest_latency;
       
  2842 		} else if (bytes/packets > 2000)
       
  2843 			retval = bulk_latency;
       
  2844 		else if (packets <= 2 && bytes < 512)
       
  2845 			retval = lowest_latency;
       
  2846 		break;
       
  2847 	case bulk_latency: /* 250 usec aka 4000 ints/s */
       
  2848 		if (bytes > 25000) {
       
  2849 			if (packets > 35)
       
  2850 				retval = low_latency;
       
  2851 		} else if (bytes < 6000) {
       
  2852 			retval = low_latency;
       
  2853 		}
       
  2854 		break;
       
  2855 	}
       
  2856 
       
  2857 update_itr_done:
       
  2858 	return retval;
       
  2859 }
       
  2860 
       
  2861 static void e1000_set_itr(struct e1000_adapter *adapter)
       
  2862 {
       
  2863 	struct e1000_hw *hw = &adapter->hw;
       
  2864 	uint16_t current_itr;
       
  2865 	uint32_t new_itr = adapter->itr;
       
  2866 
       
  2867 	if (unlikely(hw->mac_type < e1000_82540))
       
  2868 		return;
       
  2869 
       
  2870 	/* for non-gigabit speeds, just fix the interrupt rate at 4000 */
       
  2871 	if (unlikely(adapter->link_speed != SPEED_1000)) {
       
  2872 		current_itr = 0;
       
  2873 		new_itr = 4000;
       
  2874 		goto set_itr_now;
       
  2875 	}
       
  2876 
       
  2877 	adapter->tx_itr = e1000_update_itr(adapter,
       
  2878 	                            adapter->tx_itr,
       
  2879 	                            adapter->total_tx_packets,
       
  2880 	                            adapter->total_tx_bytes);
       
  2881 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
       
  2882 	if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
       
  2883 		adapter->tx_itr = low_latency;
       
  2884 
       
  2885 	adapter->rx_itr = e1000_update_itr(adapter,
       
  2886 	                            adapter->rx_itr,
       
  2887 	                            adapter->total_rx_packets,
       
  2888 	                            adapter->total_rx_bytes);
       
  2889 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
       
  2890 	if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
       
  2891 		adapter->rx_itr = low_latency;
       
  2892 
       
  2893 	current_itr = max(adapter->rx_itr, adapter->tx_itr);
       
  2894 
       
  2895 	switch (current_itr) {
       
  2896 	/* counts and packets in update_itr are dependent on these numbers */
       
  2897 	case lowest_latency:
       
  2898 		new_itr = 70000;
       
  2899 		break;
       
  2900 	case low_latency:
       
  2901 		new_itr = 20000; /* aka hwitr = ~200 */
       
  2902 		break;
       
  2903 	case bulk_latency:
       
  2904 		new_itr = 4000;
       
  2905 		break;
       
  2906 	default:
       
  2907 		break;
       
  2908 	}
       
  2909 
       
  2910 set_itr_now:
       
  2911 	if (new_itr != adapter->itr) {
       
  2912 		/* this attempts to bias the interrupt rate towards Bulk
       
  2913 		 * by adding intermediate steps when interrupt rate is
       
  2914 		 * increasing */
       
  2915 		new_itr = new_itr > adapter->itr ?
       
  2916 		             min(adapter->itr + (new_itr >> 2), new_itr) :
       
  2917 		             new_itr;
       
  2918 		adapter->itr = new_itr;
       
  2919 		E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
       
  2920 	}
       
  2921 
       
  2922 	return;
       
  2923 }
       
  2924 
       
  2925 #define E1000_TX_FLAGS_CSUM		0x00000001
       
  2926 #define E1000_TX_FLAGS_VLAN		0x00000002
       
  2927 #define E1000_TX_FLAGS_TSO		0x00000004
       
  2928 #define E1000_TX_FLAGS_IPV4		0x00000008
       
  2929 #define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
       
  2930 #define E1000_TX_FLAGS_VLAN_SHIFT	16
       
  2931 
       
  2932 static int
       
  2933 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
       
  2934           struct sk_buff *skb)
       
  2935 {
       
  2936 	struct e1000_context_desc *context_desc;
       
  2937 	struct e1000_buffer *buffer_info;
       
  2938 	unsigned int i;
       
  2939 	uint32_t cmd_length = 0;
       
  2940 	uint16_t ipcse = 0, tucse, mss;
       
  2941 	uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
       
  2942 	int err;
       
  2943 
       
  2944 	if (skb_is_gso(skb)) {
       
  2945 		if (skb_header_cloned(skb)) {
       
  2946 			err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
       
  2947 			if (err)
       
  2948 				return err;
       
  2949 		}
       
  2950 
       
  2951 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
       
  2952 		mss = skb_shinfo(skb)->gso_size;
       
  2953 		if (skb->protocol == htons(ETH_P_IP)) {
       
  2954 			struct iphdr *iph = ip_hdr(skb);
       
  2955 			iph->tot_len = 0;
       
  2956 			iph->check = 0;
       
  2957 			tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
       
  2958 								 iph->daddr, 0,
       
  2959 								 IPPROTO_TCP,
       
  2960 								 0);
       
  2961 			cmd_length = E1000_TXD_CMD_IP;
       
  2962 			ipcse = skb_transport_offset(skb) - 1;
       
  2963 		} else if (skb->protocol == htons(ETH_P_IPV6)) {
       
  2964 			ipv6_hdr(skb)->payload_len = 0;
       
  2965 			tcp_hdr(skb)->check =
       
  2966 				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
       
  2967 						 &ipv6_hdr(skb)->daddr,
       
  2968 						 0, IPPROTO_TCP, 0);
       
  2969 			ipcse = 0;
       
  2970 		}
       
  2971 		ipcss = skb_network_offset(skb);
       
  2972 		ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
       
  2973 		tucss = skb_transport_offset(skb);
       
  2974 		tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
       
  2975 		tucse = 0;
       
  2976 
       
  2977 		cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
       
  2978 			       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
       
  2979 
       
  2980 		i = tx_ring->next_to_use;
       
  2981 		context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
       
  2982 		buffer_info = &tx_ring->buffer_info[i];
       
  2983 
       
  2984 		context_desc->lower_setup.ip_fields.ipcss  = ipcss;
       
  2985 		context_desc->lower_setup.ip_fields.ipcso  = ipcso;
       
  2986 		context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
       
  2987 		context_desc->upper_setup.tcp_fields.tucss = tucss;
       
  2988 		context_desc->upper_setup.tcp_fields.tucso = tucso;
       
  2989 		context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
       
  2990 		context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
       
  2991 		context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
       
  2992 		context_desc->cmd_and_length = cpu_to_le32(cmd_length);
       
  2993 
       
  2994 		buffer_info->time_stamp = jiffies;
       
  2995 		buffer_info->next_to_watch = i;
       
  2996 
       
  2997 		if (++i == tx_ring->count) i = 0;
       
  2998 		tx_ring->next_to_use = i;
       
  2999 
       
  3000 		return TRUE;
       
  3001 	}
       
  3002 	return FALSE;
       
  3003 }
       
  3004 
       
  3005 static boolean_t
       
  3006 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
       
  3007               struct sk_buff *skb)
       
  3008 {
       
  3009 	struct e1000_context_desc *context_desc;
       
  3010 	struct e1000_buffer *buffer_info;
       
  3011 	unsigned int i;
       
  3012 	uint8_t css;
       
  3013 
       
  3014 	if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
       
  3015 		css = skb_transport_offset(skb);
       
  3016 
       
  3017 		i = tx_ring->next_to_use;
       
  3018 		buffer_info = &tx_ring->buffer_info[i];
       
  3019 		context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
       
  3020 
       
  3021 		context_desc->lower_setup.ip_config = 0;
       
  3022 		context_desc->upper_setup.tcp_fields.tucss = css;
       
  3023 		context_desc->upper_setup.tcp_fields.tucso =
       
  3024 			css + skb->csum_offset;
       
  3025 		context_desc->upper_setup.tcp_fields.tucse = 0;
       
  3026 		context_desc->tcp_seg_setup.data = 0;
       
  3027 		context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
       
  3028 
       
  3029 		buffer_info->time_stamp = jiffies;
       
  3030 		buffer_info->next_to_watch = i;
       
  3031 
       
  3032 		if (unlikely(++i == tx_ring->count)) i = 0;
       
  3033 		tx_ring->next_to_use = i;
       
  3034 
       
  3035 		return TRUE;
       
  3036 	}
       
  3037 
       
  3038 	return FALSE;
       
  3039 }
       
  3040 
       
  3041 #define E1000_MAX_TXD_PWR	12
       
  3042 #define E1000_MAX_DATA_PER_TXD	(1<<E1000_MAX_TXD_PWR)
       
  3043 
       
  3044 static int
       
  3045 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
       
  3046              struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
       
  3047              unsigned int nr_frags, unsigned int mss)
       
  3048 {
       
  3049 	struct e1000_buffer *buffer_info;
       
  3050 	unsigned int len = skb->len;
       
  3051 	unsigned int offset = 0, size, count = 0, i;
       
  3052 	unsigned int f;
       
  3053 	len -= skb->data_len;
       
  3054 
       
  3055 	i = tx_ring->next_to_use;
       
  3056 
       
  3057 	while (len) {
       
  3058 		buffer_info = &tx_ring->buffer_info[i];
       
  3059 		size = min(len, max_per_txd);
       
  3060 		/* Workaround for Controller erratum --
       
  3061 		 * descriptor for non-tso packet in a linear SKB that follows a
       
  3062 		 * tso gets written back prematurely before the data is fully
       
  3063 		 * DMA'd to the controller */
       
  3064 		if (!skb->data_len && tx_ring->last_tx_tso &&
       
  3065 		    !skb_is_gso(skb)) {
       
  3066 			tx_ring->last_tx_tso = 0;
       
  3067 			size -= 4;
       
  3068 		}
       
  3069 
       
  3070 		/* Workaround for premature desc write-backs
       
  3071 		 * in TSO mode.  Append 4-byte sentinel desc */
       
  3072 		if (unlikely(mss && !nr_frags && size == len && size > 8))
       
  3073 			size -= 4;
       
  3074 		/* work-around for errata 10 and it applies
       
  3075 		 * to all controllers in PCI-X mode
       
  3076 		 * The fix is to make sure that the first descriptor of a
       
  3077 		 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
       
  3078 		 */
       
  3079 		if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
       
  3080 		                (size > 2015) && count == 0))
       
  3081 		        size = 2015;
       
  3082 
       
  3083 		/* Workaround for potential 82544 hang in PCI-X.  Avoid
       
  3084 		 * terminating buffers within evenly-aligned dwords. */
       
  3085 		if (unlikely(adapter->pcix_82544 &&
       
  3086 		   !((unsigned long)(skb->data + offset + size - 1) & 4) &&
       
  3087 		   size > 4))
       
  3088 			size -= 4;
       
  3089 
       
  3090 		buffer_info->length = size;
       
  3091 		buffer_info->dma =
       
  3092 			pci_map_single(adapter->pdev,
       
  3093 				skb->data + offset,
       
  3094 				size,
       
  3095 				PCI_DMA_TODEVICE);
       
  3096 		buffer_info->time_stamp = jiffies;
       
  3097 		buffer_info->next_to_watch = i;
       
  3098 
       
  3099 		len -= size;
       
  3100 		offset += size;
       
  3101 		count++;
       
  3102 		if (unlikely(++i == tx_ring->count)) i = 0;
       
  3103 	}
       
  3104 
       
  3105 	for (f = 0; f < nr_frags; f++) {
       
  3106 		struct skb_frag_struct *frag;
       
  3107 
       
  3108 		frag = &skb_shinfo(skb)->frags[f];
       
  3109 		len = frag->size;
       
  3110 		offset = frag->page_offset;
       
  3111 
       
  3112 		while (len) {
       
  3113 			buffer_info = &tx_ring->buffer_info[i];
       
  3114 			size = min(len, max_per_txd);
       
  3115 			/* Workaround for premature desc write-backs
       
  3116 			 * in TSO mode.  Append 4-byte sentinel desc */
       
  3117 			if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
       
  3118 				size -= 4;
       
  3119 			/* Workaround for potential 82544 hang in PCI-X.
       
  3120 			 * Avoid terminating buffers within evenly-aligned
       
  3121 			 * dwords. */
       
  3122 			if (unlikely(adapter->pcix_82544 &&
       
  3123 			   !((unsigned long)(frag->page+offset+size-1) & 4) &&
       
  3124 			   size > 4))
       
  3125 				size -= 4;
       
  3126 
       
  3127 			buffer_info->length = size;
       
  3128 			buffer_info->dma =
       
  3129 				pci_map_page(adapter->pdev,
       
  3130 					frag->page,
       
  3131 					offset,
       
  3132 					size,
       
  3133 					PCI_DMA_TODEVICE);
       
  3134 			buffer_info->time_stamp = jiffies;
       
  3135 			buffer_info->next_to_watch = i;
       
  3136 
       
  3137 			len -= size;
       
  3138 			offset += size;
       
  3139 			count++;
       
  3140 			if (unlikely(++i == tx_ring->count)) i = 0;
       
  3141 		}
       
  3142 	}
       
  3143 
       
  3144 	i = (i == 0) ? tx_ring->count - 1 : i - 1;
       
  3145 	tx_ring->buffer_info[i].skb = skb;
       
  3146 	tx_ring->buffer_info[first].next_to_watch = i;
       
  3147 
       
  3148 	return count;
       
  3149 }
       
  3150 
       
  3151 static void
       
  3152 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
       
  3153                int tx_flags, int count)
       
  3154 {
       
  3155 	struct e1000_tx_desc *tx_desc = NULL;
       
  3156 	struct e1000_buffer *buffer_info;
       
  3157 	uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
       
  3158 	unsigned int i;
       
  3159 
       
  3160 	if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
       
  3161 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
       
  3162 		             E1000_TXD_CMD_TSE;
       
  3163 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
       
  3164 
       
  3165 		if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
       
  3166 			txd_upper |= E1000_TXD_POPTS_IXSM << 8;
       
  3167 	}
       
  3168 
       
  3169 	if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
       
  3170 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
       
  3171 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
       
  3172 	}
       
  3173 
       
  3174 	if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
       
  3175 		txd_lower |= E1000_TXD_CMD_VLE;
       
  3176 		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
       
  3177 	}
       
  3178 
       
  3179 	i = tx_ring->next_to_use;
       
  3180 
       
  3181 	while (count--) {
       
  3182 		buffer_info = &tx_ring->buffer_info[i];
       
  3183 		tx_desc = E1000_TX_DESC(*tx_ring, i);
       
  3184 		tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
       
  3185 		tx_desc->lower.data =
       
  3186 			cpu_to_le32(txd_lower | buffer_info->length);
       
  3187 		tx_desc->upper.data = cpu_to_le32(txd_upper);
       
  3188 		if (unlikely(++i == tx_ring->count)) i = 0;
       
  3189 	}
       
  3190 
       
  3191 	tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
       
  3192 
       
  3193 	/* Force memory writes to complete before letting h/w
       
  3194 	 * know there are new descriptors to fetch.  (Only
       
  3195 	 * applicable for weak-ordered memory model archs,
       
  3196 	 * such as IA-64). */
       
  3197 	wmb();
       
  3198 
       
  3199 	tx_ring->next_to_use = i;
       
  3200 	writel(i, adapter->hw.hw_addr + tx_ring->tdt);
       
  3201 	/* we need this if more than one processor can write to our tail
       
  3202 	 * at a time, it syncronizes IO on IA64/Altix systems */
       
  3203 	mmiowb();
       
  3204 }
       
  3205 
       
  3206 /**
       
  3207  * 82547 workaround to avoid controller hang in half-duplex environment.
       
  3208  * The workaround is to avoid queuing a large packet that would span
       
  3209  * the internal Tx FIFO ring boundary by notifying the stack to resend
       
  3210  * the packet at a later time.  This gives the Tx FIFO an opportunity to
       
  3211  * flush all packets.  When that occurs, we reset the Tx FIFO pointers
       
  3212  * to the beginning of the Tx FIFO.
       
  3213  **/
       
  3214 
       
  3215 #define E1000_FIFO_HDR			0x10
       
  3216 #define E1000_82547_PAD_LEN		0x3E0
       
  3217 
       
  3218 static int
       
  3219 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
       
  3220 {
       
  3221 	uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
       
  3222 	uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
       
  3223 
       
  3224 	skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
       
  3225 
       
  3226 	if (adapter->link_duplex != HALF_DUPLEX)
       
  3227 		goto no_fifo_stall_required;
       
  3228 
       
  3229 	if (atomic_read(&adapter->tx_fifo_stall))
       
  3230 		return 1;
       
  3231 
       
  3232 	if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
       
  3233 		atomic_set(&adapter->tx_fifo_stall, 1);
       
  3234 		return 1;
       
  3235 	}
       
  3236 
       
  3237 no_fifo_stall_required:
       
  3238 	adapter->tx_fifo_head += skb_fifo_len;
       
  3239 	if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
       
  3240 		adapter->tx_fifo_head -= adapter->tx_fifo_size;
       
  3241 	return 0;
       
  3242 }
       
  3243 
       
  3244 #define MINIMUM_DHCP_PACKET_SIZE 282
       
  3245 static int
       
  3246 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
       
  3247 {
       
  3248 	struct e1000_hw *hw =  &adapter->hw;
       
  3249 	uint16_t length, offset;
       
  3250 	if (vlan_tx_tag_present(skb)) {
       
  3251 		if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
       
  3252 			( adapter->hw.mng_cookie.status &
       
  3253 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
       
  3254 			return 0;
       
  3255 	}
       
  3256 	if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
       
  3257 		struct ethhdr *eth = (struct ethhdr *) skb->data;
       
  3258 		if ((htons(ETH_P_IP) == eth->h_proto)) {
       
  3259 			const struct iphdr *ip =
       
  3260 				(struct iphdr *)((uint8_t *)skb->data+14);
       
  3261 			if (IPPROTO_UDP == ip->protocol) {
       
  3262 				struct udphdr *udp =
       
  3263 					(struct udphdr *)((uint8_t *)ip +
       
  3264 						(ip->ihl << 2));
       
  3265 				if (ntohs(udp->dest) == 67) {
       
  3266 					offset = (uint8_t *)udp + 8 - skb->data;
       
  3267 					length = skb->len - offset;
       
  3268 
       
  3269 					return e1000_mng_write_dhcp_info(hw,
       
  3270 							(uint8_t *)udp + 8,
       
  3271 							length);
       
  3272 				}
       
  3273 			}
       
  3274 		}
       
  3275 	}
       
  3276 	return 0;
       
  3277 }
       
  3278 
       
  3279 static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
       
  3280 {
       
  3281 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3282 	struct e1000_tx_ring *tx_ring = adapter->tx_ring;
       
  3283 
       
  3284 	netif_stop_queue(netdev);
       
  3285 	/* Herbert's original patch had:
       
  3286 	 *  smp_mb__after_netif_stop_queue();
       
  3287 	 * but since that doesn't exist yet, just open code it. */
       
  3288 	smp_mb();
       
  3289 
       
  3290 	/* We need to check again in a case another CPU has just
       
  3291 	 * made room available. */
       
  3292 	if (likely(E1000_DESC_UNUSED(tx_ring) < size))
       
  3293 		return -EBUSY;
       
  3294 
       
  3295 	/* A reprieve! */
       
  3296 	netif_start_queue(netdev);
       
  3297 	++adapter->restart_queue;
       
  3298 	return 0;
       
  3299 }
       
  3300 
       
  3301 static int e1000_maybe_stop_tx(struct net_device *netdev,
       
  3302                                struct e1000_tx_ring *tx_ring, int size)
       
  3303 {
       
  3304 	if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
       
  3305 		return 0;
       
  3306 	return __e1000_maybe_stop_tx(netdev, size);
       
  3307 }
       
  3308 
       
  3309 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
       
  3310 static int
       
  3311 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
       
  3312 {
       
  3313 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3314 	struct e1000_tx_ring *tx_ring;
       
  3315 	unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
       
  3316 	unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
       
  3317 	unsigned int tx_flags = 0;
       
  3318 	unsigned int len = skb->len;
       
  3319 	unsigned long flags = 0;
       
  3320 	unsigned int nr_frags = 0;
       
  3321 	unsigned int mss = 0;
       
  3322 	int count = 0;
       
  3323 	int tso;
       
  3324 	unsigned int f;
       
  3325 	len -= skb->data_len;
       
  3326 
       
  3327 	/* This goes back to the question of how to logically map a tx queue
       
  3328 	 * to a flow.  Right now, performance is impacted slightly negatively
       
  3329 	 * if using multiple tx queues.  If the stack breaks away from a
       
  3330 	 * single qdisc implementation, we can look at this again. */
       
  3331 	tx_ring = adapter->tx_ring;
       
  3332 
       
  3333 	if (unlikely(skb->len <= 0)) {
       
  3334 		if (!adapter->ecdev)
       
  3335 			dev_kfree_skb_any(skb);
       
  3336 		return NETDEV_TX_OK;
       
  3337 	}
       
  3338 
       
  3339 	/* 82571 and newer doesn't need the workaround that limited descriptor
       
  3340 	 * length to 4kB */
       
  3341 	if (adapter->hw.mac_type >= e1000_82571)
       
  3342 		max_per_txd = 8192;
       
  3343 
       
  3344 	mss = skb_shinfo(skb)->gso_size;
       
  3345 	/* The controller does a simple calculation to
       
  3346 	 * make sure there is enough room in the FIFO before
       
  3347 	 * initiating the DMA for each buffer.  The calc is:
       
  3348 	 * 4 = ceil(buffer len/mss).  To make sure we don't
       
  3349 	 * overrun the FIFO, adjust the max buffer len if mss
       
  3350 	 * drops. */
       
  3351 	if (mss) {
       
  3352 		uint8_t hdr_len;
       
  3353 		max_per_txd = min(mss << 2, max_per_txd);
       
  3354 		max_txd_pwr = fls(max_per_txd) - 1;
       
  3355 
       
  3356 		/* TSO Workaround for 82571/2/3 Controllers -- if skb->data
       
  3357 		* points to just header, pull a few bytes of payload from
       
  3358 		* frags into skb->data */
       
  3359 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
       
  3360 		if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
       
  3361 			switch (adapter->hw.mac_type) {
       
  3362 				unsigned int pull_size;
       
  3363 			case e1000_82544:
       
  3364 				/* Make sure we have room to chop off 4 bytes,
       
  3365 				 * and that the end alignment will work out to
       
  3366 				 * this hardware's requirements
       
  3367 				 * NOTE: this is a TSO only workaround
       
  3368 				 * if end byte alignment not correct move us
       
  3369 				 * into the next dword */
       
  3370 				if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
       
  3371 					break;
       
  3372 				/* fall through */
       
  3373 			case e1000_82571:
       
  3374 			case e1000_82572:
       
  3375 			case e1000_82573:
       
  3376 			case e1000_ich8lan:
       
  3377 				pull_size = min((unsigned int)4, skb->data_len);
       
  3378 				if (!__pskb_pull_tail(skb, pull_size)) {
       
  3379 					DPRINTK(DRV, ERR,
       
  3380 						"__pskb_pull_tail failed.\n");
       
  3381 					dev_kfree_skb_any(skb);
       
  3382 					return NETDEV_TX_OK;
       
  3383 				}
       
  3384 				len = skb->len - skb->data_len;
       
  3385 				break;
       
  3386 			default:
       
  3387 				/* do nothing */
       
  3388 				break;
       
  3389 			}
       
  3390 		}
       
  3391 	}
       
  3392 
       
  3393 	/* reserve a descriptor for the offload context */
       
  3394 	if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
       
  3395 		count++;
       
  3396 	count++;
       
  3397 
       
  3398 	/* Controller Erratum workaround */
       
  3399 	if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
       
  3400 		count++;
       
  3401 
       
  3402 	count += TXD_USE_COUNT(len, max_txd_pwr);
       
  3403 
       
  3404 	if (adapter->pcix_82544)
       
  3405 		count++;
       
  3406 
       
  3407 	/* work-around for errata 10 and it applies to all controllers
       
  3408 	 * in PCI-X mode, so add one more descriptor to the count
       
  3409 	 */
       
  3410 	if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
       
  3411 			(len > 2015)))
       
  3412 		count++;
       
  3413 
       
  3414 	nr_frags = skb_shinfo(skb)->nr_frags;
       
  3415 	for (f = 0; f < nr_frags; f++)
       
  3416 		count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
       
  3417 				       max_txd_pwr);
       
  3418 	if (adapter->pcix_82544)
       
  3419 		count += nr_frags;
       
  3420 
       
  3421 
       
  3422 	if (adapter->hw.tx_pkt_filtering &&
       
  3423 	    (adapter->hw.mac_type == e1000_82573))
       
  3424 		e1000_transfer_dhcp_info(adapter, skb);
       
  3425 
       
  3426 	if (!adapter->ecdev)
       
  3427 		if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
       
  3428 			/* Collision - tell upper layer to requeue */
       
  3429 			return NETDEV_TX_LOCKED;
       
  3430 
       
  3431 	/* need: count + 2 desc gap to keep tail from touching
       
  3432 	 * head, otherwise try next time */
       
  3433 	if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
       
  3434 		spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
       
  3435 		return NETDEV_TX_BUSY;
       
  3436 	}
       
  3437 
       
  3438 	if (unlikely(adapter->hw.mac_type == e1000_82547)) {
       
  3439 		if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
       
  3440 			if (!adapter->ecdev) {
       
  3441 				netif_stop_queue(netdev);
       
  3442 				mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
       
  3443 				spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
       
  3444 			}
       
  3445 			return NETDEV_TX_BUSY;
       
  3446 		}
       
  3447 	}
       
  3448 
       
  3449 	if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
       
  3450 		tx_flags |= E1000_TX_FLAGS_VLAN;
       
  3451 		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
       
  3452 	}
       
  3453 
       
  3454 	first = tx_ring->next_to_use;
       
  3455 
       
  3456 	tso = e1000_tso(adapter, tx_ring, skb);
       
  3457 	if (tso < 0) {
       
  3458 		if (!adapter->ecdev) {
       
  3459 			dev_kfree_skb_any(skb);
       
  3460 			spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
       
  3461 		}
       
  3462 		return NETDEV_TX_OK;
       
  3463 	}
       
  3464 
       
  3465 	if (likely(tso)) {
       
  3466 		tx_ring->last_tx_tso = 1;
       
  3467 		tx_flags |= E1000_TX_FLAGS_TSO;
       
  3468 	} else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
       
  3469 		tx_flags |= E1000_TX_FLAGS_CSUM;
       
  3470 
       
  3471 	/* Old method was to assume IPv4 packet by default if TSO was enabled.
       
  3472 	 * 82571 hardware supports TSO capabilities for IPv6 as well...
       
  3473 	 * no longer assume, we must. */
       
  3474 	if (likely(skb->protocol == htons(ETH_P_IP)))
       
  3475 		tx_flags |= E1000_TX_FLAGS_IPV4;
       
  3476 
       
  3477 	e1000_tx_queue(adapter, tx_ring, tx_flags,
       
  3478 	               e1000_tx_map(adapter, tx_ring, skb, first,
       
  3479 	                            max_per_txd, nr_frags, mss));
       
  3480 
       
  3481 	netdev->trans_start = jiffies;
       
  3482 
       
  3483 	if (!adapter->ecdev) {
       
  3484 		/* Make sure there is space in the ring for the next send. */
       
  3485 		e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
       
  3486 
       
  3487 		spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
       
  3488 	}
       
  3489 	return NETDEV_TX_OK;
       
  3490 }
       
  3491 
       
  3492 /**
       
  3493  * e1000_tx_timeout - Respond to a Tx Hang
       
  3494  * @netdev: network interface device structure
       
  3495  **/
       
  3496 
       
  3497 static void
       
  3498 e1000_tx_timeout(struct net_device *netdev)
       
  3499 {
       
  3500 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3501 
       
  3502 	/* Do the reset outside of interrupt context */
       
  3503 	adapter->tx_timeout_count++;
       
  3504 	schedule_work(&adapter->reset_task);
       
  3505 }
       
  3506 
       
  3507 static void
       
  3508 e1000_reset_task(struct work_struct *work)
       
  3509 {
       
  3510 	struct e1000_adapter *adapter =
       
  3511 		container_of(work, struct e1000_adapter, reset_task);
       
  3512 
       
  3513 	e1000_reinit_locked(adapter);
       
  3514 }
       
  3515 
       
  3516 /**
       
  3517  * e1000_get_stats - Get System Network Statistics
       
  3518  * @netdev: network interface device structure
       
  3519  *
       
  3520  * Returns the address of the device statistics structure.
       
  3521  * The statistics are actually updated from the timer callback.
       
  3522  **/
       
  3523 
       
  3524 static struct net_device_stats *
       
  3525 e1000_get_stats(struct net_device *netdev)
       
  3526 {
       
  3527 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3528 
       
  3529 	/* only return the current stats */
       
  3530 	return &adapter->net_stats;
       
  3531 }
       
  3532 
       
  3533 /**
       
  3534  * e1000_change_mtu - Change the Maximum Transfer Unit
       
  3535  * @netdev: network interface device structure
       
  3536  * @new_mtu: new value for maximum frame size
       
  3537  *
       
  3538  * Returns 0 on success, negative on failure
       
  3539  **/
       
  3540 
       
  3541 static int
       
  3542 e1000_change_mtu(struct net_device *netdev, int new_mtu)
       
  3543 {
       
  3544 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3545 	int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
       
  3546 	uint16_t eeprom_data = 0;
       
  3547 
       
  3548 	if (adapter->ecdev)
       
  3549 		return -EBUSY;
       
  3550 
       
  3551 	if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
       
  3552 	    (max_frame > MAX_JUMBO_FRAME_SIZE)) {
       
  3553 		DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
       
  3554 		return -EINVAL;
       
  3555 	}
       
  3556 
       
  3557 	/* Adapter-specific max frame size limits. */
       
  3558 	switch (adapter->hw.mac_type) {
       
  3559 	case e1000_undefined ... e1000_82542_rev2_1:
       
  3560 	case e1000_ich8lan:
       
  3561 		if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
       
  3562 			DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
       
  3563 			return -EINVAL;
       
  3564 		}
       
  3565 		break;
       
  3566 	case e1000_82573:
       
  3567 		/* Jumbo Frames not supported if:
       
  3568 		 * - this is not an 82573L device
       
  3569 		 * - ASPM is enabled in any way (0x1A bits 3:2) */
       
  3570 		e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
       
  3571 		                  &eeprom_data);
       
  3572 		if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
       
  3573 		    (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
       
  3574 			if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
       
  3575 				DPRINTK(PROBE, ERR,
       
  3576 			            	"Jumbo Frames not supported.\n");
       
  3577 				return -EINVAL;
       
  3578 			}
       
  3579 			break;
       
  3580 		}
       
  3581 		/* ERT will be enabled later to enable wire speed receives */
       
  3582 
       
  3583 		/* fall through to get support */
       
  3584 	case e1000_82571:
       
  3585 	case e1000_82572:
       
  3586 	case e1000_80003es2lan:
       
  3587 #define MAX_STD_JUMBO_FRAME_SIZE 9234
       
  3588 		if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
       
  3589 			DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
       
  3590 			return -EINVAL;
       
  3591 		}
       
  3592 		break;
       
  3593 	default:
       
  3594 		/* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
       
  3595 		break;
       
  3596 	}
       
  3597 
       
  3598 	/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
       
  3599 	 * means we reserve 2 more, this pushes us to allocate from the next
       
  3600 	 * larger slab size
       
  3601 	 * i.e. RXBUFFER_2048 --> size-4096 slab */
       
  3602 
       
  3603 	if (max_frame <= E1000_RXBUFFER_256)
       
  3604 		adapter->rx_buffer_len = E1000_RXBUFFER_256;
       
  3605 	else if (max_frame <= E1000_RXBUFFER_512)
       
  3606 		adapter->rx_buffer_len = E1000_RXBUFFER_512;
       
  3607 	else if (max_frame <= E1000_RXBUFFER_1024)
       
  3608 		adapter->rx_buffer_len = E1000_RXBUFFER_1024;
       
  3609 	else if (max_frame <= E1000_RXBUFFER_2048)
       
  3610 		adapter->rx_buffer_len = E1000_RXBUFFER_2048;
       
  3611 	else if (max_frame <= E1000_RXBUFFER_4096)
       
  3612 		adapter->rx_buffer_len = E1000_RXBUFFER_4096;
       
  3613 	else if (max_frame <= E1000_RXBUFFER_8192)
       
  3614 		adapter->rx_buffer_len = E1000_RXBUFFER_8192;
       
  3615 	else if (max_frame <= E1000_RXBUFFER_16384)
       
  3616 		adapter->rx_buffer_len = E1000_RXBUFFER_16384;
       
  3617 
       
  3618 	/* adjust allocation if LPE protects us, and we aren't using SBP */
       
  3619 	if (!adapter->hw.tbi_compatibility_on &&
       
  3620 	    ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
       
  3621 	     (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
       
  3622 		adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
       
  3623 
       
  3624 	netdev->mtu = new_mtu;
       
  3625 	adapter->hw.max_frame_size = max_frame;
       
  3626 
       
  3627 	if (netif_running(netdev))
       
  3628 		e1000_reinit_locked(adapter);
       
  3629 
       
  3630 	return 0;
       
  3631 }
       
  3632 
       
  3633 /**
       
  3634  * e1000_update_stats - Update the board statistics counters
       
  3635  * @adapter: board private structure
       
  3636  **/
       
  3637 
       
  3638 void
       
  3639 e1000_update_stats(struct e1000_adapter *adapter)
       
  3640 {
       
  3641 	struct e1000_hw *hw = &adapter->hw;
       
  3642 	struct pci_dev *pdev = adapter->pdev;
       
  3643 	unsigned long flags = 0;
       
  3644 	uint16_t phy_tmp;
       
  3645 
       
  3646 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
       
  3647 
       
  3648 	/*
       
  3649 	 * Prevent stats update while adapter is being reset, or if the pci
       
  3650 	 * connection is down.
       
  3651 	 */
       
  3652 	if (adapter->link_speed == 0)
       
  3653 		return;
       
  3654 	if (pci_channel_offline(pdev))
       
  3655 		return;
       
  3656 
       
  3657 	if (!adapter->ecdev)
       
  3658 		spin_lock_irqsave(&adapter->stats_lock, flags);
       
  3659 
       
  3660 	/* these counters are modified from e1000_adjust_tbi_stats,
       
  3661 	 * called from the interrupt context, so they must only
       
  3662 	 * be written while holding adapter->stats_lock
       
  3663 	 */
       
  3664 
       
  3665 	adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
       
  3666 	adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
       
  3667 	adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
       
  3668 	adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
       
  3669 	adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
       
  3670 	adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
       
  3671 	adapter->stats.roc += E1000_READ_REG(hw, ROC);
       
  3672 
       
  3673 	if (adapter->hw.mac_type != e1000_ich8lan) {
       
  3674 		adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
       
  3675 		adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
       
  3676 		adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
       
  3677 		adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
       
  3678 		adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
       
  3679 		adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
       
  3680 	}
       
  3681 
       
  3682 	adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
       
  3683 	adapter->stats.mpc += E1000_READ_REG(hw, MPC);
       
  3684 	adapter->stats.scc += E1000_READ_REG(hw, SCC);
       
  3685 	adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
       
  3686 	adapter->stats.mcc += E1000_READ_REG(hw, MCC);
       
  3687 	adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
       
  3688 	adapter->stats.dc += E1000_READ_REG(hw, DC);
       
  3689 	adapter->stats.sec += E1000_READ_REG(hw, SEC);
       
  3690 	adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
       
  3691 	adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
       
  3692 	adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
       
  3693 	adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
       
  3694 	adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
       
  3695 	adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
       
  3696 	adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
       
  3697 	adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
       
  3698 	adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
       
  3699 	adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
       
  3700 	adapter->stats.ruc += E1000_READ_REG(hw, RUC);
       
  3701 	adapter->stats.rfc += E1000_READ_REG(hw, RFC);
       
  3702 	adapter->stats.rjc += E1000_READ_REG(hw, RJC);
       
  3703 	adapter->stats.torl += E1000_READ_REG(hw, TORL);
       
  3704 	adapter->stats.torh += E1000_READ_REG(hw, TORH);
       
  3705 	adapter->stats.totl += E1000_READ_REG(hw, TOTL);
       
  3706 	adapter->stats.toth += E1000_READ_REG(hw, TOTH);
       
  3707 	adapter->stats.tpr += E1000_READ_REG(hw, TPR);
       
  3708 
       
  3709 	if (adapter->hw.mac_type != e1000_ich8lan) {
       
  3710 		adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
       
  3711 		adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
       
  3712 		adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
       
  3713 		adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
       
  3714 		adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
       
  3715 		adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
       
  3716 	}
       
  3717 
       
  3718 	adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
       
  3719 	adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
       
  3720 
       
  3721 	/* used for adaptive IFS */
       
  3722 
       
  3723 	hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
       
  3724 	adapter->stats.tpt += hw->tx_packet_delta;
       
  3725 	hw->collision_delta = E1000_READ_REG(hw, COLC);
       
  3726 	adapter->stats.colc += hw->collision_delta;
       
  3727 
       
  3728 	if (hw->mac_type >= e1000_82543) {
       
  3729 		adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
       
  3730 		adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
       
  3731 		adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
       
  3732 		adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
       
  3733 		adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
       
  3734 		adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
       
  3735 	}
       
  3736 	if (hw->mac_type > e1000_82547_rev_2) {
       
  3737 		adapter->stats.iac += E1000_READ_REG(hw, IAC);
       
  3738 		adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
       
  3739 
       
  3740 		if (adapter->hw.mac_type != e1000_ich8lan) {
       
  3741 			adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
       
  3742 			adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
       
  3743 			adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
       
  3744 			adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
       
  3745 			adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
       
  3746 			adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
       
  3747 			adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
       
  3748 		}
       
  3749 	}
       
  3750 
       
  3751 	/* Fill out the OS statistics structure */
       
  3752 	adapter->net_stats.rx_packets = adapter->stats.gprc;
       
  3753 	adapter->net_stats.tx_packets = adapter->stats.gptc;
       
  3754 	adapter->net_stats.rx_bytes = adapter->stats.gorcl;
       
  3755 	adapter->net_stats.tx_bytes = adapter->stats.gotcl;
       
  3756 	adapter->net_stats.multicast = adapter->stats.mprc;
       
  3757 	adapter->net_stats.collisions = adapter->stats.colc;
       
  3758 
       
  3759 	/* Rx Errors */
       
  3760 
       
  3761 	/* RLEC on some newer hardware can be incorrect so build
       
  3762 	* our own version based on RUC and ROC */
       
  3763 	adapter->net_stats.rx_errors = adapter->stats.rxerrc +
       
  3764 		adapter->stats.crcerrs + adapter->stats.algnerrc +
       
  3765 		adapter->stats.ruc + adapter->stats.roc +
       
  3766 		adapter->stats.cexterr;
       
  3767 	adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
       
  3768 	adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
       
  3769 	adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
       
  3770 	adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
       
  3771 	adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
       
  3772 
       
  3773 	/* Tx Errors */
       
  3774 	adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
       
  3775 	adapter->net_stats.tx_errors = adapter->stats.txerrc;
       
  3776 	adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
       
  3777 	adapter->net_stats.tx_window_errors = adapter->stats.latecol;
       
  3778 	adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
       
  3779 	if (adapter->hw.bad_tx_carr_stats_fd &&
       
  3780 	    adapter->link_duplex == FULL_DUPLEX) {
       
  3781 		adapter->net_stats.tx_carrier_errors = 0;
       
  3782 		adapter->stats.tncrs = 0;
       
  3783 	}
       
  3784 
       
  3785 	/* Tx Dropped needs to be maintained elsewhere */
       
  3786 
       
  3787 	/* Phy Stats */
       
  3788 	if (hw->media_type == e1000_media_type_copper) {
       
  3789 		if ((adapter->link_speed == SPEED_1000) &&
       
  3790 		   (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
       
  3791 			phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
       
  3792 			adapter->phy_stats.idle_errors += phy_tmp;
       
  3793 		}
       
  3794 
       
  3795 		if ((hw->mac_type <= e1000_82546) &&
       
  3796 		   (hw->phy_type == e1000_phy_m88) &&
       
  3797 		   !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
       
  3798 			adapter->phy_stats.receive_errors += phy_tmp;
       
  3799 	}
       
  3800 
       
  3801 	/* Management Stats */
       
  3802 	if (adapter->hw.has_smbus) {
       
  3803 		adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
       
  3804 		adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
       
  3805 		adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
       
  3806 	}
       
  3807 
       
  3808 	if (!adapter->ecdev)
       
  3809 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
       
  3810 }
       
  3811 
       
  3812 void ec_poll(struct net_device *netdev)
       
  3813 {
       
  3814     struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3815 
       
  3816     if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) {
       
  3817         e1000_watchdog((unsigned long) adapter);
       
  3818         adapter->ec_watchdog_jiffies = jiffies;
       
  3819     }
       
  3820 
       
  3821 #ifdef CONFIG_PCI_MSI
       
  3822 	e1000_intr_msi(0, netdev);
       
  3823 #else
       
  3824     e1000_intr(0, netdev);
       
  3825 #endif
       
  3826 }
       
  3827 
       
  3828 /**
       
  3829  * e1000_intr_msi - Interrupt Handler
       
  3830  * @irq: interrupt number
       
  3831  * @data: pointer to a network interface device structure
       
  3832  **/
       
  3833 
       
  3834 static irqreturn_t
       
  3835 e1000_intr_msi(int irq, void *data)
       
  3836 {
       
  3837 	struct net_device *netdev = data;
       
  3838 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3839 	struct e1000_hw *hw = &adapter->hw;
       
  3840 	int i;
       
  3841 #ifdef CONFIG_E1000_NAPI
       
  3842 	int ec_work_done = 0;
       
  3843 #endif
       
  3844 	uint32_t icr = E1000_READ_REG(hw, ICR);
       
  3845 
       
  3846 	if (adapter->ecdev) {
       
  3847 		for (i = 0; i < E1000_MAX_INTR; i++)
       
  3848 #ifdef CONFIG_E1000_NAPI
       
  3849 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring,
       
  3850 							&ec_work_done, 100) &
       
  3851 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  3852 #else
       
  3853 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
       
  3854 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  3855 #endif
       
  3856 				break;
       
  3857 	} else {
       
  3858 #ifdef CONFIG_E1000_NAPI
       
  3859 		/* read ICR disables interrupts using IAM, so keep up with our
       
  3860 		 * enable/disable accounting */
       
  3861 		atomic_inc(&adapter->irq_sem);
       
  3862 #endif
       
  3863 		if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
       
  3864 			hw->get_link_status = 1;
       
  3865 			/* 80003ES2LAN workaround-- For packet buffer work-around on
       
  3866 			 * link down event; disable receives here in the ISR and reset
       
  3867 			 * adapter in watchdog */
       
  3868 			if (netif_carrier_ok(netdev) &&
       
  3869 					(adapter->hw.mac_type == e1000_80003es2lan)) {
       
  3870 				/* disable receives */
       
  3871 				uint32_t rctl = E1000_READ_REG(hw, RCTL);
       
  3872 				E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
       
  3873 			}
       
  3874 			/* guard against interrupt when we're going down */
       
  3875 			if (!test_bit(__E1000_DOWN, &adapter->flags))
       
  3876 				mod_timer(&adapter->watchdog_timer, jiffies + 1);
       
  3877 		}
       
  3878 
       
  3879 #ifdef CONFIG_E1000_NAPI
       
  3880 		if (likely(netif_rx_schedule_prep(netdev))) {
       
  3881 			adapter->total_tx_bytes = 0;
       
  3882 			adapter->total_tx_packets = 0;
       
  3883 			adapter->total_rx_bytes = 0;
       
  3884 			adapter->total_rx_packets = 0;
       
  3885 			__netif_rx_schedule(netdev);
       
  3886 		} else
       
  3887 			e1000_irq_enable(adapter);
       
  3888 #else
       
  3889 		adapter->total_tx_bytes = 0;
       
  3890 		adapter->total_rx_bytes = 0;
       
  3891 		adapter->total_tx_packets = 0;
       
  3892 		adapter->total_rx_packets = 0;
       
  3893 
       
  3894 		for (i = 0; i < E1000_MAX_INTR; i++)
       
  3895 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
       
  3896 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  3897 				break;
       
  3898 
       
  3899 		if (likely(adapter->itr_setting & 3))
       
  3900 			e1000_set_itr(adapter);
       
  3901 #endif
       
  3902 	}
       
  3903 
       
  3904 	return IRQ_HANDLED;
       
  3905 }
       
  3906 
       
  3907 /**
       
  3908  * e1000_intr - Interrupt Handler
       
  3909  * @irq: interrupt number
       
  3910  * @data: pointer to a network interface device structure
       
  3911  **/
       
  3912 
       
  3913 static irqreturn_t
       
  3914 e1000_intr(int irq, void *data)
       
  3915 {
       
  3916 	struct net_device *netdev = data;
       
  3917 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  3918 	struct e1000_hw *hw = &adapter->hw;
       
  3919 	uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
       
  3920 	int i;
       
  3921 #ifdef CONFIG_E1000_NAPI
       
  3922 	int ec_work_done = 0;
       
  3923 #endif
       
  3924 	if (unlikely(!icr))
       
  3925 		return IRQ_NONE;  /* Not our interrupt */
       
  3926 
       
  3927 #ifdef CONFIG_E1000_NAPI
       
  3928 	/* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
       
  3929 	 * not set, then the adapter didn't send an interrupt */
       
  3930 	if (unlikely(hw->mac_type >= e1000_82571 &&
       
  3931 	             !(icr & E1000_ICR_INT_ASSERTED)))
       
  3932 		return IRQ_NONE;
       
  3933 
       
  3934 	/* Interrupt Auto-Mask...upon reading ICR,
       
  3935 	 * interrupts are masked.  No need for the
       
  3936 	 * IMC write, but it does mean we should
       
  3937 	 * account for it ASAP. */
       
  3938 	if (!adapter->ecdev && likely(hw->mac_type >= e1000_82571))
       
  3939 		atomic_inc(&adapter->irq_sem);
       
  3940 #endif
       
  3941 
       
  3942 	if (!adapter->ecdev && unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
       
  3943 		hw->get_link_status = 1;
       
  3944 		/* 80003ES2LAN workaround--
       
  3945 		 * For packet buffer work-around on link down event;
       
  3946 		 * disable receives here in the ISR and
       
  3947 		 * reset adapter in watchdog
       
  3948 		 */
       
  3949 		if (netif_carrier_ok(netdev) &&
       
  3950 		    (adapter->hw.mac_type == e1000_80003es2lan)) {
       
  3951 			/* disable receives */
       
  3952 			rctl = E1000_READ_REG(hw, RCTL);
       
  3953 			E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
       
  3954 		}
       
  3955 		/* guard against interrupt when we're going down */
       
  3956 		if (!test_bit(__E1000_DOWN, &adapter->flags))
       
  3957 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
       
  3958 	}
       
  3959 
       
  3960 	if (adapter->ecdev) {
       
  3961 		for (i = 0; i < E1000_MAX_INTR; i++)
       
  3962 #ifdef CONFIG_E1000_NAPI
       
  3963 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring,
       
  3964                             &ec_work_done, 100) &
       
  3965 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  3966 #else
       
  3967 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
       
  3968 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  3969 #endif
       
  3970 				break;
       
  3971 	} else {
       
  3972 #ifdef CONFIG_E1000_NAPI
       
  3973 		if (unlikely(hw->mac_type < e1000_82571)) {
       
  3974 			/* disable interrupts, without the synchronize_irq bit */
       
  3975 			atomic_inc(&adapter->irq_sem);
       
  3976 			E1000_WRITE_REG(hw, IMC, ~0);
       
  3977 			E1000_WRITE_FLUSH(hw);
       
  3978 		}
       
  3979 		if (likely(netif_rx_schedule_prep(netdev))) {
       
  3980 			adapter->total_tx_bytes = 0;
       
  3981 			adapter->total_tx_packets = 0;
       
  3982 			adapter->total_rx_bytes = 0;
       
  3983 			adapter->total_rx_packets = 0;
       
  3984 			__netif_rx_schedule(netdev);
       
  3985 		} else
       
  3986 			/* this really should not happen! if it does it is basically a
       
  3987 			 * bug, but not a hard error, so enable ints and continue */
       
  3988 			e1000_irq_enable(adapter);
       
  3989 #else
       
  3990 		/* Writing IMC and IMS is needed for 82547.
       
  3991 		 * Due to Hub Link bus being occupied, an interrupt
       
  3992 		 * de-assertion message is not able to be sent.
       
  3993 		 * When an interrupt assertion message is generated later,
       
  3994 		 * two messages are re-ordered and sent out.
       
  3995 		 * That causes APIC to think 82547 is in de-assertion
       
  3996 		 * state, while 82547 is in assertion state, resulting
       
  3997 		 * in dead lock. Writing IMC forces 82547 into
       
  3998 		 * de-assertion state.
       
  3999 		 */
       
  4000 		if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
       
  4001 			atomic_inc(&adapter->irq_sem);
       
  4002 			E1000_WRITE_REG(hw, IMC, ~0);
       
  4003 		}
       
  4004 
       
  4005 		adapter->total_tx_bytes = 0;
       
  4006 		adapter->total_rx_bytes = 0;
       
  4007 		adapter->total_tx_packets = 0;
       
  4008 		adapter->total_rx_packets = 0;
       
  4009 
       
  4010 		for (i = 0; i < E1000_MAX_INTR; i++)
       
  4011 			if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
       
  4012 						!e1000_clean_tx_irq(adapter, adapter->tx_ring)))
       
  4013 				break;
       
  4014 
       
  4015 		if (likely(adapter->itr_setting & 3))
       
  4016 			e1000_set_itr(adapter);
       
  4017 
       
  4018 		if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
       
  4019 			e1000_irq_enable(adapter);
       
  4020 
       
  4021 #endif
       
  4022 	}
       
  4023 	return IRQ_HANDLED;
       
  4024 }
       
  4025 
       
  4026 #ifdef CONFIG_E1000_NAPI
       
  4027 /**
       
  4028  * e1000_clean - NAPI Rx polling callback
       
  4029  * @adapter: board private structure
       
  4030  **/
       
  4031 
       
  4032 static int
       
  4033 e1000_clean(struct net_device *poll_dev, int *budget) // EtherCAT: never called
       
  4034 {
       
  4035 	struct e1000_adapter *adapter;
       
  4036 	int work_to_do = min(*budget, poll_dev->quota);
       
  4037 	int tx_cleaned = 0, work_done = 0;
       
  4038 
       
  4039 	/* Must NOT use netdev_priv macro here. */
       
  4040 	adapter = poll_dev->priv;
       
  4041 
       
  4042 	/* Keep link state information with original netdev */
       
  4043 	if (!netif_carrier_ok(poll_dev))
       
  4044 		goto quit_polling;
       
  4045 
       
  4046 	/* e1000_clean is called per-cpu.  This lock protects
       
  4047 	 * tx_ring[0] from being cleaned by multiple cpus
       
  4048 	 * simultaneously.  A failure obtaining the lock means
       
  4049 	 * tx_ring[0] is currently being cleaned anyway. */
       
  4050 	if (spin_trylock(&adapter->tx_queue_lock)) {
       
  4051 		tx_cleaned = e1000_clean_tx_irq(adapter,
       
  4052 		                                &adapter->tx_ring[0]);
       
  4053 		spin_unlock(&adapter->tx_queue_lock);
       
  4054 	}
       
  4055 
       
  4056 	adapter->clean_rx(adapter, &adapter->rx_ring[0],
       
  4057 	                  &work_done, work_to_do);
       
  4058 
       
  4059 	*budget -= work_done;
       
  4060 	poll_dev->quota -= work_done;
       
  4061 
       
  4062 	/* If no Tx and not enough Rx work done, exit the polling mode */
       
  4063 	if ((!tx_cleaned && (work_done == 0)) ||
       
  4064 	   !netif_running(poll_dev)) {
       
  4065 quit_polling:
       
  4066 		if (likely(adapter->itr_setting & 3))
       
  4067 			e1000_set_itr(adapter);
       
  4068 		netif_rx_complete(poll_dev);
       
  4069 		e1000_irq_enable(adapter);
       
  4070 		return 0;
       
  4071 	}
       
  4072 
       
  4073 	return 1;
       
  4074 }
       
  4075 
       
  4076 #endif
       
  4077 /**
       
  4078  * e1000_clean_tx_irq - Reclaim resources after transmit completes
       
  4079  * @adapter: board private structure
       
  4080  **/
       
  4081 
       
  4082 static boolean_t
       
  4083 e1000_clean_tx_irq(struct e1000_adapter *adapter,
       
  4084                    struct e1000_tx_ring *tx_ring)
       
  4085 {
       
  4086 	struct net_device *netdev = adapter->netdev;
       
  4087 	struct e1000_tx_desc *tx_desc, *eop_desc;
       
  4088 	struct e1000_buffer *buffer_info;
       
  4089 	unsigned int i, eop;
       
  4090 #ifdef CONFIG_E1000_NAPI
       
  4091 	unsigned int count = 0;
       
  4092 #endif
       
  4093 	boolean_t cleaned = FALSE;
       
  4094 	unsigned int total_tx_bytes=0, total_tx_packets=0;
       
  4095 
       
  4096 	i = tx_ring->next_to_clean;
       
  4097 	eop = tx_ring->buffer_info[i].next_to_watch;
       
  4098 	eop_desc = E1000_TX_DESC(*tx_ring, eop);
       
  4099 
       
  4100 	while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
       
  4101 		for (cleaned = FALSE; !cleaned; ) {
       
  4102 			tx_desc = E1000_TX_DESC(*tx_ring, i);
       
  4103 			buffer_info = &tx_ring->buffer_info[i];
       
  4104 			cleaned = (i == eop);
       
  4105 
       
  4106 			if (cleaned) {
       
  4107 				struct sk_buff *skb = buffer_info->skb;
       
  4108 				unsigned int segs, bytecount;
       
  4109 				segs = skb_shinfo(skb)->gso_segs ?: 1;
       
  4110 				/* multiply data chunks by size of headers */
       
  4111 				bytecount = ((segs - 1) * skb_headlen(skb)) +
       
  4112 				            skb->len;
       
  4113 				total_tx_packets += segs;
       
  4114 				total_tx_bytes += bytecount;
       
  4115 			}
       
  4116 			e1000_unmap_and_free_tx_resource(adapter, buffer_info);
       
  4117 			tx_desc->upper.data = 0;
       
  4118 
       
  4119 			if (unlikely(++i == tx_ring->count)) i = 0;
       
  4120 		}
       
  4121 
       
  4122 		eop = tx_ring->buffer_info[i].next_to_watch;
       
  4123 		eop_desc = E1000_TX_DESC(*tx_ring, eop);
       
  4124 #ifdef CONFIG_E1000_NAPI
       
  4125 #define E1000_TX_WEIGHT 64
       
  4126 		/* weight of a sort for tx, to avoid endless transmit cleanup */
       
  4127 		if (count++ == E1000_TX_WEIGHT) break;
       
  4128 #endif
       
  4129 	}
       
  4130 
       
  4131 	tx_ring->next_to_clean = i;
       
  4132 
       
  4133 #define TX_WAKE_THRESHOLD 32
       
  4134 	if (!adapter->ecdev && unlikely(cleaned && netif_carrier_ok(netdev) &&
       
  4135 		     E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
       
  4136 		/* Make sure that anybody stopping the queue after this
       
  4137 		 * sees the new next_to_clean.
       
  4138 		 */
       
  4139 		smp_mb();
       
  4140 		if (netif_queue_stopped(netdev)) {
       
  4141 			netif_wake_queue(netdev);
       
  4142 			++adapter->restart_queue;
       
  4143 		}
       
  4144 	}
       
  4145 
       
  4146 	if (!adapter->ecdev && adapter->detect_tx_hung) {
       
  4147 		/* Detect a transmit hang in hardware, this serializes the
       
  4148 		 * check with the clearing of time_stamp and movement of i */
       
  4149 		adapter->detect_tx_hung = FALSE;
       
  4150 		if (tx_ring->buffer_info[eop].dma &&
       
  4151 		    time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
       
  4152 		               (adapter->tx_timeout_factor * HZ))
       
  4153 		    && !(E1000_READ_REG(&adapter->hw, STATUS) &
       
  4154 		         E1000_STATUS_TXOFF)) {
       
  4155 
       
  4156 			/* detected Tx unit hang */
       
  4157 			DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
       
  4158 					"  Tx Queue             <%lu>\n"
       
  4159 					"  TDH                  <%x>\n"
       
  4160 					"  TDT                  <%x>\n"
       
  4161 					"  next_to_use          <%x>\n"
       
  4162 					"  next_to_clean        <%x>\n"
       
  4163 					"buffer_info[next_to_clean]\n"
       
  4164 					"  time_stamp           <%lx>\n"
       
  4165 					"  next_to_watch        <%x>\n"
       
  4166 					"  jiffies              <%lx>\n"
       
  4167 					"  next_to_watch.status <%x>\n",
       
  4168 				(unsigned long)((tx_ring - adapter->tx_ring) /
       
  4169 					sizeof(struct e1000_tx_ring)),
       
  4170 				readl(adapter->hw.hw_addr + tx_ring->tdh),
       
  4171 				readl(adapter->hw.hw_addr + tx_ring->tdt),
       
  4172 				tx_ring->next_to_use,
       
  4173 				tx_ring->next_to_clean,
       
  4174 				tx_ring->buffer_info[eop].time_stamp,
       
  4175 				eop,
       
  4176 				jiffies,
       
  4177 				eop_desc->upper.fields.status);
       
  4178 			netif_stop_queue(netdev);
       
  4179 		}
       
  4180 	}
       
  4181 	adapter->total_tx_bytes += total_tx_bytes;
       
  4182 	adapter->total_tx_packets += total_tx_packets;
       
  4183 	return cleaned;
       
  4184 }
       
  4185 
       
  4186 /**
       
  4187  * e1000_rx_checksum - Receive Checksum Offload for 82543
       
  4188  * @adapter:     board private structure
       
  4189  * @status_err:  receive descriptor status and error fields
       
  4190  * @csum:        receive descriptor csum field
       
  4191  * @sk_buff:     socket buffer with received data
       
  4192  **/
       
  4193 
       
  4194 static void
       
  4195 e1000_rx_checksum(struct e1000_adapter *adapter,
       
  4196 		  uint32_t status_err, uint32_t csum,
       
  4197 		  struct sk_buff *skb)
       
  4198 {
       
  4199 	uint16_t status = (uint16_t)status_err;
       
  4200 	uint8_t errors = (uint8_t)(status_err >> 24);
       
  4201 	skb->ip_summed = CHECKSUM_NONE;
       
  4202 
       
  4203 	/* 82543 or newer only */
       
  4204 	if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
       
  4205 	/* Ignore Checksum bit is set */
       
  4206 	if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
       
  4207 	/* TCP/UDP checksum error bit is set */
       
  4208 	if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
       
  4209 		/* let the stack verify checksum errors */
       
  4210 		adapter->hw_csum_err++;
       
  4211 		return;
       
  4212 	}
       
  4213 	/* TCP/UDP Checksum has not been calculated */
       
  4214 	if (adapter->hw.mac_type <= e1000_82547_rev_2) {
       
  4215 		if (!(status & E1000_RXD_STAT_TCPCS))
       
  4216 			return;
       
  4217 	} else {
       
  4218 		if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
       
  4219 			return;
       
  4220 	}
       
  4221 	/* It must be a TCP or UDP packet with a valid checksum */
       
  4222 	if (likely(status & E1000_RXD_STAT_TCPCS)) {
       
  4223 		/* TCP checksum is good */
       
  4224 		skb->ip_summed = CHECKSUM_UNNECESSARY;
       
  4225 	} else if (adapter->hw.mac_type > e1000_82547_rev_2) {
       
  4226 		/* IP fragment with UDP payload */
       
  4227 		/* Hardware complements the payload checksum, so we undo it
       
  4228 		 * and then put the value in host order for further stack use.
       
  4229 		 */
       
  4230 		csum = ntohl(csum ^ 0xFFFF);
       
  4231 		skb->csum = csum;
       
  4232 		skb->ip_summed = CHECKSUM_COMPLETE;
       
  4233 	}
       
  4234 	adapter->hw_csum_good++;
       
  4235 }
       
  4236 
       
  4237 /**
       
  4238  * e1000_clean_rx_irq - Send received data up the network stack; legacy
       
  4239  * @adapter: board private structure
       
  4240  **/
       
  4241 
       
  4242 static boolean_t
       
  4243 #ifdef CONFIG_E1000_NAPI
       
  4244 e1000_clean_rx_irq(struct e1000_adapter *adapter,
       
  4245                    struct e1000_rx_ring *rx_ring,
       
  4246                    int *work_done, int work_to_do)
       
  4247 #else
       
  4248 e1000_clean_rx_irq(struct e1000_adapter *adapter,
       
  4249                    struct e1000_rx_ring *rx_ring)
       
  4250 #endif
       
  4251 {
       
  4252 	struct net_device *netdev = adapter->netdev;
       
  4253 	struct pci_dev *pdev = adapter->pdev;
       
  4254 	struct e1000_rx_desc *rx_desc, *next_rxd;
       
  4255 	struct e1000_buffer *buffer_info, *next_buffer;
       
  4256 	unsigned long flags;
       
  4257 	uint32_t length;
       
  4258 	uint8_t last_byte;
       
  4259 	unsigned int i;
       
  4260 	int cleaned_count = 0;
       
  4261 	boolean_t cleaned = FALSE;
       
  4262 	unsigned int total_rx_bytes=0, total_rx_packets=0;
       
  4263 
       
  4264 	i = rx_ring->next_to_clean;
       
  4265 	rx_desc = E1000_RX_DESC(*rx_ring, i);
       
  4266 	buffer_info = &rx_ring->buffer_info[i];
       
  4267 
       
  4268 	while (rx_desc->status & E1000_RXD_STAT_DD) {
       
  4269 		struct sk_buff *skb;
       
  4270 		u8 status;
       
  4271 
       
  4272 #ifdef CONFIG_E1000_NAPI
       
  4273 		if (*work_done >= work_to_do)
       
  4274 			break;
       
  4275 		(*work_done)++;
       
  4276 #endif
       
  4277 		status = rx_desc->status;
       
  4278 		skb = buffer_info->skb;
       
  4279 		if (!adapter->ecdev) buffer_info->skb = NULL;
       
  4280 
       
  4281 		prefetch(skb->data - NET_IP_ALIGN);
       
  4282 
       
  4283 		if (++i == rx_ring->count) i = 0;
       
  4284 		next_rxd = E1000_RX_DESC(*rx_ring, i);
       
  4285 		prefetch(next_rxd);
       
  4286 
       
  4287 		next_buffer = &rx_ring->buffer_info[i];
       
  4288 
       
  4289 		cleaned = TRUE;
       
  4290 		cleaned_count++;
       
  4291 		pci_unmap_single(pdev,
       
  4292 		                 buffer_info->dma,
       
  4293 		                 buffer_info->length,
       
  4294 		                 PCI_DMA_FROMDEVICE);
       
  4295 
       
  4296 		length = le16_to_cpu(rx_desc->length);
       
  4297 
       
  4298 		if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
       
  4299 			/* All receives must fit into a single buffer */
       
  4300 			E1000_DBG("%s: Receive packet consumed multiple"
       
  4301 				  " buffers\n", netdev->name);
       
  4302 			/* recycle */
       
  4303 			buffer_info->skb = skb;
       
  4304 			goto next_desc;
       
  4305 		}
       
  4306 
       
  4307 		if (!adapter->ecdev &&
       
  4308                 unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
       
  4309 			last_byte = *(skb->data + length - 1);
       
  4310 			if (TBI_ACCEPT(&adapter->hw, status,
       
  4311 			              rx_desc->errors, length, last_byte)) {
       
  4312 				spin_lock_irqsave(&adapter->stats_lock, flags);
       
  4313 				e1000_tbi_adjust_stats(&adapter->hw,
       
  4314 				                       &adapter->stats,
       
  4315 				                       length, skb->data);
       
  4316 				spin_unlock_irqrestore(&adapter->stats_lock,
       
  4317 				                       flags);
       
  4318 				length--;
       
  4319 			} else {
       
  4320 				/* recycle */
       
  4321 				buffer_info->skb = skb;
       
  4322 				goto next_desc;
       
  4323 			}
       
  4324 		}
       
  4325 
       
  4326 		/* adjust length to remove Ethernet CRC, this must be
       
  4327 		 * done after the TBI_ACCEPT workaround above */
       
  4328 		length -= 4;
       
  4329 
       
  4330 		/* probably a little skewed due to removing CRC */
       
  4331 		total_rx_bytes += length;
       
  4332 		total_rx_packets++;
       
  4333 
       
  4334 		/* code added for copybreak, this should improve
       
  4335 		 * performance for small packets with large amounts
       
  4336 		 * of reassembly being done in the stack */
       
  4337 		if (!adapter->ecdev && length < copybreak) {
       
  4338 			struct sk_buff *new_skb =
       
  4339 			    netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
       
  4340 			if (new_skb) {
       
  4341 				skb_reserve(new_skb, NET_IP_ALIGN);
       
  4342 				skb_copy_to_linear_data_offset(new_skb,
       
  4343 							       -NET_IP_ALIGN,
       
  4344 							       (skb->data -
       
  4345 							        NET_IP_ALIGN),
       
  4346 							       (length +
       
  4347 							        NET_IP_ALIGN));
       
  4348 				/* save the skb in buffer_info as good */
       
  4349 				buffer_info->skb = skb;
       
  4350 				skb = new_skb;
       
  4351 			}
       
  4352 			/* else just continue with the old one */
       
  4353 		}
       
  4354 		/* end copybreak code */
       
  4355 		skb_put(skb, length);
       
  4356 
       
  4357 		/* Receive Checksum Offload */
       
  4358 		e1000_rx_checksum(adapter,
       
  4359 				  (uint32_t)(status) |
       
  4360 				  ((uint32_t)(rx_desc->errors) << 24),
       
  4361 				  le16_to_cpu(rx_desc->csum), skb);
       
  4362 
       
  4363 		if (adapter->ecdev) {
       
  4364 			ecdev_receive(adapter->ecdev, skb->data, length);
       
  4365 		} else {
       
  4366 			skb->protocol = eth_type_trans(skb, netdev);
       
  4367 #ifdef CONFIG_E1000_NAPI
       
  4368 			if (unlikely(adapter->vlgrp &&
       
  4369 						(status & E1000_RXD_STAT_VP))) {
       
  4370 				vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
       
  4371 						le16_to_cpu(rx_desc->special) &
       
  4372 						E1000_RXD_SPC_VLAN_MASK);
       
  4373 			} else {
       
  4374 				netif_receive_skb(skb);
       
  4375 			}
       
  4376 #else /* CONFIG_E1000_NAPI */
       
  4377 			if (unlikely(adapter->vlgrp &&
       
  4378 						(status & E1000_RXD_STAT_VP))) {
       
  4379 				vlan_hwaccel_rx(skb, adapter->vlgrp,
       
  4380 						le16_to_cpu(rx_desc->special) &
       
  4381 						E1000_RXD_SPC_VLAN_MASK);
       
  4382 			} else {
       
  4383 				netif_rx(skb);
       
  4384 			}
       
  4385 #endif /* CONFIG_E1000_NAPI */
       
  4386 		}
       
  4387 		netdev->last_rx = jiffies;
       
  4388 
       
  4389 next_desc:
       
  4390 		rx_desc->status = 0;
       
  4391 
       
  4392 		/* return some buffers to hardware, one at a time is too slow */
       
  4393 		if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
       
  4394 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
       
  4395 			cleaned_count = 0;
       
  4396 		}
       
  4397 
       
  4398 		/* use prefetched values */
       
  4399 		rx_desc = next_rxd;
       
  4400 		buffer_info = next_buffer;
       
  4401 	}
       
  4402 	rx_ring->next_to_clean = i;
       
  4403 
       
  4404 	cleaned_count = E1000_DESC_UNUSED(rx_ring);
       
  4405 	if (cleaned_count)
       
  4406 		adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
       
  4407 
       
  4408 	adapter->total_rx_packets += total_rx_packets;
       
  4409 	adapter->total_rx_bytes += total_rx_bytes;
       
  4410 	return cleaned;
       
  4411 }
       
  4412 
       
  4413 /**
       
  4414  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
       
  4415  * @adapter: board private structure
       
  4416  **/
       
  4417 
       
  4418 static boolean_t
       
  4419 #ifdef CONFIG_E1000_NAPI
       
  4420 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
       
  4421                       struct e1000_rx_ring *rx_ring,
       
  4422                       int *work_done, int work_to_do)
       
  4423 #else
       
  4424 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
       
  4425                       struct e1000_rx_ring *rx_ring)
       
  4426 #endif
       
  4427 {
       
  4428 	union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
       
  4429 	struct net_device *netdev = adapter->netdev;
       
  4430 	struct pci_dev *pdev = adapter->pdev;
       
  4431 	struct e1000_buffer *buffer_info, *next_buffer;
       
  4432 	struct e1000_ps_page *ps_page;
       
  4433 	struct e1000_ps_page_dma *ps_page_dma;
       
  4434 	struct sk_buff *skb;
       
  4435 	unsigned int i, j;
       
  4436 	uint32_t length, staterr;
       
  4437 	int cleaned_count = 0;
       
  4438 	boolean_t cleaned = FALSE;
       
  4439 	unsigned int total_rx_bytes=0, total_rx_packets=0;
       
  4440 
       
  4441 	i = rx_ring->next_to_clean;
       
  4442 	rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
       
  4443 	staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
       
  4444 	buffer_info = &rx_ring->buffer_info[i];
       
  4445 
       
  4446 	while (staterr & E1000_RXD_STAT_DD) {
       
  4447 		ps_page = &rx_ring->ps_page[i];
       
  4448 		ps_page_dma = &rx_ring->ps_page_dma[i];
       
  4449 #ifdef CONFIG_E1000_NAPI
       
  4450 		if (unlikely(*work_done >= work_to_do))
       
  4451 			break;
       
  4452 		(*work_done)++;
       
  4453 #endif
       
  4454 		skb = buffer_info->skb;
       
  4455 
       
  4456 		/* in the packet split case this is header only */
       
  4457 		prefetch(skb->data - NET_IP_ALIGN);
       
  4458 
       
  4459 		if (++i == rx_ring->count) i = 0;
       
  4460 		next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
       
  4461 		prefetch(next_rxd);
       
  4462 
       
  4463 		next_buffer = &rx_ring->buffer_info[i];
       
  4464 
       
  4465 		cleaned = TRUE;
       
  4466 		cleaned_count++;
       
  4467 		pci_unmap_single(pdev, buffer_info->dma,
       
  4468 				 buffer_info->length,
       
  4469 				 PCI_DMA_FROMDEVICE);
       
  4470 
       
  4471 		if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
       
  4472 			E1000_DBG("%s: Packet Split buffers didn't pick up"
       
  4473 				  " the full packet\n", netdev->name);
       
  4474 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
       
  4475 			goto next_desc;
       
  4476 		}
       
  4477 
       
  4478 		if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
       
  4479 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
       
  4480 			goto next_desc;
       
  4481 		}
       
  4482 
       
  4483 		length = le16_to_cpu(rx_desc->wb.middle.length0);
       
  4484 
       
  4485 		if (unlikely(!length)) {
       
  4486 			E1000_DBG("%s: Last part of the packet spanning"
       
  4487 				  " multiple descriptors\n", netdev->name);
       
  4488 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
       
  4489 			goto next_desc;
       
  4490 		}
       
  4491 
       
  4492 		/* Good Receive */
       
  4493 		skb_put(skb, length);
       
  4494 
       
  4495 		{
       
  4496 		/* this looks ugly, but it seems compiler issues make it
       
  4497 		   more efficient than reusing j */
       
  4498 		int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
       
  4499 
       
  4500 		/* page alloc/put takes too long and effects small packet
       
  4501 		 * throughput, so unsplit small packets and save the alloc/put*/
       
  4502 		if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
       
  4503 			u8 *vaddr;
       
  4504 			/* there is no documentation about how to call
       
  4505 			 * kmap_atomic, so we can't hold the mapping
       
  4506 			 * very long */
       
  4507 			pci_dma_sync_single_for_cpu(pdev,
       
  4508 				ps_page_dma->ps_page_dma[0],
       
  4509 				PAGE_SIZE,
       
  4510 				PCI_DMA_FROMDEVICE);
       
  4511 			vaddr = kmap_atomic(ps_page->ps_page[0],
       
  4512 			                    KM_SKB_DATA_SOFTIRQ);
       
  4513 			memcpy(skb_tail_pointer(skb), vaddr, l1);
       
  4514 			kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
       
  4515 			pci_dma_sync_single_for_device(pdev,
       
  4516 				ps_page_dma->ps_page_dma[0],
       
  4517 				PAGE_SIZE, PCI_DMA_FROMDEVICE);
       
  4518 			/* remove the CRC */
       
  4519 			l1 -= 4;
       
  4520 			skb_put(skb, l1);
       
  4521 			goto copydone;
       
  4522 		} /* if */
       
  4523 		}
       
  4524 
       
  4525 		for (j = 0; j < adapter->rx_ps_pages; j++) {
       
  4526 			if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
       
  4527 				break;
       
  4528 			pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
       
  4529 					PAGE_SIZE, PCI_DMA_FROMDEVICE);
       
  4530 			ps_page_dma->ps_page_dma[j] = 0;
       
  4531 			skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
       
  4532 			                   length);
       
  4533 			ps_page->ps_page[j] = NULL;
       
  4534 			skb->len += length;
       
  4535 			skb->data_len += length;
       
  4536 			skb->truesize += length;
       
  4537 		}
       
  4538 
       
  4539 		/* strip the ethernet crc, problem is we're using pages now so
       
  4540 		 * this whole operation can get a little cpu intensive */
       
  4541 		pskb_trim(skb, skb->len - 4);
       
  4542 
       
  4543 copydone:
       
  4544 		total_rx_bytes += skb->len;
       
  4545 		total_rx_packets++;
       
  4546 
       
  4547 		e1000_rx_checksum(adapter, staterr,
       
  4548 				  le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
       
  4549 
       
  4550 		if (likely(rx_desc->wb.upper.header_status &
       
  4551 			   cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
       
  4552 			adapter->rx_hdr_split++;
       
  4553 		if (adapter->ecdev) {
       
  4554 			ecdev_receive(adapter->ecdev, skb->data, length);
       
  4555 		} else {
       
  4556 			skb->protocol = eth_type_trans(skb, netdev);
       
  4557 #ifdef CONFIG_E1000_NAPI
       
  4558 			if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
       
  4559 				vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
       
  4560 						le16_to_cpu(rx_desc->wb.middle.vlan) &
       
  4561 						E1000_RXD_SPC_VLAN_MASK);
       
  4562 			} else {
       
  4563 				netif_receive_skb(skb);
       
  4564 			}
       
  4565 #else /* CONFIG_E1000_NAPI */
       
  4566 			if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
       
  4567 				vlan_hwaccel_rx(skb, adapter->vlgrp,
       
  4568 						le16_to_cpu(rx_desc->wb.middle.vlan) &
       
  4569 						E1000_RXD_SPC_VLAN_MASK);
       
  4570 			} else {
       
  4571 				netif_rx(skb);
       
  4572 			}
       
  4573 #endif /* CONFIG_E1000_NAPI */
       
  4574 		}
       
  4575 		netdev->last_rx = jiffies;
       
  4576 
       
  4577 next_desc:
       
  4578 		rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
       
  4579 		if (!adapter->ecdev) buffer_info->skb = NULL;
       
  4580 
       
  4581 		/* return some buffers to hardware, one at a time is too slow */
       
  4582 		if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
       
  4583 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
       
  4584 			cleaned_count = 0;
       
  4585 		}
       
  4586 
       
  4587 		/* use prefetched values */
       
  4588 		rx_desc = next_rxd;
       
  4589 		buffer_info = next_buffer;
       
  4590 
       
  4591 		staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
       
  4592 	}
       
  4593 	rx_ring->next_to_clean = i;
       
  4594 
       
  4595 	cleaned_count = E1000_DESC_UNUSED(rx_ring);
       
  4596 	if (cleaned_count)
       
  4597 		adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
       
  4598 
       
  4599 	adapter->total_rx_packets += total_rx_packets;
       
  4600 	adapter->total_rx_bytes += total_rx_bytes;
       
  4601 	return cleaned;
       
  4602 }
       
  4603 
       
  4604 /**
       
  4605  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
       
  4606  * @adapter: address of board private structure
       
  4607  **/
       
  4608 
       
  4609 static void
       
  4610 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
       
  4611                        struct e1000_rx_ring *rx_ring,
       
  4612 		       int cleaned_count)
       
  4613 {
       
  4614 	struct net_device *netdev = adapter->netdev;
       
  4615 	struct pci_dev *pdev = adapter->pdev;
       
  4616 	struct e1000_rx_desc *rx_desc;
       
  4617 	struct e1000_buffer *buffer_info;
       
  4618 	struct sk_buff *skb;
       
  4619 	unsigned int i;
       
  4620 	unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
       
  4621 
       
  4622 	i = rx_ring->next_to_use;
       
  4623 	buffer_info = &rx_ring->buffer_info[i];
       
  4624 
       
  4625 	while (cleaned_count--) {
       
  4626 		skb = buffer_info->skb;
       
  4627 		if (skb) {
       
  4628 			skb_trim(skb, 0);
       
  4629 			goto map_skb;
       
  4630 		}
       
  4631 
       
  4632 		skb = netdev_alloc_skb(netdev, bufsz);
       
  4633 		if (unlikely(!skb)) {
       
  4634 			/* Better luck next round */
       
  4635 			adapter->alloc_rx_buff_failed++;
       
  4636 			break;
       
  4637 		}
       
  4638 
       
  4639 		/* Fix for errata 23, can't cross 64kB boundary */
       
  4640 		if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
       
  4641 			struct sk_buff *oldskb = skb;
       
  4642 			DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
       
  4643 					     "at %p\n", bufsz, skb->data);
       
  4644 			/* Try again, without freeing the previous */
       
  4645 			skb = netdev_alloc_skb(netdev, bufsz);
       
  4646 			/* Failed allocation, critical failure */
       
  4647 			if (!skb) {
       
  4648 				dev_kfree_skb(oldskb);
       
  4649 				break;
       
  4650 			}
       
  4651 
       
  4652 			if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
       
  4653 				/* give up */
       
  4654 				dev_kfree_skb(skb);
       
  4655 				dev_kfree_skb(oldskb);
       
  4656 				break; /* while !buffer_info->skb */
       
  4657 			}
       
  4658 
       
  4659 			/* Use new allocation */
       
  4660 			dev_kfree_skb(oldskb);
       
  4661 		}
       
  4662 		/* Make buffer alignment 2 beyond a 16 byte boundary
       
  4663 		 * this will result in a 16 byte aligned IP header after
       
  4664 		 * the 14 byte MAC header is removed
       
  4665 		 */
       
  4666 		skb_reserve(skb, NET_IP_ALIGN);
       
  4667 
       
  4668 		buffer_info->skb = skb;
       
  4669 		buffer_info->length = adapter->rx_buffer_len;
       
  4670 map_skb:
       
  4671 		buffer_info->dma = pci_map_single(pdev,
       
  4672 						  skb->data,
       
  4673 						  adapter->rx_buffer_len,
       
  4674 						  PCI_DMA_FROMDEVICE);
       
  4675 
       
  4676 		/* Fix for errata 23, can't cross 64kB boundary */
       
  4677 		if (!e1000_check_64k_bound(adapter,
       
  4678 					(void *)(unsigned long)buffer_info->dma,
       
  4679 					adapter->rx_buffer_len)) {
       
  4680 			DPRINTK(RX_ERR, ERR,
       
  4681 				"dma align check failed: %u bytes at %p\n",
       
  4682 				adapter->rx_buffer_len,
       
  4683 				(void *)(unsigned long)buffer_info->dma);
       
  4684 			if (!adapter->ecdev) {
       
  4685                 dev_kfree_skb(skb);
       
  4686 				buffer_info->skb = NULL;
       
  4687 			}
       
  4688 
       
  4689 			pci_unmap_single(pdev, buffer_info->dma,
       
  4690 					 adapter->rx_buffer_len,
       
  4691 					 PCI_DMA_FROMDEVICE);
       
  4692 
       
  4693 			break; /* while !buffer_info->skb */
       
  4694 		}
       
  4695 		rx_desc = E1000_RX_DESC(*rx_ring, i);
       
  4696 		rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
       
  4697 
       
  4698 		if (unlikely(++i == rx_ring->count))
       
  4699 			i = 0;
       
  4700 		buffer_info = &rx_ring->buffer_info[i];
       
  4701 	}
       
  4702 
       
  4703 	if (likely(rx_ring->next_to_use != i)) {
       
  4704 		rx_ring->next_to_use = i;
       
  4705 		if (unlikely(i-- == 0))
       
  4706 			i = (rx_ring->count - 1);
       
  4707 
       
  4708 		/* Force memory writes to complete before letting h/w
       
  4709 		 * know there are new descriptors to fetch.  (Only
       
  4710 		 * applicable for weak-ordered memory model archs,
       
  4711 		 * such as IA-64). */
       
  4712 		wmb();
       
  4713 		writel(i, adapter->hw.hw_addr + rx_ring->rdt);
       
  4714 	}
       
  4715 }
       
  4716 
       
  4717 /**
       
  4718  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
       
  4719  * @adapter: address of board private structure
       
  4720  **/
       
  4721 
       
  4722 static void
       
  4723 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
       
  4724                           struct e1000_rx_ring *rx_ring,
       
  4725 			  int cleaned_count)
       
  4726 {
       
  4727 	struct net_device *netdev = adapter->netdev;
       
  4728 	struct pci_dev *pdev = adapter->pdev;
       
  4729 	union e1000_rx_desc_packet_split *rx_desc;
       
  4730 	struct e1000_buffer *buffer_info;
       
  4731 	struct e1000_ps_page *ps_page;
       
  4732 	struct e1000_ps_page_dma *ps_page_dma;
       
  4733 	struct sk_buff *skb;
       
  4734 	unsigned int i, j;
       
  4735 
       
  4736 	i = rx_ring->next_to_use;
       
  4737 	buffer_info = &rx_ring->buffer_info[i];
       
  4738 	ps_page = &rx_ring->ps_page[i];
       
  4739 	ps_page_dma = &rx_ring->ps_page_dma[i];
       
  4740 
       
  4741 	while (cleaned_count--) {
       
  4742 		rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
       
  4743 
       
  4744 		for (j = 0; j < PS_PAGE_BUFFERS; j++) {
       
  4745 			if (j < adapter->rx_ps_pages) {
       
  4746 				if (likely(!ps_page->ps_page[j])) {
       
  4747 					ps_page->ps_page[j] =
       
  4748 						alloc_page(GFP_ATOMIC);
       
  4749 					if (unlikely(!ps_page->ps_page[j])) {
       
  4750 						adapter->alloc_rx_buff_failed++;
       
  4751 						goto no_buffers;
       
  4752 					}
       
  4753 					ps_page_dma->ps_page_dma[j] =
       
  4754 						pci_map_page(pdev,
       
  4755 							    ps_page->ps_page[j],
       
  4756 							    0, PAGE_SIZE,
       
  4757 							    PCI_DMA_FROMDEVICE);
       
  4758 				}
       
  4759 				/* Refresh the desc even if buffer_addrs didn't
       
  4760 				 * change because each write-back erases
       
  4761 				 * this info.
       
  4762 				 */
       
  4763 				rx_desc->read.buffer_addr[j+1] =
       
  4764 				     cpu_to_le64(ps_page_dma->ps_page_dma[j]);
       
  4765 			} else
       
  4766 				rx_desc->read.buffer_addr[j+1] = ~0;
       
  4767 		}
       
  4768 
       
  4769 		skb = netdev_alloc_skb(netdev,
       
  4770 		                       adapter->rx_ps_bsize0 + NET_IP_ALIGN);
       
  4771 
       
  4772 		if (unlikely(!skb)) {
       
  4773 			adapter->alloc_rx_buff_failed++;
       
  4774 			break;
       
  4775 		}
       
  4776 
       
  4777 		/* Make buffer alignment 2 beyond a 16 byte boundary
       
  4778 		 * this will result in a 16 byte aligned IP header after
       
  4779 		 * the 14 byte MAC header is removed
       
  4780 		 */
       
  4781 		skb_reserve(skb, NET_IP_ALIGN);
       
  4782 
       
  4783 		buffer_info->skb = skb;
       
  4784 		buffer_info->length = adapter->rx_ps_bsize0;
       
  4785 		buffer_info->dma = pci_map_single(pdev, skb->data,
       
  4786 						  adapter->rx_ps_bsize0,
       
  4787 						  PCI_DMA_FROMDEVICE);
       
  4788 
       
  4789 		rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
       
  4790 
       
  4791 		if (unlikely(++i == rx_ring->count)) i = 0;
       
  4792 		buffer_info = &rx_ring->buffer_info[i];
       
  4793 		ps_page = &rx_ring->ps_page[i];
       
  4794 		ps_page_dma = &rx_ring->ps_page_dma[i];
       
  4795 	}
       
  4796 
       
  4797 no_buffers:
       
  4798 	if (likely(rx_ring->next_to_use != i)) {
       
  4799 		rx_ring->next_to_use = i;
       
  4800 		if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
       
  4801 
       
  4802 		/* Force memory writes to complete before letting h/w
       
  4803 		 * know there are new descriptors to fetch.  (Only
       
  4804 		 * applicable for weak-ordered memory model archs,
       
  4805 		 * such as IA-64). */
       
  4806 		wmb();
       
  4807 		/* Hardware increments by 16 bytes, but packet split
       
  4808 		 * descriptors are 32 bytes...so we increment tail
       
  4809 		 * twice as much.
       
  4810 		 */
       
  4811 		writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
       
  4812 	}
       
  4813 }
       
  4814 
       
  4815 /**
       
  4816  * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
       
  4817  * @adapter:
       
  4818  **/
       
  4819 
       
  4820 static void
       
  4821 e1000_smartspeed(struct e1000_adapter *adapter)
       
  4822 {
       
  4823 	uint16_t phy_status;
       
  4824 	uint16_t phy_ctrl;
       
  4825 
       
  4826 	if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
       
  4827 	   !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
       
  4828 		return;
       
  4829 
       
  4830 	if (adapter->smartspeed == 0) {
       
  4831 		/* If Master/Slave config fault is asserted twice,
       
  4832 		 * we assume back-to-back */
       
  4833 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
       
  4834 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
       
  4835 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
       
  4836 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
       
  4837 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
       
  4838 		if (phy_ctrl & CR_1000T_MS_ENABLE) {
       
  4839 			phy_ctrl &= ~CR_1000T_MS_ENABLE;
       
  4840 			e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
       
  4841 					    phy_ctrl);
       
  4842 			adapter->smartspeed++;
       
  4843 			if (!e1000_phy_setup_autoneg(&adapter->hw) &&
       
  4844 			   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
       
  4845 				   	       &phy_ctrl)) {
       
  4846 				phy_ctrl |= (MII_CR_AUTO_NEG_EN |
       
  4847 					     MII_CR_RESTART_AUTO_NEG);
       
  4848 				e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
       
  4849 						    phy_ctrl);
       
  4850 			}
       
  4851 		}
       
  4852 		return;
       
  4853 	} else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
       
  4854 		/* If still no link, perhaps using 2/3 pair cable */
       
  4855 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
       
  4856 		phy_ctrl |= CR_1000T_MS_ENABLE;
       
  4857 		e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
       
  4858 		if (!e1000_phy_setup_autoneg(&adapter->hw) &&
       
  4859 		   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
       
  4860 			phy_ctrl |= (MII_CR_AUTO_NEG_EN |
       
  4861 				     MII_CR_RESTART_AUTO_NEG);
       
  4862 			e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
       
  4863 		}
       
  4864 	}
       
  4865 	/* Restart process after E1000_SMARTSPEED_MAX iterations */
       
  4866 	if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
       
  4867 		adapter->smartspeed = 0;
       
  4868 }
       
  4869 
       
  4870 /**
       
  4871  * e1000_ioctl -
       
  4872  * @netdev:
       
  4873  * @ifreq:
       
  4874  * @cmd:
       
  4875  **/
       
  4876 
       
  4877 static int
       
  4878 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
       
  4879 {
       
  4880 	switch (cmd) {
       
  4881 	case SIOCGMIIPHY:
       
  4882 	case SIOCGMIIREG:
       
  4883 	case SIOCSMIIREG:
       
  4884 		return e1000_mii_ioctl(netdev, ifr, cmd);
       
  4885 	default:
       
  4886 		return -EOPNOTSUPP;
       
  4887 	}
       
  4888 }
       
  4889 
       
  4890 /**
       
  4891  * e1000_mii_ioctl -
       
  4892  * @netdev:
       
  4893  * @ifreq:
       
  4894  * @cmd:
       
  4895  **/
       
  4896 
       
  4897 static int
       
  4898 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
       
  4899 {
       
  4900 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  4901 	struct mii_ioctl_data *data = if_mii(ifr);
       
  4902 	int retval;
       
  4903 	uint16_t mii_reg;
       
  4904 	uint16_t spddplx;
       
  4905 	unsigned long flags;
       
  4906 
       
  4907 	if (adapter->hw.media_type != e1000_media_type_copper)
       
  4908 		return -EOPNOTSUPP;
       
  4909 
       
  4910 	switch (cmd) {
       
  4911 	case SIOCGMIIPHY:
       
  4912 		data->phy_id = adapter->hw.phy_addr;
       
  4913 		break;
       
  4914 	case SIOCGMIIREG:
       
  4915 		if (adapter->ecdev || !capable(CAP_NET_ADMIN))
       
  4916 			return -EPERM;
       
  4917 		spin_lock_irqsave(&adapter->stats_lock, flags);
       
  4918 		if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
       
  4919 				   &data->val_out)) {
       
  4920 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
       
  4921 			return -EIO;
       
  4922 		}
       
  4923 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
       
  4924 		break;
       
  4925 	case SIOCSMIIREG:
       
  4926 		if (adapter->ecdev || !capable(CAP_NET_ADMIN))
       
  4927 			return -EPERM;
       
  4928 		if (data->reg_num & ~(0x1F))
       
  4929 			return -EFAULT;
       
  4930 		mii_reg = data->val_in;
       
  4931 		spin_lock_irqsave(&adapter->stats_lock, flags);
       
  4932 		if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
       
  4933 					mii_reg)) {
       
  4934 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
       
  4935 			return -EIO;
       
  4936 		}
       
  4937 		if (adapter->hw.media_type == e1000_media_type_copper) {
       
  4938 			switch (data->reg_num) {
       
  4939 			case PHY_CTRL:
       
  4940 				if (mii_reg & MII_CR_POWER_DOWN)
       
  4941 					break;
       
  4942 				if (mii_reg & MII_CR_AUTO_NEG_EN) {
       
  4943 					adapter->hw.autoneg = 1;
       
  4944 					adapter->hw.autoneg_advertised = 0x2F;
       
  4945 				} else {
       
  4946 					if (mii_reg & 0x40)
       
  4947 						spddplx = SPEED_1000;
       
  4948 					else if (mii_reg & 0x2000)
       
  4949 						spddplx = SPEED_100;
       
  4950 					else
       
  4951 						spddplx = SPEED_10;
       
  4952 					spddplx += (mii_reg & 0x100)
       
  4953 						   ? DUPLEX_FULL :
       
  4954 						   DUPLEX_HALF;
       
  4955 					retval = e1000_set_spd_dplx(adapter,
       
  4956 								    spddplx);
       
  4957 					if (retval) {
       
  4958 						spin_unlock_irqrestore(
       
  4959 							&adapter->stats_lock,
       
  4960 							flags);
       
  4961 						return retval;
       
  4962 					}
       
  4963 				}
       
  4964 				if (netif_running(adapter->netdev))
       
  4965 					e1000_reinit_locked(adapter);
       
  4966 				else
       
  4967 					e1000_reset(adapter);
       
  4968 				break;
       
  4969 			case M88E1000_PHY_SPEC_CTRL:
       
  4970 			case M88E1000_EXT_PHY_SPEC_CTRL:
       
  4971 				if (e1000_phy_reset(&adapter->hw)) {
       
  4972 					spin_unlock_irqrestore(
       
  4973 						&adapter->stats_lock, flags);
       
  4974 					return -EIO;
       
  4975 				}
       
  4976 				break;
       
  4977 			}
       
  4978 		} else {
       
  4979 			switch (data->reg_num) {
       
  4980 			case PHY_CTRL:
       
  4981 				if (mii_reg & MII_CR_POWER_DOWN)
       
  4982 					break;
       
  4983 				if (netif_running(adapter->netdev))
       
  4984 					e1000_reinit_locked(adapter);
       
  4985 				else
       
  4986 					e1000_reset(adapter);
       
  4987 				break;
       
  4988 			}
       
  4989 		}
       
  4990 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
       
  4991 		break;
       
  4992 	default:
       
  4993 		return -EOPNOTSUPP;
       
  4994 	}
       
  4995 	return E1000_SUCCESS;
       
  4996 }
       
  4997 
       
  4998 void
       
  4999 e1000_pci_set_mwi(struct e1000_hw *hw)
       
  5000 {
       
  5001 	struct e1000_adapter *adapter = hw->back;
       
  5002 	int ret_val = pci_set_mwi(adapter->pdev);
       
  5003 
       
  5004 	if (ret_val)
       
  5005 		DPRINTK(PROBE, ERR, "Error in setting MWI\n");
       
  5006 }
       
  5007 
       
  5008 void
       
  5009 e1000_pci_clear_mwi(struct e1000_hw *hw)
       
  5010 {
       
  5011 	struct e1000_adapter *adapter = hw->back;
       
  5012 
       
  5013 	pci_clear_mwi(adapter->pdev);
       
  5014 }
       
  5015 
       
  5016 void
       
  5017 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
       
  5018 {
       
  5019 	struct e1000_adapter *adapter = hw->back;
       
  5020 
       
  5021 	pci_read_config_word(adapter->pdev, reg, value);
       
  5022 }
       
  5023 
       
  5024 void
       
  5025 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
       
  5026 {
       
  5027 	struct e1000_adapter *adapter = hw->back;
       
  5028 
       
  5029 	pci_write_config_word(adapter->pdev, reg, *value);
       
  5030 }
       
  5031 
       
  5032 int32_t
       
  5033 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
       
  5034 {
       
  5035     struct e1000_adapter *adapter = hw->back;
       
  5036     uint16_t cap_offset;
       
  5037 
       
  5038     cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
       
  5039     if (!cap_offset)
       
  5040         return -E1000_ERR_CONFIG;
       
  5041 
       
  5042     pci_read_config_word(adapter->pdev, cap_offset + reg, value);
       
  5043 
       
  5044     return E1000_SUCCESS;
       
  5045 }
       
  5046 
       
  5047 void
       
  5048 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
       
  5049 {
       
  5050 	outl(value, port);
       
  5051 }
       
  5052 
       
  5053 static void
       
  5054 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
       
  5055 {
       
  5056 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5057 	uint32_t ctrl, rctl;
       
  5058 
       
  5059 	e1000_irq_disable(adapter);
       
  5060 	adapter->vlgrp = grp;
       
  5061 
       
  5062 	if (grp) {
       
  5063 		/* enable VLAN tag insert/strip */
       
  5064 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
       
  5065 		ctrl |= E1000_CTRL_VME;
       
  5066 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
       
  5067 
       
  5068 		if (adapter->hw.mac_type != e1000_ich8lan) {
       
  5069 			/* enable VLAN receive filtering */
       
  5070 			rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  5071 			rctl |= E1000_RCTL_VFE;
       
  5072 			rctl &= ~E1000_RCTL_CFIEN;
       
  5073 			E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  5074 			e1000_update_mng_vlan(adapter);
       
  5075 		}
       
  5076 	} else {
       
  5077 		/* disable VLAN tag insert/strip */
       
  5078 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
       
  5079 		ctrl &= ~E1000_CTRL_VME;
       
  5080 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
       
  5081 
       
  5082 		if (adapter->hw.mac_type != e1000_ich8lan) {
       
  5083 			/* disable VLAN filtering */
       
  5084 			rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  5085 			rctl &= ~E1000_RCTL_VFE;
       
  5086 			E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  5087 			if (adapter->mng_vlan_id !=
       
  5088 			    (uint16_t)E1000_MNG_VLAN_NONE) {
       
  5089 				e1000_vlan_rx_kill_vid(netdev,
       
  5090 				                       adapter->mng_vlan_id);
       
  5091 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
       
  5092 			}
       
  5093 		}
       
  5094 	}
       
  5095 
       
  5096 	e1000_irq_enable(adapter);
       
  5097 }
       
  5098 
       
  5099 static void
       
  5100 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
       
  5101 {
       
  5102 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5103 	uint32_t vfta, index;
       
  5104 
       
  5105 	if ((adapter->hw.mng_cookie.status &
       
  5106 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
       
  5107 	    (vid == adapter->mng_vlan_id))
       
  5108 		return;
       
  5109 	/* add VID to filter table */
       
  5110 	index = (vid >> 5) & 0x7F;
       
  5111 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
       
  5112 	vfta |= (1 << (vid & 0x1F));
       
  5113 	e1000_write_vfta(&adapter->hw, index, vfta);
       
  5114 }
       
  5115 
       
  5116 static void
       
  5117 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
       
  5118 {
       
  5119 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5120 	uint32_t vfta, index;
       
  5121 
       
  5122 	e1000_irq_disable(adapter);
       
  5123 	vlan_group_set_device(adapter->vlgrp, vid, NULL);
       
  5124 	e1000_irq_enable(adapter);
       
  5125 
       
  5126 	if ((adapter->hw.mng_cookie.status &
       
  5127 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
       
  5128 	    (vid == adapter->mng_vlan_id)) {
       
  5129 		/* release control to f/w */
       
  5130 		e1000_release_hw_control(adapter);
       
  5131 		return;
       
  5132 	}
       
  5133 
       
  5134 	/* remove VID from filter table */
       
  5135 	index = (vid >> 5) & 0x7F;
       
  5136 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
       
  5137 	vfta &= ~(1 << (vid & 0x1F));
       
  5138 	e1000_write_vfta(&adapter->hw, index, vfta);
       
  5139 }
       
  5140 
       
  5141 static void
       
  5142 e1000_restore_vlan(struct e1000_adapter *adapter)
       
  5143 {
       
  5144 	e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
       
  5145 
       
  5146 	if (adapter->vlgrp) {
       
  5147 		uint16_t vid;
       
  5148 		for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
       
  5149 			if (!vlan_group_get_device(adapter->vlgrp, vid))
       
  5150 				continue;
       
  5151 			e1000_vlan_rx_add_vid(adapter->netdev, vid);
       
  5152 		}
       
  5153 	}
       
  5154 }
       
  5155 
       
  5156 int
       
  5157 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
       
  5158 {
       
  5159 	adapter->hw.autoneg = 0;
       
  5160 
       
  5161 	/* Fiber NICs only allow 1000 gbps Full duplex */
       
  5162 	if ((adapter->hw.media_type == e1000_media_type_fiber) &&
       
  5163 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
       
  5164 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
       
  5165 		return -EINVAL;
       
  5166 	}
       
  5167 
       
  5168 	switch (spddplx) {
       
  5169 	case SPEED_10 + DUPLEX_HALF:
       
  5170 		adapter->hw.forced_speed_duplex = e1000_10_half;
       
  5171 		break;
       
  5172 	case SPEED_10 + DUPLEX_FULL:
       
  5173 		adapter->hw.forced_speed_duplex = e1000_10_full;
       
  5174 		break;
       
  5175 	case SPEED_100 + DUPLEX_HALF:
       
  5176 		adapter->hw.forced_speed_duplex = e1000_100_half;
       
  5177 		break;
       
  5178 	case SPEED_100 + DUPLEX_FULL:
       
  5179 		adapter->hw.forced_speed_duplex = e1000_100_full;
       
  5180 		break;
       
  5181 	case SPEED_1000 + DUPLEX_FULL:
       
  5182 		adapter->hw.autoneg = 1;
       
  5183 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
       
  5184 		break;
       
  5185 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
       
  5186 	default:
       
  5187 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
       
  5188 		return -EINVAL;
       
  5189 	}
       
  5190 	return 0;
       
  5191 }
       
  5192 
       
  5193 static int
       
  5194 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
       
  5195 {
       
  5196 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  5197 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5198 	uint32_t ctrl, ctrl_ext, rctl, status;
       
  5199 	uint32_t wufc = adapter->wol;
       
  5200 #ifdef CONFIG_PM
       
  5201 	int retval = 0;
       
  5202 #endif
       
  5203 
       
  5204 	if (adapter->ecdev)
       
  5205 		return -EBUSY;
       
  5206 
       
  5207 	netif_device_detach(netdev);
       
  5208 
       
  5209 	if (netif_running(netdev)) {
       
  5210 		WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
       
  5211 		e1000_down(adapter);
       
  5212 	}
       
  5213 
       
  5214 #ifdef CONFIG_PM
       
  5215 	retval = pci_save_state(pdev);
       
  5216 	if (retval)
       
  5217 		return retval;
       
  5218 #endif
       
  5219 
       
  5220 	status = E1000_READ_REG(&adapter->hw, STATUS);
       
  5221 	if (status & E1000_STATUS_LU)
       
  5222 		wufc &= ~E1000_WUFC_LNKC;
       
  5223 
       
  5224 	if (wufc) {
       
  5225 		e1000_setup_rctl(adapter);
       
  5226 		e1000_set_multi(netdev);
       
  5227 
       
  5228 		/* turn on all-multi mode if wake on multicast is enabled */
       
  5229 		if (wufc & E1000_WUFC_MC) {
       
  5230 			rctl = E1000_READ_REG(&adapter->hw, RCTL);
       
  5231 			rctl |= E1000_RCTL_MPE;
       
  5232 			E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
       
  5233 		}
       
  5234 
       
  5235 		if (adapter->hw.mac_type >= e1000_82540) {
       
  5236 			ctrl = E1000_READ_REG(&adapter->hw, CTRL);
       
  5237 			/* advertise wake from D3Cold */
       
  5238 			#define E1000_CTRL_ADVD3WUC 0x00100000
       
  5239 			/* phy power management enable */
       
  5240 			#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
       
  5241 			ctrl |= E1000_CTRL_ADVD3WUC |
       
  5242 				E1000_CTRL_EN_PHY_PWR_MGMT;
       
  5243 			E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
       
  5244 		}
       
  5245 
       
  5246 		if (adapter->hw.media_type == e1000_media_type_fiber ||
       
  5247 		   adapter->hw.media_type == e1000_media_type_internal_serdes) {
       
  5248 			/* keep the laser running in D3 */
       
  5249 			ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
       
  5250 			ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
       
  5251 			E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
       
  5252 		}
       
  5253 
       
  5254 		/* Allow time for pending master requests to run */
       
  5255 		e1000_disable_pciex_master(&adapter->hw);
       
  5256 
       
  5257 		E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
       
  5258 		E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
       
  5259 		pci_enable_wake(pdev, PCI_D3hot, 1);
       
  5260 		pci_enable_wake(pdev, PCI_D3cold, 1);
       
  5261 	} else {
       
  5262 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
       
  5263 		E1000_WRITE_REG(&adapter->hw, WUFC, 0);
       
  5264 		pci_enable_wake(pdev, PCI_D3hot, 0);
       
  5265 		pci_enable_wake(pdev, PCI_D3cold, 0);
       
  5266 	}
       
  5267 
       
  5268 	e1000_release_manageability(adapter);
       
  5269 
       
  5270 	/* make sure adapter isn't asleep if manageability is enabled */
       
  5271 	if (adapter->en_mng_pt) {
       
  5272 		pci_enable_wake(pdev, PCI_D3hot, 1);
       
  5273 		pci_enable_wake(pdev, PCI_D3cold, 1);
       
  5274 	}
       
  5275 
       
  5276 	if (adapter->hw.phy_type == e1000_phy_igp_3)
       
  5277 		e1000_phy_powerdown_workaround(&adapter->hw);
       
  5278 
       
  5279 	if (netif_running(netdev))
       
  5280 		e1000_free_irq(adapter);
       
  5281 
       
  5282 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
       
  5283 	 * would have already happened in close and is redundant. */
       
  5284 	e1000_release_hw_control(adapter);
       
  5285 
       
  5286 	pci_disable_device(pdev);
       
  5287 
       
  5288 	pci_set_power_state(pdev, pci_choose_state(pdev, state));
       
  5289 
       
  5290 	return 0;
       
  5291 }
       
  5292 
       
  5293 #ifdef CONFIG_PM
       
  5294 static int
       
  5295 e1000_resume(struct pci_dev *pdev)
       
  5296 {
       
  5297 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  5298 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5299 	uint32_t err;
       
  5300 
       
  5301 	if (adapter->ecdev)
       
  5302 		return -EBUSY;
       
  5303 
       
  5304 	pci_set_power_state(pdev, PCI_D0);
       
  5305 	pci_restore_state(pdev);
       
  5306 	if ((err = pci_enable_device(pdev))) {
       
  5307 		printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
       
  5308 		return err;
       
  5309 	}
       
  5310 	pci_set_master(pdev);
       
  5311 
       
  5312 	pci_enable_wake(pdev, PCI_D3hot, 0);
       
  5313 	pci_enable_wake(pdev, PCI_D3cold, 0);
       
  5314 
       
  5315 	if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
       
  5316 		return err;
       
  5317 
       
  5318 	e1000_power_up_phy(adapter);
       
  5319 	e1000_reset(adapter);
       
  5320 	E1000_WRITE_REG(&adapter->hw, WUS, ~0);
       
  5321 
       
  5322 	e1000_init_manageability(adapter);
       
  5323 
       
  5324 	if (netif_running(netdev))
       
  5325 		e1000_up(adapter);
       
  5326 
       
  5327 	if (!adapter->ecdev) netif_device_attach(netdev);
       
  5328 
       
  5329 	/* If the controller is 82573 and f/w is AMT, do not set
       
  5330 	 * DRV_LOAD until the interface is up.  For all other cases,
       
  5331 	 * let the f/w know that the h/w is now under the control
       
  5332 	 * of the driver. */
       
  5333 	if (adapter->hw.mac_type != e1000_82573 ||
       
  5334 	    !e1000_check_mng_mode(&adapter->hw))
       
  5335 		e1000_get_hw_control(adapter);
       
  5336 
       
  5337 	return 0;
       
  5338 }
       
  5339 #endif
       
  5340 
       
  5341 static void e1000_shutdown(struct pci_dev *pdev)
       
  5342 {
       
  5343 	e1000_suspend(pdev, PMSG_SUSPEND);
       
  5344 }
       
  5345 
       
  5346 #ifdef CONFIG_NET_POLL_CONTROLLER
       
  5347 /*
       
  5348  * Polling 'interrupt' - used by things like netconsole to send skbs
       
  5349  * without having to re-enable interrupts. It's not called while
       
  5350  * the interrupt routine is executing.
       
  5351  */
       
  5352 static void
       
  5353 e1000_netpoll(struct net_device *netdev)
       
  5354 {
       
  5355 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  5356 
       
  5357 	disable_irq(adapter->pdev->irq);
       
  5358 	e1000_intr(adapter->pdev->irq, netdev);
       
  5359 	e1000_clean_tx_irq(adapter, adapter->tx_ring);
       
  5360 #ifndef CONFIG_E1000_NAPI
       
  5361 	adapter->clean_rx(adapter, adapter->rx_ring);
       
  5362 #endif
       
  5363 	enable_irq(adapter->pdev->irq);
       
  5364 }
       
  5365 #endif
       
  5366 
       
  5367 /**
       
  5368  * e1000_io_error_detected - called when PCI error is detected
       
  5369  * @pdev: Pointer to PCI device
       
  5370  * @state: The current pci conneection state
       
  5371  *
       
  5372  * This function is called after a PCI bus error affecting
       
  5373  * this device has been detected.
       
  5374  */
       
  5375 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
       
  5376 {
       
  5377 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  5378 	struct e1000_adapter *adapter = netdev->priv;
       
  5379 
       
  5380 	netif_device_detach(netdev);
       
  5381 
       
  5382 	if (netif_running(netdev))
       
  5383 		e1000_down(adapter);
       
  5384 	pci_disable_device(pdev);
       
  5385 
       
  5386 	/* Request a slot slot reset. */
       
  5387 	return PCI_ERS_RESULT_NEED_RESET;
       
  5388 }
       
  5389 
       
  5390 /**
       
  5391  * e1000_io_slot_reset - called after the pci bus has been reset.
       
  5392  * @pdev: Pointer to PCI device
       
  5393  *
       
  5394  * Restart the card from scratch, as if from a cold-boot. Implementation
       
  5395  * resembles the first-half of the e1000_resume routine.
       
  5396  */
       
  5397 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
       
  5398 {
       
  5399 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  5400 	struct e1000_adapter *adapter = netdev->priv;
       
  5401 
       
  5402 	if (pci_enable_device(pdev)) {
       
  5403 		printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
       
  5404 		return PCI_ERS_RESULT_DISCONNECT;
       
  5405 	}
       
  5406 	pci_set_master(pdev);
       
  5407 
       
  5408 	pci_enable_wake(pdev, PCI_D3hot, 0);
       
  5409 	pci_enable_wake(pdev, PCI_D3cold, 0);
       
  5410 
       
  5411 	e1000_reset(adapter);
       
  5412 	E1000_WRITE_REG(&adapter->hw, WUS, ~0);
       
  5413 
       
  5414 	return PCI_ERS_RESULT_RECOVERED;
       
  5415 }
       
  5416 
       
  5417 /**
       
  5418  * e1000_io_resume - called when traffic can start flowing again.
       
  5419  * @pdev: Pointer to PCI device
       
  5420  *
       
  5421  * This callback is called when the error recovery driver tells us that
       
  5422  * its OK to resume normal operation. Implementation resembles the
       
  5423  * second-half of the e1000_resume routine.
       
  5424  */
       
  5425 static void e1000_io_resume(struct pci_dev *pdev)
       
  5426 {
       
  5427 	struct net_device *netdev = pci_get_drvdata(pdev);
       
  5428 	struct e1000_adapter *adapter = netdev->priv;
       
  5429 
       
  5430 	e1000_init_manageability(adapter);
       
  5431 
       
  5432 	if (netif_running(netdev)) {
       
  5433 		if (e1000_up(adapter)) {
       
  5434 			printk("e1000: can't bring device back up after reset\n");
       
  5435 			return;
       
  5436 		}
       
  5437 	}
       
  5438 
       
  5439 	netif_device_attach(netdev);
       
  5440 
       
  5441 	/* If the controller is 82573 and f/w is AMT, do not set
       
  5442 	 * DRV_LOAD until the interface is up.  For all other cases,
       
  5443 	 * let the f/w know that the h/w is now under the control
       
  5444 	 * of the driver. */
       
  5445 	if (adapter->hw.mac_type != e1000_82573 ||
       
  5446 	    !e1000_check_mng_mode(&adapter->hw))
       
  5447 		e1000_get_hw_control(adapter);
       
  5448 
       
  5449 }
       
  5450 
       
  5451 /* e1000_main.c */