ch1010832@1996: /*******************************************************************************
ch1010832@1996: 
ch1010832@1996:   Intel PRO/1000 Linux driver
ch1010832@1996:   Copyright(c) 1999 - 2006 Intel Corporation.
ch1010832@1996: 
ch1010832@1996:   This program is free software; you can redistribute it and/or modify it
ch1010832@1996:   under the terms and conditions of the GNU General Public License,
ch1010832@1996:   version 2, as published by the Free Software Foundation.
ch1010832@1996: 
ch1010832@1996:   This program is distributed in the hope it will be useful, but WITHOUT
ch1010832@1996:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ch1010832@1996:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
ch1010832@1996:   more details.
ch1010832@1996: 
ch1010832@1996:   You should have received a copy of the GNU General Public License along with
ch1010832@1996:   this program; if not, write to the Free Software Foundation, Inc.,
ch1010832@1996:   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
ch1010832@1996: 
ch1010832@1996:   The full GNU General Public License is included in this distribution in
ch1010832@1996:   the file called "COPYING".
ch1010832@1996: 
ch1010832@1996:   Contact Information:
ch1010832@1996:   Linux NICS <linux.nics@intel.com>
ch1010832@1996:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
ch1010832@1996:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
ch1010832@1996: 
ch1010832@1996: *******************************************************************************/
ch1010832@1996: 
ch1010832@1996: #include "e1000.h"
ch1010832@1996: #include <net/ip6_checksum.h>
ch1010832@1996: 
ch1010832@1996: char e1000_driver_name[] = "e1000";
ch1010832@1996: static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
ch1010832@1996: #define DRV_VERSION "7.3.21-k3-NAPI"
ch1010832@1996: const char e1000_driver_version[] = DRV_VERSION;
ch1010832@1996: static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
ch1010832@1996: 
ch1010832@1996: /* e1000_pci_tbl - PCI Device ID Table
ch1010832@1996:  *
ch1010832@1996:  * Last entry must be all 0s
ch1010832@1996:  *
ch1010832@1996:  * Macro expands to...
ch1010832@1996:  *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
ch1010832@1996:  */
ch1010832@1996: static struct pci_device_id e1000_pci_tbl[] = {
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1000),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1001),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1004),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1008),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1009),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x100C),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x100D),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x100E),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x100F),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1010),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1011),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1012),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1013),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1014),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1015),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1016),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1017),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1018),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1019),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x101A),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x101D),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x101E),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1026),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1027),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1028),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1075),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1076),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1077),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1078),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1079),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x107A),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x107B),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x107C),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x108A),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x1099),
ch1010832@1996: 	INTEL_E1000_ETHERNET_DEVICE(0x10B5),
ch1010832@1996: 	/* required last entry */
ch1010832@1996: 	{0,}
ch1010832@1996: };
ch1010832@1996: 
ch1010832@1996: MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
ch1010832@1996: 
ch1010832@1996: int e1000_up(struct e1000_adapter *adapter);
ch1010832@1996: void e1000_down(struct e1000_adapter *adapter);
ch1010832@1996: void e1000_reinit_locked(struct e1000_adapter *adapter);
ch1010832@1996: void e1000_reset(struct e1000_adapter *adapter);
ch1010832@1996: int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
ch1010832@1996: int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
ch1010832@1996: int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
ch1010832@1996: void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
ch1010832@1996: void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
ch1010832@1996: static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
ch1010832@1996:                              struct e1000_tx_ring *txdr);
ch1010832@1996: static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
ch1010832@1996:                              struct e1000_rx_ring *rxdr);
ch1010832@1996: static void e1000_free_tx_resources(struct e1000_adapter *adapter,
ch1010832@1996:                              struct e1000_tx_ring *tx_ring);
ch1010832@1996: static void e1000_free_rx_resources(struct e1000_adapter *adapter,
ch1010832@1996:                              struct e1000_rx_ring *rx_ring);
ch1010832@1996: void e1000_update_stats(struct e1000_adapter *adapter);
ch1010832@1996: 
ch1010832@1996: static int e1000_init_module(void);
ch1010832@1996: static void e1000_exit_module(void);
ch1010832@1996: static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
ch1010832@1996: static void __devexit e1000_remove(struct pci_dev *pdev);
ch1010832@1996: static int e1000_alloc_queues(struct e1000_adapter *adapter);
ch1010832@1996: static int e1000_sw_init(struct e1000_adapter *adapter);
ch1010832@1996: static int e1000_open(struct net_device *netdev);
ch1010832@1996: static int e1000_close(struct net_device *netdev);
ch1010832@1996: static void e1000_configure_tx(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_configure_rx(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_setup_rctl(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
ch1010832@1996:                                 struct e1000_tx_ring *tx_ring);
ch1010832@1996: static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
ch1010832@1996:                                 struct e1000_rx_ring *rx_ring);
ch1010832@1996: static void e1000_set_rx_mode(struct net_device *netdev);
ch1010832@1996: static void e1000_update_phy_info(unsigned long data);
ch1010832@1996: static void e1000_watchdog(unsigned long data);
ch1010832@1996: static void e1000_82547_tx_fifo_stall(unsigned long data);
ch1010832@1996: static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
ch1010832@1996: static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
ch1010832@1996: static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
ch1010832@1996: static int e1000_set_mac(struct net_device *netdev, void *p);
ch1010832@1996: static irqreturn_t e1000_intr(int irq, void *data);
ch1010832@1996: static irqreturn_t e1000_intr_msi(int irq, void *data);
ch1010832@1996: static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
ch1010832@1996: 			       struct e1000_tx_ring *tx_ring);
ch1010832@1996: static int e1000_clean(struct napi_struct *napi, int budget);
ch1010832@1996: static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
ch1010832@1996: 			       struct e1000_rx_ring *rx_ring,
ch1010832@1996: 			       int *work_done, int work_to_do);
ch1010832@1996: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
ch1010832@1996:                                    struct e1000_rx_ring *rx_ring,
ch1010832@1996: 				   int cleaned_count);
ch1010832@1996: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
ch1010832@1996: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
ch1010832@1996: 			   int cmd);
ch1010832@1996: static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
ch1010832@1996: static void e1000_tx_timeout(struct net_device *dev);
ch1010832@1996: static void e1000_reset_task(struct work_struct *work);
ch1010832@1996: static void e1000_smartspeed(struct e1000_adapter *adapter);
ch1010832@1996: static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
ch1010832@1996:                                        struct sk_buff *skb);
ch1010832@1996: 
ch1010832@1996: static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
ch1010832@1996: static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
ch1010832@1996: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
ch1010832@1996: static void e1000_restore_vlan(struct e1000_adapter *adapter);
ch1010832@1996: 
ch1010832@1996: #ifdef CONFIG_PM
ch1010832@1996: static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
ch1010832@1996: static int e1000_resume(struct pci_dev *pdev);
ch1010832@1996: #endif
ch1010832@1996: static void e1000_shutdown(struct pci_dev *pdev);
ch1010832@1996: 
ch1010832@1996: #ifdef CONFIG_NET_POLL_CONTROLLER
ch1010832@1996: /* for netdump / net console */
ch1010832@1996: static void e1000_netpoll (struct net_device *netdev);
ch1010832@1996: #endif
ch1010832@1996: 
ch1010832@1996: #define COPYBREAK_DEFAULT 256
ch1010832@1996: static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
ch1010832@1996: module_param(copybreak, uint, 0644);
ch1010832@1996: MODULE_PARM_DESC(copybreak,
ch1010832@1996: 	"Maximum size of packet that is copied to a new buffer on receive");
ch1010832@1996: 
ch1010832@1996: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
ch1010832@1996:                      pci_channel_state_t state);
ch1010832@1996: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
ch1010832@1996: static void e1000_io_resume(struct pci_dev *pdev);
ch1010832@1996: 
ch1010832@1996: static struct pci_error_handlers e1000_err_handler = {
ch1010832@1996: 	.error_detected = e1000_io_error_detected,
ch1010832@1996: 	.slot_reset = e1000_io_slot_reset,
ch1010832@1996: 	.resume = e1000_io_resume,
ch1010832@1996: };
ch1010832@1996: 
ch1010832@1996: static struct pci_driver e1000_driver = {
ch1010832@1996: 	.name     = e1000_driver_name,
ch1010832@1996: 	.id_table = e1000_pci_tbl,
ch1010832@1996: 	.probe    = e1000_probe,
ch1010832@1996: 	.remove   = __devexit_p(e1000_remove),
ch1010832@1996: #ifdef CONFIG_PM
ch1010832@1996: 	/* Power Managment Hooks */
ch1010832@1996: 	.suspend  = e1000_suspend,
ch1010832@1996: 	.resume   = e1000_resume,
ch1010832@1996: #endif
ch1010832@1996: 	.shutdown = e1000_shutdown,
ch1010832@1996: 	.err_handler = &e1000_err_handler
ch1010832@1996: };
ch1010832@1996: 
ch1010832@1996: MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
ch1010832@1996: MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
ch1010832@1996: MODULE_LICENSE("GPL");
ch1010832@1996: MODULE_VERSION(DRV_VERSION);
ch1010832@1996: 
ch1010832@1996: static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
ch1010832@1996: module_param(debug, int, 0);
ch1010832@1996: MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_init_module - Driver Registration Routine
ch1010832@1996:  *
ch1010832@1996:  * e1000_init_module is the first routine called when the driver is
ch1010832@1996:  * loaded. All it does is register with the PCI subsystem.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int __init e1000_init_module(void)
ch1010832@1996: {
ch1010832@1996: 	int ret;
ch1010832@1996: 	printk(KERN_INFO "%s - version %s\n",
ch1010832@1996: 	       e1000_driver_string, e1000_driver_version);
ch1010832@1996: 
ch1010832@1996: 	printk(KERN_INFO "%s\n", e1000_copyright);
ch1010832@1996: 
ch1010832@1996: 	ret = pci_register_driver(&e1000_driver);
ch1010832@1996: 	if (copybreak != COPYBREAK_DEFAULT) {
ch1010832@1996: 		if (copybreak == 0)
ch1010832@1996: 			printk(KERN_INFO "e1000: copybreak disabled\n");
ch1010832@1996: 		else
ch1010832@1996: 			printk(KERN_INFO "e1000: copybreak enabled for "
ch1010832@1996: 			       "packets <= %u bytes\n", copybreak);
ch1010832@1996: 	}
ch1010832@1996: 	return ret;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: module_init(e1000_init_module);
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_exit_module - Driver Exit Cleanup Routine
ch1010832@1996:  *
ch1010832@1996:  * e1000_exit_module is called just before the driver is removed
ch1010832@1996:  * from memory.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void __exit e1000_exit_module(void)
ch1010832@1996: {
ch1010832@1996: 	pci_unregister_driver(&e1000_driver);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: module_exit(e1000_exit_module);
ch1010832@1996: 
ch1010832@1996: static int e1000_request_irq(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	irq_handler_t handler = e1000_intr;
ch1010832@1996: 	int irq_flags = IRQF_SHARED;
ch1010832@1996: 	int err;
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type >= e1000_82571) {
ch1010832@1996: 		adapter->have_msi = !pci_enable_msi(adapter->pdev);
ch1010832@1996: 		if (adapter->have_msi) {
ch1010832@1996: 			handler = e1000_intr_msi;
ch1010832@1996: 			irq_flags = 0;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
ch1010832@1996: 	                  netdev);
ch1010832@1996: 	if (err) {
ch1010832@1996: 		if (adapter->have_msi)
ch1010832@1996: 			pci_disable_msi(adapter->pdev);
ch1010832@1996: 		DPRINTK(PROBE, ERR,
ch1010832@1996: 		        "Unable to allocate interrupt Error: %d\n", err);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return err;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_free_irq(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 
ch1010832@1996: 	free_irq(adapter->pdev->irq, netdev);
ch1010832@1996: 
ch1010832@1996: 	if (adapter->have_msi)
ch1010832@1996: 		pci_disable_msi(adapter->pdev);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_irq_disable - Mask off interrupt generation on the NIC
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_irq_disable(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	ew32(IMC, ~0);
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: 	synchronize_irq(adapter->pdev->irq);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_irq_enable - Enable default interrupt generation settings
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_irq_enable(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	ew32(IMS, IMS_ENABLE_MASK);
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	u16 vid = hw->mng_cookie.vlan_id;
ch1010832@1996: 	u16 old_vid = adapter->mng_vlan_id;
ch1010832@1996: 	if (adapter->vlgrp) {
ch1010832@1996: 		if (!vlan_group_get_device(adapter->vlgrp, vid)) {
ch1010832@1996: 			if (hw->mng_cookie.status &
ch1010832@1996: 				E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
ch1010832@1996: 				e1000_vlan_rx_add_vid(netdev, vid);
ch1010832@1996: 				adapter->mng_vlan_id = vid;
ch1010832@1996: 			} else
ch1010832@1996: 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
ch1010832@1996: 
ch1010832@1996: 			if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
ch1010832@1996: 					(vid != old_vid) &&
ch1010832@1996: 			    !vlan_group_get_device(adapter->vlgrp, old_vid))
ch1010832@1996: 				e1000_vlan_rx_kill_vid(netdev, old_vid);
ch1010832@1996: 		} else
ch1010832@1996: 			adapter->mng_vlan_id = vid;
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_release_hw_control - release control of the h/w to f/w
ch1010832@1996:  * @adapter: address of board private structure
ch1010832@1996:  *
ch1010832@1996:  * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
ch1010832@1996:  * For ASF and Pass Through versions of f/w this means that the
ch1010832@1996:  * driver is no longer loaded. For AMT version (only with 82573) i
ch1010832@1996:  * of the f/w this means that the network i/f is closed.
ch1010832@1996:  *
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_release_hw_control(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	u32 ctrl_ext;
ch1010832@1996: 	u32 swsm;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	/* Let firmware taken over control of h/w */
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_82573:
ch1010832@1996: 		swsm = er32(SWSM);
ch1010832@1996: 		ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82571:
ch1010832@1996: 	case e1000_82572:
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: 	case e1000_ich8lan:
ch1010832@1996: 		ctrl_ext = er32(CTRL_EXT);
ch1010832@1996: 		ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_get_hw_control - get control of the h/w from f/w
ch1010832@1996:  * @adapter: address of board private structure
ch1010832@1996:  *
ch1010832@1996:  * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
ch1010832@1996:  * For ASF and Pass Through versions of f/w this means that
ch1010832@1996:  * the driver is loaded. For AMT version (only with 82573)
ch1010832@1996:  * of the f/w this means that the network i/f is open.
ch1010832@1996:  *
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_get_hw_control(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	u32 ctrl_ext;
ch1010832@1996: 	u32 swsm;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	/* Let firmware know the driver has taken over */
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_82573:
ch1010832@1996: 		swsm = er32(SWSM);
ch1010832@1996: 		ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82571:
ch1010832@1996: 	case e1000_82572:
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: 	case e1000_ich8lan:
ch1010832@1996: 		ctrl_ext = er32(CTRL_EXT);
ch1010832@1996: 		ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_init_manageability(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->en_mng_pt) {
ch1010832@1996: 		u32 manc = er32(MANC);
ch1010832@1996: 
ch1010832@1996: 		/* disable hardware interception of ARP */
ch1010832@1996: 		manc &= ~(E1000_MANC_ARP_EN);
ch1010832@1996: 
ch1010832@1996: 		/* enable receiving management packets to the host */
ch1010832@1996: 		/* this will probably generate destination unreachable messages
ch1010832@1996: 		 * from the host OS, but the packets will be handled on SMBUS */
ch1010832@1996: 		if (hw->has_manc2h) {
ch1010832@1996: 			u32 manc2h = er32(MANC2H);
ch1010832@1996: 
ch1010832@1996: 			manc |= E1000_MANC_EN_MNG2HOST;
ch1010832@1996: #define E1000_MNG2HOST_PORT_623 (1 << 5)
ch1010832@1996: #define E1000_MNG2HOST_PORT_664 (1 << 6)
ch1010832@1996: 			manc2h |= E1000_MNG2HOST_PORT_623;
ch1010832@1996: 			manc2h |= E1000_MNG2HOST_PORT_664;
ch1010832@1996: 			ew32(MANC2H, manc2h);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		ew32(MANC, manc);
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_release_manageability(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->en_mng_pt) {
ch1010832@1996: 		u32 manc = er32(MANC);
ch1010832@1996: 
ch1010832@1996: 		/* re-enable hardware interception of ARP */
ch1010832@1996: 		manc |= E1000_MANC_ARP_EN;
ch1010832@1996: 
ch1010832@1996: 		if (hw->has_manc2h)
ch1010832@1996: 			manc &= ~E1000_MANC_EN_MNG2HOST;
ch1010832@1996: 
ch1010832@1996: 		/* don't explicitly have to mess with MANC2H since
ch1010832@1996: 		 * MANC has an enable disable that gates MANC2H */
ch1010832@1996: 
ch1010832@1996: 		ew32(MANC, manc);
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_configure - configure the hardware for RX and TX
ch1010832@1996:  * @adapter = private board structure
ch1010832@1996:  **/
ch1010832@1996: static void e1000_configure(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	int i;
ch1010832@1996: 
ch1010832@1996: 	e1000_set_rx_mode(netdev);
ch1010832@1996: 
ch1010832@1996: 	e1000_restore_vlan(adapter);
ch1010832@1996: 	e1000_init_manageability(adapter);
ch1010832@1996: 
ch1010832@1996: 	e1000_configure_tx(adapter);
ch1010832@1996: 	e1000_setup_rctl(adapter);
ch1010832@1996: 	e1000_configure_rx(adapter);
ch1010832@1996: 	/* call E1000_DESC_UNUSED which always leaves
ch1010832@1996: 	 * at least 1 descriptor unused to make sure
ch1010832@1996: 	 * next_to_use != next_to_clean */
ch1010832@1996: 	for (i = 0; i < adapter->num_rx_queues; i++) {
ch1010832@1996: 		struct e1000_rx_ring *ring = &adapter->rx_ring[i];
ch1010832@1996: 		adapter->alloc_rx_buf(adapter, ring,
ch1010832@1996: 		                      E1000_DESC_UNUSED(ring));
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	adapter->tx_queue_len = netdev->tx_queue_len;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: int e1000_up(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	/* hardware has been reset, we need to reload some things */
ch1010832@1996: 	e1000_configure(adapter);
ch1010832@1996: 
ch1010832@1996: 	clear_bit(__E1000_DOWN, &adapter->flags);
ch1010832@1996: 
ch1010832@1996: 	napi_enable(&adapter->napi);
ch1010832@1996: 
ch1010832@1996: 	e1000_irq_enable(adapter);
ch1010832@1996: 
ch1010832@1996: 	netif_wake_queue(adapter->netdev);
ch1010832@1996: 
ch1010832@1996: 	/* fire a link change interrupt to start the watchdog */
ch1010832@1996: 	ew32(ICS, E1000_ICS_LSC);
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_power_up_phy - restore link in case the phy was powered down
ch1010832@1996:  * @adapter: address of board private structure
ch1010832@1996:  *
ch1010832@1996:  * The phy may be powered down to save power and turn off link when the
ch1010832@1996:  * driver is unloaded and wake on lan is not enabled (among others)
ch1010832@1996:  * *** this routine MUST be followed by a call to e1000_reset ***
ch1010832@1996:  *
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: void e1000_power_up_phy(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u16 mii_reg = 0;
ch1010832@1996: 
ch1010832@1996: 	/* Just clear the power down bit to wake the phy back up */
ch1010832@1996: 	if (hw->media_type == e1000_media_type_copper) {
ch1010832@1996: 		/* according to the manual, the phy will retain its
ch1010832@1996: 		 * settings across a power-down/up cycle */
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
ch1010832@1996: 		mii_reg &= ~MII_CR_POWER_DOWN;
ch1010832@1996: 		e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_power_down_phy(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	/* Power down the PHY so no link is implied when interface is down *
ch1010832@1996: 	 * The PHY cannot be powered down if any of the following is true *
ch1010832@1996: 	 * (a) WoL is enabled
ch1010832@1996: 	 * (b) AMT is active
ch1010832@1996: 	 * (c) SoL/IDER session is active */
ch1010832@1996: 	if (!adapter->wol && hw->mac_type >= e1000_82540 &&
ch1010832@1996: 	   hw->media_type == e1000_media_type_copper) {
ch1010832@1996: 		u16 mii_reg = 0;
ch1010832@1996: 
ch1010832@1996: 		switch (hw->mac_type) {
ch1010832@1996: 		case e1000_82540:
ch1010832@1996: 		case e1000_82545:
ch1010832@1996: 		case e1000_82545_rev_3:
ch1010832@1996: 		case e1000_82546:
ch1010832@1996: 		case e1000_82546_rev_3:
ch1010832@1996: 		case e1000_82541:
ch1010832@1996: 		case e1000_82541_rev_2:
ch1010832@1996: 		case e1000_82547:
ch1010832@1996: 		case e1000_82547_rev_2:
ch1010832@1996: 			if (er32(MANC) & E1000_MANC_SMBUS_EN)
ch1010832@1996: 				goto out;
ch1010832@1996: 			break;
ch1010832@1996: 		case e1000_82571:
ch1010832@1996: 		case e1000_82572:
ch1010832@1996: 		case e1000_82573:
ch1010832@1996: 		case e1000_80003es2lan:
ch1010832@1996: 		case e1000_ich8lan:
ch1010832@1996: 			if (e1000_check_mng_mode(hw) ||
ch1010832@1996: 			    e1000_check_phy_reset_block(hw))
ch1010832@1996: 				goto out;
ch1010832@1996: 			break;
ch1010832@1996: 		default:
ch1010832@1996: 			goto out;
ch1010832@1996: 		}
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
ch1010832@1996: 		mii_reg |= MII_CR_POWER_DOWN;
ch1010832@1996: 		e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
ch1010832@1996: 		mdelay(1);
ch1010832@1996: 	}
ch1010832@1996: out:
ch1010832@1996: 	return;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_down(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	u32 rctl, tctl;
ch1010832@1996: 
ch1010832@1996: 	/* signal that we're down so the interrupt handler does not
ch1010832@1996: 	 * reschedule our watchdog timer */
ch1010832@1996: 	set_bit(__E1000_DOWN, &adapter->flags);
ch1010832@1996: 
ch1010832@1996: 	/* disable receives in the hardware */
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 	ew32(RCTL, rctl & ~E1000_RCTL_EN);
ch1010832@1996: 	/* flush and sleep below */
ch1010832@1996: 
ch1010832@1996: 	/* can be netif_tx_disable when NETIF_F_LLTX is removed */
ch1010832@1996: 	netif_stop_queue(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* disable transmits in the hardware */
ch1010832@1996: 	tctl = er32(TCTL);
ch1010832@1996: 	tctl &= ~E1000_TCTL_EN;
ch1010832@1996: 	ew32(TCTL, tctl);
ch1010832@1996: 	/* flush both disables and wait for them to finish */
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: 	msleep(10);
ch1010832@1996: 
ch1010832@1996: 	napi_disable(&adapter->napi);
ch1010832@1996: 
ch1010832@1996: 	e1000_irq_disable(adapter);
ch1010832@1996: 
ch1010832@1996: 	del_timer_sync(&adapter->tx_fifo_stall_timer);
ch1010832@1996: 	del_timer_sync(&adapter->watchdog_timer);
ch1010832@1996: 	del_timer_sync(&adapter->phy_info_timer);
ch1010832@1996: 
ch1010832@1996: 	netdev->tx_queue_len = adapter->tx_queue_len;
ch1010832@1996: 	adapter->link_speed = 0;
ch1010832@1996: 	adapter->link_duplex = 0;
ch1010832@1996: 	netif_carrier_off(netdev);
ch1010832@1996: 
ch1010832@1996: 	e1000_reset(adapter);
ch1010832@1996: 	e1000_clean_all_tx_rings(adapter);
ch1010832@1996: 	e1000_clean_all_rx_rings(adapter);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_reinit_locked(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	WARN_ON(in_interrupt());
ch1010832@1996: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
ch1010832@1996: 		msleep(1);
ch1010832@1996: 	e1000_down(adapter);
ch1010832@1996: 	e1000_up(adapter);
ch1010832@1996: 	clear_bit(__E1000_RESETTING, &adapter->flags);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_reset(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 pba = 0, tx_space, min_tx_space, min_rx_space;
ch1010832@1996: 	u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
ch1010832@1996: 	bool legacy_pba_adjust = false;
ch1010832@1996: 
ch1010832@1996: 	/* Repartition Pba for greater than 9k mtu
ch1010832@1996: 	 * To take effect CTRL.RST is required.
ch1010832@1996: 	 */
ch1010832@1996: 
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_82542_rev2_0:
ch1010832@1996: 	case e1000_82542_rev2_1:
ch1010832@1996: 	case e1000_82543:
ch1010832@1996: 	case e1000_82544:
ch1010832@1996: 	case e1000_82540:
ch1010832@1996: 	case e1000_82541:
ch1010832@1996: 	case e1000_82541_rev_2:
ch1010832@1996: 		legacy_pba_adjust = true;
ch1010832@1996: 		pba = E1000_PBA_48K;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82545:
ch1010832@1996: 	case e1000_82545_rev_3:
ch1010832@1996: 	case e1000_82546:
ch1010832@1996: 	case e1000_82546_rev_3:
ch1010832@1996: 		pba = E1000_PBA_48K;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82547:
ch1010832@1996: 	case e1000_82547_rev_2:
ch1010832@1996: 		legacy_pba_adjust = true;
ch1010832@1996: 		pba = E1000_PBA_30K;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82571:
ch1010832@1996: 	case e1000_82572:
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: 		pba = E1000_PBA_38K;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82573:
ch1010832@1996: 		pba = E1000_PBA_20K;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_ich8lan:
ch1010832@1996: 		pba = E1000_PBA_8K;
ch1010832@1996: 	case e1000_undefined:
ch1010832@1996: 	case e1000_num_macs:
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (legacy_pba_adjust) {
ch1010832@1996: 		if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
ch1010832@1996: 			pba -= 8; /* allocate more FIFO for Tx */
ch1010832@1996: 
ch1010832@1996: 		if (hw->mac_type == e1000_82547) {
ch1010832@1996: 			adapter->tx_fifo_head = 0;
ch1010832@1996: 			adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
ch1010832@1996: 			adapter->tx_fifo_size =
ch1010832@1996: 				(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
ch1010832@1996: 			atomic_set(&adapter->tx_fifo_stall, 0);
ch1010832@1996: 		}
ch1010832@1996: 	} else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
ch1010832@1996: 		/* adjust PBA for jumbo frames */
ch1010832@1996: 		ew32(PBA, pba);
ch1010832@1996: 
ch1010832@1996: 		/* To maintain wire speed transmits, the Tx FIFO should be
ch1010832@1996: 		 * large enough to accomodate two full transmit packets,
ch1010832@1996: 		 * rounded up to the next 1KB and expressed in KB.  Likewise,
ch1010832@1996: 		 * the Rx FIFO should be large enough to accomodate at least
ch1010832@1996: 		 * one full receive packet and is similarly rounded up and
ch1010832@1996: 		 * expressed in KB. */
ch1010832@1996: 		pba = er32(PBA);
ch1010832@1996: 		/* upper 16 bits has Tx packet buffer allocation size in KB */
ch1010832@1996: 		tx_space = pba >> 16;
ch1010832@1996: 		/* lower 16 bits has Rx packet buffer allocation size in KB */
ch1010832@1996: 		pba &= 0xffff;
ch1010832@1996: 		/* don't include ethernet FCS because hardware appends/strips */
ch1010832@1996: 		min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
ch1010832@1996: 		               VLAN_TAG_SIZE;
ch1010832@1996: 		min_tx_space = min_rx_space;
ch1010832@1996: 		min_tx_space *= 2;
ch1010832@1996: 		min_tx_space = ALIGN(min_tx_space, 1024);
ch1010832@1996: 		min_tx_space >>= 10;
ch1010832@1996: 		min_rx_space = ALIGN(min_rx_space, 1024);
ch1010832@1996: 		min_rx_space >>= 10;
ch1010832@1996: 
ch1010832@1996: 		/* If current Tx allocation is less than the min Tx FIFO size,
ch1010832@1996: 		 * and the min Tx FIFO size is less than the current Rx FIFO
ch1010832@1996: 		 * allocation, take space away from current Rx allocation */
ch1010832@1996: 		if (tx_space < min_tx_space &&
ch1010832@1996: 		    ((min_tx_space - tx_space) < pba)) {
ch1010832@1996: 			pba = pba - (min_tx_space - tx_space);
ch1010832@1996: 
ch1010832@1996: 			/* PCI/PCIx hardware has PBA alignment constraints */
ch1010832@1996: 			switch (hw->mac_type) {
ch1010832@1996: 			case e1000_82545 ... e1000_82546_rev_3:
ch1010832@1996: 				pba &= ~(E1000_PBA_8K - 1);
ch1010832@1996: 				break;
ch1010832@1996: 			default:
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			/* if short on rx space, rx wins and must trump tx
ch1010832@1996: 			 * adjustment or use Early Receive if available */
ch1010832@1996: 			if (pba < min_rx_space) {
ch1010832@1996: 				switch (hw->mac_type) {
ch1010832@1996: 				case e1000_82573:
ch1010832@1996: 					/* ERT enabled in e1000_configure_rx */
ch1010832@1996: 					break;
ch1010832@1996: 				default:
ch1010832@1996: 					pba = min_rx_space;
ch1010832@1996: 					break;
ch1010832@1996: 				}
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	ew32(PBA, pba);
ch1010832@1996: 
ch1010832@1996: 	/* flow control settings */
ch1010832@1996: 	/* Set the FC high water mark to 90% of the FIFO size.
ch1010832@1996: 	 * Required to clear last 3 LSB */
ch1010832@1996: 	fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
ch1010832@1996: 	/* We can't use 90% on small FIFOs because the remainder
ch1010832@1996: 	 * would be less than 1 full frame.  In this case, we size
ch1010832@1996: 	 * it to allow at least a full frame above the high water
ch1010832@1996: 	 *  mark. */
ch1010832@1996: 	if (pba < E1000_PBA_16K)
ch1010832@1996: 		fc_high_water_mark = (pba * 1024) - 1600;
ch1010832@1996: 
ch1010832@1996: 	hw->fc_high_water = fc_high_water_mark;
ch1010832@1996: 	hw->fc_low_water = fc_high_water_mark - 8;
ch1010832@1996: 	if (hw->mac_type == e1000_80003es2lan)
ch1010832@1996: 		hw->fc_pause_time = 0xFFFF;
ch1010832@1996: 	else
ch1010832@1996: 		hw->fc_pause_time = E1000_FC_PAUSE_TIME;
ch1010832@1996: 	hw->fc_send_xon = 1;
ch1010832@1996: 	hw->fc = hw->original_fc;
ch1010832@1996: 
ch1010832@1996: 	/* Allow time for pending master requests to run */
ch1010832@1996: 	e1000_reset_hw(hw);
ch1010832@1996: 	if (hw->mac_type >= e1000_82544)
ch1010832@1996: 		ew32(WUC, 0);
ch1010832@1996: 
ch1010832@1996: 	if (e1000_init_hw(hw))
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Hardware Error\n");
ch1010832@1996: 	e1000_update_mng_vlan(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
ch1010832@1996: 	if (hw->mac_type >= e1000_82544 &&
ch1010832@1996: 	    hw->mac_type <= e1000_82547_rev_2 &&
ch1010832@1996: 	    hw->autoneg == 1 &&
ch1010832@1996: 	    hw->autoneg_advertised == ADVERTISE_1000_FULL) {
ch1010832@1996: 		u32 ctrl = er32(CTRL);
ch1010832@1996: 		/* clear phy power management bit if we are in gig only mode,
ch1010832@1996: 		 * which if enabled will attempt negotiation to 100Mb, which
ch1010832@1996: 		 * can cause a loss of link at power off or driver unload */
ch1010832@1996: 		ctrl &= ~E1000_CTRL_SWDPIN3;
ch1010832@1996: 		ew32(CTRL, ctrl);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
ch1010832@1996: 	ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
ch1010832@1996: 
ch1010832@1996: 	e1000_reset_adaptive(hw);
ch1010832@1996: 	e1000_phy_get_info(hw, &adapter->phy_info);
ch1010832@1996: 
ch1010832@1996: 	if (!adapter->smart_power_down &&
ch1010832@1996: 	    (hw->mac_type == e1000_82571 ||
ch1010832@1996: 	     hw->mac_type == e1000_82572)) {
ch1010832@1996: 		u16 phy_data = 0;
ch1010832@1996: 		/* speed up time to link by disabling smart power down, ignore
ch1010832@1996: 		 * the return value of this function because there is nothing
ch1010832@1996: 		 * different we would do if it failed */
ch1010832@1996: 		e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
ch1010832@1996: 		                   &phy_data);
ch1010832@1996: 		phy_data &= ~IGP02E1000_PM_SPD;
ch1010832@1996: 		e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
ch1010832@1996: 		                    phy_data);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_release_manageability(adapter);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  *  Dump the eeprom for users having checksum issues
ch1010832@1996:  **/
ch1010832@1996: static void e1000_dump_eeprom(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct ethtool_eeprom eeprom;
ch1010832@1996: 	const struct ethtool_ops *ops = netdev->ethtool_ops;
ch1010832@1996: 	u8 *data;
ch1010832@1996: 	int i;
ch1010832@1996: 	u16 csum_old, csum_new = 0;
ch1010832@1996: 
ch1010832@1996: 	eeprom.len = ops->get_eeprom_len(netdev);
ch1010832@1996: 	eeprom.offset = 0;
ch1010832@1996: 
ch1010832@1996: 	data = kmalloc(eeprom.len, GFP_KERNEL);
ch1010832@1996: 	if (!data) {
ch1010832@1996: 		printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
ch1010832@1996: 		       " data\n");
ch1010832@1996: 		return;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	ops->get_eeprom(netdev, &eeprom, data);
ch1010832@1996: 
ch1010832@1996: 	csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
ch1010832@1996: 		   (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
ch1010832@1996: 	for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
ch1010832@1996: 		csum_new += data[i] + (data[i + 1] << 8);
ch1010832@1996: 	csum_new = EEPROM_SUM - csum_new;
ch1010832@1996: 
ch1010832@1996: 	printk(KERN_ERR "/*********************/\n");
ch1010832@1996: 	printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
ch1010832@1996: 	printk(KERN_ERR "Calculated              : 0x%04x\n", csum_new);
ch1010832@1996: 
ch1010832@1996: 	printk(KERN_ERR "Offset    Values\n");
ch1010832@1996: 	printk(KERN_ERR "========  ======\n");
ch1010832@1996: 	print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
ch1010832@1996: 
ch1010832@1996: 	printk(KERN_ERR "Include this output when contacting your support "
ch1010832@1996: 	       "provider.\n");
ch1010832@1996: 	printk(KERN_ERR "This is not a software error! Something bad "
ch1010832@1996: 	       "happened to your hardware or\n");
ch1010832@1996: 	printk(KERN_ERR "EEPROM image. Ignoring this "
ch1010832@1996: 	       "problem could result in further problems,\n");
ch1010832@1996: 	printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
ch1010832@1996: 	printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
ch1010832@1996: 	       "which is invalid\n");
ch1010832@1996: 	printk(KERN_ERR "and requires you to set the proper MAC "
ch1010832@1996: 	       "address manually before continuing\n");
ch1010832@1996: 	printk(KERN_ERR "to enable this network device.\n");
ch1010832@1996: 	printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
ch1010832@1996: 	       "to your hardware vendor\n");
ch1010832@1996: 	printk(KERN_ERR "or Intel Customer Support.\n");
ch1010832@1996: 	printk(KERN_ERR "/*********************/\n");
ch1010832@1996: 
ch1010832@1996: 	kfree(data);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
ch1010832@1996:  * @pdev: PCI device information struct
ch1010832@1996:  *
ch1010832@1996:  * Return true if an adapter needs ioport resources
ch1010832@1996:  **/
ch1010832@1996: static int e1000_is_need_ioport(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	switch (pdev->device) {
ch1010832@1996: 	case E1000_DEV_ID_82540EM:
ch1010832@1996: 	case E1000_DEV_ID_82540EM_LOM:
ch1010832@1996: 	case E1000_DEV_ID_82540EP:
ch1010832@1996: 	case E1000_DEV_ID_82540EP_LOM:
ch1010832@1996: 	case E1000_DEV_ID_82540EP_LP:
ch1010832@1996: 	case E1000_DEV_ID_82541EI:
ch1010832@1996: 	case E1000_DEV_ID_82541EI_MOBILE:
ch1010832@1996: 	case E1000_DEV_ID_82541ER:
ch1010832@1996: 	case E1000_DEV_ID_82541ER_LOM:
ch1010832@1996: 	case E1000_DEV_ID_82541GI:
ch1010832@1996: 	case E1000_DEV_ID_82541GI_LF:
ch1010832@1996: 	case E1000_DEV_ID_82541GI_MOBILE:
ch1010832@1996: 	case E1000_DEV_ID_82544EI_COPPER:
ch1010832@1996: 	case E1000_DEV_ID_82544EI_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82544GC_COPPER:
ch1010832@1996: 	case E1000_DEV_ID_82544GC_LOM:
ch1010832@1996: 	case E1000_DEV_ID_82545EM_COPPER:
ch1010832@1996: 	case E1000_DEV_ID_82545EM_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82546EB_COPPER:
ch1010832@1996: 	case E1000_DEV_ID_82546EB_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82546EB_QUAD_COPPER:
ch1010832@1996: 		return true;
ch1010832@1996: 	default:
ch1010832@1996: 		return false;
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static const struct net_device_ops e1000_netdev_ops = {
ch1010832@1996: 	.ndo_open		= e1000_open,
ch1010832@1996: 	.ndo_stop		= e1000_close,
ch1010832@1996: 	.ndo_start_xmit		= e1000_xmit_frame,
ch1010832@1996: 	.ndo_get_stats		= e1000_get_stats,
ch1010832@1996: 	.ndo_set_rx_mode	= e1000_set_rx_mode,
ch1010832@1996: 	.ndo_set_mac_address	= e1000_set_mac,
ch1010832@1996: 	.ndo_tx_timeout 	= e1000_tx_timeout,
ch1010832@1996: 	.ndo_change_mtu		= e1000_change_mtu,
ch1010832@1996: 	.ndo_do_ioctl		= e1000_ioctl,
ch1010832@1996: 	.ndo_validate_addr	= eth_validate_addr,
ch1010832@1996: 
ch1010832@1996: 	.ndo_vlan_rx_register	= e1000_vlan_rx_register,
ch1010832@1996: 	.ndo_vlan_rx_add_vid	= e1000_vlan_rx_add_vid,
ch1010832@1996: 	.ndo_vlan_rx_kill_vid	= e1000_vlan_rx_kill_vid,
ch1010832@1996: #ifdef CONFIG_NET_POLL_CONTROLLER
ch1010832@1996: 	.ndo_poll_controller	= e1000_netpoll,
ch1010832@1996: #endif
ch1010832@1996: };
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_probe - Device Initialization Routine
ch1010832@1996:  * @pdev: PCI device information struct
ch1010832@1996:  * @ent: entry in e1000_pci_tbl
ch1010832@1996:  *
ch1010832@1996:  * Returns 0 on success, negative on failure
ch1010832@1996:  *
ch1010832@1996:  * e1000_probe initializes an adapter identified by a pci_dev structure.
ch1010832@1996:  * The OS initialization, configuring of the adapter private structure,
ch1010832@1996:  * and a hardware reset occur.
ch1010832@1996:  **/
ch1010832@1996: static int __devinit e1000_probe(struct pci_dev *pdev,
ch1010832@1996: 				 const struct pci_device_id *ent)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev;
ch1010832@1996: 	struct e1000_adapter *adapter;
ch1010832@1996: 	struct e1000_hw *hw;
ch1010832@1996: 
ch1010832@1996: 	static int cards_found = 0;
ch1010832@1996: 	static int global_quad_port_a = 0; /* global ksp3 port a indication */
ch1010832@1996: 	int i, err, pci_using_dac;
ch1010832@1996: 	u16 eeprom_data = 0;
ch1010832@1996: 	u16 eeprom_apme_mask = E1000_EEPROM_APME;
ch1010832@1996: 	int bars, need_ioport;
ch1010832@1996: 
ch1010832@1996: 	/* do not allocate ioport bars when not needed */
ch1010832@1996: 	need_ioport = e1000_is_need_ioport(pdev);
ch1010832@1996: 	if (need_ioport) {
ch1010832@1996: 		bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
ch1010832@1996: 		err = pci_enable_device(pdev);
ch1010832@1996: 	} else {
ch1010832@1996: 		bars = pci_select_bars(pdev, IORESOURCE_MEM);
ch1010832@1996: 		err = pci_enable_device_mem(pdev);
ch1010832@1996: 	}
ch1010832@1996: 	if (err)
ch1010832@1996: 		return err;
ch1010832@1996: 
ch1010832@1996: 	if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
ch1010832@1996: 	    !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
ch1010832@1996: 		pci_using_dac = 1;
ch1010832@1996: 	} else {
ch1010832@1996: 		err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
ch1010832@1996: 		if (err) {
ch1010832@1996: 			err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
ch1010832@1996: 			if (err) {
ch1010832@1996: 				E1000_ERR("No usable DMA configuration, "
ch1010832@1996: 					  "aborting\n");
ch1010832@1996: 				goto err_dma;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 		pci_using_dac = 0;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_pci_reg;
ch1010832@1996: 
ch1010832@1996: 	pci_set_master(pdev);
ch1010832@1996: 
ch1010832@1996: 	err = -ENOMEM;
ch1010832@1996: 	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
ch1010832@1996: 	if (!netdev)
ch1010832@1996: 		goto err_alloc_etherdev;
ch1010832@1996: 
ch1010832@1996: 	SET_NETDEV_DEV(netdev, &pdev->dev);
ch1010832@1996: 
ch1010832@1996: 	pci_set_drvdata(pdev, netdev);
ch1010832@1996: 	adapter = netdev_priv(netdev);
ch1010832@1996: 	adapter->netdev = netdev;
ch1010832@1996: 	adapter->pdev = pdev;
ch1010832@1996: 	adapter->msg_enable = (1 << debug) - 1;
ch1010832@1996: 	adapter->bars = bars;
ch1010832@1996: 	adapter->need_ioport = need_ioport;
ch1010832@1996: 
ch1010832@1996: 	hw = &adapter->hw;
ch1010832@1996: 	hw->back = adapter;
ch1010832@1996: 
ch1010832@1996: 	err = -EIO;
ch1010832@1996: 	hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
ch1010832@1996: 	if (!hw->hw_addr)
ch1010832@1996: 		goto err_ioremap;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->need_ioport) {
ch1010832@1996: 		for (i = BAR_1; i <= BAR_5; i++) {
ch1010832@1996: 			if (pci_resource_len(pdev, i) == 0)
ch1010832@1996: 				continue;
ch1010832@1996: 			if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
ch1010832@1996: 				hw->io_base = pci_resource_start(pdev, i);
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	netdev->netdev_ops = &e1000_netdev_ops;
ch1010832@1996: 	e1000_set_ethtool_ops(netdev);
ch1010832@1996: 	netdev->watchdog_timeo = 5 * HZ;
ch1010832@1996: 	netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
ch1010832@1996: 
ch1010832@1996: 	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
ch1010832@1996: 
ch1010832@1996: 	adapter->bd_number = cards_found;
ch1010832@1996: 
ch1010832@1996: 	/* setup the private structure */
ch1010832@1996: 
ch1010832@1996: 	err = e1000_sw_init(adapter);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_sw_init;
ch1010832@1996: 
ch1010832@1996: 	err = -EIO;
ch1010832@1996: 	/* Flash BAR mapping must happen after e1000_sw_init
ch1010832@1996: 	 * because it depends on mac_type */
ch1010832@1996: 	if ((hw->mac_type == e1000_ich8lan) &&
ch1010832@1996: 	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
ch1010832@1996: 		hw->flash_address = pci_ioremap_bar(pdev, 1);
ch1010832@1996: 		if (!hw->flash_address)
ch1010832@1996: 			goto err_flashmap;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (e1000_check_phy_reset_block(hw))
ch1010832@1996: 		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type >= e1000_82543) {
ch1010832@1996: 		netdev->features = NETIF_F_SG |
ch1010832@1996: 				   NETIF_F_HW_CSUM |
ch1010832@1996: 				   NETIF_F_HW_VLAN_TX |
ch1010832@1996: 				   NETIF_F_HW_VLAN_RX |
ch1010832@1996: 				   NETIF_F_HW_VLAN_FILTER;
ch1010832@1996: 		if (hw->mac_type == e1000_ich8lan)
ch1010832@1996: 			netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if ((hw->mac_type >= e1000_82544) &&
ch1010832@1996: 	   (hw->mac_type != e1000_82547))
ch1010832@1996: 		netdev->features |= NETIF_F_TSO;
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type > e1000_82547_rev_2)
ch1010832@1996: 		netdev->features |= NETIF_F_TSO6;
ch1010832@1996: 	if (pci_using_dac)
ch1010832@1996: 		netdev->features |= NETIF_F_HIGHDMA;
ch1010832@1996: 
ch1010832@1996: 	netdev->vlan_features |= NETIF_F_TSO;
ch1010832@1996: 	netdev->vlan_features |= NETIF_F_TSO6;
ch1010832@1996: 	netdev->vlan_features |= NETIF_F_HW_CSUM;
ch1010832@1996: 	netdev->vlan_features |= NETIF_F_SG;
ch1010832@1996: 
ch1010832@1996: 	adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
ch1010832@1996: 
ch1010832@1996: 	/* initialize eeprom parameters */
ch1010832@1996: 	if (e1000_init_eeprom_params(hw)) {
ch1010832@1996: 		E1000_ERR("EEPROM initialization failed\n");
ch1010832@1996: 		goto err_eeprom;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* before reading the EEPROM, reset the controller to
ch1010832@1996: 	 * put the device in a known good starting state */
ch1010832@1996: 
ch1010832@1996: 	e1000_reset_hw(hw);
ch1010832@1996: 
ch1010832@1996: 	/* make sure the EEPROM is good */
ch1010832@1996: 	if (e1000_validate_eeprom_checksum(hw) < 0) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
ch1010832@1996: 		e1000_dump_eeprom(adapter);
ch1010832@1996: 		/*
ch1010832@1996: 		 * set MAC address to all zeroes to invalidate and temporary
ch1010832@1996: 		 * disable this device for the user. This blocks regular
ch1010832@1996: 		 * traffic while still permitting ethtool ioctls from reaching
ch1010832@1996: 		 * the hardware as well as allowing the user to run the
ch1010832@1996: 		 * interface after manually setting a hw addr using
ch1010832@1996: 		 * `ip set address`
ch1010832@1996: 		 */
ch1010832@1996: 		memset(hw->mac_addr, 0, netdev->addr_len);
ch1010832@1996: 	} else {
ch1010832@1996: 		/* copy the MAC address out of the EEPROM */
ch1010832@1996: 		if (e1000_read_mac_addr(hw))
ch1010832@1996: 			DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
ch1010832@1996: 	}
ch1010832@1996: 	/* don't block initalization here due to bad MAC address */
ch1010832@1996: 	memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
ch1010832@1996: 	memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
ch1010832@1996: 
ch1010832@1996: 	if (!is_valid_ether_addr(netdev->perm_addr))
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
ch1010832@1996: 
ch1010832@1996: 	e1000_get_bus_info(hw);
ch1010832@1996: 
ch1010832@1996: 	init_timer(&adapter->tx_fifo_stall_timer);
ch1010832@1996: 	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
ch1010832@1996: 	adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
ch1010832@1996: 
ch1010832@1996: 	init_timer(&adapter->watchdog_timer);
ch1010832@1996: 	adapter->watchdog_timer.function = &e1000_watchdog;
ch1010832@1996: 	adapter->watchdog_timer.data = (unsigned long) adapter;
ch1010832@1996: 
ch1010832@1996: 	init_timer(&adapter->phy_info_timer);
ch1010832@1996: 	adapter->phy_info_timer.function = &e1000_update_phy_info;
ch1010832@1996: 	adapter->phy_info_timer.data = (unsigned long)adapter;
ch1010832@1996: 
ch1010832@1996: 	INIT_WORK(&adapter->reset_task, e1000_reset_task);
ch1010832@1996: 
ch1010832@1996: 	e1000_check_options(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* Initial Wake on LAN setting
ch1010832@1996: 	 * If APM wake is enabled in the EEPROM,
ch1010832@1996: 	 * enable the ACPI Magic Packet filter
ch1010832@1996: 	 */
ch1010832@1996: 
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_82542_rev2_0:
ch1010832@1996: 	case e1000_82542_rev2_1:
ch1010832@1996: 	case e1000_82543:
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82544:
ch1010832@1996: 		e1000_read_eeprom(hw,
ch1010832@1996: 			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
ch1010832@1996: 		eeprom_apme_mask = E1000_EEPROM_82544_APM;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_ich8lan:
ch1010832@1996: 		e1000_read_eeprom(hw,
ch1010832@1996: 			EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
ch1010832@1996: 		eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82546:
ch1010832@1996: 	case e1000_82546_rev_3:
ch1010832@1996: 	case e1000_82571:
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: 		if (er32(STATUS) & E1000_STATUS_FUNC_1){
ch1010832@1996: 			e1000_read_eeprom(hw,
ch1010832@1996: 				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
ch1010832@1996: 			break;
ch1010832@1996: 		}
ch1010832@1996: 		/* Fall Through */
ch1010832@1996: 	default:
ch1010832@1996: 		e1000_read_eeprom(hw,
ch1010832@1996: 			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 	if (eeprom_data & eeprom_apme_mask)
ch1010832@1996: 		adapter->eeprom_wol |= E1000_WUFC_MAG;
ch1010832@1996: 
ch1010832@1996: 	/* now that we have the eeprom settings, apply the special cases
ch1010832@1996: 	 * where the eeprom may be wrong or the board simply won't support
ch1010832@1996: 	 * wake on lan on a particular port */
ch1010832@1996: 	switch (pdev->device) {
ch1010832@1996: 	case E1000_DEV_ID_82546GB_PCIE:
ch1010832@1996: 		adapter->eeprom_wol = 0;
ch1010832@1996: 		break;
ch1010832@1996: 	case E1000_DEV_ID_82546EB_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82546GB_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82571EB_FIBER:
ch1010832@1996: 		/* Wake events only supported on port A for dual fiber
ch1010832@1996: 		 * regardless of eeprom setting */
ch1010832@1996: 		if (er32(STATUS) & E1000_STATUS_FUNC_1)
ch1010832@1996: 			adapter->eeprom_wol = 0;
ch1010832@1996: 		break;
ch1010832@1996: 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
ch1010832@1996: 	case E1000_DEV_ID_82571EB_QUAD_COPPER:
ch1010832@1996: 	case E1000_DEV_ID_82571EB_QUAD_FIBER:
ch1010832@1996: 	case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
ch1010832@1996: 	case E1000_DEV_ID_82571PT_QUAD_COPPER:
ch1010832@1996: 		/* if quad port adapter, disable WoL on all but port A */
ch1010832@1996: 		if (global_quad_port_a != 0)
ch1010832@1996: 			adapter->eeprom_wol = 0;
ch1010832@1996: 		else
ch1010832@1996: 			adapter->quad_port_a = 1;
ch1010832@1996: 		/* Reset for multiple quad port adapters */
ch1010832@1996: 		if (++global_quad_port_a == 4)
ch1010832@1996: 			global_quad_port_a = 0;
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* initialize the wol settings based on the eeprom settings */
ch1010832@1996: 	adapter->wol = adapter->eeprom_wol;
ch1010832@1996: 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
ch1010832@1996: 
ch1010832@1996: 	/* print bus type/speed/width info */
ch1010832@1996: 	DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
ch1010832@1996: 		((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
ch1010832@1996: 		 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
ch1010832@1996: 		((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
ch1010832@1996: 		 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
ch1010832@1996: 		 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
ch1010832@1996: 		 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
ch1010832@1996: 		 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
ch1010832@1996: 		((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
ch1010832@1996: 		 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
ch1010832@1996: 		 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
ch1010832@1996: 		 "32-bit"));
ch1010832@1996: 
ch1010832@1996: 	printk("%pM\n", netdev->dev_addr);
ch1010832@1996: 
ch1010832@1996: 	if (hw->bus_type == e1000_bus_type_pci_express) {
ch1010832@1996: 		DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
ch1010832@1996: 			"longer be supported by this driver in the future.\n",
ch1010832@1996: 			pdev->vendor, pdev->device);
ch1010832@1996: 		DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
ch1010832@1996: 			"driver instead.\n");
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* reset the hardware with the new settings */
ch1010832@1996: 	e1000_reset(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* If the controller is 82573 and f/w is AMT, do not set
ch1010832@1996: 	 * DRV_LOAD until the interface is up.  For all other cases,
ch1010832@1996: 	 * let the f/w know that the h/w is now under the control
ch1010832@1996: 	 * of the driver. */
ch1010832@1996: 	if (hw->mac_type != e1000_82573 ||
ch1010832@1996: 	    !e1000_check_mng_mode(hw))
ch1010832@1996: 		e1000_get_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	strcpy(netdev->name, "eth%d");
ch1010832@1996: 	err = register_netdev(netdev);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_register;
ch1010832@1996: 
ch1010832@1996: 	/* carrier off reporting is important to ethtool even BEFORE open */
ch1010832@1996: 	netif_carrier_off(netdev);
ch1010832@1996: 
ch1010832@1996: 	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
ch1010832@1996: 
ch1010832@1996: 	cards_found++;
ch1010832@1996: 	return 0;
ch1010832@1996: 
ch1010832@1996: err_register:
ch1010832@1996: 	e1000_release_hw_control(adapter);
ch1010832@1996: err_eeprom:
ch1010832@1996: 	if (!e1000_check_phy_reset_block(hw))
ch1010832@1996: 		e1000_phy_hw_reset(hw);
ch1010832@1996: 
ch1010832@1996: 	if (hw->flash_address)
ch1010832@1996: 		iounmap(hw->flash_address);
ch1010832@1996: err_flashmap:
ch1010832@1996: 	kfree(adapter->tx_ring);
ch1010832@1996: 	kfree(adapter->rx_ring);
ch1010832@1996: err_sw_init:
ch1010832@1996: 	iounmap(hw->hw_addr);
ch1010832@1996: err_ioremap:
ch1010832@1996: 	free_netdev(netdev);
ch1010832@1996: err_alloc_etherdev:
ch1010832@1996: 	pci_release_selected_regions(pdev, bars);
ch1010832@1996: err_pci_reg:
ch1010832@1996: err_dma:
ch1010832@1996: 	pci_disable_device(pdev);
ch1010832@1996: 	return err;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_remove - Device Removal Routine
ch1010832@1996:  * @pdev: PCI device information struct
ch1010832@1996:  *
ch1010832@1996:  * e1000_remove is called by the PCI subsystem to alert the driver
ch1010832@1996:  * that it should release a PCI device.  The could be caused by a
ch1010832@1996:  * Hot-Plug event, or because the driver is going to be removed from
ch1010832@1996:  * memory.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void __devexit e1000_remove(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	cancel_work_sync(&adapter->reset_task);
ch1010832@1996: 
ch1010832@1996: 	e1000_release_manageability(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
ch1010832@1996: 	 * would have already happened in close and is redundant. */
ch1010832@1996: 	e1000_release_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	unregister_netdev(netdev);
ch1010832@1996: 
ch1010832@1996: 	if (!e1000_check_phy_reset_block(hw))
ch1010832@1996: 		e1000_phy_hw_reset(hw);
ch1010832@1996: 
ch1010832@1996: 	kfree(adapter->tx_ring);
ch1010832@1996: 	kfree(adapter->rx_ring);
ch1010832@1996: 
ch1010832@1996: 	iounmap(hw->hw_addr);
ch1010832@1996: 	if (hw->flash_address)
ch1010832@1996: 		iounmap(hw->flash_address);
ch1010832@1996: 	pci_release_selected_regions(pdev, adapter->bars);
ch1010832@1996: 
ch1010832@1996: 	free_netdev(netdev);
ch1010832@1996: 
ch1010832@1996: 	pci_disable_device(pdev);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
ch1010832@1996:  * @adapter: board private structure to initialize
ch1010832@1996:  *
ch1010832@1996:  * e1000_sw_init initializes the Adapter private data structure.
ch1010832@1996:  * Fields are initialized based on PCI device information and
ch1010832@1996:  * OS network device settings (MTU size).
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 
ch1010832@1996: 	/* PCI config space info */
ch1010832@1996: 
ch1010832@1996: 	hw->vendor_id = pdev->vendor;
ch1010832@1996: 	hw->device_id = pdev->device;
ch1010832@1996: 	hw->subsystem_vendor_id = pdev->subsystem_vendor;
ch1010832@1996: 	hw->subsystem_id = pdev->subsystem_device;
ch1010832@1996: 	hw->revision_id = pdev->revision;
ch1010832@1996: 
ch1010832@1996: 	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
ch1010832@1996: 
ch1010832@1996: 	adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
ch1010832@1996: 	hw->max_frame_size = netdev->mtu +
ch1010832@1996: 			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
ch1010832@1996: 	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
ch1010832@1996: 
ch1010832@1996: 	/* identify the MAC */
ch1010832@1996: 
ch1010832@1996: 	if (e1000_set_mac_type(hw)) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
ch1010832@1996: 		return -EIO;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	default:
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82541:
ch1010832@1996: 	case e1000_82547:
ch1010832@1996: 	case e1000_82541_rev_2:
ch1010832@1996: 	case e1000_82547_rev_2:
ch1010832@1996: 		hw->phy_init_script = 1;
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_set_media_type(hw);
ch1010832@1996: 
ch1010832@1996: 	hw->wait_autoneg_complete = false;
ch1010832@1996: 	hw->tbi_compatibility_en = true;
ch1010832@1996: 	hw->adaptive_ifs = true;
ch1010832@1996: 
ch1010832@1996: 	/* Copper options */
ch1010832@1996: 
ch1010832@1996: 	if (hw->media_type == e1000_media_type_copper) {
ch1010832@1996: 		hw->mdix = AUTO_ALL_MODES;
ch1010832@1996: 		hw->disable_polarity_correction = false;
ch1010832@1996: 		hw->master_slave = E1000_MASTER_SLAVE;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	adapter->num_tx_queues = 1;
ch1010832@1996: 	adapter->num_rx_queues = 1;
ch1010832@1996: 
ch1010832@1996: 	if (e1000_alloc_queues(adapter)) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Explicitly disable IRQ since the NIC can be in any state. */
ch1010832@1996: 	e1000_irq_disable(adapter);
ch1010832@1996: 
ch1010832@1996: 	spin_lock_init(&adapter->stats_lock);
ch1010832@1996: 
ch1010832@1996: 	set_bit(__E1000_DOWN, &adapter->flags);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_alloc_queues - Allocate memory for all rings
ch1010832@1996:  * @adapter: board private structure to initialize
ch1010832@1996:  *
ch1010832@1996:  * We allocate one ring per queue at run-time since we don't know the
ch1010832@1996:  * number of queues at compile-time.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	adapter->tx_ring = kcalloc(adapter->num_tx_queues,
ch1010832@1996: 	                           sizeof(struct e1000_tx_ring), GFP_KERNEL);
ch1010832@1996: 	if (!adapter->tx_ring)
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 
ch1010832@1996: 	adapter->rx_ring = kcalloc(adapter->num_rx_queues,
ch1010832@1996: 	                           sizeof(struct e1000_rx_ring), GFP_KERNEL);
ch1010832@1996: 	if (!adapter->rx_ring) {
ch1010832@1996: 		kfree(adapter->tx_ring);
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return E1000_SUCCESS;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_open - Called when a network interface is made active
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  *
ch1010832@1996:  * Returns 0 on success, negative value on failure
ch1010832@1996:  *
ch1010832@1996:  * The open entry point is called when a network interface is made
ch1010832@1996:  * active by the system (IFF_UP).  At this point all resources needed
ch1010832@1996:  * for transmit and receive operations are allocated, the interrupt
ch1010832@1996:  * handler is registered with the OS, the watchdog timer is started,
ch1010832@1996:  * and the stack is notified that the interface is ready.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_open(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	int err;
ch1010832@1996: 
ch1010832@1996: 	/* disallow open during test */
ch1010832@1996: 	if (test_bit(__E1000_TESTING, &adapter->flags))
ch1010832@1996: 		return -EBUSY;
ch1010832@1996: 
ch1010832@1996: 	netif_carrier_off(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* allocate transmit descriptors */
ch1010832@1996: 	err = e1000_setup_all_tx_resources(adapter);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_setup_tx;
ch1010832@1996: 
ch1010832@1996: 	/* allocate receive descriptors */
ch1010832@1996: 	err = e1000_setup_all_rx_resources(adapter);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_setup_rx;
ch1010832@1996: 
ch1010832@1996: 	e1000_power_up_phy(adapter);
ch1010832@1996: 
ch1010832@1996: 	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
ch1010832@1996: 	if ((hw->mng_cookie.status &
ch1010832@1996: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
ch1010832@1996: 		e1000_update_mng_vlan(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* If AMT is enabled, let the firmware know that the network
ch1010832@1996: 	 * interface is now open */
ch1010832@1996: 	if (hw->mac_type == e1000_82573 &&
ch1010832@1996: 	    e1000_check_mng_mode(hw))
ch1010832@1996: 		e1000_get_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* before we allocate an interrupt, we must be ready to handle it.
ch1010832@1996: 	 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
ch1010832@1996: 	 * as soon as we call pci_request_irq, so we have to setup our
ch1010832@1996: 	 * clean_rx handler before we do so.  */
ch1010832@1996: 	e1000_configure(adapter);
ch1010832@1996: 
ch1010832@1996: 	err = e1000_request_irq(adapter);
ch1010832@1996: 	if (err)
ch1010832@1996: 		goto err_req_irq;
ch1010832@1996: 
ch1010832@1996: 	/* From here on the code is the same as e1000_up() */
ch1010832@1996: 	clear_bit(__E1000_DOWN, &adapter->flags);
ch1010832@1996: 
ch1010832@1996: 	napi_enable(&adapter->napi);
ch1010832@1996: 
ch1010832@1996: 	e1000_irq_enable(adapter);
ch1010832@1996: 
ch1010832@1996: 	netif_start_queue(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* fire a link status change interrupt to start the watchdog */
ch1010832@1996: 	ew32(ICS, E1000_ICS_LSC);
ch1010832@1996: 
ch1010832@1996: 	return E1000_SUCCESS;
ch1010832@1996: 
ch1010832@1996: err_req_irq:
ch1010832@1996: 	e1000_release_hw_control(adapter);
ch1010832@1996: 	e1000_power_down_phy(adapter);
ch1010832@1996: 	e1000_free_all_rx_resources(adapter);
ch1010832@1996: err_setup_rx:
ch1010832@1996: 	e1000_free_all_tx_resources(adapter);
ch1010832@1996: err_setup_tx:
ch1010832@1996: 	e1000_reset(adapter);
ch1010832@1996: 
ch1010832@1996: 	return err;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_close - Disables a network interface
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  *
ch1010832@1996:  * Returns 0, this is not allowed to fail
ch1010832@1996:  *
ch1010832@1996:  * The close entry point is called when an interface is de-activated
ch1010832@1996:  * by the OS.  The hardware is still under the drivers control, but
ch1010832@1996:  * needs to be disabled.  A global MAC reset is issued to stop the
ch1010832@1996:  * hardware, and all transmit and receive resources are freed.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_close(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
ch1010832@1996: 	e1000_down(adapter);
ch1010832@1996: 	e1000_power_down_phy(adapter);
ch1010832@1996: 	e1000_free_irq(adapter);
ch1010832@1996: 
ch1010832@1996: 	e1000_free_all_tx_resources(adapter);
ch1010832@1996: 	e1000_free_all_rx_resources(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* kill manageability vlan ID if supported, but not if a vlan with
ch1010832@1996: 	 * the same ID is registered on the host OS (let 8021q kill it) */
ch1010832@1996: 	if ((hw->mng_cookie.status &
ch1010832@1996: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
ch1010832@1996: 	     !(adapter->vlgrp &&
ch1010832@1996: 	       vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
ch1010832@1996: 		e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* If AMT is enabled, let the firmware know that the network
ch1010832@1996: 	 * interface is now closed */
ch1010832@1996: 	if (hw->mac_type == e1000_82573 &&
ch1010832@1996: 	    e1000_check_mng_mode(hw))
ch1010832@1996: 		e1000_release_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
ch1010832@1996:  * @adapter: address of board private structure
ch1010832@1996:  * @start: address of beginning of memory
ch1010832@1996:  * @len: length of memory
ch1010832@1996:  **/
ch1010832@1996: static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
ch1010832@1996: 				  unsigned long len)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	unsigned long begin = (unsigned long)start;
ch1010832@1996: 	unsigned long end = begin + len;
ch1010832@1996: 
ch1010832@1996: 	/* First rev 82545 and 82546 need to not allow any memory
ch1010832@1996: 	 * write location to cross 64k boundary due to errata 23 */
ch1010832@1996: 	if (hw->mac_type == e1000_82545 ||
ch1010832@1996: 	    hw->mac_type == e1000_82546) {
ch1010832@1996: 		return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return true;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @txdr:    tx descriptor ring (for a specific queue) to setup
ch1010832@1996:  *
ch1010832@1996:  * Return 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
ch1010832@1996: 				    struct e1000_tx_ring *txdr)
ch1010832@1996: {
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	int size;
ch1010832@1996: 
ch1010832@1996: 	size = sizeof(struct e1000_buffer) * txdr->count;
ch1010832@1996: 	txdr->buffer_info = vmalloc(size);
ch1010832@1996: 	if (!txdr->buffer_info) {
ch1010832@1996: 		DPRINTK(PROBE, ERR,
ch1010832@1996: 		"Unable to allocate memory for the transmit descriptor ring\n");
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 	memset(txdr->buffer_info, 0, size);
ch1010832@1996: 
ch1010832@1996: 	/* round up to nearest 4K */
ch1010832@1996: 
ch1010832@1996: 	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
ch1010832@1996: 	txdr->size = ALIGN(txdr->size, 4096);
ch1010832@1996: 
ch1010832@1996: 	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
ch1010832@1996: 	if (!txdr->desc) {
ch1010832@1996: setup_tx_desc_die:
ch1010832@1996: 		vfree(txdr->buffer_info);
ch1010832@1996: 		DPRINTK(PROBE, ERR,
ch1010832@1996: 		"Unable to allocate memory for the transmit descriptor ring\n");
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Fix for errata 23, can't cross 64kB boundary */
ch1010832@1996: 	if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
ch1010832@1996: 		void *olddesc = txdr->desc;
ch1010832@1996: 		dma_addr_t olddma = txdr->dma;
ch1010832@1996: 		DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
ch1010832@1996: 				     "at %p\n", txdr->size, txdr->desc);
ch1010832@1996: 		/* Try again, without freeing the previous */
ch1010832@1996: 		txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
ch1010832@1996: 		/* Failed allocation, critical failure */
ch1010832@1996: 		if (!txdr->desc) {
ch1010832@1996: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
ch1010832@1996: 			goto setup_tx_desc_die;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
ch1010832@1996: 			/* give up */
ch1010832@1996: 			pci_free_consistent(pdev, txdr->size, txdr->desc,
ch1010832@1996: 					    txdr->dma);
ch1010832@1996: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
ch1010832@1996: 			DPRINTK(PROBE, ERR,
ch1010832@1996: 				"Unable to allocate aligned memory "
ch1010832@1996: 				"for the transmit descriptor ring\n");
ch1010832@1996: 			vfree(txdr->buffer_info);
ch1010832@1996: 			return -ENOMEM;
ch1010832@1996: 		} else {
ch1010832@1996: 			/* Free old allocation, new allocation was successful */
ch1010832@1996: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 	memset(txdr->desc, 0, txdr->size);
ch1010832@1996: 
ch1010832@1996: 	txdr->next_to_use = 0;
ch1010832@1996: 	txdr->next_to_clean = 0;
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
ch1010832@1996:  * 				  (Descriptors) for all queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Return 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i, err = 0;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_tx_queues; i++) {
ch1010832@1996: 		err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
ch1010832@1996: 		if (err) {
ch1010832@1996: 			DPRINTK(PROBE, ERR,
ch1010832@1996: 				"Allocation for Tx Queue %u failed\n", i);
ch1010832@1996: 			for (i-- ; i >= 0; i--)
ch1010832@1996: 				e1000_free_tx_resources(adapter,
ch1010832@1996: 							&adapter->tx_ring[i]);
ch1010832@1996: 			break;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return err;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Configure the Tx unit of the MAC after a reset.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_configure_tx(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	u64 tdba;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 tdlen, tctl, tipg, tarc;
ch1010832@1996: 	u32 ipgr1, ipgr2;
ch1010832@1996: 
ch1010832@1996: 	/* Setup the HW Tx Head and Tail descriptor pointers */
ch1010832@1996: 
ch1010832@1996: 	switch (adapter->num_tx_queues) {
ch1010832@1996: 	case 1:
ch1010832@1996: 	default:
ch1010832@1996: 		tdba = adapter->tx_ring[0].dma;
ch1010832@1996: 		tdlen = adapter->tx_ring[0].count *
ch1010832@1996: 			sizeof(struct e1000_tx_desc);
ch1010832@1996: 		ew32(TDLEN, tdlen);
ch1010832@1996: 		ew32(TDBAH, (tdba >> 32));
ch1010832@1996: 		ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
ch1010832@1996: 		ew32(TDT, 0);
ch1010832@1996: 		ew32(TDH, 0);
ch1010832@1996: 		adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
ch1010832@1996: 		adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Set the default values for the Tx Inter Packet Gap timer */
ch1010832@1996: 	if (hw->mac_type <= e1000_82547_rev_2 &&
ch1010832@1996: 	    (hw->media_type == e1000_media_type_fiber ||
ch1010832@1996: 	     hw->media_type == e1000_media_type_internal_serdes))
ch1010832@1996: 		tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
ch1010832@1996: 	else
ch1010832@1996: 		tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
ch1010832@1996: 
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_82542_rev2_0:
ch1010832@1996: 	case e1000_82542_rev2_1:
ch1010832@1996: 		tipg = DEFAULT_82542_TIPG_IPGT;
ch1010832@1996: 		ipgr1 = DEFAULT_82542_TIPG_IPGR1;
ch1010832@1996: 		ipgr2 = DEFAULT_82542_TIPG_IPGR2;
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
ch1010832@1996: 		ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
ch1010832@1996: 		ipgr2 = DEFAULT_82543_TIPG_IPGR2;
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 	tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
ch1010832@1996: 	tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
ch1010832@1996: 	ew32(TIPG, tipg);
ch1010832@1996: 
ch1010832@1996: 	/* Set the Tx Interrupt Delay register */
ch1010832@1996: 
ch1010832@1996: 	ew32(TIDV, adapter->tx_int_delay);
ch1010832@1996: 	if (hw->mac_type >= e1000_82540)
ch1010832@1996: 		ew32(TADV, adapter->tx_abs_int_delay);
ch1010832@1996: 
ch1010832@1996: 	/* Program the Transmit Control Register */
ch1010832@1996: 
ch1010832@1996: 	tctl = er32(TCTL);
ch1010832@1996: 	tctl &= ~E1000_TCTL_CT;
ch1010832@1996: 	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
ch1010832@1996: 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
ch1010832@1996: 		tarc = er32(TARC0);
ch1010832@1996: 		/* set the speed mode bit, we'll clear it if we're not at
ch1010832@1996: 		 * gigabit link later */
ch1010832@1996: 		tarc |= (1 << 21);
ch1010832@1996: 		ew32(TARC0, tarc);
ch1010832@1996: 	} else if (hw->mac_type == e1000_80003es2lan) {
ch1010832@1996: 		tarc = er32(TARC0);
ch1010832@1996: 		tarc |= 1;
ch1010832@1996: 		ew32(TARC0, tarc);
ch1010832@1996: 		tarc = er32(TARC1);
ch1010832@1996: 		tarc |= 1;
ch1010832@1996: 		ew32(TARC1, tarc);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_config_collision_dist(hw);
ch1010832@1996: 
ch1010832@1996: 	/* Setup Transmit Descriptor Settings for eop descriptor */
ch1010832@1996: 	adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
ch1010832@1996: 
ch1010832@1996: 	/* only set IDE if we are delaying interrupts using the timers */
ch1010832@1996: 	if (adapter->tx_int_delay)
ch1010832@1996: 		adapter->txd_cmd |= E1000_TXD_CMD_IDE;
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type < e1000_82543)
ch1010832@1996: 		adapter->txd_cmd |= E1000_TXD_CMD_RPS;
ch1010832@1996: 	else
ch1010832@1996: 		adapter->txd_cmd |= E1000_TXD_CMD_RS;
ch1010832@1996: 
ch1010832@1996: 	/* Cache if we're 82544 running in PCI-X because we'll
ch1010832@1996: 	 * need this to apply a workaround later in the send path. */
ch1010832@1996: 	if (hw->mac_type == e1000_82544 &&
ch1010832@1996: 	    hw->bus_type == e1000_bus_type_pcix)
ch1010832@1996: 		adapter->pcix_82544 = 1;
ch1010832@1996: 
ch1010832@1996: 	ew32(TCTL, tctl);
ch1010832@1996: 
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @rxdr:    rx descriptor ring (for a specific queue) to setup
ch1010832@1996:  *
ch1010832@1996:  * Returns 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
ch1010832@1996: 				    struct e1000_rx_ring *rxdr)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	int size, desc_len;
ch1010832@1996: 
ch1010832@1996: 	size = sizeof(struct e1000_buffer) * rxdr->count;
ch1010832@1996: 	rxdr->buffer_info = vmalloc(size);
ch1010832@1996: 	if (!rxdr->buffer_info) {
ch1010832@1996: 		DPRINTK(PROBE, ERR,
ch1010832@1996: 		"Unable to allocate memory for the receive descriptor ring\n");
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 	memset(rxdr->buffer_info, 0, size);
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type <= e1000_82547_rev_2)
ch1010832@1996: 		desc_len = sizeof(struct e1000_rx_desc);
ch1010832@1996: 	else
ch1010832@1996: 		desc_len = sizeof(union e1000_rx_desc_packet_split);
ch1010832@1996: 
ch1010832@1996: 	/* Round up to nearest 4K */
ch1010832@1996: 
ch1010832@1996: 	rxdr->size = rxdr->count * desc_len;
ch1010832@1996: 	rxdr->size = ALIGN(rxdr->size, 4096);
ch1010832@1996: 
ch1010832@1996: 	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
ch1010832@1996: 
ch1010832@1996: 	if (!rxdr->desc) {
ch1010832@1996: 		DPRINTK(PROBE, ERR,
ch1010832@1996: 		"Unable to allocate memory for the receive descriptor ring\n");
ch1010832@1996: setup_rx_desc_die:
ch1010832@1996: 		vfree(rxdr->buffer_info);
ch1010832@1996: 		return -ENOMEM;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Fix for errata 23, can't cross 64kB boundary */
ch1010832@1996: 	if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
ch1010832@1996: 		void *olddesc = rxdr->desc;
ch1010832@1996: 		dma_addr_t olddma = rxdr->dma;
ch1010832@1996: 		DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
ch1010832@1996: 				     "at %p\n", rxdr->size, rxdr->desc);
ch1010832@1996: 		/* Try again, without freeing the previous */
ch1010832@1996: 		rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
ch1010832@1996: 		/* Failed allocation, critical failure */
ch1010832@1996: 		if (!rxdr->desc) {
ch1010832@1996: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
ch1010832@1996: 			DPRINTK(PROBE, ERR,
ch1010832@1996: 				"Unable to allocate memory "
ch1010832@1996: 				"for the receive descriptor ring\n");
ch1010832@1996: 			goto setup_rx_desc_die;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
ch1010832@1996: 			/* give up */
ch1010832@1996: 			pci_free_consistent(pdev, rxdr->size, rxdr->desc,
ch1010832@1996: 					    rxdr->dma);
ch1010832@1996: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
ch1010832@1996: 			DPRINTK(PROBE, ERR,
ch1010832@1996: 				"Unable to allocate aligned memory "
ch1010832@1996: 				"for the receive descriptor ring\n");
ch1010832@1996: 			goto setup_rx_desc_die;
ch1010832@1996: 		} else {
ch1010832@1996: 			/* Free old allocation, new allocation was successful */
ch1010832@1996: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 	memset(rxdr->desc, 0, rxdr->size);
ch1010832@1996: 
ch1010832@1996: 	rxdr->next_to_clean = 0;
ch1010832@1996: 	rxdr->next_to_use = 0;
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
ch1010832@1996:  * 				  (Descriptors) for all queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Return 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i, err = 0;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_rx_queues; i++) {
ch1010832@1996: 		err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
ch1010832@1996: 		if (err) {
ch1010832@1996: 			DPRINTK(PROBE, ERR,
ch1010832@1996: 				"Allocation for Rx Queue %u failed\n", i);
ch1010832@1996: 			for (i-- ; i >= 0; i--)
ch1010832@1996: 				e1000_free_rx_resources(adapter,
ch1010832@1996: 							&adapter->rx_ring[i]);
ch1010832@1996: 			break;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return err;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_setup_rctl - configure the receive control registers
ch1010832@1996:  * @adapter: Board private structure
ch1010832@1996:  **/
ch1010832@1996: static void e1000_setup_rctl(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 rctl;
ch1010832@1996: 
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 
ch1010832@1996: 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
ch1010832@1996: 
ch1010832@1996: 	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
ch1010832@1996: 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
ch1010832@1996: 		(hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
ch1010832@1996: 
ch1010832@1996: 	if (hw->tbi_compatibility_on == 1)
ch1010832@1996: 		rctl |= E1000_RCTL_SBP;
ch1010832@1996: 	else
ch1010832@1996: 		rctl &= ~E1000_RCTL_SBP;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->netdev->mtu <= ETH_DATA_LEN)
ch1010832@1996: 		rctl &= ~E1000_RCTL_LPE;
ch1010832@1996: 	else
ch1010832@1996: 		rctl |= E1000_RCTL_LPE;
ch1010832@1996: 
ch1010832@1996: 	/* Setup buffer sizes */
ch1010832@1996: 	rctl &= ~E1000_RCTL_SZ_4096;
ch1010832@1996: 	rctl |= E1000_RCTL_BSEX;
ch1010832@1996: 	switch (adapter->rx_buffer_len) {
ch1010832@1996: 		case E1000_RXBUFFER_256:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_256;
ch1010832@1996: 			rctl &= ~E1000_RCTL_BSEX;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_512:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_512;
ch1010832@1996: 			rctl &= ~E1000_RCTL_BSEX;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_1024:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_1024;
ch1010832@1996: 			rctl &= ~E1000_RCTL_BSEX;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_2048:
ch1010832@1996: 		default:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_2048;
ch1010832@1996: 			rctl &= ~E1000_RCTL_BSEX;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_4096:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_4096;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_8192:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_8192;
ch1010832@1996: 			break;
ch1010832@1996: 		case E1000_RXBUFFER_16384:
ch1010832@1996: 			rctl |= E1000_RCTL_SZ_16384;
ch1010832@1996: 			break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	ew32(RCTL, rctl);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_configure_rx - Configure 8254x Receive Unit after Reset
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Configure the Rx unit of the MAC after a reset.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_configure_rx(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	u64 rdba;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 rdlen, rctl, rxcsum, ctrl_ext;
ch1010832@1996: 
ch1010832@1996: 	rdlen = adapter->rx_ring[0].count *
ch1010832@1996: 		sizeof(struct e1000_rx_desc);
ch1010832@1996: 	adapter->clean_rx = e1000_clean_rx_irq;
ch1010832@1996: 	adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
ch1010832@1996: 
ch1010832@1996: 	/* disable receives while setting up the descriptors */
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 	ew32(RCTL, rctl & ~E1000_RCTL_EN);
ch1010832@1996: 
ch1010832@1996: 	/* set the Receive Delay Timer Register */
ch1010832@1996: 	ew32(RDTR, adapter->rx_int_delay);
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type >= e1000_82540) {
ch1010832@1996: 		ew32(RADV, adapter->rx_abs_int_delay);
ch1010832@1996: 		if (adapter->itr_setting != 0)
ch1010832@1996: 			ew32(ITR, 1000000000 / (adapter->itr * 256));
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type >= e1000_82571) {
ch1010832@1996: 		ctrl_ext = er32(CTRL_EXT);
ch1010832@1996: 		/* Reset delay timers after every interrupt */
ch1010832@1996: 		ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
ch1010832@1996: 		/* Auto-Mask interrupts upon ICR access */
ch1010832@1996: 		ctrl_ext |= E1000_CTRL_EXT_IAME;
ch1010832@1996: 		ew32(IAM, 0xffffffff);
ch1010832@1996: 		ew32(CTRL_EXT, ctrl_ext);
ch1010832@1996: 		E1000_WRITE_FLUSH();
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Setup the HW Rx Head and Tail Descriptor Pointers and
ch1010832@1996: 	 * the Base and Length of the Rx Descriptor Ring */
ch1010832@1996: 	switch (adapter->num_rx_queues) {
ch1010832@1996: 	case 1:
ch1010832@1996: 	default:
ch1010832@1996: 		rdba = adapter->rx_ring[0].dma;
ch1010832@1996: 		ew32(RDLEN, rdlen);
ch1010832@1996: 		ew32(RDBAH, (rdba >> 32));
ch1010832@1996: 		ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
ch1010832@1996: 		ew32(RDT, 0);
ch1010832@1996: 		ew32(RDH, 0);
ch1010832@1996: 		adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
ch1010832@1996: 		adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Enable 82543 Receive Checksum Offload for TCP and UDP */
ch1010832@1996: 	if (hw->mac_type >= e1000_82543) {
ch1010832@1996: 		rxcsum = er32(RXCSUM);
ch1010832@1996: 		if (adapter->rx_csum)
ch1010832@1996: 			rxcsum |= E1000_RXCSUM_TUOFL;
ch1010832@1996: 		else
ch1010832@1996: 			/* don't need to clear IPPCSE as it defaults to 0 */
ch1010832@1996: 			rxcsum &= ~E1000_RXCSUM_TUOFL;
ch1010832@1996: 		ew32(RXCSUM, rxcsum);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Enable Receives */
ch1010832@1996: 	ew32(RCTL, rctl);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_free_tx_resources - Free Tx Resources per Queue
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @tx_ring: Tx descriptor ring for a specific queue
ch1010832@1996:  *
ch1010832@1996:  * Free all transmit software resources
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_free_tx_resources(struct e1000_adapter *adapter,
ch1010832@1996: 				    struct e1000_tx_ring *tx_ring)
ch1010832@1996: {
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 
ch1010832@1996: 	e1000_clean_tx_ring(adapter, tx_ring);
ch1010832@1996: 
ch1010832@1996: 	vfree(tx_ring->buffer_info);
ch1010832@1996: 	tx_ring->buffer_info = NULL;
ch1010832@1996: 
ch1010832@1996: 	pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
ch1010832@1996: 
ch1010832@1996: 	tx_ring->desc = NULL;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_free_all_tx_resources - Free Tx Resources for All Queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Free all transmit software resources
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_tx_queues; i++)
ch1010832@1996: 		e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
ch1010832@1996: 					     struct e1000_buffer *buffer_info)
ch1010832@1996: {
ch1010832@1996: 	buffer_info->dma = 0;
ch1010832@1996: 	if (buffer_info->skb) {
ch1010832@1996: 		skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
ch1010832@1996: 		              DMA_TO_DEVICE);
ch1010832@1996: 		dev_kfree_skb_any(buffer_info->skb);
ch1010832@1996: 		buffer_info->skb = NULL;
ch1010832@1996: 	}
ch1010832@1996: 	buffer_info->time_stamp = 0;
ch1010832@1996: 	/* buffer_info must be completely set up in the transmit path */
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_tx_ring - Free Tx Buffers
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @tx_ring: ring to be cleaned
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
ch1010832@1996: 				struct e1000_tx_ring *tx_ring)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	unsigned long size;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 
ch1010832@1996: 	/* Free all the Tx ring sk_buffs */
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < tx_ring->count; i++) {
ch1010832@1996: 		buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 		e1000_unmap_and_free_tx_resource(adapter, buffer_info);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	size = sizeof(struct e1000_buffer) * tx_ring->count;
ch1010832@1996: 	memset(tx_ring->buffer_info, 0, size);
ch1010832@1996: 
ch1010832@1996: 	/* Zero out the descriptor ring */
ch1010832@1996: 
ch1010832@1996: 	memset(tx_ring->desc, 0, tx_ring->size);
ch1010832@1996: 
ch1010832@1996: 	tx_ring->next_to_use = 0;
ch1010832@1996: 	tx_ring->next_to_clean = 0;
ch1010832@1996: 	tx_ring->last_tx_tso = 0;
ch1010832@1996: 
ch1010832@1996: 	writel(0, hw->hw_addr + tx_ring->tdh);
ch1010832@1996: 	writel(0, hw->hw_addr + tx_ring->tdt);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_tx_queues; i++)
ch1010832@1996: 		e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_free_rx_resources - Free Rx Resources
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @rx_ring: ring to clean the resources from
ch1010832@1996:  *
ch1010832@1996:  * Free all receive software resources
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_free_rx_resources(struct e1000_adapter *adapter,
ch1010832@1996: 				    struct e1000_rx_ring *rx_ring)
ch1010832@1996: {
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 
ch1010832@1996: 	e1000_clean_rx_ring(adapter, rx_ring);
ch1010832@1996: 
ch1010832@1996: 	vfree(rx_ring->buffer_info);
ch1010832@1996: 	rx_ring->buffer_info = NULL;
ch1010832@1996: 
ch1010832@1996: 	pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
ch1010832@1996: 
ch1010832@1996: 	rx_ring->desc = NULL;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_free_all_rx_resources - Free Rx Resources for All Queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  *
ch1010832@1996:  * Free all receive software resources
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_rx_queues; i++)
ch1010832@1996: 		e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_rx_ring - Free Rx Buffers per Queue
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  * @rx_ring: ring to free buffers from
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
ch1010832@1996: 				struct e1000_rx_ring *rx_ring)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	unsigned long size;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 
ch1010832@1996: 	/* Free all the Rx ring sk_buffs */
ch1010832@1996: 	for (i = 0; i < rx_ring->count; i++) {
ch1010832@1996: 		buffer_info = &rx_ring->buffer_info[i];
ch1010832@1996: 		if (buffer_info->dma) {
ch1010832@1996: 			pci_unmap_single(pdev,
ch1010832@1996: 					 buffer_info->dma,
ch1010832@1996: 					 buffer_info->length,
ch1010832@1996: 					 PCI_DMA_FROMDEVICE);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		buffer_info->dma = 0;
ch1010832@1996: 
ch1010832@1996: 		if (buffer_info->skb) {
ch1010832@1996: 			dev_kfree_skb(buffer_info->skb);
ch1010832@1996: 			buffer_info->skb = NULL;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	size = sizeof(struct e1000_buffer) * rx_ring->count;
ch1010832@1996: 	memset(rx_ring->buffer_info, 0, size);
ch1010832@1996: 
ch1010832@1996: 	/* Zero out the descriptor ring */
ch1010832@1996: 
ch1010832@1996: 	memset(rx_ring->desc, 0, rx_ring->size);
ch1010832@1996: 
ch1010832@1996: 	rx_ring->next_to_clean = 0;
ch1010832@1996: 	rx_ring->next_to_use = 0;
ch1010832@1996: 
ch1010832@1996: 	writel(0, hw->hw_addr + rx_ring->rdh);
ch1010832@1996: 	writel(0, hw->hw_addr + rx_ring->rdt);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	int i;
ch1010832@1996: 
ch1010832@1996: 	for (i = 0; i < adapter->num_rx_queues; i++)
ch1010832@1996: 		e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
ch1010832@1996:  * and memory write and invalidate disabled for certain operations
ch1010832@1996:  */
ch1010832@1996: static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	u32 rctl;
ch1010832@1996: 
ch1010832@1996: 	e1000_pci_clear_mwi(hw);
ch1010832@1996: 
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 	rctl |= E1000_RCTL_RST;
ch1010832@1996: 	ew32(RCTL, rctl);
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: 	mdelay(5);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev))
ch1010832@1996: 		e1000_clean_all_rx_rings(adapter);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	u32 rctl;
ch1010832@1996: 
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 	rctl &= ~E1000_RCTL_RST;
ch1010832@1996: 	ew32(RCTL, rctl);
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: 	mdelay(5);
ch1010832@1996: 
ch1010832@1996: 	if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
ch1010832@1996: 		e1000_pci_set_mwi(hw);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev)) {
ch1010832@1996: 		/* No need to loop, because 82542 supports only 1 queue */
ch1010832@1996: 		struct e1000_rx_ring *ring = &adapter->rx_ring[0];
ch1010832@1996: 		e1000_configure_rx(adapter);
ch1010832@1996: 		adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_set_mac - Change the Ethernet Address of the NIC
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  * @p: pointer to an address structure
ch1010832@1996:  *
ch1010832@1996:  * Returns 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_set_mac(struct net_device *netdev, void *p)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct sockaddr *addr = p;
ch1010832@1996: 
ch1010832@1996: 	if (!is_valid_ether_addr(addr->sa_data))
ch1010832@1996: 		return -EADDRNOTAVAIL;
ch1010832@1996: 
ch1010832@1996: 	/* 82542 2.0 needs to be in reset to write receive address registers */
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82542_rev2_0)
ch1010832@1996: 		e1000_enter_82542_rst(adapter);
ch1010832@1996: 
ch1010832@1996: 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
ch1010832@1996: 	memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
ch1010832@1996: 
ch1010832@1996: 	e1000_rar_set(hw, hw->mac_addr, 0);
ch1010832@1996: 
ch1010832@1996: 	/* With 82571 controllers, LAA may be overwritten (with the default)
ch1010832@1996: 	 * due to controller reset from the other port. */
ch1010832@1996: 	if (hw->mac_type == e1000_82571) {
ch1010832@1996: 		/* activate the work around */
ch1010832@1996: 		hw->laa_is_present = 1;
ch1010832@1996: 
ch1010832@1996: 		/* Hold a copy of the LAA in RAR[14] This is done so that
ch1010832@1996: 		 * between the time RAR[0] gets clobbered  and the time it
ch1010832@1996: 		 * gets fixed (in e1000_watchdog), the actual LAA is in one
ch1010832@1996: 		 * of the RARs and no incoming packets directed to this port
ch1010832@1996: 		 * are dropped. Eventaully the LAA will be in RAR[0] and
ch1010832@1996: 		 * RAR[14] */
ch1010832@1996: 		e1000_rar_set(hw, hw->mac_addr,
ch1010832@1996: 					E1000_RAR_ENTRIES - 1);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82542_rev2_0)
ch1010832@1996: 		e1000_leave_82542_rst(adapter);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  *
ch1010832@1996:  * The set_rx_mode entry point is called whenever the unicast or multicast
ch1010832@1996:  * address lists or the network interface flags are updated. This routine is
ch1010832@1996:  * responsible for configuring the hardware for proper unicast, multicast,
ch1010832@1996:  * promiscuous mode, and all-multi behavior.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_set_rx_mode(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct netdev_hw_addr *ha;
ch1010832@1996: 	bool use_uc = false;
ch1010832@1996: 	struct dev_addr_list *mc_ptr;
ch1010832@1996: 	u32 rctl;
ch1010832@1996: 	u32 hash_value;
ch1010832@1996: 	int i, rar_entries = E1000_RAR_ENTRIES;
ch1010832@1996: 	int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
ch1010832@1996: 				E1000_NUM_MTA_REGISTERS_ICH8LAN :
ch1010832@1996: 				E1000_NUM_MTA_REGISTERS;
ch1010832@1996: 	u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
ch1010832@1996: 
ch1010832@1996: 	if (!mcarray) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "memory allocation failed\n");
ch1010832@1996: 		return;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_ich8lan)
ch1010832@1996: 		rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
ch1010832@1996: 
ch1010832@1996: 	/* reserve RAR[14] for LAA over-write work-around */
ch1010832@1996: 	if (hw->mac_type == e1000_82571)
ch1010832@1996: 		rar_entries--;
ch1010832@1996: 
ch1010832@1996: 	/* Check for Promiscuous and All Multicast modes */
ch1010832@1996: 
ch1010832@1996: 	rctl = er32(RCTL);
ch1010832@1996: 
ch1010832@1996: 	if (netdev->flags & IFF_PROMISC) {
ch1010832@1996: 		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
ch1010832@1996: 		rctl &= ~E1000_RCTL_VFE;
ch1010832@1996: 	} else {
ch1010832@1996: 		if (netdev->flags & IFF_ALLMULTI) {
ch1010832@1996: 			rctl |= E1000_RCTL_MPE;
ch1010832@1996: 		} else {
ch1010832@1996: 			rctl &= ~E1000_RCTL_MPE;
ch1010832@1996: 		}
ch1010832@1996: 		if (adapter->hw.mac_type != e1000_ich8lan)
ch1010832@1996: 			rctl |= E1000_RCTL_VFE;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (netdev->uc.count > rar_entries - 1) {
ch1010832@1996: 		rctl |= E1000_RCTL_UPE;
ch1010832@1996: 	} else if (!(netdev->flags & IFF_PROMISC)) {
ch1010832@1996: 		rctl &= ~E1000_RCTL_UPE;
ch1010832@1996: 		use_uc = true;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	ew32(RCTL, rctl);
ch1010832@1996: 
ch1010832@1996: 	/* 82542 2.0 needs to be in reset to write receive address registers */
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82542_rev2_0)
ch1010832@1996: 		e1000_enter_82542_rst(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* load the first 14 addresses into the exact filters 1-14. Unicast
ch1010832@1996: 	 * addresses take precedence to avoid disabling unicast filtering
ch1010832@1996: 	 * when possible.
ch1010832@1996: 	 *
ch1010832@1996: 	 * RAR 0 is used for the station MAC adddress
ch1010832@1996: 	 * if there are not 14 addresses, go ahead and clear the filters
ch1010832@1996: 	 * -- with 82571 controllers only 0-13 entries are filled here
ch1010832@1996: 	 */
ch1010832@1996: 	i = 1;
ch1010832@1996: 	if (use_uc)
ch1010832@1996: 		list_for_each_entry(ha, &netdev->uc.list, list) {
ch1010832@1996: 			if (i == rar_entries)
ch1010832@1996: 				break;
ch1010832@1996: 			e1000_rar_set(hw, ha->addr, i++);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 	WARN_ON(i == rar_entries);
ch1010832@1996: 
ch1010832@1996: 	mc_ptr = netdev->mc_list;
ch1010832@1996: 
ch1010832@1996: 	for (; i < rar_entries; i++) {
ch1010832@1996: 		if (mc_ptr) {
ch1010832@1996: 			e1000_rar_set(hw, mc_ptr->da_addr, i);
ch1010832@1996: 			mc_ptr = mc_ptr->next;
ch1010832@1996: 		} else {
ch1010832@1996: 			E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
ch1010832@1996: 			E1000_WRITE_FLUSH();
ch1010832@1996: 			E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
ch1010832@1996: 			E1000_WRITE_FLUSH();
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* load any remaining addresses into the hash table */
ch1010832@1996: 
ch1010832@1996: 	for (; mc_ptr; mc_ptr = mc_ptr->next) {
ch1010832@1996: 		u32 hash_reg, hash_bit, mta;
ch1010832@1996: 		hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
ch1010832@1996: 		hash_reg = (hash_value >> 5) & 0x7F;
ch1010832@1996: 		hash_bit = hash_value & 0x1F;
ch1010832@1996: 		mta = (1 << hash_bit);
ch1010832@1996: 		mcarray[hash_reg] |= mta;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* write the hash table completely, write from bottom to avoid
ch1010832@1996: 	 * both stupid write combining chipsets, and flushing each write */
ch1010832@1996: 	for (i = mta_reg_count - 1; i >= 0 ; i--) {
ch1010832@1996: 		/*
ch1010832@1996: 		 * If we are on an 82544 has an errata where writing odd
ch1010832@1996: 		 * offsets overwrites the previous even offset, but writing
ch1010832@1996: 		 * backwards over the range solves the issue by always
ch1010832@1996: 		 * writing the odd offset first
ch1010832@1996: 		 */
ch1010832@1996: 		E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
ch1010832@1996: 	}
ch1010832@1996: 	E1000_WRITE_FLUSH();
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82542_rev2_0)
ch1010832@1996: 		e1000_leave_82542_rst(adapter);
ch1010832@1996: 
ch1010832@1996: 	kfree(mcarray);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /* Need to wait a few seconds after link up to get diagnostic information from
ch1010832@1996:  * the phy */
ch1010832@1996: 
ch1010832@1996: static void e1000_update_phy_info(unsigned long data)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = (struct e1000_adapter *)data;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	e1000_phy_get_info(hw, &adapter->phy_info);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_82547_tx_fifo_stall - Timer Call-back
ch1010832@1996:  * @data: pointer to adapter cast into an unsigned long
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_82547_tx_fifo_stall(unsigned long data)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = (struct e1000_adapter *)data;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	u32 tctl;
ch1010832@1996: 
ch1010832@1996: 	if (atomic_read(&adapter->tx_fifo_stall)) {
ch1010832@1996: 		if ((er32(TDT) == er32(TDH)) &&
ch1010832@1996: 		   (er32(TDFT) == er32(TDFH)) &&
ch1010832@1996: 		   (er32(TDFTS) == er32(TDFHS))) {
ch1010832@1996: 			tctl = er32(TCTL);
ch1010832@1996: 			ew32(TCTL, tctl & ~E1000_TCTL_EN);
ch1010832@1996: 			ew32(TDFT, adapter->tx_head_addr);
ch1010832@1996: 			ew32(TDFH, adapter->tx_head_addr);
ch1010832@1996: 			ew32(TDFTS, adapter->tx_head_addr);
ch1010832@1996: 			ew32(TDFHS, adapter->tx_head_addr);
ch1010832@1996: 			ew32(TCTL, tctl);
ch1010832@1996: 			E1000_WRITE_FLUSH();
ch1010832@1996: 
ch1010832@1996: 			adapter->tx_fifo_head = 0;
ch1010832@1996: 			atomic_set(&adapter->tx_fifo_stall, 0);
ch1010832@1996: 			netif_wake_queue(netdev);
ch1010832@1996: 		} else {
ch1010832@1996: 			mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_watchdog - Timer Call-back
ch1010832@1996:  * @data: pointer to adapter cast into an unsigned long
ch1010832@1996:  **/
ch1010832@1996: static void e1000_watchdog(unsigned long data)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = (struct e1000_adapter *)data;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct e1000_tx_ring *txdr = adapter->tx_ring;
ch1010832@1996: 	u32 link, tctl;
ch1010832@1996: 	s32 ret_val;
ch1010832@1996: 
ch1010832@1996: 	ret_val = e1000_check_for_link(hw);
ch1010832@1996: 	if ((ret_val == E1000_ERR_PHY) &&
ch1010832@1996: 	    (hw->phy_type == e1000_phy_igp_3) &&
ch1010832@1996: 	    (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
ch1010832@1996: 		/* See e1000_kumeran_lock_loss_workaround() */
ch1010832@1996: 		DPRINTK(LINK, INFO,
ch1010832@1996: 			"Gigabit has been disabled, downgrading speed\n");
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type == e1000_82573) {
ch1010832@1996: 		e1000_enable_tx_pkt_filtering(hw);
ch1010832@1996: 		if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
ch1010832@1996: 			e1000_update_mng_vlan(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if ((hw->media_type == e1000_media_type_internal_serdes) &&
ch1010832@1996: 	   !(er32(TXCW) & E1000_TXCW_ANE))
ch1010832@1996: 		link = !hw->serdes_link_down;
ch1010832@1996: 	else
ch1010832@1996: 		link = er32(STATUS) & E1000_STATUS_LU;
ch1010832@1996: 
ch1010832@1996: 	if (link) {
ch1010832@1996: 		if (!netif_carrier_ok(netdev)) {
ch1010832@1996: 			u32 ctrl;
ch1010832@1996: 			bool txb2b = true;
ch1010832@1996: 			e1000_get_speed_and_duplex(hw,
ch1010832@1996: 			                           &adapter->link_speed,
ch1010832@1996: 			                           &adapter->link_duplex);
ch1010832@1996: 
ch1010832@1996: 			ctrl = er32(CTRL);
ch1010832@1996: 			printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, "
ch1010832@1996: 			       "Flow Control: %s\n",
ch1010832@1996: 			       netdev->name,
ch1010832@1996: 			       adapter->link_speed,
ch1010832@1996: 			       adapter->link_duplex == FULL_DUPLEX ?
ch1010832@1996: 			        "Full Duplex" : "Half Duplex",
ch1010832@1996: 			        ((ctrl & E1000_CTRL_TFCE) && (ctrl &
ch1010832@1996: 			        E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
ch1010832@1996: 			        E1000_CTRL_RFCE) ? "RX" : ((ctrl &
ch1010832@1996: 			        E1000_CTRL_TFCE) ? "TX" : "None" )));
ch1010832@1996: 
ch1010832@1996: 			/* tweak tx_queue_len according to speed/duplex
ch1010832@1996: 			 * and adjust the timeout factor */
ch1010832@1996: 			netdev->tx_queue_len = adapter->tx_queue_len;
ch1010832@1996: 			adapter->tx_timeout_factor = 1;
ch1010832@1996: 			switch (adapter->link_speed) {
ch1010832@1996: 			case SPEED_10:
ch1010832@1996: 				txb2b = false;
ch1010832@1996: 				netdev->tx_queue_len = 10;
ch1010832@1996: 				adapter->tx_timeout_factor = 8;
ch1010832@1996: 				break;
ch1010832@1996: 			case SPEED_100:
ch1010832@1996: 				txb2b = false;
ch1010832@1996: 				netdev->tx_queue_len = 100;
ch1010832@1996: 				/* maybe add some timeout factor ? */
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			if ((hw->mac_type == e1000_82571 ||
ch1010832@1996: 			     hw->mac_type == e1000_82572) &&
ch1010832@1996: 			    !txb2b) {
ch1010832@1996: 				u32 tarc0;
ch1010832@1996: 				tarc0 = er32(TARC0);
ch1010832@1996: 				tarc0 &= ~(1 << 21);
ch1010832@1996: 				ew32(TARC0, tarc0);
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			/* disable TSO for pcie and 10/100 speeds, to avoid
ch1010832@1996: 			 * some hardware issues */
ch1010832@1996: 			if (!adapter->tso_force &&
ch1010832@1996: 			    hw->bus_type == e1000_bus_type_pci_express){
ch1010832@1996: 				switch (adapter->link_speed) {
ch1010832@1996: 				case SPEED_10:
ch1010832@1996: 				case SPEED_100:
ch1010832@1996: 					DPRINTK(PROBE,INFO,
ch1010832@1996: 				        "10/100 speed: disabling TSO\n");
ch1010832@1996: 					netdev->features &= ~NETIF_F_TSO;
ch1010832@1996: 					netdev->features &= ~NETIF_F_TSO6;
ch1010832@1996: 					break;
ch1010832@1996: 				case SPEED_1000:
ch1010832@1996: 					netdev->features |= NETIF_F_TSO;
ch1010832@1996: 					netdev->features |= NETIF_F_TSO6;
ch1010832@1996: 					break;
ch1010832@1996: 				default:
ch1010832@1996: 					/* oops */
ch1010832@1996: 					break;
ch1010832@1996: 				}
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			/* enable transmits in the hardware, need to do this
ch1010832@1996: 			 * after setting TARC0 */
ch1010832@1996: 			tctl = er32(TCTL);
ch1010832@1996: 			tctl |= E1000_TCTL_EN;
ch1010832@1996: 			ew32(TCTL, tctl);
ch1010832@1996: 
ch1010832@1996: 			netif_carrier_on(netdev);
ch1010832@1996: 			mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
ch1010832@1996: 			adapter->smartspeed = 0;
ch1010832@1996: 		} else {
ch1010832@1996: 			/* make sure the receive unit is started */
ch1010832@1996: 			if (hw->rx_needs_kicking) {
ch1010832@1996: 				u32 rctl = er32(RCTL);
ch1010832@1996: 				ew32(RCTL, rctl | E1000_RCTL_EN);
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	} else {
ch1010832@1996: 		if (netif_carrier_ok(netdev)) {
ch1010832@1996: 			adapter->link_speed = 0;
ch1010832@1996: 			adapter->link_duplex = 0;
ch1010832@1996: 			printk(KERN_INFO "e1000: %s NIC Link is Down\n",
ch1010832@1996: 			       netdev->name);
ch1010832@1996: 			netif_carrier_off(netdev);
ch1010832@1996: 			mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
ch1010832@1996: 
ch1010832@1996: 			/* 80003ES2LAN workaround--
ch1010832@1996: 			 * For packet buffer work-around on link down event;
ch1010832@1996: 			 * disable receives in the ISR and
ch1010832@1996: 			 * reset device here in the watchdog
ch1010832@1996: 			 */
ch1010832@1996: 			if (hw->mac_type == e1000_80003es2lan)
ch1010832@1996: 				/* reset device */
ch1010832@1996: 				schedule_work(&adapter->reset_task);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		e1000_smartspeed(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_update_stats(adapter);
ch1010832@1996: 
ch1010832@1996: 	hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
ch1010832@1996: 	adapter->tpt_old = adapter->stats.tpt;
ch1010832@1996: 	hw->collision_delta = adapter->stats.colc - adapter->colc_old;
ch1010832@1996: 	adapter->colc_old = adapter->stats.colc;
ch1010832@1996: 
ch1010832@1996: 	adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
ch1010832@1996: 	adapter->gorcl_old = adapter->stats.gorcl;
ch1010832@1996: 	adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
ch1010832@1996: 	adapter->gotcl_old = adapter->stats.gotcl;
ch1010832@1996: 
ch1010832@1996: 	e1000_update_adaptive(hw);
ch1010832@1996: 
ch1010832@1996: 	if (!netif_carrier_ok(netdev)) {
ch1010832@1996: 		if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
ch1010832@1996: 			/* We've lost link, so the controller stops DMA,
ch1010832@1996: 			 * but we've got queued Tx work that's never going
ch1010832@1996: 			 * to get done, so reset controller to flush Tx.
ch1010832@1996: 			 * (Do the reset outside of interrupt context). */
ch1010832@1996: 			adapter->tx_timeout_count++;
ch1010832@1996: 			schedule_work(&adapter->reset_task);
ch1010832@1996: 			/* return immediately since reset is imminent */
ch1010832@1996: 			return;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Cause software interrupt to ensure rx ring is cleaned */
ch1010832@1996: 	ew32(ICS, E1000_ICS_RXDMT0);
ch1010832@1996: 
ch1010832@1996: 	/* Force detection of hung controller every watchdog period */
ch1010832@1996: 	adapter->detect_tx_hung = true;
ch1010832@1996: 
ch1010832@1996: 	/* With 82571 controllers, LAA may be overwritten due to controller
ch1010832@1996: 	 * reset from the other port. Set the appropriate LAA in RAR[0] */
ch1010832@1996: 	if (hw->mac_type == e1000_82571 && hw->laa_is_present)
ch1010832@1996: 		e1000_rar_set(hw, hw->mac_addr, 0);
ch1010832@1996: 
ch1010832@1996: 	/* Reset the timer */
ch1010832@1996: 	mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: enum latency_range {
ch1010832@1996: 	lowest_latency = 0,
ch1010832@1996: 	low_latency = 1,
ch1010832@1996: 	bulk_latency = 2,
ch1010832@1996: 	latency_invalid = 255
ch1010832@1996: };
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_update_itr - update the dynamic ITR value based on statistics
ch1010832@1996:  *      Stores a new ITR value based on packets and byte
ch1010832@1996:  *      counts during the last interrupt.  The advantage of per interrupt
ch1010832@1996:  *      computation is faster updates and more accurate ITR for the current
ch1010832@1996:  *      traffic pattern.  Constants in this function were computed
ch1010832@1996:  *      based on theoretical maximum wire speed and thresholds were set based
ch1010832@1996:  *      on testing data as well as attempting to minimize response time
ch1010832@1996:  *      while increasing bulk throughput.
ch1010832@1996:  *      this functionality is controlled by the InterruptThrottleRate module
ch1010832@1996:  *      parameter (see e1000_param.c)
ch1010832@1996:  * @adapter: pointer to adapter
ch1010832@1996:  * @itr_setting: current adapter->itr
ch1010832@1996:  * @packets: the number of packets during this measurement interval
ch1010832@1996:  * @bytes: the number of bytes during this measurement interval
ch1010832@1996:  **/
ch1010832@1996: static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
ch1010832@1996: 				     u16 itr_setting, int packets, int bytes)
ch1010832@1996: {
ch1010832@1996: 	unsigned int retval = itr_setting;
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(hw->mac_type < e1000_82540))
ch1010832@1996: 		goto update_itr_done;
ch1010832@1996: 
ch1010832@1996: 	if (packets == 0)
ch1010832@1996: 		goto update_itr_done;
ch1010832@1996: 
ch1010832@1996: 	switch (itr_setting) {
ch1010832@1996: 	case lowest_latency:
ch1010832@1996: 		/* jumbo frames get bulk treatment*/
ch1010832@1996: 		if (bytes/packets > 8000)
ch1010832@1996: 			retval = bulk_latency;
ch1010832@1996: 		else if ((packets < 5) && (bytes > 512))
ch1010832@1996: 			retval = low_latency;
ch1010832@1996: 		break;
ch1010832@1996: 	case low_latency:  /* 50 usec aka 20000 ints/s */
ch1010832@1996: 		if (bytes > 10000) {
ch1010832@1996: 			/* jumbo frames need bulk latency setting */
ch1010832@1996: 			if (bytes/packets > 8000)
ch1010832@1996: 				retval = bulk_latency;
ch1010832@1996: 			else if ((packets < 10) || ((bytes/packets) > 1200))
ch1010832@1996: 				retval = bulk_latency;
ch1010832@1996: 			else if ((packets > 35))
ch1010832@1996: 				retval = lowest_latency;
ch1010832@1996: 		} else if (bytes/packets > 2000)
ch1010832@1996: 			retval = bulk_latency;
ch1010832@1996: 		else if (packets <= 2 && bytes < 512)
ch1010832@1996: 			retval = lowest_latency;
ch1010832@1996: 		break;
ch1010832@1996: 	case bulk_latency: /* 250 usec aka 4000 ints/s */
ch1010832@1996: 		if (bytes > 25000) {
ch1010832@1996: 			if (packets > 35)
ch1010832@1996: 				retval = low_latency;
ch1010832@1996: 		} else if (bytes < 6000) {
ch1010832@1996: 			retval = low_latency;
ch1010832@1996: 		}
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: update_itr_done:
ch1010832@1996: 	return retval;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_set_itr(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u16 current_itr;
ch1010832@1996: 	u32 new_itr = adapter->itr;
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(hw->mac_type < e1000_82540))
ch1010832@1996: 		return;
ch1010832@1996: 
ch1010832@1996: 	/* for non-gigabit speeds, just fix the interrupt rate at 4000 */
ch1010832@1996: 	if (unlikely(adapter->link_speed != SPEED_1000)) {
ch1010832@1996: 		current_itr = 0;
ch1010832@1996: 		new_itr = 4000;
ch1010832@1996: 		goto set_itr_now;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	adapter->tx_itr = e1000_update_itr(adapter,
ch1010832@1996: 	                            adapter->tx_itr,
ch1010832@1996: 	                            adapter->total_tx_packets,
ch1010832@1996: 	                            adapter->total_tx_bytes);
ch1010832@1996: 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
ch1010832@1996: 	if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
ch1010832@1996: 		adapter->tx_itr = low_latency;
ch1010832@1996: 
ch1010832@1996: 	adapter->rx_itr = e1000_update_itr(adapter,
ch1010832@1996: 	                            adapter->rx_itr,
ch1010832@1996: 	                            adapter->total_rx_packets,
ch1010832@1996: 	                            adapter->total_rx_bytes);
ch1010832@1996: 	/* conservative mode (itr 3) eliminates the lowest_latency setting */
ch1010832@1996: 	if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
ch1010832@1996: 		adapter->rx_itr = low_latency;
ch1010832@1996: 
ch1010832@1996: 	current_itr = max(adapter->rx_itr, adapter->tx_itr);
ch1010832@1996: 
ch1010832@1996: 	switch (current_itr) {
ch1010832@1996: 	/* counts and packets in update_itr are dependent on these numbers */
ch1010832@1996: 	case lowest_latency:
ch1010832@1996: 		new_itr = 70000;
ch1010832@1996: 		break;
ch1010832@1996: 	case low_latency:
ch1010832@1996: 		new_itr = 20000; /* aka hwitr = ~200 */
ch1010832@1996: 		break;
ch1010832@1996: 	case bulk_latency:
ch1010832@1996: 		new_itr = 4000;
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: set_itr_now:
ch1010832@1996: 	if (new_itr != adapter->itr) {
ch1010832@1996: 		/* this attempts to bias the interrupt rate towards Bulk
ch1010832@1996: 		 * by adding intermediate steps when interrupt rate is
ch1010832@1996: 		 * increasing */
ch1010832@1996: 		new_itr = new_itr > adapter->itr ?
ch1010832@1996: 		             min(adapter->itr + (new_itr >> 2), new_itr) :
ch1010832@1996: 		             new_itr;
ch1010832@1996: 		adapter->itr = new_itr;
ch1010832@1996: 		ew32(ITR, 1000000000 / (new_itr * 256));
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #define E1000_TX_FLAGS_CSUM		0x00000001
ch1010832@1996: #define E1000_TX_FLAGS_VLAN		0x00000002
ch1010832@1996: #define E1000_TX_FLAGS_TSO		0x00000004
ch1010832@1996: #define E1000_TX_FLAGS_IPV4		0x00000008
ch1010832@1996: #define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
ch1010832@1996: #define E1000_TX_FLAGS_VLAN_SHIFT	16
ch1010832@1996: 
ch1010832@1996: static int e1000_tso(struct e1000_adapter *adapter,
ch1010832@1996: 		     struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_context_desc *context_desc;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 	u32 cmd_length = 0;
ch1010832@1996: 	u16 ipcse = 0, tucse, mss;
ch1010832@1996: 	u8 ipcss, ipcso, tucss, tucso, hdr_len;
ch1010832@1996: 	int err;
ch1010832@1996: 
ch1010832@1996: 	if (skb_is_gso(skb)) {
ch1010832@1996: 		if (skb_header_cloned(skb)) {
ch1010832@1996: 			err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
ch1010832@1996: 			if (err)
ch1010832@1996: 				return err;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
ch1010832@1996: 		mss = skb_shinfo(skb)->gso_size;
ch1010832@1996: 		if (skb->protocol == htons(ETH_P_IP)) {
ch1010832@1996: 			struct iphdr *iph = ip_hdr(skb);
ch1010832@1996: 			iph->tot_len = 0;
ch1010832@1996: 			iph->check = 0;
ch1010832@1996: 			tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
ch1010832@1996: 								 iph->daddr, 0,
ch1010832@1996: 								 IPPROTO_TCP,
ch1010832@1996: 								 0);
ch1010832@1996: 			cmd_length = E1000_TXD_CMD_IP;
ch1010832@1996: 			ipcse = skb_transport_offset(skb) - 1;
ch1010832@1996: 		} else if (skb->protocol == htons(ETH_P_IPV6)) {
ch1010832@1996: 			ipv6_hdr(skb)->payload_len = 0;
ch1010832@1996: 			tcp_hdr(skb)->check =
ch1010832@1996: 				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
ch1010832@1996: 						 &ipv6_hdr(skb)->daddr,
ch1010832@1996: 						 0, IPPROTO_TCP, 0);
ch1010832@1996: 			ipcse = 0;
ch1010832@1996: 		}
ch1010832@1996: 		ipcss = skb_network_offset(skb);
ch1010832@1996: 		ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
ch1010832@1996: 		tucss = skb_transport_offset(skb);
ch1010832@1996: 		tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
ch1010832@1996: 		tucse = 0;
ch1010832@1996: 
ch1010832@1996: 		cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
ch1010832@1996: 			       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
ch1010832@1996: 
ch1010832@1996: 		i = tx_ring->next_to_use;
ch1010832@1996: 		context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
ch1010832@1996: 		buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 
ch1010832@1996: 		context_desc->lower_setup.ip_fields.ipcss  = ipcss;
ch1010832@1996: 		context_desc->lower_setup.ip_fields.ipcso  = ipcso;
ch1010832@1996: 		context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
ch1010832@1996: 		context_desc->upper_setup.tcp_fields.tucss = tucss;
ch1010832@1996: 		context_desc->upper_setup.tcp_fields.tucso = tucso;
ch1010832@1996: 		context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
ch1010832@1996: 		context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
ch1010832@1996: 		context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
ch1010832@1996: 		context_desc->cmd_and_length = cpu_to_le32(cmd_length);
ch1010832@1996: 
ch1010832@1996: 		buffer_info->time_stamp = jiffies;
ch1010832@1996: 		buffer_info->next_to_watch = i;
ch1010832@1996: 
ch1010832@1996: 		if (++i == tx_ring->count) i = 0;
ch1010832@1996: 		tx_ring->next_to_use = i;
ch1010832@1996: 
ch1010832@1996: 		return true;
ch1010832@1996: 	}
ch1010832@1996: 	return false;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static bool e1000_tx_csum(struct e1000_adapter *adapter,
ch1010832@1996: 			  struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_context_desc *context_desc;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 	u8 css;
ch1010832@1996: 	u32 cmd_len = E1000_TXD_CMD_DEXT;
ch1010832@1996: 
ch1010832@1996: 	if (skb->ip_summed != CHECKSUM_PARTIAL)
ch1010832@1996: 		return false;
ch1010832@1996: 
ch1010832@1996: 	switch (skb->protocol) {
ch1010832@1996: 	case cpu_to_be16(ETH_P_IP):
ch1010832@1996: 		if (ip_hdr(skb)->protocol == IPPROTO_TCP)
ch1010832@1996: 			cmd_len |= E1000_TXD_CMD_TCP;
ch1010832@1996: 		break;
ch1010832@1996: 	case cpu_to_be16(ETH_P_IPV6):
ch1010832@1996: 		/* XXX not handling all IPV6 headers */
ch1010832@1996: 		if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
ch1010832@1996: 			cmd_len |= E1000_TXD_CMD_TCP;
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		if (unlikely(net_ratelimit()))
ch1010832@1996: 			DPRINTK(DRV, WARNING,
ch1010832@1996: 			        "checksum_partial proto=%x!\n", skb->protocol);
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	css = skb_transport_offset(skb);
ch1010832@1996: 
ch1010832@1996: 	i = tx_ring->next_to_use;
ch1010832@1996: 	buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 	context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
ch1010832@1996: 
ch1010832@1996: 	context_desc->lower_setup.ip_config = 0;
ch1010832@1996: 	context_desc->upper_setup.tcp_fields.tucss = css;
ch1010832@1996: 	context_desc->upper_setup.tcp_fields.tucso =
ch1010832@1996: 		css + skb->csum_offset;
ch1010832@1996: 	context_desc->upper_setup.tcp_fields.tucse = 0;
ch1010832@1996: 	context_desc->tcp_seg_setup.data = 0;
ch1010832@1996: 	context_desc->cmd_and_length = cpu_to_le32(cmd_len);
ch1010832@1996: 
ch1010832@1996: 	buffer_info->time_stamp = jiffies;
ch1010832@1996: 	buffer_info->next_to_watch = i;
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(++i == tx_ring->count)) i = 0;
ch1010832@1996: 	tx_ring->next_to_use = i;
ch1010832@1996: 
ch1010832@1996: 	return true;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #define E1000_MAX_TXD_PWR	12
ch1010832@1996: #define E1000_MAX_DATA_PER_TXD	(1<<E1000_MAX_TXD_PWR)
ch1010832@1996: 
ch1010832@1996: static int e1000_tx_map(struct e1000_adapter *adapter,
ch1010832@1996: 			struct e1000_tx_ring *tx_ring,
ch1010832@1996: 			struct sk_buff *skb, unsigned int first,
ch1010832@1996: 			unsigned int max_per_txd, unsigned int nr_frags,
ch1010832@1996: 			unsigned int mss)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	unsigned int len = skb_headlen(skb);
ch1010832@1996: 	unsigned int offset, size, count = 0, i;
ch1010832@1996: 	unsigned int f;
ch1010832@1996: 	dma_addr_t *map;
ch1010832@1996: 
ch1010832@1996: 	i = tx_ring->next_to_use;
ch1010832@1996: 
ch1010832@1996: 	if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
ch1010832@1996: 		dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
ch1010832@1996: 		return 0;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	map = skb_shinfo(skb)->dma_maps;
ch1010832@1996: 	offset = 0;
ch1010832@1996: 
ch1010832@1996: 	while (len) {
ch1010832@1996: 		buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 		size = min(len, max_per_txd);
ch1010832@1996: 		/* Workaround for Controller erratum --
ch1010832@1996: 		 * descriptor for non-tso packet in a linear SKB that follows a
ch1010832@1996: 		 * tso gets written back prematurely before the data is fully
ch1010832@1996: 		 * DMA'd to the controller */
ch1010832@1996: 		if (!skb->data_len && tx_ring->last_tx_tso &&
ch1010832@1996: 		    !skb_is_gso(skb)) {
ch1010832@1996: 			tx_ring->last_tx_tso = 0;
ch1010832@1996: 			size -= 4;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		/* Workaround for premature desc write-backs
ch1010832@1996: 		 * in TSO mode.  Append 4-byte sentinel desc */
ch1010832@1996: 		if (unlikely(mss && !nr_frags && size == len && size > 8))
ch1010832@1996: 			size -= 4;
ch1010832@1996: 		/* work-around for errata 10 and it applies
ch1010832@1996: 		 * to all controllers in PCI-X mode
ch1010832@1996: 		 * The fix is to make sure that the first descriptor of a
ch1010832@1996: 		 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
ch1010832@1996: 		 */
ch1010832@1996: 		if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
ch1010832@1996: 		                (size > 2015) && count == 0))
ch1010832@1996: 		        size = 2015;
ch1010832@1996: 
ch1010832@1996: 		/* Workaround for potential 82544 hang in PCI-X.  Avoid
ch1010832@1996: 		 * terminating buffers within evenly-aligned dwords. */
ch1010832@1996: 		if (unlikely(adapter->pcix_82544 &&
ch1010832@1996: 		   !((unsigned long)(skb->data + offset + size - 1) & 4) &&
ch1010832@1996: 		   size > 4))
ch1010832@1996: 			size -= 4;
ch1010832@1996: 
ch1010832@1996: 		buffer_info->length = size;
ch1010832@1996: 		buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
ch1010832@1996: 		buffer_info->time_stamp = jiffies;
ch1010832@1996: 		buffer_info->next_to_watch = i;
ch1010832@1996: 
ch1010832@1996: 		len -= size;
ch1010832@1996: 		offset += size;
ch1010832@1996: 		count++;
ch1010832@1996: 		if (len) {
ch1010832@1996: 			i++;
ch1010832@1996: 			if (unlikely(i == tx_ring->count))
ch1010832@1996: 				i = 0;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	for (f = 0; f < nr_frags; f++) {
ch1010832@1996: 		struct skb_frag_struct *frag;
ch1010832@1996: 
ch1010832@1996: 		frag = &skb_shinfo(skb)->frags[f];
ch1010832@1996: 		len = frag->size;
ch1010832@1996: 		offset = 0;
ch1010832@1996: 
ch1010832@1996: 		while (len) {
ch1010832@1996: 			i++;
ch1010832@1996: 			if (unlikely(i == tx_ring->count))
ch1010832@1996: 				i = 0;
ch1010832@1996: 
ch1010832@1996: 			buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 			size = min(len, max_per_txd);
ch1010832@1996: 			/* Workaround for premature desc write-backs
ch1010832@1996: 			 * in TSO mode.  Append 4-byte sentinel desc */
ch1010832@1996: 			if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
ch1010832@1996: 				size -= 4;
ch1010832@1996: 			/* Workaround for potential 82544 hang in PCI-X.
ch1010832@1996: 			 * Avoid terminating buffers within evenly-aligned
ch1010832@1996: 			 * dwords. */
ch1010832@1996: 			if (unlikely(adapter->pcix_82544 &&
ch1010832@1996: 			   !((unsigned long)(frag->page+offset+size-1) & 4) &&
ch1010832@1996: 			   size > 4))
ch1010832@1996: 				size -= 4;
ch1010832@1996: 
ch1010832@1996: 			buffer_info->length = size;
ch1010832@1996: 			buffer_info->dma = map[f] + offset;
ch1010832@1996: 			buffer_info->time_stamp = jiffies;
ch1010832@1996: 			buffer_info->next_to_watch = i;
ch1010832@1996: 
ch1010832@1996: 			len -= size;
ch1010832@1996: 			offset += size;
ch1010832@1996: 			count++;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	tx_ring->buffer_info[i].skb = skb;
ch1010832@1996: 	tx_ring->buffer_info[first].next_to_watch = i;
ch1010832@1996: 
ch1010832@1996: 	return count;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_tx_queue(struct e1000_adapter *adapter,
ch1010832@1996: 			   struct e1000_tx_ring *tx_ring, int tx_flags,
ch1010832@1996: 			   int count)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct e1000_tx_desc *tx_desc = NULL;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 
ch1010832@1996: 	if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
ch1010832@1996: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
ch1010832@1996: 		             E1000_TXD_CMD_TSE;
ch1010832@1996: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
ch1010832@1996: 
ch1010832@1996: 		if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
ch1010832@1996: 			txd_upper |= E1000_TXD_POPTS_IXSM << 8;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
ch1010832@1996: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
ch1010832@1996: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
ch1010832@1996: 		txd_lower |= E1000_TXD_CMD_VLE;
ch1010832@1996: 		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	i = tx_ring->next_to_use;
ch1010832@1996: 
ch1010832@1996: 	while (count--) {
ch1010832@1996: 		buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 		tx_desc = E1000_TX_DESC(*tx_ring, i);
ch1010832@1996: 		tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
ch1010832@1996: 		tx_desc->lower.data =
ch1010832@1996: 			cpu_to_le32(txd_lower | buffer_info->length);
ch1010832@1996: 		tx_desc->upper.data = cpu_to_le32(txd_upper);
ch1010832@1996: 		if (unlikely(++i == tx_ring->count)) i = 0;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
ch1010832@1996: 
ch1010832@1996: 	/* Force memory writes to complete before letting h/w
ch1010832@1996: 	 * know there are new descriptors to fetch.  (Only
ch1010832@1996: 	 * applicable for weak-ordered memory model archs,
ch1010832@1996: 	 * such as IA-64). */
ch1010832@1996: 	wmb();
ch1010832@1996: 
ch1010832@1996: 	tx_ring->next_to_use = i;
ch1010832@1996: 	writel(i, hw->hw_addr + tx_ring->tdt);
ch1010832@1996: 	/* we need this if more than one processor can write to our tail
ch1010832@1996: 	 * at a time, it syncronizes IO on IA64/Altix systems */
ch1010832@1996: 	mmiowb();
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * 82547 workaround to avoid controller hang in half-duplex environment.
ch1010832@1996:  * The workaround is to avoid queuing a large packet that would span
ch1010832@1996:  * the internal Tx FIFO ring boundary by notifying the stack to resend
ch1010832@1996:  * the packet at a later time.  This gives the Tx FIFO an opportunity to
ch1010832@1996:  * flush all packets.  When that occurs, we reset the Tx FIFO pointers
ch1010832@1996:  * to the beginning of the Tx FIFO.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: #define E1000_FIFO_HDR			0x10
ch1010832@1996: #define E1000_82547_PAD_LEN		0x3E0
ch1010832@1996: 
ch1010832@1996: static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
ch1010832@1996: 				       struct sk_buff *skb)
ch1010832@1996: {
ch1010832@1996: 	u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
ch1010832@1996: 	u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
ch1010832@1996: 
ch1010832@1996: 	skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
ch1010832@1996: 
ch1010832@1996: 	if (adapter->link_duplex != HALF_DUPLEX)
ch1010832@1996: 		goto no_fifo_stall_required;
ch1010832@1996: 
ch1010832@1996: 	if (atomic_read(&adapter->tx_fifo_stall))
ch1010832@1996: 		return 1;
ch1010832@1996: 
ch1010832@1996: 	if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
ch1010832@1996: 		atomic_set(&adapter->tx_fifo_stall, 1);
ch1010832@1996: 		return 1;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: no_fifo_stall_required:
ch1010832@1996: 	adapter->tx_fifo_head += skb_fifo_len;
ch1010832@1996: 	if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
ch1010832@1996: 		adapter->tx_fifo_head -= adapter->tx_fifo_size;
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #define MINIMUM_DHCP_PACKET_SIZE 282
ch1010832@1996: static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
ch1010832@1996: 				    struct sk_buff *skb)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw =  &adapter->hw;
ch1010832@1996: 	u16 length, offset;
ch1010832@1996: 	if (vlan_tx_tag_present(skb)) {
ch1010832@1996: 		if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
ch1010832@1996: 			( hw->mng_cookie.status &
ch1010832@1996: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
ch1010832@1996: 			return 0;
ch1010832@1996: 	}
ch1010832@1996: 	if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
ch1010832@1996: 		struct ethhdr *eth = (struct ethhdr *)skb->data;
ch1010832@1996: 		if ((htons(ETH_P_IP) == eth->h_proto)) {
ch1010832@1996: 			const struct iphdr *ip =
ch1010832@1996: 				(struct iphdr *)((u8 *)skb->data+14);
ch1010832@1996: 			if (IPPROTO_UDP == ip->protocol) {
ch1010832@1996: 				struct udphdr *udp =
ch1010832@1996: 					(struct udphdr *)((u8 *)ip +
ch1010832@1996: 						(ip->ihl << 2));
ch1010832@1996: 				if (ntohs(udp->dest) == 67) {
ch1010832@1996: 					offset = (u8 *)udp + 8 - skb->data;
ch1010832@1996: 					length = skb->len - offset;
ch1010832@1996: 
ch1010832@1996: 					return e1000_mng_write_dhcp_info(hw,
ch1010832@1996: 							(u8 *)udp + 8,
ch1010832@1996: 							length);
ch1010832@1996: 				}
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_tx_ring *tx_ring = adapter->tx_ring;
ch1010832@1996: 
ch1010832@1996: 	netif_stop_queue(netdev);
ch1010832@1996: 	/* Herbert's original patch had:
ch1010832@1996: 	 *  smp_mb__after_netif_stop_queue();
ch1010832@1996: 	 * but since that doesn't exist yet, just open code it. */
ch1010832@1996: 	smp_mb();
ch1010832@1996: 
ch1010832@1996: 	/* We need to check again in a case another CPU has just
ch1010832@1996: 	 * made room available. */
ch1010832@1996: 	if (likely(E1000_DESC_UNUSED(tx_ring) < size))
ch1010832@1996: 		return -EBUSY;
ch1010832@1996: 
ch1010832@1996: 	/* A reprieve! */
ch1010832@1996: 	netif_start_queue(netdev);
ch1010832@1996: 	++adapter->restart_queue;
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static int e1000_maybe_stop_tx(struct net_device *netdev,
ch1010832@1996:                                struct e1000_tx_ring *tx_ring, int size)
ch1010832@1996: {
ch1010832@1996: 	if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
ch1010832@1996: 		return 0;
ch1010832@1996: 	return __e1000_maybe_stop_tx(netdev, size);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
ch1010832@1996: static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct e1000_tx_ring *tx_ring;
ch1010832@1996: 	unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
ch1010832@1996: 	unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
ch1010832@1996: 	unsigned int tx_flags = 0;
ch1010832@1996: 	unsigned int len = skb->len - skb->data_len;
ch1010832@1996: 	unsigned int nr_frags;
ch1010832@1996: 	unsigned int mss;
ch1010832@1996: 	int count = 0;
ch1010832@1996: 	int tso;
ch1010832@1996: 	unsigned int f;
ch1010832@1996: 
ch1010832@1996: 	/* This goes back to the question of how to logically map a tx queue
ch1010832@1996: 	 * to a flow.  Right now, performance is impacted slightly negatively
ch1010832@1996: 	 * if using multiple tx queues.  If the stack breaks away from a
ch1010832@1996: 	 * single qdisc implementation, we can look at this again. */
ch1010832@1996: 	tx_ring = adapter->tx_ring;
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(skb->len <= 0)) {
ch1010832@1996: 		dev_kfree_skb_any(skb);
ch1010832@1996: 		return NETDEV_TX_OK;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* 82571 and newer doesn't need the workaround that limited descriptor
ch1010832@1996: 	 * length to 4kB */
ch1010832@1996: 	if (hw->mac_type >= e1000_82571)
ch1010832@1996: 		max_per_txd = 8192;
ch1010832@1996: 
ch1010832@1996: 	mss = skb_shinfo(skb)->gso_size;
ch1010832@1996: 	/* The controller does a simple calculation to
ch1010832@1996: 	 * make sure there is enough room in the FIFO before
ch1010832@1996: 	 * initiating the DMA for each buffer.  The calc is:
ch1010832@1996: 	 * 4 = ceil(buffer len/mss).  To make sure we don't
ch1010832@1996: 	 * overrun the FIFO, adjust the max buffer len if mss
ch1010832@1996: 	 * drops. */
ch1010832@1996: 	if (mss) {
ch1010832@1996: 		u8 hdr_len;
ch1010832@1996: 		max_per_txd = min(mss << 2, max_per_txd);
ch1010832@1996: 		max_txd_pwr = fls(max_per_txd) - 1;
ch1010832@1996: 
ch1010832@1996: 		/* TSO Workaround for 82571/2/3 Controllers -- if skb->data
ch1010832@1996: 		* points to just header, pull a few bytes of payload from
ch1010832@1996: 		* frags into skb->data */
ch1010832@1996: 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
ch1010832@1996: 		if (skb->data_len && hdr_len == len) {
ch1010832@1996: 			switch (hw->mac_type) {
ch1010832@1996: 				unsigned int pull_size;
ch1010832@1996: 			case e1000_82544:
ch1010832@1996: 				/* Make sure we have room to chop off 4 bytes,
ch1010832@1996: 				 * and that the end alignment will work out to
ch1010832@1996: 				 * this hardware's requirements
ch1010832@1996: 				 * NOTE: this is a TSO only workaround
ch1010832@1996: 				 * if end byte alignment not correct move us
ch1010832@1996: 				 * into the next dword */
ch1010832@1996: 				if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
ch1010832@1996: 					break;
ch1010832@1996: 				/* fall through */
ch1010832@1996: 			case e1000_82571:
ch1010832@1996: 			case e1000_82572:
ch1010832@1996: 			case e1000_82573:
ch1010832@1996: 			case e1000_ich8lan:
ch1010832@1996: 				pull_size = min((unsigned int)4, skb->data_len);
ch1010832@1996: 				if (!__pskb_pull_tail(skb, pull_size)) {
ch1010832@1996: 					DPRINTK(DRV, ERR,
ch1010832@1996: 						"__pskb_pull_tail failed.\n");
ch1010832@1996: 					dev_kfree_skb_any(skb);
ch1010832@1996: 					return NETDEV_TX_OK;
ch1010832@1996: 				}
ch1010832@1996: 				len = skb->len - skb->data_len;
ch1010832@1996: 				break;
ch1010832@1996: 			default:
ch1010832@1996: 				/* do nothing */
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* reserve a descriptor for the offload context */
ch1010832@1996: 	if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
ch1010832@1996: 		count++;
ch1010832@1996: 	count++;
ch1010832@1996: 
ch1010832@1996: 	/* Controller Erratum workaround */
ch1010832@1996: 	if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
ch1010832@1996: 		count++;
ch1010832@1996: 
ch1010832@1996: 	count += TXD_USE_COUNT(len, max_txd_pwr);
ch1010832@1996: 
ch1010832@1996: 	if (adapter->pcix_82544)
ch1010832@1996: 		count++;
ch1010832@1996: 
ch1010832@1996: 	/* work-around for errata 10 and it applies to all controllers
ch1010832@1996: 	 * in PCI-X mode, so add one more descriptor to the count
ch1010832@1996: 	 */
ch1010832@1996: 	if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
ch1010832@1996: 			(len > 2015)))
ch1010832@1996: 		count++;
ch1010832@1996: 
ch1010832@1996: 	nr_frags = skb_shinfo(skb)->nr_frags;
ch1010832@1996: 	for (f = 0; f < nr_frags; f++)
ch1010832@1996: 		count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
ch1010832@1996: 				       max_txd_pwr);
ch1010832@1996: 	if (adapter->pcix_82544)
ch1010832@1996: 		count += nr_frags;
ch1010832@1996: 
ch1010832@1996: 
ch1010832@1996: 	if (hw->tx_pkt_filtering &&
ch1010832@1996: 	    (hw->mac_type == e1000_82573))
ch1010832@1996: 		e1000_transfer_dhcp_info(adapter, skb);
ch1010832@1996: 
ch1010832@1996: 	/* need: count + 2 desc gap to keep tail from touching
ch1010832@1996: 	 * head, otherwise try next time */
ch1010832@1996: 	if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
ch1010832@1996: 		return NETDEV_TX_BUSY;
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(hw->mac_type == e1000_82547)) {
ch1010832@1996: 		if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
ch1010832@1996: 			netif_stop_queue(netdev);
ch1010832@1996: 			mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
ch1010832@1996: 			return NETDEV_TX_BUSY;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
ch1010832@1996: 		tx_flags |= E1000_TX_FLAGS_VLAN;
ch1010832@1996: 		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	first = tx_ring->next_to_use;
ch1010832@1996: 
ch1010832@1996: 	tso = e1000_tso(adapter, tx_ring, skb);
ch1010832@1996: 	if (tso < 0) {
ch1010832@1996: 		dev_kfree_skb_any(skb);
ch1010832@1996: 		return NETDEV_TX_OK;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (likely(tso)) {
ch1010832@1996: 		tx_ring->last_tx_tso = 1;
ch1010832@1996: 		tx_flags |= E1000_TX_FLAGS_TSO;
ch1010832@1996: 	} else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
ch1010832@1996: 		tx_flags |= E1000_TX_FLAGS_CSUM;
ch1010832@1996: 
ch1010832@1996: 	/* Old method was to assume IPv4 packet by default if TSO was enabled.
ch1010832@1996: 	 * 82571 hardware supports TSO capabilities for IPv6 as well...
ch1010832@1996: 	 * no longer assume, we must. */
ch1010832@1996: 	if (likely(skb->protocol == htons(ETH_P_IP)))
ch1010832@1996: 		tx_flags |= E1000_TX_FLAGS_IPV4;
ch1010832@1996: 
ch1010832@1996: 	count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
ch1010832@1996: 	                     nr_frags, mss);
ch1010832@1996: 
ch1010832@1996: 	if (count) {
ch1010832@1996: 		e1000_tx_queue(adapter, tx_ring, tx_flags, count);
ch1010832@1996: 		/* Make sure there is space in the ring for the next send. */
ch1010832@1996: 		e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
ch1010832@1996: 
ch1010832@1996: 	} else {
ch1010832@1996: 		dev_kfree_skb_any(skb);
ch1010832@1996: 		tx_ring->buffer_info[first].time_stamp = 0;
ch1010832@1996: 		tx_ring->next_to_use = first;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return NETDEV_TX_OK;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_tx_timeout - Respond to a Tx Hang
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_tx_timeout(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* Do the reset outside of interrupt context */
ch1010832@1996: 	adapter->tx_timeout_count++;
ch1010832@1996: 	schedule_work(&adapter->reset_task);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_reset_task(struct work_struct *work)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter =
ch1010832@1996: 		container_of(work, struct e1000_adapter, reset_task);
ch1010832@1996: 
ch1010832@1996: 	e1000_reinit_locked(adapter);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_get_stats - Get System Network Statistics
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  *
ch1010832@1996:  * Returns the address of the device statistics structure.
ch1010832@1996:  * The statistics are actually updated from the timer callback.
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* only return the current stats */
ch1010832@1996: 	return &adapter->net_stats;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_change_mtu - Change the Maximum Transfer Unit
ch1010832@1996:  * @netdev: network interface device structure
ch1010832@1996:  * @new_mtu: new value for maximum frame size
ch1010832@1996:  *
ch1010832@1996:  * Returns 0 on success, negative on failure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
ch1010832@1996: 	u16 eeprom_data = 0;
ch1010832@1996: 
ch1010832@1996: 	if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
ch1010832@1996: 	    (max_frame > MAX_JUMBO_FRAME_SIZE)) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
ch1010832@1996: 		return -EINVAL;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Adapter-specific max frame size limits. */
ch1010832@1996: 	switch (hw->mac_type) {
ch1010832@1996: 	case e1000_undefined ... e1000_82542_rev2_1:
ch1010832@1996: 	case e1000_ich8lan:
ch1010832@1996: 		if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
ch1010832@1996: 			DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
ch1010832@1996: 			return -EINVAL;
ch1010832@1996: 		}
ch1010832@1996: 		break;
ch1010832@1996: 	case e1000_82573:
ch1010832@1996: 		/* Jumbo Frames not supported if:
ch1010832@1996: 		 * - this is not an 82573L device
ch1010832@1996: 		 * - ASPM is enabled in any way (0x1A bits 3:2) */
ch1010832@1996: 		e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
ch1010832@1996: 		                  &eeprom_data);
ch1010832@1996: 		if ((hw->device_id != E1000_DEV_ID_82573L) ||
ch1010832@1996: 		    (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
ch1010832@1996: 			if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
ch1010832@1996: 				DPRINTK(PROBE, ERR,
ch1010832@1996: 			            	"Jumbo Frames not supported.\n");
ch1010832@1996: 				return -EINVAL;
ch1010832@1996: 			}
ch1010832@1996: 			break;
ch1010832@1996: 		}
ch1010832@1996: 		/* ERT will be enabled later to enable wire speed receives */
ch1010832@1996: 
ch1010832@1996: 		/* fall through to get support */
ch1010832@1996: 	case e1000_82571:
ch1010832@1996: 	case e1000_82572:
ch1010832@1996: 	case e1000_80003es2lan:
ch1010832@1996: #define MAX_STD_JUMBO_FRAME_SIZE 9234
ch1010832@1996: 		if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
ch1010832@1996: 			DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
ch1010832@1996: 			return -EINVAL;
ch1010832@1996: 		}
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		/* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
ch1010832@1996: 		break;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
ch1010832@1996: 	 * means we reserve 2 more, this pushes us to allocate from the next
ch1010832@1996: 	 * larger slab size
ch1010832@1996: 	 * i.e. RXBUFFER_2048 --> size-4096 slab */
ch1010832@1996: 
ch1010832@1996: 	if (max_frame <= E1000_RXBUFFER_256)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_256;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_512)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_512;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_1024)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_1024;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_2048)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_2048;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_4096)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_4096;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_8192)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_8192;
ch1010832@1996: 	else if (max_frame <= E1000_RXBUFFER_16384)
ch1010832@1996: 		adapter->rx_buffer_len = E1000_RXBUFFER_16384;
ch1010832@1996: 
ch1010832@1996: 	/* adjust allocation if LPE protects us, and we aren't using SBP */
ch1010832@1996: 	if (!hw->tbi_compatibility_on &&
ch1010832@1996: 	    ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
ch1010832@1996: 	     (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
ch1010832@1996: 		adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
ch1010832@1996: 
ch1010832@1996: 	netdev->mtu = new_mtu;
ch1010832@1996: 	hw->max_frame_size = max_frame;
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev))
ch1010832@1996: 		e1000_reinit_locked(adapter);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_update_stats - Update the board statistics counters
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: void e1000_update_stats(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	unsigned long flags;
ch1010832@1996: 	u16 phy_tmp;
ch1010832@1996: 
ch1010832@1996: #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
ch1010832@1996: 
ch1010832@1996: 	/*
ch1010832@1996: 	 * Prevent stats update while adapter is being reset, or if the pci
ch1010832@1996: 	 * connection is down.
ch1010832@1996: 	 */
ch1010832@1996: 	if (adapter->link_speed == 0)
ch1010832@1996: 		return;
ch1010832@1996: 	if (pci_channel_offline(pdev))
ch1010832@1996: 		return;
ch1010832@1996: 
ch1010832@1996: 	spin_lock_irqsave(&adapter->stats_lock, flags);
ch1010832@1996: 
ch1010832@1996: 	/* these counters are modified from e1000_tbi_adjust_stats,
ch1010832@1996: 	 * called from the interrupt context, so they must only
ch1010832@1996: 	 * be written while holding adapter->stats_lock
ch1010832@1996: 	 */
ch1010832@1996: 
ch1010832@1996: 	adapter->stats.crcerrs += er32(CRCERRS);
ch1010832@1996: 	adapter->stats.gprc += er32(GPRC);
ch1010832@1996: 	adapter->stats.gorcl += er32(GORCL);
ch1010832@1996: 	adapter->stats.gorch += er32(GORCH);
ch1010832@1996: 	adapter->stats.bprc += er32(BPRC);
ch1010832@1996: 	adapter->stats.mprc += er32(MPRC);
ch1010832@1996: 	adapter->stats.roc += er32(ROC);
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type != e1000_ich8lan) {
ch1010832@1996: 		adapter->stats.prc64 += er32(PRC64);
ch1010832@1996: 		adapter->stats.prc127 += er32(PRC127);
ch1010832@1996: 		adapter->stats.prc255 += er32(PRC255);
ch1010832@1996: 		adapter->stats.prc511 += er32(PRC511);
ch1010832@1996: 		adapter->stats.prc1023 += er32(PRC1023);
ch1010832@1996: 		adapter->stats.prc1522 += er32(PRC1522);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	adapter->stats.symerrs += er32(SYMERRS);
ch1010832@1996: 	adapter->stats.mpc += er32(MPC);
ch1010832@1996: 	adapter->stats.scc += er32(SCC);
ch1010832@1996: 	adapter->stats.ecol += er32(ECOL);
ch1010832@1996: 	adapter->stats.mcc += er32(MCC);
ch1010832@1996: 	adapter->stats.latecol += er32(LATECOL);
ch1010832@1996: 	adapter->stats.dc += er32(DC);
ch1010832@1996: 	adapter->stats.sec += er32(SEC);
ch1010832@1996: 	adapter->stats.rlec += er32(RLEC);
ch1010832@1996: 	adapter->stats.xonrxc += er32(XONRXC);
ch1010832@1996: 	adapter->stats.xontxc += er32(XONTXC);
ch1010832@1996: 	adapter->stats.xoffrxc += er32(XOFFRXC);
ch1010832@1996: 	adapter->stats.xofftxc += er32(XOFFTXC);
ch1010832@1996: 	adapter->stats.fcruc += er32(FCRUC);
ch1010832@1996: 	adapter->stats.gptc += er32(GPTC);
ch1010832@1996: 	adapter->stats.gotcl += er32(GOTCL);
ch1010832@1996: 	adapter->stats.gotch += er32(GOTCH);
ch1010832@1996: 	adapter->stats.rnbc += er32(RNBC);
ch1010832@1996: 	adapter->stats.ruc += er32(RUC);
ch1010832@1996: 	adapter->stats.rfc += er32(RFC);
ch1010832@1996: 	adapter->stats.rjc += er32(RJC);
ch1010832@1996: 	adapter->stats.torl += er32(TORL);
ch1010832@1996: 	adapter->stats.torh += er32(TORH);
ch1010832@1996: 	adapter->stats.totl += er32(TOTL);
ch1010832@1996: 	adapter->stats.toth += er32(TOTH);
ch1010832@1996: 	adapter->stats.tpr += er32(TPR);
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type != e1000_ich8lan) {
ch1010832@1996: 		adapter->stats.ptc64 += er32(PTC64);
ch1010832@1996: 		adapter->stats.ptc127 += er32(PTC127);
ch1010832@1996: 		adapter->stats.ptc255 += er32(PTC255);
ch1010832@1996: 		adapter->stats.ptc511 += er32(PTC511);
ch1010832@1996: 		adapter->stats.ptc1023 += er32(PTC1023);
ch1010832@1996: 		adapter->stats.ptc1522 += er32(PTC1522);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	adapter->stats.mptc += er32(MPTC);
ch1010832@1996: 	adapter->stats.bptc += er32(BPTC);
ch1010832@1996: 
ch1010832@1996: 	/* used for adaptive IFS */
ch1010832@1996: 
ch1010832@1996: 	hw->tx_packet_delta = er32(TPT);
ch1010832@1996: 	adapter->stats.tpt += hw->tx_packet_delta;
ch1010832@1996: 	hw->collision_delta = er32(COLC);
ch1010832@1996: 	adapter->stats.colc += hw->collision_delta;
ch1010832@1996: 
ch1010832@1996: 	if (hw->mac_type >= e1000_82543) {
ch1010832@1996: 		adapter->stats.algnerrc += er32(ALGNERRC);
ch1010832@1996: 		adapter->stats.rxerrc += er32(RXERRC);
ch1010832@1996: 		adapter->stats.tncrs += er32(TNCRS);
ch1010832@1996: 		adapter->stats.cexterr += er32(CEXTERR);
ch1010832@1996: 		adapter->stats.tsctc += er32(TSCTC);
ch1010832@1996: 		adapter->stats.tsctfc += er32(TSCTFC);
ch1010832@1996: 	}
ch1010832@1996: 	if (hw->mac_type > e1000_82547_rev_2) {
ch1010832@1996: 		adapter->stats.iac += er32(IAC);
ch1010832@1996: 		adapter->stats.icrxoc += er32(ICRXOC);
ch1010832@1996: 
ch1010832@1996: 		if (hw->mac_type != e1000_ich8lan) {
ch1010832@1996: 			adapter->stats.icrxptc += er32(ICRXPTC);
ch1010832@1996: 			adapter->stats.icrxatc += er32(ICRXATC);
ch1010832@1996: 			adapter->stats.ictxptc += er32(ICTXPTC);
ch1010832@1996: 			adapter->stats.ictxatc += er32(ICTXATC);
ch1010832@1996: 			adapter->stats.ictxqec += er32(ICTXQEC);
ch1010832@1996: 			adapter->stats.ictxqmtc += er32(ICTXQMTC);
ch1010832@1996: 			adapter->stats.icrxdmtc += er32(ICRXDMTC);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Fill out the OS statistics structure */
ch1010832@1996: 	adapter->net_stats.multicast = adapter->stats.mprc;
ch1010832@1996: 	adapter->net_stats.collisions = adapter->stats.colc;
ch1010832@1996: 
ch1010832@1996: 	/* Rx Errors */
ch1010832@1996: 
ch1010832@1996: 	/* RLEC on some newer hardware can be incorrect so build
ch1010832@1996: 	* our own version based on RUC and ROC */
ch1010832@1996: 	adapter->net_stats.rx_errors = adapter->stats.rxerrc +
ch1010832@1996: 		adapter->stats.crcerrs + adapter->stats.algnerrc +
ch1010832@1996: 		adapter->stats.ruc + adapter->stats.roc +
ch1010832@1996: 		adapter->stats.cexterr;
ch1010832@1996: 	adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
ch1010832@1996: 	adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
ch1010832@1996: 	adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
ch1010832@1996: 	adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
ch1010832@1996: 	adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
ch1010832@1996: 
ch1010832@1996: 	/* Tx Errors */
ch1010832@1996: 	adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
ch1010832@1996: 	adapter->net_stats.tx_errors = adapter->stats.txerrc;
ch1010832@1996: 	adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
ch1010832@1996: 	adapter->net_stats.tx_window_errors = adapter->stats.latecol;
ch1010832@1996: 	adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
ch1010832@1996: 	if (hw->bad_tx_carr_stats_fd &&
ch1010832@1996: 	    adapter->link_duplex == FULL_DUPLEX) {
ch1010832@1996: 		adapter->net_stats.tx_carrier_errors = 0;
ch1010832@1996: 		adapter->stats.tncrs = 0;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Tx Dropped needs to be maintained elsewhere */
ch1010832@1996: 
ch1010832@1996: 	/* Phy Stats */
ch1010832@1996: 	if (hw->media_type == e1000_media_type_copper) {
ch1010832@1996: 		if ((adapter->link_speed == SPEED_1000) &&
ch1010832@1996: 		   (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
ch1010832@1996: 			phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
ch1010832@1996: 			adapter->phy_stats.idle_errors += phy_tmp;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if ((hw->mac_type <= e1000_82546) &&
ch1010832@1996: 		   (hw->phy_type == e1000_phy_m88) &&
ch1010832@1996: 		   !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
ch1010832@1996: 			adapter->phy_stats.receive_errors += phy_tmp;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* Management Stats */
ch1010832@1996: 	if (hw->has_smbus) {
ch1010832@1996: 		adapter->stats.mgptc += er32(MGTPTC);
ch1010832@1996: 		adapter->stats.mgprc += er32(MGTPRC);
ch1010832@1996: 		adapter->stats.mgpdc += er32(MGTPDC);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	spin_unlock_irqrestore(&adapter->stats_lock, flags);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_intr_msi - Interrupt Handler
ch1010832@1996:  * @irq: interrupt number
ch1010832@1996:  * @data: pointer to a network interface device structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static irqreturn_t e1000_intr_msi(int irq, void *data)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = data;
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 icr = er32(ICR);
ch1010832@1996: 
ch1010832@1996: 	/* in NAPI mode read ICR disables interrupts using IAM */
ch1010832@1996: 
ch1010832@1996: 	if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
ch1010832@1996: 		hw->get_link_status = 1;
ch1010832@1996: 		/* 80003ES2LAN workaround-- For packet buffer work-around on
ch1010832@1996: 		 * link down event; disable receives here in the ISR and reset
ch1010832@1996: 		 * adapter in watchdog */
ch1010832@1996: 		if (netif_carrier_ok(netdev) &&
ch1010832@1996: 		    (hw->mac_type == e1000_80003es2lan)) {
ch1010832@1996: 			/* disable receives */
ch1010832@1996: 			u32 rctl = er32(RCTL);
ch1010832@1996: 			ew32(RCTL, rctl & ~E1000_RCTL_EN);
ch1010832@1996: 		}
ch1010832@1996: 		/* guard against interrupt when we're going down */
ch1010832@1996: 		if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (likely(napi_schedule_prep(&adapter->napi))) {
ch1010832@1996: 		adapter->total_tx_bytes = 0;
ch1010832@1996: 		adapter->total_tx_packets = 0;
ch1010832@1996: 		adapter->total_rx_bytes = 0;
ch1010832@1996: 		adapter->total_rx_packets = 0;
ch1010832@1996: 		__napi_schedule(&adapter->napi);
ch1010832@1996: 	} else
ch1010832@1996: 		e1000_irq_enable(adapter);
ch1010832@1996: 
ch1010832@1996: 	return IRQ_HANDLED;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_intr - Interrupt Handler
ch1010832@1996:  * @irq: interrupt number
ch1010832@1996:  * @data: pointer to a network interface device structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static irqreturn_t e1000_intr(int irq, void *data)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = data;
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 rctl, icr = er32(ICR);
ch1010832@1996: 
ch1010832@1996: 	if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags)))
ch1010832@1996: 		return IRQ_NONE;  /* Not our interrupt */
ch1010832@1996: 
ch1010832@1996: 	/* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
ch1010832@1996: 	 * not set, then the adapter didn't send an interrupt */
ch1010832@1996: 	if (unlikely(hw->mac_type >= e1000_82571 &&
ch1010832@1996: 	             !(icr & E1000_ICR_INT_ASSERTED)))
ch1010832@1996: 		return IRQ_NONE;
ch1010832@1996: 
ch1010832@1996: 	/* Interrupt Auto-Mask...upon reading ICR, interrupts are masked.  No
ch1010832@1996: 	 * need for the IMC write */
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
ch1010832@1996: 		hw->get_link_status = 1;
ch1010832@1996: 		/* 80003ES2LAN workaround--
ch1010832@1996: 		 * For packet buffer work-around on link down event;
ch1010832@1996: 		 * disable receives here in the ISR and
ch1010832@1996: 		 * reset adapter in watchdog
ch1010832@1996: 		 */
ch1010832@1996: 		if (netif_carrier_ok(netdev) &&
ch1010832@1996: 		    (hw->mac_type == e1000_80003es2lan)) {
ch1010832@1996: 			/* disable receives */
ch1010832@1996: 			rctl = er32(RCTL);
ch1010832@1996: 			ew32(RCTL, rctl & ~E1000_RCTL_EN);
ch1010832@1996: 		}
ch1010832@1996: 		/* guard against interrupt when we're going down */
ch1010832@1996: 		if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (unlikely(hw->mac_type < e1000_82571)) {
ch1010832@1996: 		/* disable interrupts, without the synchronize_irq bit */
ch1010832@1996: 		ew32(IMC, ~0);
ch1010832@1996: 		E1000_WRITE_FLUSH();
ch1010832@1996: 	}
ch1010832@1996: 	if (likely(napi_schedule_prep(&adapter->napi))) {
ch1010832@1996: 		adapter->total_tx_bytes = 0;
ch1010832@1996: 		adapter->total_tx_packets = 0;
ch1010832@1996: 		adapter->total_rx_bytes = 0;
ch1010832@1996: 		adapter->total_rx_packets = 0;
ch1010832@1996: 		__napi_schedule(&adapter->napi);
ch1010832@1996: 	} else {
ch1010832@1996: 		/* this really should not happen! if it does it is basically a
ch1010832@1996: 		 * bug, but not a hard error, so enable ints and continue */
ch1010832@1996: 		if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 			e1000_irq_enable(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return IRQ_HANDLED;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean - NAPI Rx polling callback
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: static int e1000_clean(struct napi_struct *napi, int budget)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
ch1010832@1996: 	struct net_device *poll_dev = adapter->netdev;
ch1010832@1996: 	int tx_cleaned = 0, work_done = 0;
ch1010832@1996: 
ch1010832@1996: 	adapter = netdev_priv(poll_dev);
ch1010832@1996: 
ch1010832@1996: 	tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
ch1010832@1996: 
ch1010832@1996: 	adapter->clean_rx(adapter, &adapter->rx_ring[0],
ch1010832@1996: 	                  &work_done, budget);
ch1010832@1996: 
ch1010832@1996: 	if (!tx_cleaned)
ch1010832@1996: 		work_done = budget;
ch1010832@1996: 
ch1010832@1996: 	/* If budget not fully consumed, exit the polling mode */
ch1010832@1996: 	if (work_done < budget) {
ch1010832@1996: 		if (likely(adapter->itr_setting & 3))
ch1010832@1996: 			e1000_set_itr(adapter);
ch1010832@1996: 		napi_complete(napi);
ch1010832@1996: 		if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 			e1000_irq_enable(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return work_done;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_tx_irq - Reclaim resources after transmit completes
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
ch1010832@1996: 			       struct e1000_tx_ring *tx_ring)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct e1000_tx_desc *tx_desc, *eop_desc;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	unsigned int i, eop;
ch1010832@1996: 	unsigned int count = 0;
ch1010832@1996: 	unsigned int total_tx_bytes=0, total_tx_packets=0;
ch1010832@1996: 
ch1010832@1996: 	i = tx_ring->next_to_clean;
ch1010832@1996: 	eop = tx_ring->buffer_info[i].next_to_watch;
ch1010832@1996: 	eop_desc = E1000_TX_DESC(*tx_ring, eop);
ch1010832@1996: 
ch1010832@1996: 	while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
ch1010832@1996: 	       (count < tx_ring->count)) {
ch1010832@1996: 		bool cleaned = false;
ch1010832@1996: 		for ( ; !cleaned; count++) {
ch1010832@1996: 			tx_desc = E1000_TX_DESC(*tx_ring, i);
ch1010832@1996: 			buffer_info = &tx_ring->buffer_info[i];
ch1010832@1996: 			cleaned = (i == eop);
ch1010832@1996: 
ch1010832@1996: 			if (cleaned) {
ch1010832@1996: 				struct sk_buff *skb = buffer_info->skb;
ch1010832@1996: 				unsigned int segs, bytecount;
ch1010832@1996: 				segs = skb_shinfo(skb)->gso_segs ?: 1;
ch1010832@1996: 				/* multiply data chunks by size of headers */
ch1010832@1996: 				bytecount = ((segs - 1) * skb_headlen(skb)) +
ch1010832@1996: 				            skb->len;
ch1010832@1996: 				total_tx_packets += segs;
ch1010832@1996: 				total_tx_bytes += bytecount;
ch1010832@1996: 			}
ch1010832@1996: 			e1000_unmap_and_free_tx_resource(adapter, buffer_info);
ch1010832@1996: 			tx_desc->upper.data = 0;
ch1010832@1996: 
ch1010832@1996: 			if (unlikely(++i == tx_ring->count)) i = 0;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		eop = tx_ring->buffer_info[i].next_to_watch;
ch1010832@1996: 		eop_desc = E1000_TX_DESC(*tx_ring, eop);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	tx_ring->next_to_clean = i;
ch1010832@1996: 
ch1010832@1996: #define TX_WAKE_THRESHOLD 32
ch1010832@1996: 	if (unlikely(count && netif_carrier_ok(netdev) &&
ch1010832@1996: 		     E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
ch1010832@1996: 		/* Make sure that anybody stopping the queue after this
ch1010832@1996: 		 * sees the new next_to_clean.
ch1010832@1996: 		 */
ch1010832@1996: 		smp_mb();
ch1010832@1996: 		if (netif_queue_stopped(netdev)) {
ch1010832@1996: 			netif_wake_queue(netdev);
ch1010832@1996: 			++adapter->restart_queue;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (adapter->detect_tx_hung) {
ch1010832@1996: 		/* Detect a transmit hang in hardware, this serializes the
ch1010832@1996: 		 * check with the clearing of time_stamp and movement of i */
ch1010832@1996: 		adapter->detect_tx_hung = false;
ch1010832@1996: 		if (tx_ring->buffer_info[i].time_stamp &&
ch1010832@1996: 		    time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
ch1010832@1996: 		               (adapter->tx_timeout_factor * HZ))
ch1010832@1996: 		    && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
ch1010832@1996: 
ch1010832@1996: 			/* detected Tx unit hang */
ch1010832@1996: 			DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
ch1010832@1996: 					"  Tx Queue             <%lu>\n"
ch1010832@1996: 					"  TDH                  <%x>\n"
ch1010832@1996: 					"  TDT                  <%x>\n"
ch1010832@1996: 					"  next_to_use          <%x>\n"
ch1010832@1996: 					"  next_to_clean        <%x>\n"
ch1010832@1996: 					"buffer_info[next_to_clean]\n"
ch1010832@1996: 					"  time_stamp           <%lx>\n"
ch1010832@1996: 					"  next_to_watch        <%x>\n"
ch1010832@1996: 					"  jiffies              <%lx>\n"
ch1010832@1996: 					"  next_to_watch.status <%x>\n",
ch1010832@1996: 				(unsigned long)((tx_ring - adapter->tx_ring) /
ch1010832@1996: 					sizeof(struct e1000_tx_ring)),
ch1010832@1996: 				readl(hw->hw_addr + tx_ring->tdh),
ch1010832@1996: 				readl(hw->hw_addr + tx_ring->tdt),
ch1010832@1996: 				tx_ring->next_to_use,
ch1010832@1996: 				tx_ring->next_to_clean,
ch1010832@1996: 				tx_ring->buffer_info[i].time_stamp,
ch1010832@1996: 				eop,
ch1010832@1996: 				jiffies,
ch1010832@1996: 				eop_desc->upper.fields.status);
ch1010832@1996: 			netif_stop_queue(netdev);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 	adapter->total_tx_bytes += total_tx_bytes;
ch1010832@1996: 	adapter->total_tx_packets += total_tx_packets;
ch1010832@1996: 	adapter->net_stats.tx_bytes += total_tx_bytes;
ch1010832@1996: 	adapter->net_stats.tx_packets += total_tx_packets;
ch1010832@1996: 	return (count < tx_ring->count);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_rx_checksum - Receive Checksum Offload for 82543
ch1010832@1996:  * @adapter:     board private structure
ch1010832@1996:  * @status_err:  receive descriptor status and error fields
ch1010832@1996:  * @csum:        receive descriptor csum field
ch1010832@1996:  * @sk_buff:     socket buffer with received data
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
ch1010832@1996: 			      u32 csum, struct sk_buff *skb)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u16 status = (u16)status_err;
ch1010832@1996: 	u8 errors = (u8)(status_err >> 24);
ch1010832@1996: 	skb->ip_summed = CHECKSUM_NONE;
ch1010832@1996: 
ch1010832@1996: 	/* 82543 or newer only */
ch1010832@1996: 	if (unlikely(hw->mac_type < e1000_82543)) return;
ch1010832@1996: 	/* Ignore Checksum bit is set */
ch1010832@1996: 	if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
ch1010832@1996: 	/* TCP/UDP checksum error bit is set */
ch1010832@1996: 	if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
ch1010832@1996: 		/* let the stack verify checksum errors */
ch1010832@1996: 		adapter->hw_csum_err++;
ch1010832@1996: 		return;
ch1010832@1996: 	}
ch1010832@1996: 	/* TCP/UDP Checksum has not been calculated */
ch1010832@1996: 	if (hw->mac_type <= e1000_82547_rev_2) {
ch1010832@1996: 		if (!(status & E1000_RXD_STAT_TCPCS))
ch1010832@1996: 			return;
ch1010832@1996: 	} else {
ch1010832@1996: 		if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
ch1010832@1996: 			return;
ch1010832@1996: 	}
ch1010832@1996: 	/* It must be a TCP or UDP packet with a valid checksum */
ch1010832@1996: 	if (likely(status & E1000_RXD_STAT_TCPCS)) {
ch1010832@1996: 		/* TCP checksum is good */
ch1010832@1996: 		skb->ip_summed = CHECKSUM_UNNECESSARY;
ch1010832@1996: 	} else if (hw->mac_type > e1000_82547_rev_2) {
ch1010832@1996: 		/* IP fragment with UDP payload */
ch1010832@1996: 		/* Hardware complements the payload checksum, so we undo it
ch1010832@1996: 		 * and then put the value in host order for further stack use.
ch1010832@1996: 		 */
ch1010832@1996: 		__sum16 sum = (__force __sum16)htons(csum);
ch1010832@1996: 		skb->csum = csum_unfold(~sum);
ch1010832@1996: 		skb->ip_summed = CHECKSUM_COMPLETE;
ch1010832@1996: 	}
ch1010832@1996: 	adapter->hw_csum_good++;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_clean_rx_irq - Send received data up the network stack; legacy
ch1010832@1996:  * @adapter: board private structure
ch1010832@1996:  **/
ch1010832@1996: static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
ch1010832@1996: 			       struct e1000_rx_ring *rx_ring,
ch1010832@1996: 			       int *work_done, int work_to_do)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	struct e1000_rx_desc *rx_desc, *next_rxd;
ch1010832@1996: 	struct e1000_buffer *buffer_info, *next_buffer;
ch1010832@1996: 	unsigned long flags;
ch1010832@1996: 	u32 length;
ch1010832@1996: 	u8 last_byte;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 	int cleaned_count = 0;
ch1010832@1996: 	bool cleaned = false;
ch1010832@1996: 	unsigned int total_rx_bytes=0, total_rx_packets=0;
ch1010832@1996: 
ch1010832@1996: 	i = rx_ring->next_to_clean;
ch1010832@1996: 	rx_desc = E1000_RX_DESC(*rx_ring, i);
ch1010832@1996: 	buffer_info = &rx_ring->buffer_info[i];
ch1010832@1996: 
ch1010832@1996: 	while (rx_desc->status & E1000_RXD_STAT_DD) {
ch1010832@1996: 		struct sk_buff *skb;
ch1010832@1996: 		u8 status;
ch1010832@1996: 
ch1010832@1996: 		if (*work_done >= work_to_do)
ch1010832@1996: 			break;
ch1010832@1996: 		(*work_done)++;
ch1010832@1996: 
ch1010832@1996: 		status = rx_desc->status;
ch1010832@1996: 		skb = buffer_info->skb;
ch1010832@1996: 		buffer_info->skb = NULL;
ch1010832@1996: 
ch1010832@1996: 		prefetch(skb->data - NET_IP_ALIGN);
ch1010832@1996: 
ch1010832@1996: 		if (++i == rx_ring->count) i = 0;
ch1010832@1996: 		next_rxd = E1000_RX_DESC(*rx_ring, i);
ch1010832@1996: 		prefetch(next_rxd);
ch1010832@1996: 
ch1010832@1996: 		next_buffer = &rx_ring->buffer_info[i];
ch1010832@1996: 
ch1010832@1996: 		cleaned = true;
ch1010832@1996: 		cleaned_count++;
ch1010832@1996: 		pci_unmap_single(pdev,
ch1010832@1996: 		                 buffer_info->dma,
ch1010832@1996: 		                 buffer_info->length,
ch1010832@1996: 		                 PCI_DMA_FROMDEVICE);
ch1010832@1996: 		buffer_info->dma = 0;
ch1010832@1996: 
ch1010832@1996: 		length = le16_to_cpu(rx_desc->length);
ch1010832@1996: 		/* !EOP means multiple descriptors were used to store a single
ch1010832@1996: 		 * packet, also make sure the frame isn't just CRC only */
ch1010832@1996: 		if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) {
ch1010832@1996: 			/* All receives must fit into a single buffer */
ch1010832@1996: 			E1000_DBG("%s: Receive packet consumed multiple"
ch1010832@1996: 				  " buffers\n", netdev->name);
ch1010832@1996: 			/* recycle */
ch1010832@1996: 			buffer_info->skb = skb;
ch1010832@1996: 			goto next_desc;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
ch1010832@1996: 			last_byte = *(skb->data + length - 1);
ch1010832@1996: 			if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
ch1010832@1996: 				       last_byte)) {
ch1010832@1996: 				spin_lock_irqsave(&adapter->stats_lock, flags);
ch1010832@1996: 				e1000_tbi_adjust_stats(hw, &adapter->stats,
ch1010832@1996: 				                       length, skb->data);
ch1010832@1996: 				spin_unlock_irqrestore(&adapter->stats_lock,
ch1010832@1996: 				                       flags);
ch1010832@1996: 				length--;
ch1010832@1996: 			} else {
ch1010832@1996: 				/* recycle */
ch1010832@1996: 				buffer_info->skb = skb;
ch1010832@1996: 				goto next_desc;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		/* adjust length to remove Ethernet CRC, this must be
ch1010832@1996: 		 * done after the TBI_ACCEPT workaround above */
ch1010832@1996: 		length -= 4;
ch1010832@1996: 
ch1010832@1996: 		/* probably a little skewed due to removing CRC */
ch1010832@1996: 		total_rx_bytes += length;
ch1010832@1996: 		total_rx_packets++;
ch1010832@1996: 
ch1010832@1996: 		/* code added for copybreak, this should improve
ch1010832@1996: 		 * performance for small packets with large amounts
ch1010832@1996: 		 * of reassembly being done in the stack */
ch1010832@1996: 		if (length < copybreak) {
ch1010832@1996: 			struct sk_buff *new_skb =
ch1010832@1996: 			    netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
ch1010832@1996: 			if (new_skb) {
ch1010832@1996: 				skb_reserve(new_skb, NET_IP_ALIGN);
ch1010832@1996: 				skb_copy_to_linear_data_offset(new_skb,
ch1010832@1996: 							       -NET_IP_ALIGN,
ch1010832@1996: 							       (skb->data -
ch1010832@1996: 							        NET_IP_ALIGN),
ch1010832@1996: 							       (length +
ch1010832@1996: 							        NET_IP_ALIGN));
ch1010832@1996: 				/* save the skb in buffer_info as good */
ch1010832@1996: 				buffer_info->skb = skb;
ch1010832@1996: 				skb = new_skb;
ch1010832@1996: 			}
ch1010832@1996: 			/* else just continue with the old one */
ch1010832@1996: 		}
ch1010832@1996: 		/* end copybreak code */
ch1010832@1996: 		skb_put(skb, length);
ch1010832@1996: 
ch1010832@1996: 		/* Receive Checksum Offload */
ch1010832@1996: 		e1000_rx_checksum(adapter,
ch1010832@1996: 				  (u32)(status) |
ch1010832@1996: 				  ((u32)(rx_desc->errors) << 24),
ch1010832@1996: 				  le16_to_cpu(rx_desc->csum), skb);
ch1010832@1996: 
ch1010832@1996: 		skb->protocol = eth_type_trans(skb, netdev);
ch1010832@1996: 
ch1010832@1996: 		if (unlikely(adapter->vlgrp &&
ch1010832@1996: 			    (status & E1000_RXD_STAT_VP))) {
ch1010832@1996: 			vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
ch1010832@1996: 						 le16_to_cpu(rx_desc->special));
ch1010832@1996: 		} else {
ch1010832@1996: 			netif_receive_skb(skb);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: next_desc:
ch1010832@1996: 		rx_desc->status = 0;
ch1010832@1996: 
ch1010832@1996: 		/* return some buffers to hardware, one at a time is too slow */
ch1010832@1996: 		if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
ch1010832@1996: 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
ch1010832@1996: 			cleaned_count = 0;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		/* use prefetched values */
ch1010832@1996: 		rx_desc = next_rxd;
ch1010832@1996: 		buffer_info = next_buffer;
ch1010832@1996: 	}
ch1010832@1996: 	rx_ring->next_to_clean = i;
ch1010832@1996: 
ch1010832@1996: 	cleaned_count = E1000_DESC_UNUSED(rx_ring);
ch1010832@1996: 	if (cleaned_count)
ch1010832@1996: 		adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
ch1010832@1996: 
ch1010832@1996: 	adapter->total_rx_packets += total_rx_packets;
ch1010832@1996: 	adapter->total_rx_bytes += total_rx_bytes;
ch1010832@1996: 	adapter->net_stats.rx_bytes += total_rx_bytes;
ch1010832@1996: 	adapter->net_stats.rx_packets += total_rx_packets;
ch1010832@1996: 	return cleaned;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
ch1010832@1996:  * @adapter: address of board private structure
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
ch1010832@1996: 				   struct e1000_rx_ring *rx_ring,
ch1010832@1996: 				   int cleaned_count)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct net_device *netdev = adapter->netdev;
ch1010832@1996: 	struct pci_dev *pdev = adapter->pdev;
ch1010832@1996: 	struct e1000_rx_desc *rx_desc;
ch1010832@1996: 	struct e1000_buffer *buffer_info;
ch1010832@1996: 	struct sk_buff *skb;
ch1010832@1996: 	unsigned int i;
ch1010832@1996: 	unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
ch1010832@1996: 
ch1010832@1996: 	i = rx_ring->next_to_use;
ch1010832@1996: 	buffer_info = &rx_ring->buffer_info[i];
ch1010832@1996: 
ch1010832@1996: 	while (cleaned_count--) {
ch1010832@1996: 		skb = buffer_info->skb;
ch1010832@1996: 		if (skb) {
ch1010832@1996: 			skb_trim(skb, 0);
ch1010832@1996: 			goto map_skb;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		skb = netdev_alloc_skb(netdev, bufsz);
ch1010832@1996: 		if (unlikely(!skb)) {
ch1010832@1996: 			/* Better luck next round */
ch1010832@1996: 			adapter->alloc_rx_buff_failed++;
ch1010832@1996: 			break;
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		/* Fix for errata 23, can't cross 64kB boundary */
ch1010832@1996: 		if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
ch1010832@1996: 			struct sk_buff *oldskb = skb;
ch1010832@1996: 			DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
ch1010832@1996: 					     "at %p\n", bufsz, skb->data);
ch1010832@1996: 			/* Try again, without freeing the previous */
ch1010832@1996: 			skb = netdev_alloc_skb(netdev, bufsz);
ch1010832@1996: 			/* Failed allocation, critical failure */
ch1010832@1996: 			if (!skb) {
ch1010832@1996: 				dev_kfree_skb(oldskb);
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
ch1010832@1996: 				/* give up */
ch1010832@1996: 				dev_kfree_skb(skb);
ch1010832@1996: 				dev_kfree_skb(oldskb);
ch1010832@1996: 				break; /* while !buffer_info->skb */
ch1010832@1996: 			}
ch1010832@1996: 
ch1010832@1996: 			/* Use new allocation */
ch1010832@1996: 			dev_kfree_skb(oldskb);
ch1010832@1996: 		}
ch1010832@1996: 		/* Make buffer alignment 2 beyond a 16 byte boundary
ch1010832@1996: 		 * this will result in a 16 byte aligned IP header after
ch1010832@1996: 		 * the 14 byte MAC header is removed
ch1010832@1996: 		 */
ch1010832@1996: 		skb_reserve(skb, NET_IP_ALIGN);
ch1010832@1996: 
ch1010832@1996: 		buffer_info->skb = skb;
ch1010832@1996: 		buffer_info->length = adapter->rx_buffer_len;
ch1010832@1996: map_skb:
ch1010832@1996: 		buffer_info->dma = pci_map_single(pdev,
ch1010832@1996: 						  skb->data,
ch1010832@1996: 						  adapter->rx_buffer_len,
ch1010832@1996: 						  PCI_DMA_FROMDEVICE);
ch1010832@1996: 
ch1010832@1996: 		/* Fix for errata 23, can't cross 64kB boundary */
ch1010832@1996: 		if (!e1000_check_64k_bound(adapter,
ch1010832@1996: 					(void *)(unsigned long)buffer_info->dma,
ch1010832@1996: 					adapter->rx_buffer_len)) {
ch1010832@1996: 			DPRINTK(RX_ERR, ERR,
ch1010832@1996: 				"dma align check failed: %u bytes at %p\n",
ch1010832@1996: 				adapter->rx_buffer_len,
ch1010832@1996: 				(void *)(unsigned long)buffer_info->dma);
ch1010832@1996: 			dev_kfree_skb(skb);
ch1010832@1996: 			buffer_info->skb = NULL;
ch1010832@1996: 
ch1010832@1996: 			pci_unmap_single(pdev, buffer_info->dma,
ch1010832@1996: 					 adapter->rx_buffer_len,
ch1010832@1996: 					 PCI_DMA_FROMDEVICE);
ch1010832@1996: 			buffer_info->dma = 0;
ch1010832@1996: 
ch1010832@1996: 			break; /* while !buffer_info->skb */
ch1010832@1996: 		}
ch1010832@1996: 		rx_desc = E1000_RX_DESC(*rx_ring, i);
ch1010832@1996: 		rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
ch1010832@1996: 
ch1010832@1996: 		if (unlikely(++i == rx_ring->count))
ch1010832@1996: 			i = 0;
ch1010832@1996: 		buffer_info = &rx_ring->buffer_info[i];
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (likely(rx_ring->next_to_use != i)) {
ch1010832@1996: 		rx_ring->next_to_use = i;
ch1010832@1996: 		if (unlikely(i-- == 0))
ch1010832@1996: 			i = (rx_ring->count - 1);
ch1010832@1996: 
ch1010832@1996: 		/* Force memory writes to complete before letting h/w
ch1010832@1996: 		 * know there are new descriptors to fetch.  (Only
ch1010832@1996: 		 * applicable for weak-ordered memory model archs,
ch1010832@1996: 		 * such as IA-64). */
ch1010832@1996: 		wmb();
ch1010832@1996: 		writel(i, hw->hw_addr + rx_ring->rdt);
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
ch1010832@1996:  * @adapter:
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static void e1000_smartspeed(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u16 phy_status;
ch1010832@1996: 	u16 phy_ctrl;
ch1010832@1996: 
ch1010832@1996: 	if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
ch1010832@1996: 	   !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
ch1010832@1996: 		return;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->smartspeed == 0) {
ch1010832@1996: 		/* If Master/Slave config fault is asserted twice,
ch1010832@1996: 		 * we assume back-to-back */
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
ch1010832@1996: 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
ch1010832@1996: 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
ch1010832@1996: 		if (phy_ctrl & CR_1000T_MS_ENABLE) {
ch1010832@1996: 			phy_ctrl &= ~CR_1000T_MS_ENABLE;
ch1010832@1996: 			e1000_write_phy_reg(hw, PHY_1000T_CTRL,
ch1010832@1996: 					    phy_ctrl);
ch1010832@1996: 			adapter->smartspeed++;
ch1010832@1996: 			if (!e1000_phy_setup_autoneg(hw) &&
ch1010832@1996: 			   !e1000_read_phy_reg(hw, PHY_CTRL,
ch1010832@1996: 				   	       &phy_ctrl)) {
ch1010832@1996: 				phy_ctrl |= (MII_CR_AUTO_NEG_EN |
ch1010832@1996: 					     MII_CR_RESTART_AUTO_NEG);
ch1010832@1996: 				e1000_write_phy_reg(hw, PHY_CTRL,
ch1010832@1996: 						    phy_ctrl);
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 		return;
ch1010832@1996: 	} else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
ch1010832@1996: 		/* If still no link, perhaps using 2/3 pair cable */
ch1010832@1996: 		e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
ch1010832@1996: 		phy_ctrl |= CR_1000T_MS_ENABLE;
ch1010832@1996: 		e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
ch1010832@1996: 		if (!e1000_phy_setup_autoneg(hw) &&
ch1010832@1996: 		   !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
ch1010832@1996: 			phy_ctrl |= (MII_CR_AUTO_NEG_EN |
ch1010832@1996: 				     MII_CR_RESTART_AUTO_NEG);
ch1010832@1996: 			e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 	/* Restart process after E1000_SMARTSPEED_MAX iterations */
ch1010832@1996: 	if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
ch1010832@1996: 		adapter->smartspeed = 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_ioctl -
ch1010832@1996:  * @netdev:
ch1010832@1996:  * @ifreq:
ch1010832@1996:  * @cmd:
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
ch1010832@1996: {
ch1010832@1996: 	switch (cmd) {
ch1010832@1996: 	case SIOCGMIIPHY:
ch1010832@1996: 	case SIOCGMIIREG:
ch1010832@1996: 	case SIOCSMIIREG:
ch1010832@1996: 		return e1000_mii_ioctl(netdev, ifr, cmd);
ch1010832@1996: 	default:
ch1010832@1996: 		return -EOPNOTSUPP;
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_mii_ioctl -
ch1010832@1996:  * @netdev:
ch1010832@1996:  * @ifreq:
ch1010832@1996:  * @cmd:
ch1010832@1996:  **/
ch1010832@1996: 
ch1010832@1996: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
ch1010832@1996: 			   int cmd)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	struct mii_ioctl_data *data = if_mii(ifr);
ch1010832@1996: 	int retval;
ch1010832@1996: 	u16 mii_reg;
ch1010832@1996: 	u16 spddplx;
ch1010832@1996: 	unsigned long flags;
ch1010832@1996: 
ch1010832@1996: 	if (hw->media_type != e1000_media_type_copper)
ch1010832@1996: 		return -EOPNOTSUPP;
ch1010832@1996: 
ch1010832@1996: 	switch (cmd) {
ch1010832@1996: 	case SIOCGMIIPHY:
ch1010832@1996: 		data->phy_id = hw->phy_addr;
ch1010832@1996: 		break;
ch1010832@1996: 	case SIOCGMIIREG:
ch1010832@1996: 		if (!capable(CAP_NET_ADMIN))
ch1010832@1996: 			return -EPERM;
ch1010832@1996: 		spin_lock_irqsave(&adapter->stats_lock, flags);
ch1010832@1996: 		if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
ch1010832@1996: 				   &data->val_out)) {
ch1010832@1996: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
ch1010832@1996: 			return -EIO;
ch1010832@1996: 		}
ch1010832@1996: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
ch1010832@1996: 		break;
ch1010832@1996: 	case SIOCSMIIREG:
ch1010832@1996: 		if (!capable(CAP_NET_ADMIN))
ch1010832@1996: 			return -EPERM;
ch1010832@1996: 		if (data->reg_num & ~(0x1F))
ch1010832@1996: 			return -EFAULT;
ch1010832@1996: 		mii_reg = data->val_in;
ch1010832@1996: 		spin_lock_irqsave(&adapter->stats_lock, flags);
ch1010832@1996: 		if (e1000_write_phy_reg(hw, data->reg_num,
ch1010832@1996: 					mii_reg)) {
ch1010832@1996: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
ch1010832@1996: 			return -EIO;
ch1010832@1996: 		}
ch1010832@1996: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
ch1010832@1996: 		if (hw->media_type == e1000_media_type_copper) {
ch1010832@1996: 			switch (data->reg_num) {
ch1010832@1996: 			case PHY_CTRL:
ch1010832@1996: 				if (mii_reg & MII_CR_POWER_DOWN)
ch1010832@1996: 					break;
ch1010832@1996: 				if (mii_reg & MII_CR_AUTO_NEG_EN) {
ch1010832@1996: 					hw->autoneg = 1;
ch1010832@1996: 					hw->autoneg_advertised = 0x2F;
ch1010832@1996: 				} else {
ch1010832@1996: 					if (mii_reg & 0x40)
ch1010832@1996: 						spddplx = SPEED_1000;
ch1010832@1996: 					else if (mii_reg & 0x2000)
ch1010832@1996: 						spddplx = SPEED_100;
ch1010832@1996: 					else
ch1010832@1996: 						spddplx = SPEED_10;
ch1010832@1996: 					spddplx += (mii_reg & 0x100)
ch1010832@1996: 						   ? DUPLEX_FULL :
ch1010832@1996: 						   DUPLEX_HALF;
ch1010832@1996: 					retval = e1000_set_spd_dplx(adapter,
ch1010832@1996: 								    spddplx);
ch1010832@1996: 					if (retval)
ch1010832@1996: 						return retval;
ch1010832@1996: 				}
ch1010832@1996: 				if (netif_running(adapter->netdev))
ch1010832@1996: 					e1000_reinit_locked(adapter);
ch1010832@1996: 				else
ch1010832@1996: 					e1000_reset(adapter);
ch1010832@1996: 				break;
ch1010832@1996: 			case M88E1000_PHY_SPEC_CTRL:
ch1010832@1996: 			case M88E1000_EXT_PHY_SPEC_CTRL:
ch1010832@1996: 				if (e1000_phy_reset(hw))
ch1010832@1996: 					return -EIO;
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 		} else {
ch1010832@1996: 			switch (data->reg_num) {
ch1010832@1996: 			case PHY_CTRL:
ch1010832@1996: 				if (mii_reg & MII_CR_POWER_DOWN)
ch1010832@1996: 					break;
ch1010832@1996: 				if (netif_running(adapter->netdev))
ch1010832@1996: 					e1000_reinit_locked(adapter);
ch1010832@1996: 				else
ch1010832@1996: 					e1000_reset(adapter);
ch1010832@1996: 				break;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 		break;
ch1010832@1996: 	default:
ch1010832@1996: 		return -EOPNOTSUPP;
ch1010832@1996: 	}
ch1010832@1996: 	return E1000_SUCCESS;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_pci_set_mwi(struct e1000_hw *hw)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = hw->back;
ch1010832@1996: 	int ret_val = pci_set_mwi(adapter->pdev);
ch1010832@1996: 
ch1010832@1996: 	if (ret_val)
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Error in setting MWI\n");
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_pci_clear_mwi(struct e1000_hw *hw)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = hw->back;
ch1010832@1996: 
ch1010832@1996: 	pci_clear_mwi(adapter->pdev);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = hw->back;
ch1010832@1996: 	return pcix_get_mmrbc(adapter->pdev);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = hw->back;
ch1010832@1996: 	pcix_set_mmrbc(adapter->pdev, mmrbc);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
ch1010832@1996: {
ch1010832@1996:     struct e1000_adapter *adapter = hw->back;
ch1010832@1996:     u16 cap_offset;
ch1010832@1996: 
ch1010832@1996:     cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
ch1010832@1996:     if (!cap_offset)
ch1010832@1996:         return -E1000_ERR_CONFIG;
ch1010832@1996: 
ch1010832@1996:     pci_read_config_word(adapter->pdev, cap_offset + reg, value);
ch1010832@1996: 
ch1010832@1996:     return E1000_SUCCESS;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
ch1010832@1996: {
ch1010832@1996: 	outl(value, port);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_vlan_rx_register(struct net_device *netdev,
ch1010832@1996: 				   struct vlan_group *grp)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 ctrl, rctl;
ch1010832@1996: 
ch1010832@1996: 	if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 		e1000_irq_disable(adapter);
ch1010832@1996: 	adapter->vlgrp = grp;
ch1010832@1996: 
ch1010832@1996: 	if (grp) {
ch1010832@1996: 		/* enable VLAN tag insert/strip */
ch1010832@1996: 		ctrl = er32(CTRL);
ch1010832@1996: 		ctrl |= E1000_CTRL_VME;
ch1010832@1996: 		ew32(CTRL, ctrl);
ch1010832@1996: 
ch1010832@1996: 		if (adapter->hw.mac_type != e1000_ich8lan) {
ch1010832@1996: 			/* enable VLAN receive filtering */
ch1010832@1996: 			rctl = er32(RCTL);
ch1010832@1996: 			rctl &= ~E1000_RCTL_CFIEN;
ch1010832@1996: 			ew32(RCTL, rctl);
ch1010832@1996: 			e1000_update_mng_vlan(adapter);
ch1010832@1996: 		}
ch1010832@1996: 	} else {
ch1010832@1996: 		/* disable VLAN tag insert/strip */
ch1010832@1996: 		ctrl = er32(CTRL);
ch1010832@1996: 		ctrl &= ~E1000_CTRL_VME;
ch1010832@1996: 		ew32(CTRL, ctrl);
ch1010832@1996: 
ch1010832@1996: 		if (adapter->hw.mac_type != e1000_ich8lan) {
ch1010832@1996: 			if (adapter->mng_vlan_id !=
ch1010832@1996: 			    (u16)E1000_MNG_VLAN_NONE) {
ch1010832@1996: 				e1000_vlan_rx_kill_vid(netdev,
ch1010832@1996: 				                       adapter->mng_vlan_id);
ch1010832@1996: 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
ch1010832@1996: 			}
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 		e1000_irq_enable(adapter);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 vfta, index;
ch1010832@1996: 
ch1010832@1996: 	if ((hw->mng_cookie.status &
ch1010832@1996: 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
ch1010832@1996: 	    (vid == adapter->mng_vlan_id))
ch1010832@1996: 		return;
ch1010832@1996: 	/* add VID to filter table */
ch1010832@1996: 	index = (vid >> 5) & 0x7F;
ch1010832@1996: 	vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
ch1010832@1996: 	vfta |= (1 << (vid & 0x1F));
ch1010832@1996: 	e1000_write_vfta(hw, index, vfta);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 vfta, index;
ch1010832@1996: 
ch1010832@1996: 	if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 		e1000_irq_disable(adapter);
ch1010832@1996: 	vlan_group_set_device(adapter->vlgrp, vid, NULL);
ch1010832@1996: 	if (!test_bit(__E1000_DOWN, &adapter->flags))
ch1010832@1996: 		e1000_irq_enable(adapter);
ch1010832@1996: 
ch1010832@1996: 	if ((hw->mng_cookie.status &
ch1010832@1996: 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
ch1010832@1996: 	    (vid == adapter->mng_vlan_id)) {
ch1010832@1996: 		/* release control to f/w */
ch1010832@1996: 		e1000_release_hw_control(adapter);
ch1010832@1996: 		return;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	/* remove VID from filter table */
ch1010832@1996: 	index = (vid >> 5) & 0x7F;
ch1010832@1996: 	vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
ch1010832@1996: 	vfta &= ~(1 << (vid & 0x1F));
ch1010832@1996: 	e1000_write_vfta(hw, index, vfta);
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static void e1000_restore_vlan(struct e1000_adapter *adapter)
ch1010832@1996: {
ch1010832@1996: 	e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
ch1010832@1996: 
ch1010832@1996: 	if (adapter->vlgrp) {
ch1010832@1996: 		u16 vid;
ch1010832@1996: 		for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
ch1010832@1996: 			if (!vlan_group_get_device(adapter->vlgrp, vid))
ch1010832@1996: 				continue;
ch1010832@1996: 			e1000_vlan_rx_add_vid(adapter->netdev, vid);
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	hw->autoneg = 0;
ch1010832@1996: 
ch1010832@1996: 	/* Fiber NICs only allow 1000 gbps Full duplex */
ch1010832@1996: 	if ((hw->media_type == e1000_media_type_fiber) &&
ch1010832@1996: 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
ch1010832@1996: 		return -EINVAL;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	switch (spddplx) {
ch1010832@1996: 	case SPEED_10 + DUPLEX_HALF:
ch1010832@1996: 		hw->forced_speed_duplex = e1000_10_half;
ch1010832@1996: 		break;
ch1010832@1996: 	case SPEED_10 + DUPLEX_FULL:
ch1010832@1996: 		hw->forced_speed_duplex = e1000_10_full;
ch1010832@1996: 		break;
ch1010832@1996: 	case SPEED_100 + DUPLEX_HALF:
ch1010832@1996: 		hw->forced_speed_duplex = e1000_100_half;
ch1010832@1996: 		break;
ch1010832@1996: 	case SPEED_100 + DUPLEX_FULL:
ch1010832@1996: 		hw->forced_speed_duplex = e1000_100_full;
ch1010832@1996: 		break;
ch1010832@1996: 	case SPEED_1000 + DUPLEX_FULL:
ch1010832@1996: 		hw->autoneg = 1;
ch1010832@1996: 		hw->autoneg_advertised = ADVERTISE_1000_FULL;
ch1010832@1996: 		break;
ch1010832@1996: 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
ch1010832@1996: 	default:
ch1010832@1996: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
ch1010832@1996: 		return -EINVAL;
ch1010832@1996: 	}
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 ctrl, ctrl_ext, rctl, status;
ch1010832@1996: 	u32 wufc = adapter->wol;
ch1010832@1996: #ifdef CONFIG_PM
ch1010832@1996: 	int retval = 0;
ch1010832@1996: #endif
ch1010832@1996: 
ch1010832@1996: 	netif_device_detach(netdev);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev)) {
ch1010832@1996: 		WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
ch1010832@1996: 		e1000_down(adapter);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: #ifdef CONFIG_PM
ch1010832@1996: 	retval = pci_save_state(pdev);
ch1010832@1996: 	if (retval)
ch1010832@1996: 		return retval;
ch1010832@1996: #endif
ch1010832@1996: 
ch1010832@1996: 	status = er32(STATUS);
ch1010832@1996: 	if (status & E1000_STATUS_LU)
ch1010832@1996: 		wufc &= ~E1000_WUFC_LNKC;
ch1010832@1996: 
ch1010832@1996: 	if (wufc) {
ch1010832@1996: 		e1000_setup_rctl(adapter);
ch1010832@1996: 		e1000_set_rx_mode(netdev);
ch1010832@1996: 
ch1010832@1996: 		/* turn on all-multi mode if wake on multicast is enabled */
ch1010832@1996: 		if (wufc & E1000_WUFC_MC) {
ch1010832@1996: 			rctl = er32(RCTL);
ch1010832@1996: 			rctl |= E1000_RCTL_MPE;
ch1010832@1996: 			ew32(RCTL, rctl);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if (hw->mac_type >= e1000_82540) {
ch1010832@1996: 			ctrl = er32(CTRL);
ch1010832@1996: 			/* advertise wake from D3Cold */
ch1010832@1996: 			#define E1000_CTRL_ADVD3WUC 0x00100000
ch1010832@1996: 			/* phy power management enable */
ch1010832@1996: 			#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
ch1010832@1996: 			ctrl |= E1000_CTRL_ADVD3WUC |
ch1010832@1996: 				E1000_CTRL_EN_PHY_PWR_MGMT;
ch1010832@1996: 			ew32(CTRL, ctrl);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		if (hw->media_type == e1000_media_type_fiber ||
ch1010832@1996: 		   hw->media_type == e1000_media_type_internal_serdes) {
ch1010832@1996: 			/* keep the laser running in D3 */
ch1010832@1996: 			ctrl_ext = er32(CTRL_EXT);
ch1010832@1996: 			ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
ch1010832@1996: 			ew32(CTRL_EXT, ctrl_ext);
ch1010832@1996: 		}
ch1010832@1996: 
ch1010832@1996: 		/* Allow time for pending master requests to run */
ch1010832@1996: 		e1000_disable_pciex_master(hw);
ch1010832@1996: 
ch1010832@1996: 		ew32(WUC, E1000_WUC_PME_EN);
ch1010832@1996: 		ew32(WUFC, wufc);
ch1010832@1996: 	} else {
ch1010832@1996: 		ew32(WUC, 0);
ch1010832@1996: 		ew32(WUFC, 0);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_release_manageability(adapter);
ch1010832@1996: 
ch1010832@1996: 	*enable_wake = !!wufc;
ch1010832@1996: 
ch1010832@1996: 	/* make sure adapter isn't asleep if manageability is enabled */
ch1010832@1996: 	if (adapter->en_mng_pt)
ch1010832@1996: 		*enable_wake = true;
ch1010832@1996: 
ch1010832@1996: 	if (hw->phy_type == e1000_phy_igp_3)
ch1010832@1996: 		e1000_phy_powerdown_workaround(hw);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev))
ch1010832@1996: 		e1000_free_irq(adapter);
ch1010832@1996: 
ch1010832@1996: 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
ch1010832@1996: 	 * would have already happened in close and is redundant. */
ch1010832@1996: 	e1000_release_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	pci_disable_device(pdev);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #ifdef CONFIG_PM
ch1010832@1996: static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
ch1010832@1996: {
ch1010832@1996: 	int retval;
ch1010832@1996: 	bool wake;
ch1010832@1996: 
ch1010832@1996: 	retval = __e1000_shutdown(pdev, &wake);
ch1010832@1996: 	if (retval)
ch1010832@1996: 		return retval;
ch1010832@1996: 
ch1010832@1996: 	if (wake) {
ch1010832@1996: 		pci_prepare_to_sleep(pdev);
ch1010832@1996: 	} else {
ch1010832@1996: 		pci_wake_from_d3(pdev, false);
ch1010832@1996: 		pci_set_power_state(pdev, PCI_D3hot);
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: static int e1000_resume(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	u32 err;
ch1010832@1996: 
ch1010832@1996: 	pci_set_power_state(pdev, PCI_D0);
ch1010832@1996: 	pci_restore_state(pdev);
ch1010832@1996: 
ch1010832@1996: 	if (adapter->need_ioport)
ch1010832@1996: 		err = pci_enable_device(pdev);
ch1010832@1996: 	else
ch1010832@1996: 		err = pci_enable_device_mem(pdev);
ch1010832@1996: 	if (err) {
ch1010832@1996: 		printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
ch1010832@1996: 		return err;
ch1010832@1996: 	}
ch1010832@1996: 	pci_set_master(pdev);
ch1010832@1996: 
ch1010832@1996: 	pci_enable_wake(pdev, PCI_D3hot, 0);
ch1010832@1996: 	pci_enable_wake(pdev, PCI_D3cold, 0);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev)) {
ch1010832@1996: 		err = e1000_request_irq(adapter);
ch1010832@1996: 		if (err)
ch1010832@1996: 			return err;
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	e1000_power_up_phy(adapter);
ch1010832@1996: 	e1000_reset(adapter);
ch1010832@1996: 	ew32(WUS, ~0);
ch1010832@1996: 
ch1010832@1996: 	e1000_init_manageability(adapter);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev))
ch1010832@1996: 		e1000_up(adapter);
ch1010832@1996: 
ch1010832@1996: 	netif_device_attach(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* If the controller is 82573 and f/w is AMT, do not set
ch1010832@1996: 	 * DRV_LOAD until the interface is up.  For all other cases,
ch1010832@1996: 	 * let the f/w know that the h/w is now under the control
ch1010832@1996: 	 * of the driver. */
ch1010832@1996: 	if (hw->mac_type != e1000_82573 ||
ch1010832@1996: 	    !e1000_check_mng_mode(hw))
ch1010832@1996: 		e1000_get_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: 	return 0;
ch1010832@1996: }
ch1010832@1996: #endif
ch1010832@1996: 
ch1010832@1996: static void e1000_shutdown(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	bool wake;
ch1010832@1996: 
ch1010832@1996: 	__e1000_shutdown(pdev, &wake);
ch1010832@1996: 
ch1010832@1996: 	if (system_state == SYSTEM_POWER_OFF) {
ch1010832@1996: 		pci_wake_from_d3(pdev, wake);
ch1010832@1996: 		pci_set_power_state(pdev, PCI_D3hot);
ch1010832@1996: 	}
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: #ifdef CONFIG_NET_POLL_CONTROLLER
ch1010832@1996: /*
ch1010832@1996:  * Polling 'interrupt' - used by things like netconsole to send skbs
ch1010832@1996:  * without having to re-enable interrupts. It's not called while
ch1010832@1996:  * the interrupt routine is executing.
ch1010832@1996:  */
ch1010832@1996: static void e1000_netpoll(struct net_device *netdev)
ch1010832@1996: {
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 
ch1010832@1996: 	disable_irq(adapter->pdev->irq);
ch1010832@1996: 	e1000_intr(adapter->pdev->irq, netdev);
ch1010832@1996: 	enable_irq(adapter->pdev->irq);
ch1010832@1996: }
ch1010832@1996: #endif
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_io_error_detected - called when PCI error is detected
ch1010832@1996:  * @pdev: Pointer to PCI device
ch1010832@1996:  * @state: The current pci conneection state
ch1010832@1996:  *
ch1010832@1996:  * This function is called after a PCI bus error affecting
ch1010832@1996:  * this device has been detected.
ch1010832@1996:  */
ch1010832@1996: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
ch1010832@1996: 						pci_channel_state_t state)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 
ch1010832@1996: 	netif_device_detach(netdev);
ch1010832@1996: 
ch1010832@1996: 	if (state == pci_channel_io_perm_failure)
ch1010832@1996: 		return PCI_ERS_RESULT_DISCONNECT;
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev))
ch1010832@1996: 		e1000_down(adapter);
ch1010832@1996: 	pci_disable_device(pdev);
ch1010832@1996: 
ch1010832@1996: 	/* Request a slot slot reset. */
ch1010832@1996: 	return PCI_ERS_RESULT_NEED_RESET;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_io_slot_reset - called after the pci bus has been reset.
ch1010832@1996:  * @pdev: Pointer to PCI device
ch1010832@1996:  *
ch1010832@1996:  * Restart the card from scratch, as if from a cold-boot. Implementation
ch1010832@1996:  * resembles the first-half of the e1000_resume routine.
ch1010832@1996:  */
ch1010832@1996: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 	int err;
ch1010832@1996: 
ch1010832@1996: 	if (adapter->need_ioport)
ch1010832@1996: 		err = pci_enable_device(pdev);
ch1010832@1996: 	else
ch1010832@1996: 		err = pci_enable_device_mem(pdev);
ch1010832@1996: 	if (err) {
ch1010832@1996: 		printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
ch1010832@1996: 		return PCI_ERS_RESULT_DISCONNECT;
ch1010832@1996: 	}
ch1010832@1996: 	pci_set_master(pdev);
ch1010832@1996: 
ch1010832@1996: 	pci_enable_wake(pdev, PCI_D3hot, 0);
ch1010832@1996: 	pci_enable_wake(pdev, PCI_D3cold, 0);
ch1010832@1996: 
ch1010832@1996: 	e1000_reset(adapter);
ch1010832@1996: 	ew32(WUS, ~0);
ch1010832@1996: 
ch1010832@1996: 	return PCI_ERS_RESULT_RECOVERED;
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /**
ch1010832@1996:  * e1000_io_resume - called when traffic can start flowing again.
ch1010832@1996:  * @pdev: Pointer to PCI device
ch1010832@1996:  *
ch1010832@1996:  * This callback is called when the error recovery driver tells us that
ch1010832@1996:  * its OK to resume normal operation. Implementation resembles the
ch1010832@1996:  * second-half of the e1000_resume routine.
ch1010832@1996:  */
ch1010832@1996: static void e1000_io_resume(struct pci_dev *pdev)
ch1010832@1996: {
ch1010832@1996: 	struct net_device *netdev = pci_get_drvdata(pdev);
ch1010832@1996: 	struct e1000_adapter *adapter = netdev_priv(netdev);
ch1010832@1996: 	struct e1000_hw *hw = &adapter->hw;
ch1010832@1996: 
ch1010832@1996: 	e1000_init_manageability(adapter);
ch1010832@1996: 
ch1010832@1996: 	if (netif_running(netdev)) {
ch1010832@1996: 		if (e1000_up(adapter)) {
ch1010832@1996: 			printk("e1000: can't bring device back up after reset\n");
ch1010832@1996: 			return;
ch1010832@1996: 		}
ch1010832@1996: 	}
ch1010832@1996: 
ch1010832@1996: 	netif_device_attach(netdev);
ch1010832@1996: 
ch1010832@1996: 	/* If the controller is 82573 and f/w is AMT, do not set
ch1010832@1996: 	 * DRV_LOAD until the interface is up.  For all other cases,
ch1010832@1996: 	 * let the f/w know that the h/w is now under the control
ch1010832@1996: 	 * of the driver. */
ch1010832@1996: 	if (hw->mac_type != e1000_82573 ||
ch1010832@1996: 	    !e1000_check_mng_mode(hw))
ch1010832@1996: 		e1000_get_hw_control(adapter);
ch1010832@1996: 
ch1010832@1996: }
ch1010832@1996: 
ch1010832@1996: /* e1000_main.c */