fp@673: /*******************************************************************************
fp@673: 
fp@673:   
fp@673:   Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
fp@673:   
fp@673:   This program is free software; you can redistribute it and/or modify it 
fp@673:   under the terms of the GNU General Public License as published by the Free 
fp@673:   Software Foundation; either version 2 of the License, or (at your option) 
fp@673:   any later version.
fp@673:   
fp@673:   This program is distributed in the hope that it will be useful, but WITHOUT 
fp@673:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
fp@673:   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
fp@673:   more details.
fp@673:   
fp@673:   You should have received a copy of the GNU General Public License along with
fp@673:   this program; if not, write to the Free Software Foundation, Inc., 59 
fp@673:   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
fp@673:   
fp@673:   The full GNU General Public License is included in this distribution in the
fp@673:   file called LICENSE.
fp@673:   
fp@673:   Contact Information:
fp@673:   Linux NICS <linux.nics@intel.com>
fp@673:   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@673: 
fp@1325:   vim: noexpandtab
fp@1325: 
fp@673: *******************************************************************************/
fp@673: 
fp@673: #include "e1000-2.6.13-ethercat.h"
fp@673: 
fp@673: /* Change Log
fp@673:  * 6.0.58       4/20/05
fp@673:  *   o Accepted ethtool cleanup patch from Stephen Hemminger 
fp@673:  * 6.0.44+	2/15/05
fp@673:  *   o applied Anton's patch to resolve tx hang in hardware
fp@673:  *   o Applied Andrew Mortons patch - e1000 stops working after resume
fp@673:  */
fp@673: 
fp@673: char e1000_driver_name[] = "ec_e1000";
fp@673: static char e1000_driver_string[] = "EtherCAT Intel(R) PRO/1000 Network Driver";
fp@673: #ifndef CONFIG_E1000_NAPI
fp@673: #define DRIVERNAPI
fp@673: #else
fp@673: #define DRIVERNAPI "-NAPI"
fp@673: #endif
fp@673: #define DRV_VERSION		"6.0.60-k2"DRIVERNAPI
fp@673: char e1000_driver_version[] = DRV_VERSION;
fp@673: char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
fp@673: 
fp@673: /* e1000_pci_tbl - PCI Device ID Table
fp@673:  *
fp@673:  * Last entry must be all 0s
fp@673:  *
fp@673:  * Macro expands to...
fp@673:  *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
fp@673:  */
fp@673: static struct pci_device_id e1000_pci_tbl[] = {
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1000),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1001),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1004),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1008),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1009),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x100C),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x100D),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x100E),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x100F),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1010),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1011),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1012),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1013),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1014),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1015),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1016),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1017),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1018),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1019),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x101A),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x101D),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x101E),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1026),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1027),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1028),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1075),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1076),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1077),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1078),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1079),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x107A),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x107B),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x107C),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x108A),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x108B),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x108C),
fp@673: 	INTEL_E1000_ETHERNET_DEVICE(0x1099),
fp@673: 	/* required last entry */
fp@673: 	{0,}
fp@673: };
fp@673: 
fp@673: // do not auto-load driver
fp@673: // MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
fp@673: 
fp@673: int e1000_up(struct e1000_adapter *adapter);
fp@673: void e1000_down(struct e1000_adapter *adapter);
fp@673: void e1000_reset(struct e1000_adapter *adapter);
fp@673: int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
fp@673: int e1000_setup_tx_resources(struct e1000_adapter *adapter);
fp@673: int e1000_setup_rx_resources(struct e1000_adapter *adapter);
fp@673: void e1000_free_tx_resources(struct e1000_adapter *adapter);
fp@673: void e1000_free_rx_resources(struct e1000_adapter *adapter);
fp@673: void e1000_update_stats(struct e1000_adapter *adapter);
fp@673: 
fp@673: /* Local Function Prototypes */
fp@673: 
fp@673: static int e1000_init_module(void);
fp@673: static void e1000_exit_module(void);
fp@673: static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
fp@673: static void __devexit e1000_remove(struct pci_dev *pdev);
fp@673: static int e1000_sw_init(struct e1000_adapter *adapter);
fp@673: static int e1000_open(struct net_device *netdev);
fp@673: static int e1000_close(struct net_device *netdev);
fp@673: static void e1000_configure_tx(struct e1000_adapter *adapter);
fp@673: static void e1000_configure_rx(struct e1000_adapter *adapter);
fp@673: static void e1000_setup_rctl(struct e1000_adapter *adapter);
fp@673: static void e1000_clean_tx_ring(struct e1000_adapter *adapter);
fp@673: static void e1000_clean_rx_ring(struct e1000_adapter *adapter);
fp@673: static void e1000_set_multi(struct net_device *netdev);
fp@673: static void e1000_update_phy_info(unsigned long data);
fp@673: static void e1000_watchdog(unsigned long data);
fp@673: static void e1000_watchdog_task(struct e1000_adapter *adapter);
fp@673: static void e1000_82547_tx_fifo_stall(unsigned long data);
fp@673: static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
fp@673: static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
fp@673: static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
fp@673: static int e1000_set_mac(struct net_device *netdev, void *p);
fp@673: void ec_poll(struct net_device *);
fp@673: static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
fp@673: static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter);
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: static int e1000_clean(struct net_device *netdev, int *budget);
fp@673: static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
fp@673:                                     int *work_done, int work_to_do);
fp@673: static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
fp@673:                                        int *work_done, int work_to_do);
fp@673: #else
fp@673: static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter);
fp@673: static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter);
fp@673: #endif
fp@673: static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);
fp@673: static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter);
fp@673: static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
fp@673: static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
fp@673: 			   int cmd);
fp@673: void e1000_set_ethtool_ops(struct net_device *netdev);
fp@673: static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
fp@673: static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
fp@673: static void e1000_tx_timeout(struct net_device *dev);
fp@673: static void e1000_tx_timeout_task(struct net_device *dev);
fp@673: static void e1000_smartspeed(struct e1000_adapter *adapter);
fp@673: static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
fp@673: 					      struct sk_buff *skb);
fp@673: 
fp@673: static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
fp@673: static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
fp@673: static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
fp@673: static void e1000_restore_vlan(struct e1000_adapter *adapter);
fp@673: 
fp@724: #ifdef CONFIG_PM
fp@673: static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
fp@673: static int e1000_resume(struct pci_dev *pdev);
fp@673: #endif
fp@673: 
fp@673: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@673: /* for netdump / net console */
fp@673: static void e1000_netpoll (struct net_device *netdev);
fp@673: #endif
fp@673: 
fp@673: /* Exported from other modules */
fp@673: 
fp@673: extern void e1000_check_options(struct e1000_adapter *adapter);
fp@673: 
fp@673: static struct pci_driver e1000_driver = {
fp@673: 	.name     = e1000_driver_name,
fp@673: 	.id_table = e1000_pci_tbl,
fp@673: 	.probe    = e1000_probe,
fp@673: 	.remove   = __devexit_p(e1000_remove),
fp@673: 	/* Power Managment Hooks */
fp@673: #ifdef CONFIG_PM
fp@673: 	.suspend  = e1000_suspend,
fp@673: 	.resume   = e1000_resume
fp@673: #endif
fp@673: };
fp@673: 
fp@673: MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
fp@673: MODULE_DESCRIPTION("EtherCAT-capable Intel(R) PRO/1000 Network Driver");
fp@673: MODULE_LICENSE("GPL");
fp@673: MODULE_VERSION(DRV_VERSION);
fp@673: 
fp@673: static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
fp@673: module_param(debug, int, 0);
fp@673: MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
fp@673: 
fp@673: /**
fp@673:  * e1000_init_module - Driver Registration Routine
fp@673:  *
fp@673:  * e1000_init_module is the first routine called when the driver is
fp@673:  * loaded. All it does is register with the PCI subsystem.
fp@673:  **/
fp@673: 
fp@673: static int __init
fp@673: e1000_init_module(void)
fp@673: {
fp@673: 	int ret;
fp@673: 	printk(KERN_INFO "%s - version %s\n",
fp@673: 	       e1000_driver_string, e1000_driver_version);
fp@673: 
fp@673: 	printk(KERN_INFO "%s\n", e1000_copyright);
fp@673: 
fp@673: 	ret = pci_module_init(&e1000_driver);
fp@673: 
fp@673: 	return ret;
fp@673: }
fp@673: 
fp@673: module_init(e1000_init_module);
fp@673: 
fp@673: /**
fp@673:  * e1000_exit_module - Driver Exit Cleanup Routine
fp@673:  *
fp@673:  * e1000_exit_module is called just before the driver is removed
fp@673:  * from memory.
fp@673:  **/
fp@673: 
fp@673: static void __exit
fp@673: e1000_exit_module(void)
fp@673: {
fp@673: 	pci_unregister_driver(&e1000_driver);
fp@673: }
fp@673: 
fp@673: module_exit(e1000_exit_module);
fp@673: 
fp@673: /**
fp@673:  * e1000_irq_disable - Mask off interrupt generation on the NIC
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static inline void
fp@673: e1000_irq_disable(struct e1000_adapter *adapter)
fp@673: {
fp@676:     if (adapter->ecdev)
fp@676:         return;
fp@673: 	atomic_inc(&adapter->irq_sem);
fp@673: 	E1000_WRITE_REG(&adapter->hw, IMC, ~0);
fp@673: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@673: 	synchronize_irq(adapter->pdev->irq);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_irq_enable - Enable default interrupt generation settings
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static inline void
fp@673: e1000_irq_enable(struct e1000_adapter *adapter)
fp@673: {
fp@676:     if (adapter->ecdev)
fp@676:         return;
fp@676: 	if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
fp@673: 		E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
fp@673: 		E1000_WRITE_FLUSH(&adapter->hw);
fp@673: 	}
fp@673: }
fp@673: void
fp@673: e1000_update_mng_vlan(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	uint16_t vid = adapter->hw.mng_cookie.vlan_id;
fp@673: 	uint16_t old_vid = adapter->mng_vlan_id;
fp@673: 	if(adapter->vlgrp) {
fp@673: 		if(!adapter->vlgrp->vlan_devices[vid]) {
fp@673: 			if(adapter->hw.mng_cookie.status &
fp@673: 				E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
fp@673: 				e1000_vlan_rx_add_vid(netdev, vid);
fp@673: 				adapter->mng_vlan_id = vid;
fp@673: 			} else
fp@673: 				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@673: 				
fp@673: 			if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
fp@673: 					(vid != old_vid) && 
fp@673: 					!adapter->vlgrp->vlan_devices[old_vid])
fp@673: 				e1000_vlan_rx_kill_vid(netdev, old_vid);
fp@673: 		}
fp@673: 	}
fp@673: }
fp@673: 	
fp@673: int
fp@673: e1000_up(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	int err;
fp@673: 
fp@673: 	/* hardware has been reset, we need to reload some things */
fp@673: 
fp@673: 	/* Reset the PHY if it was previously powered down */
fp@673: 	if(adapter->hw.media_type == e1000_media_type_copper) {
fp@673: 		uint16_t mii_reg;
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
fp@673: 		if(mii_reg & MII_CR_POWER_DOWN)
fp@673: 			e1000_phy_reset(&adapter->hw);
fp@673: 	}
fp@673: 
fp@673: 	e1000_set_multi(netdev);
fp@673: 
fp@673: 	e1000_restore_vlan(adapter);
fp@673: 
fp@673: 	e1000_configure_tx(adapter);
fp@673: 	e1000_setup_rctl(adapter);
fp@673: 	e1000_configure_rx(adapter);
fp@673: 	adapter->alloc_rx_buf(adapter);
fp@673: 
fp@673: #ifdef CONFIG_PCI_MSI
fp@673: 	if(adapter->hw.mac_type > e1000_82547_rev_2) {
fp@673: 		adapter->have_msi = TRUE;
fp@673: 		if((err = pci_enable_msi(adapter->pdev))) {
fp@673: 			DPRINTK(PROBE, ERR,
fp@673: 			 "Unable to allocate MSI interrupt Error: %d\n", err);
fp@673: 			adapter->have_msi = FALSE;
fp@673: 		}
fp@673: 	}
fp@673: #endif
fp@676:     if (!adapter->ecdev) {
fp@676:         if((err = request_irq(adapter->pdev->irq, &e1000_intr,
fp@676:                         SA_SHIRQ | SA_SAMPLE_RANDOM,
fp@676:                         netdev->name, netdev))) {
fp@676:             DPRINTK(PROBE, ERR,
fp@676:                     "Unable to allocate interrupt Error: %d\n", err);
fp@676:             return err;
fp@676:         }
fp@676: 
fp@676:         mod_timer(&adapter->watchdog_timer, jiffies);
fp@673: 
fp@673: #ifdef CONFIG_E1000_NAPI
fp@676:         netif_poll_enable(netdev);
fp@673: #endif
fp@676:         e1000_irq_enable(adapter);
fp@676:     }
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_down(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 
fp@676:     if (!adapter->ecdev) {
fp@676:         e1000_irq_disable(adapter);
fp@676:         free_irq(adapter->pdev->irq, netdev);
fp@676:     }
fp@673: #ifdef CONFIG_PCI_MSI
fp@673: 	if(adapter->hw.mac_type > e1000_82547_rev_2 &&
fp@673: 	   adapter->have_msi == TRUE)
fp@673: 		pci_disable_msi(adapter->pdev);
fp@673: #endif
fp@676:     if (!adapter->ecdev) {
fp@676:         del_timer_sync(&adapter->tx_fifo_stall_timer);
fp@676:         del_timer_sync(&adapter->watchdog_timer);
fp@676:         del_timer_sync(&adapter->phy_info_timer);
fp@673: 
fp@673: #ifdef CONFIG_E1000_NAPI
fp@676:         netif_poll_disable(netdev);
fp@673: #endif
fp@676:     }
fp@673: 	adapter->link_speed = 0;
fp@673: 	adapter->link_duplex = 0;
fp@673: 	if (!adapter->ecdev) {
fp@673: 		netif_carrier_off(netdev);
fp@673: 		netif_stop_queue(netdev);
fp@673: 	}
fp@673: 
fp@673: 	e1000_reset(adapter);
fp@673: 	e1000_clean_tx_ring(adapter);
fp@673: 	e1000_clean_rx_ring(adapter);
fp@673: 
fp@673: 	/* If WoL is not enabled
fp@673: 	 * and management mode is not IAMT
fp@673: 	 * Power down the PHY so no link is implied when interface is down */
fp@673: 	if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
fp@673: 	   adapter->hw.media_type == e1000_media_type_copper &&
fp@673: 	   !e1000_check_mng_mode(&adapter->hw) &&
fp@673: 	   !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
fp@673: 		uint16_t mii_reg;
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
fp@673: 		mii_reg |= MII_CR_POWER_DOWN;
fp@673: 		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
fp@673: 		mdelay(1);
fp@673: 	}
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_reset(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	uint32_t pba, manc;
fp@673: 	uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
fp@673: 	uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
fp@673: 
fp@673: 	/* Repartition Pba for greater than 9k mtu
fp@673: 	 * To take effect CTRL.RST is required.
fp@673: 	 */
fp@673: 
fp@673: 	switch (adapter->hw.mac_type) {
fp@673: 	case e1000_82547:
fp@673: 	case e1000_82547_rev_2:
fp@673: 		pba = E1000_PBA_30K;
fp@673: 		break;
fp@673: 	case e1000_82573:
fp@673: 		pba = E1000_PBA_12K;
fp@673: 		break;
fp@673: 	default:
fp@673: 		pba = E1000_PBA_48K;
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	if((adapter->hw.mac_type != e1000_82573) &&
fp@673: 	   (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {
fp@673: 		pba -= 8; /* allocate more FIFO for Tx */
fp@673: 		/* send an XOFF when there is enough space in the
fp@673: 		 * Rx FIFO to hold one extra full size Rx packet 
fp@673: 		*/
fp@673: 		fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE + 
fp@673: 					ETHERNET_FCS_SIZE + 1;
fp@673: 		fc_low_water_mark = fc_high_water_mark + 8;
fp@673: 	}
fp@673: 
fp@673: 
fp@673: 	if(adapter->hw.mac_type == e1000_82547) {
fp@673: 		adapter->tx_fifo_head = 0;
fp@673: 		adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
fp@673: 		adapter->tx_fifo_size =
fp@673: 			(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
fp@673: 		atomic_set(&adapter->tx_fifo_stall, 0);
fp@673: 	}
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, PBA, pba);
fp@673: 
fp@673: 	/* flow control settings */
fp@673: 	adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
fp@673: 				    fc_high_water_mark;
fp@673: 	adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
fp@673: 				   fc_low_water_mark;
fp@673: 	adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
fp@673: 	adapter->hw.fc_send_xon = 1;
fp@673: 	adapter->hw.fc = adapter->hw.original_fc;
fp@673: 
fp@673: 	/* Allow time for pending master requests to run */
fp@673: 	e1000_reset_hw(&adapter->hw);
fp@673: 	if(adapter->hw.mac_type >= e1000_82544)
fp@673: 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
fp@673: 	if(e1000_init_hw(&adapter->hw))
fp@673: 		DPRINTK(PROBE, ERR, "Hardware Error\n");
fp@673: 	e1000_update_mng_vlan(adapter);
fp@673: 	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
fp@673: 	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
fp@673: 
fp@673: 	e1000_reset_adaptive(&adapter->hw);
fp@673: 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
fp@673: 	if (adapter->en_mng_pt) {
fp@673: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@673: 		manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
fp@673: 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_probe - Device Initialization Routine
fp@673:  * @pdev: PCI device information struct
fp@673:  * @ent: entry in e1000_pci_tbl
fp@673:  *
fp@673:  * Returns 0 on success, negative on failure
fp@673:  *
fp@673:  * e1000_probe initializes an adapter identified by a pci_dev structure.
fp@673:  * The OS initialization, configuring of the adapter private structure,
fp@673:  * and a hardware reset occur.
fp@673:  **/
fp@673: 
fp@673: static int __devinit
fp@673: e1000_probe(struct pci_dev *pdev,
fp@673:             const struct pci_device_id *ent)
fp@673: {
fp@673: 	struct net_device *netdev;
fp@673: 	struct e1000_adapter *adapter;
fp@673: 	unsigned long mmio_start, mmio_len;
fp@673: 	uint32_t swsm;
fp@673: 
fp@673: 	static int cards_found = 0;
fp@673: 	int i, err, pci_using_dac;
fp@673: 	uint16_t eeprom_data;
fp@673: 	uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
fp@673: 	if((err = pci_enable_device(pdev)))
fp@673: 		return err;
fp@673: 
fp@673: 	if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
fp@673: 		pci_using_dac = 1;
fp@673: 	} else {
fp@673: 		if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
fp@673: 			E1000_ERR("No usable DMA configuration, aborting\n");
fp@673: 			return err;
fp@673: 		}
fp@673: 		pci_using_dac = 0;
fp@673: 	}
fp@673: 
fp@673: 	if((err = pci_request_regions(pdev, e1000_driver_name)))
fp@673: 		return err;
fp@673: 
fp@673: 	pci_set_master(pdev);
fp@673: 
fp@673: 	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
fp@673: 	if(!netdev) {
fp@673: 		err = -ENOMEM;
fp@673: 		goto err_alloc_etherdev;
fp@673: 	}
fp@673: 
fp@673: 	SET_MODULE_OWNER(netdev);
fp@673: 	SET_NETDEV_DEV(netdev, &pdev->dev);
fp@673: 
fp@673: 	pci_set_drvdata(pdev, netdev);
fp@673: 	adapter = netdev_priv(netdev);
fp@673: 	adapter->netdev = netdev;
fp@673: 	adapter->pdev = pdev;
fp@673: 	adapter->hw.back = adapter;
fp@673: 	adapter->msg_enable = (1 << debug) - 1;
fp@673: 
fp@673: 	mmio_start = pci_resource_start(pdev, BAR_0);
fp@673: 	mmio_len = pci_resource_len(pdev, BAR_0);
fp@673: 
fp@673: 	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
fp@673: 	if(!adapter->hw.hw_addr) {
fp@673: 		err = -EIO;
fp@673: 		goto err_ioremap;
fp@673: 	}
fp@673: 
fp@673: 	for(i = BAR_1; i <= BAR_5; i++) {
fp@673: 		if(pci_resource_len(pdev, i) == 0)
fp@673: 			continue;
fp@673: 		if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
fp@673: 			adapter->hw.io_base = pci_resource_start(pdev, i);
fp@673: 			break;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	netdev->open = &e1000_open;
fp@673: 	netdev->stop = &e1000_close;
fp@673: 	netdev->hard_start_xmit = &e1000_xmit_frame;
fp@673: 	netdev->get_stats = &e1000_get_stats;
fp@673: 	netdev->set_multicast_list = &e1000_set_multi;
fp@673: 	netdev->set_mac_address = &e1000_set_mac;
fp@673: 	netdev->change_mtu = &e1000_change_mtu;
fp@673: 	netdev->do_ioctl = &e1000_ioctl;
fp@673: 	e1000_set_ethtool_ops(netdev);
fp@673: 	netdev->tx_timeout = &e1000_tx_timeout;
fp@673: 	netdev->watchdog_timeo = 5 * HZ;
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: 	netdev->poll = &e1000_clean;
fp@673: 	netdev->weight = 64;
fp@673: #endif
fp@673: 	netdev->vlan_rx_register = e1000_vlan_rx_register;
fp@673: 	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
fp@673: 	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
fp@673: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@673: 	netdev->poll_controller = e1000_netpoll;
fp@673: #endif
fp@673: 	strcpy(netdev->name, pci_name(pdev));
fp@673: 
fp@673: 	netdev->mem_start = mmio_start;
fp@673: 	netdev->mem_end = mmio_start + mmio_len;
fp@673: 	netdev->base_addr = adapter->hw.io_base;
fp@673: 
fp@673: 	adapter->bd_number = cards_found;
fp@673: 
fp@673: 	/* setup the private structure */
fp@673: 
fp@673: 	if((err = e1000_sw_init(adapter)))
fp@673: 		goto err_sw_init;
fp@673: 
fp@673: 	if((err = e1000_check_phy_reset_block(&adapter->hw)))
fp@673: 		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
fp@673: 
fp@673: 	if(adapter->hw.mac_type >= e1000_82543) {
fp@673: 		netdev->features = NETIF_F_SG |
fp@673: 				   NETIF_F_HW_CSUM |
fp@673: 				   NETIF_F_HW_VLAN_TX |
fp@673: 				   NETIF_F_HW_VLAN_RX |
fp@673: 				   NETIF_F_HW_VLAN_FILTER;
fp@673: 	}
fp@673: 
fp@673: #ifdef NETIF_F_TSO
fp@673: 	if((adapter->hw.mac_type >= e1000_82544) &&
fp@673: 	   (adapter->hw.mac_type != e1000_82547))
fp@673: 		netdev->features |= NETIF_F_TSO;
fp@673: 
fp@673: #ifdef NETIF_F_TSO_IPV6
fp@673: 	if(adapter->hw.mac_type > e1000_82547_rev_2)
fp@673: 		netdev->features |= NETIF_F_TSO_IPV6;
fp@673: #endif
fp@673: #endif
fp@673: 	if(pci_using_dac)
fp@673: 		netdev->features |= NETIF_F_HIGHDMA;
fp@673: 
fp@673:  	/* hard_start_xmit is safe against parallel locking */
fp@673:  	netdev->features |= NETIF_F_LLTX; 
fp@673:  
fp@673: 	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
fp@673: 
fp@673: 	/* before reading the EEPROM, reset the controller to 
fp@673: 	 * put the device in a known good starting state */
fp@673: 	
fp@673: 	e1000_reset_hw(&adapter->hw);
fp@673: 
fp@673: 	/* make sure the EEPROM is good */
fp@673: 
fp@673: 	if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
fp@673: 		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
fp@673: 		err = -EIO;
fp@673: 		goto err_eeprom;
fp@673: 	}
fp@673: 
fp@673: 	/* copy the MAC address out of the EEPROM */
fp@673: 
fp@673: 	if(e1000_read_mac_addr(&adapter->hw))
fp@673: 		DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
fp@673: 	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
fp@673: 
fp@673: 	if(!is_valid_ether_addr(netdev->dev_addr)) {
fp@673: 		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
fp@673: 		err = -EIO;
fp@673: 		goto err_eeprom;
fp@673: 	}
fp@673: 
fp@673: 	e1000_read_part_num(&adapter->hw, &(adapter->part_num));
fp@673: 
fp@673: 	e1000_get_bus_info(&adapter->hw);
fp@673: 
fp@673: 	init_timer(&adapter->tx_fifo_stall_timer);
fp@673: 	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
fp@673: 	adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
fp@673: 
fp@673: 	init_timer(&adapter->watchdog_timer);
fp@673: 	adapter->watchdog_timer.function = &e1000_watchdog;
fp@673: 	adapter->watchdog_timer.data = (unsigned long) adapter;
fp@673: 
fp@673: 	INIT_WORK(&adapter->watchdog_task,
fp@673: 		(void (*)(void *))e1000_watchdog_task, adapter);
fp@673: 
fp@673: 	init_timer(&adapter->phy_info_timer);
fp@673: 	adapter->phy_info_timer.function = &e1000_update_phy_info;
fp@673: 	adapter->phy_info_timer.data = (unsigned long) adapter;
fp@673: 
fp@673: 	INIT_WORK(&adapter->tx_timeout_task,
fp@673: 		(void (*)(void *))e1000_tx_timeout_task, netdev);
fp@673: 
fp@673: 	/* we're going to reset, so assume we have no link for now */
fp@673: 
fp@673: 	if (!adapter->ecdev) {
fp@673: 		netif_carrier_off(netdev);
fp@673: 		netif_stop_queue(netdev);
fp@673: 	}
fp@673: 
fp@673: 	e1000_check_options(adapter);
fp@673: 
fp@673: 	/* Initial Wake on LAN setting
fp@673: 	 * If APM wake is enabled in the EEPROM,
fp@673: 	 * enable the ACPI Magic Packet filter
fp@673: 	 */
fp@673: 
fp@673: 	switch(adapter->hw.mac_type) {
fp@673: 	case e1000_82542_rev2_0:
fp@673: 	case e1000_82542_rev2_1:
fp@673: 	case e1000_82543:
fp@673: 		break;
fp@673: 	case e1000_82544:
fp@673: 		e1000_read_eeprom(&adapter->hw,
fp@673: 			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
fp@673: 		eeprom_apme_mask = E1000_EEPROM_82544_APM;
fp@673: 		break;
fp@673: 	case e1000_82546:
fp@673: 	case e1000_82546_rev_3:
fp@673: 		if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
fp@673: 		   && (adapter->hw.media_type == e1000_media_type_copper)) {
fp@673: 			e1000_read_eeprom(&adapter->hw,
fp@673: 				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
fp@673: 			break;
fp@673: 		}
fp@673: 		/* Fall Through */
fp@673: 	default:
fp@673: 		e1000_read_eeprom(&adapter->hw,
fp@673: 			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
fp@673: 		break;
fp@673: 	}
fp@673: 	if(eeprom_data & eeprom_apme_mask)
fp@673: 		adapter->wol |= E1000_WUFC_MAG;
fp@673: 
fp@673: 	/* reset the hardware with the new settings */
fp@673: 	e1000_reset(adapter);
fp@673: 
fp@673: 	/* Let firmware know the driver has taken over */
fp@673: 	switch(adapter->hw.mac_type) {
fp@673: 	case e1000_82573:
fp@673: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@673: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@673: 				swsm | E1000_SWSM_DRV_LOAD);
fp@673: 		break;
fp@673: 	default:
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	// offer device to EtherCAT master module
fp@1011: 	adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE);
fp@673: 	if (adapter->ecdev) {
fp@673: 		if (ecdev_open(adapter->ecdev)) {
fp@673: 			ecdev_withdraw(adapter->ecdev);
fp@673: 			goto err_register;
fp@673: 		}
fp@673: 	} else {
fp@673: 		strcpy(netdev->name, "eth%d");
fp@673: 		if ((err = register_netdev(netdev)))
fp@673: 			goto err_register;
fp@673: 	}
fp@673: 
fp@673: 	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
fp@673: 
fp@673: 	cards_found++;
fp@673: 	return 0;
fp@673: 
fp@673: err_register:
fp@673: err_sw_init:
fp@673: err_eeprom:
fp@673: 	iounmap(adapter->hw.hw_addr);
fp@673: err_ioremap:
fp@673: 	free_netdev(netdev);
fp@673: err_alloc_etherdev:
fp@673: 	pci_release_regions(pdev);
fp@673: 	return err;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_remove - Device Removal Routine
fp@673:  * @pdev: PCI device information struct
fp@673:  *
fp@673:  * e1000_remove is called by the PCI subsystem to alert the driver
fp@673:  * that it should release a PCI device.  The could be caused by a
fp@673:  * Hot-Plug event, or because the driver is going to be removed from
fp@673:  * memory.
fp@673:  **/
fp@673: 
fp@673: static void __devexit
fp@673: e1000_remove(struct pci_dev *pdev)
fp@673: {
fp@673: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t manc, swsm;
fp@673: 
fp@673: 	flush_scheduled_work();
fp@673: 
fp@673: 	if(adapter->hw.mac_type >= e1000_82540 &&
fp@673: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@673: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@673: 		if(manc & E1000_MANC_SMBUS_EN) {
fp@673: 			manc |= E1000_MANC_ARP_EN;
fp@673: 			E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	switch(adapter->hw.mac_type) {
fp@673: 	case e1000_82573:
fp@673: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@673: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@673: 				swsm & ~E1000_SWSM_DRV_LOAD);
fp@673: 		break;
fp@673: 
fp@673: 	default:
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	if (adapter->ecdev) {
fp@673: 		ecdev_close(adapter->ecdev);
fp@673: 		ecdev_withdraw(adapter->ecdev);
fp@673: 	} else {
fp@673: 		unregister_netdev(netdev);
fp@673: 	}
fp@673: 
fp@673: 	if(!e1000_check_phy_reset_block(&adapter->hw))
fp@673: 		e1000_phy_hw_reset(&adapter->hw);
fp@673: 
fp@673: 	iounmap(adapter->hw.hw_addr);
fp@673: 	pci_release_regions(pdev);
fp@673: 
fp@673: 	free_netdev(netdev);
fp@673: 
fp@673: 	pci_disable_device(pdev);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
fp@673:  * @adapter: board private structure to initialize
fp@673:  *
fp@673:  * e1000_sw_init initializes the Adapter private data structure.
fp@673:  * Fields are initialized based on PCI device information and
fp@673:  * OS network device settings (MTU size).
fp@673:  **/
fp@673: 
fp@673: static int __devinit
fp@673: e1000_sw_init(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_hw *hw = &adapter->hw;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 
fp@673: 	/* PCI config space info */
fp@673: 
fp@673: 	hw->vendor_id = pdev->vendor;
fp@673: 	hw->device_id = pdev->device;
fp@673: 	hw->subsystem_vendor_id = pdev->subsystem_vendor;
fp@673: 	hw->subsystem_id = pdev->subsystem_device;
fp@673: 
fp@673: 	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
fp@673: 
fp@673: 	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
fp@673: 
fp@673: 	adapter->rx_buffer_len = E1000_RXBUFFER_2048;
fp@673: 	adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
fp@673: 	hw->max_frame_size = netdev->mtu +
fp@673: 			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
fp@673: 	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
fp@673: 
fp@673: 	/* identify the MAC */
fp@673: 
fp@673: 	if(e1000_set_mac_type(hw)) {
fp@673: 		DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
fp@673: 		return -EIO;
fp@673: 	}
fp@673: 
fp@673: 	/* initialize eeprom parameters */
fp@673: 
fp@673: 	if(e1000_init_eeprom_params(hw)) {
fp@673: 		E1000_ERR("EEPROM initialization failed\n");
fp@673: 		return -EIO;
fp@673: 	}
fp@673: 
fp@673: 	switch(hw->mac_type) {
fp@673: 	default:
fp@673: 		break;
fp@673: 	case e1000_82541:
fp@673: 	case e1000_82547:
fp@673: 	case e1000_82541_rev_2:
fp@673: 	case e1000_82547_rev_2:
fp@673: 		hw->phy_init_script = 1;
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	e1000_set_media_type(hw);
fp@673: 
fp@673: 	hw->wait_autoneg_complete = FALSE;
fp@673: 	hw->tbi_compatibility_en = TRUE;
fp@673: 	hw->adaptive_ifs = TRUE;
fp@673: 
fp@673: 	/* Copper options */
fp@673: 
fp@673: 	if(hw->media_type == e1000_media_type_copper) {
fp@673: 		hw->mdix = AUTO_ALL_MODES;
fp@673: 		hw->disable_polarity_correction = FALSE;
fp@673: 		hw->master_slave = E1000_MASTER_SLAVE;
fp@673: 	}
fp@673: 
fp@673: 	atomic_set(&adapter->irq_sem, 1);
fp@673: 	spin_lock_init(&adapter->stats_lock);
fp@673: 	spin_lock_init(&adapter->tx_lock);
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_open - Called when a network interface is made active
fp@673:  * @netdev: network interface device structure
fp@673:  *
fp@673:  * Returns 0 on success, negative value on failure
fp@673:  *
fp@673:  * The open entry point is called when a network interface is made
fp@673:  * active by the system (IFF_UP).  At this point all resources needed
fp@673:  * for transmit and receive operations are allocated, the interrupt
fp@673:  * handler is registered with the OS, the watchdog timer is started,
fp@673:  * and the stack is notified that the interface is ready.
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_open(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	int err;
fp@673: 
fp@673: 	/* allocate transmit descriptors */
fp@673: 
fp@673: 	if((err = e1000_setup_tx_resources(adapter)))
fp@673: 		goto err_setup_tx;
fp@673: 
fp@673: 	/* allocate receive descriptors */
fp@673: 
fp@673: 	if((err = e1000_setup_rx_resources(adapter)))
fp@673: 		goto err_setup_rx;
fp@673: 
fp@673: 	if((err = e1000_up(adapter)))
fp@673: 		goto err_up;
fp@673: 	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@673: 	if((adapter->hw.mng_cookie.status &
fp@673: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
fp@673: 		e1000_update_mng_vlan(adapter);
fp@673: 	}
fp@673: 
fp@673: 	return E1000_SUCCESS;
fp@673: 
fp@673: err_up:
fp@673: 	e1000_free_rx_resources(adapter);
fp@673: err_setup_rx:
fp@673: 	e1000_free_tx_resources(adapter);
fp@673: err_setup_tx:
fp@673: 	e1000_reset(adapter);
fp@673: 
fp@673: 	return err;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_close - Disables a network interface
fp@673:  * @netdev: network interface device structure
fp@673:  *
fp@673:  * Returns 0, this is not allowed to fail
fp@673:  *
fp@673:  * The close entry point is called when an interface is de-activated
fp@673:  * by the OS.  The hardware is still under the drivers control, but
fp@673:  * needs to be disabled.  A global MAC reset is issued to stop the
fp@673:  * hardware, and all transmit and receive resources are freed.
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_close(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 
fp@673: 	e1000_down(adapter);
fp@673: 
fp@673: 	e1000_free_tx_resources(adapter);
fp@673: 	e1000_free_rx_resources(adapter);
fp@673: 
fp@673: 	if((adapter->hw.mng_cookie.status &
fp@673: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
fp@673: 		e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
fp@673: 	}
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
fp@673:  * @adapter: address of board private structure
fp@673:  * @start: address of beginning of memory
fp@673:  * @len: length of memory
fp@673:  **/
fp@673: static inline boolean_t
fp@673: e1000_check_64k_bound(struct e1000_adapter *adapter,
fp@673: 		      void *start, unsigned long len)
fp@673: {
fp@673: 	unsigned long begin = (unsigned long) start;
fp@673: 	unsigned long end = begin + len;
fp@673: 
fp@673: 	/* First rev 82545 and 82546 need to not allow any memory
fp@673: 	 * write location to cross 64k boundary due to errata 23 */
fp@673: 	if (adapter->hw.mac_type == e1000_82545 ||
fp@673: 	    adapter->hw.mac_type == e1000_82546) {
fp@673: 		return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
fp@673: 	}
fp@673: 
fp@673: 	return TRUE;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Return 0 on success, negative on failure
fp@673:  **/
fp@673: 
fp@673: int
fp@673: e1000_setup_tx_resources(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *txdr = &adapter->tx_ring;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	int size;
fp@673: 
fp@673: 	size = sizeof(struct e1000_buffer) * txdr->count;
fp@673: 	txdr->buffer_info = vmalloc(size);
fp@673: 	if(!txdr->buffer_info) {
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the transmit descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 	memset(txdr->buffer_info, 0, size);
fp@673: 
fp@673: 	/* round up to nearest 4K */
fp@673: 
fp@673: 	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
fp@673: 	E1000_ROUNDUP(txdr->size, 4096);
fp@673: 
fp@673: 	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
fp@673: 	if(!txdr->desc) {
fp@673: setup_tx_desc_die:
fp@673: 		vfree(txdr->buffer_info);
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the transmit descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 
fp@673: 	/* Fix for errata 23, can't cross 64kB boundary */
fp@673: 	if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
fp@673: 		void *olddesc = txdr->desc;
fp@673: 		dma_addr_t olddma = txdr->dma;
fp@673: 		DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
fp@673: 				     "at %p\n", txdr->size, txdr->desc);
fp@673: 		/* Try again, without freeing the previous */
fp@673: 		txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
fp@673: 		if(!txdr->desc) {
fp@673: 		/* Failed allocation, critical failure */
fp@673: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@673: 			goto setup_tx_desc_die;
fp@673: 		}
fp@673: 
fp@673: 		if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
fp@673: 			/* give up */
fp@673: 			pci_free_consistent(pdev, txdr->size, txdr->desc,
fp@673: 					    txdr->dma);
fp@673: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@673: 			DPRINTK(PROBE, ERR,
fp@673: 				"Unable to allocate aligned memory "
fp@673: 				"for the transmit descriptor ring\n");
fp@673: 			vfree(txdr->buffer_info);
fp@673: 			return -ENOMEM;
fp@673: 		} else {
fp@673: 			/* Free old allocation, new allocation was successful */
fp@673: 			pci_free_consistent(pdev, txdr->size, olddesc, olddma);
fp@673: 		}
fp@673: 	}
fp@673: 	memset(txdr->desc, 0, txdr->size);
fp@673: 
fp@673: 	txdr->next_to_use = 0;
fp@673: 	txdr->next_to_clean = 0;
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Configure the Tx unit of the MAC after a reset.
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_configure_tx(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	uint64_t tdba = adapter->tx_ring.dma;
fp@673: 	uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc);
fp@673: 	uint32_t tctl, tipg;
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
fp@673: 
fp@673: 	/* Setup the HW Tx Head and Tail descriptor pointers */
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDH, 0);
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDT, 0);
fp@673: 
fp@673: 	/* Set the default values for the Tx Inter Packet Gap timer */
fp@673: 
fp@673: 	switch (adapter->hw.mac_type) {
fp@673: 	case e1000_82542_rev2_0:
fp@673: 	case e1000_82542_rev2_1:
fp@673: 		tipg = DEFAULT_82542_TIPG_IPGT;
fp@673: 		tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
fp@673: 		tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
fp@673: 		break;
fp@673: 	default:
fp@673: 		if(adapter->hw.media_type == e1000_media_type_fiber ||
fp@673: 		   adapter->hw.media_type == e1000_media_type_internal_serdes)
fp@673: 			tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
fp@673: 		else
fp@673: 			tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
fp@673: 		tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
fp@673: 		tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
fp@673: 	}
fp@673: 	E1000_WRITE_REG(&adapter->hw, TIPG, tipg);
fp@673: 
fp@673: 	/* Set the Tx Interrupt Delay register */
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
fp@673: 	if(adapter->hw.mac_type >= e1000_82540)
fp@673: 		E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay);
fp@673: 
fp@673: 	/* Program the Transmit Control Register */
fp@673: 
fp@673: 	tctl = E1000_READ_REG(&adapter->hw, TCTL);
fp@673: 
fp@673: 	tctl &= ~E1000_TCTL_CT;
fp@673: 	tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
fp@673: 		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
fp@673: 
fp@673: 	e1000_config_collision_dist(&adapter->hw);
fp@673: 
fp@673: 	/* Setup Transmit Descriptor Settings for eop descriptor */
fp@673: 	adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
fp@673: 		E1000_TXD_CMD_IFCS;
fp@673: 
fp@673: 	if(adapter->hw.mac_type < e1000_82543)
fp@673: 		adapter->txd_cmd |= E1000_TXD_CMD_RPS;
fp@673: 	else
fp@673: 		adapter->txd_cmd |= E1000_TXD_CMD_RS;
fp@673: 
fp@673: 	/* Cache if we're 82544 running in PCI-X because we'll
fp@673: 	 * need this to apply a workaround later in the send path. */
fp@673: 	if(adapter->hw.mac_type == e1000_82544 &&
fp@673: 	   adapter->hw.bus_type == e1000_bus_type_pcix)
fp@673: 		adapter->pcix_82544 = 1;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Returns 0 on success, negative on failure
fp@673:  **/
fp@673: 
fp@673: int
fp@673: e1000_setup_rx_resources(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *rxdr = &adapter->rx_ring;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	int size, desc_len;
fp@673: 
fp@673: 	size = sizeof(struct e1000_buffer) * rxdr->count;
fp@673: 	rxdr->buffer_info = vmalloc(size);
fp@673: 	if(!rxdr->buffer_info) {
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 	memset(rxdr->buffer_info, 0, size);
fp@673: 
fp@673: 	size = sizeof(struct e1000_ps_page) * rxdr->count;
fp@673: 	rxdr->ps_page = kmalloc(size, GFP_KERNEL);
fp@673: 	if(!rxdr->ps_page) {
fp@673: 		vfree(rxdr->buffer_info);
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 	memset(rxdr->ps_page, 0, size);
fp@673: 
fp@673: 	size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
fp@673: 	rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
fp@673: 	if(!rxdr->ps_page_dma) {
fp@673: 		vfree(rxdr->buffer_info);
fp@673: 		kfree(rxdr->ps_page);
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 	memset(rxdr->ps_page_dma, 0, size);
fp@673: 
fp@673: 	if(adapter->hw.mac_type <= e1000_82547_rev_2)
fp@673: 		desc_len = sizeof(struct e1000_rx_desc);
fp@673: 	else
fp@673: 		desc_len = sizeof(union e1000_rx_desc_packet_split);
fp@673: 
fp@673: 	/* Round up to nearest 4K */
fp@673: 
fp@673: 	rxdr->size = rxdr->count * desc_len;
fp@673: 	E1000_ROUNDUP(rxdr->size, 4096);
fp@673: 
fp@673: 	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
fp@673: 
fp@673: 	if(!rxdr->desc) {
fp@673: setup_rx_desc_die:
fp@673: 		vfree(rxdr->buffer_info);
fp@673: 		kfree(rxdr->ps_page);
fp@673: 		kfree(rxdr->ps_page_dma);
fp@673: 		DPRINTK(PROBE, ERR,
fp@673: 		"Unable to allocate memory for the receive descriptor ring\n");
fp@673: 		return -ENOMEM;
fp@673: 	}
fp@673: 
fp@673: 	/* Fix for errata 23, can't cross 64kB boundary */
fp@673: 	if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
fp@673: 		void *olddesc = rxdr->desc;
fp@673: 		dma_addr_t olddma = rxdr->dma;
fp@673: 		DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
fp@673: 				     "at %p\n", rxdr->size, rxdr->desc);
fp@673: 		/* Try again, without freeing the previous */
fp@673: 		rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
fp@673: 		if(!rxdr->desc) {
fp@673: 		/* Failed allocation, critical failure */
fp@673: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@673: 			goto setup_rx_desc_die;
fp@673: 		}
fp@673: 
fp@673: 		if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
fp@673: 			/* give up */
fp@673: 			pci_free_consistent(pdev, rxdr->size, rxdr->desc,
fp@673: 					    rxdr->dma);
fp@673: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@673: 			DPRINTK(PROBE, ERR,
fp@673: 				"Unable to allocate aligned memory "
fp@673: 				"for the receive descriptor ring\n");
fp@673: 			vfree(rxdr->buffer_info);
fp@673: 			kfree(rxdr->ps_page);
fp@673: 			kfree(rxdr->ps_page_dma);
fp@673: 			return -ENOMEM;
fp@673: 		} else {
fp@673: 			/* Free old allocation, new allocation was successful */
fp@673: 			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
fp@673: 		}
fp@673: 	}
fp@673: 	memset(rxdr->desc, 0, rxdr->size);
fp@673: 
fp@673: 	rxdr->next_to_clean = 0;
fp@673: 	rxdr->next_to_use = 0;
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_setup_rctl - configure the receive control registers
fp@673:  * @adapter: Board private structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_setup_rctl(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	uint32_t rctl, rfctl;
fp@673: 	uint32_t psrctl = 0;
fp@673: 
fp@673: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 
fp@673: 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
fp@673: 
fp@673: 	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
fp@673: 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
fp@673: 		(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@673: 
fp@673: 	if(adapter->hw.tbi_compatibility_on == 1)
fp@673: 		rctl |= E1000_RCTL_SBP;
fp@673: 	else
fp@673: 		rctl &= ~E1000_RCTL_SBP;
fp@673: 
fp@673: 	if (adapter->netdev->mtu <= ETH_DATA_LEN)
fp@673: 		rctl &= ~E1000_RCTL_LPE;
fp@673: 	else
fp@673: 		rctl |= E1000_RCTL_LPE;
fp@673: 
fp@673: 	/* Setup buffer sizes */
fp@673: 	if(adapter->hw.mac_type == e1000_82573) {
fp@673: 		/* We can now specify buffers in 1K increments.
fp@673: 		 * BSIZE and BSEX are ignored in this case. */
fp@673: 		rctl |= adapter->rx_buffer_len << 0x11;
fp@673: 	} else {
fp@673: 		rctl &= ~E1000_RCTL_SZ_4096;
fp@673: 		rctl |= E1000_RCTL_BSEX; 
fp@673: 		switch (adapter->rx_buffer_len) {
fp@673: 		case E1000_RXBUFFER_2048:
fp@673: 		default:
fp@673: 			rctl |= E1000_RCTL_SZ_2048;
fp@673: 			rctl &= ~E1000_RCTL_BSEX;
fp@673: 			break;
fp@673: 		case E1000_RXBUFFER_4096:
fp@673: 			rctl |= E1000_RCTL_SZ_4096;
fp@673: 			break;
fp@673: 		case E1000_RXBUFFER_8192:
fp@673: 			rctl |= E1000_RCTL_SZ_8192;
fp@673: 			break;
fp@673: 		case E1000_RXBUFFER_16384:
fp@673: 			rctl |= E1000_RCTL_SZ_16384;
fp@673: 			break;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: #ifdef CONFIG_E1000_PACKET_SPLIT
fp@673: 	/* 82571 and greater support packet-split where the protocol
fp@673: 	 * header is placed in skb->data and the packet data is
fp@673: 	 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
fp@673: 	 * In the case of a non-split, skb->data is linearly filled,
fp@673: 	 * followed by the page buffers.  Therefore, skb->data is
fp@673: 	 * sized to hold the largest protocol header.
fp@673: 	 */
fp@673: 	adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2) 
fp@673: 			  && (adapter->netdev->mtu 
fp@673: 	                      < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0));
fp@673: #endif
fp@673: 	if(adapter->rx_ps) {
fp@673: 		/* Configure extra packet-split registers */
fp@673: 		rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
fp@673: 		rfctl |= E1000_RFCTL_EXTEN;
fp@673: 		/* disable IPv6 packet split support */
fp@673: 		rfctl |= E1000_RFCTL_IPV6_DIS;
fp@673: 		E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
fp@673: 
fp@673: 		rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
fp@673: 		
fp@673: 		psrctl |= adapter->rx_ps_bsize0 >>
fp@673: 			E1000_PSRCTL_BSIZE0_SHIFT;
fp@673: 		psrctl |= PAGE_SIZE >>
fp@673: 			E1000_PSRCTL_BSIZE1_SHIFT;
fp@673: 		psrctl |= PAGE_SIZE <<
fp@673: 			E1000_PSRCTL_BSIZE2_SHIFT;
fp@673: 		psrctl |= PAGE_SIZE <<
fp@673: 			E1000_PSRCTL_BSIZE3_SHIFT;
fp@673: 
fp@673: 		E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
fp@673: 	}
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_configure_rx - Configure 8254x Receive Unit after Reset
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Configure the Rx unit of the MAC after a reset.
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_configure_rx(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	uint64_t rdba = adapter->rx_ring.dma;
fp@673: 	uint32_t rdlen, rctl, rxcsum;
fp@673: 
fp@673: 	if(adapter->rx_ps) {
fp@673: 		rdlen = adapter->rx_ring.count *
fp@673: 			sizeof(union e1000_rx_desc_packet_split);
fp@673: 		adapter->clean_rx = e1000_clean_rx_irq_ps;
fp@673: 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
fp@673: 	} else {
fp@673: 		rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc);
fp@673: 		adapter->clean_rx = e1000_clean_rx_irq;
fp@673: 		adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
fp@673: 	}
fp@673: 
fp@673: 	/* disable receives while setting up the descriptors */
fp@673: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
fp@673: 
fp@673: 	/* set the Receive Delay Timer Register */
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay);
fp@673: 
fp@673: 	if(adapter->hw.mac_type >= e1000_82540) {
fp@673: 		E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay);
fp@673: 		if(adapter->itr > 1)
fp@673: 			E1000_WRITE_REG(&adapter->hw, ITR,
fp@673: 				1000000000 / (adapter->itr * 256));
fp@673: 	}
fp@673: 
fp@673: 	/* Setup the Base and Length of the Rx Descriptor Ring */
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL));
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen);
fp@673: 
fp@673: 	/* Setup the HW Rx Head and Tail Descriptor Pointers */
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDH, 0);
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDT, 0);
fp@673: 
fp@673: 	/* Enable 82543 Receive Checksum Offload for TCP and UDP */
fp@673: 	if(adapter->hw.mac_type >= e1000_82543) {
fp@673: 		rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
fp@673: 		if(adapter->rx_csum == TRUE) {
fp@673: 			rxcsum |= E1000_RXCSUM_TUOFL;
fp@673: 
fp@673: 			/* Enable 82573 IPv4 payload checksum for UDP fragments
fp@673: 			 * Must be used in conjunction with packet-split. */
fp@673: 			if((adapter->hw.mac_type > e1000_82547_rev_2) && 
fp@673: 			   (adapter->rx_ps)) {
fp@673: 				rxcsum |= E1000_RXCSUM_IPPCSE;
fp@673: 			}
fp@673: 		} else {
fp@673: 			rxcsum &= ~E1000_RXCSUM_TUOFL;
fp@673: 			/* don't need to clear IPPCSE as it defaults to 0 */
fp@673: 		}
fp@673: 		E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum);
fp@673: 	}
fp@673: 
fp@673: 	if (adapter->hw.mac_type == e1000_82573)
fp@673: 		E1000_WRITE_REG(&adapter->hw, ERT, 0x0100);
fp@673: 
fp@673: 	/* Enable Receives */
fp@673: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_free_tx_resources - Free Tx Resources
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Free all transmit software resources
fp@673:  **/
fp@673: 
fp@673: void
fp@673: e1000_free_tx_resources(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 
fp@673: 	e1000_clean_tx_ring(adapter);
fp@673: 
fp@673: 	vfree(adapter->tx_ring.buffer_info);
fp@673: 	adapter->tx_ring.buffer_info = NULL;
fp@673: 
fp@673: 	pci_free_consistent(pdev, adapter->tx_ring.size,
fp@673: 	                    adapter->tx_ring.desc, adapter->tx_ring.dma);
fp@673: 
fp@673: 	adapter->tx_ring.desc = NULL;
fp@673: }
fp@673: 
fp@673: static inline void
fp@673: e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
fp@673: 			struct e1000_buffer *buffer_info)
fp@673: {
fp@676: 	if (adapter->ecdev)
fp@676: 		return;
fp@676: 
fp@673: 	if(buffer_info->dma) {
fp@673: 		pci_unmap_page(adapter->pdev,
fp@673: 				buffer_info->dma,
fp@673: 				buffer_info->length,
fp@673: 				PCI_DMA_TODEVICE);
fp@673: 		buffer_info->dma = 0;
fp@673: 	}
fp@673: 	if(buffer_info->skb) {
fp@673: 		dev_kfree_skb_any(buffer_info->skb);
fp@673: 		buffer_info->skb = NULL;
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_clean_tx_ring - Free Tx Buffers
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_clean_tx_ring(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	unsigned long size;
fp@673: 	unsigned int i;
fp@673: 
fp@673: 	/* Free all the Tx ring sk_buffs */
fp@673: 
fp@673: 	if (likely(adapter->previous_buffer_info.skb != NULL)) {
fp@673: 		e1000_unmap_and_free_tx_resource(adapter,
fp@673: 				&adapter->previous_buffer_info);
fp@673: 	}
fp@673: 
fp@673: 	for(i = 0; i < tx_ring->count; i++) {
fp@673: 		buffer_info = &tx_ring->buffer_info[i];
fp@673: 		e1000_unmap_and_free_tx_resource(adapter, buffer_info);
fp@673: 	}
fp@673: 
fp@673: 	size = sizeof(struct e1000_buffer) * tx_ring->count;
fp@673: 	memset(tx_ring->buffer_info, 0, size);
fp@673: 
fp@673: 	/* Zero out the descriptor ring */
fp@673: 
fp@673: 	memset(tx_ring->desc, 0, tx_ring->size);
fp@673: 
fp@673: 	tx_ring->next_to_use = 0;
fp@673: 	tx_ring->next_to_clean = 0;
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDH, 0);
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDT, 0);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_free_rx_resources - Free Rx Resources
fp@673:  * @adapter: board private structure
fp@673:  *
fp@673:  * Free all receive software resources
fp@673:  **/
fp@673: 
fp@673: void
fp@673: e1000_free_rx_resources(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 
fp@673: 	e1000_clean_rx_ring(adapter);
fp@673: 
fp@673: 	vfree(rx_ring->buffer_info);
fp@673: 	rx_ring->buffer_info = NULL;
fp@673: 	kfree(rx_ring->ps_page);
fp@673: 	rx_ring->ps_page = NULL;
fp@673: 	kfree(rx_ring->ps_page_dma);
fp@673: 	rx_ring->ps_page_dma = NULL;
fp@673: 
fp@673: 	pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
fp@673: 
fp@673: 	rx_ring->desc = NULL;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_clean_rx_ring - Free Rx Buffers
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_clean_rx_ring(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	struct e1000_ps_page *ps_page;
fp@673: 	struct e1000_ps_page_dma *ps_page_dma;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	unsigned long size;
fp@673: 	unsigned int i, j;
fp@673: 
fp@673: 	/* Free all the Rx ring sk_buffs */
fp@673: 
fp@673: 	for(i = 0; i < rx_ring->count; i++) {
fp@673: 		buffer_info = &rx_ring->buffer_info[i];
fp@673: 		if(buffer_info->skb) {
fp@673: 			ps_page = &rx_ring->ps_page[i];
fp@673: 			ps_page_dma = &rx_ring->ps_page_dma[i];
fp@673: 			pci_unmap_single(pdev,
fp@673: 					 buffer_info->dma,
fp@673: 					 buffer_info->length,
fp@673: 					 PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 			dev_kfree_skb(buffer_info->skb);
fp@673: 			buffer_info->skb = NULL;
fp@673: 
fp@673: 			for(j = 0; j < PS_PAGE_BUFFERS; j++) {
fp@673: 				if(!ps_page->ps_page[j]) break;
fp@673: 				pci_unmap_single(pdev,
fp@673: 						 ps_page_dma->ps_page_dma[j],
fp@673: 						 PAGE_SIZE, PCI_DMA_FROMDEVICE);
fp@673: 				ps_page_dma->ps_page_dma[j] = 0;
fp@673: 				put_page(ps_page->ps_page[j]);
fp@673: 				ps_page->ps_page[j] = NULL;
fp@673: 			}
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	size = sizeof(struct e1000_buffer) * rx_ring->count;
fp@673: 	memset(rx_ring->buffer_info, 0, size);
fp@673: 	size = sizeof(struct e1000_ps_page) * rx_ring->count;
fp@673: 	memset(rx_ring->ps_page, 0, size);
fp@673: 	size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
fp@673: 	memset(rx_ring->ps_page_dma, 0, size);
fp@673: 
fp@673: 	/* Zero out the descriptor ring */
fp@673: 
fp@673: 	memset(rx_ring->desc, 0, rx_ring->size);
fp@673: 
fp@673: 	rx_ring->next_to_clean = 0;
fp@673: 	rx_ring->next_to_use = 0;
fp@673: 
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDH, 0);
fp@673: 	E1000_WRITE_REG(&adapter->hw, RDT, 0);
fp@673: }
fp@673: 
fp@673: /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
fp@673:  * and memory write and invalidate disabled for certain operations
fp@673:  */
fp@673: static void
fp@673: e1000_enter_82542_rst(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	uint32_t rctl;
fp@673: 
fp@673: 	e1000_pci_clear_mwi(&adapter->hw);
fp@673: 
fp@673: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 	rctl |= E1000_RCTL_RST;
fp@673: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@673: 	mdelay(5);
fp@673: 
fp@673: 	if (!adapter->ecdev && netif_running(netdev))
fp@673: 		e1000_clean_rx_ring(adapter);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_leave_82542_rst(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	uint32_t rctl;
fp@673: 
fp@673: 	rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 	rctl &= ~E1000_RCTL_RST;
fp@673: 	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: 	E1000_WRITE_FLUSH(&adapter->hw);
fp@673: 	mdelay(5);
fp@673: 
fp@673: 	if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
fp@673: 		e1000_pci_set_mwi(&adapter->hw);
fp@673: 
fp@673: 	if (!adapter->ecdev && netif_running(netdev)) {
fp@673: 		e1000_configure_rx(adapter);
fp@673: 		e1000_alloc_rx_buffers(adapter);
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_set_mac - Change the Ethernet Address of the NIC
fp@673:  * @netdev: network interface device structure
fp@673:  * @p: pointer to an address structure
fp@673:  *
fp@673:  * Returns 0 on success, negative on failure
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_set_mac(struct net_device *netdev, void *p)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	struct sockaddr *addr = p;
fp@673: 
fp@673: 	if(!is_valid_ether_addr(addr->sa_data))
fp@673: 		return -EADDRNOTAVAIL;
fp@673: 
fp@673: 	/* 82542 2.0 needs to be in reset to write receive address registers */
fp@673: 
fp@673: 	if(adapter->hw.mac_type == e1000_82542_rev2_0)
fp@673: 		e1000_enter_82542_rst(adapter);
fp@673: 
fp@673: 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
fp@673: 	memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
fp@673: 
fp@673: 	e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
fp@673: 
fp@673: 	if(adapter->hw.mac_type == e1000_82542_rev2_0)
fp@673: 		e1000_leave_82542_rst(adapter);
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_set_multi - Multicast and Promiscuous mode set
fp@673:  * @netdev: network interface device structure
fp@673:  *
fp@673:  * The set_multi entry point is called whenever the multicast address
fp@673:  * list or the network interface flags are updated.  This routine is
fp@673:  * responsible for configuring the hardware for proper multicast,
fp@673:  * promiscuous mode, and all-multi behavior.
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_set_multi(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	struct e1000_hw *hw = &adapter->hw;
fp@673: 	struct dev_mc_list *mc_ptr;
fp@676: 	unsigned long flags = 0;
fp@673: 	uint32_t rctl;
fp@673: 	uint32_t hash_value;
fp@673: 	int i;
fp@673: 
fp@676:     if (!adapter->ecdev)
fp@676:         spin_lock_irqsave(&adapter->tx_lock, flags);
fp@673: 
fp@673: 	/* Check for Promiscuous and All Multicast modes */
fp@673: 
fp@673: 	rctl = E1000_READ_REG(hw, RCTL);
fp@673: 
fp@673: 	if(netdev->flags & IFF_PROMISC) {
fp@673: 		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
fp@673: 	} else if(netdev->flags & IFF_ALLMULTI) {
fp@673: 		rctl |= E1000_RCTL_MPE;
fp@673: 		rctl &= ~E1000_RCTL_UPE;
fp@673: 	} else {
fp@673: 		rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
fp@673: 	}
fp@673: 
fp@673: 	E1000_WRITE_REG(hw, RCTL, rctl);
fp@673: 
fp@673: 	/* 82542 2.0 needs to be in reset to write receive address registers */
fp@673: 
fp@673: 	if(hw->mac_type == e1000_82542_rev2_0)
fp@673: 		e1000_enter_82542_rst(adapter);
fp@673: 
fp@673: 	/* load the first 14 multicast address into the exact filters 1-14
fp@673: 	 * RAR 0 is used for the station MAC adddress
fp@673: 	 * if there are not 14 addresses, go ahead and clear the filters
fp@673: 	 */
fp@673: 	mc_ptr = netdev->mc_list;
fp@673: 
fp@673: 	for(i = 1; i < E1000_RAR_ENTRIES; i++) {
fp@673: 		if(mc_ptr) {
fp@673: 			e1000_rar_set(hw, mc_ptr->dmi_addr, i);
fp@673: 			mc_ptr = mc_ptr->next;
fp@673: 		} else {
fp@673: 			E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
fp@673: 			E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	/* clear the old settings from the multicast hash table */
fp@673: 
fp@673: 	for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
fp@673: 		E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
fp@673: 
fp@673: 	/* load any remaining addresses into the hash table */
fp@673: 
fp@673: 	for(; mc_ptr; mc_ptr = mc_ptr->next) {
fp@673: 		hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
fp@673: 		e1000_mta_set(hw, hash_value);
fp@673: 	}
fp@673: 
fp@673: 	if(hw->mac_type == e1000_82542_rev2_0)
fp@673: 		e1000_leave_82542_rst(adapter);
fp@673: 
fp@676:     if (!adapter->ecdev)
fp@676:         spin_unlock_irqrestore(&adapter->tx_lock, flags);
fp@673: }
fp@673: 
fp@673: /* Need to wait a few seconds after link up to get diagnostic information from
fp@673:  * the phy */
fp@673: 
fp@673: static void
fp@673: e1000_update_phy_info(unsigned long data)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@673: 	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_82547_tx_fifo_stall - Timer Call-back
fp@673:  * @data: pointer to adapter cast into an unsigned long
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_82547_tx_fifo_stall(unsigned long data)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	uint32_t tctl;
fp@673: 
fp@673: 	if(atomic_read(&adapter->tx_fifo_stall)) {
fp@673: 		if((E1000_READ_REG(&adapter->hw, TDT) ==
fp@673: 		    E1000_READ_REG(&adapter->hw, TDH)) &&
fp@673: 		   (E1000_READ_REG(&adapter->hw, TDFT) ==
fp@673: 		    E1000_READ_REG(&adapter->hw, TDFH)) &&
fp@673: 		   (E1000_READ_REG(&adapter->hw, TDFTS) ==
fp@673: 		    E1000_READ_REG(&adapter->hw, TDFHS))) {
fp@673: 			tctl = E1000_READ_REG(&adapter->hw, TCTL);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TCTL,
fp@673: 					tctl & ~E1000_TCTL_EN);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TDFT,
fp@673: 					adapter->tx_head_addr);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TDFH,
fp@673: 					adapter->tx_head_addr);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TDFTS,
fp@673: 					adapter->tx_head_addr);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TDFHS,
fp@673: 					adapter->tx_head_addr);
fp@673: 			E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
fp@673: 			E1000_WRITE_FLUSH(&adapter->hw);
fp@673: 
fp@673: 			adapter->tx_fifo_head = 0;
fp@673: 			atomic_set(&adapter->tx_fifo_stall, 0);
fp@673: 			if (!adapter->ecdev) netif_wake_queue(netdev);
fp@673: 		} else {
fp@673: 			mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
fp@673: 		}
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_watchdog - Timer Call-back
fp@673:  * @data: pointer to adapter cast into an unsigned long
fp@673:  **/
fp@673: static void
fp@673: e1000_watchdog(unsigned long data)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
fp@673: 
fp@673: 	/* Do the rest outside of interrupt context */
fp@673: 	schedule_work(&adapter->watchdog_task);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_watchdog_task(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct e1000_desc_ring *txdr = &adapter->tx_ring;
fp@673: 	uint32_t link;
fp@673: 
fp@673: 	e1000_check_for_link(&adapter->hw);
fp@673: 	if (adapter->hw.mac_type == e1000_82573) {
fp@673: 		e1000_enable_tx_pkt_filtering(&adapter->hw);
fp@673: 		if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
fp@673: 			e1000_update_mng_vlan(adapter);
fp@673: 	}	
fp@673: 
fp@673: 	if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
fp@673: 	   !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
fp@673: 		link = !adapter->hw.serdes_link_down;
fp@673: 	else
fp@673: 		link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
fp@673: 
fp@673: 	if (link) {
fp@673: 		if ((adapter->ecdev && !ecdev_get_link(adapter->ecdev))
fp@673: 				|| (!adapter->ecdev && !netif_carrier_ok(netdev))) {
fp@673: 			e1000_get_speed_and_duplex(&adapter->hw,
fp@673: 			                           &adapter->link_speed,
fp@673: 			                           &adapter->link_duplex);
fp@673: 
fp@673: 			DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
fp@673: 			       adapter->link_speed,
fp@673: 			       adapter->link_duplex == FULL_DUPLEX ?
fp@673: 			       "Full Duplex" : "Half Duplex");
fp@673: 
fp@673: 			if (adapter->ecdev) {
fp@673: 				ecdev_set_link(adapter->ecdev, 1);
fp@673: 			} else {
fp@673: 				netif_carrier_on(netdev);
fp@673: 				netif_wake_queue(netdev);
fp@676:                 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
fp@673: 			}
fp@673: 			adapter->smartspeed = 0;
fp@673: 		}
fp@673: 	} else {
fp@673: 		if ((adapter->ecdev && ecdev_get_link(adapter->ecdev))
fp@673: 				|| (!adapter->ecdev && netif_carrier_ok(netdev))) {
fp@673: 			adapter->link_speed = 0;
fp@673: 			adapter->link_duplex = 0;
fp@673: 			DPRINTK(LINK, INFO, "NIC Link is Down\n");
fp@673: 			if (adapter->ecdev) {
fp@673: 				ecdev_set_link(adapter->ecdev, 0);
fp@673: 			} else {
fp@673: 				netif_carrier_off(netdev);
fp@673: 				netif_stop_queue(netdev);
fp@676:                 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
fp@673: 			}
fp@673: 		}
fp@673: 
fp@673: 		e1000_smartspeed(adapter);
fp@673: 	}
fp@673: 
fp@673: 	e1000_update_stats(adapter);
fp@673: 
fp@673: 	adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
fp@673: 	adapter->tpt_old = adapter->stats.tpt;
fp@673: 	adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
fp@673: 	adapter->colc_old = adapter->stats.colc;
fp@673: 
fp@673: 	adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
fp@673: 	adapter->gorcl_old = adapter->stats.gorcl;
fp@673: 	adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
fp@673: 	adapter->gotcl_old = adapter->stats.gotcl;
fp@673: 
fp@673: 	e1000_update_adaptive(&adapter->hw);
fp@673: 
fp@676: 	if (!adapter->ecdev && !netif_carrier_ok(netdev)) {
fp@677: 		if(E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
fp@673: 			/* We've lost link, so the controller stops DMA,
fp@673: 			 * but we've got queued Tx work that's never going
fp@673: 			 * to get done, so reset controller to flush Tx.
fp@673: 			 * (Do the reset outside of interrupt context). */
fp@673: 			schedule_work(&adapter->tx_timeout_task);
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	/* Dynamic mode for Interrupt Throttle Rate (ITR) */
fp@673: 	if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
fp@673: 		/* Symmetric Tx/Rx gets a reduced ITR=2000; Total
fp@673: 		 * asymmetrical Tx or Rx gets ITR=8000; everyone
fp@673: 		 * else is between 2000-8000. */
fp@673: 		uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
fp@673: 		uint32_t dif = (adapter->gotcl > adapter->gorcl ? 
fp@673: 			adapter->gotcl - adapter->gorcl :
fp@673: 			adapter->gorcl - adapter->gotcl) / 10000;
fp@673: 		uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
fp@673: 		E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
fp@673: 	}
fp@673: 
fp@673: 	/* Cause software interrupt to ensure rx ring is cleaned */
fp@673: 	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
fp@673: 
fp@673: 	/* Force detection of hung controller every watchdog period */
fp@676: 	if (!adapter->ecdev) adapter->detect_tx_hung = TRUE;
fp@673: 
fp@673: 	/* Reset the timer */
fp@676: 	if (!adapter->ecdev)
fp@676:         mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
fp@673: }
fp@673: 
fp@673: #define E1000_TX_FLAGS_CSUM		0x00000001
fp@673: #define E1000_TX_FLAGS_VLAN		0x00000002
fp@673: #define E1000_TX_FLAGS_TSO		0x00000004
fp@673: #define E1000_TX_FLAGS_IPV4		0x00000008
fp@673: #define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
fp@673: #define E1000_TX_FLAGS_VLAN_SHIFT	16
fp@673: 
fp@673: static inline int
fp@673: e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@673: {
fp@673: #ifdef NETIF_F_TSO
fp@673: 	struct e1000_context_desc *context_desc;
fp@673: 	unsigned int i;
fp@673: 	uint32_t cmd_length = 0;
fp@673: 	uint16_t ipcse = 0, tucse, mss;
fp@673: 	uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
fp@673: 	int err;
fp@673: 
fp@673: 	if(skb_shinfo(skb)->tso_size) {
fp@673: 		if (skb_header_cloned(skb)) {
fp@673: 			err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
fp@673: 			if (err)
fp@673: 				return err;
fp@673: 		}
fp@673: 
fp@673: 		hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
fp@673: 		mss = skb_shinfo(skb)->tso_size;
fp@673: 		if(skb->protocol == ntohs(ETH_P_IP)) {
fp@673: 			skb->nh.iph->tot_len = 0;
fp@673: 			skb->nh.iph->check = 0;
fp@673: 			skb->h.th->check =
fp@673: 				~csum_tcpudp_magic(skb->nh.iph->saddr,
fp@673: 						   skb->nh.iph->daddr,
fp@673: 						   0,
fp@673: 						   IPPROTO_TCP,
fp@673: 						   0);
fp@673: 			cmd_length = E1000_TXD_CMD_IP;
fp@673: 			ipcse = skb->h.raw - skb->data - 1;
fp@673: #ifdef NETIF_F_TSO_IPV6
fp@673: 		} else if(skb->protocol == ntohs(ETH_P_IPV6)) {
fp@673: 			skb->nh.ipv6h->payload_len = 0;
fp@673: 			skb->h.th->check =
fp@673: 				~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
fp@673: 						 &skb->nh.ipv6h->daddr,
fp@673: 						 0,
fp@673: 						 IPPROTO_TCP,
fp@673: 						 0);
fp@673: 			ipcse = 0;
fp@673: #endif
fp@673: 		}
fp@673: 		ipcss = skb->nh.raw - skb->data;
fp@673: 		ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
fp@673: 		tucss = skb->h.raw - skb->data;
fp@673: 		tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
fp@673: 		tucse = 0;
fp@673: 
fp@673: 		cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
fp@673: 			       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
fp@673: 
fp@673: 		i = adapter->tx_ring.next_to_use;
fp@673: 		context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
fp@673: 
fp@673: 		context_desc->lower_setup.ip_fields.ipcss  = ipcss;
fp@673: 		context_desc->lower_setup.ip_fields.ipcso  = ipcso;
fp@673: 		context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
fp@673: 		context_desc->upper_setup.tcp_fields.tucss = tucss;
fp@673: 		context_desc->upper_setup.tcp_fields.tucso = tucso;
fp@673: 		context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
fp@673: 		context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
fp@673: 		context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
fp@673: 		context_desc->cmd_and_length = cpu_to_le32(cmd_length);
fp@673: 
fp@673: 		if(++i == adapter->tx_ring.count) i = 0;
fp@673: 		adapter->tx_ring.next_to_use = i;
fp@673: 
fp@673: 		return 1;
fp@673: 	}
fp@673: #endif
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: static inline boolean_t
fp@673: e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@673: {
fp@673: 	struct e1000_context_desc *context_desc;
fp@673: 	unsigned int i;
fp@673: 	uint8_t css;
fp@673: 
fp@673: 	if(likely(skb->ip_summed == CHECKSUM_HW)) {
fp@673: 		css = skb->h.raw - skb->data;
fp@673: 
fp@673: 		i = adapter->tx_ring.next_to_use;
fp@673: 		context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
fp@673: 
fp@673: 		context_desc->upper_setup.tcp_fields.tucss = css;
fp@673: 		context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
fp@673: 		context_desc->upper_setup.tcp_fields.tucse = 0;
fp@673: 		context_desc->tcp_seg_setup.data = 0;
fp@673: 		context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
fp@673: 
fp@673: 		if(unlikely(++i == adapter->tx_ring.count)) i = 0;
fp@673: 		adapter->tx_ring.next_to_use = i;
fp@673: 
fp@673: 		return TRUE;
fp@673: 	}
fp@673: 
fp@673: 	return FALSE;
fp@673: }
fp@673: 
fp@673: #define E1000_MAX_TXD_PWR	12
fp@673: #define E1000_MAX_DATA_PER_TXD	(1<<E1000_MAX_TXD_PWR)
fp@673: 
fp@673: static inline int
fp@673: e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb,
fp@673: 	unsigned int first, unsigned int max_per_txd,
fp@673: 	unsigned int nr_frags, unsigned int mss)
fp@673: {
fp@673: 	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	unsigned int len = skb->len;
fp@673: 	unsigned int offset = 0, size, count = 0, i;
fp@673: 	unsigned int f;
fp@673: 	len -= skb->data_len;
fp@673: 
fp@673: 	i = tx_ring->next_to_use;
fp@673: 
fp@673: 	while(len) {
fp@673: 		buffer_info = &tx_ring->buffer_info[i];
fp@673: 		size = min(len, max_per_txd);
fp@673: #ifdef NETIF_F_TSO
fp@673: 		/* Workaround for premature desc write-backs
fp@673: 		 * in TSO mode.  Append 4-byte sentinel desc */
fp@673: 		if(unlikely(mss && !nr_frags && size == len && size > 8))
fp@673: 			size -= 4;
fp@673: #endif
fp@673: 		/* work-around for errata 10 and it applies
fp@673: 		 * to all controllers in PCI-X mode
fp@673: 		 * The fix is to make sure that the first descriptor of a
fp@673: 		 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
fp@673: 		 */
fp@673: 		if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
fp@673: 		                (size > 2015) && count == 0))
fp@673: 		        size = 2015;
fp@673:                                                                                 
fp@673: 		/* Workaround for potential 82544 hang in PCI-X.  Avoid
fp@673: 		 * terminating buffers within evenly-aligned dwords. */
fp@673: 		if(unlikely(adapter->pcix_82544 &&
fp@673: 		   !((unsigned long)(skb->data + offset + size - 1) & 4) &&
fp@673: 		   size > 4))
fp@673: 			size -= 4;
fp@673: 
fp@673: 		buffer_info->length = size;
fp@673: 		buffer_info->dma =
fp@673: 			pci_map_single(adapter->pdev,
fp@673: 				skb->data + offset,
fp@673: 				size,
fp@673: 				PCI_DMA_TODEVICE);
fp@673: 		buffer_info->time_stamp = jiffies;
fp@673: 
fp@673: 		len -= size;
fp@673: 		offset += size;
fp@673: 		count++;
fp@673: 		if(unlikely(++i == tx_ring->count)) i = 0;
fp@673: 	}
fp@673: 
fp@673: 	for(f = 0; f < nr_frags; f++) {
fp@673: 		struct skb_frag_struct *frag;
fp@673: 
fp@673: 		frag = &skb_shinfo(skb)->frags[f];
fp@673: 		len = frag->size;
fp@673: 		offset = frag->page_offset;
fp@673: 
fp@673: 		while(len) {
fp@673: 			buffer_info = &tx_ring->buffer_info[i];
fp@673: 			size = min(len, max_per_txd);
fp@673: #ifdef NETIF_F_TSO
fp@673: 			/* Workaround for premature desc write-backs
fp@673: 			 * in TSO mode.  Append 4-byte sentinel desc */
fp@673: 			if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
fp@673: 				size -= 4;
fp@673: #endif
fp@673: 			/* Workaround for potential 82544 hang in PCI-X.
fp@673: 			 * Avoid terminating buffers within evenly-aligned
fp@673: 			 * dwords. */
fp@673: 			if(unlikely(adapter->pcix_82544 &&
fp@673: 			   !((unsigned long)(frag->page+offset+size-1) & 4) &&
fp@673: 			   size > 4))
fp@673: 				size -= 4;
fp@673: 
fp@673: 			buffer_info->length = size;
fp@673: 			buffer_info->dma =
fp@673: 				pci_map_page(adapter->pdev,
fp@673: 					frag->page,
fp@673: 					offset,
fp@673: 					size,
fp@673: 					PCI_DMA_TODEVICE);
fp@673: 			buffer_info->time_stamp = jiffies;
fp@673: 
fp@673: 			len -= size;
fp@673: 			offset += size;
fp@673: 			count++;
fp@673: 			if(unlikely(++i == tx_ring->count)) i = 0;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	i = (i == 0) ? tx_ring->count - 1 : i - 1;
fp@673: 	tx_ring->buffer_info[i].skb = skb;
fp@673: 	tx_ring->buffer_info[first].next_to_watch = i;
fp@673: 
fp@673: 	return count;
fp@673: }
fp@673: 
fp@673: static inline void
fp@673: e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
fp@673: {
fp@673: 	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
fp@673: 	struct e1000_tx_desc *tx_desc = NULL;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
fp@673: 	unsigned int i;
fp@673: 
fp@673: 	if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
fp@673: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
fp@673: 		             E1000_TXD_CMD_TSE;
fp@673: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
fp@673: 
fp@673: 		if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
fp@673: 			txd_upper |= E1000_TXD_POPTS_IXSM << 8;
fp@673: 	}
fp@673: 
fp@673: 	if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
fp@673: 		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
fp@673: 		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
fp@673: 	}
fp@673: 
fp@673: 	if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
fp@673: 		txd_lower |= E1000_TXD_CMD_VLE;
fp@673: 		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
fp@673: 	}
fp@673: 
fp@673: 	i = tx_ring->next_to_use;
fp@673: 
fp@673: 	while(count--) {
fp@673: 		buffer_info = &tx_ring->buffer_info[i];
fp@673: 		tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@673: 		tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
fp@673: 		tx_desc->lower.data =
fp@673: 			cpu_to_le32(txd_lower | buffer_info->length);
fp@673: 		tx_desc->upper.data = cpu_to_le32(txd_upper);
fp@673: 		if(unlikely(++i == tx_ring->count)) i = 0;
fp@673: 	}
fp@673: 
fp@673: 	tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
fp@673: 
fp@673: 	/* Force memory writes to complete before letting h/w
fp@673: 	 * know there are new descriptors to fetch.  (Only
fp@673: 	 * applicable for weak-ordered memory model archs,
fp@673: 	 * such as IA-64). */
fp@673: 	wmb();
fp@673: 
fp@673: 	tx_ring->next_to_use = i;
fp@673: 	E1000_WRITE_REG(&adapter->hw, TDT, i);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * 82547 workaround to avoid controller hang in half-duplex environment.
fp@673:  * The workaround is to avoid queuing a large packet that would span
fp@673:  * the internal Tx FIFO ring boundary by notifying the stack to resend
fp@673:  * the packet at a later time.  This gives the Tx FIFO an opportunity to
fp@673:  * flush all packets.  When that occurs, we reset the Tx FIFO pointers
fp@673:  * to the beginning of the Tx FIFO.
fp@673:  **/
fp@673: 
fp@673: #define E1000_FIFO_HDR			0x10
fp@673: #define E1000_82547_PAD_LEN		0x3E0
fp@673: 
fp@673: static inline int
fp@673: e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@673: {
fp@673: 	uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
fp@673: 	uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
fp@673: 
fp@673: 	E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
fp@673: 
fp@673: 	if(adapter->link_duplex != HALF_DUPLEX)
fp@673: 		goto no_fifo_stall_required;
fp@673: 
fp@673: 	if(atomic_read(&adapter->tx_fifo_stall))
fp@673: 		return 1;
fp@673: 
fp@673: 	if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
fp@673: 		atomic_set(&adapter->tx_fifo_stall, 1);
fp@673: 		return 1;
fp@673: 	}
fp@673: 
fp@673: no_fifo_stall_required:
fp@673: 	adapter->tx_fifo_head += skb_fifo_len;
fp@673: 	if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
fp@673: 		adapter->tx_fifo_head -= adapter->tx_fifo_size;
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: #define MINIMUM_DHCP_PACKET_SIZE 282
fp@673: static inline int
fp@673: e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
fp@673: {
fp@673: 	struct e1000_hw *hw =  &adapter->hw;
fp@673: 	uint16_t length, offset;
fp@673: 	if(vlan_tx_tag_present(skb)) {
fp@673: 		if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
fp@673: 			( adapter->hw.mng_cookie.status &
fp@673: 			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
fp@673: 			return 0;
fp@673: 	}
fp@673: 	if(htons(ETH_P_IP) == skb->protocol) {
fp@673: 		const struct iphdr *ip = skb->nh.iph;
fp@673: 		if(IPPROTO_UDP == ip->protocol) {
fp@673: 			struct udphdr *udp = (struct udphdr *)(skb->h.uh);
fp@673: 			if(ntohs(udp->dest) == 67) {
fp@673: 				offset = (uint8_t *)udp + 8 - skb->data;
fp@673: 				length = skb->len - offset;
fp@673: 
fp@673: 				return e1000_mng_write_dhcp_info(hw,
fp@673: 						(uint8_t *)udp + 8, length);
fp@673: 			}
fp@673: 		}
fp@673: 	} else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
fp@673: 		struct ethhdr *eth = (struct ethhdr *) skb->data;
fp@673: 		if((htons(ETH_P_IP) == eth->h_proto)) {
fp@673: 			const struct iphdr *ip = 
fp@673: 				(struct iphdr *)((uint8_t *)skb->data+14);
fp@673: 			if(IPPROTO_UDP == ip->protocol) {
fp@673: 				struct udphdr *udp = 
fp@673: 					(struct udphdr *)((uint8_t *)ip + 
fp@673: 						(ip->ihl << 2));
fp@673: 				if(ntohs(udp->dest) == 67) {
fp@673: 					offset = (uint8_t *)udp + 8 - skb->data;
fp@673: 					length = skb->len - offset;
fp@673: 
fp@673: 					return e1000_mng_write_dhcp_info(hw,
fp@673: 							(uint8_t *)udp + 8, 
fp@673: 							length);
fp@673: 				}
fp@673: 			}
fp@673: 		}
fp@673: 	}
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
fp@673: static int
fp@673: e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
fp@673: 	unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
fp@673: 	unsigned int tx_flags = 0;
fp@673: 	unsigned int len = skb->len;
fp@673: 	unsigned long flags = 0;
fp@673: 	unsigned int nr_frags = 0;
fp@673: 	unsigned int mss = 0;
fp@673: 	int count = 0;
fp@673: 	int tso;
fp@673: 	unsigned int f;
fp@673: 	len -= skb->data_len;
fp@673: 
fp@673: 	if(unlikely(skb->len <= 0)) {
fp@673: 		if (!adapter->ecdev)
fp@673: 			dev_kfree_skb_any(skb);
fp@673: 		return NETDEV_TX_OK;
fp@673: 	}
fp@673: 
fp@673: #ifdef NETIF_F_TSO
fp@673: 	mss = skb_shinfo(skb)->tso_size;
fp@673: 	/* The controller does a simple calculation to 
fp@673: 	 * make sure there is enough room in the FIFO before
fp@673: 	 * initiating the DMA for each buffer.  The calc is:
fp@673: 	 * 4 = ceil(buffer len/mss).  To make sure we don't
fp@673: 	 * overrun the FIFO, adjust the max buffer len if mss
fp@673: 	 * drops. */
fp@673: 	if(mss) {
fp@673: 		max_per_txd = min(mss << 2, max_per_txd);
fp@673: 		max_txd_pwr = fls(max_per_txd) - 1;
fp@673: 	}
fp@673: 
fp@673: 	if((mss) || (skb->ip_summed == CHECKSUM_HW))
fp@673: 		count++;
fp@673: 	count++;
fp@673: #else
fp@673: 	if(skb->ip_summed == CHECKSUM_HW)
fp@673: 		count++;
fp@673: #endif
fp@673: 	count += TXD_USE_COUNT(len, max_txd_pwr);
fp@673: 
fp@673: 	if(adapter->pcix_82544)
fp@673: 		count++;
fp@673: 
fp@673: 	/* work-around for errata 10 and it applies to all controllers 
fp@673: 	 * in PCI-X mode, so add one more descriptor to the count
fp@673: 	 */
fp@673: 	if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
fp@673: 			(len > 2015)))
fp@673: 		count++;
fp@673: 
fp@673: 	nr_frags = skb_shinfo(skb)->nr_frags;
fp@673: 	for(f = 0; f < nr_frags; f++)
fp@673: 		count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
fp@673: 				       max_txd_pwr);
fp@673: 	if(adapter->pcix_82544)
fp@673: 		count += nr_frags;
fp@673: 
fp@676: 	if (!adapter->ecdev) {
fp@676: 		local_irq_save(flags); 
fp@676: 		if (!spin_trylock(&adapter->tx_lock)) { 
fp@676: 			/* Collision - tell upper layer to requeue */ 
fp@676: 			local_irq_restore(flags); 
fp@676: 			return NETDEV_TX_LOCKED; 
fp@676: 		} 
fp@676: 		if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
fp@676: 			e1000_transfer_dhcp_info(adapter, skb);
fp@676: 	}
fp@673: 
fp@673: 
fp@673: 	/* need: count + 2 desc gap to keep tail from touching
fp@673: 	 * head, otherwise try next time */
fp@673: 	if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < count + 2)) {
fp@673: 		if (!adapter->ecdev) {
fp@673: 			netif_stop_queue(netdev);
fp@673: 			spin_unlock_irqrestore(&adapter->tx_lock, flags);
fp@673: 		}
fp@673: 		return NETDEV_TX_BUSY;
fp@673: 	}
fp@673: 
fp@673: 	if(unlikely(adapter->hw.mac_type == e1000_82547)) {
fp@673: 		if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
fp@676: 			if (!adapter->ecdev) {
fp@673: 				netif_stop_queue(netdev);
fp@676:                 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
fp@673: 				spin_unlock_irqrestore(&adapter->tx_lock, flags);
fp@676:             }
fp@673: 			return NETDEV_TX_BUSY;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
fp@673: 		tx_flags |= E1000_TX_FLAGS_VLAN;
fp@673: 		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
fp@673: 	}
fp@673: 
fp@673: 	first = adapter->tx_ring.next_to_use;
fp@673: 	
fp@673: 	tso = e1000_tso(adapter, skb);
fp@673: 	if (tso < 0) {
fp@673: 		if (!adapter->ecdev) {
fp@673: 			dev_kfree_skb_any(skb);
fp@673: 			spin_unlock_irqrestore(&adapter->tx_lock, flags);
fp@673: 		}
fp@673: 		return NETDEV_TX_OK;
fp@673: 	}
fp@673: 
fp@673: 	if (likely(tso))
fp@673: 		tx_flags |= E1000_TX_FLAGS_TSO;
fp@673: 	else if(likely(e1000_tx_csum(adapter, skb)))
fp@673: 		tx_flags |= E1000_TX_FLAGS_CSUM;
fp@673: 
fp@673: 	/* Old method was to assume IPv4 packet by default if TSO was enabled.
fp@673: 	 * 82573 hardware supports TSO capabilities for IPv6 as well...
fp@673: 	 * no longer assume, we must. */
fp@673: 	if(likely(skb->protocol == ntohs(ETH_P_IP)))
fp@673: 		tx_flags |= E1000_TX_FLAGS_IPV4;
fp@673: 
fp@673: 	e1000_tx_queue(adapter,
fp@673: 		e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss),
fp@673: 		tx_flags);
fp@673: 
fp@673: 	netdev->trans_start = jiffies;
fp@673: 
fp@673: 	/* Make sure there is space in the ring for the next send. */
fp@673: 	if (!adapter->ecdev) {
fp@673: 		if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2))
fp@673: 			netif_stop_queue(netdev);
fp@673: 		spin_unlock_irqrestore(&adapter->tx_lock, flags);
fp@673: 	}
fp@673: 	return NETDEV_TX_OK;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_tx_timeout - Respond to a Tx Hang
fp@673:  * @netdev: network interface device structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_tx_timeout(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 
fp@673: 	/* Do the reset outside of interrupt context */
fp@673: 	schedule_work(&adapter->tx_timeout_task);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_tx_timeout_task(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 
fp@673: 	e1000_down(adapter);
fp@673: 	e1000_up(adapter);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_get_stats - Get System Network Statistics
fp@673:  * @netdev: network interface device structure
fp@673:  *
fp@673:  * Returns the address of the device statistics structure.
fp@673:  * The statistics are actually updated from the timer callback.
fp@673:  **/
fp@673: 
fp@673: static struct net_device_stats *
fp@673: e1000_get_stats(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 
fp@673: 	e1000_update_stats(adapter);
fp@673: 	return &adapter->net_stats;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_change_mtu - Change the Maximum Transfer Unit
fp@673:  * @netdev: network interface device structure
fp@673:  * @new_mtu: new value for maximum frame size
fp@673:  *
fp@673:  * Returns 0 on success, negative on failure
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_change_mtu(struct net_device *netdev, int new_mtu)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
fp@673: 
fp@673: 	if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
fp@673: 		(max_frame > MAX_JUMBO_FRAME_SIZE)) {
fp@673: 			DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
fp@673: 			return -EINVAL;
fp@673: 	}
fp@673: 
fp@673: #define MAX_STD_JUMBO_FRAME_SIZE 9216
fp@673: 	/* might want this to be bigger enum check... */
fp@673: 	if (adapter->hw.mac_type == e1000_82573 &&
fp@673: 	    max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
fp@673: 		DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
fp@673: 				    "on 82573\n");
fp@673: 		return -EINVAL;
fp@673: 	}
fp@673: 
fp@673: 	if(adapter->hw.mac_type > e1000_82547_rev_2) {
fp@673: 		adapter->rx_buffer_len = max_frame;
fp@673: 		E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
fp@673: 	} else {
fp@673: 		if(unlikely((adapter->hw.mac_type < e1000_82543) &&
fp@673: 		   (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
fp@673: 			DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
fp@673: 					    "on 82542\n");
fp@673: 			return -EINVAL;
fp@673: 
fp@673: 		} else {
fp@673: 			if(max_frame <= E1000_RXBUFFER_2048) {
fp@673: 				adapter->rx_buffer_len = E1000_RXBUFFER_2048;
fp@673: 			} else if(max_frame <= E1000_RXBUFFER_4096) {
fp@673: 				adapter->rx_buffer_len = E1000_RXBUFFER_4096;
fp@673: 			} else if(max_frame <= E1000_RXBUFFER_8192) {
fp@673: 				adapter->rx_buffer_len = E1000_RXBUFFER_8192;
fp@673: 			} else if(max_frame <= E1000_RXBUFFER_16384) {
fp@673: 				adapter->rx_buffer_len = E1000_RXBUFFER_16384;
fp@673: 			}
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	netdev->mtu = new_mtu;
fp@673: 
fp@673: 	if (adapter->ecdev || netif_running(netdev)) {
fp@673: 		e1000_down(adapter);
fp@673: 		e1000_up(adapter);
fp@673: 	}
fp@673: 
fp@673: 	adapter->hw.max_frame_size = max_frame;
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_update_stats - Update the board statistics counters
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: void
fp@673: e1000_update_stats(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_hw *hw = &adapter->hw;
fp@673: 	unsigned long flags = 0;
fp@673: 	uint16_t phy_tmp;
fp@673: 
fp@673: #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
fp@673: 
fp@673: 	if (!adapter->ecdev)
fp@673: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@673: 
fp@673: 	/* these counters are modified from e1000_adjust_tbi_stats,
fp@673: 	 * called from the interrupt context, so they must only
fp@673: 	 * be written while holding adapter->stats_lock
fp@673: 	 */
fp@673: 
fp@673: 	adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
fp@673: 	adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
fp@673: 	adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
fp@673: 	adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
fp@673: 	adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
fp@673: 	adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
fp@673: 	adapter->stats.roc += E1000_READ_REG(hw, ROC);
fp@673: 	adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
fp@673: 	adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
fp@673: 	adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
fp@673: 	adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
fp@673: 	adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
fp@673: 	adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
fp@673: 
fp@673: 	adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
fp@673: 	adapter->stats.mpc += E1000_READ_REG(hw, MPC);
fp@673: 	adapter->stats.scc += E1000_READ_REG(hw, SCC);
fp@673: 	adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
fp@673: 	adapter->stats.mcc += E1000_READ_REG(hw, MCC);
fp@673: 	adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
fp@673: 	adapter->stats.dc += E1000_READ_REG(hw, DC);
fp@673: 	adapter->stats.sec += E1000_READ_REG(hw, SEC);
fp@673: 	adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
fp@673: 	adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
fp@673: 	adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
fp@673: 	adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
fp@673: 	adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
fp@673: 	adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
fp@673: 	adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
fp@673: 	adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
fp@673: 	adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
fp@673: 	adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
fp@673: 	adapter->stats.ruc += E1000_READ_REG(hw, RUC);
fp@673: 	adapter->stats.rfc += E1000_READ_REG(hw, RFC);
fp@673: 	adapter->stats.rjc += E1000_READ_REG(hw, RJC);
fp@673: 	adapter->stats.torl += E1000_READ_REG(hw, TORL);
fp@673: 	adapter->stats.torh += E1000_READ_REG(hw, TORH);
fp@673: 	adapter->stats.totl += E1000_READ_REG(hw, TOTL);
fp@673: 	adapter->stats.toth += E1000_READ_REG(hw, TOTH);
fp@673: 	adapter->stats.tpr += E1000_READ_REG(hw, TPR);
fp@673: 	adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
fp@673: 	adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
fp@673: 	adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
fp@673: 	adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
fp@673: 	adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
fp@673: 	adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
fp@673: 	adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
fp@673: 	adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
fp@673: 
fp@673: 	/* used for adaptive IFS */
fp@673: 
fp@673: 	hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
fp@673: 	adapter->stats.tpt += hw->tx_packet_delta;
fp@673: 	hw->collision_delta = E1000_READ_REG(hw, COLC);
fp@673: 	adapter->stats.colc += hw->collision_delta;
fp@673: 
fp@673: 	if(hw->mac_type >= e1000_82543) {
fp@673: 		adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
fp@673: 		adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
fp@673: 		adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
fp@673: 		adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
fp@673: 		adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
fp@673: 		adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
fp@673: 	}
fp@673: 	if(hw->mac_type > e1000_82547_rev_2) {
fp@673: 		adapter->stats.iac += E1000_READ_REG(hw, IAC);
fp@673: 		adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
fp@673: 		adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
fp@673: 		adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
fp@673: 		adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
fp@673: 		adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
fp@673: 		adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
fp@673: 		adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
fp@673: 		adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
fp@673: 	}
fp@673: 
fp@673: 	/* Fill out the OS statistics structure */
fp@673: 
fp@673: 	adapter->net_stats.rx_packets = adapter->stats.gprc;
fp@673: 	adapter->net_stats.tx_packets = adapter->stats.gptc;
fp@673: 	adapter->net_stats.rx_bytes = adapter->stats.gorcl;
fp@673: 	adapter->net_stats.tx_bytes = adapter->stats.gotcl;
fp@673: 	adapter->net_stats.multicast = adapter->stats.mprc;
fp@673: 	adapter->net_stats.collisions = adapter->stats.colc;
fp@673: 
fp@673: 	/* Rx Errors */
fp@673: 
fp@673: 	adapter->net_stats.rx_errors = adapter->stats.rxerrc +
fp@673: 		adapter->stats.crcerrs + adapter->stats.algnerrc +
fp@673: 		adapter->stats.rlec + adapter->stats.mpc + 
fp@673: 		adapter->stats.cexterr;
fp@673: 	adapter->net_stats.rx_dropped = adapter->stats.mpc;
fp@673: 	adapter->net_stats.rx_length_errors = adapter->stats.rlec;
fp@673: 	adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
fp@673: 	adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
fp@673: 	adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
fp@673: 	adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
fp@673: 
fp@673: 	/* Tx Errors */
fp@673: 
fp@673: 	adapter->net_stats.tx_errors = adapter->stats.ecol +
fp@673: 	                               adapter->stats.latecol;
fp@673: 	adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
fp@673: 	adapter->net_stats.tx_window_errors = adapter->stats.latecol;
fp@673: 	adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
fp@673: 
fp@673: 	/* Tx Dropped needs to be maintained elsewhere */
fp@673: 
fp@673: 	/* Phy Stats */
fp@673: 
fp@673: 	if(hw->media_type == e1000_media_type_copper) {
fp@673: 		if((adapter->link_speed == SPEED_1000) &&
fp@673: 		   (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
fp@673: 			phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
fp@673: 			adapter->phy_stats.idle_errors += phy_tmp;
fp@673: 		}
fp@673: 
fp@673: 		if((hw->mac_type <= e1000_82546) &&
fp@673: 		   (hw->phy_type == e1000_phy_m88) &&
fp@673: 		   !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
fp@673: 			adapter->phy_stats.receive_errors += phy_tmp;
fp@673: 	}
fp@673: 
fp@673: 	if (!adapter->ecdev)
fp@673: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@673: }
fp@673: 
fp@676: void ec_poll(struct net_device *netdev)
fp@676: {
fp@676:     struct e1000_adapter *adapter = netdev_priv(netdev);
fp@676: 
fp@676:     if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) {
fp@676:         e1000_watchdog_task(adapter);
fp@676:         adapter->ec_watchdog_jiffies = jiffies;
fp@676:     }
fp@676: 
fp@676:     e1000_intr(0, netdev, NULL);
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_intr - Interrupt Handler
fp@673:  * @irq: interrupt number
fp@673:  * @data: pointer to a network interface device structure
fp@673:  * @pt_regs: CPU registers structure
fp@673:  **/
fp@673: 
fp@673: static irqreturn_t
fp@673: e1000_intr(int irq, void *data, struct pt_regs *regs)
fp@673: {
fp@673: 	struct net_device *netdev = data;
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	struct e1000_hw *hw = &adapter->hw;
fp@673: 	uint32_t icr = E1000_READ_REG(hw, ICR);
fp@673: 	unsigned int i;
fp@727: #ifdef CONFIG_E1000_NAPI
fp@727: 	int work_done = 0;
fp@673: #endif
fp@673: 
fp@673: 	if(unlikely(!icr))
fp@673: 		return IRQ_NONE;  /* Not our interrupt */
fp@673: 
fp@673: 	if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
fp@673: 		hw->get_link_status = 1;
fp@676: 		if (!adapter->ecdev)
fp@676:             mod_timer(&adapter->watchdog_timer, jiffies);
fp@673: 	}
fp@673: 
fp@673: #ifdef CONFIG_E1000_NAPI
fp@727: 	if (adapter->ecdev) {
fp@727: 		for(i = 0; i < E1000_MAX_INTR; i++)
fp@727: 			if(unlikely(!adapter->clean_rx(adapter, &work_done, 100) &
fp@727: 						!e1000_clean_tx_irq(adapter)))
fp@727: 				break;
fp@727: 	} else {
fp@727: 		if(likely(netif_rx_schedule_prep(netdev))) {
fp@727: 
fp@727: 			/* Disable interrupts and register for poll. The flush 
fp@727: 			   of the posted write is intentionally left out.
fp@727: 			 */
fp@727: 
fp@727: 			atomic_inc(&adapter->irq_sem);
fp@727: 			E1000_WRITE_REG(hw, IMC, ~0);
fp@727: 			__netif_rx_schedule(netdev);
fp@727: 		}
fp@673: 	}
fp@673: #else
fp@673: 	/* Writing IMC and IMS is needed for 82547.
fp@673: 	   Due to Hub Link bus being occupied, an interrupt
fp@673: 	   de-assertion message is not able to be sent.
fp@673: 	   When an interrupt assertion message is generated later,
fp@673: 	   two messages are re-ordered and sent out.
fp@673: 	   That causes APIC to think 82547 is in de-assertion
fp@673: 	   state, while 82547 is in assertion state, resulting
fp@673: 	   in dead lock. Writing IMC forces 82547 into
fp@673: 	   de-assertion state.
fp@673: 	*/
fp@676: 	if(!adapter->ecdev &&
fp@676: 			(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)){
fp@673: 		atomic_inc(&adapter->irq_sem);
fp@673: 		E1000_WRITE_REG(hw, IMC, ~0);
fp@673: 	}
fp@673: 
fp@673: 	for(i = 0; i < E1000_MAX_INTR; i++)
fp@673: 		if(unlikely(!adapter->clean_rx(adapter) &
fp@673: 		   !e1000_clean_tx_irq(adapter)))
fp@673: 			break;
fp@673: 
fp@673: 	if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
fp@673: 		e1000_irq_enable(adapter);
fp@673: #endif
fp@673: 
fp@673: 	return IRQ_HANDLED;
fp@673: }
fp@673: 
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: /**
fp@673:  * e1000_clean - NAPI Rx polling callback
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_clean(struct net_device *netdev, int *budget) // never called for EtherCAT
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	int work_to_do = min(*budget, netdev->quota);
fp@673: 	int tx_cleaned;
fp@673: 	int work_done = 0;
fp@673: 
fp@673: 	tx_cleaned = e1000_clean_tx_irq(adapter);
fp@673: 	adapter->clean_rx(adapter, &work_done, work_to_do);
fp@673: 
fp@673: 	*budget -= work_done;
fp@673: 	netdev->quota -= work_done;
fp@673: 	
fp@673: 	if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
fp@673: 	/* If no Tx and not enough Rx work done, exit the polling mode */
fp@673: 		netif_rx_complete(netdev);
fp@673: 		e1000_irq_enable(adapter);
fp@673: 		return 0;
fp@673: 	}
fp@673: 
fp@673: 	return 1;
fp@673: }
fp@673: 
fp@673: #endif
fp@673: /**
fp@673:  * e1000_clean_tx_irq - Reclaim resources after transmit completes
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static boolean_t
fp@673: e1000_clean_tx_irq(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct e1000_tx_desc *tx_desc, *eop_desc;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	unsigned int i, eop;
fp@673: 	boolean_t cleaned = FALSE;
fp@673: 
fp@673: 	i = tx_ring->next_to_clean;
fp@673: 	eop = tx_ring->buffer_info[i].next_to_watch;
fp@673: 	eop_desc = E1000_TX_DESC(*tx_ring, eop);
fp@673: 
fp@673: 	while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
fp@673: 		/* Premature writeback of Tx descriptors clear (free buffers
fp@673: 		 * and unmap pci_mapping) previous_buffer_info */
fp@673: 		if (likely(adapter->previous_buffer_info.skb != NULL)) {
fp@673: 			e1000_unmap_and_free_tx_resource(adapter,
fp@673: 					&adapter->previous_buffer_info);
fp@673: 		}
fp@673: 
fp@673: 		for(cleaned = FALSE; !cleaned; ) {
fp@673: 			tx_desc = E1000_TX_DESC(*tx_ring, i);
fp@673: 			buffer_info = &tx_ring->buffer_info[i];
fp@673: 			cleaned = (i == eop);
fp@673: 
fp@673: #ifdef NETIF_F_TSO
fp@673: 			if (!(netdev->features & NETIF_F_TSO)) {
fp@673: #endif
fp@673: 				e1000_unmap_and_free_tx_resource(adapter,
fp@673: 				                                 buffer_info);
fp@673: #ifdef NETIF_F_TSO
fp@673: 			} else {
fp@673: 				if (cleaned) {
fp@673: 					memcpy(&adapter->previous_buffer_info,
fp@673: 					       buffer_info,
fp@673: 					       sizeof(struct e1000_buffer));
fp@673: 					memset(buffer_info, 0,
fp@673: 					       sizeof(struct e1000_buffer));
fp@673: 				} else {
fp@673: 					e1000_unmap_and_free_tx_resource(
fp@673: 					    adapter, buffer_info);
fp@673: 				}
fp@673: 			}
fp@673: #endif
fp@673: 
fp@673: 			tx_desc->buffer_addr = 0;
fp@673: 			tx_desc->lower.data = 0;
fp@673: 			tx_desc->upper.data = 0;
fp@673: 
fp@673: 			if(unlikely(++i == tx_ring->count)) i = 0;
fp@673: 		}
fp@673: 		
fp@673: 		eop = tx_ring->buffer_info[i].next_to_watch;
fp@673: 		eop_desc = E1000_TX_DESC(*tx_ring, eop);
fp@673: 	}
fp@673: 
fp@673: 	tx_ring->next_to_clean = i;
fp@673: 
fp@673: 	if (!adapter->ecdev) {
fp@673: 		spin_lock(&adapter->tx_lock);
fp@673: 
fp@673: 		if(unlikely(cleaned && netif_queue_stopped(netdev) &&
fp@673: 					netif_carrier_ok(netdev)))
fp@673: 			netif_wake_queue(netdev);
fp@673: 
fp@673: 		spin_unlock(&adapter->tx_lock);
fp@673: 	}
fp@673: 
fp@676: 	if(!adapter->ecdev && adapter->detect_tx_hung) {
fp@673: 
fp@673: 		/* Detect a transmit hang in hardware, this serializes the
fp@673: 		 * check with the clearing of time_stamp and movement of i */
fp@673: 		adapter->detect_tx_hung = FALSE;
fp@673: 		if (tx_ring->buffer_info[i].dma &&
fp@673: 		    time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
fp@673: 		    && !(E1000_READ_REG(&adapter->hw, STATUS) &
fp@673: 			E1000_STATUS_TXOFF)) {
fp@673: 
fp@673: 			/* detected Tx unit hang */
fp@673: 			i = tx_ring->next_to_clean;
fp@673: 			eop = tx_ring->buffer_info[i].next_to_watch;
fp@673: 			eop_desc = E1000_TX_DESC(*tx_ring, eop);
fp@673: 			DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
fp@673: 					"  TDH                  <%x>\n"
fp@673: 					"  TDT                  <%x>\n"
fp@673: 					"  next_to_use          <%x>\n"
fp@673: 					"  next_to_clean        <%x>\n"
fp@673: 					"buffer_info[next_to_clean]\n"
fp@673: 					"  dma                  <%zx>\n"
fp@673: 					"  time_stamp           <%lx>\n"
fp@673: 					"  next_to_watch        <%x>\n"
fp@673: 					"  jiffies              <%lx>\n"
fp@673: 					"  next_to_watch.status <%x>\n",
fp@673: 				E1000_READ_REG(&adapter->hw, TDH),
fp@673: 				E1000_READ_REG(&adapter->hw, TDT),
fp@673: 				tx_ring->next_to_use,
fp@673: 				i,
fp@673: 				tx_ring->buffer_info[i].dma,
fp@673: 				tx_ring->buffer_info[i].time_stamp,
fp@673: 				eop,
fp@673: 				jiffies,
fp@673: 				eop_desc->upper.fields.status);
fp@676: 			netif_stop_queue(netdev);
fp@673: 		}
fp@673: 	}
fp@673: #ifdef NETIF_F_TSO
fp@673: 
fp@673: 	if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
fp@673: 	    time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
fp@673: 		e1000_unmap_and_free_tx_resource(
fp@673: 		    adapter, &adapter->previous_buffer_info);
fp@673: 
fp@673: #endif
fp@673: 	return cleaned;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_rx_checksum - Receive Checksum Offload for 82543
fp@673:  * @adapter:     board private structure
fp@673:  * @status_err:  receive descriptor status and error fields
fp@673:  * @csum:        receive descriptor csum field
fp@673:  * @sk_buff:     socket buffer with received data
fp@673:  **/
fp@673: 
fp@673: static inline void
fp@673: e1000_rx_checksum(struct e1000_adapter *adapter,
fp@673: 		  uint32_t status_err, uint32_t csum,
fp@673: 		  struct sk_buff *skb)
fp@673: {
fp@673: 	uint16_t status = (uint16_t)status_err;
fp@673: 	uint8_t errors = (uint8_t)(status_err >> 24);
fp@673: 	skb->ip_summed = CHECKSUM_NONE;
fp@673: 
fp@673: 	/* 82543 or newer only */
fp@673: 	if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
fp@673: 	/* Ignore Checksum bit is set */
fp@673: 	if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
fp@673: 	/* TCP/UDP checksum error bit is set */
fp@673: 	if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
fp@673: 		/* let the stack verify checksum errors */
fp@673: 		adapter->hw_csum_err++;
fp@673: 		return;
fp@673: 	}
fp@673: 	/* TCP/UDP Checksum has not been calculated */
fp@673: 	if(adapter->hw.mac_type <= e1000_82547_rev_2) {
fp@673: 		if(!(status & E1000_RXD_STAT_TCPCS))
fp@673: 			return;
fp@673: 	} else {
fp@673: 		if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
fp@673: 			return;
fp@673: 	}
fp@673: 	/* It must be a TCP or UDP packet with a valid checksum */
fp@673: 	if (likely(status & E1000_RXD_STAT_TCPCS)) {
fp@673: 		/* TCP checksum is good */
fp@673: 		skb->ip_summed = CHECKSUM_UNNECESSARY;
fp@673: 	} else if (adapter->hw.mac_type > e1000_82547_rev_2) {
fp@673: 		/* IP fragment with UDP payload */
fp@673: 		/* Hardware complements the payload checksum, so we undo it
fp@673: 		 * and then put the value in host order for further stack use.
fp@673: 		 */
fp@673: 		csum = ntohl(csum ^ 0xFFFF);
fp@673: 		skb->csum = csum;
fp@673: 		skb->ip_summed = CHECKSUM_HW;
fp@673: 	}
fp@673: 	adapter->hw_csum_good++;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_clean_rx_irq - Send received data up the network stack; legacy
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static boolean_t
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done,
fp@673:                    int work_to_do)
fp@673: #else
fp@673: e1000_clean_rx_irq(struct e1000_adapter *adapter)
fp@673: #endif
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	struct e1000_rx_desc *rx_desc;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	struct sk_buff *skb;
fp@673: 	unsigned long flags;
fp@673: 	uint32_t length;
fp@673: 	uint8_t last_byte;
fp@673: 	unsigned int i;
fp@673: 	boolean_t cleaned = FALSE;
fp@673: 
fp@673: 	i = rx_ring->next_to_clean;
fp@673: 	rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@673: 
fp@673: 	while(rx_desc->status & E1000_RXD_STAT_DD) {
fp@673: 		buffer_info = &rx_ring->buffer_info[i];
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: 		if(*work_done >= work_to_do)
fp@673: 			break;
fp@673: 		(*work_done)++;
fp@673: #endif
fp@673: 		cleaned = TRUE;
fp@673: 
fp@673: 		pci_unmap_single(pdev,
fp@673: 		                 buffer_info->dma,
fp@673: 		                 buffer_info->length,
fp@673: 		                 PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 		skb = buffer_info->skb;
fp@673: 		length = le16_to_cpu(rx_desc->length);
fp@673: 
fp@673: 		if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
fp@673: 			/* All receives must fit into a single buffer */
fp@673: 			E1000_DBG("%s: Receive packet consumed multiple"
fp@673: 				  " buffers\n", netdev->name);
fp@673: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@673: 			goto next_desc;
fp@673: 		}
fp@673: 
fp@673: 		if(!adapter->ecdev && unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
fp@673: 			last_byte = *(skb->data + length - 1);
fp@673: 			if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
fp@673: 			              rx_desc->errors, length, last_byte)) {
fp@673: 				spin_lock_irqsave(&adapter->stats_lock, flags);
fp@673: 				e1000_tbi_adjust_stats(&adapter->hw,
fp@673: 				                       &adapter->stats,
fp@673: 				                       length, skb->data);
fp@673: 				spin_unlock_irqrestore(&adapter->stats_lock,
fp@673: 				                       flags);
fp@673: 				length--;
fp@673: 			} else {
fp@673: 				dev_kfree_skb_irq(skb);
fp@673: 				goto next_desc;
fp@673: 			}
fp@673: 		}
fp@673: 
fp@673: 		/* Good Receive */
fp@673: 		skb_put(skb, length - ETHERNET_FCS_SIZE);
fp@673: 
fp@673: 		/* Receive Checksum Offload */
fp@673: 		e1000_rx_checksum(adapter,
fp@673: 				  (uint32_t)(rx_desc->status) |
fp@673: 				  ((uint32_t)(rx_desc->errors) << 24),
fp@673: 				  rx_desc->csum, skb);
fp@673: 		if (adapter->ecdev) {
fp@673: 			ecdev_receive(adapter->ecdev, skb->data, length);
fp@1152: 
fp@1152: 			// No need to detect link status as
fp@1152: 			// long as frames are received: Reset watchdog.
fp@1152: 			adapter->ec_watchdog_jiffies = jiffies;
fp@1152: 
fp@676: 			skb_trim(skb, 0);
fp@676: 
fp@676: 			if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@676: 				/* Force memory writes to complete before letting h/w
fp@676: 				 * know there are new descriptors to fetch.  (Only
fp@676: 				 * applicable for weak-ordered memory model archs,
fp@676: 				 * such as IA-64). */
fp@676: 				wmb();
fp@676: 				E1000_WRITE_REG(&adapter->hw, RDT, i);
fp@676: 			}
fp@673: 		} else {
fp@673: 			skb->protocol = eth_type_trans(skb, netdev);
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: 			if(unlikely(adapter->vlgrp &&
fp@673: 						(rx_desc->status & E1000_RXD_STAT_VP))) {
fp@673: 				vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
fp@673: 						le16_to_cpu(rx_desc->special) &
fp@673: 						E1000_RXD_SPC_VLAN_MASK);
fp@673: 			} else {
fp@673: 				netif_receive_skb(skb);
fp@673: 			}
fp@673: #else /* CONFIG_E1000_NAPI */
fp@673: 			if(unlikely(adapter->vlgrp &&
fp@673: 						(rx_desc->status & E1000_RXD_STAT_VP))) {
fp@673: 				vlan_hwaccel_rx(skb, adapter->vlgrp,
fp@673: 						le16_to_cpu(rx_desc->special) &
fp@673: 						E1000_RXD_SPC_VLAN_MASK);
fp@673: 			} else {
fp@673: 				netif_rx(skb);
fp@673: 			}
fp@673: #endif /* CONFIG_E1000_NAPI */
fp@673: 		}
fp@673: 		netdev->last_rx = jiffies;
fp@673: 
fp@673: next_desc:
fp@673: 		rx_desc->status = 0;
fp@676: 		if (!adapter->ecdev) buffer_info->skb = NULL;
fp@673: 		if(unlikely(++i == rx_ring->count)) i = 0;
fp@673: 
fp@673: 		rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@673: 	}
fp@673: 	rx_ring->next_to_clean = i;
fp@676: 	if (adapter->ecdev) {
fp@676: 		rx_ring->next_to_use = i;
fp@676: 	} else {
fp@676: 		adapter->alloc_rx_buf(adapter);
fp@676: 	}
fp@673: 
fp@673: 	return cleaned;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
fp@673:  * @adapter: board private structure
fp@673:  **/
fp@673: 
fp@673: static boolean_t
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done,
fp@673:                       int work_to_do)
fp@673: #else
fp@673: e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
fp@673: #endif
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	union e1000_rx_desc_packet_split *rx_desc;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	struct e1000_ps_page *ps_page;
fp@673: 	struct e1000_ps_page_dma *ps_page_dma;
fp@673: 	struct sk_buff *skb;
fp@673: 	unsigned int i, j;
fp@673: 	uint32_t length, staterr;
fp@673: 	boolean_t cleaned = FALSE;
fp@673: 
fp@673: 	i = rx_ring->next_to_clean;
fp@673: 	rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
fp@673: 	staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
fp@673: 
fp@673: 	while(staterr & E1000_RXD_STAT_DD) {
fp@673: 		buffer_info = &rx_ring->buffer_info[i];
fp@673: 		ps_page = &rx_ring->ps_page[i];
fp@673: 		ps_page_dma = &rx_ring->ps_page_dma[i];
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: 		if(unlikely(*work_done >= work_to_do))
fp@673: 			break;
fp@673: 		(*work_done)++;
fp@673: #endif
fp@673: 		cleaned = TRUE;
fp@673: 		pci_unmap_single(pdev, buffer_info->dma,
fp@673: 				 buffer_info->length,
fp@673: 				 PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 		skb = buffer_info->skb;
fp@673: 
fp@673: 		if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
fp@673: 			E1000_DBG("%s: Packet Split buffers didn't pick up"
fp@673: 				  " the full packet\n", netdev->name);
fp@673: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@673: 			goto next_desc;
fp@673: 		}
fp@673: 
fp@673: 		if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
fp@673: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@673: 			goto next_desc;
fp@673: 		}
fp@673: 
fp@673: 		length = le16_to_cpu(rx_desc->wb.middle.length0);
fp@673: 
fp@673: 		if(unlikely(!length)) {
fp@673: 			E1000_DBG("%s: Last part of the packet spanning"
fp@673: 				  " multiple descriptors\n", netdev->name);
fp@673: 			if (!adapter->ecdev) dev_kfree_skb_irq(skb);
fp@673: 			goto next_desc;
fp@673: 		}
fp@673: 
fp@673: 		/* Good Receive */
fp@673: 		skb_put(skb, length);
fp@673: 
fp@673: 		for(j = 0; j < PS_PAGE_BUFFERS; j++) {
fp@673: 			if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
fp@673: 				break;
fp@673: 
fp@673: 			pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
fp@673: 					PAGE_SIZE, PCI_DMA_FROMDEVICE);
fp@673: 			ps_page_dma->ps_page_dma[j] = 0;
fp@673: 			skb_shinfo(skb)->frags[j].page =
fp@673: 				ps_page->ps_page[j];
fp@673: 			ps_page->ps_page[j] = NULL;
fp@673: 			skb_shinfo(skb)->frags[j].page_offset = 0;
fp@673: 			skb_shinfo(skb)->frags[j].size = length;
fp@673: 			skb_shinfo(skb)->nr_frags++;
fp@673: 			skb->len += length;
fp@673: 			skb->data_len += length;
fp@673: 		}
fp@673: 
fp@673: 		e1000_rx_checksum(adapter, staterr,
fp@673: 				  rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
fp@673: 
fp@673: #ifdef HAVE_RX_ZERO_COPY
fp@673: 		if(likely(rx_desc->wb.upper.header_status &
fp@673: 			  E1000_RXDPS_HDRSTAT_HDRSP))
fp@673: 			skb_shinfo(skb)->zero_copy = TRUE;
fp@673: #endif
fp@673: 		if (adapter->ecdev) {
fp@673: 			ecdev_receive(adapter->ecdev, skb->data, length);
fp@676: 			skb_trim(skb, 0);
fp@676: 
fp@676: 			if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@676: 				/* Force memory writes to complete before letting h/w
fp@676: 				 * know there are new descriptors to fetch.  (Only
fp@676: 				 * applicable for weak-ordered memory model archs,
fp@676: 				 * such as IA-64). */
fp@676: 				wmb();
fp@676: 				/* Hardware increments by 16 bytes, but packet split
fp@676: 				 * descriptors are 32 bytes...so we increment tail
fp@676: 				 * twice as much.
fp@676: 				 */
fp@676: 				E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
fp@676: 			}
fp@673: 		} else {
fp@673: 			skb->protocol = eth_type_trans(skb, netdev);
fp@673: #ifdef CONFIG_E1000_NAPI
fp@673: 			if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
fp@673: 				vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
fp@673: 						le16_to_cpu(rx_desc->wb.middle.vlan) &
fp@673: 						E1000_RXD_SPC_VLAN_MASK);
fp@673: 			} else {
fp@673: 				netif_receive_skb(skb);
fp@673: 			}
fp@673: #else /* CONFIG_E1000_NAPI */
fp@673: 			if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
fp@673: 				vlan_hwaccel_rx(skb, adapter->vlgrp,
fp@673: 						le16_to_cpu(rx_desc->wb.middle.vlan) &
fp@673: 						E1000_RXD_SPC_VLAN_MASK);
fp@673: 			} else {
fp@673: 				netif_rx(skb);
fp@673: 			}
fp@673: #endif /* CONFIG_E1000_NAPI */
fp@673: 		}
fp@673: 		netdev->last_rx = jiffies;
fp@673: 
fp@673: next_desc:
fp@673: 		rx_desc->wb.middle.status_error &= ~0xFF;
fp@673: 		if (!adapter->ecdev) buffer_info->skb = NULL;
fp@673: 		if(unlikely(++i == rx_ring->count)) i = 0;
fp@673: 
fp@673: 		rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
fp@673: 		staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
fp@673: 	}
fp@673: 	rx_ring->next_to_clean = i;
fp@676: 	if (adapter->ecdev) { 
fp@676: 		rx_ring->next_to_use = i;
fp@676: 	} else {
fp@676: 		adapter->alloc_rx_buf(adapter);
fp@676: 	}
fp@673: 
fp@673: 	return cleaned;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
fp@673:  * @adapter: address of board private structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	struct e1000_rx_desc *rx_desc;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	struct sk_buff *skb;
fp@673: 	unsigned int i;
fp@673: 	unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
fp@673: 
fp@673: 	i = rx_ring->next_to_use;
fp@673: 	buffer_info = &rx_ring->buffer_info[i];
fp@673: 
fp@673: 	while(!buffer_info->skb) {
fp@673: 		skb = dev_alloc_skb(bufsz);
fp@673: 
fp@673: 		if(unlikely(!skb)) {
fp@673: 			/* Better luck next round */
fp@673: 			break;
fp@673: 		}
fp@673: 
fp@673: 		/* Fix for errata 23, can't cross 64kB boundary */
fp@673: 		if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
fp@673: 			struct sk_buff *oldskb = skb;
fp@673: 			DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
fp@673: 					     "at %p\n", bufsz, skb->data);
fp@673: 			/* Try again, without freeing the previous */
fp@673: 			skb = dev_alloc_skb(bufsz);
fp@673: 			/* Failed allocation, critical failure */
fp@673: 			if (!skb) {
fp@673: 				dev_kfree_skb(oldskb);
fp@673: 				break;
fp@673: 			}
fp@673: 
fp@673: 			if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
fp@673: 				/* give up */
fp@673: 				dev_kfree_skb(skb);
fp@673: 				dev_kfree_skb(oldskb);
fp@673: 				break; /* while !buffer_info->skb */
fp@673: 			} else {
fp@673: 				/* Use new allocation */
fp@673: 				dev_kfree_skb(oldskb);
fp@673: 			}
fp@673: 		}
fp@673: 		/* Make buffer alignment 2 beyond a 16 byte boundary
fp@673: 		 * this will result in a 16 byte aligned IP header after
fp@673: 		 * the 14 byte MAC header is removed
fp@673: 		 */
fp@673: 		skb_reserve(skb, NET_IP_ALIGN);
fp@673: 
fp@673: 		skb->dev = netdev;
fp@673: 
fp@673: 		buffer_info->skb = skb;
fp@673: 		buffer_info->length = adapter->rx_buffer_len;
fp@673: 		buffer_info->dma = pci_map_single(pdev,
fp@673: 						  skb->data,
fp@673: 						  adapter->rx_buffer_len,
fp@673: 						  PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 		/* Fix for errata 23, can't cross 64kB boundary */
fp@673: 		if (!e1000_check_64k_bound(adapter,
fp@673: 					(void *)(unsigned long)buffer_info->dma,
fp@673: 					adapter->rx_buffer_len)) {
fp@673: 			DPRINTK(RX_ERR, ERR,
fp@673: 				"dma align check failed: %u bytes at %p\n",
fp@673: 				adapter->rx_buffer_len,
fp@673: 				(void *)(unsigned long)buffer_info->dma);
fp@673: 			dev_kfree_skb(skb);
fp@673: 			buffer_info->skb = NULL;
fp@673: 
fp@673: 			pci_unmap_single(pdev, buffer_info->dma,
fp@673: 					 adapter->rx_buffer_len,
fp@673: 					 PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 			break; /* while !buffer_info->skb */
fp@673: 		}
fp@673: 		rx_desc = E1000_RX_DESC(*rx_ring, i);
fp@673: 		rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
fp@673: 
fp@673: 		if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@673: 			/* Force memory writes to complete before letting h/w
fp@673: 			 * know there are new descriptors to fetch.  (Only
fp@673: 			 * applicable for weak-ordered memory model archs,
fp@673: 			 * such as IA-64). */
fp@673: 			wmb();
fp@673: 			E1000_WRITE_REG(&adapter->hw, RDT, i);
fp@673: 		}
fp@673: 
fp@673: 		if(unlikely(++i == rx_ring->count)) i = 0;
fp@673: 		buffer_info = &rx_ring->buffer_info[i];
fp@673: 	}
fp@673: 
fp@673: 	rx_ring->next_to_use = i;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
fp@673:  * @adapter: address of board private structure
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
fp@673: 	struct net_device *netdev = adapter->netdev;
fp@673: 	struct pci_dev *pdev = adapter->pdev;
fp@673: 	union e1000_rx_desc_packet_split *rx_desc;
fp@673: 	struct e1000_buffer *buffer_info;
fp@673: 	struct e1000_ps_page *ps_page;
fp@673: 	struct e1000_ps_page_dma *ps_page_dma;
fp@673: 	struct sk_buff *skb;
fp@673: 	unsigned int i, j;
fp@673: 
fp@673: 	i = rx_ring->next_to_use;
fp@673: 	buffer_info = &rx_ring->buffer_info[i];
fp@673: 	ps_page = &rx_ring->ps_page[i];
fp@673: 	ps_page_dma = &rx_ring->ps_page_dma[i];
fp@673: 
fp@673: 	while(!buffer_info->skb) {
fp@673: 		rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
fp@673: 
fp@673: 		for(j = 0; j < PS_PAGE_BUFFERS; j++) {
fp@673: 			if(unlikely(!ps_page->ps_page[j])) {
fp@673: 				ps_page->ps_page[j] =
fp@673: 					alloc_page(GFP_ATOMIC);
fp@673: 				if(unlikely(!ps_page->ps_page[j]))
fp@673: 					goto no_buffers;
fp@673: 				ps_page_dma->ps_page_dma[j] =
fp@673: 					pci_map_page(pdev,
fp@673: 						     ps_page->ps_page[j],
fp@673: 						     0, PAGE_SIZE,
fp@673: 						     PCI_DMA_FROMDEVICE);
fp@673: 			}
fp@673: 			/* Refresh the desc even if buffer_addrs didn't
fp@673: 			 * change because each write-back erases this info.
fp@673: 			 */
fp@673: 			rx_desc->read.buffer_addr[j+1] =
fp@673: 				cpu_to_le64(ps_page_dma->ps_page_dma[j]);
fp@673: 		}
fp@673: 
fp@673: 		skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
fp@673: 
fp@673: 		if(unlikely(!skb))
fp@673: 			break;
fp@673: 
fp@673: 		/* Make buffer alignment 2 beyond a 16 byte boundary
fp@673: 		 * this will result in a 16 byte aligned IP header after
fp@673: 		 * the 14 byte MAC header is removed
fp@673: 		 */
fp@673: 		skb_reserve(skb, NET_IP_ALIGN);
fp@673: 
fp@673: 		skb->dev = netdev;
fp@673: 
fp@673: 		buffer_info->skb = skb;
fp@673: 		buffer_info->length = adapter->rx_ps_bsize0;
fp@673: 		buffer_info->dma = pci_map_single(pdev, skb->data,
fp@673: 						  adapter->rx_ps_bsize0,
fp@673: 						  PCI_DMA_FROMDEVICE);
fp@673: 
fp@673: 		rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
fp@673: 
fp@673: 		if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
fp@673: 			/* Force memory writes to complete before letting h/w
fp@673: 			 * know there are new descriptors to fetch.  (Only
fp@673: 			 * applicable for weak-ordered memory model archs,
fp@673: 			 * such as IA-64). */
fp@673: 			wmb();
fp@673: 			/* Hardware increments by 16 bytes, but packet split
fp@673: 			 * descriptors are 32 bytes...so we increment tail
fp@673: 			 * twice as much.
fp@673: 			 */
fp@673: 			E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
fp@673: 		}
fp@673: 
fp@673: 		if(unlikely(++i == rx_ring->count)) i = 0;
fp@673: 		buffer_info = &rx_ring->buffer_info[i];
fp@673: 		ps_page = &rx_ring->ps_page[i];
fp@673: 		ps_page_dma = &rx_ring->ps_page_dma[i];
fp@673: 	}
fp@673: 
fp@673: no_buffers:
fp@673: 	rx_ring->next_to_use = i;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
fp@673:  * @adapter:
fp@673:  **/
fp@673: 
fp@673: static void
fp@673: e1000_smartspeed(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	uint16_t phy_status;
fp@673: 	uint16_t phy_ctrl;
fp@673: 
fp@673: 	if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
fp@673: 	   !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
fp@673: 		return;
fp@673: 
fp@673: 	if(adapter->smartspeed == 0) {
fp@673: 		/* If Master/Slave config fault is asserted twice,
fp@673: 		 * we assume back-to-back */
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
fp@673: 		if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
fp@673: 		if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
fp@673: 		if(phy_ctrl & CR_1000T_MS_ENABLE) {
fp@673: 			phy_ctrl &= ~CR_1000T_MS_ENABLE;
fp@673: 			e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
fp@673: 					    phy_ctrl);
fp@673: 			adapter->smartspeed++;
fp@673: 			if(!e1000_phy_setup_autoneg(&adapter->hw) &&
fp@673: 			   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
fp@673: 				   	       &phy_ctrl)) {
fp@673: 				phy_ctrl |= (MII_CR_AUTO_NEG_EN |
fp@673: 					     MII_CR_RESTART_AUTO_NEG);
fp@673: 				e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
fp@673: 						    phy_ctrl);
fp@673: 			}
fp@673: 		}
fp@673: 		return;
fp@673: 	} else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
fp@673: 		/* If still no link, perhaps using 2/3 pair cable */
fp@673: 		e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
fp@673: 		phy_ctrl |= CR_1000T_MS_ENABLE;
fp@673: 		e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
fp@673: 		if(!e1000_phy_setup_autoneg(&adapter->hw) &&
fp@673: 		   !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
fp@673: 			phy_ctrl |= (MII_CR_AUTO_NEG_EN |
fp@673: 				     MII_CR_RESTART_AUTO_NEG);
fp@673: 			e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
fp@673: 		}
fp@673: 	}
fp@673: 	/* Restart process after E1000_SMARTSPEED_MAX iterations */
fp@673: 	if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
fp@673: 		adapter->smartspeed = 0;
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_ioctl -
fp@673:  * @netdev:
fp@673:  * @ifreq:
fp@673:  * @cmd:
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@673: {
fp@673: 	switch (cmd) {
fp@673: 	case SIOCGMIIPHY:
fp@673: 	case SIOCGMIIREG:
fp@673: 	case SIOCSMIIREG:
fp@673: 		return e1000_mii_ioctl(netdev, ifr, cmd);
fp@673: 	default:
fp@673: 		return -EOPNOTSUPP;
fp@673: 	}
fp@673: }
fp@673: 
fp@673: /**
fp@673:  * e1000_mii_ioctl -
fp@673:  * @netdev:
fp@673:  * @ifreq:
fp@673:  * @cmd:
fp@673:  **/
fp@673: 
fp@673: static int
fp@673: e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	struct mii_ioctl_data *data = if_mii(ifr);
fp@673: 	int retval;
fp@673: 	uint16_t mii_reg;
fp@673: 	uint16_t spddplx;
fp@673: 	unsigned long flags;
fp@673: 
fp@673: 	if(adapter->hw.media_type != e1000_media_type_copper)
fp@673: 		return -EOPNOTSUPP;
fp@673: 
fp@673: 	switch (cmd) {
fp@673: 	case SIOCGMIIPHY:
fp@673: 		data->phy_id = adapter->hw.phy_addr;
fp@673: 		break;
fp@673: 	case SIOCGMIIREG:
fp@676: 		if(adapter->ecdev || !capable(CAP_NET_ADMIN))
fp@673: 			return -EPERM;
fp@673: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@673: 		if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
fp@673: 				   &data->val_out)) {
fp@673: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@673: 			return -EIO;
fp@673: 		}
fp@673: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@673: 		break;
fp@673: 	case SIOCSMIIREG:
fp@676: 		if(adapter->ecdev || !capable(CAP_NET_ADMIN))
fp@673: 			return -EPERM;
fp@673: 		if(data->reg_num & ~(0x1F))
fp@673: 			return -EFAULT;
fp@673: 		mii_reg = data->val_in;
fp@673: 		spin_lock_irqsave(&adapter->stats_lock, flags);
fp@673: 		if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
fp@673: 					mii_reg)) {
fp@673: 			spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@673: 			return -EIO;
fp@673: 		}
fp@673: 		if(adapter->hw.phy_type == e1000_phy_m88) {
fp@673: 			switch (data->reg_num) {
fp@673: 			case PHY_CTRL:
fp@673: 				if(mii_reg & MII_CR_POWER_DOWN)
fp@673: 					break;
fp@673: 				if(mii_reg & MII_CR_AUTO_NEG_EN) {
fp@673: 					adapter->hw.autoneg = 1;
fp@673: 					adapter->hw.autoneg_advertised = 0x2F;
fp@673: 				} else {
fp@673: 					if (mii_reg & 0x40)
fp@673: 						spddplx = SPEED_1000;
fp@673: 					else if (mii_reg & 0x2000)
fp@673: 						spddplx = SPEED_100;
fp@673: 					else
fp@673: 						spddplx = SPEED_10;
fp@673: 					spddplx += (mii_reg & 0x100)
fp@673: 						   ? FULL_DUPLEX :
fp@673: 						   HALF_DUPLEX;
fp@673: 					retval = e1000_set_spd_dplx(adapter,
fp@673: 								    spddplx);
fp@673: 					if(retval) {
fp@673: 						spin_unlock_irqrestore(
fp@673: 							&adapter->stats_lock, 
fp@673: 							flags);
fp@673: 						return retval;
fp@673: 					}
fp@673: 				}
fp@673: 				if(adapter->ecdev || netif_running(adapter->netdev)) {
fp@673: 					e1000_down(adapter);
fp@673: 					e1000_up(adapter);
fp@673: 				} else
fp@673: 					e1000_reset(adapter);
fp@673: 				break;
fp@673: 			case M88E1000_PHY_SPEC_CTRL:
fp@673: 			case M88E1000_EXT_PHY_SPEC_CTRL:
fp@673: 				if(e1000_phy_reset(&adapter->hw)) {
fp@673: 					spin_unlock_irqrestore(
fp@673: 						&adapter->stats_lock, flags);
fp@673: 					return -EIO;
fp@673: 				}
fp@673: 				break;
fp@673: 			}
fp@673: 		} else {
fp@673: 			switch (data->reg_num) {
fp@673: 			case PHY_CTRL:
fp@673: 				if(mii_reg & MII_CR_POWER_DOWN)
fp@673: 					break;
fp@673: 				if(adapter->ecdev || netif_running(adapter->netdev)) {
fp@673: 					e1000_down(adapter);
fp@673: 					e1000_up(adapter);
fp@673: 				} else
fp@673: 					e1000_reset(adapter);
fp@673: 				break;
fp@673: 			}
fp@673: 		}
fp@673: 		spin_unlock_irqrestore(&adapter->stats_lock, flags);
fp@673: 		break;
fp@673: 	default:
fp@673: 		return -EOPNOTSUPP;
fp@673: 	}
fp@673: 	return E1000_SUCCESS;
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_pci_set_mwi(struct e1000_hw *hw)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = hw->back;
fp@673: 	int ret_val = pci_set_mwi(adapter->pdev);
fp@673: 
fp@673: 	if(ret_val)
fp@673: 		DPRINTK(PROBE, ERR, "Error in setting MWI\n");
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_pci_clear_mwi(struct e1000_hw *hw)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = hw->back;
fp@673: 
fp@673: 	pci_clear_mwi(adapter->pdev);
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = hw->back;
fp@673: 
fp@673: 	pci_read_config_word(adapter->pdev, reg, value);
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = hw->back;
fp@673: 
fp@673: 	pci_write_config_word(adapter->pdev, reg, *value);
fp@673: }
fp@673: 
fp@673: uint32_t
fp@673: e1000_io_read(struct e1000_hw *hw, unsigned long port)
fp@673: {
fp@673: 	return inl(port);
fp@673: }
fp@673: 
fp@673: void
fp@673: e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
fp@673: {
fp@673: 	outl(value, port);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t ctrl, rctl;
fp@673: 
fp@673: 	e1000_irq_disable(adapter);
fp@673: 	adapter->vlgrp = grp;
fp@673: 
fp@673: 	if(grp) {
fp@673: 		/* enable VLAN tag insert/strip */
fp@673: 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@673: 		ctrl |= E1000_CTRL_VME;
fp@673: 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@673: 
fp@673: 		/* enable VLAN receive filtering */
fp@673: 		rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 		rctl |= E1000_RCTL_VFE;
fp@673: 		rctl &= ~E1000_RCTL_CFIEN;
fp@673: 		E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: 		e1000_update_mng_vlan(adapter);
fp@673: 	} else {
fp@673: 		/* disable VLAN tag insert/strip */
fp@673: 		ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@673: 		ctrl &= ~E1000_CTRL_VME;
fp@673: 		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@673: 
fp@673: 		/* disable VLAN filtering */
fp@673: 		rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 		rctl &= ~E1000_RCTL_VFE;
fp@673: 		E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: 		if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
fp@673: 			e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
fp@673: 			adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	e1000_irq_enable(adapter);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t vfta, index;
fp@673: 	if((adapter->hw.mng_cookie.status &
fp@673: 		E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
fp@673: 		(vid == adapter->mng_vlan_id))
fp@673: 		return;
fp@673: 	/* add VID to filter table */
fp@673: 	index = (vid >> 5) & 0x7F;
fp@673: 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
fp@673: 	vfta |= (1 << (vid & 0x1F));
fp@673: 	e1000_write_vfta(&adapter->hw, index, vfta);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t vfta, index;
fp@673: 
fp@673: 	e1000_irq_disable(adapter);
fp@673: 
fp@673: 	if(adapter->vlgrp)
fp@673: 		adapter->vlgrp->vlan_devices[vid] = NULL;
fp@673: 
fp@673: 	e1000_irq_enable(adapter);
fp@673: 
fp@673: 	if((adapter->hw.mng_cookie.status &
fp@673: 		E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
fp@673: 		(vid == adapter->mng_vlan_id))
fp@673: 		return;
fp@673: 	/* remove VID from filter table */
fp@673: 	index = (vid >> 5) & 0x7F;
fp@673: 	vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
fp@673: 	vfta &= ~(1 << (vid & 0x1F));
fp@673: 	e1000_write_vfta(&adapter->hw, index, vfta);
fp@673: }
fp@673: 
fp@673: static void
fp@673: e1000_restore_vlan(struct e1000_adapter *adapter)
fp@673: {
fp@673: 	e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
fp@673: 
fp@673: 	if(adapter->vlgrp) {
fp@673: 		uint16_t vid;
fp@673: 		for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
fp@673: 			if(!adapter->vlgrp->vlan_devices[vid])
fp@673: 				continue;
fp@673: 			e1000_vlan_rx_add_vid(adapter->netdev, vid);
fp@673: 		}
fp@673: 	}
fp@673: }
fp@673: 
fp@673: int
fp@673: e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
fp@673: {
fp@673: 	adapter->hw.autoneg = 0;
fp@673: 
fp@673: 	/* Fiber NICs only allow 1000 gbps Full duplex */
fp@673: 	if((adapter->hw.media_type == e1000_media_type_fiber) &&
fp@673: 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
fp@673: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
fp@673: 		return -EINVAL;
fp@673: 	}
fp@673: 
fp@673: 	switch(spddplx) {
fp@673: 	case SPEED_10 + DUPLEX_HALF:
fp@673: 		adapter->hw.forced_speed_duplex = e1000_10_half;
fp@673: 		break;
fp@673: 	case SPEED_10 + DUPLEX_FULL:
fp@673: 		adapter->hw.forced_speed_duplex = e1000_10_full;
fp@673: 		break;
fp@673: 	case SPEED_100 + DUPLEX_HALF:
fp@673: 		adapter->hw.forced_speed_duplex = e1000_100_half;
fp@673: 		break;
fp@673: 	case SPEED_100 + DUPLEX_FULL:
fp@673: 		adapter->hw.forced_speed_duplex = e1000_100_full;
fp@673: 		break;
fp@673: 	case SPEED_1000 + DUPLEX_FULL:
fp@673: 		adapter->hw.autoneg = 1;
fp@673: 		adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
fp@673: 		break;
fp@673: 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
fp@673: 	default:
fp@673: 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
fp@673: 		return -EINVAL;
fp@673: 	}
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@724: #ifdef CONFIG_PM
fp@673: static int
fp@673: e1000_suspend(struct pci_dev *pdev, uint32_t state)
fp@673: {
fp@673: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
fp@673: 	uint32_t wufc = adapter->wol;
fp@673: 
fp@673: 	if (!adapter->ecdev)
fp@673: 		netif_device_detach(netdev);
fp@673: 
fp@673: 	if (adapter->ecdev || netif_running(netdev))
fp@673: 		e1000_down(adapter);
fp@673: 
fp@673: 	status = E1000_READ_REG(&adapter->hw, STATUS);
fp@673: 	if(status & E1000_STATUS_LU)
fp@673: 		wufc &= ~E1000_WUFC_LNKC;
fp@673: 
fp@673: 	if(wufc) {
fp@673: 		e1000_setup_rctl(adapter);
fp@673: 		e1000_set_multi(netdev);
fp@673: 
fp@673: 		/* turn on all-multi mode if wake on multicast is enabled */
fp@673: 		if(adapter->wol & E1000_WUFC_MC) {
fp@673: 			rctl = E1000_READ_REG(&adapter->hw, RCTL);
fp@673: 			rctl |= E1000_RCTL_MPE;
fp@673: 			E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
fp@673: 		}
fp@673: 
fp@673: 		if(adapter->hw.mac_type >= e1000_82540) {
fp@673: 			ctrl = E1000_READ_REG(&adapter->hw, CTRL);
fp@673: 			/* advertise wake from D3Cold */
fp@673: 			#define E1000_CTRL_ADVD3WUC 0x00100000
fp@673: 			/* phy power management enable */
fp@673: 			#define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
fp@673: 			ctrl |= E1000_CTRL_ADVD3WUC |
fp@673: 				E1000_CTRL_EN_PHY_PWR_MGMT;
fp@673: 			E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
fp@673: 		}
fp@673: 
fp@673: 		if(adapter->hw.media_type == e1000_media_type_fiber ||
fp@673: 		   adapter->hw.media_type == e1000_media_type_internal_serdes) {
fp@673: 			/* keep the laser running in D3 */
fp@673: 			ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
fp@673: 			ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
fp@673: 			E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
fp@673: 		}
fp@673: 
fp@673: 		/* Allow time for pending master requests to run */
fp@673: 		e1000_disable_pciex_master(&adapter->hw);
fp@673: 
fp@673: 		E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
fp@673: 		E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
fp@673: 		pci_enable_wake(pdev, 3, 1);
fp@673: 		pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
fp@673: 	} else {
fp@673: 		E1000_WRITE_REG(&adapter->hw, WUC, 0);
fp@673: 		E1000_WRITE_REG(&adapter->hw, WUFC, 0);
fp@673: 		pci_enable_wake(pdev, 3, 0);
fp@673: 		pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
fp@673: 	}
fp@673: 
fp@673: 	pci_save_state(pdev);
fp@673: 
fp@673: 	if(adapter->hw.mac_type >= e1000_82540 &&
fp@673: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@673: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@673: 		if(manc & E1000_MANC_SMBUS_EN) {
fp@673: 			manc |= E1000_MANC_ARP_EN;
fp@673: 			E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@673: 			pci_enable_wake(pdev, 3, 1);
fp@673: 			pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
fp@673: 		}
fp@673: 	}
fp@673: 
fp@673: 	switch(adapter->hw.mac_type) {
fp@673: 	case e1000_82573:
fp@673: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@673: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@673: 				swsm & ~E1000_SWSM_DRV_LOAD);
fp@673: 		break;
fp@673: 	default:
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	pci_disable_device(pdev);
fp@673: 
fp@673: 	state = (state > 0) ? 3 : 0;
fp@673: 	pci_set_power_state(pdev, state);
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: 
fp@673: static int
fp@673: e1000_resume(struct pci_dev *pdev)
fp@673: {
fp@673: 	struct net_device *netdev = pci_get_drvdata(pdev);
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	uint32_t manc, ret_val, swsm;
fp@673: 
fp@673: 	pci_set_power_state(pdev, 0);
fp@673: 	pci_restore_state(pdev);
fp@673: 	ret_val = pci_enable_device(pdev);
fp@673: 	pci_set_master(pdev);
fp@673: 
fp@673: 	pci_enable_wake(pdev, 3, 0);
fp@673: 	pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
fp@673: 
fp@673: 	e1000_reset(adapter);
fp@673: 	E1000_WRITE_REG(&adapter->hw, WUS, ~0);
fp@673: 
fp@673: 	if(adapter->ecdev || netif_running(netdev))
fp@673: 		e1000_up(adapter);
fp@673: 
fp@673: 	if (!adapter->ecdev) netif_device_attach(netdev);
fp@673: 
fp@673: 	if(adapter->hw.mac_type >= e1000_82540 &&
fp@673: 	   adapter->hw.media_type == e1000_media_type_copper) {
fp@673: 		manc = E1000_READ_REG(&adapter->hw, MANC);
fp@673: 		manc &= ~(E1000_MANC_ARP_EN);
fp@673: 		E1000_WRITE_REG(&adapter->hw, MANC, manc);
fp@673: 	}
fp@673: 
fp@673: 	switch(adapter->hw.mac_type) {
fp@673: 	case e1000_82573:
fp@673: 		swsm = E1000_READ_REG(&adapter->hw, SWSM);
fp@673: 		E1000_WRITE_REG(&adapter->hw, SWSM,
fp@673: 				swsm | E1000_SWSM_DRV_LOAD);
fp@673: 		break;
fp@673: 	default:
fp@673: 		break;
fp@673: 	}
fp@673: 
fp@673: 	return 0;
fp@673: }
fp@673: #endif
fp@673: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@673: /*
fp@673:  * Polling 'interrupt' - used by things like netconsole to send skbs
fp@673:  * without having to re-enable interrupts. It's not called while
fp@673:  * the interrupt routine is executing.
fp@673:  */
fp@673: static void
fp@673: e1000_netpoll(struct net_device *netdev)
fp@673: {
fp@673: 	struct e1000_adapter *adapter = netdev_priv(netdev);
fp@673: 	disable_irq(adapter->pdev->irq);
fp@673: 	e1000_intr(adapter->pdev->irq, netdev, NULL);
fp@673: 	e1000_clean_tx_irq(adapter);
fp@673: 	enable_irq(adapter->pdev->irq);
fp@673: }
fp@673: #endif
fp@673: 
fp@673: /* e1000_main.c */