fp@667: /*******************************************************************************
fp@667: 
fp@667:   
fp@667:   Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
fp@667:   
fp@667:   This program is free software; you can redistribute it and/or modify it 
fp@667:   under the terms of the GNU General Public License as published by the Free 
fp@667:   Software Foundation; either version 2 of the License, or (at your option) 
fp@667:   any later version.
fp@667:   
fp@667:   This program is distributed in the hope that it will be useful, but WITHOUT 
fp@667:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
fp@667:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
fp@667:   more details.
fp@667:   
fp@667:   You should have received a copy of the GNU General Public License along with
fp@667:   this program; if not, write to the Free Software Foundation, Inc., 59 
fp@667:   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
fp@667:   
fp@667:   The full GNU General Public License is included in this distribution in the
fp@667:   file called LICENSE.
fp@667:   
fp@667:   Contact Information:
fp@667:   Linux NICS <linux.nics@intel.com>
fp@667:   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
fp@667:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@667: 
fp@667: *******************************************************************************/
fp@667: 
fp@667: #include "e1000-2.6.18-ethercat.h"
fp@667: 
fp@667: char e1000_driver_name[] = "ec_e1000";
fp@667: static char e1000_driver_string[] = "EtherCAT Intel(R) PRO/1000 Network Driver";
fp@667: #ifndef CONFIG_E1000_NAPI
fp@667: #define DRIVERNAPI
fp@667: #else
fp@667: #define DRIVERNAPI "-NAPI"
fp@667: #endif
fp@667: #define DRV_VERSION "7.1.9-k4"DRIVERNAPI
fp@667: char e1000_driver_version[] = DRV_VERSION;
fp@667: static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
fp@667: 
fp@667: /* e1000_pci_tbl - PCI Device ID Table
fp@667:  *
fp@667:  * Last entry must be all 0s
fp@667:  *
fp@667:  * Macro expands to...
fp@667:  *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
fp@667:  */
fp@667: static struct pci_device_id e1000_pci_tbl[] = {
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1000),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1001),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1004),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1008),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1009),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x100C),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x100D),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x100E),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x100F),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1010),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1011),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1012),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1013),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1014),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1015),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1016),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1017),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1018),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1019),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x101A),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x101D),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x101E),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1026),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1027),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1028),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1049),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x104A),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x104B),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x104C),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x104D),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x105E),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x105F),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1060),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1075),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1076),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1077),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1078),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1079),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107A),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107B),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107C),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107D),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107E),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x107F),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x108A),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x108B),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x108C),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1096),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1098),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x1099),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x109A),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x10B5),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x10B9),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x10BA),
fp@667: 	INTEL_E1000_ETHERNET_DEVICE(0x10BB),
fp@667: 	/* required last entry */
fp@667: 	{0,}
fp@667: };
fp@667: 
fp@667: // do not auto-load driver
fp@667: // MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
fp@667: 
fp@667: static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_tx_ring *txdr);
fp@667: static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_rx_ring *rxdr);
fp@667: static void e1000_free_tx_resources(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_tx_ring *tx_ring);
fp@667: static void e1000_free_rx_resources(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_rx_ring *rx_ring);
fp@667: 
fp@667: /* Local Function Prototypes */
fp@667: 
fp@667: static int e1000_init_module(void);
fp@667: static void e1000_exit_module(void);
fp@667: static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
fp@667: static void __devexit e1000_remove(struct pci_dev *pdev);
fp@667: static int e1000_alloc_queues(struct e1000_adapter *adapter);
fp@667: static int e1000_sw_init(struct e1000_adapter *adapter);
fp@667: static int e1000_open(struct net_device *netdev);
fp@667: static int e1000_close(struct net_device *netdev);
fp@667: static void e1000_configure_tx(struct e1000_adapter *adapter);
fp@667: static void e1000_configure_rx(struct e1000_adapter *adapter);
fp@667: static void e1000_setup_rctl(struct e1000_adapter *adapter);
fp@667: static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
fp@667: static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
fp@667: static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
fp@667:                                 struct e1000_tx_ring *tx_ring);
fp@667: static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
fp@667:                                 struct e1000_rx_ring *rx_ring);
fp@667: static void e1000_set_multi(struct net_device *netdev);
fp@667: static void e1000_update_phy_info(unsigned long data);
fp@667: static void e1000_watchdog(unsigned long data);
fp@667: static void e1000_82547_tx_fifo_stall(unsigned long data);
fp@667: static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
fp@667: static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
fp@667: static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
fp@667: static int e1000_set_mac(struct net_device *netdev, void *p);
fp@671: void ec_poll(struct net_device *);
fp@667: static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
fp@667: static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_tx_ring *tx_ring);
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: static int e1000_clean(struct net_device *poll_dev, int *budget);
fp@667: static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_rx_ring *rx_ring,
fp@667:                                     int *work_done, int work_to_do);
fp@667: static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
fp@667:                                        struct e1000_rx_ring *rx_ring,
fp@667:                                        int *work_done, int work_to_do);
fp@667: #else
fp@667: static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
fp@667:                                     struct e1000_rx_ring *rx_ring);
fp@667: static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
fp@667:                                        struct e1000_rx_ring *rx_ring);
fp@667: #endif
fp@667: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
fp@667:                                    struct e1000_rx_ring *rx_ring,
fp@667: 				   int cleaned_count);
fp@667: static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
fp@667:                                       struct e1000_rx_ring *rx_ring,
fp@667: 				      int cleaned_count);
fp@667: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
fp@667: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
fp@667: 			   int cmd);
fp@667: static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
fp@667: static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
fp@667: static void e1000_tx_timeout(struct net_device *dev);
fp@667: static void e1000_reset_task(struct net_device *dev);
fp@667: static void e1000_smartspeed(struct e1000_adapter *adapter);
fp@667: static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
fp@667:                                        struct sk_buff *skb);
fp@667: 
fp@667: static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
fp@667: static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
fp@667: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
fp@667: static void e1000_restore_vlan(struct e1000_adapter *adapter);
fp@667: 
fp@667: static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
fp@667: #ifdef CONFIG_PM
fp@667: static int e1000_resume(struct pci_dev *pdev);
fp@667: #endif
fp@667: static void e1000_shutdown(struct pci_dev *pdev);
fp@667: 
fp@667: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@667: /* for netdump / net console */
fp@667: static void e1000_netpoll (struct net_device *netdev);
fp@667: #endif
fp@667: 
fp@667: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
fp@667:                      pci_channel_state_t state);
fp@667: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
fp@667: static void e1000_io_resume(struct pci_dev *pdev);
fp@667: 
fp@667: static struct pci_error_handlers e1000_err_handler = {
fp@667: 	.error_detected = e1000_io_error_detected,
fp@667: 	.slot_reset = e1000_io_slot_reset,
fp@667: 	.resume = e1000_io_resume,
fp@667: };
fp@667: 
fp@667: static struct pci_driver e1000_driver = {
fp@667: 	.name     = e1000_driver_name,
fp@667: 	.id_table = e1000_pci_tbl,
fp@667: 	.probe    = e1000_probe,
fp@667: 	.remove   = __devexit_p(e1000_remove),
fp@667: 	/* Power Managment Hooks */
fp@667: 	.suspend  = e1000_suspend,
fp@667: #ifdef CONFIG_PM
fp@667: 	.resume   = e1000_resume,
fp@667: #endif
fp@667: 	.shutdown = e1000_shutdown,
fp@667: 	.err_handler = &e1000_err_handler
fp@667: };
fp@667: 
fp@667: MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
fp@667: MODULE_DESCRIPTION("EtherCAT-capable Intel(R) PRO/1000 Network Driver");
fp@667: MODULE_LICENSE("GPL");
fp@667: MODULE_VERSION(DRV_VERSION);
fp@667: 
fp@667: static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
fp@667: module_param(debug, int, 0);
fp@667: MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
fp@667: 
fp@667: /**
fp@667:  * e1000_init_module - Driver Registration Routine
fp@667:  *
fp@667:  * e1000_init_module is the first routine called when the driver is
fp@667:  * loaded. All it does is register with the PCI subsystem.
fp@667:  **/
fp@667: 
fp@667: static int __init
fp@667: e1000_init_module(void)
fp@667: {
fp@667: 	int ret;
fp@667: 	printk(KERN_INFO "%s - version %s\n",
fp@667: 	       e1000_driver_string, e1000_driver_version);
fp@667: 
fp@667: 	printk(KERN_INFO "%s\n", e1000_copyright);
fp@667: 
fp@667: 	ret = pci_module_init(&e1000_driver);
fp@667: 
fp@667: 	return ret;
fp@667: }
fp@667: 
fp@667: module_init(e1000_init_module);
fp@667: 
fp@667: /**
fp@667:  * e1000_exit_module - Driver Exit Cleanup Routine
fp@667:  *
fp@667:  * e1000_exit_module is called just before the driver is removed
fp@667:  * from memory.
fp@667:  **/
fp@667: 
fp@667: static void __exit
fp@667: e1000_exit_module(void)
fp@667: {
fp@667: 	pci_unregister_driver(&e1000_driver);
fp@667: }
fp@667: 
fp@667: module_exit(e1000_exit_module);
fp@667: 
fp@667: static int e1000_request_irq(struct e1000_adapter *adapter) // not called when EtherCAT
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	int flags, err = 0;
fp@667: 
fp@667: 	flags = IRQF_SHARED;
fp@667: #ifdef CONFIG_PCI_MSI
fp@667: 	if (adapter->hw.mac_type > e1000_82547_rev_2) {
fp@667: 		adapter->have_msi = TRUE;
fp@667: 		if ((err = pci_enable_msi(adapter->pdev))) {
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 			 "Unable to allocate MSI interrupt Error: %d\n", err);
fp@667: 			adapter->have_msi = FALSE;
fp@667: 		}
fp@667: 	}
fp@667: 	if (adapter->have_msi)
fp@667: 		flags &= ~IRQF_SHARED;
fp@667: #endif
fp@667: 	if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
fp@667: 	                       netdev->name, netdev)))
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		        "Unable to allocate interrupt Error: %d\n", err);
fp@667: 
fp@667: 	return err;
fp@667: }
fp@667: 
fp@671: static void e1000_free_irq(struct e1000_adapter *adapter) // not called when EtherCAT
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 
fp@667: 	free_irq(adapter->pdev->irq, netdev);
fp@667: 
fp@667: #ifdef CONFIG_PCI_MSI
fp@667: 	if (adapter->have_msi)
fp@667: 		pci_disable_msi(adapter->pdev);
fp@667: #endif
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_irq_disable - Mask off interrupt generation on the NIC
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_irq_disable(struct e1000_adapter *adapter)
fp@667: {
fp@678:     if (adapter->ecdev)
fp@678:         return;
fp@667: 	atomic_inc(&adapter->irq_sem);
fp@667: 	E1000_WRITE_REG(&adapter->hw, IMC, ~0);
fp@667: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@667: 	synchronize_irq(adapter->pdev->irq);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_irq_enable - Enable default interrupt generation settings
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_irq_enable(struct e1000_adapter *adapter)
fp@667: {
fp@678:     if (adapter->ecdev)
fp@678:         return;
fp@678: 	if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
fp@667: 		E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
fp@667: 		E1000_WRITE_FLUSH(&adapter->hw);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_update_mng_vlan(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	uint16_t vid = adapter->hw.mng_cookie.vlan_id;
fp@667: 	uint16_t old_vid = adapter->mng_vlan_id;
fp@667: 	if (adapter->vlgrp) {
fp@667: 		if (!adapter->vlgrp->vlan_devices[vid]) {
fp@667: 			if (adapter->hw.mng_cookie.status &
fp@667: 				E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
fp@667: 				e1000_vlan_rx_add_vid(netdev, vid);
fp@667: 				adapter->mng_vlan_id = vid;
fp@667: 			} else
fp@667: 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@667: 
fp@667: 			if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
fp@667: 					(vid != old_vid) &&
fp@667: 					!adapter->vlgrp->vlan_devices[old_vid])
fp@667: 				e1000_vlan_rx_kill_vid(netdev, old_vid);
fp@667: 		} else
fp@667: 			adapter->mng_vlan_id = vid;
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_release_hw_control - release control of the h/w to f/w
fp@667:  * @adapter: address of board private structure
fp@667:  *
fp@667:  * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
fp@667:  * For ASF and Pass Through versions of f/w this means that the
fp@667:  * driver is no longer loaded. For AMT version (only with 82573) i
fp@667:  * of the f/w this means that the netowrk i/f is closed.
fp@667:  *
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_release_hw_control(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint32_t ctrl_ext;
fp@667: 	uint32_t swsm;
fp@667: 	uint32_t extcnf;
fp@667: 
fp@667: 	/* Let firmware taken over control of h/w */
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_82571:
fp@667: 	case e1000_82572:
fp@667: 	case e1000_80003es2lan:
fp@667: 		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
fp@667: 		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
fp@667: 				ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
fp@667: 		break;
fp@667: 	case e1000_82573:
fp@667: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@667: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@667: 				swsm & ~E1000_SWSM_DRV_LOAD);
fp@667: 	case e1000_ich8lan:
fp@667: 		extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
fp@667: 		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
fp@667: 				extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
fp@667: 		break;
fp@667: 	default:
fp@667: 		break;
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_get_hw_control - get control of the h/w from f/w
fp@667:  * @adapter: address of board private structure
fp@667:  *
fp@667:  * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
fp@667:  * For ASF and Pass Through versions of f/w this means that
fp@667:  * the driver is loaded. For AMT version (only with 82573)
fp@667:  * of the f/w this means that the netowrk i/f is open.
fp@667:  *
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_get_hw_control(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint32_t ctrl_ext;
fp@667: 	uint32_t swsm;
fp@667: 	uint32_t extcnf;
fp@667: 	/* Let firmware know the driver has taken over */
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_82571:
fp@667: 	case e1000_82572:
fp@667: 	case e1000_80003es2lan:
fp@667: 		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
fp@667: 		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
fp@667: 				ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
fp@667: 		break;
fp@667: 	case e1000_82573:
fp@667: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@667: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@667: 				swsm | E1000_SWSM_DRV_LOAD);
fp@667: 		break;
fp@667: 	case e1000_ich8lan:
fp@667: 		extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
fp@667: 		E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
fp@667: 				extcnf | E1000_EXTCNF_CTRL_SWFLAG);
fp@667: 		break;
fp@667: 	default:
fp@667: 		break;
fp@667: 	}
fp@667: }
fp@667: 
fp@667: int
fp@667: e1000_up(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	int i;
fp@667: 
fp@667: 	/* hardware has been reset, we need to reload some things */
fp@667: 
fp@667: 	e1000_set_multi(netdev);
fp@667: 
fp@667: 	e1000_restore_vlan(adapter);
fp@667: 
fp@667: 	e1000_configure_tx(adapter);
fp@667: 	e1000_setup_rctl(adapter);
fp@667: 	e1000_configure_rx(adapter);
fp@667: 	/* call E1000_DESC_UNUSED which always leaves
fp@667: 	 * at least 1 descriptor unused to make sure
fp@667: 	 * next_to_use != next_to_clean */
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++) {
fp@667: 		struct e1000_rx_ring *ring = &adapter->rx_ring[i];
fp@667: 		adapter->alloc_rx_buf(adapter, ring,
fp@667: 		                      E1000_DESC_UNUSED(ring));
fp@667: 	}
fp@667: 
fp@667: 	adapter->tx_queue_len = netdev->tx_queue_len;
fp@667: 
fp@678: 	if (!adapter->ecdev) {
fp@678: 		mod_timer(&adapter->watchdog_timer, jiffies);
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@678:         netif_poll_enable(netdev);
fp@667: #endif
fp@678:         e1000_irq_enable(adapter);
fp@678:     }
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_power_up_phy - restore link in case the phy was powered down
fp@667:  * @adapter: address of board private structure
fp@667:  *
fp@667:  * The phy may be powered down to save power and turn off link when the
fp@667:  * driver is unloaded and wake on lan is not enabled (among others)
fp@667:  * *** this routine MUST be followed by a call to e1000_reset ***
fp@667:  *
fp@667:  **/
fp@667: 
fp@667: static void e1000_power_up_phy(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint16_t mii_reg = 0;
fp@667: 
fp@667: 	/* Just clear the power down bit to wake the phy back up */
fp@667: 	if (adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 		/* according to the manual, the phy will retain its
fp@667: 		 * settings across a power-down/up cycle */
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
fp@667: 		mii_reg &= ~MII_CR_POWER_DOWN;
fp@667: 		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: static void e1000_power_down_phy(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
fp@667: 	                              e1000_check_mng_mode(&adapter->hw);
fp@667: 	/* Power down the PHY so no link is implied when interface is down
fp@667: 	 * The PHY cannot be powered down if any of the following is TRUE
fp@667: 	 * (a) WoL is enabled
fp@667: 	 * (b) AMT is active
fp@667: 	 * (c) SoL/IDER session is active */
fp@667: 	if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
fp@667: 	    adapter->hw.mac_type != e1000_ich8lan &&
fp@667: 	    adapter->hw.media_type == e1000_media_type_copper &&
fp@667: 	    !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
fp@667: 	    !mng_mode_enabled &&
fp@667: 	    !e1000_check_phy_reset_block(&adapter->hw)) {
fp@667: 		uint16_t mii_reg = 0;
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
fp@667: 		mii_reg |= MII_CR_POWER_DOWN;
fp@667: 		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
fp@667: 		mdelay(1);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_down(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 
fp@678:     if (!adapter->ecdev) {
fp@678:         e1000_irq_disable(adapter);
fp@678: 
fp@678:         del_timer_sync(&adapter->tx_fifo_stall_timer);
fp@678:         del_timer_sync(&adapter->watchdog_timer);
fp@678:         del_timer_sync(&adapter->phy_info_timer);
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@678:         netif_poll_disable(netdev);
fp@667: #endif
fp@678: 		netdev->tx_queue_len = adapter->tx_queue_len;
fp@678:     }
fp@667: 	adapter->link_speed = 0;
fp@667: 	adapter->link_duplex = 0;
fp@667: 	if (!adapter->ecdev) {
fp@667: 		netif_carrier_off(netdev);
fp@667: 		netif_stop_queue(netdev);
fp@667: 	}
fp@667: 
fp@667: 	e1000_reset(adapter);
fp@667: 	e1000_clean_all_tx_rings(adapter);
fp@667: 	e1000_clean_all_rx_rings(adapter);
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_reinit_locked(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	WARN_ON(in_interrupt());
fp@667: 	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
fp@667: 		msleep(1);
fp@667: 	e1000_down(adapter);
fp@667: 	e1000_up(adapter);
fp@667: 	clear_bit(__E1000_RESETTING, &adapter->flags);
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_reset(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint32_t pba, manc;
fp@667: 	uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
fp@667: 
fp@667: 	/* Repartition Pba for greater than 9k mtu
fp@667: 	 * To take effect CTRL.RST is required.
fp@667: 	 */
fp@667: 
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_82547:
fp@667: 	case e1000_82547_rev_2:
fp@667: 		pba = E1000_PBA_30K;
fp@667: 		break;
fp@667: 	case e1000_82571:
fp@667: 	case e1000_82572:
fp@667: 	case e1000_80003es2lan:
fp@667: 		pba = E1000_PBA_38K;
fp@667: 		break;
fp@667: 	case e1000_82573:
fp@667: 		pba = E1000_PBA_12K;
fp@667: 		break;
fp@667: 	case e1000_ich8lan:
fp@667: 		pba = E1000_PBA_8K;
fp@667: 		break;
fp@667: 	default:
fp@667: 		pba = E1000_PBA_48K;
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@667: 	if ((adapter->hw.mac_type != e1000_82573) &&
fp@667: 	   (adapter->netdev->mtu > E1000_RXBUFFER_8192))
fp@667: 		pba -= 8; /* allocate more FIFO for Tx */
fp@667: 
fp@667: 
fp@667: 	if (adapter->hw.mac_type == e1000_82547) {
fp@667: 		adapter->tx_fifo_head = 0;
fp@667: 		adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
fp@667: 		adapter->tx_fifo_size =
fp@667: 			(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
fp@667: 		atomic_set(&adapter->tx_fifo_stall, 0);
fp@667: 	}
fp@667: 
fp@667: 	E1000_WRITE_REG(&adapter->hw, PBA, pba);
fp@667: 
fp@667: 	/* flow control settings */
fp@667: 	/* Set the FC high water mark to 90% of the FIFO size.
fp@667: 	 * Required to clear last 3 LSB */
fp@667: 	fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
fp@667: 	/* We can't use 90% on small FIFOs because the remainder
fp@667: 	 * would be less than 1 full frame.  In this case, we size
fp@667: 	 * it to allow at least a full frame above the high water
fp@667: 	 *  mark. */
fp@667: 	if (pba < E1000_PBA_16K)
fp@667: 		fc_high_water_mark = (pba * 1024) - 1600;
fp@667: 
fp@667: 	adapter->hw.fc_high_water = fc_high_water_mark;
fp@667: 	adapter->hw.fc_low_water = fc_high_water_mark - 8;
fp@667: 	if (adapter->hw.mac_type == e1000_80003es2lan)
fp@667: 		adapter->hw.fc_pause_time = 0xFFFF;
fp@667: 	else
fp@667: 		adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
fp@667: 	adapter->hw.fc_send_xon = 1;
fp@667: 	adapter->hw.fc = adapter->hw.original_fc;
fp@667: 
fp@667: 	/* Allow time for pending master requests to run */
fp@667: 	e1000_reset_hw(&adapter->hw);
fp@667: 	if (adapter->hw.mac_type >= e1000_82544)
fp@667: 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
fp@667: 	if (e1000_init_hw(&adapter->hw))
fp@667: 		DPRINTK(PROBE, ERR, "Hardware Error\n");
fp@667: 	e1000_update_mng_vlan(adapter);
fp@667: 	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
fp@667: 	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
fp@667: 
fp@667: 	e1000_reset_adaptive(&adapter->hw);
fp@667: 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
fp@667: 
fp@667: 	if (!adapter->smart_power_down &&
fp@667: 	    (adapter->hw.mac_type == e1000_82571 ||
fp@667: 	     adapter->hw.mac_type == e1000_82572)) {
fp@667: 		uint16_t phy_data = 0;
fp@667: 		/* speed up time to link by disabling smart power down, ignore
fp@667: 		 * the return value of this function because there is nothing
fp@667: 		 * different we would do if it failed */
fp@667: 		e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
fp@667: 		                   &phy_data);
fp@667: 		phy_data &= ~IGP02E1000_PM_SPD;
fp@667: 		e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
fp@667: 		                    phy_data);
fp@667: 	}
fp@667: 
fp@667: 	if (adapter->hw.mac_type < e1000_ich8lan)
fp@667: 	/* FIXME: this code is duplicate and wrong for PCI Express */
fp@667: 	if (adapter->en_mng_pt) {
fp@667: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@667: 		manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
fp@667: 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_probe - Device Initialization Routine
fp@667:  * @pdev: PCI device information struct
fp@667:  * @ent: entry in e1000_pci_tbl
fp@667:  *
fp@667:  * Returns 0 on success, negative on failure
fp@667:  *
fp@667:  * e1000_probe initializes an adapter identified by a pci_dev structure.
fp@667:  * The OS initialization, configuring of the adapter private structure,
fp@667:  * and a hardware reset occur.
fp@667:  **/
fp@667: 
fp@667: static int __devinit
fp@667: e1000_probe(struct pci_dev *pdev,
fp@667:             const struct pci_device_id *ent)
fp@667: {
fp@667: 	struct net_device *netdev;
fp@667: 	struct e1000_adapter *adapter;
fp@667: 	unsigned long mmio_start, mmio_len;
fp@667: 	unsigned long flash_start, flash_len;
fp@667: 
fp@667: 	static int cards_found = 0;
fp@667: 	static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
fp@667: 	int i, err, pci_using_dac;
fp@667: 	uint16_t eeprom_data;
fp@667: 	uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
fp@667: 	if ((err = pci_enable_device(pdev)))
fp@667: 		return err;
fp@667: 
fp@667: 	if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
fp@667: 	    !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
fp@667: 		pci_using_dac = 1;
fp@667: 	} else {
fp@667: 		if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
fp@667: 		    (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
fp@667: 			E1000_ERR("No usable DMA configuration, aborting\n");
fp@667: 			return err;
fp@667: 		}
fp@667: 		pci_using_dac = 0;
fp@667: 	}
fp@667: 
fp@667: 	if ((err = pci_request_regions(pdev, e1000_driver_name)))
fp@667: 		return err;
fp@667: 
fp@667: 	pci_set_master(pdev);
fp@667: 
fp@667: 	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
fp@667: 	if (!netdev) {
fp@667: 		err = -ENOMEM;
fp@667: 		goto err_alloc_etherdev;
fp@667: 	}
fp@667: 
fp@667: 	SET_MODULE_OWNER(netdev);
fp@667: 	SET_NETDEV_DEV(netdev, &pdev->dev);
fp@667: 
fp@667: 	pci_set_drvdata(pdev, netdev);
fp@667: 	adapter = netdev_priv(netdev);
fp@667: 	adapter->netdev = netdev;
fp@667: 	adapter->pdev = pdev;
fp@667: 	adapter->hw.back = adapter;
fp@667: 	adapter->msg_enable = (1 << debug) - 1;
fp@667: 
fp@667: 	mmio_start = pci_resource_start(pdev, BAR_0);
fp@667: 	mmio_len = pci_resource_len(pdev, BAR_0);
fp@667: 
fp@667: 	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
fp@667: 	if (!adapter->hw.hw_addr) {
fp@667: 		err = -EIO;
fp@667: 		goto err_ioremap;
fp@667: 	}
fp@667: 
fp@667: 	for (i = BAR_1; i <= BAR_5; i++) {
fp@667: 		if (pci_resource_len(pdev, i) == 0)
fp@667: 			continue;
fp@667: 		if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
fp@667: 			adapter->hw.io_base = pci_resource_start(pdev, i);
fp@667: 			break;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	netdev->open = &e1000_open;
fp@667: 	netdev->stop = &e1000_close;
fp@667: 	netdev->hard_start_xmit = &e1000_xmit_frame;
fp@667: 	netdev->get_stats = &e1000_get_stats;
fp@667: 	netdev->set_multicast_list = &e1000_set_multi;
fp@667: 	netdev->set_mac_address = &e1000_set_mac;
fp@667: 	netdev->change_mtu = &e1000_change_mtu;
fp@667: 	netdev->do_ioctl = &e1000_ioctl;
fp@667: 	e1000_set_ethtool_ops(netdev);
fp@667: 	netdev->tx_timeout = &e1000_tx_timeout;
fp@667: 	netdev->watchdog_timeo = 5 * HZ;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	netdev->poll = &e1000_clean;
fp@667: 	netdev->weight = 64;
fp@667: #endif
fp@667: 	netdev->vlan_rx_register = e1000_vlan_rx_register;
fp@667: 	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
fp@667: 	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
fp@667: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@667: 	netdev->poll_controller = e1000_netpoll;
fp@667: #endif
fp@667: 	strcpy(netdev->name, pci_name(pdev));
fp@667: 
fp@667: 	netdev->mem_start = mmio_start;
fp@667: 	netdev->mem_end = mmio_start + mmio_len;
fp@667: 	netdev->base_addr = adapter->hw.io_base;
fp@667: 
fp@667: 	adapter->bd_number = cards_found;
fp@667: 
fp@667: 	/* setup the private structure */
fp@667: 
fp@667: 	if ((err = e1000_sw_init(adapter)))
fp@667: 		goto err_sw_init;
fp@667: 
fp@667: 	/* Flash BAR mapping must happen after e1000_sw_init
fp@667: 	 * because it depends on mac_type */
fp@667: 	if ((adapter->hw.mac_type == e1000_ich8lan) &&
fp@667: 	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
fp@667: 		flash_start = pci_resource_start(pdev, 1);
fp@667: 		flash_len = pci_resource_len(pdev, 1);
fp@667: 		adapter->hw.flash_address = ioremap(flash_start, flash_len);
fp@667: 		if (!adapter->hw.flash_address) {
fp@667: 			err = -EIO;
fp@667: 			goto err_flashmap;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	if ((err = e1000_check_phy_reset_block(&adapter->hw)))
fp@667: 		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
fp@667: 
fp@667: 	/* if ksp3, indicate if it's port a being setup */
fp@667: 	if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
fp@667: 			e1000_ksp3_port_a == 0)
fp@667: 		adapter->ksp3_port_a = 1;
fp@667: 	e1000_ksp3_port_a++;
fp@667: 	/* Reset for multiple KP3 adapters */
fp@667: 	if (e1000_ksp3_port_a == 4)
fp@667: 		e1000_ksp3_port_a = 0;
fp@667: 
fp@667: 	if (adapter->hw.mac_type >= e1000_82543) {
fp@667: 		netdev->features = NETIF_F_SG |
fp@667: 				   NETIF_F_HW_CSUM |
fp@667: 				   NETIF_F_HW_VLAN_TX |
fp@667: 				   NETIF_F_HW_VLAN_RX |
fp@667: 				   NETIF_F_HW_VLAN_FILTER;
fp@667: 		if (adapter->hw.mac_type == e1000_ich8lan)
fp@667: 			netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
fp@667: 	}
fp@667: 
fp@667: #ifdef NETIF_F_TSO
fp@667: 	if ((adapter->hw.mac_type >= e1000_82544) &&
fp@667: 	   (adapter->hw.mac_type != e1000_82547))
fp@667: 		netdev->features |= NETIF_F_TSO;
fp@667: 
fp@667: #ifdef NETIF_F_TSO_IPV6
fp@667: 	if (adapter->hw.mac_type > e1000_82547_rev_2)
fp@667: 		netdev->features |= NETIF_F_TSO_IPV6;
fp@667: #endif
fp@667: #endif
fp@667: 	if (pci_using_dac)
fp@667: 		netdev->features |= NETIF_F_HIGHDMA;
fp@667: 
fp@667: 	netdev->features |= NETIF_F_LLTX;
fp@667: 
fp@667: 	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
fp@667: 
fp@667: 	/* initialize eeprom parameters */
fp@667: 
fp@667: 	if (e1000_init_eeprom_params(&adapter->hw)) {
fp@667: 		E1000_ERR("EEPROM initialization failed\n");
fp@667: 		return -EIO;
fp@667: 	}
fp@667: 
fp@667: 	/* before reading the EEPROM, reset the controller to
fp@667: 	 * put the device in a known good starting state */
fp@667: 
fp@667: 	e1000_reset_hw(&adapter->hw);
fp@667: 
fp@667: 	/* make sure the EEPROM is good */
fp@667: 
fp@667: 	if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
fp@667: 		/* On some hardware the first attemp fails */
fp@667: 		if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
fp@667: 			DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
fp@667: 			err = -EIO;
fp@667: 			goto err_eeprom;
fp@667: 		} else
fp@667: 			DPRINTK(PROBE, INFO, "The EEPROM Checksum failed in the first read, now OK\n");
fp@667: 	}
fp@667: 
fp@667: 	/* copy the MAC address out of the EEPROM */
fp@667: 
fp@667: 	if (e1000_read_mac_addr(&adapter->hw))
fp@667: 		DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
fp@667: 	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
fp@667: 	memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
fp@667: 
fp@667: 	if (!is_valid_ether_addr(netdev->perm_addr)) {
fp@667: 		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
fp@667: 		err = -EIO;
fp@667: 		goto err_eeprom;
fp@667: 	}
fp@667: 
fp@667: 	e1000_read_part_num(&adapter->hw, &(adapter->part_num));
fp@667: 
fp@667: 	e1000_get_bus_info(&adapter->hw);
fp@667: 
fp@667: 	init_timer(&adapter->tx_fifo_stall_timer);
fp@667: 	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
fp@667: 	adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
fp@667: 
fp@667: 	init_timer(&adapter->watchdog_timer);
fp@667: 	adapter->watchdog_timer.function = &e1000_watchdog;
fp@667: 	adapter->watchdog_timer.data = (unsigned long) adapter;
fp@667: 
fp@667: 	init_timer(&adapter->phy_info_timer);
fp@667: 	adapter->phy_info_timer.function = &e1000_update_phy_info;
fp@667: 	adapter->phy_info_timer.data = (unsigned long) adapter;
fp@667: 
fp@667: 	INIT_WORK(&adapter->reset_task,
fp@667: 		(void (*)(void *))e1000_reset_task, netdev);
fp@667: 
fp@667: 	/* we're going to reset, so assume we have no link for now */
fp@667: 
fp@667: 	if (!adapter->ecdev) {
fp@667: 		netif_carrier_off(netdev);
fp@667: 		netif_stop_queue(netdev);
fp@667: 	}
fp@667: 
fp@667: 	e1000_check_options(adapter);
fp@667: 
fp@667: 	/* Initial Wake on LAN setting
fp@667: 	 * If APM wake is enabled in the EEPROM,
fp@667: 	 * enable the ACPI Magic Packet filter
fp@667: 	 */
fp@667: 
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_82542_rev2_0:
fp@667: 	case e1000_82542_rev2_1:
fp@667: 	case e1000_82543:
fp@667: 		break;
fp@667: 	case e1000_82544:
fp@667: 		e1000_read_eeprom(&adapter->hw,
fp@667: 			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
fp@667: 		eeprom_apme_mask = E1000_EEPROM_82544_APM;
fp@667: 		break;
fp@667: 	case e1000_ich8lan:
fp@667: 		e1000_read_eeprom(&adapter->hw,
fp@667: 			EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
fp@667: 		eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
fp@667: 		break;
fp@667: 	case e1000_82546:
fp@667: 	case e1000_82546_rev_3:
fp@667: 	case e1000_82571:
fp@667: 	case e1000_80003es2lan:
fp@667: 		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
fp@667: 			e1000_read_eeprom(&adapter->hw,
fp@667: 				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
fp@667: 			break;
fp@667: 		}
fp@667: 		/* Fall Through */
fp@667: 	default:
fp@667: 		e1000_read_eeprom(&adapter->hw,
fp@667: 			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
fp@667: 		break;
fp@667: 	}
fp@667: 	if (eeprom_data & eeprom_apme_mask)
fp@667: 		adapter->wol |= E1000_WUFC_MAG;
fp@667: 
fp@667: 	/* print bus type/speed/width info */
fp@667: 	{
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
fp@667: 		((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
fp@667: 		 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
fp@667: 		((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
fp@667: 		 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
fp@667: 		 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
fp@667: 		 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
fp@667: 		 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
fp@667: 		((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
fp@667: 		 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
fp@667: 		 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
fp@667: 		 "32-bit"));
fp@667: 	}
fp@667: 
fp@667: 	for (i = 0; i < 6; i++)
fp@667: 		printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
fp@667: 
fp@667: 	/* reset the hardware with the new settings */
fp@667: 	e1000_reset(adapter);
fp@667: 
fp@667: 	/* If the controller is 82573 and f/w is AMT, do not set
fp@667: 	 * DRV_LOAD until the interface is up.  For all other cases,
fp@667: 	 * let the f/w know that the h/w is now under the control
fp@667: 	 * of the driver. */
fp@667: 	if (adapter->hw.mac_type != e1000_82573 ||
fp@667: 	    !e1000_check_mng_mode(&adapter->hw))
fp@667: 		e1000_get_hw_control(adapter);
fp@667: 
fp@671: 	// offer device to EtherCAT master module
fp@671: 	if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) {
fp@671: 		DPRINTK(PROBE, ERR, "Failed to offer device.\n");
fp@667: 		goto err_register;
fp@671: 	}
fp@671: 
fp@671: 	if (adapter->ecdev) {
fp@671: 		if (ecdev_open(adapter->ecdev)) {
fp@671: 			ecdev_withdraw(adapter->ecdev);
fp@671: 			goto err_register;
fp@671: 		}
fp@671: 	} else {
fp@671: 		strcpy(netdev->name, "eth%d");
fp@671: 		if ((err = register_netdev(netdev)))
fp@671: 			goto err_register;
fp@671: 	}
fp@671: 
fp@671: 	return 0;
fp@667: 
fp@667: 	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
fp@667: 
fp@667: 	cards_found++;
fp@667: 	return 0;
fp@667: 
fp@667: err_register:
fp@667: 	if (adapter->hw.flash_address)
fp@667: 		iounmap(adapter->hw.flash_address);
fp@667: err_flashmap:
fp@667: err_sw_init:
fp@667: err_eeprom:
fp@667: 	iounmap(adapter->hw.hw_addr);
fp@667: err_ioremap:
fp@667: 	free_netdev(netdev);
fp@667: err_alloc_etherdev:
fp@667: 	pci_release_regions(pdev);
fp@667: 	return err;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_remove - Device Removal Routine
fp@667:  * @pdev: PCI device information struct
fp@667:  *
fp@667:  * e1000_remove is called by the PCI subsystem to alert the driver
fp@667:  * that it should release a PCI device.  The could be caused by a
fp@667:  * Hot-Plug event, or because the driver is going to be removed from
fp@667:  * memory.
fp@667:  **/
fp@667: 
fp@667: static void __devexit
fp@667: e1000_remove(struct pci_dev *pdev)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t manc;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	int i;
fp@667: #endif
fp@667: 
fp@667: 	flush_scheduled_work();
fp@667: 
fp@667: 	if (adapter->hw.mac_type >= e1000_82540 &&
fp@667: 	   adapter->hw.mac_type != e1000_ich8lan &&
fp@667: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@667: 		if (manc & E1000_MANC_SMBUS_EN) {
fp@667: 			manc |= E1000_MANC_ARP_EN;
fp@667: 			E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
fp@667: 	 * would have already happened in close and is redundant. */
fp@667: 	e1000_release_hw_control(adapter);
fp@667: 
fp@671: 	if (adapter->ecdev) {
fp@671: 		ecdev_close(adapter->ecdev);
fp@671: 		ecdev_withdraw(adapter->ecdev);
fp@671: 	} else {
fp@671: 		unregister_netdev(netdev);
fp@671: 	}
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++)
fp@667: 		dev_put(&adapter->polling_netdev[i]);
fp@667: #endif
fp@667: 
fp@667: 	if (!e1000_check_phy_reset_block(&adapter->hw))
fp@667: 		e1000_phy_hw_reset(&adapter->hw);
fp@667: 
fp@667: 	kfree(adapter->tx_ring);
fp@667: 	kfree(adapter->rx_ring);
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	kfree(adapter->polling_netdev);
fp@667: #endif
fp@667: 
fp@667: 	iounmap(adapter->hw.hw_addr);
fp@667: 	if (adapter->hw.flash_address)
fp@667: 		iounmap(adapter->hw.flash_address);
fp@667: 	pci_release_regions(pdev);
fp@667: 
fp@667: 	free_netdev(netdev);
fp@667: 
fp@667: 	pci_disable_device(pdev);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
fp@667:  * @adapter: board private structure to initialize
fp@667:  *
fp@667:  * e1000_sw_init initializes the Adapter private data structure.
fp@667:  * Fields are initialized based on PCI device information and
fp@667:  * OS network device settings (MTU size).
fp@667:  **/
fp@667: 
fp@667: static int __devinit
fp@667: e1000_sw_init(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	int i;
fp@667: #endif
fp@667: 
fp@667: 	/* PCI config space info */
fp@667: 
fp@667: 	hw->vendor_id = pdev->vendor;
fp@667: 	hw->device_id = pdev->device;
fp@667: 	hw->subsystem_vendor_id = pdev->subsystem_vendor;
fp@667: 	hw->subsystem_id = pdev->subsystem_device;
fp@667: 
fp@667: 	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
fp@667: 
fp@667: 	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
fp@667: 
fp@667: 	adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
fp@667: 	adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
fp@667: 	hw->max_frame_size = netdev->mtu +
fp@667: 			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
fp@667: 	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
fp@667: 
fp@667: 	/* identify the MAC */
fp@667: 
fp@667: 	if (e1000_set_mac_type(hw)) {
fp@667: 		DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
fp@667: 		return -EIO;
fp@667: 	}
fp@667: 
fp@667: 	switch (hw->mac_type) {
fp@667: 	default:
fp@667: 		break;
fp@667: 	case e1000_82541:
fp@667: 	case e1000_82547:
fp@667: 	case e1000_82541_rev_2:
fp@667: 	case e1000_82547_rev_2:
fp@667: 		hw->phy_init_script = 1;
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@667: 	e1000_set_media_type(hw);
fp@667: 
fp@667: 	hw->wait_autoneg_complete = FALSE;
fp@667: 	hw->tbi_compatibility_en = TRUE;
fp@667: 	hw->adaptive_ifs = TRUE;
fp@667: 
fp@667: 	/* Copper options */
fp@667: 
fp@667: 	if (hw->media_type == e1000_media_type_copper) {
fp@667: 		hw->mdix = AUTO_ALL_MODES;
fp@667: 		hw->disable_polarity_correction = FALSE;
fp@667: 		hw->master_slave = E1000_MASTER_SLAVE;
fp@667: 	}
fp@667: 
fp@667: 	adapter->num_tx_queues = 1;
fp@667: 	adapter->num_rx_queues = 1;
fp@667: 
fp@667: 	if (e1000_alloc_queues(adapter)) {
fp@667: 		DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++) {
fp@667: 		adapter->polling_netdev[i].priv = adapter;
fp@667: 		adapter->polling_netdev[i].poll = &e1000_clean;
fp@667: 		adapter->polling_netdev[i].weight = 64;
fp@667: 		dev_hold(&adapter->polling_netdev[i]);
fp@667: 		set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
fp@667: 	}
fp@667: 	spin_lock_init(&adapter->tx_queue_lock);
fp@667: #endif
fp@667: 
fp@667: 	atomic_set(&adapter->irq_sem, 1);
fp@667: 	spin_lock_init(&adapter->stats_lock);
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_alloc_queues - Allocate memory for all rings
fp@667:  * @adapter: board private structure to initialize
fp@667:  *
fp@667:  * We allocate one ring per queue at run-time since we don't know the
fp@667:  * number of queues at compile-time.  The polling_netdev array is
fp@667:  * intended for Multiqueue, but should work fine with a single queue.
fp@667:  **/
fp@667: 
fp@667: static int __devinit
fp@667: e1000_alloc_queues(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int size;
fp@667: 
fp@667: 	size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
fp@667: 	adapter->tx_ring = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!adapter->tx_ring)
fp@667: 		return -ENOMEM;
fp@667: 	memset(adapter->tx_ring, 0, size);
fp@667: 
fp@667: 	size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
fp@667: 	adapter->rx_ring = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!adapter->rx_ring) {
fp@667: 		kfree(adapter->tx_ring);
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(adapter->rx_ring, 0, size);
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	size = sizeof(struct net_device) * adapter->num_rx_queues;
fp@667: 	adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!adapter->polling_netdev) {
fp@667: 		kfree(adapter->tx_ring);
fp@667: 		kfree(adapter->rx_ring);
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(adapter->polling_netdev, 0, size);
fp@667: #endif
fp@667: 
fp@667: 	return E1000_SUCCESS;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_open - Called when a network interface is made active
fp@667:  * @netdev: network interface device structure
fp@667:  *
fp@667:  * Returns 0 on success, negative value on failure
fp@667:  *
fp@667:  * The open entry point is called when a network interface is made
fp@667:  * active by the system (IFF_UP).  At this point all resources needed
fp@667:  * for transmit and receive operations are allocated, the interrupt
fp@667:  * handler is registered with the OS, the watchdog timer is started,
fp@667:  * and the stack is notified that the interface is ready.
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_open(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	int err;
fp@667: 
fp@667: 	/* disallow open during test */
fp@667: 	if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
fp@667: 		return -EBUSY;
fp@667: 
fp@667: 	/* allocate transmit descriptors */
fp@667: 
fp@667: 	if ((err = e1000_setup_all_tx_resources(adapter)))
fp@667: 		goto err_setup_tx;
fp@667: 
fp@667: 	/* allocate receive descriptors */
fp@667: 
fp@667: 	if ((err = e1000_setup_all_rx_resources(adapter)))
fp@667: 		goto err_setup_rx;
fp@667: 
fp@671: 	if (!adapter->ecdev) {
fp@667: 		err = e1000_request_irq(adapter);
fp@667: 		if (err)
fp@667: 			goto err_up;
fp@667: 	}
fp@667: 
fp@667: 	e1000_power_up_phy(adapter);
fp@667: 
fp@667: 	if ((err = e1000_up(adapter)))
fp@667: 		goto err_up;
fp@667: 	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@667: 	if ((adapter->hw.mng_cookie.status &
fp@667: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
fp@667: 		e1000_update_mng_vlan(adapter);
fp@667: 	}
fp@667: 
fp@667: 	/* If AMT is enabled, let the firmware know that the network
fp@667: 	 * interface is now open */
fp@667: 	if (adapter->hw.mac_type == e1000_82573 &&
fp@667: 	    e1000_check_mng_mode(&adapter->hw))
fp@667: 		e1000_get_hw_control(adapter);
fp@667: 
fp@667: 	return E1000_SUCCESS;
fp@667: 
fp@667: err_up:
fp@667: 	e1000_free_all_rx_resources(adapter);
fp@667: err_setup_rx:
fp@667: 	e1000_free_all_tx_resources(adapter);
fp@667: err_setup_tx:
fp@667: 	e1000_reset(adapter);
fp@667: 
fp@667: 	return err;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_close - Disables a network interface
fp@667:  * @netdev: network interface device structure
fp@667:  *
fp@667:  * Returns 0, this is not allowed to fail
fp@667:  *
fp@667:  * The close entry point is called when an interface is de-activated
fp@667:  * by the OS.  The hardware is still under the drivers control, but
fp@667:  * needs to be disabled.  A global MAC reset is issued to stop the
fp@667:  * hardware, and all transmit and receive resources are freed.
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_close(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 
fp@667: 	WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
fp@667: 	e1000_down(adapter);
fp@667: 	e1000_power_down_phy(adapter);
fp@671: 	if (!adapter->ecdev) e1000_free_irq(adapter);
fp@667: 
fp@667: 	e1000_free_all_tx_resources(adapter);
fp@667: 	e1000_free_all_rx_resources(adapter);
fp@667: 
fp@667: 	if ((adapter->hw.mng_cookie.status &
fp@667: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
fp@667: 		e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
fp@667: 	}
fp@667: 
fp@667: 	/* If AMT is enabled, let the firmware know that the network
fp@667: 	 * interface is now closed */
fp@667: 	if (adapter->hw.mac_type == e1000_82573 &&
fp@667: 	    e1000_check_mng_mode(&adapter->hw))
fp@667: 		e1000_release_hw_control(adapter);
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
fp@667:  * @adapter: address of board private structure
fp@667:  * @start: address of beginning of memory
fp@667:  * @len: length of memory
fp@667:  **/
fp@667: static boolean_t
fp@667: e1000_check_64k_bound(struct e1000_adapter *adapter,
fp@667: 		      void *start, unsigned long len)
fp@667: {
fp@667: 	unsigned long begin = (unsigned long) start;
fp@667: 	unsigned long end = begin + len;
fp@667: 
fp@667: 	/* First rev 82545 and 82546 need to not allow any memory
fp@667: 	 * write location to cross 64k boundary due to errata 23 */
fp@667: 	if (adapter->hw.mac_type == e1000_82545 ||
fp@667: 	    adapter->hw.mac_type == e1000_82546) {
fp@667: 		return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
fp@667: 	}
fp@667: 
fp@667: 	return TRUE;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
fp@667:  * @adapter: board private structure
fp@667:  * @txdr:    tx descriptor ring (for a specific queue) to setup
fp@667:  *
fp@667:  * Return 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_setup_tx_resources(struct e1000_adapter *adapter,
fp@667:                          struct e1000_tx_ring *txdr)
fp@667: {
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	int size;
fp@667: 
fp@667: 	size = sizeof(struct e1000_buffer) * txdr->count;
fp@667: 	txdr->buffer_info = vmalloc(size);
fp@667: 	if (!txdr->buffer_info) {
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the transmit descriptor ring\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(txdr->buffer_info, 0, size);
fp@667: 
fp@667: 	/* round up to nearest 4K */
fp@667: 
fp@667: 	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
fp@667: 	E1000_ROUNDUP(txdr->size, 4096);
fp@667: 
fp@667: 	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
fp@667: 	if (!txdr->desc) {
fp@667: setup_tx_desc_die:
fp@667: 		vfree(txdr->buffer_info);
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the transmit descriptor ring\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 
fp@667: 	/* Fix for errata 23, can't cross 64kB boundary */
fp@667: 	if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
fp@667: 		void *olddesc = txdr->desc;
fp@667: 		dma_addr_t olddma = txdr->dma;
fp@667: 		DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
fp@667: 				     "at %p\n", txdr->size, txdr->desc);
fp@667: 		/* Try again, without freeing the previous */
fp@667: 		txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
fp@667: 		/* Failed allocation, critical failure */
fp@667: 		if (!txdr->desc) {
fp@667: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@667: 			goto setup_tx_desc_die;
fp@667: 		}
fp@667: 
fp@667: 		if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
fp@667: 			/* give up */
fp@667: 			pci_free_consistent(pdev, txdr->size, txdr->desc,
fp@667: 					    txdr->dma);
fp@667: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 				"Unable to allocate aligned memory "
fp@667: 				"for the transmit descriptor ring\n");
fp@667: 			vfree(txdr->buffer_info);
fp@667: 			return -ENOMEM;
fp@667: 		} else {
fp@667: 			/* Free old allocation, new allocation was successful */
fp@667: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@667: 		}
fp@667: 	}
fp@667: 	memset(txdr->desc, 0, txdr->size);
fp@667: 
fp@667: 	txdr->next_to_use = 0;
fp@667: 	txdr->next_to_clean = 0;
fp@667: 	spin_lock_init(&txdr->tx_lock);
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
fp@667:  * 				  (Descriptors) for all queues
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * If this function returns with an error, then it's possible one or
fp@667:  * more of the rings is populated (while the rest are not).  It is the
fp@667:  * callers duty to clean those orphaned rings.
fp@667:  *
fp@667:  * Return 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: int
fp@667: e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i, err = 0;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_tx_queues; i++) {
fp@667: 		err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
fp@667: 		if (err) {
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 				"Allocation for Tx Queue %u failed\n", i);
fp@667: 			break;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	return err;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * Configure the Tx unit of the MAC after a reset.
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_configure_tx(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint64_t tdba;
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	uint32_t tdlen, tctl, tipg, tarc;
fp@667: 	uint32_t ipgr1, ipgr2;
fp@667: 
fp@667: 	/* Setup the HW Tx Head and Tail descriptor pointers */
fp@667: 
fp@667: 	switch (adapter->num_tx_queues) {
fp@667: 	case 1:
fp@667: 	default:
fp@667: 		tdba = adapter->tx_ring[0].dma;
fp@667: 		tdlen = adapter->tx_ring[0].count *
fp@667: 			sizeof(struct e1000_tx_desc);
fp@667: 		E1000_WRITE_REG(hw, TDLEN, tdlen);
fp@667: 		E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
fp@667: 		E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
fp@667: 		E1000_WRITE_REG(hw, TDT, 0);
fp@667: 		E1000_WRITE_REG(hw, TDH, 0);
fp@667: 		adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
fp@667: 		adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@667: 	/* Set the default values for the Tx Inter Packet Gap timer */
fp@667: 
fp@667: 	if (hw->media_type == e1000_media_type_fiber ||
fp@667: 	    hw->media_type == e1000_media_type_internal_serdes)
fp@667: 		tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
fp@667: 	else
fp@667: 		tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
fp@667: 
fp@667: 	switch (hw->mac_type) {
fp@667: 	case e1000_82542_rev2_0:
fp@667: 	case e1000_82542_rev2_1:
fp@667: 		tipg = DEFAULT_82542_TIPG_IPGT;
fp@667: 		ipgr1 = DEFAULT_82542_TIPG_IPGR1;
fp@667: 		ipgr2 = DEFAULT_82542_TIPG_IPGR2;
fp@667: 		break;
fp@667: 	case e1000_80003es2lan:
fp@667: 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
fp@667: 		ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
fp@667: 		break;
fp@667: 	default:
fp@667: 		ipgr1 = DEFAULT_82543_TIPG_IPGR1;
fp@667: 		ipgr2 = DEFAULT_82543_TIPG_IPGR2;
fp@667: 		break;
fp@667: 	}
fp@667: 	tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
fp@667: 	tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
fp@667: 	E1000_WRITE_REG(hw, TIPG, tipg);
fp@667: 
fp@667: 	/* Set the Tx Interrupt Delay register */
fp@667: 
fp@667: 	E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
fp@667: 	if (hw->mac_type >= e1000_82540)
fp@667: 		E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
fp@667: 
fp@667: 	/* Program the Transmit Control Register */
fp@667: 
fp@667: 	tctl = E1000_READ_REG(hw, TCTL);
fp@667: 
fp@667: 	tctl &= ~E1000_TCTL_CT;
fp@667: 	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
fp@667: 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
fp@667: 
fp@667: #ifdef DISABLE_MULR
fp@667: 	/* disable Multiple Reads for debugging */
fp@667: 	tctl &= ~E1000_TCTL_MULR;
fp@667: #endif
fp@667: 
fp@667: 	if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
fp@667: 		tarc = E1000_READ_REG(hw, TARC0);
fp@667: 		tarc |= ((1 << 25) | (1 << 21));
fp@667: 		E1000_WRITE_REG(hw, TARC0, tarc);
fp@667: 		tarc = E1000_READ_REG(hw, TARC1);
fp@667: 		tarc |= (1 << 25);
fp@667: 		if (tctl & E1000_TCTL_MULR)
fp@667: 			tarc &= ~(1 << 28);
fp@667: 		else
fp@667: 			tarc |= (1 << 28);
fp@667: 		E1000_WRITE_REG(hw, TARC1, tarc);
fp@667: 	} else if (hw->mac_type == e1000_80003es2lan) {
fp@667: 		tarc = E1000_READ_REG(hw, TARC0);
fp@667: 		tarc |= 1;
fp@667: 		if (hw->media_type == e1000_media_type_internal_serdes)
fp@667: 			tarc |= (1 << 20);
fp@667: 		E1000_WRITE_REG(hw, TARC0, tarc);
fp@667: 		tarc = E1000_READ_REG(hw, TARC1);
fp@667: 		tarc |= 1;
fp@667: 		E1000_WRITE_REG(hw, TARC1, tarc);
fp@667: 	}
fp@667: 
fp@667: 	e1000_config_collision_dist(hw);
fp@667: 
fp@667: 	/* Setup Transmit Descriptor Settings for eop descriptor */
fp@667: 	adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
fp@667: 		E1000_TXD_CMD_IFCS;
fp@667: 
fp@667: 	if (hw->mac_type < e1000_82543)
fp@667: 		adapter->txd_cmd |= E1000_TXD_CMD_RPS;
fp@667: 	else
fp@667: 		adapter->txd_cmd |= E1000_TXD_CMD_RS;
fp@667: 
fp@667: 	/* Cache if we're 82544 running in PCI-X because we'll
fp@667: 	 * need this to apply a workaround later in the send path. */
fp@667: 	if (hw->mac_type == e1000_82544 &&
fp@667: 	    hw->bus_type == e1000_bus_type_pcix)
fp@667: 		adapter->pcix_82544 = 1;
fp@667: 
fp@667: 	E1000_WRITE_REG(hw, TCTL, tctl);
fp@667: 
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
fp@667:  * @adapter: board private structure
fp@667:  * @rxdr:    rx descriptor ring (for a specific queue) to setup
fp@667:  *
fp@667:  * Returns 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_setup_rx_resources(struct e1000_adapter *adapter,
fp@667:                          struct e1000_rx_ring *rxdr)
fp@667: {
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	int size, desc_len;
fp@667: 
fp@667: 	size = sizeof(struct e1000_buffer) * rxdr->count;
fp@667: 	rxdr->buffer_info = vmalloc(size);
fp@667: 	if (!rxdr->buffer_info) {
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(rxdr->buffer_info, 0, size);
fp@667: 
fp@667: 	size = sizeof(struct e1000_ps_page) * rxdr->count;
fp@667: 	rxdr->ps_page = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!rxdr->ps_page) {
fp@667: 		vfree(rxdr->buffer_info);
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(rxdr->ps_page, 0, size);
fp@667: 
fp@667: 	size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
fp@667: 	rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!rxdr->ps_page_dma) {
fp@667: 		vfree(rxdr->buffer_info);
fp@667: 		kfree(rxdr->ps_page);
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	memset(rxdr->ps_page_dma, 0, size);
fp@667: 
fp@667: 	if (adapter->hw.mac_type <= e1000_82547_rev_2)
fp@667: 		desc_len = sizeof(struct e1000_rx_desc);
fp@667: 	else
fp@667: 		desc_len = sizeof(union e1000_rx_desc_packet_split);
fp@667: 
fp@667: 	/* Round up to nearest 4K */
fp@667: 
fp@667: 	rxdr->size = rxdr->count * desc_len;
fp@667: 	E1000_ROUNDUP(rxdr->size, 4096);
fp@667: 
fp@667: 	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
fp@667: 
fp@667: 	if (!rxdr->desc) {
fp@667: 		DPRINTK(PROBE, ERR,
fp@667: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@667: setup_rx_desc_die:
fp@667: 		vfree(rxdr->buffer_info);
fp@667: 		kfree(rxdr->ps_page);
fp@667: 		kfree(rxdr->ps_page_dma);
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 
fp@667: 	/* Fix for errata 23, can't cross 64kB boundary */
fp@667: 	if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
fp@667: 		void *olddesc = rxdr->desc;
fp@667: 		dma_addr_t olddma = rxdr->dma;
fp@667: 		DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
fp@667: 				     "at %p\n", rxdr->size, rxdr->desc);
fp@667: 		/* Try again, without freeing the previous */
fp@667: 		rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
fp@667: 		/* Failed allocation, critical failure */
fp@667: 		if (!rxdr->desc) {
fp@667: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 				"Unable to allocate memory "
fp@667: 				"for the receive descriptor ring\n");
fp@667: 			goto setup_rx_desc_die;
fp@667: 		}
fp@667: 
fp@667: 		if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
fp@667: 			/* give up */
fp@667: 			pci_free_consistent(pdev, rxdr->size, rxdr->desc,
fp@667: 					    rxdr->dma);
fp@667: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 				"Unable to allocate aligned memory "
fp@667: 				"for the receive descriptor ring\n");
fp@667: 			goto setup_rx_desc_die;
fp@667: 		} else {
fp@667: 			/* Free old allocation, new allocation was successful */
fp@667: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@667: 		}
fp@667: 	}
fp@667: 	memset(rxdr->desc, 0, rxdr->size);
fp@667: 
fp@667: 	rxdr->next_to_clean = 0;
fp@667: 	rxdr->next_to_use = 0;
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
fp@667:  * 				  (Descriptors) for all queues
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * If this function returns with an error, then it's possible one or
fp@667:  * more of the rings is populated (while the rest are not).  It is the
fp@667:  * callers duty to clean those orphaned rings.
fp@667:  *
fp@667:  * Return 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: int
fp@667: e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i, err = 0;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++) {
fp@667: 		err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
fp@667: 		if (err) {
fp@667: 			DPRINTK(PROBE, ERR,
fp@667: 				"Allocation for Rx Queue %u failed\n", i);
fp@667: 			break;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	return err;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_setup_rctl - configure the receive control registers
fp@667:  * @adapter: Board private structure
fp@667:  **/
fp@667: #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
fp@667: 			(((S) & (PAGE_SIZE - 1)) ? 1 : 0))
fp@667: static void
fp@667: e1000_setup_rctl(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint32_t rctl, rfctl;
fp@667: 	uint32_t psrctl = 0;
fp@667: #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
fp@667: 	uint32_t pages = 0;
fp@667: #endif
fp@667: 
fp@667: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 
fp@667: 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
fp@667: 
fp@667: 	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
fp@667: 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
fp@667: 		(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@667: 
fp@667: 	if (adapter->hw.tbi_compatibility_on == 1)
fp@667: 		rctl |= E1000_RCTL_SBP;
fp@667: 	else
fp@667: 		rctl &= ~E1000_RCTL_SBP;
fp@667: 
fp@667: 	if (adapter->netdev->mtu <= ETH_DATA_LEN)
fp@667: 		rctl &= ~E1000_RCTL_LPE;
fp@667: 	else
fp@667: 		rctl |= E1000_RCTL_LPE;
fp@667: 
fp@667: 	/* Setup buffer sizes */
fp@667: 	rctl &= ~E1000_RCTL_SZ_4096;
fp@667: 	rctl |= E1000_RCTL_BSEX;
fp@667: 	switch (adapter->rx_buffer_len) {
fp@667: 		case E1000_RXBUFFER_256:
fp@667: 			rctl |= E1000_RCTL_SZ_256;
fp@667: 			rctl &= ~E1000_RCTL_BSEX;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_512:
fp@667: 			rctl |= E1000_RCTL_SZ_512;
fp@667: 			rctl &= ~E1000_RCTL_BSEX;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_1024:
fp@667: 			rctl |= E1000_RCTL_SZ_1024;
fp@667: 			rctl &= ~E1000_RCTL_BSEX;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_2048:
fp@667: 		default:
fp@667: 			rctl |= E1000_RCTL_SZ_2048;
fp@667: 			rctl &= ~E1000_RCTL_BSEX;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_4096:
fp@667: 			rctl |= E1000_RCTL_SZ_4096;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_8192:
fp@667: 			rctl |= E1000_RCTL_SZ_8192;
fp@667: 			break;
fp@667: 		case E1000_RXBUFFER_16384:
fp@667: 			rctl |= E1000_RCTL_SZ_16384;
fp@667: 			break;
fp@667: 	}
fp@667: 
fp@667: #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
fp@667: 	/* 82571 and greater support packet-split where the protocol
fp@667: 	 * header is placed in skb->data and the packet data is
fp@667: 	 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
fp@667: 	 * In the case of a non-split, skb->data is linearly filled,
fp@667: 	 * followed by the page buffers.  Therefore, skb->data is
fp@667: 	 * sized to hold the largest protocol header.
fp@667: 	 */
fp@667: 	pages = PAGE_USE_COUNT(adapter->netdev->mtu);
fp@667: 	if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
fp@667: 	    PAGE_SIZE <= 16384)
fp@667: 		adapter->rx_ps_pages = pages;
fp@667: 	else
fp@667: 		adapter->rx_ps_pages = 0;
fp@667: #endif
fp@667: 	if (adapter->rx_ps_pages) {
fp@667: 		/* Configure extra packet-split registers */
fp@667: 		rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
fp@667: 		rfctl |= E1000_RFCTL_EXTEN;
fp@667: 		/* disable IPv6 packet split support */
fp@667: 		rfctl |= E1000_RFCTL_IPV6_DIS;
fp@667: 		E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
fp@667: 
fp@667: 		rctl |= E1000_RCTL_DTYP_PS;
fp@667: 
fp@667: 		psrctl |= adapter->rx_ps_bsize0 >>
fp@667: 			E1000_PSRCTL_BSIZE0_SHIFT;
fp@667: 
fp@667: 		switch (adapter->rx_ps_pages) {
fp@667: 		case 3:
fp@667: 			psrctl |= PAGE_SIZE <<
fp@667: 				E1000_PSRCTL_BSIZE3_SHIFT;
fp@667: 		case 2:
fp@667: 			psrctl |= PAGE_SIZE <<
fp@667: 				E1000_PSRCTL_BSIZE2_SHIFT;
fp@667: 		case 1:
fp@667: 			psrctl |= PAGE_SIZE >>
fp@667: 				E1000_PSRCTL_BSIZE1_SHIFT;
fp@667: 			break;
fp@667: 		}
fp@667: 
fp@667: 		E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
fp@667: 	}
fp@667: 
fp@667: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_configure_rx - Configure 8254x Receive Unit after Reset
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * Configure the Rx unit of the MAC after a reset.
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_configure_rx(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint64_t rdba;
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	uint32_t rdlen, rctl, rxcsum, ctrl_ext;
fp@667: 
fp@667: 	if (adapter->rx_ps_pages) {
fp@667: 		/* this is a 32 byte descriptor */
fp@667: 		rdlen = adapter->rx_ring[0].count *
fp@667: 			sizeof(union e1000_rx_desc_packet_split);
fp@667: 		adapter->clean_rx = e1000_clean_rx_irq_ps;
fp@667: 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
fp@667: 	} else {
fp@667: 		rdlen = adapter->rx_ring[0].count *
fp@667: 			sizeof(struct e1000_rx_desc);
fp@667: 		adapter->clean_rx = e1000_clean_rx_irq;
fp@667: 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
fp@667: 	}
fp@667: 
fp@667: 	/* disable receives while setting up the descriptors */
fp@667: 	rctl = E1000_READ_REG(hw, RCTL);
fp@667: 	E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
fp@667: 
fp@667: 	/* set the Receive Delay Timer Register */
fp@667: 	E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
fp@667: 
fp@667: 	if (hw->mac_type >= e1000_82540) {
fp@667: 		E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
fp@667: 		if (adapter->itr > 1)
fp@667: 			E1000_WRITE_REG(hw, ITR,
fp@667: 				1000000000 / (adapter->itr * 256));
fp@667: 	}
fp@667: 
fp@667: 	if (hw->mac_type >= e1000_82571) {
fp@667: 		ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
fp@667: 		/* Reset delay timers after every interrupt */
fp@667: 		ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 		/* Auto-Mask interrupts upon ICR read. */
fp@667: 		ctrl_ext |= E1000_CTRL_EXT_IAME;
fp@667: #endif
fp@667: 		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
fp@667: 		E1000_WRITE_REG(hw, IAM, ~0);
fp@667: 		E1000_WRITE_FLUSH(hw);
fp@667: 	}
fp@667: 
fp@667: 	/* Setup the HW Rx Head and Tail Descriptor Pointers and
fp@667: 	 * the Base and Length of the Rx Descriptor Ring */
fp@667: 	switch (adapter->num_rx_queues) {
fp@667: 	case 1:
fp@667: 	default:
fp@667: 		rdba = adapter->rx_ring[0].dma;
fp@667: 		E1000_WRITE_REG(hw, RDLEN, rdlen);
fp@667: 		E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
fp@667: 		E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
fp@667: 		E1000_WRITE_REG(hw, RDT, 0);
fp@667: 		E1000_WRITE_REG(hw, RDH, 0);
fp@667: 		adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
fp@667: 		adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@667: 	/* Enable 82543 Receive Checksum Offload for TCP and UDP */
fp@667: 	if (hw->mac_type >= e1000_82543) {
fp@667: 		rxcsum = E1000_READ_REG(hw, RXCSUM);
fp@667: 		if (adapter->rx_csum == TRUE) {
fp@667: 			rxcsum |= E1000_RXCSUM_TUOFL;
fp@667: 
fp@667: 			/* Enable 82571 IPv4 payload checksum for UDP fragments
fp@667: 			 * Must be used in conjunction with packet-split. */
fp@667: 			if ((hw->mac_type >= e1000_82571) &&
fp@667: 			    (adapter->rx_ps_pages)) {
fp@667: 				rxcsum |= E1000_RXCSUM_IPPCSE;
fp@667: 			}
fp@667: 		} else {
fp@667: 			rxcsum &= ~E1000_RXCSUM_TUOFL;
fp@667: 			/* don't need to clear IPPCSE as it defaults to 0 */
fp@667: 		}
fp@667: 		E1000_WRITE_REG(hw, RXCSUM, rxcsum);
fp@667: 	}
fp@667: 
fp@667: 	/* Enable Receives */
fp@667: 	E1000_WRITE_REG(hw, RCTL, rctl);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_free_tx_resources - Free Tx Resources per Queue
fp@667:  * @adapter: board private structure
fp@667:  * @tx_ring: Tx descriptor ring for a specific queue
fp@667:  *
fp@667:  * Free all transmit software resources
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_free_tx_resources(struct e1000_adapter *adapter,
fp@667:                         struct e1000_tx_ring *tx_ring)
fp@667: {
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 
fp@667: 	e1000_clean_tx_ring(adapter, tx_ring);
fp@667: 
fp@667: 	vfree(tx_ring->buffer_info);
fp@667: 	tx_ring->buffer_info = NULL;
fp@667: 
fp@667: 	pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
fp@667: 
fp@667: 	tx_ring->desc = NULL;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_free_all_tx_resources - Free Tx Resources for All Queues
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * Free all transmit software resources
fp@667:  **/
fp@667: 
fp@667: void
fp@667: e1000_free_all_tx_resources(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_tx_queues; i++)
fp@667: 		e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
fp@667: 			struct e1000_buffer *buffer_info)
fp@667: {
fp@678: 	if (adapter->ecdev)
fp@678: 		return;
fp@678: 
fp@667: 	if (buffer_info->dma) {
fp@667: 		pci_unmap_page(adapter->pdev,
fp@667: 				buffer_info->dma,
fp@667: 				buffer_info->length,
fp@667: 				PCI_DMA_TODEVICE);
fp@667: 	}
fp@667: 	if (buffer_info->skb)
fp@667: 		dev_kfree_skb_any(buffer_info->skb);
fp@667: 	memset(buffer_info, 0, sizeof(struct e1000_buffer));
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_tx_ring - Free Tx Buffers
fp@667:  * @adapter: board private structure
fp@667:  * @tx_ring: ring to be cleaned
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_clean_tx_ring(struct e1000_adapter *adapter,
fp@667:                     struct e1000_tx_ring *tx_ring)
fp@667: {
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	unsigned long size;
fp@667: 	unsigned int i;
fp@667: 
fp@667: 	/* Free all the Tx ring sk_buffs */
fp@667: 
fp@667: 	for (i = 0; i < tx_ring->count; i++) {
fp@667: 		buffer_info = &tx_ring->buffer_info[i];
fp@667: 		e1000_unmap_and_free_tx_resource(adapter, buffer_info);
fp@667: 	}
fp@667: 
fp@667: 	size = sizeof(struct e1000_buffer) * tx_ring->count;
fp@667: 	memset(tx_ring->buffer_info, 0, size);
fp@667: 
fp@667: 	/* Zero out the descriptor ring */
fp@667: 
fp@667: 	memset(tx_ring->desc, 0, tx_ring->size);
fp@667: 
fp@667: 	tx_ring->next_to_use = 0;
fp@667: 	tx_ring->next_to_clean = 0;
fp@667: 	tx_ring->last_tx_tso = 0;
fp@667: 
fp@667: 	writel(0, adapter->hw.hw_addr + tx_ring->tdh);
fp@667: 	writel(0, adapter->hw.hw_addr + tx_ring->tdt);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_tx_queues; i++)
fp@667: 		e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_free_rx_resources - Free Rx Resources
fp@667:  * @adapter: board private structure
fp@667:  * @rx_ring: ring to clean the resources from
fp@667:  *
fp@667:  * Free all receive software resources
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_free_rx_resources(struct e1000_adapter *adapter,
fp@667:                         struct e1000_rx_ring *rx_ring)
fp@667: {
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 
fp@667: 	e1000_clean_rx_ring(adapter, rx_ring);
fp@667: 
fp@667: 	vfree(rx_ring->buffer_info);
fp@667: 	rx_ring->buffer_info = NULL;
fp@667: 	kfree(rx_ring->ps_page);
fp@667: 	rx_ring->ps_page = NULL;
fp@667: 	kfree(rx_ring->ps_page_dma);
fp@667: 	rx_ring->ps_page_dma = NULL;
fp@667: 
fp@667: 	pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
fp@667: 
fp@667: 	rx_ring->desc = NULL;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_free_all_rx_resources - Free Rx Resources for All Queues
fp@667:  * @adapter: board private structure
fp@667:  *
fp@667:  * Free all receive software resources
fp@667:  **/
fp@667: 
fp@667: void
fp@667: e1000_free_all_rx_resources(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++)
fp@667: 		e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_rx_ring - Free Rx Buffers per Queue
fp@667:  * @adapter: board private structure
fp@667:  * @rx_ring: ring to free buffers from
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_clean_rx_ring(struct e1000_adapter *adapter,
fp@667:                     struct e1000_rx_ring *rx_ring)
fp@667: {
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	struct e1000_ps_page *ps_page;
fp@667: 	struct e1000_ps_page_dma *ps_page_dma;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	unsigned long size;
fp@667: 	unsigned int i, j;
fp@667: 
fp@667: 	/* Free all the Rx ring sk_buffs */
fp@667: 	for (i = 0; i < rx_ring->count; i++) {
fp@667: 		buffer_info = &rx_ring->buffer_info[i];
fp@667: 		if (buffer_info->skb) {
fp@667: 			pci_unmap_single(pdev,
fp@667: 					 buffer_info->dma,
fp@667: 					 buffer_info->length,
fp@667: 					 PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 			dev_kfree_skb(buffer_info->skb);
fp@667: 			buffer_info->skb = NULL;
fp@667: 		}
fp@667: 		ps_page = &rx_ring->ps_page[i];
fp@667: 		ps_page_dma = &rx_ring->ps_page_dma[i];
fp@667: 		for (j = 0; j < adapter->rx_ps_pages; j++) {
fp@667: 			if (!ps_page->ps_page[j]) break;
fp@667: 			pci_unmap_page(pdev,
fp@667: 				       ps_page_dma->ps_page_dma[j],
fp@667: 				       PAGE_SIZE, PCI_DMA_FROMDEVICE);
fp@667: 			ps_page_dma->ps_page_dma[j] = 0;
fp@667: 			put_page(ps_page->ps_page[j]);
fp@667: 			ps_page->ps_page[j] = NULL;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	size = sizeof(struct e1000_buffer) * rx_ring->count;
fp@667: 	memset(rx_ring->buffer_info, 0, size);
fp@667: 	size = sizeof(struct e1000_ps_page) * rx_ring->count;
fp@667: 	memset(rx_ring->ps_page, 0, size);
fp@667: 	size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
fp@667: 	memset(rx_ring->ps_page_dma, 0, size);
fp@667: 
fp@667: 	/* Zero out the descriptor ring */
fp@667: 
fp@667: 	memset(rx_ring->desc, 0, rx_ring->size);
fp@667: 
fp@667: 	rx_ring->next_to_clean = 0;
fp@667: 	rx_ring->next_to_use = 0;
fp@667: 
fp@667: 	writel(0, adapter->hw.hw_addr + rx_ring->rdh);
fp@667: 	writel(0, adapter->hw.hw_addr + rx_ring->rdt);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	int i;
fp@667: 
fp@667: 	for (i = 0; i < adapter->num_rx_queues; i++)
fp@667: 		e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
fp@667: }
fp@667: 
fp@667: /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
fp@667:  * and memory write and invalidate disabled for certain operations
fp@667:  */
fp@667: static void
fp@667: e1000_enter_82542_rst(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	uint32_t rctl;
fp@667: 
fp@667: 	e1000_pci_clear_mwi(&adapter->hw);
fp@667: 
fp@667: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 	rctl |= E1000_RCTL_RST;
fp@667: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@667: 	mdelay(5);
fp@667: 
fp@671: 	if (!adapter->ecdev && netif_running(netdev))
fp@667: 		e1000_clean_all_rx_rings(adapter);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_leave_82542_rst(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	uint32_t rctl;
fp@667: 
fp@667: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 	rctl &= ~E1000_RCTL_RST;
fp@667: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@667: 	mdelay(5);
fp@667: 
fp@667: 	if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
fp@667: 		e1000_pci_set_mwi(&adapter->hw);
fp@667: 
fp@671: 	if (!adapter->ecdev && netif_running(netdev)) {
fp@667: 		/* No need to loop, because 82542 supports only 1 queue */
fp@667: 		struct e1000_rx_ring *ring = &adapter->rx_ring[0];
fp@667: 		e1000_configure_rx(adapter);
fp@667: 		adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_set_mac - Change the Ethernet Address of the NIC
fp@667:  * @netdev: network interface device structure
fp@667:  * @p: pointer to an address structure
fp@667:  *
fp@667:  * Returns 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_set_mac(struct net_device *netdev, void *p)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	struct sockaddr *addr = p;
fp@667: 
fp@667: 	if (!is_valid_ether_addr(addr->sa_data))
fp@667: 		return -EADDRNOTAVAIL;
fp@667: 
fp@667: 	/* 82542 2.0 needs to be in reset to write receive address registers */
fp@667: 
fp@667: 	if (adapter->hw.mac_type == e1000_82542_rev2_0)
fp@667: 		e1000_enter_82542_rst(adapter);
fp@667: 
fp@667: 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
fp@667: 	memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
fp@667: 
fp@667: 	e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
fp@667: 
fp@667: 	/* With 82571 controllers, LAA may be overwritten (with the default)
fp@667: 	 * due to controller reset from the other port. */
fp@667: 	if (adapter->hw.mac_type == e1000_82571) {
fp@667: 		/* activate the work around */
fp@667: 		adapter->hw.laa_is_present = 1;
fp@667: 
fp@667: 		/* Hold a copy of the LAA in RAR[14] This is done so that
fp@667: 		 * between the time RAR[0] gets clobbered  and the time it
fp@667: 		 * gets fixed (in e1000_watchdog), the actual LAA is in one
fp@667: 		 * of the RARs and no incoming packets directed to this port
fp@667: 		 * are dropped. Eventaully the LAA will be in RAR[0] and
fp@667: 		 * RAR[14] */
fp@667: 		e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
fp@667: 					E1000_RAR_ENTRIES - 1);
fp@667: 	}
fp@667: 
fp@667: 	if (adapter->hw.mac_type == e1000_82542_rev2_0)
fp@667: 		e1000_leave_82542_rst(adapter);
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_set_multi - Multicast and Promiscuous mode set
fp@667:  * @netdev: network interface device structure
fp@667:  *
fp@667:  * The set_multi entry point is called whenever the multicast address
fp@667:  * list or the network interface flags are updated.  This routine is
fp@667:  * responsible for configuring the hardware for proper multicast,
fp@667:  * promiscuous mode, and all-multi behavior.
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_set_multi(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	struct dev_mc_list *mc_ptr;
fp@667: 	uint32_t rctl;
fp@667: 	uint32_t hash_value;
fp@667: 	int i, rar_entries = E1000_RAR_ENTRIES;
fp@667: 	int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
fp@667: 				E1000_NUM_MTA_REGISTERS_ICH8LAN :
fp@667: 				E1000_NUM_MTA_REGISTERS;
fp@667: 
fp@667: 	if (adapter->hw.mac_type == e1000_ich8lan)
fp@667: 		rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
fp@667: 
fp@667: 	/* reserve RAR[14] for LAA over-write work-around */
fp@667: 	if (adapter->hw.mac_type == e1000_82571)
fp@667: 		rar_entries--;
fp@667: 
fp@667: 	/* Check for Promiscuous and All Multicast modes */
fp@667: 
fp@667: 	rctl = E1000_READ_REG(hw, RCTL);
fp@667: 
fp@667: 	if (netdev->flags & IFF_PROMISC) {
fp@667: 		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
fp@667: 	} else if (netdev->flags & IFF_ALLMULTI) {
fp@667: 		rctl |= E1000_RCTL_MPE;
fp@667: 		rctl &= ~E1000_RCTL_UPE;
fp@667: 	} else {
fp@667: 		rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
fp@667: 	}
fp@667: 
fp@667: 	E1000_WRITE_REG(hw, RCTL, rctl);
fp@667: 
fp@667: 	/* 82542 2.0 needs to be in reset to write receive address registers */
fp@667: 
fp@667: 	if (hw->mac_type == e1000_82542_rev2_0)
fp@667: 		e1000_enter_82542_rst(adapter);
fp@667: 
fp@667: 	/* load the first 14 multicast address into the exact filters 1-14
fp@667: 	 * RAR 0 is used for the station MAC adddress
fp@667: 	 * if there are not 14 addresses, go ahead and clear the filters
fp@667: 	 * -- with 82571 controllers only 0-13 entries are filled here
fp@667: 	 */
fp@667: 	mc_ptr = netdev->mc_list;
fp@667: 
fp@667: 	for (i = 1; i < rar_entries; i++) {
fp@667: 		if (mc_ptr) {
fp@667: 			e1000_rar_set(hw, mc_ptr->dmi_addr, i);
fp@667: 			mc_ptr = mc_ptr->next;
fp@667: 		} else {
fp@667: 			E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
fp@667: 			E1000_WRITE_FLUSH(hw);
fp@667: 			E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
fp@667: 			E1000_WRITE_FLUSH(hw);
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	/* clear the old settings from the multicast hash table */
fp@667: 
fp@667: 	for (i = 0; i < mta_reg_count; i++) {
fp@667: 		E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
fp@667: 		E1000_WRITE_FLUSH(hw);
fp@667: 	}
fp@667: 
fp@667: 	/* load any remaining addresses into the hash table */
fp@667: 
fp@667: 	for (; mc_ptr; mc_ptr = mc_ptr->next) {
fp@667: 		hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
fp@667: 		e1000_mta_set(hw, hash_value);
fp@667: 	}
fp@667: 
fp@667: 	if (hw->mac_type == e1000_82542_rev2_0)
fp@667: 		e1000_leave_82542_rst(adapter);
fp@667: }
fp@667: 
fp@667: /* Need to wait a few seconds after link up to get diagnostic information from
fp@667:  * the phy */
fp@667: 
fp@667: static void
fp@667: e1000_update_phy_info(unsigned long data)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@667: 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_82547_tx_fifo_stall - Timer Call-back
fp@667:  * @data: pointer to adapter cast into an unsigned long
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_82547_tx_fifo_stall(unsigned long data)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	uint32_t tctl;
fp@667: 
fp@667: 	if (atomic_read(&adapter->tx_fifo_stall)) {
fp@667: 		if ((E1000_READ_REG(&adapter->hw, TDT) ==
fp@667: 		    E1000_READ_REG(&adapter->hw, TDH)) &&
fp@667: 		   (E1000_READ_REG(&adapter->hw, TDFT) ==
fp@667: 		    E1000_READ_REG(&adapter->hw, TDFH)) &&
fp@667: 		   (E1000_READ_REG(&adapter->hw, TDFTS) ==
fp@667: 		    E1000_READ_REG(&adapter->hw, TDFHS))) {
fp@667: 			tctl = E1000_READ_REG(&adapter->hw, TCTL);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TCTL,
fp@667: 					tctl & ~E1000_TCTL_EN);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TDFT,
fp@667: 					adapter->tx_head_addr);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TDFH,
fp@667: 					adapter->tx_head_addr);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TDFTS,
fp@667: 					adapter->tx_head_addr);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TDFHS,
fp@667: 					adapter->tx_head_addr);
fp@667: 			E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
fp@667: 			E1000_WRITE_FLUSH(&adapter->hw);
fp@667: 
fp@667: 			adapter->tx_fifo_head = 0;
fp@667: 			atomic_set(&adapter->tx_fifo_stall, 0);
fp@667: 			if (!adapter->ecdev) netif_wake_queue(netdev);
fp@667: 		} else {
fp@667: 			mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
fp@667: 		}
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_watchdog - Timer Call-back
fp@667:  * @data: pointer to adapter cast into an unsigned long
fp@667:  **/
fp@667: static void
fp@667: e1000_watchdog(unsigned long data)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct e1000_tx_ring *txdr = adapter->tx_ring;
fp@667: 	uint32_t link, tctl;
fp@667: 	int32_t ret_val;
fp@667: 
fp@667: 	ret_val = e1000_check_for_link(&adapter->hw);
fp@667: 	if ((ret_val == E1000_ERR_PHY) &&
fp@667: 	    (adapter->hw.phy_type == e1000_phy_igp_3) &&
fp@667: 	    (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
fp@667: 		/* See e1000_kumeran_lock_loss_workaround() */
fp@667: 		DPRINTK(LINK, INFO,
fp@667: 			"Gigabit has been disabled, downgrading speed\n");
fp@667: 	}
fp@667: 	if (adapter->hw.mac_type == e1000_82573) {
fp@667: 		e1000_enable_tx_pkt_filtering(&adapter->hw);
fp@667: 		if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
fp@667: 			e1000_update_mng_vlan(adapter);
fp@667: 	}
fp@667: 
fp@667: 	if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
fp@667: 	   !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
fp@667: 		link = !adapter->hw.serdes_link_down;
fp@667: 	else
fp@667: 		link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
fp@667: 
fp@667: 	if (link) {
fp@671: 		if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev))
fp@671: 				|| (!adapter->ecdev && !netif_carrier_ok(netdev))) {
fp@667: 			boolean_t txb2b = 1;
fp@667: 			e1000_get_speed_and_duplex(&adapter->hw,
fp@667: 			                           &adapter->link_speed,
fp@667: 			                           &adapter->link_duplex);
fp@667: 
fp@667: 			DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
fp@667: 			       adapter->link_speed,
fp@667: 			       adapter->link_duplex == FULL_DUPLEX ?
fp@667: 			       "Full Duplex" : "Half Duplex");
fp@667: 
fp@667: 			/* tweak tx_queue_len according to speed/duplex
fp@667: 			 * and adjust the timeout factor */
fp@667: 			netdev->tx_queue_len = adapter->tx_queue_len;
fp@667: 			adapter->tx_timeout_factor = 1;
fp@667: 			switch (adapter->link_speed) {
fp@667: 			case SPEED_10:
fp@667: 				txb2b = 0;
fp@667: 				netdev->tx_queue_len = 10;
fp@667: 				adapter->tx_timeout_factor = 8;
fp@667: 				break;
fp@667: 			case SPEED_100:
fp@667: 				txb2b = 0;
fp@667: 				netdev->tx_queue_len = 100;
fp@667: 				/* maybe add some timeout factor ? */
fp@667: 				break;
fp@667: 			}
fp@667: 
fp@667: 			if ((adapter->hw.mac_type == e1000_82571 ||
fp@667: 			     adapter->hw.mac_type == e1000_82572) &&
fp@667: 			    txb2b == 0) {
fp@667: #define SPEED_MODE_BIT (1 << 21)
fp@667: 				uint32_t tarc0;
fp@667: 				tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
fp@667: 				tarc0 &= ~SPEED_MODE_BIT;
fp@667: 				E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
fp@667: 			}
fp@667: 				
fp@667: #ifdef NETIF_F_TSO
fp@667: 			/* disable TSO for pcie and 10/100 speeds, to avoid
fp@667: 			 * some hardware issues */
fp@667: 			if (!adapter->tso_force &&
fp@667: 			    adapter->hw.bus_type == e1000_bus_type_pci_express){
fp@667: 				switch (adapter->link_speed) {
fp@667: 				case SPEED_10:
fp@667: 				case SPEED_100:
fp@667: 					DPRINTK(PROBE,INFO,
fp@667: 				        "10/100 speed: disabling TSO\n");
fp@667: 					netdev->features &= ~NETIF_F_TSO;
fp@667: 					break;
fp@667: 				case SPEED_1000:
fp@667: 					netdev->features |= NETIF_F_TSO;
fp@667: 					break;
fp@667: 				default:
fp@667: 					/* oops */
fp@667: 					break;
fp@667: 				}
fp@667: 			}
fp@667: #endif
fp@667: 
fp@667: 			/* enable transmits in the hardware, need to do this
fp@667: 			 * after setting TARC0 */
fp@667: 			tctl = E1000_READ_REG(&adapter->hw, TCTL);
fp@667: 			tctl |= E1000_TCTL_EN;
fp@667: 			E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
fp@667: 
fp@668: 			if (adapter->ecdev) {
fp@671: 				ecdev_set_link(adapter->ecdev, 1);
fp@671: 			} else {
fp@671: 				netif_carrier_on(netdev);
fp@671: 				netif_wake_queue(netdev);
fp@678:                 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
fp@671: 			}
fp@667: 			adapter->smartspeed = 0;
fp@667: 		}
fp@667: 	} else {
fp@671: 		if ((adapter->ecdev && ecdev_get_link(adapter->ecdev))
fp@671: 				|| (!adapter->ecdev && netif_carrier_ok(netdev))) {
fp@667: 			adapter->link_speed = 0;
fp@667: 			adapter->link_duplex = 0;
fp@667: 			DPRINTK(LINK, INFO, "NIC Link is Down\n");
fp@671: 			if (adapter->ecdev) {
fp@671: 				ecdev_set_link(adapter->ecdev, 0);
fp@671: 			} else {
fp@671: 				netif_carrier_off(netdev);
fp@671: 				netif_stop_queue(netdev);
fp@678:                 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
fp@671: 			}
fp@667: 
fp@667: 			/* 80003ES2LAN workaround--
fp@667: 			 * For packet buffer work-around on link down event;
fp@667: 			 * disable receives in the ISR and
fp@667: 			 * reset device here in the watchdog
fp@667: 			 */
fp@667: 			if (adapter->hw.mac_type == e1000_80003es2lan) {
fp@667: 				/* reset device */
fp@667: 				schedule_work(&adapter->reset_task);
fp@667: 			}
fp@667: 		}
fp@667: 
fp@667: 		e1000_smartspeed(adapter);
fp@667: 	}
fp@667: 
fp@667: 	e1000_update_stats(adapter);
fp@667: 
fp@667: 	adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
fp@667: 	adapter->tpt_old = adapter->stats.tpt;
fp@667: 	adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
fp@667: 	adapter->colc_old = adapter->stats.colc;
fp@667: 
fp@667: 	adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
fp@667: 	adapter->gorcl_old = adapter->stats.gorcl;
fp@667: 	adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
fp@667: 	adapter->gotcl_old = adapter->stats.gotcl;
fp@667: 
fp@667: 	e1000_update_adaptive(&adapter->hw);
fp@667: 
fp@678: 	if (!adapter->ecdev && !netif_carrier_ok(netdev)) {
fp@667: 		if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
fp@667: 			/* We've lost link, so the controller stops DMA,
fp@667: 			 * but we've got queued Tx work that's never going
fp@667: 			 * to get done, so reset controller to flush Tx.
fp@667: 			 * (Do the reset outside of interrupt context). */
fp@667: 			adapter->tx_timeout_count++;
fp@667: 			schedule_work(&adapter->reset_task);
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	/* Dynamic mode for Interrupt Throttle Rate (ITR) */
fp@667: 	if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
fp@667: 		/* Symmetric Tx/Rx gets a reduced ITR=2000; Total
fp@667: 		 * asymmetrical Tx or Rx gets ITR=8000; everyone
fp@667: 		 * else is between 2000-8000. */
fp@667: 		uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
fp@667: 		uint32_t dif = (adapter->gotcl > adapter->gorcl ?
fp@667: 			adapter->gotcl - adapter->gorcl :
fp@667: 			adapter->gorcl - adapter->gotcl) / 10000;
fp@667: 		uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
fp@667: 		E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
fp@667: 	}
fp@667: 
fp@667: 	/* Cause software interrupt to ensure rx ring is cleaned */
fp@667: 	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
fp@667: 
fp@667: 	/* Force detection of hung controller every watchdog period */
fp@678: 	if (!adapter->ecdev) adapter->detect_tx_hung = TRUE;
fp@667: 
fp@667: 	/* With 82571 controllers, LAA may be overwritten due to controller
fp@667: 	 * reset from the other port. Set the appropriate LAA in RAR[0] */
fp@667: 	if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
fp@667: 		e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
fp@667: 
fp@667: 	/* Reset the timer */
fp@678: 	if (!adapter->ecdev)
fp@678:         mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
fp@667: }
fp@667: 
fp@667: #define E1000_TX_FLAGS_CSUM		0x00000001
fp@667: #define E1000_TX_FLAGS_VLAN		0x00000002
fp@667: #define E1000_TX_FLAGS_TSO		0x00000004
fp@667: #define E1000_TX_FLAGS_IPV4		0x00000008
fp@667: #define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
fp@667: #define E1000_TX_FLAGS_VLAN_SHIFT	16
fp@667: 
fp@667: static int
fp@667: e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
fp@667:           struct sk_buff *skb)
fp@667: {
fp@667: #ifdef NETIF_F_TSO
fp@667: 	struct e1000_context_desc *context_desc;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	unsigned int i;
fp@667: 	uint32_t cmd_length = 0;
fp@667: 	uint16_t ipcse = 0, tucse, mss;
fp@667: 	uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
fp@667: 	int err;
fp@667: 
fp@667: 	if (skb_is_gso(skb)) {
fp@667: 		if (skb_header_cloned(skb)) {
fp@667: 			err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
fp@667: 			if (err)
fp@667: 				return err;
fp@667: 		}
fp@667: 
fp@667: 		hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
fp@667: 		mss = skb_shinfo(skb)->gso_size;
fp@667: 		if (skb->protocol == htons(ETH_P_IP)) {
fp@667: 			skb->nh.iph->tot_len = 0;
fp@667: 			skb->nh.iph->check = 0;
fp@667: 			skb->h.th->check =
fp@667: 				~csum_tcpudp_magic(skb->nh.iph->saddr,
fp@667: 						   skb->nh.iph->daddr,
fp@667: 						   0,
fp@667: 						   IPPROTO_TCP,
fp@667: 						   0);
fp@667: 			cmd_length = E1000_TXD_CMD_IP;
fp@667: 			ipcse = skb->h.raw - skb->data - 1;
fp@667: #ifdef NETIF_F_TSO_IPV6
fp@667: 		} else if (skb->protocol == ntohs(ETH_P_IPV6)) {
fp@667: 			skb->nh.ipv6h->payload_len = 0;
fp@667: 			skb->h.th->check =
fp@667: 				~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
fp@667: 						 &skb->nh.ipv6h->daddr,
fp@667: 						 0,
fp@667: 						 IPPROTO_TCP,
fp@667: 						 0);
fp@667: 			ipcse = 0;
fp@667: #endif
fp@667: 		}
fp@667: 		ipcss = skb->nh.raw - skb->data;
fp@667: 		ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
fp@667: 		tucss = skb->h.raw - skb->data;
fp@667: 		tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
fp@667: 		tucse = 0;
fp@667: 
fp@667: 		cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
fp@667: 			       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
fp@667: 
fp@667: 		i = tx_ring->next_to_use;
fp@667: 		context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
fp@667: 		buffer_info = &tx_ring->buffer_info[i];
fp@667: 
fp@667: 		context_desc->lower_setup.ip_fields.ipcss  = ipcss;
fp@667: 		context_desc->lower_setup.ip_fields.ipcso  = ipcso;
fp@667: 		context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
fp@667: 		context_desc->upper_setup.tcp_fields.tucss = tucss;
fp@667: 		context_desc->upper_setup.tcp_fields.tucso = tucso;
fp@667: 		context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
fp@667: 		context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
fp@667: 		context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
fp@667: 		context_desc->cmd_and_length = cpu_to_le32(cmd_length);
fp@667: 
fp@667: 		buffer_info->time_stamp = jiffies;
fp@667: 
fp@667: 		if (++i == tx_ring->count) i = 0;
fp@667: 		tx_ring->next_to_use = i;
fp@667: 
fp@667: 		return TRUE;
fp@667: 	}
fp@667: #endif
fp@667: 
fp@667: 	return FALSE;
fp@667: }
fp@667: 
fp@667: static boolean_t
fp@667: e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
fp@667:               struct sk_buff *skb)
fp@667: {
fp@667: 	struct e1000_context_desc *context_desc;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	unsigned int i;
fp@667: 	uint8_t css;
fp@667: 
fp@667: 	if (likely(skb->ip_summed == CHECKSUM_HW)) {
fp@667: 		css = skb->h.raw - skb->data;
fp@667: 
fp@667: 		i = tx_ring->next_to_use;
fp@667: 		buffer_info = &tx_ring->buffer_info[i];
fp@667: 		context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
fp@667: 
fp@667: 		context_desc->upper_setup.tcp_fields.tucss = css;
fp@667: 		context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
fp@667: 		context_desc->upper_setup.tcp_fields.tucse = 0;
fp@667: 		context_desc->tcp_seg_setup.data = 0;
fp@667: 		context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
fp@667: 
fp@667: 		buffer_info->time_stamp = jiffies;
fp@667: 
fp@667: 		if (unlikely(++i == tx_ring->count)) i = 0;
fp@667: 		tx_ring->next_to_use = i;
fp@667: 
fp@667: 		return TRUE;
fp@667: 	}
fp@667: 
fp@667: 	return FALSE;
fp@667: }
fp@667: 
fp@667: #define E1000_MAX_TXD_PWR	12
fp@667: #define E1000_MAX_DATA_PER_TXD	(1<<E1000_MAX_TXD_PWR)
fp@667: 
fp@667: static int
fp@667: e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
fp@667:              struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
fp@667:              unsigned int nr_frags, unsigned int mss)
fp@667: {
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	unsigned int len = skb->len;
fp@667: 	unsigned int offset = 0, size, count = 0, i;
fp@667: 	unsigned int f;
fp@667: 	len -= skb->data_len;
fp@667: 
fp@667: 	i = tx_ring->next_to_use;
fp@667: 
fp@667: 	while (len) {
fp@667: 		buffer_info = &tx_ring->buffer_info[i];
fp@667: 		size = min(len, max_per_txd);
fp@667: #ifdef NETIF_F_TSO
fp@667: 		/* Workaround for Controller erratum --
fp@667: 		 * descriptor for non-tso packet in a linear SKB that follows a
fp@667: 		 * tso gets written back prematurely before the data is fully
fp@667: 		 * DMA'd to the controller */
fp@667: 		if (!skb->data_len && tx_ring->last_tx_tso &&
fp@667: 		    !skb_is_gso(skb)) {
fp@667: 			tx_ring->last_tx_tso = 0;
fp@667: 			size -= 4;
fp@667: 		}
fp@667: 
fp@667: 		/* Workaround for premature desc write-backs
fp@667: 		 * in TSO mode.  Append 4-byte sentinel desc */
fp@667: 		if (unlikely(mss && !nr_frags && size == len && size > 8))
fp@667: 			size -= 4;
fp@667: #endif
fp@667: 		/* work-around for errata 10 and it applies
fp@667: 		 * to all controllers in PCI-X mode
fp@667: 		 * The fix is to make sure that the first descriptor of a
fp@667: 		 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
fp@667: 		 */
fp@667: 		if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
fp@667: 		                (size > 2015) && count == 0))
fp@667: 		        size = 2015;
fp@667: 
fp@667: 		/* Workaround for potential 82544 hang in PCI-X.  Avoid
fp@667: 		 * terminating buffers within evenly-aligned dwords. */
fp@667: 		if (unlikely(adapter->pcix_82544 &&
fp@667: 		   !((unsigned long)(skb->data + offset + size - 1) & 4) &&
fp@667: 		   size > 4))
fp@667: 			size -= 4;
fp@667: 
fp@667: 		buffer_info->length = size;
fp@667: 		buffer_info->dma =
fp@667: 			pci_map_single(adapter->pdev,
fp@667: 				skb->data + offset,
fp@667: 				size,
fp@667: 				PCI_DMA_TODEVICE);
fp@667: 		buffer_info->time_stamp = jiffies;
fp@667: 
fp@667: 		len -= size;
fp@667: 		offset += size;
fp@667: 		count++;
fp@667: 		if (unlikely(++i == tx_ring->count)) i = 0;
fp@667: 	}
fp@667: 
fp@667: 	for (f = 0; f < nr_frags; f++) {
fp@667: 		struct skb_frag_struct *frag;
fp@667: 
fp@667: 		frag = &skb_shinfo(skb)->frags[f];
fp@667: 		len = frag->size;
fp@667: 		offset = frag->page_offset;
fp@667: 
fp@667: 		while (len) {
fp@667: 			buffer_info = &tx_ring->buffer_info[i];
fp@667: 			size = min(len, max_per_txd);
fp@667: #ifdef NETIF_F_TSO
fp@667: 			/* Workaround for premature desc write-backs
fp@667: 			 * in TSO mode.  Append 4-byte sentinel desc */
fp@667: 			if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
fp@667: 				size -= 4;
fp@667: #endif
fp@667: 			/* Workaround for potential 82544 hang in PCI-X.
fp@667: 			 * Avoid terminating buffers within evenly-aligned
fp@667: 			 * dwords. */
fp@667: 			if (unlikely(adapter->pcix_82544 &&
fp@667: 			   !((unsigned long)(frag->page+offset+size-1) & 4) &&
fp@667: 			   size > 4))
fp@667: 				size -= 4;
fp@667: 
fp@667: 			buffer_info->length = size;
fp@667: 			buffer_info->dma =
fp@667: 				pci_map_page(adapter->pdev,
fp@667: 					frag->page,
fp@667: 					offset,
fp@667: 					size,
fp@667: 					PCI_DMA_TODEVICE);
fp@667: 			buffer_info->time_stamp = jiffies;
fp@667: 
fp@667: 			len -= size;
fp@667: 			offset += size;
fp@667: 			count++;
fp@667: 			if (unlikely(++i == tx_ring->count)) i = 0;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	i = (i == 0) ? tx_ring->count - 1 : i - 1;
fp@667: 	tx_ring->buffer_info[i].skb = skb;
fp@667: 	tx_ring->buffer_info[first].next_to_watch = i;
fp@667: 
fp@667: 	return count;
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
fp@667:                int tx_flags, int count)
fp@667: {
fp@667: 	struct e1000_tx_desc *tx_desc = NULL;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
fp@667: 	unsigned int i;
fp@667: 
fp@667: 	if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
fp@667: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
fp@667: 		             E1000_TXD_CMD_TSE;
fp@667: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
fp@667: 
fp@667: 		if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
fp@667: 			txd_upper |= E1000_TXD_POPTS_IXSM << 8;
fp@667: 	}
fp@667: 
fp@667: 	if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
fp@667: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
fp@667: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
fp@667: 	}
fp@667: 
fp@667: 	if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
fp@667: 		txd_lower |= E1000_TXD_CMD_VLE;
fp@667: 		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
fp@667: 	}
fp@667: 
fp@667: 	i = tx_ring->next_to_use;
fp@667: 
fp@667: 	while (count--) {
fp@667: 		buffer_info = &tx_ring->buffer_info[i];
fp@667: 		tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@667: 		tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
fp@667: 		tx_desc->lower.data =
fp@667: 			cpu_to_le32(txd_lower | buffer_info->length);
fp@667: 		tx_desc->upper.data = cpu_to_le32(txd_upper);
fp@667: 		if (unlikely(++i == tx_ring->count)) i = 0;
fp@667: 	}
fp@667: 
fp@667: 	tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
fp@667: 
fp@667: 	/* Force memory writes to complete before letting h/w
fp@667: 	 * know there are new descriptors to fetch.  (Only
fp@667: 	 * applicable for weak-ordered memory model archs,
fp@667: 	 * such as IA-64). */
fp@667: 	wmb();
fp@667: 
fp@667: 	tx_ring->next_to_use = i;
fp@667: 	writel(i, adapter->hw.hw_addr + tx_ring->tdt);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * 82547 workaround to avoid controller hang in half-duplex environment.
fp@667:  * The workaround is to avoid queuing a large packet that would span
fp@667:  * the internal Tx FIFO ring boundary by notifying the stack to resend
fp@667:  * the packet at a later time.  This gives the Tx FIFO an opportunity to
fp@667:  * flush all packets.  When that occurs, we reset the Tx FIFO pointers
fp@667:  * to the beginning of the Tx FIFO.
fp@667:  **/
fp@667: 
fp@667: #define E1000_FIFO_HDR			0x10
fp@667: #define E1000_82547_PAD_LEN		0x3E0
fp@667: 
fp@667: static int
fp@667: e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@667: {
fp@667: 	uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
fp@667: 	uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
fp@667: 
fp@667: 	E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
fp@667: 
fp@667: 	if (adapter->link_duplex != HALF_DUPLEX)
fp@667: 		goto no_fifo_stall_required;
fp@667: 
fp@667: 	if (atomic_read(&adapter->tx_fifo_stall))
fp@667: 		return 1;
fp@667: 
fp@667: 	if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
fp@667: 		atomic_set(&adapter->tx_fifo_stall, 1);
fp@667: 		return 1;
fp@667: 	}
fp@667: 
fp@667: no_fifo_stall_required:
fp@667: 	adapter->tx_fifo_head += skb_fifo_len;
fp@667: 	if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
fp@667: 		adapter->tx_fifo_head -= adapter->tx_fifo_size;
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: #define MINIMUM_DHCP_PACKET_SIZE 282
fp@667: static int
fp@667: e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@667: {
fp@667: 	struct e1000_hw *hw =  &adapter->hw;
fp@667: 	uint16_t length, offset;
fp@667: 	if (vlan_tx_tag_present(skb)) {
fp@667: 		if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
fp@667: 			( adapter->hw.mng_cookie.status &
fp@667: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
fp@667: 			return 0;
fp@667: 	}
fp@667: 	if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
fp@667: 		struct ethhdr *eth = (struct ethhdr *) skb->data;
fp@667: 		if ((htons(ETH_P_IP) == eth->h_proto)) {
fp@667: 			const struct iphdr *ip =
fp@667: 				(struct iphdr *)((uint8_t *)skb->data+14);
fp@667: 			if (IPPROTO_UDP == ip->protocol) {
fp@667: 				struct udphdr *udp =
fp@667: 					(struct udphdr *)((uint8_t *)ip +
fp@667: 						(ip->ihl << 2));
fp@667: 				if (ntohs(udp->dest) == 67) {
fp@667: 					offset = (uint8_t *)udp + 8 - skb->data;
fp@667: 					length = skb->len - offset;
fp@667: 
fp@667: 					return e1000_mng_write_dhcp_info(hw,
fp@667: 							(uint8_t *)udp + 8,
fp@667: 							length);
fp@667: 				}
fp@667: 			}
fp@667: 		}
fp@667: 	}
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
fp@667: static int
fp@667: e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	struct e1000_tx_ring *tx_ring;
fp@667: 	unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
fp@667: 	unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
fp@667: 	unsigned int tx_flags = 0;
fp@667: 	unsigned int len = skb->len;
fp@671: 	unsigned long flags = 0;
fp@667: 	unsigned int nr_frags = 0;
fp@667: 	unsigned int mss = 0;
fp@667: 	int count = 0;
fp@667: 	int tso;
fp@667: 	unsigned int f;
fp@667: 	len -= skb->data_len;
fp@667: 
fp@667: 	tx_ring = adapter->tx_ring;
fp@667: 
fp@667: 	if (unlikely(skb->len <= 0)) {
fp@671: 		if (!adapter->ecdev)
fp@671: 			dev_kfree_skb_any(skb);
fp@667: 		return NETDEV_TX_OK;
fp@667: 	}
fp@667: 
fp@667: #ifdef NETIF_F_TSO
fp@667: 	mss = skb_shinfo(skb)->gso_size;
fp@667: 	/* The controller does a simple calculation to
fp@667: 	 * make sure there is enough room in the FIFO before
fp@667: 	 * initiating the DMA for each buffer.  The calc is:
fp@667: 	 * 4 = ceil(buffer len/mss).  To make sure we don't
fp@667: 	 * overrun the FIFO, adjust the max buffer len if mss
fp@667: 	 * drops. */
fp@667: 	if (mss) {
fp@667: 		uint8_t hdr_len;
fp@667: 		max_per_txd = min(mss << 2, max_per_txd);
fp@667: 		max_txd_pwr = fls(max_per_txd) - 1;
fp@667: 
fp@667: 	/* TSO Workaround for 82571/2/3 Controllers -- if skb->data
fp@667: 	 * points to just header, pull a few bytes of payload from
fp@667: 	 * frags into skb->data */
fp@667: 		hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
fp@667: 		if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
fp@667: 			switch (adapter->hw.mac_type) {
fp@667: 				unsigned int pull_size;
fp@667: 			case e1000_82571:
fp@667: 			case e1000_82572:
fp@667: 			case e1000_82573:
fp@667: 			case e1000_ich8lan:
fp@667: 				pull_size = min((unsigned int)4, skb->data_len);
fp@667: 				if (!__pskb_pull_tail(skb, pull_size)) {
fp@667: 					DPRINTK(DRV, ERR,
fp@667: 						"__pskb_pull_tail failed.\n");
fp@668: 					if (!adapter->ecdev)
fp@671: 						dev_kfree_skb_any(skb);
fp@667: 					return NETDEV_TX_OK;
fp@667: 				}
fp@667: 				len = skb->len - skb->data_len;
fp@667: 				break;
fp@667: 			default:
fp@667: 				/* do nothing */
fp@667: 				break;
fp@667: 			}
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	/* reserve a descriptor for the offload context */
fp@667: 	if ((mss) || (skb->ip_summed == CHECKSUM_HW))
fp@667: 		count++;
fp@667: 	count++;
fp@667: #else
fp@667: 	if (skb->ip_summed == CHECKSUM_HW)
fp@667: 		count++;
fp@667: #endif
fp@667: 
fp@667: #ifdef NETIF_F_TSO
fp@667: 	/* Controller Erratum workaround */
fp@667: 	if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
fp@667: 		count++;
fp@667: #endif
fp@667: 
fp@667: 	count += TXD_USE_COUNT(len, max_txd_pwr);
fp@667: 
fp@667: 	if (adapter->pcix_82544)
fp@667: 		count++;
fp@667: 
fp@667: 	/* work-around for errata 10 and it applies to all controllers
fp@667: 	 * in PCI-X mode, so add one more descriptor to the count
fp@667: 	 */
fp@667: 	if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
fp@667: 			(len > 2015)))
fp@667: 		count++;
fp@667: 
fp@667: 	nr_frags = skb_shinfo(skb)->nr_frags;
fp@667: 	for (f = 0; f < nr_frags; f++)
fp@667: 		count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
fp@667: 				       max_txd_pwr);
fp@667: 	if (adapter->pcix_82544)
fp@667: 		count += nr_frags;
fp@667: 
fp@667: 
fp@667: 	if (adapter->hw.tx_pkt_filtering &&
fp@667: 	    (adapter->hw.mac_type == e1000_82573))
fp@667: 		e1000_transfer_dhcp_info(adapter, skb);
fp@667: 
fp@671: 	if (!adapter->ecdev) {
fp@671: 		local_irq_save(flags);
fp@671: 		if (!spin_trylock(&tx_ring->tx_lock)) {
fp@671: 			/* Collision - tell upper layer to requeue */
fp@671: 			local_irq_restore(flags);
fp@671: 			return NETDEV_TX_LOCKED;
fp@671: 		}
fp@671: 	}
fp@667: 
fp@667: 	/* need: count + 2 desc gap to keep tail from touching
fp@667: 	 * head, otherwise try next time */
fp@667: 	if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
fp@671: 		if (!adapter->ecdev) {
fp@671: 			netif_stop_queue(netdev);
fp@671: 			spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
fp@671: 		}
fp@667: 		return NETDEV_TX_BUSY;
fp@667: 	}
fp@667: 
fp@667: 	if (unlikely(adapter->hw.mac_type == e1000_82547)) {
fp@667: 		if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
fp@678: 			if (!adapter->ecdev) {
fp@671: 				netif_stop_queue(netdev);
fp@678:                 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
fp@671: 				spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
fp@678:             }
fp@667: 			return NETDEV_TX_BUSY;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
fp@667: 		tx_flags |= E1000_TX_FLAGS_VLAN;
fp@667: 		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
fp@667: 	}
fp@667: 
fp@667: 	first = tx_ring->next_to_use;
fp@667: 
fp@667: 	tso = e1000_tso(adapter, tx_ring, skb);
fp@667: 	if (tso < 0) {
fp@671: 		if (!adapter->ecdev) {
fp@671: 			dev_kfree_skb_any(skb);
fp@671: 			spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
fp@671: 		}
fp@667: 		return NETDEV_TX_OK;
fp@667: 	}
fp@667: 
fp@667: 	if (likely(tso)) {
fp@667: 		tx_ring->last_tx_tso = 1;
fp@667: 		tx_flags |= E1000_TX_FLAGS_TSO;
fp@667: 	} else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
fp@667: 		tx_flags |= E1000_TX_FLAGS_CSUM;
fp@667: 
fp@667: 	/* Old method was to assume IPv4 packet by default if TSO was enabled.
fp@667: 	 * 82571 hardware supports TSO capabilities for IPv6 as well...
fp@667: 	 * no longer assume, we must. */
fp@667: 	if (likely(skb->protocol == htons(ETH_P_IP)))
fp@667: 		tx_flags |= E1000_TX_FLAGS_IPV4;
fp@667: 
fp@667: 	e1000_tx_queue(adapter, tx_ring, tx_flags,
fp@667: 	               e1000_tx_map(adapter, tx_ring, skb, first,
fp@667: 	                            max_per_txd, nr_frags, mss));
fp@667: 
fp@667: 	netdev->trans_start = jiffies;
fp@667: 
fp@667: 	/* Make sure there is space in the ring for the next send. */
fp@668: 	if (!adapter->ecdev) {
fp@671: 		if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
fp@671: 			netif_stop_queue(netdev);
fp@671: 
fp@671: 		spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
fp@671: 	}
fp@667: 	return NETDEV_TX_OK;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_tx_timeout - Respond to a Tx Hang
fp@667:  * @netdev: network interface device structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_tx_timeout(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 
fp@667: 	/* Do the reset outside of interrupt context */
fp@667: 	adapter->tx_timeout_count++;
fp@667: 	schedule_work(&adapter->reset_task);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_reset_task(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 
fp@667: 	e1000_reinit_locked(adapter);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_get_stats - Get System Network Statistics
fp@667:  * @netdev: network interface device structure
fp@667:  *
fp@667:  * Returns the address of the device statistics structure.
fp@667:  * The statistics are actually updated from the timer callback.
fp@667:  **/
fp@667: 
fp@667: static struct net_device_stats *
fp@667: e1000_get_stats(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 
fp@667: 	/* only return the current stats */
fp@667: 	return &adapter->net_stats;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_change_mtu - Change the Maximum Transfer Unit
fp@667:  * @netdev: network interface device structure
fp@667:  * @new_mtu: new value for maximum frame size
fp@667:  *
fp@667:  * Returns 0 on success, negative on failure
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_change_mtu(struct net_device *netdev, int new_mtu)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
fp@667: 	uint16_t eeprom_data = 0;
fp@667: 
fp@667: 	if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
fp@667: 	    (max_frame > MAX_JUMBO_FRAME_SIZE)) {
fp@667: 		DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
fp@667: 		return -EINVAL;
fp@667: 	}
fp@667: 
fp@667: 	/* Adapter-specific max frame size limits. */
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_undefined ... e1000_82542_rev2_1:
fp@667: 	case e1000_ich8lan:
fp@667: 		if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
fp@667: 			DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
fp@667: 			return -EINVAL;
fp@667: 		}
fp@667: 		break;
fp@667: 	case e1000_82573:
fp@667: 		/* only enable jumbo frames if ASPM is disabled completely
fp@667: 		 * this means both bits must be zero in 0x1A bits 3:2 */
fp@667: 		e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
fp@667: 		                  &eeprom_data);
fp@667: 		if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
fp@667: 			if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
fp@667: 				DPRINTK(PROBE, ERR,
fp@667: 			            	"Jumbo Frames not supported.\n");
fp@667: 				return -EINVAL;
fp@667: 			}
fp@667: 			break;
fp@667: 		}
fp@667: 		/* fall through to get support */
fp@667: 	case e1000_82571:
fp@667: 	case e1000_82572:
fp@667: 	case e1000_80003es2lan:
fp@667: #define MAX_STD_JUMBO_FRAME_SIZE 9234
fp@667: 		if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
fp@667: 			DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
fp@667: 			return -EINVAL;
fp@667: 		}
fp@667: 		break;
fp@667: 	default:
fp@667: 		/* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@667: 	/* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
fp@667: 	 * means we reserve 2 more, this pushes us to allocate from the next
fp@667: 	 * larger slab size
fp@667: 	 * i.e. RXBUFFER_2048 --> size-4096 slab */
fp@667: 
fp@667: 	if (max_frame <= E1000_RXBUFFER_256)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_256;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_512)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_512;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_1024)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_1024;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_2048)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_2048;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_4096)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_4096;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_8192)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_8192;
fp@667: 	else if (max_frame <= E1000_RXBUFFER_16384)
fp@667: 		adapter->rx_buffer_len = E1000_RXBUFFER_16384;
fp@667: 
fp@667: 	/* adjust allocation if LPE protects us, and we aren't using SBP */
fp@667: 	if (!adapter->hw.tbi_compatibility_on &&
fp@667: 	    ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
fp@667: 	     (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
fp@667: 		adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
fp@667: 
fp@667: 	netdev->mtu = new_mtu;
fp@667: 
fp@668: 	if (adapter->ecdev || netif_running(netdev))
fp@667: 		e1000_reinit_locked(adapter);
fp@667: 
fp@667: 	adapter->hw.max_frame_size = max_frame;
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_update_stats - Update the board statistics counters
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: void
fp@667: e1000_update_stats(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@671: 	unsigned long flags = 0;
fp@667: 	uint16_t phy_tmp;
fp@667: 
fp@667: #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
fp@667: 
fp@667: 	/*
fp@667: 	 * Prevent stats update while adapter is being reset, or if the pci
fp@667: 	 * connection is down.
fp@667: 	 */
fp@667: 	if (adapter->link_speed == 0)
fp@667: 		return;
fp@667: 	if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
fp@667: 		return;
fp@667: 
fp@671: 	if (!adapter->ecdev)
fp@671: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@667: 
fp@667: 	/* these counters are modified from e1000_adjust_tbi_stats,
fp@667: 	 * called from the interrupt context, so they must only
fp@667: 	 * be written while holding adapter->stats_lock
fp@667: 	 */
fp@667: 
fp@667: 	adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
fp@667: 	adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
fp@667: 	adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
fp@667: 	adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
fp@667: 	adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
fp@667: 	adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
fp@667: 	adapter->stats.roc += E1000_READ_REG(hw, ROC);
fp@667: 
fp@667: 	if (adapter->hw.mac_type != e1000_ich8lan) {
fp@667: 	adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
fp@667: 	adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
fp@667: 	adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
fp@667: 	adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
fp@667: 	adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
fp@667: 	adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
fp@667: 	}
fp@667: 
fp@667: 	adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
fp@667: 	adapter->stats.mpc += E1000_READ_REG(hw, MPC);
fp@667: 	adapter->stats.scc += E1000_READ_REG(hw, SCC);
fp@667: 	adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
fp@667: 	adapter->stats.mcc += E1000_READ_REG(hw, MCC);
fp@667: 	adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
fp@667: 	adapter->stats.dc += E1000_READ_REG(hw, DC);
fp@667: 	adapter->stats.sec += E1000_READ_REG(hw, SEC);
fp@667: 	adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
fp@667: 	adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
fp@667: 	adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
fp@667: 	adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
fp@667: 	adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
fp@667: 	adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
fp@667: 	adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
fp@667: 	adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
fp@667: 	adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
fp@667: 	adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
fp@667: 	adapter->stats.ruc += E1000_READ_REG(hw, RUC);
fp@667: 	adapter->stats.rfc += E1000_READ_REG(hw, RFC);
fp@667: 	adapter->stats.rjc += E1000_READ_REG(hw, RJC);
fp@667: 	adapter->stats.torl += E1000_READ_REG(hw, TORL);
fp@667: 	adapter->stats.torh += E1000_READ_REG(hw, TORH);
fp@667: 	adapter->stats.totl += E1000_READ_REG(hw, TOTL);
fp@667: 	adapter->stats.toth += E1000_READ_REG(hw, TOTH);
fp@667: 	adapter->stats.tpr += E1000_READ_REG(hw, TPR);
fp@667: 
fp@667: 	if (adapter->hw.mac_type != e1000_ich8lan) {
fp@667: 	adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
fp@667: 	adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
fp@667: 	adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
fp@667: 	adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
fp@667: 	adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
fp@667: 	adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
fp@667: 	}
fp@667: 
fp@667: 	adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
fp@667: 	adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
fp@667: 
fp@667: 	/* used for adaptive IFS */
fp@667: 
fp@667: 	hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
fp@667: 	adapter->stats.tpt += hw->tx_packet_delta;
fp@667: 	hw->collision_delta = E1000_READ_REG(hw, COLC);
fp@667: 	adapter->stats.colc += hw->collision_delta;
fp@667: 
fp@667: 	if (hw->mac_type >= e1000_82543) {
fp@667: 		adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
fp@667: 		adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
fp@667: 		adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
fp@667: 		adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
fp@667: 		adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
fp@667: 		adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
fp@667: 	}
fp@667: 	if (hw->mac_type > e1000_82547_rev_2) {
fp@667: 		adapter->stats.iac += E1000_READ_REG(hw, IAC);
fp@667: 		adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
fp@667: 
fp@667: 		if (adapter->hw.mac_type != e1000_ich8lan) {
fp@667: 		adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
fp@667: 		adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
fp@667: 		adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
fp@667: 		adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
fp@667: 		adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
fp@667: 		adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
fp@667: 		adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	/* Fill out the OS statistics structure */
fp@667: 
fp@667: 	adapter->net_stats.rx_packets = adapter->stats.gprc;
fp@667: 	adapter->net_stats.tx_packets = adapter->stats.gptc;
fp@667: 	adapter->net_stats.rx_bytes = adapter->stats.gorcl;
fp@667: 	adapter->net_stats.tx_bytes = adapter->stats.gotcl;
fp@667: 	adapter->net_stats.multicast = adapter->stats.mprc;
fp@667: 	adapter->net_stats.collisions = adapter->stats.colc;
fp@667: 
fp@667: 	/* Rx Errors */
fp@667: 
fp@667: 	/* RLEC on some newer hardware can be incorrect so build
fp@667: 	* our own version based on RUC and ROC */
fp@667: 	adapter->net_stats.rx_errors = adapter->stats.rxerrc +
fp@667: 		adapter->stats.crcerrs + adapter->stats.algnerrc +
fp@667: 		adapter->stats.ruc + adapter->stats.roc +
fp@667: 		adapter->stats.cexterr;
fp@667: 	adapter->net_stats.rx_length_errors = adapter->stats.ruc +
fp@667: 	                                      adapter->stats.roc;
fp@667: 	adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
fp@667: 	adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
fp@667: 	adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
fp@667: 
fp@667: 	/* Tx Errors */
fp@667: 
fp@667: 	adapter->net_stats.tx_errors = adapter->stats.ecol +
fp@667: 	                               adapter->stats.latecol;
fp@667: 	adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
fp@667: 	adapter->net_stats.tx_window_errors = adapter->stats.latecol;
fp@667: 	adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
fp@667: 
fp@667: 	/* Tx Dropped needs to be maintained elsewhere */
fp@667: 
fp@667: 	/* Phy Stats */
fp@667: 
fp@667: 	if (hw->media_type == e1000_media_type_copper) {
fp@667: 		if ((adapter->link_speed == SPEED_1000) &&
fp@667: 		   (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
fp@667: 			phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
fp@667: 			adapter->phy_stats.idle_errors += phy_tmp;
fp@667: 		}
fp@667: 
fp@667: 		if ((hw->mac_type <= e1000_82546) &&
fp@667: 		   (hw->phy_type == e1000_phy_m88) &&
fp@667: 		   !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
fp@667: 			adapter->phy_stats.receive_errors += phy_tmp;
fp@667: 	}
fp@667: 
fp@671: 	if (!adapter->ecdev)
fp@671: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@671: }
fp@671: 
fp@678: void ec_poll(struct net_device *netdev)
fp@678: {
fp@678:     struct e1000_adapter *adapter = netdev_priv(netdev);
fp@678: 
fp@678:     if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) {
fp@678:         e1000_watchdog_task(adapter);
fp@678:         adapter->ec_watchdog_jiffies = jiffies;
fp@678:     }
fp@678: 
fp@678:     e1000_intr(0, netdev, NULL);
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_intr - Interrupt Handler
fp@667:  * @irq: interrupt number
fp@667:  * @data: pointer to a network interface device structure
fp@667:  * @pt_regs: CPU registers structure
fp@667:  **/
fp@667: 
fp@667: static irqreturn_t
fp@667: e1000_intr(int irq, void *data, struct pt_regs *regs)
fp@667: {
fp@667: 	struct net_device *netdev = data;
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	struct e1000_hw *hw = &adapter->hw;
fp@667: 	uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
fp@667: #ifndef CONFIG_E1000_NAPI
fp@667: 	int i;
fp@667: #else
fp@667: 	/* Interrupt Auto-Mask...upon reading ICR,
fp@667: 	 * interrupts are masked.  No need for the
fp@667: 	 * IMC write, but it does mean we should
fp@667: 	 * account for it ASAP. */
fp@667: 	if (likely(hw->mac_type >= e1000_82571))
fp@667: 		atomic_inc(&adapter->irq_sem);
fp@667: #endif
fp@667: 
fp@667: 	if (unlikely(!icr)) {
fp@667: #ifdef CONFIG_E1000_NAPI
fp@671: 		if (hw->mac_type >= e1000_82571)
fp@667: 			e1000_irq_enable(adapter);
fp@667: #endif
fp@667: 		return IRQ_NONE;  /* Not our interrupt */
fp@667: 	}
fp@667: 
fp@678: 	if (!adapter->ecdev && unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
fp@667: 		hw->get_link_status = 1;
fp@667: 		/* 80003ES2LAN workaround--
fp@667: 		 * For packet buffer work-around on link down event;
fp@667: 		 * disable receives here in the ISR and
fp@667: 		 * reset adapter in watchdog
fp@667: 		 */
fp@678: 		if (netif_carrier_ok(netdev) &&
fp@678: 		    (adapter->hw.mac_type == e1000_80003es2lan)) {
fp@667: 			/* disable receives */
fp@667: 			rctl = E1000_READ_REG(hw, RCTL);
fp@667: 			E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
fp@667: 		}
fp@667: 		mod_timer(&adapter->watchdog_timer, jiffies);
fp@667: 	}
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@678:     if (!adapter->ecdev) {
fp@678:         if (unlikely(hw->mac_type < e1000_82571)) {
fp@678:             atomic_inc(&adapter->irq_sem);
fp@678:             E1000_WRITE_REG(hw, IMC, ~0);
fp@678:             E1000_WRITE_FLUSH(hw);
fp@678:         }
fp@678: 
fp@671: 		if (likely(netif_rx_schedule_prep(netdev)))
fp@671: 			__netif_rx_schedule(netdev);
fp@671: 		else
fp@671: 			e1000_irq_enable(adapter);
fp@678:     }
fp@667: #else
fp@671: 	/* Writing IMC and IMS is needed for 82547.
fp@671: 	 * Due to Hub Link bus being occupied, an interrupt
fp@667: 	 * de-assertion message is not able to be sent.
fp@667: 	 * When an interrupt assertion message is generated later,
fp@667: 	 * two messages are re-ordered and sent out.
fp@667: 	 * That causes APIC to think 82547 is in de-assertion
fp@667: 	 * state, while 82547 is in assertion state, resulting
fp@667: 	 * in dead lock. Writing IMC forces 82547 into
fp@667: 	 * de-assertion state.
fp@667: 	 */
fp@678: 	if (!adapter->ecdev &&
fp@678:             (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)) {
fp@667: 		atomic_inc(&adapter->irq_sem);
fp@667: 		E1000_WRITE_REG(hw, IMC, ~0);
fp@667: 	}
fp@667: 
fp@667: 	for (i = 0; i < E1000_MAX_INTR; i++)
fp@667: 		if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
fp@667: 		   !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
fp@667: 			break;
fp@667: 
fp@678: 	if (adapter->ecdev &&
fp@678:             (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2))
fp@667: 		e1000_irq_enable(adapter);
fp@667: 
fp@667: #endif
fp@667: 
fp@667: 	return IRQ_HANDLED;
fp@667: }
fp@667: 
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: /**
fp@667:  * e1000_clean - NAPI Rx polling callback
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static int
fp@668: e1000_clean(struct net_device *poll_dev, int *budget) // never called for EtherCAT
fp@667: {
fp@667: 	struct e1000_adapter *adapter;
fp@667: 	int work_to_do = min(*budget, poll_dev->quota);
fp@667: 	int tx_cleaned = 0, work_done = 0;
fp@667: 
fp@667: 	/* Must NOT use netdev_priv macro here. */
fp@667: 	adapter = poll_dev->priv;
fp@667: 
fp@667: 	/* Keep link state information with original netdev */
fp@667: 	if (!netif_carrier_ok(poll_dev))
fp@667: 		goto quit_polling;
fp@667: 
fp@667: 	/* e1000_clean is called per-cpu.  This lock protects
fp@667: 	 * tx_ring[0] from being cleaned by multiple cpus
fp@667: 	 * simultaneously.  A failure obtaining the lock means
fp@667: 	 * tx_ring[0] is currently being cleaned anyway. */
fp@667: 	if (spin_trylock(&adapter->tx_queue_lock)) {
fp@667: 		tx_cleaned = e1000_clean_tx_irq(adapter,
fp@667: 		                                &adapter->tx_ring[0]);
fp@667: 		spin_unlock(&adapter->tx_queue_lock);
fp@667: 	}
fp@667: 
fp@667: 	adapter->clean_rx(adapter, &adapter->rx_ring[0],
fp@667: 	                  &work_done, work_to_do);
fp@667: 
fp@667: 	*budget -= work_done;
fp@667: 	poll_dev->quota -= work_done;
fp@667: 
fp@667: 	/* If no Tx and not enough Rx work done, exit the polling mode */
fp@667: 	if ((!tx_cleaned && (work_done == 0)) ||
fp@667: 	   !netif_running(poll_dev)) {
fp@667: quit_polling:
fp@667: 		netif_rx_complete(poll_dev);
fp@667: 		e1000_irq_enable(adapter);
fp@667: 		return 0;
fp@667: 	}
fp@667: 
fp@667: 	return 1;
fp@667: }
fp@667: 
fp@667: #endif
fp@667: /**
fp@667:  * e1000_clean_tx_irq - Reclaim resources after transmit completes
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static boolean_t
fp@667: e1000_clean_tx_irq(struct e1000_adapter *adapter,
fp@667:                    struct e1000_tx_ring *tx_ring)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct e1000_tx_desc *tx_desc, *eop_desc;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	unsigned int i, eop;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 	unsigned int count = 0;
fp@667: #endif
fp@667: 	boolean_t cleaned = FALSE;
fp@667: 
fp@667: 	i = tx_ring->next_to_clean;
fp@667: 	eop = tx_ring->buffer_info[i].next_to_watch;
fp@667: 	eop_desc = E1000_TX_DESC(*tx_ring, eop);
fp@667: 
fp@667: 	while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
fp@667: 		for (cleaned = FALSE; !cleaned; ) {
fp@667: 			tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@667: 			buffer_info = &tx_ring->buffer_info[i];
fp@667: 			cleaned = (i == eop);
fp@667: 
fp@667: 			e1000_unmap_and_free_tx_resource(adapter, buffer_info);
fp@667: 			memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
fp@667: 
fp@667: 			if (unlikely(++i == tx_ring->count)) i = 0;
fp@667: 		}
fp@667: 
fp@667: 
fp@667: 		eop = tx_ring->buffer_info[i].next_to_watch;
fp@667: 		eop_desc = E1000_TX_DESC(*tx_ring, eop);
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: #define E1000_TX_WEIGHT 64
fp@667: 		/* weight of a sort for tx, to avoid endless transmit cleanup */
fp@667: 		if (count++ == E1000_TX_WEIGHT) break;
fp@667: #endif
fp@667: 	}
fp@667: 
fp@667: 	tx_ring->next_to_clean = i;
fp@667: 
fp@667: #define TX_WAKE_THRESHOLD 32
fp@668: 	if (unlikely(!adapter->ecdev && cleaned && netif_queue_stopped(netdev) &&
fp@678: 	             netif_carrier_ok(netdev))) {
fp@667: 		spin_lock(&tx_ring->tx_lock);
fp@667: 		if (netif_queue_stopped(netdev) &&
fp@678: 		    (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
fp@667: 			netif_wake_queue(netdev);
fp@667: 		spin_unlock(&tx_ring->tx_lock);
fp@667: 	}
fp@667: 
fp@678: 	if(!adapter->ecdev && adapter->detect_tx_hung) {
fp@667: 		/* Detect a transmit hang in hardware, this serializes the
fp@667: 		 * check with the clearing of time_stamp and movement of i */
fp@667: 		adapter->detect_tx_hung = FALSE;
fp@667: 		if (tx_ring->buffer_info[eop].dma &&
fp@667: 		    time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
fp@667: 		               (adapter->tx_timeout_factor * HZ))
fp@667: 		    && !(E1000_READ_REG(&adapter->hw, STATUS) &
fp@667: 		         E1000_STATUS_TXOFF)) {
fp@667: 
fp@667: 			/* detected Tx unit hang */
fp@667: 			DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
fp@667: 					"  Tx Queue             <%lu>\n"
fp@667: 					"  TDH                  <%x>\n"
fp@667: 					"  TDT                  <%x>\n"
fp@667: 					"  next_to_use          <%x>\n"
fp@667: 					"  next_to_clean        <%x>\n"
fp@667: 					"buffer_info[next_to_clean]\n"
fp@667: 					"  time_stamp           <%lx>\n"
fp@667: 					"  next_to_watch        <%x>\n"
fp@667: 					"  jiffies              <%lx>\n"
fp@667: 					"  next_to_watch.status <%x>\n",
fp@678: 				(unsigned long)((tx_ring - adapter->tx_ring) /
fp@678: 					sizeof(struct e1000_tx_ring)),
fp@678: 				readl(adapter->hw.hw_addr + tx_ring->tdh),
fp@678: 				readl(adapter->hw.hw_addr + tx_ring->tdt),
fp@678: 				tx_ring->next_to_use,
fp@678: 				tx_ring->next_to_clean,
fp@678: 				tx_ring->buffer_info[eop].time_stamp,
fp@678: 				eop,
fp@678: 				jiffies,
fp@678: 				eop_desc->upper.fields.status);
fp@678: 			netif_stop_queue(netdev);
fp@667: 		}
fp@667: 	}
fp@667: 	return cleaned;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_rx_checksum - Receive Checksum Offload for 82543
fp@667:  * @adapter:     board private structure
fp@667:  * @status_err:  receive descriptor status and error fields
fp@667:  * @csum:        receive descriptor csum field
fp@667:  * @sk_buff:     socket buffer with received data
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_rx_checksum(struct e1000_adapter *adapter,
fp@667: 		  uint32_t status_err, uint32_t csum,
fp@667: 		  struct sk_buff *skb)
fp@667: {
fp@667: 	uint16_t status = (uint16_t)status_err;
fp@667: 	uint8_t errors = (uint8_t)(status_err >> 24);
fp@667: 	skb->ip_summed = CHECKSUM_NONE;
fp@667: 
fp@667: 	/* 82543 or newer only */
fp@667: 	if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
fp@667: 	/* Ignore Checksum bit is set */
fp@667: 	if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
fp@667: 	/* TCP/UDP checksum error bit is set */
fp@667: 	if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
fp@667: 		/* let the stack verify checksum errors */
fp@667: 		adapter->hw_csum_err++;
fp@667: 		return;
fp@667: 	}
fp@667: 	/* TCP/UDP Checksum has not been calculated */
fp@667: 	if (adapter->hw.mac_type <= e1000_82547_rev_2) {
fp@667: 		if (!(status & E1000_RXD_STAT_TCPCS))
fp@667: 			return;
fp@667: 	} else {
fp@667: 		if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
fp@667: 			return;
fp@667: 	}
fp@667: 	/* It must be a TCP or UDP packet with a valid checksum */
fp@667: 	if (likely(status & E1000_RXD_STAT_TCPCS)) {
fp@667: 		/* TCP checksum is good */
fp@667: 		skb->ip_summed = CHECKSUM_UNNECESSARY;
fp@667: 	} else if (adapter->hw.mac_type > e1000_82547_rev_2) {
fp@667: 		/* IP fragment with UDP payload */
fp@667: 		/* Hardware complements the payload checksum, so we undo it
fp@667: 		 * and then put the value in host order for further stack use.
fp@667: 		 */
fp@667: 		csum = ntohl(csum ^ 0xFFFF);
fp@667: 		skb->csum = csum;
fp@667: 		skb->ip_summed = CHECKSUM_HW;
fp@667: 	}
fp@667: 	adapter->hw_csum_good++;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_rx_irq - Send received data up the network stack; legacy
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static boolean_t
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: e1000_clean_rx_irq(struct e1000_adapter *adapter,
fp@667:                    struct e1000_rx_ring *rx_ring,
fp@667:                    int *work_done, int work_to_do)
fp@667: #else
fp@667: e1000_clean_rx_irq(struct e1000_adapter *adapter,
fp@667:                    struct e1000_rx_ring *rx_ring)
fp@667: #endif
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	struct e1000_rx_desc *rx_desc, *next_rxd;
fp@667: 	struct e1000_buffer *buffer_info, *next_buffer;
fp@667: 	unsigned long flags;
fp@667: 	uint32_t length;
fp@667: 	uint8_t last_byte;
fp@667: 	unsigned int i;
fp@667: 	int cleaned_count = 0;
fp@667: 	boolean_t cleaned = FALSE;
fp@667: 
fp@667: 	i = rx_ring->next_to_clean;
fp@667: 	rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@667: 	buffer_info = &rx_ring->buffer_info[i];
fp@667: 
fp@667: 	while (rx_desc->status & E1000_RXD_STAT_DD) {
fp@667: 		struct sk_buff *skb;
fp@667: 		u8 status;
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 		if (*work_done >= work_to_do)
fp@667: 			break;
fp@667: 		(*work_done)++;
fp@667: #endif
fp@667: 		status = rx_desc->status;
fp@667: 		skb = buffer_info->skb;
fp@671: 		if (!adapter->ecdev) buffer_info->skb = NULL;
fp@667: 
fp@667: 		prefetch(skb->data - NET_IP_ALIGN);
fp@667: 
fp@667: 		if (++i == rx_ring->count) i = 0;
fp@667: 		next_rxd = E1000_RX_DESC(*rx_ring, i);
fp@667: 		prefetch(next_rxd);
fp@667: 
fp@667: 		next_buffer = &rx_ring->buffer_info[i];
fp@667: 
fp@667: 		cleaned = TRUE;
fp@667: 		cleaned_count++;
fp@667: 		pci_unmap_single(pdev,
fp@667: 		                 buffer_info->dma,
fp@667: 		                 buffer_info->length,
fp@667: 		                 PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 		length = le16_to_cpu(rx_desc->length);
fp@667: 
fp@667: 		/* adjust length to remove Ethernet CRC */
fp@667: 		length -= 4;
fp@667: 
fp@667: 		if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
fp@667: 			/* All receives must fit into a single buffer */
fp@667: 			E1000_DBG("%s: Receive packet consumed multiple"
fp@667: 				  " buffers\n", netdev->name);
fp@667: 			/* recycle */
fp@667: 			buffer_info-> skb = skb;
fp@667: 			goto next_desc;
fp@667: 		}
fp@667: 
fp@668: 		if (!adapter->ecdev && unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
fp@667: 			last_byte = *(skb->data + length - 1);
fp@667: 			if (TBI_ACCEPT(&adapter->hw, status,
fp@678: 			              rx_desc->errors, length, last_byte)) {
fp@667: 				spin_lock_irqsave(&adapter->stats_lock, flags);
fp@667: 				e1000_tbi_adjust_stats(&adapter->hw,
fp@678: 				                       &adapter->stats,
fp@678: 				                       length, skb->data);
fp@667: 				spin_unlock_irqrestore(&adapter->stats_lock,
fp@678: 				                       flags);
fp@667: 				length--;
fp@667: 			} else {
fp@667: 				/* recycle */
fp@667: 				buffer_info->skb = skb;
fp@667: 				goto next_desc;
fp@667: 			}
fp@667: 		}
fp@667: 
fp@667: 		/* code added for copybreak, this should improve
fp@667: 		 * performance for small packets with large amounts
fp@667: 		 * of reassembly being done in the stack */
fp@667: #define E1000_CB_LENGTH 256
fp@668: 		if (!adapter->ecdev && length < E1000_CB_LENGTH) {
fp@667: 			struct sk_buff *new_skb =
fp@678: 			    netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
fp@667: 			if (new_skb) {
fp@667: 				skb_reserve(new_skb, NET_IP_ALIGN);
fp@667: 				new_skb->dev = netdev;
fp@667: 				memcpy(new_skb->data - NET_IP_ALIGN,
fp@678: 				       skb->data - NET_IP_ALIGN,
fp@678: 				       length + NET_IP_ALIGN);
fp@667: 				/* save the skb in buffer_info as good */
fp@667: 				buffer_info->skb = skb;
fp@667: 				skb = new_skb;
fp@667: 				skb_put(skb, length);
fp@667: 			}
fp@667: 		} else
fp@667: 			skb_put(skb, length);
fp@667: 
fp@667: 		/* end copybreak code */
fp@667: 
fp@667: 		/* Receive Checksum Offload */
fp@667: 		e1000_rx_checksum(adapter,
fp@667: 				  (uint32_t)(status) |
fp@667: 				  ((uint32_t)(rx_desc->errors) << 24),
fp@667: 				  le16_to_cpu(rx_desc->csum), skb);
fp@667: 
fp@671: 		if (adapter->ecdev) {
fp@671: 			ecdev_receive(adapter->ecdev, skb->data, length);
fp@678: 			skb_trim(skb, 0);
fp@678: 
fp@678: 			if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@678: 				/* Force memory writes to complete before letting h/w
fp@678: 				 * know there are new descriptors to fetch.  (Only
fp@678: 				 * applicable for weak-ordered memory model archs,
fp@678: 				 * such as IA-64). */
fp@678: 				wmb();
fp@678: 				E1000_WRITE_REG(&adapter->hw, RDT, i);
fp@678: 			}
fp@671: 		} else {
fp@671: 			skb->protocol = eth_type_trans(skb, netdev);
fp@667: #ifdef CONFIG_E1000_NAPI
fp@671:             if (unlikely(adapter->vlgrp &&
fp@671:                         (status & E1000_RXD_STAT_VP))) {
fp@671:                 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
fp@671:                         le16_to_cpu(rx_desc->special) &
fp@671:                         E1000_RXD_SPC_VLAN_MASK);
fp@671:             } else {
fp@671:                 netif_receive_skb(skb);
fp@671:             }
fp@667: #else /* CONFIG_E1000_NAPI */
fp@671:             if (unlikely(adapter->vlgrp &&
fp@671:                         (status & E1000_RXD_STAT_VP))) {
fp@671:                 vlan_hwaccel_rx(skb, adapter->vlgrp,
fp@671:                         le16_to_cpu(rx_desc->special) &
fp@671:                         E1000_RXD_SPC_VLAN_MASK);
fp@671:             } else {
fp@671:                 netif_rx(skb);
fp@671:             }
fp@667: #endif /* CONFIG_E1000_NAPI */
fp@671:         }
fp@667: 		netdev->last_rx = jiffies;
fp@667: 
fp@667: next_desc:
fp@667: 		rx_desc->status = 0;
fp@667: 
fp@667: 		/* return some buffers to hardware, one at a time is too slow */
fp@667: 		if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
fp@667: 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
fp@667: 			cleaned_count = 0;
fp@667: 		}
fp@667: 
fp@667: 		/* use prefetched values */
fp@667: 		rx_desc = next_rxd;
fp@667: 		buffer_info = next_buffer;
fp@667: 	}
fp@667: 	rx_ring->next_to_clean = i;
fp@667: 
fp@667: 	cleaned_count = E1000_DESC_UNUSED(rx_ring);
fp@667: 	if (cleaned_count)
fp@667: 		adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
fp@667: 
fp@667: 	return cleaned;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
fp@667:  * @adapter: board private structure
fp@667:  **/
fp@667: 
fp@667: static boolean_t
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
fp@667:                       struct e1000_rx_ring *rx_ring,
fp@667:                       int *work_done, int work_to_do)
fp@667: #else
fp@667: e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
fp@667:                       struct e1000_rx_ring *rx_ring)
fp@667: #endif
fp@667: {
fp@667: 	union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	struct e1000_buffer *buffer_info, *next_buffer;
fp@667: 	struct e1000_ps_page *ps_page;
fp@667: 	struct e1000_ps_page_dma *ps_page_dma;
fp@667: 	struct sk_buff *skb;
fp@667: 	unsigned int i, j;
fp@667: 	uint32_t length, staterr;
fp@667: 	int cleaned_count = 0;
fp@667: 	boolean_t cleaned = FALSE;
fp@667: 
fp@667: 	i = rx_ring->next_to_clean;
fp@667: 	rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
fp@667: 	staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
fp@667: 	buffer_info = &rx_ring->buffer_info[i];
fp@667: 
fp@667: 	while (staterr & E1000_RXD_STAT_DD) {
fp@667: 		ps_page = &rx_ring->ps_page[i];
fp@667: 		ps_page_dma = &rx_ring->ps_page_dma[i];
fp@667: #ifdef CONFIG_E1000_NAPI
fp@667: 		if (unlikely(*work_done >= work_to_do))
fp@667: 			break;
fp@667: 		(*work_done)++;
fp@667: #endif
fp@667: 		skb = buffer_info->skb;
fp@667: 
fp@667: 		/* in the packet split case this is header only */
fp@667: 		prefetch(skb->data - NET_IP_ALIGN);
fp@667: 
fp@667: 		if (++i == rx_ring->count) i = 0;
fp@667: 		next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
fp@667: 		prefetch(next_rxd);
fp@667: 
fp@667: 		next_buffer = &rx_ring->buffer_info[i];
fp@667: 
fp@667: 		cleaned = TRUE;
fp@667: 		cleaned_count++;
fp@667: 		pci_unmap_single(pdev, buffer_info->dma,
fp@667: 				 buffer_info->length,
fp@667: 				 PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 		if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
fp@667: 			E1000_DBG("%s: Packet Split buffers didn't pick up"
fp@667: 				  " the full packet\n", netdev->name);
fp@671: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@667: 			goto next_desc;
fp@667: 		}
fp@667: 
fp@667: 		if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
fp@671: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@667: 			goto next_desc;
fp@667: 		}
fp@667: 
fp@667: 		length = le16_to_cpu(rx_desc->wb.middle.length0);
fp@667: 
fp@667: 		if (unlikely(!length)) {
fp@667: 			E1000_DBG("%s: Last part of the packet spanning"
fp@667: 				  " multiple descriptors\n", netdev->name);
fp@671: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@667: 			goto next_desc;
fp@667: 		}
fp@667: 
fp@667: 		/* Good Receive */
fp@667: 		skb_put(skb, length);
fp@667: 
fp@667: 		{
fp@667: 		/* this looks ugly, but it seems compiler issues make it
fp@667: 		   more efficient than reusing j */
fp@667: 		int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
fp@667: 
fp@667: 		/* page alloc/put takes too long and effects small packet
fp@667: 		 * throughput, so unsplit small packets and save the alloc/put*/
fp@667: 		if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
fp@667: 			u8 *vaddr;
fp@667: 			/* there is no documentation about how to call
fp@667: 			 * kmap_atomic, so we can't hold the mapping
fp@667: 			 * very long */
fp@667: 			pci_dma_sync_single_for_cpu(pdev,
fp@667: 				ps_page_dma->ps_page_dma[0],
fp@667: 				PAGE_SIZE,
fp@667: 				PCI_DMA_FROMDEVICE);
fp@667: 			vaddr = kmap_atomic(ps_page->ps_page[0],
fp@667: 			                    KM_SKB_DATA_SOFTIRQ);
fp@667: 			memcpy(skb->tail, vaddr, l1);
fp@667: 			kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
fp@667: 			pci_dma_sync_single_for_device(pdev,
fp@667: 				ps_page_dma->ps_page_dma[0],
fp@667: 				PAGE_SIZE, PCI_DMA_FROMDEVICE);
fp@667: 			/* remove the CRC */
fp@667: 			l1 -= 4;
fp@667: 			skb_put(skb, l1);
fp@667: 			goto copydone;
fp@667: 		} /* if */
fp@667: 		}
fp@667: 		
fp@667: 		for (j = 0; j < adapter->rx_ps_pages; j++) {
fp@667: 			if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
fp@667: 				break;
fp@667: 			pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
fp@667: 					PAGE_SIZE, PCI_DMA_FROMDEVICE);
fp@667: 			ps_page_dma->ps_page_dma[j] = 0;
fp@667: 			skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
fp@667: 			                   length);
fp@667: 			ps_page->ps_page[j] = NULL;
fp@667: 			skb->len += length;
fp@667: 			skb->data_len += length;
fp@667: 			skb->truesize += length;
fp@667: 		}
fp@667: 
fp@667: 		/* strip the ethernet crc, problem is we're using pages now so
fp@667: 		 * this whole operation can get a little cpu intensive */
fp@667: 		pskb_trim(skb, skb->len - 4);
fp@667: 
fp@667: copydone:
fp@667: 		e1000_rx_checksum(adapter, staterr,
fp@667: 				  le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
fp@667: 
fp@667: 		if (likely(rx_desc->wb.upper.header_status &
fp@667: 			   cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
fp@667: 			adapter->rx_hdr_split++;
fp@671: 		if (adapter->ecdev) {
fp@671: 			ecdev_receive(adapter->ecdev, skb->data, length);
fp@678: 			skb_trim(skb, 0);
fp@678: 
fp@678: 			if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@678: 				/* Force memory writes to complete before letting h/w
fp@678: 				 * know there are new descriptors to fetch.  (Only
fp@678: 				 * applicable for weak-ordered memory model archs,
fp@678: 				 * such as IA-64). */
fp@678: 				wmb();
fp@678: 				/* Hardware increments by 16 bytes, but packet split
fp@678: 				 * descriptors are 32 bytes...so we increment tail
fp@678: 				 * twice as much.
fp@678: 				 */
fp@678: 				E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
fp@678: 			}
fp@671: 		} else {
fp@671: 			skb->protocol = eth_type_trans(skb, netdev);
fp@667: #ifdef CONFIG_E1000_NAPI
fp@671: 			if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
fp@671: 				vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
fp@671: 						le16_to_cpu(rx_desc->wb.middle.vlan) &
fp@671: 						E1000_RXD_SPC_VLAN_MASK);
fp@671: 			} else {
fp@671: 				netif_receive_skb(skb);
fp@671: 			}
fp@667: #else /* CONFIG_E1000_NAPI */
fp@671: 			if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
fp@671: 				vlan_hwaccel_rx(skb, adapter->vlgrp,
fp@671: 						le16_to_cpu(rx_desc->wb.middle.vlan) &
fp@671: 						E1000_RXD_SPC_VLAN_MASK);
fp@671: 			} else {
fp@671: 				netif_rx(skb);
fp@671: 			}
fp@667: #endif /* CONFIG_E1000_NAPI */
fp@671: 		}
fp@667: 		netdev->last_rx = jiffies;
fp@667: 
fp@667: next_desc:
fp@667: 		rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
fp@671: 		if (!adapter->ecdev) buffer_info->skb = NULL;
fp@667: 
fp@667: 		/* return some buffers to hardware, one at a time is too slow */
fp@671: 		if (unlikely(!adapter->ecdev && cleaned_count >= E1000_RX_BUFFER_WRITE)) {
fp@667: 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
fp@667: 			cleaned_count = 0;
fp@667: 		}
fp@667: 
fp@667: 		/* use prefetched values */
fp@667: 		rx_desc = next_rxd;
fp@667: 		buffer_info = next_buffer;
fp@667: 
fp@667: 		staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
fp@667: 	}
fp@667: 	rx_ring->next_to_clean = i;
fp@667: 
fp@671: 	if (!adapter->ecdev) {
fp@671: 		cleaned_count = E1000_DESC_UNUSED(rx_ring);
fp@671: 		if (cleaned_count)
fp@671: 			adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
fp@671: 	}
fp@667: 
fp@667: 	return cleaned;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
fp@667:  * @adapter: address of board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
fp@667:                        struct e1000_rx_ring *rx_ring,
fp@667: 		       int cleaned_count)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	struct e1000_rx_desc *rx_desc;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	struct sk_buff *skb;
fp@667: 	unsigned int i;
fp@667: 	unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
fp@667: 
fp@667: 	i = rx_ring->next_to_use;
fp@667: 	buffer_info = &rx_ring->buffer_info[i];
fp@667: 
fp@667: 	while (cleaned_count--) {
fp@667: 		if (!(skb = buffer_info->skb))
fp@667: 			skb = netdev_alloc_skb(netdev, bufsz);
fp@667: 		else {
fp@667: 			skb_trim(skb, 0);
fp@667: 			goto map_skb;
fp@667: 		}
fp@667: 
fp@667: 		if (unlikely(!skb)) {
fp@667: 			/* Better luck next round */
fp@667: 			adapter->alloc_rx_buff_failed++;
fp@667: 			break;
fp@667: 		}
fp@667: 
fp@667: 		/* Fix for errata 23, can't cross 64kB boundary */
fp@667: 		if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
fp@667: 			struct sk_buff *oldskb = skb;
fp@667: 			DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
fp@667: 					     "at %p\n", bufsz, skb->data);
fp@667: 			/* Try again, without freeing the previous */
fp@667: 			skb = netdev_alloc_skb(netdev, bufsz);
fp@667: 			/* Failed allocation, critical failure */
fp@667: 			if (!skb) {
fp@667: 				dev_kfree_skb(oldskb);
fp@667: 				break;
fp@667: 			}
fp@667: 
fp@667: 			if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
fp@667: 				/* give up */
fp@667: 				dev_kfree_skb(skb);
fp@667: 				dev_kfree_skb(oldskb);
fp@667: 				break; /* while !buffer_info->skb */
fp@667: 			} else {
fp@667: 				/* Use new allocation */
fp@667: 				dev_kfree_skb(oldskb);
fp@667: 			}
fp@667: 		}
fp@667: 		/* Make buffer alignment 2 beyond a 16 byte boundary
fp@667: 		 * this will result in a 16 byte aligned IP header after
fp@667: 		 * the 14 byte MAC header is removed
fp@667: 		 */
fp@667: 		skb_reserve(skb, NET_IP_ALIGN);
fp@667: 
fp@667: 		skb->dev = netdev;
fp@667: 
fp@667: 		buffer_info->skb = skb;
fp@667: 		buffer_info->length = adapter->rx_buffer_len;
fp@667: map_skb:
fp@667: 		buffer_info->dma = pci_map_single(pdev,
fp@667: 						  skb->data,
fp@667: 						  adapter->rx_buffer_len,
fp@667: 						  PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 		/* Fix for errata 23, can't cross 64kB boundary */
fp@667: 		if (!e1000_check_64k_bound(adapter,
fp@667: 					(void *)(unsigned long)buffer_info->dma,
fp@667: 					adapter->rx_buffer_len)) {
fp@667: 			DPRINTK(RX_ERR, ERR,
fp@667: 				"dma align check failed: %u bytes at %p\n",
fp@667: 				adapter->rx_buffer_len,
fp@667: 				(void *)(unsigned long)buffer_info->dma);
fp@667: 			dev_kfree_skb(skb);
fp@667: 			buffer_info->skb = NULL;
fp@667: 
fp@667: 			pci_unmap_single(pdev, buffer_info->dma,
fp@667: 					 adapter->rx_buffer_len,
fp@667: 					 PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 			break; /* while !buffer_info->skb */
fp@667: 		}
fp@667: 		rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@667: 		rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
fp@667: 
fp@667: 		if (unlikely(++i == rx_ring->count))
fp@667: 			i = 0;
fp@667: 		buffer_info = &rx_ring->buffer_info[i];
fp@667: 	}
fp@667: 
fp@667: 	if (likely(rx_ring->next_to_use != i)) {
fp@667: 		rx_ring->next_to_use = i;
fp@667: 		if (unlikely(i-- == 0))
fp@667: 			i = (rx_ring->count - 1);
fp@667: 
fp@667: 		/* Force memory writes to complete before letting h/w
fp@667: 		 * know there are new descriptors to fetch.  (Only
fp@667: 		 * applicable for weak-ordered memory model archs,
fp@667: 		 * such as IA-64). */
fp@667: 		wmb();
fp@667: 		writel(i, adapter->hw.hw_addr + rx_ring->rdt);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
fp@667:  * @adapter: address of board private structure
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
fp@667:                           struct e1000_rx_ring *rx_ring,
fp@667: 			  int cleaned_count)
fp@667: {
fp@667: 	struct net_device *netdev = adapter->netdev;
fp@667: 	struct pci_dev *pdev = adapter->pdev;
fp@667: 	union e1000_rx_desc_packet_split *rx_desc;
fp@667: 	struct e1000_buffer *buffer_info;
fp@667: 	struct e1000_ps_page *ps_page;
fp@667: 	struct e1000_ps_page_dma *ps_page_dma;
fp@667: 	struct sk_buff *skb;
fp@667: 	unsigned int i, j;
fp@667: 
fp@667: 	i = rx_ring->next_to_use;
fp@667: 	buffer_info = &rx_ring->buffer_info[i];
fp@667: 	ps_page = &rx_ring->ps_page[i];
fp@667: 	ps_page_dma = &rx_ring->ps_page_dma[i];
fp@667: 
fp@667: 	while (cleaned_count--) {
fp@667: 		rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
fp@667: 
fp@667: 		for (j = 0; j < PS_PAGE_BUFFERS; j++) {
fp@667: 			if (j < adapter->rx_ps_pages) {
fp@667: 				if (likely(!ps_page->ps_page[j])) {
fp@667: 					ps_page->ps_page[j] =
fp@667: 						alloc_page(GFP_ATOMIC);
fp@667: 					if (unlikely(!ps_page->ps_page[j])) {
fp@667: 						adapter->alloc_rx_buff_failed++;
fp@667: 						goto no_buffers;
fp@667: 					}
fp@667: 					ps_page_dma->ps_page_dma[j] =
fp@667: 						pci_map_page(pdev,
fp@667: 							    ps_page->ps_page[j],
fp@667: 							    0, PAGE_SIZE,
fp@667: 							    PCI_DMA_FROMDEVICE);
fp@667: 				}
fp@667: 				/* Refresh the desc even if buffer_addrs didn't
fp@667: 				 * change because each write-back erases
fp@667: 				 * this info.
fp@667: 				 */
fp@667: 				rx_desc->read.buffer_addr[j+1] =
fp@667: 				     cpu_to_le64(ps_page_dma->ps_page_dma[j]);
fp@667: 			} else
fp@667: 				rx_desc->read.buffer_addr[j+1] = ~0;
fp@667: 		}
fp@667: 
fp@667: 		skb = netdev_alloc_skb(netdev,
fp@667: 				       adapter->rx_ps_bsize0 + NET_IP_ALIGN);
fp@667: 
fp@667: 		if (unlikely(!skb)) {
fp@667: 			adapter->alloc_rx_buff_failed++;
fp@667: 			break;
fp@667: 		}
fp@667: 
fp@667: 		/* Make buffer alignment 2 beyond a 16 byte boundary
fp@667: 		 * this will result in a 16 byte aligned IP header after
fp@667: 		 * the 14 byte MAC header is removed
fp@667: 		 */
fp@667: 		skb_reserve(skb, NET_IP_ALIGN);
fp@667: 
fp@667: 		skb->dev = netdev;
fp@667: 
fp@667: 		buffer_info->skb = skb;
fp@667: 		buffer_info->length = adapter->rx_ps_bsize0;
fp@667: 		buffer_info->dma = pci_map_single(pdev, skb->data,
fp@667: 						  adapter->rx_ps_bsize0,
fp@667: 						  PCI_DMA_FROMDEVICE);
fp@667: 
fp@667: 		rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
fp@667: 
fp@667: 		if (unlikely(++i == rx_ring->count)) i = 0;
fp@667: 		buffer_info = &rx_ring->buffer_info[i];
fp@667: 		ps_page = &rx_ring->ps_page[i];
fp@667: 		ps_page_dma = &rx_ring->ps_page_dma[i];
fp@667: 	}
fp@667: 
fp@667: no_buffers:
fp@667: 	if (likely(rx_ring->next_to_use != i)) {
fp@667: 		rx_ring->next_to_use = i;
fp@667: 		if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
fp@667: 
fp@667: 		/* Force memory writes to complete before letting h/w
fp@667: 		 * know there are new descriptors to fetch.  (Only
fp@667: 		 * applicable for weak-ordered memory model archs,
fp@667: 		 * such as IA-64). */
fp@667: 		wmb();
fp@667: 		/* Hardware increments by 16 bytes, but packet split
fp@667: 		 * descriptors are 32 bytes...so we increment tail
fp@667: 		 * twice as much.
fp@667: 		 */
fp@667: 		writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
fp@667:  * @adapter:
fp@667:  **/
fp@667: 
fp@667: static void
fp@667: e1000_smartspeed(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	uint16_t phy_status;
fp@667: 	uint16_t phy_ctrl;
fp@667: 
fp@667: 	if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
fp@667: 	   !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
fp@667: 		return;
fp@667: 
fp@667: 	if (adapter->smartspeed == 0) {
fp@667: 		/* If Master/Slave config fault is asserted twice,
fp@667: 		 * we assume back-to-back */
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
fp@667: 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
fp@667: 		if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
fp@667: 		if (phy_ctrl & CR_1000T_MS_ENABLE) {
fp@667: 			phy_ctrl &= ~CR_1000T_MS_ENABLE;
fp@667: 			e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
fp@667: 					    phy_ctrl);
fp@667: 			adapter->smartspeed++;
fp@667: 			if (!e1000_phy_setup_autoneg(&adapter->hw) &&
fp@667: 			   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
fp@667: 				   	       &phy_ctrl)) {
fp@667: 				phy_ctrl |= (MII_CR_AUTO_NEG_EN |
fp@667: 					     MII_CR_RESTART_AUTO_NEG);
fp@667: 				e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
fp@667: 						    phy_ctrl);
fp@667: 			}
fp@667: 		}
fp@667: 		return;
fp@667: 	} else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
fp@667: 		/* If still no link, perhaps using 2/3 pair cable */
fp@667: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
fp@667: 		phy_ctrl |= CR_1000T_MS_ENABLE;
fp@667: 		e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
fp@667: 		if (!e1000_phy_setup_autoneg(&adapter->hw) &&
fp@667: 		   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
fp@667: 			phy_ctrl |= (MII_CR_AUTO_NEG_EN |
fp@667: 				     MII_CR_RESTART_AUTO_NEG);
fp@667: 			e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
fp@667: 		}
fp@667: 	}
fp@667: 	/* Restart process after E1000_SMARTSPEED_MAX iterations */
fp@667: 	if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
fp@667: 		adapter->smartspeed = 0;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_ioctl -
fp@667:  * @netdev:
fp@667:  * @ifreq:
fp@667:  * @cmd:
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@667: {
fp@667: 	switch (cmd) {
fp@667: 	case SIOCGMIIPHY:
fp@667: 	case SIOCGMIIREG:
fp@667: 	case SIOCSMIIREG:
fp@667: 		return e1000_mii_ioctl(netdev, ifr, cmd);
fp@667: 	default:
fp@667: 		return -EOPNOTSUPP;
fp@667: 	}
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_mii_ioctl -
fp@667:  * @netdev:
fp@667:  * @ifreq:
fp@667:  * @cmd:
fp@667:  **/
fp@667: 
fp@667: static int
fp@667: e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	struct mii_ioctl_data *data = if_mii(ifr);
fp@667: 	int retval;
fp@667: 	uint16_t mii_reg;
fp@667: 	uint16_t spddplx;
fp@667: 	unsigned long flags;
fp@667: 
fp@667: 	if (adapter->hw.media_type != e1000_media_type_copper)
fp@667: 		return -EOPNOTSUPP;
fp@667: 
fp@667: 	switch (cmd) {
fp@667: 	case SIOCGMIIPHY:
fp@667: 		data->phy_id = adapter->hw.phy_addr;
fp@667: 		break;
fp@667: 	case SIOCGMIIREG:
fp@678: 		if(adapter->ecdev || !capable(CAP_NET_ADMIN))
fp@667: 			return -EPERM;
fp@667: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@667: 		if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
fp@667: 				   &data->val_out)) {
fp@667: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@667: 			return -EIO;
fp@667: 		}
fp@667: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@667: 		break;
fp@667: 	case SIOCSMIIREG:
fp@678: 		if(adapter->ecdev || !capable(CAP_NET_ADMIN))
fp@667: 			return -EPERM;
fp@667: 		if (data->reg_num & ~(0x1F))
fp@667: 			return -EFAULT;
fp@667: 		mii_reg = data->val_in;
fp@667: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@667: 		if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
fp@667: 					mii_reg)) {
fp@667: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@667: 			return -EIO;
fp@667: 		}
fp@667: 		if (adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 			switch (data->reg_num) {
fp@667: 			case PHY_CTRL:
fp@667: 				if (mii_reg & MII_CR_POWER_DOWN)
fp@667: 					break;
fp@667: 				if (mii_reg & MII_CR_AUTO_NEG_EN) {
fp@667: 					adapter->hw.autoneg = 1;
fp@667: 					adapter->hw.autoneg_advertised = 0x2F;
fp@667: 				} else {
fp@667: 					if (mii_reg & 0x40)
fp@667: 						spddplx = SPEED_1000;
fp@667: 					else if (mii_reg & 0x2000)
fp@667: 						spddplx = SPEED_100;
fp@667: 					else
fp@667: 						spddplx = SPEED_10;
fp@667: 					spddplx += (mii_reg & 0x100)
fp@667: 						   ? DUPLEX_FULL :
fp@667: 						   DUPLEX_HALF;
fp@667: 					retval = e1000_set_spd_dplx(adapter,
fp@667: 								    spddplx);
fp@667: 					if (retval) {
fp@667: 						spin_unlock_irqrestore(
fp@667: 							&adapter->stats_lock,
fp@667: 							flags);
fp@667: 						return retval;
fp@667: 					}
fp@667: 				}
fp@671: 				if (adapter->ecdev || netif_running(adapter->netdev))
fp@667: 					e1000_reinit_locked(adapter);
fp@667: 				else
fp@667: 					e1000_reset(adapter);
fp@667: 				break;
fp@667: 			case M88E1000_PHY_SPEC_CTRL:
fp@667: 			case M88E1000_EXT_PHY_SPEC_CTRL:
fp@667: 				if (e1000_phy_reset(&adapter->hw)) {
fp@667: 					spin_unlock_irqrestore(
fp@667: 						&adapter->stats_lock, flags);
fp@667: 					return -EIO;
fp@667: 				}
fp@667: 				break;
fp@667: 			}
fp@667: 		} else {
fp@667: 			switch (data->reg_num) {
fp@667: 			case PHY_CTRL:
fp@667: 				if (mii_reg & MII_CR_POWER_DOWN)
fp@667: 					break;
fp@671: 				if (adapter->ecdev || netif_running(adapter->netdev))
fp@667: 					e1000_reinit_locked(adapter);
fp@667: 				else
fp@667: 					e1000_reset(adapter);
fp@667: 				break;
fp@667: 			}
fp@667: 		}
fp@667: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@667: 		break;
fp@667: 	default:
fp@667: 		return -EOPNOTSUPP;
fp@667: 	}
fp@667: 	return E1000_SUCCESS;
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_pci_set_mwi(struct e1000_hw *hw)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = hw->back;
fp@667: 	int ret_val = pci_set_mwi(adapter->pdev);
fp@667: 
fp@667: 	if (ret_val)
fp@667: 		DPRINTK(PROBE, ERR, "Error in setting MWI\n");
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_pci_clear_mwi(struct e1000_hw *hw)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = hw->back;
fp@667: 
fp@667: 	pci_clear_mwi(adapter->pdev);
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = hw->back;
fp@667: 
fp@667: 	pci_read_config_word(adapter->pdev, reg, value);
fp@667: }
fp@667: 
fp@667: void
fp@667: e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = hw->back;
fp@667: 
fp@667: 	pci_write_config_word(adapter->pdev, reg, *value);
fp@667: }
fp@667: 
fp@667: #if 0
fp@667: uint32_t
fp@667: e1000_io_read(struct e1000_hw *hw, unsigned long port)
fp@667: {
fp@667: 	return inl(port);
fp@667: }
fp@667: #endif  /*  0  */
fp@667: 
fp@667: void
fp@667: e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
fp@667: {
fp@667: 	outl(value, port);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t ctrl, rctl;
fp@667: 
fp@667: 	e1000_irq_disable(adapter);
fp@667: 	adapter->vlgrp = grp;
fp@667: 
fp@667: 	if (grp) {
fp@667: 		/* enable VLAN tag insert/strip */
fp@667: 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@667: 		ctrl |= E1000_CTRL_VME;
fp@667: 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@667: 
fp@667: 		if (adapter->hw.mac_type != e1000_ich8lan) {
fp@667: 		/* enable VLAN receive filtering */
fp@667: 		rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 		rctl |= E1000_RCTL_VFE;
fp@667: 		rctl &= ~E1000_RCTL_CFIEN;
fp@667: 		E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: 		e1000_update_mng_vlan(adapter);
fp@667: 		}
fp@667: 	} else {
fp@667: 		/* disable VLAN tag insert/strip */
fp@667: 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@667: 		ctrl &= ~E1000_CTRL_VME;
fp@667: 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@667: 
fp@667: 		if (adapter->hw.mac_type != e1000_ich8lan) {
fp@667: 		/* disable VLAN filtering */
fp@667: 		rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 		rctl &= ~E1000_RCTL_VFE;
fp@667: 		E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: 		if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
fp@667: 			e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
fp@667: 			adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@667: 		}
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	e1000_irq_enable(adapter);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t vfta, index;
fp@667: 
fp@667: 	if ((adapter->hw.mng_cookie.status &
fp@667: 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
fp@667: 	    (vid == adapter->mng_vlan_id))
fp@667: 		return;
fp@667: 	/* add VID to filter table */
fp@667: 	index = (vid >> 5) & 0x7F;
fp@667: 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
fp@667: 	vfta |= (1 << (vid & 0x1F));
fp@667: 	e1000_write_vfta(&adapter->hw, index, vfta);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t vfta, index;
fp@667: 
fp@667: 	e1000_irq_disable(adapter);
fp@667: 
fp@667: 	if (adapter->vlgrp)
fp@667: 		adapter->vlgrp->vlan_devices[vid] = NULL;
fp@667: 
fp@667: 	e1000_irq_enable(adapter);
fp@667: 
fp@667: 	if ((adapter->hw.mng_cookie.status &
fp@667: 	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
fp@667: 	    (vid == adapter->mng_vlan_id)) {
fp@667: 		/* release control to f/w */
fp@667: 		e1000_release_hw_control(adapter);
fp@667: 		return;
fp@667: 	}
fp@667: 
fp@667: 	/* remove VID from filter table */
fp@667: 	index = (vid >> 5) & 0x7F;
fp@667: 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
fp@667: 	vfta &= ~(1 << (vid & 0x1F));
fp@667: 	e1000_write_vfta(&adapter->hw, index, vfta);
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_restore_vlan(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
fp@667: 
fp@667: 	if (adapter->vlgrp) {
fp@667: 		uint16_t vid;
fp@667: 		for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
fp@667: 			if (!adapter->vlgrp->vlan_devices[vid])
fp@667: 				continue;
fp@667: 			e1000_vlan_rx_add_vid(adapter->netdev, vid);
fp@667: 		}
fp@667: 	}
fp@667: }
fp@667: 
fp@667: int
fp@667: e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
fp@667: {
fp@667: 	adapter->hw.autoneg = 0;
fp@667: 
fp@667: 	/* Fiber NICs only allow 1000 gbps Full duplex */
fp@667: 	if ((adapter->hw.media_type == e1000_media_type_fiber) &&
fp@667: 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
fp@667: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
fp@667: 		return -EINVAL;
fp@667: 	}
fp@667: 
fp@667: 	switch (spddplx) {
fp@667: 	case SPEED_10 + DUPLEX_HALF:
fp@667: 		adapter->hw.forced_speed_duplex = e1000_10_half;
fp@667: 		break;
fp@667: 	case SPEED_10 + DUPLEX_FULL:
fp@667: 		adapter->hw.forced_speed_duplex = e1000_10_full;
fp@667: 		break;
fp@667: 	case SPEED_100 + DUPLEX_HALF:
fp@667: 		adapter->hw.forced_speed_duplex = e1000_100_half;
fp@667: 		break;
fp@667: 	case SPEED_100 + DUPLEX_FULL:
fp@667: 		adapter->hw.forced_speed_duplex = e1000_100_full;
fp@667: 		break;
fp@667: 	case SPEED_1000 + DUPLEX_FULL:
fp@667: 		adapter->hw.autoneg = 1;
fp@667: 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
fp@667: 		break;
fp@667: 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
fp@667: 	default:
fp@667: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
fp@667: 		return -EINVAL;
fp@667: 	}
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: #ifdef CONFIG_PM
fp@667: /* Save/restore 16 or 64 dwords of PCI config space depending on which
fp@667:  * bus we're on (PCI(X) vs. PCI-E)
fp@667:  */
fp@667: #define PCIE_CONFIG_SPACE_LEN 256
fp@667: #define PCI_CONFIG_SPACE_LEN 64
fp@667: static int
fp@667: e1000_pci_save_state(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct pci_dev *dev = adapter->pdev;
fp@667: 	int size;
fp@667: 	int i;
fp@667: 
fp@667: 	if (adapter->hw.mac_type >= e1000_82571)
fp@667: 		size = PCIE_CONFIG_SPACE_LEN;
fp@667: 	else
fp@667: 		size = PCI_CONFIG_SPACE_LEN;
fp@667: 
fp@667: 	WARN_ON(adapter->config_space != NULL);
fp@667: 
fp@667: 	adapter->config_space = kmalloc(size, GFP_KERNEL);
fp@667: 	if (!adapter->config_space) {
fp@667: 		DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
fp@667: 		return -ENOMEM;
fp@667: 	}
fp@667: 	for (i = 0; i < (size / 4); i++)
fp@667: 		pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: static void
fp@667: e1000_pci_restore_state(struct e1000_adapter *adapter)
fp@667: {
fp@667: 	struct pci_dev *dev = adapter->pdev;
fp@667: 	int size;
fp@667: 	int i;
fp@667: 
fp@667: 	if (adapter->config_space == NULL)
fp@667: 		return;
fp@667: 
fp@667: 	if (adapter->hw.mac_type >= e1000_82571)
fp@667: 		size = PCIE_CONFIG_SPACE_LEN;
fp@667: 	else
fp@667: 		size = PCI_CONFIG_SPACE_LEN;
fp@667: 	for (i = 0; i < (size / 4); i++)
fp@667: 		pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
fp@667: 	kfree(adapter->config_space);
fp@667: 	adapter->config_space = NULL;
fp@667: 	return;
fp@667: }
fp@667: #endif /* CONFIG_PM */
fp@667: 
fp@667: static int
fp@667: e1000_suspend(struct pci_dev *pdev, pm_message_t state)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t ctrl, ctrl_ext, rctl, manc, status;
fp@667: 	uint32_t wufc = adapter->wol;
fp@667: #ifdef CONFIG_PM
fp@667: 	int retval = 0;
fp@667: #endif
fp@667: 
fp@671: 	if (!adapter->ecdev)
fp@671: 		netif_device_detach(netdev);
fp@671: 
fp@671: 	if (adapter->ecdev || netif_running(netdev)) {
fp@667: 		WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
fp@667: 		e1000_down(adapter);
fp@667: 	}
fp@667: 
fp@667: #ifdef CONFIG_PM
fp@667: 	/* Implement our own version of pci_save_state(pdev) because pci-
fp@667: 	 * express adapters have 256-byte config spaces. */
fp@667: 	retval = e1000_pci_save_state(adapter);
fp@667: 	if (retval)
fp@667: 		return retval;
fp@667: #endif
fp@667: 
fp@667: 	status = E1000_READ_REG(&adapter->hw, STATUS);
fp@667: 	if (status & E1000_STATUS_LU)
fp@667: 		wufc &= ~E1000_WUFC_LNKC;
fp@667: 
fp@667: 	if (wufc) {
fp@667: 		e1000_setup_rctl(adapter);
fp@667: 		e1000_set_multi(netdev);
fp@667: 
fp@667: 		/* turn on all-multi mode if wake on multicast is enabled */
fp@667: 		if (adapter->wol & E1000_WUFC_MC) {
fp@667: 			rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@667: 			rctl |= E1000_RCTL_MPE;
fp@667: 			E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@667: 		}
fp@667: 
fp@667: 		if (adapter->hw.mac_type >= e1000_82540) {
fp@667: 			ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@667: 			/* advertise wake from D3Cold */
fp@667: 			#define E1000_CTRL_ADVD3WUC 0x00100000
fp@667: 			/* phy power management enable */
fp@667: 			#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
fp@667: 			ctrl |= E1000_CTRL_ADVD3WUC |
fp@667: 				E1000_CTRL_EN_PHY_PWR_MGMT;
fp@667: 			E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@667: 		}
fp@667: 
fp@667: 		if (adapter->hw.media_type == e1000_media_type_fiber ||
fp@667: 		   adapter->hw.media_type == e1000_media_type_internal_serdes) {
fp@667: 			/* keep the laser running in D3 */
fp@667: 			ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
fp@667: 			ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
fp@667: 			E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
fp@667: 		}
fp@667: 
fp@667: 		/* Allow time for pending master requests to run */
fp@667: 		e1000_disable_pciex_master(&adapter->hw);
fp@667: 
fp@667: 		E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
fp@667: 		E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
fp@667: 		pci_enable_wake(pdev, PCI_D3hot, 1);
fp@667: 		pci_enable_wake(pdev, PCI_D3cold, 1);
fp@667: 	} else {
fp@667: 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
fp@667: 		E1000_WRITE_REG(&adapter->hw, WUFC, 0);
fp@667: 		pci_enable_wake(pdev, PCI_D3hot, 0);
fp@667: 		pci_enable_wake(pdev, PCI_D3cold, 0);
fp@667: 	}
fp@667: 
fp@667: 	/* FIXME: this code is incorrect for PCI Express */
fp@667: 	if (adapter->hw.mac_type >= e1000_82540 &&
fp@667: 	   adapter->hw.mac_type != e1000_ich8lan &&
fp@667: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@667: 		if (manc & E1000_MANC_SMBUS_EN) {
fp@667: 			manc |= E1000_MANC_ARP_EN;
fp@667: 			E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@667: 			pci_enable_wake(pdev, PCI_D3hot, 1);
fp@667: 			pci_enable_wake(pdev, PCI_D3cold, 1);
fp@667: 		}
fp@667: 	}
fp@667: 
fp@667: 	if (adapter->hw.phy_type == e1000_phy_igp_3)
fp@667: 		e1000_phy_powerdown_workaround(&adapter->hw);
fp@667: 
fp@671: 	if (!adapter->ecdev && netif_running(netdev))
fp@667: 		e1000_free_irq(adapter);
fp@667: 
fp@667: 	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
fp@667: 	 * would have already happened in close and is redundant. */
fp@667: 	e1000_release_hw_control(adapter);
fp@667: 
fp@667: 	pci_disable_device(pdev);
fp@667: 
fp@667: 	pci_set_power_state(pdev, pci_choose_state(pdev, state));
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: 
fp@667: #ifdef CONFIG_PM
fp@667: static int
fp@667: e1000_resume(struct pci_dev *pdev)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 	uint32_t manc, ret_val;
fp@667: 
fp@667: 	pci_set_power_state(pdev, PCI_D0);
fp@667: 	e1000_pci_restore_state(adapter);
fp@667: 	ret_val = pci_enable_device(pdev);
fp@667: 	pci_set_master(pdev);
fp@667: 
fp@667: 	pci_enable_wake(pdev, PCI_D3hot, 0);
fp@667: 	pci_enable_wake(pdev, PCI_D3cold, 0);
fp@667: 
fp@667: 	if (!adapter->ecdev) {
fp@667: 		if (netif_running(netdev) && (ret_val = e1000_request_irq(adapter)))
fp@667: 			return ret_val;
fp@667: 	}
fp@667: 
fp@667: 	e1000_power_up_phy(adapter);
fp@667: 	e1000_reset(adapter);
fp@667: 	E1000_WRITE_REG(&adapter->hw, WUS, ~0);
fp@667: 
fp@667: 	if (adapter->ecdev || netif_running(netdev))
fp@667: 		e1000_up(adapter);
fp@667: 
fp@671: 	if (!adapter->ecdev) netif_device_attach(netdev);
fp@667: 
fp@667: 	/* FIXME: this code is incorrect for PCI Express */
fp@667: 	if (adapter->hw.mac_type >= e1000_82540 &&
fp@667: 	   adapter->hw.mac_type != e1000_ich8lan &&
fp@667: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@667: 		manc &= ~(E1000_MANC_ARP_EN);
fp@667: 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@667: 	}
fp@667: 
fp@667: 	/* If the controller is 82573 and f/w is AMT, do not set
fp@667: 	 * DRV_LOAD until the interface is up.  For all other cases,
fp@667: 	 * let the f/w know that the h/w is now under the control
fp@667: 	 * of the driver. */
fp@667: 	if (adapter->hw.mac_type != e1000_82573 ||
fp@667: 	    !e1000_check_mng_mode(&adapter->hw))
fp@667: 		e1000_get_hw_control(adapter);
fp@667: 
fp@667: 	return 0;
fp@667: }
fp@667: #endif
fp@667: 
fp@667: static void e1000_shutdown(struct pci_dev *pdev)
fp@667: {
fp@667: 	e1000_suspend(pdev, PMSG_SUSPEND);
fp@667: }
fp@667: 
fp@667: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@667: /*
fp@667:  * Polling 'interrupt' - used by things like netconsole to send skbs
fp@667:  * without having to re-enable interrupts. It's not called while
fp@667:  * the interrupt routine is executing.
fp@667:  */
fp@667: static void
fp@667: e1000_netpoll(struct net_device *netdev)
fp@667: {
fp@667: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@667: 
fp@667: 	disable_irq(adapter->pdev->irq);
fp@667: 	e1000_intr(adapter->pdev->irq, netdev, NULL);
fp@667: 	e1000_clean_tx_irq(adapter, adapter->tx_ring);
fp@667: #ifndef CONFIG_E1000_NAPI
fp@667: 	adapter->clean_rx(adapter, adapter->rx_ring);
fp@667: #endif
fp@667: 	enable_irq(adapter->pdev->irq);
fp@667: }
fp@667: #endif
fp@667: 
fp@667: /**
fp@667:  * e1000_io_error_detected - called when PCI error is detected
fp@667:  * @pdev: Pointer to PCI device
fp@667:  * @state: The current pci conneection state
fp@667:  *
fp@667:  * This function is called after a PCI bus error affecting
fp@667:  * this device has been detected.
fp@667:  */
fp@667: static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev->priv;
fp@667: 
fp@671: 	if (!adapter->ecdev)
fp@671: 		netif_device_detach(netdev);
fp@671: 
fp@671: 	if (adapter->ecdev || netif_running(netdev))
fp@667: 		e1000_down(adapter);
fp@667: 
fp@667: 	/* Request a slot slot reset. */
fp@667: 	return PCI_ERS_RESULT_NEED_RESET;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_io_slot_reset - called after the pci bus has been reset.
fp@667:  * @pdev: Pointer to PCI device
fp@667:  *
fp@667:  * Restart the card from scratch, as if from a cold-boot. Implementation
fp@667:  * resembles the first-half of the e1000_resume routine.
fp@667:  */
fp@667: static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev->priv;
fp@667: 
fp@667: 	if (pci_enable_device(pdev)) {
fp@667: 		printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
fp@667: 		return PCI_ERS_RESULT_DISCONNECT;
fp@667: 	}
fp@667: 	pci_set_master(pdev);
fp@667: 
fp@667: 	pci_enable_wake(pdev, 3, 0);
fp@667: 	pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
fp@667: 
fp@667: 	/* Perform card reset only on one instance of the card */
fp@667: 	if (PCI_FUNC (pdev->devfn) != 0)
fp@667: 		return PCI_ERS_RESULT_RECOVERED;
fp@667: 
fp@667: 	e1000_reset(adapter);
fp@667: 	E1000_WRITE_REG(&adapter->hw, WUS, ~0);
fp@667: 
fp@667: 	return PCI_ERS_RESULT_RECOVERED;
fp@667: }
fp@667: 
fp@667: /**
fp@667:  * e1000_io_resume - called when traffic can start flowing again.
fp@667:  * @pdev: Pointer to PCI device
fp@667:  *
fp@667:  * This callback is called when the error recovery driver tells us that
fp@667:  * its OK to resume normal operation. Implementation resembles the
fp@667:  * second-half of the e1000_resume routine.
fp@667:  */
fp@667: static void e1000_io_resume(struct pci_dev *pdev)
fp@667: {
fp@667: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@667: 	struct e1000_adapter *adapter = netdev->priv;
fp@667: 	uint32_t manc, swsm;
fp@667: 
fp@671: 	if (adapter->ecdev || netif_running(netdev)) {
fp@667: 		if (e1000_up(adapter)) {
fp@667: 			printk("e1000: can't bring device back up after reset\n");
fp@667: 			return;
fp@667: 		}
fp@667: 	}
fp@667: 
fp@671: 	if (!adapter->ecdev)
fp@671: 		netif_device_attach(netdev);
fp@667: 
fp@667: 	if (adapter->hw.mac_type >= e1000_82540 &&
fp@667: 	    adapter->hw.media_type == e1000_media_type_copper) {
fp@667: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@667: 		manc &= ~(E1000_MANC_ARP_EN);
fp@667: 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@667: 	}
fp@667: 
fp@667: 	switch (adapter->hw.mac_type) {
fp@667: 	case e1000_82573:
fp@667: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@667: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@667: 				swsm | E1000_SWSM_DRV_LOAD);
fp@667: 		break;
fp@667: 	default:
fp@667: 		break;
fp@667: 	}
fp@667: 
fp@671: 	if (adapter->ecdev || netif_running(netdev))
fp@667: 		mod_timer(&adapter->watchdog_timer, jiffies);
fp@667: }
fp@667: 
fp@667: /* e1000_main.c */