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