Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver |
| 4 | Copyright(c) 1999 - 2006 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include "e1000.h" |
Andrew Morton | d0bb53e | 2006-11-14 10:35:03 -0500 | [diff] [blame] | 30 | #include <net/ip6_checksum.h> |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 31 | #include <linux/io.h> |
| 32 | |
| 33 | /* Intel Media SOC GbE MDIO physical base address */ |
| 34 | static unsigned long ce4100_gbe_mdio_base_phy; |
| 35 | /* Intel Media SOC GbE MDIO virtual base address */ |
| 36 | void __iomem *ce4100_gbe_mdio_base_virt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | char e1000_driver_name[] = "e1000"; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 39 | static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; |
Anupam Chanda | ab08853 | 2010-11-21 09:54:21 -0800 | [diff] [blame] | 40 | #define DRV_VERSION "7.3.21-k8-NAPI" |
Stephen Hemminger | abec42a | 2007-10-29 10:46:19 -0700 | [diff] [blame] | 41 | const char e1000_driver_version[] = DRV_VERSION; |
| 42 | static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* e1000_pci_tbl - PCI Device ID Table |
| 45 | * |
| 46 | * Last entry must be all 0s |
| 47 | * |
| 48 | * Macro expands to... |
| 49 | * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
| 50 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 51 | static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 53 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 54 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 55 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 56 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 57 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 58 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 59 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 60 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 61 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 62 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 63 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 64 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 65 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 66 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 67 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 68 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 69 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 70 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 71 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 73 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 74 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 75 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 76 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
| 77 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 78 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 79 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 80 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 81 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 82 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 83 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 84 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
| 85 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 86 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 87 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 88 | INTEL_E1000_ETHERNET_DEVICE(0x2E6E), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* required last entry */ |
| 90 | {0,} |
| 91 | }; |
| 92 | |
| 93 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 94 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 95 | int e1000_up(struct e1000_adapter *adapter); |
| 96 | void e1000_down(struct e1000_adapter *adapter); |
| 97 | void e1000_reinit_locked(struct e1000_adapter *adapter); |
| 98 | void e1000_reset(struct e1000_adapter *adapter); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 99 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 100 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 101 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 102 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 103 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 104 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 105 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 106 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 107 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 108 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 109 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 110 | struct e1000_rx_ring *rx_ring); |
| 111 | void e1000_update_stats(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | static int e1000_init_module(void); |
| 114 | static void e1000_exit_module(void); |
| 115 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 116 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 117 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 119 | static int e1000_open(struct net_device *netdev); |
| 120 | static int e1000_close(struct net_device *netdev); |
| 121 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 122 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 123 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 124 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 125 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 126 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 127 | struct e1000_tx_ring *tx_ring); |
| 128 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 129 | struct e1000_rx_ring *rx_ring); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 130 | static void e1000_set_rx_mode(struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | static void e1000_update_phy_info(unsigned long data); |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 132 | static void e1000_update_phy_info_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static void e1000_watchdog(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 135 | static void e1000_82547_tx_fifo_stall_task(struct work_struct *work); |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 136 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 137 | struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 139 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 140 | static int e1000_set_mac(struct net_device *netdev, void *p); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 141 | static irqreturn_t e1000_intr(int irq, void *data); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 142 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 143 | struct e1000_tx_ring *tx_ring); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 144 | static int e1000_clean(struct napi_struct *napi, int budget); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 145 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 146 | struct e1000_rx_ring *rx_ring, |
| 147 | int *work_done, int work_to_do); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 148 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 149 | struct e1000_rx_ring *rx_ring, |
| 150 | int *work_done, int work_to_do); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 151 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 152 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 153 | int cleaned_count); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 154 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 155 | struct e1000_rx_ring *rx_ring, |
| 156 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 158 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 159 | int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 161 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 162 | static void e1000_tx_timeout(struct net_device *dev); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 163 | static void e1000_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 165 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 166 | struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 169 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); |
| 170 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 172 | |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 173 | #ifdef CONFIG_PM |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 174 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | static int e1000_resume(struct pci_dev *pdev); |
| 176 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 177 | static void e1000_shutdown(struct pci_dev *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 180 | /* for netdump / net console */ |
| 181 | static void e1000_netpoll (struct net_device *netdev); |
| 182 | #endif |
| 183 | |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 184 | #define COPYBREAK_DEFAULT 256 |
| 185 | static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; |
| 186 | module_param(copybreak, uint, 0644); |
| 187 | MODULE_PARM_DESC(copybreak, |
| 188 | "Maximum size of packet that is copied to a new buffer on receive"); |
| 189 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 190 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 191 | pci_channel_state_t state); |
| 192 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
| 193 | static void e1000_io_resume(struct pci_dev *pdev); |
| 194 | |
| 195 | static struct pci_error_handlers e1000_err_handler = { |
| 196 | .error_detected = e1000_io_error_detected, |
| 197 | .slot_reset = e1000_io_slot_reset, |
| 198 | .resume = e1000_io_resume, |
| 199 | }; |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static struct pci_driver e1000_driver = { |
| 202 | .name = e1000_driver_name, |
| 203 | .id_table = e1000_pci_tbl, |
| 204 | .probe = e1000_probe, |
| 205 | .remove = __devexit_p(e1000_remove), |
Auke Kok | c4e24f0 | 2006-09-27 12:53:19 -0700 | [diff] [blame] | 206 | #ifdef CONFIG_PM |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 207 | /* Power Management Hooks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | .suspend = e1000_suspend, |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 209 | .resume = e1000_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | #endif |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 211 | .shutdown = e1000_shutdown, |
| 212 | .err_handler = &e1000_err_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 216 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 217 | MODULE_LICENSE("GPL"); |
| 218 | MODULE_VERSION(DRV_VERSION); |
| 219 | |
| 220 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 221 | module_param(debug, int, 0); |
| 222 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 223 | |
| 224 | /** |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 225 | * e1000_get_hw_dev - return device |
| 226 | * used by hardware layer to print debugging information |
| 227 | * |
| 228 | **/ |
| 229 | struct net_device *e1000_get_hw_dev(struct e1000_hw *hw) |
| 230 | { |
| 231 | struct e1000_adapter *adapter = hw->back; |
| 232 | return adapter->netdev; |
| 233 | } |
| 234 | |
| 235 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | * e1000_init_module - Driver Registration Routine |
| 237 | * |
| 238 | * e1000_init_module is the first routine called when the driver is |
| 239 | * loaded. All it does is register with the PCI subsystem. |
| 240 | **/ |
| 241 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 242 | static int __init e1000_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | int ret; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 245 | pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 247 | pr_info("%s\n", e1000_copyright); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 249 | ret = pci_register_driver(&e1000_driver); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 250 | if (copybreak != COPYBREAK_DEFAULT) { |
| 251 | if (copybreak == 0) |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 252 | pr_info("copybreak disabled\n"); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 253 | else |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 254 | pr_info("copybreak enabled for " |
| 255 | "packets <= %u bytes\n", copybreak); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | module_init(e1000_init_module); |
| 261 | |
| 262 | /** |
| 263 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 264 | * |
| 265 | * e1000_exit_module is called just before the driver is removed |
| 266 | * from memory. |
| 267 | **/ |
| 268 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 269 | static void __exit e1000_exit_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | pci_unregister_driver(&e1000_driver); |
| 272 | } |
| 273 | |
| 274 | module_exit(e1000_exit_module); |
| 275 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 276 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 277 | { |
| 278 | struct net_device *netdev = adapter->netdev; |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 279 | irq_handler_t handler = e1000_intr; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 280 | int irq_flags = IRQF_SHARED; |
| 281 | int err; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 282 | |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 283 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
| 284 | netdev); |
| 285 | if (err) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 286 | e_err(probe, "Unable to allocate interrupt Error: %d\n", err); |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 287 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 288 | |
| 289 | return err; |
| 290 | } |
| 291 | |
| 292 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 293 | { |
| 294 | struct net_device *netdev = adapter->netdev; |
| 295 | |
| 296 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /** |
| 300 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 301 | * @adapter: board private structure |
| 302 | **/ |
| 303 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 304 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 306 | struct e1000_hw *hw = &adapter->hw; |
| 307 | |
| 308 | ew32(IMC, ~0); |
| 309 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | synchronize_irq(adapter->pdev->irq); |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * e1000_irq_enable - Enable default interrupt generation settings |
| 315 | * @adapter: board private structure |
| 316 | **/ |
| 317 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 318 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 320 | struct e1000_hw *hw = &adapter->hw; |
| 321 | |
| 322 | ew32(IMS, IMS_ENABLE_MASK); |
| 323 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 325 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 326 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 327 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 328 | struct e1000_hw *hw = &adapter->hw; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 329 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 330 | u16 vid = hw->mng_cookie.vlan_id; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 331 | u16 old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 332 | if (adapter->vlgrp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 333 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 334 | if (hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 335 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 336 | e1000_vlan_rx_add_vid(netdev, vid); |
| 337 | adapter->mng_vlan_id = vid; |
| 338 | } else |
| 339 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 340 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 341 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 342 | (vid != old_vid) && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 343 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 344 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 345 | } else |
| 346 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 349 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 350 | static void e1000_init_manageability(struct e1000_adapter *adapter) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 351 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 352 | struct e1000_hw *hw = &adapter->hw; |
| 353 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 354 | if (adapter->en_mng_pt) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 355 | u32 manc = er32(MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 356 | |
| 357 | /* disable hardware interception of ARP */ |
| 358 | manc &= ~(E1000_MANC_ARP_EN); |
| 359 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 360 | ew32(MANC, manc); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 364 | static void e1000_release_manageability(struct e1000_adapter *adapter) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 365 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 366 | struct e1000_hw *hw = &adapter->hw; |
| 367 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 368 | if (adapter->en_mng_pt) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 369 | u32 manc = er32(MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 370 | |
| 371 | /* re-enable hardware interception of ARP */ |
| 372 | manc |= E1000_MANC_ARP_EN; |
| 373 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 374 | ew32(MANC, manc); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 378 | /** |
| 379 | * e1000_configure - configure the hardware for RX and TX |
| 380 | * @adapter = private board structure |
| 381 | **/ |
| 382 | static void e1000_configure(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
| 384 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 385 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 387 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 390 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | e1000_configure_tx(adapter); |
| 393 | e1000_setup_rctl(adapter); |
| 394 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 395 | /* call E1000_DESC_UNUSED which always leaves |
| 396 | * at least 1 descriptor unused to make sure |
| 397 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 398 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 399 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 400 | adapter->alloc_rx_buf(adapter, ring, |
| 401 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 402 | } |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 403 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 404 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 405 | int e1000_up(struct e1000_adapter *adapter) |
| 406 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 407 | struct e1000_hw *hw = &adapter->hw; |
| 408 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 409 | /* hardware has been reset, we need to reload some things */ |
| 410 | e1000_configure(adapter); |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 411 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 412 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 413 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 414 | napi_enable(&adapter->napi); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 415 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 416 | e1000_irq_enable(adapter); |
| 417 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 418 | netif_wake_queue(adapter->netdev); |
| 419 | |
Jesse Brandeburg | 79f3d39 | 2006-12-15 10:42:34 +0100 | [diff] [blame] | 420 | /* fire a link change interrupt to start the watchdog */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 421 | ew32(ICS, E1000_ICS_LSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 425 | /** |
| 426 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 427 | * @adapter: address of board private structure |
| 428 | * |
| 429 | * The phy may be powered down to save power and turn off link when the |
| 430 | * driver is unloaded and wake on lan is not enabled (among others) |
| 431 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 432 | * |
| 433 | **/ |
| 434 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 435 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 436 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 437 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 438 | u16 mii_reg = 0; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 439 | |
| 440 | /* Just clear the power down bit to wake the phy back up */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 441 | if (hw->media_type == e1000_media_type_copper) { |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 442 | /* according to the manual, the phy will retain its |
| 443 | * settings across a power-down/up cycle */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 444 | e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 445 | mii_reg &= ~MII_CR_POWER_DOWN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 446 | e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 451 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 452 | struct e1000_hw *hw = &adapter->hw; |
| 453 | |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 454 | /* Power down the PHY so no link is implied when interface is down * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 455 | * The PHY cannot be powered down if any of the following is true * |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 456 | * (a) WoL is enabled |
| 457 | * (b) AMT is active |
| 458 | * (c) SoL/IDER session is active */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 459 | if (!adapter->wol && hw->mac_type >= e1000_82540 && |
| 460 | hw->media_type == e1000_media_type_copper) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 461 | u16 mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 462 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 463 | switch (hw->mac_type) { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 464 | case e1000_82540: |
| 465 | case e1000_82545: |
| 466 | case e1000_82545_rev_3: |
| 467 | case e1000_82546: |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 468 | case e1000_ce4100: |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 469 | case e1000_82546_rev_3: |
| 470 | case e1000_82541: |
| 471 | case e1000_82541_rev_2: |
| 472 | case e1000_82547: |
| 473 | case e1000_82547_rev_2: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 474 | if (er32(MANC) & E1000_MANC_SMBUS_EN) |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 475 | goto out; |
| 476 | break; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 477 | default: |
| 478 | goto out; |
| 479 | } |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 480 | e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 481 | mii_reg |= MII_CR_POWER_DOWN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 482 | e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 483 | mdelay(1); |
| 484 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 485 | out: |
| 486 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 489 | void e1000_down(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 491 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 493 | u32 rctl, tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 495 | |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 496 | /* disable receives in the hardware */ |
| 497 | rctl = er32(RCTL); |
| 498 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 499 | /* flush and sleep below */ |
| 500 | |
Jesse Brandeburg | 5185107 | 2009-09-25 12:17:01 +0000 | [diff] [blame] | 501 | netif_tx_disable(netdev); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 502 | |
| 503 | /* disable transmits in the hardware */ |
| 504 | tctl = er32(TCTL); |
| 505 | tctl &= ~E1000_TCTL_EN; |
| 506 | ew32(TCTL, tctl); |
| 507 | /* flush both disables and wait for them to finish */ |
| 508 | E1000_WRITE_FLUSH(); |
| 509 | msleep(10); |
| 510 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 511 | napi_disable(&adapter->napi); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 514 | |
Anupam Chanda | ab08853 | 2010-11-21 09:54:21 -0800 | [diff] [blame] | 515 | /* |
| 516 | * Setting DOWN must be after irq_disable to prevent |
| 517 | * a screaming interrupt. Setting DOWN also prevents |
| 518 | * timers and tasks from rescheduling. |
| 519 | */ |
| 520 | set_bit(__E1000_DOWN, &adapter->flags); |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 523 | del_timer_sync(&adapter->watchdog_timer); |
| 524 | del_timer_sync(&adapter->phy_info_timer); |
| 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | adapter->link_speed = 0; |
| 527 | adapter->link_duplex = 0; |
| 528 | netif_carrier_off(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 531 | e1000_clean_all_tx_rings(adapter); |
| 532 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
stephen hemminger | 38df7a3 | 2010-10-21 07:50:57 +0000 | [diff] [blame] | 535 | static void e1000_reinit_safe(struct e1000_adapter *adapter) |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 536 | { |
| 537 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 538 | msleep(1); |
| 539 | rtnl_lock(); |
| 540 | e1000_down(adapter); |
| 541 | e1000_up(adapter); |
| 542 | rtnl_unlock(); |
| 543 | clear_bit(__E1000_RESETTING, &adapter->flags); |
| 544 | } |
| 545 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 546 | void e1000_reinit_locked(struct e1000_adapter *adapter) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 547 | { |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 548 | /* if rtnl_lock is not held the call path is bogus */ |
| 549 | ASSERT_RTNL(); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 550 | WARN_ON(in_interrupt()); |
| 551 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 552 | msleep(1); |
| 553 | e1000_down(adapter); |
| 554 | e1000_up(adapter); |
| 555 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 558 | void e1000_reset(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 560 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 561 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 562 | bool legacy_pba_adjust = false; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 563 | u16 hwm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | /* Repartition Pba for greater than 9k mtu |
| 566 | * To take effect CTRL.RST is required. |
| 567 | */ |
| 568 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 569 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 570 | case e1000_82542_rev2_0: |
| 571 | case e1000_82542_rev2_1: |
| 572 | case e1000_82543: |
| 573 | case e1000_82544: |
| 574 | case e1000_82540: |
| 575 | case e1000_82541: |
| 576 | case e1000_82541_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 577 | legacy_pba_adjust = true; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 578 | pba = E1000_PBA_48K; |
| 579 | break; |
| 580 | case e1000_82545: |
| 581 | case e1000_82545_rev_3: |
| 582 | case e1000_82546: |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 583 | case e1000_ce4100: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 584 | case e1000_82546_rev_3: |
| 585 | pba = E1000_PBA_48K; |
| 586 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 587 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 588 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 589 | legacy_pba_adjust = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 590 | pba = E1000_PBA_30K; |
| 591 | break; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 592 | case e1000_undefined: |
| 593 | case e1000_num_macs: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 594 | break; |
| 595 | } |
| 596 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 597 | if (legacy_pba_adjust) { |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 598 | if (hw->max_frame_size > E1000_RXBUFFER_8192) |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 599 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 600 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 601 | if (hw->mac_type == e1000_82547) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 602 | adapter->tx_fifo_head = 0; |
| 603 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 604 | adapter->tx_fifo_size = |
| 605 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 606 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 607 | } |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 608 | } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 609 | /* adjust PBA for jumbo frames */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 610 | ew32(PBA, pba); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 611 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 612 | /* To maintain wire speed transmits, the Tx FIFO should be |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 613 | * large enough to accommodate two full transmit packets, |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 614 | * rounded up to the next 1KB and expressed in KB. Likewise, |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 615 | * the Rx FIFO should be large enough to accommodate at least |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 616 | * one full receive packet and is similarly rounded up and |
| 617 | * expressed in KB. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 618 | pba = er32(PBA); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 619 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 620 | tx_space = pba >> 16; |
| 621 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 622 | pba &= 0xffff; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 623 | /* |
| 624 | * the tx fifo also stores 16 bytes of information about the tx |
| 625 | * but don't include ethernet FCS because hardware appends it |
| 626 | */ |
| 627 | min_tx_space = (hw->max_frame_size + |
| 628 | sizeof(struct e1000_tx_desc) - |
| 629 | ETH_FCS_LEN) * 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 630 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 631 | min_tx_space >>= 10; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 632 | /* software strips receive CRC, so leave room for it */ |
| 633 | min_rx_space = hw->max_frame_size; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 634 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 635 | min_rx_space >>= 10; |
| 636 | |
| 637 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 638 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 639 | * allocation, take space away from current Rx allocation */ |
| 640 | if (tx_space < min_tx_space && |
| 641 | ((min_tx_space - tx_space) < pba)) { |
| 642 | pba = pba - (min_tx_space - tx_space); |
| 643 | |
| 644 | /* PCI/PCIx hardware has PBA alignment constraints */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 645 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 646 | case e1000_82545 ... e1000_82546_rev_3: |
| 647 | pba &= ~(E1000_PBA_8K - 1); |
| 648 | break; |
| 649 | default: |
| 650 | break; |
| 651 | } |
| 652 | |
| 653 | /* if short on rx space, rx wins and must trump tx |
| 654 | * adjustment or use Early Receive if available */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 655 | if (pba < min_rx_space) |
| 656 | pba = min_rx_space; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 659 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 660 | ew32(PBA, pba); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 662 | /* |
| 663 | * flow control settings: |
| 664 | * The high water mark must be low enough to fit one full frame |
| 665 | * (or the size used for early receive) above it in the Rx FIFO. |
| 666 | * Set it to the lower of: |
| 667 | * - 90% of the Rx FIFO size, and |
| 668 | * - the full Rx FIFO size minus the early receive size (for parts |
| 669 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
| 670 | * - the full Rx FIFO size minus one full frame |
| 671 | */ |
| 672 | hwm = min(((pba << 10) * 9 / 10), |
| 673 | ((pba << 10) - hw->max_frame_size)); |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 674 | |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 675 | hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */ |
| 676 | hw->fc_low_water = hw->fc_high_water - 8; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 677 | hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 678 | hw->fc_send_xon = 1; |
| 679 | hw->fc = hw->original_fc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 681 | /* Allow time for pending master requests to run */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 682 | e1000_reset_hw(hw); |
| 683 | if (hw->mac_type >= e1000_82544) |
| 684 | ew32(WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 685 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 686 | if (e1000_init_hw(hw)) |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 687 | e_dev_err("Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 688 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 689 | |
| 690 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 691 | if (hw->mac_type >= e1000_82544 && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 692 | hw->autoneg == 1 && |
| 693 | hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 694 | u32 ctrl = er32(CTRL); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 695 | /* clear phy power management bit if we are in gig only mode, |
| 696 | * which if enabled will attempt negotiation to 100Mb, which |
| 697 | * can cause a loss of link at power off or driver unload */ |
| 698 | ctrl &= ~E1000_CTRL_SWDPIN3; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 699 | ew32(CTRL, ctrl); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 700 | } |
| 701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 703 | ew32(VET, ETHERNET_IEEE_VLAN_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 705 | e1000_reset_adaptive(hw); |
| 706 | e1000_phy_get_info(hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 707 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 708 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /** |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 712 | * Dump the eeprom for users having checksum issues |
| 713 | **/ |
Adrian Bunk | b4ea895 | 2008-02-01 08:21:28 -0800 | [diff] [blame] | 714 | static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 715 | { |
| 716 | struct net_device *netdev = adapter->netdev; |
| 717 | struct ethtool_eeprom eeprom; |
| 718 | const struct ethtool_ops *ops = netdev->ethtool_ops; |
| 719 | u8 *data; |
| 720 | int i; |
| 721 | u16 csum_old, csum_new = 0; |
| 722 | |
| 723 | eeprom.len = ops->get_eeprom_len(netdev); |
| 724 | eeprom.offset = 0; |
| 725 | |
| 726 | data = kmalloc(eeprom.len, GFP_KERNEL); |
| 727 | if (!data) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 728 | pr_err("Unable to allocate memory to dump EEPROM data\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
| 732 | ops->get_eeprom(netdev, &eeprom, data); |
| 733 | |
| 734 | csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
| 735 | (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
| 736 | for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
| 737 | csum_new += data[i] + (data[i + 1] << 8); |
| 738 | csum_new = EEPROM_SUM - csum_new; |
| 739 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 740 | pr_err("/*********************/\n"); |
| 741 | pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old); |
| 742 | pr_err("Calculated : 0x%04x\n", csum_new); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 743 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 744 | pr_err("Offset Values\n"); |
| 745 | pr_err("======== ======\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 746 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
| 747 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 748 | pr_err("Include this output when contacting your support provider.\n"); |
| 749 | pr_err("This is not a software error! Something bad happened to\n"); |
| 750 | pr_err("your hardware or EEPROM image. Ignoring this problem could\n"); |
| 751 | pr_err("result in further problems, possibly loss of data,\n"); |
| 752 | pr_err("corruption or system hangs!\n"); |
| 753 | pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n"); |
| 754 | pr_err("which is invalid and requires you to set the proper MAC\n"); |
| 755 | pr_err("address manually before continuing to enable this network\n"); |
| 756 | pr_err("device. Please inspect the EEPROM dump and report the\n"); |
| 757 | pr_err("issue to your hardware vendor or Intel Customer Support.\n"); |
| 758 | pr_err("/*********************/\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 759 | |
| 760 | kfree(data); |
| 761 | } |
| 762 | |
| 763 | /** |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 764 | * e1000_is_need_ioport - determine if an adapter needs ioport resources or not |
| 765 | * @pdev: PCI device information struct |
| 766 | * |
| 767 | * Return true if an adapter needs ioport resources |
| 768 | **/ |
| 769 | static int e1000_is_need_ioport(struct pci_dev *pdev) |
| 770 | { |
| 771 | switch (pdev->device) { |
| 772 | case E1000_DEV_ID_82540EM: |
| 773 | case E1000_DEV_ID_82540EM_LOM: |
| 774 | case E1000_DEV_ID_82540EP: |
| 775 | case E1000_DEV_ID_82540EP_LOM: |
| 776 | case E1000_DEV_ID_82540EP_LP: |
| 777 | case E1000_DEV_ID_82541EI: |
| 778 | case E1000_DEV_ID_82541EI_MOBILE: |
| 779 | case E1000_DEV_ID_82541ER: |
| 780 | case E1000_DEV_ID_82541ER_LOM: |
| 781 | case E1000_DEV_ID_82541GI: |
| 782 | case E1000_DEV_ID_82541GI_LF: |
| 783 | case E1000_DEV_ID_82541GI_MOBILE: |
| 784 | case E1000_DEV_ID_82544EI_COPPER: |
| 785 | case E1000_DEV_ID_82544EI_FIBER: |
| 786 | case E1000_DEV_ID_82544GC_COPPER: |
| 787 | case E1000_DEV_ID_82544GC_LOM: |
| 788 | case E1000_DEV_ID_82545EM_COPPER: |
| 789 | case E1000_DEV_ID_82545EM_FIBER: |
| 790 | case E1000_DEV_ID_82546EB_COPPER: |
| 791 | case E1000_DEV_ID_82546EB_FIBER: |
| 792 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 793 | return true; |
| 794 | default: |
| 795 | return false; |
| 796 | } |
| 797 | } |
| 798 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 799 | static const struct net_device_ops e1000_netdev_ops = { |
| 800 | .ndo_open = e1000_open, |
| 801 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 802 | .ndo_start_xmit = e1000_xmit_frame, |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 803 | .ndo_get_stats = e1000_get_stats, |
| 804 | .ndo_set_rx_mode = e1000_set_rx_mode, |
| 805 | .ndo_set_mac_address = e1000_set_mac, |
| 806 | .ndo_tx_timeout = e1000_tx_timeout, |
| 807 | .ndo_change_mtu = e1000_change_mtu, |
| 808 | .ndo_do_ioctl = e1000_ioctl, |
| 809 | .ndo_validate_addr = eth_validate_addr, |
| 810 | |
| 811 | .ndo_vlan_rx_register = e1000_vlan_rx_register, |
| 812 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 813 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 814 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 815 | .ndo_poll_controller = e1000_netpoll, |
| 816 | #endif |
| 817 | }; |
| 818 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 819 | /** |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 820 | * e1000_init_hw_struct - initialize members of hw struct |
| 821 | * @adapter: board private struct |
| 822 | * @hw: structure used by e1000_hw.c |
| 823 | * |
| 824 | * Factors out initialization of the e1000_hw struct to its own function |
| 825 | * that can be called very early at init (just after struct allocation). |
| 826 | * Fields are initialized based on PCI device information and |
| 827 | * OS network device settings (MTU size). |
| 828 | * Returns negative error codes if MAC type setup fails. |
| 829 | */ |
| 830 | static int e1000_init_hw_struct(struct e1000_adapter *adapter, |
| 831 | struct e1000_hw *hw) |
| 832 | { |
| 833 | struct pci_dev *pdev = adapter->pdev; |
| 834 | |
| 835 | /* PCI config space info */ |
| 836 | hw->vendor_id = pdev->vendor; |
| 837 | hw->device_id = pdev->device; |
| 838 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 839 | hw->subsystem_id = pdev->subsystem_device; |
| 840 | hw->revision_id = pdev->revision; |
| 841 | |
| 842 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 843 | |
| 844 | hw->max_frame_size = adapter->netdev->mtu + |
| 845 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 846 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 847 | |
| 848 | /* identify the MAC */ |
| 849 | if (e1000_set_mac_type(hw)) { |
| 850 | e_err(probe, "Unknown MAC Type\n"); |
| 851 | return -EIO; |
| 852 | } |
| 853 | |
| 854 | switch (hw->mac_type) { |
| 855 | default: |
| 856 | break; |
| 857 | case e1000_82541: |
| 858 | case e1000_82547: |
| 859 | case e1000_82541_rev_2: |
| 860 | case e1000_82547_rev_2: |
| 861 | hw->phy_init_script = 1; |
| 862 | break; |
| 863 | } |
| 864 | |
| 865 | e1000_set_media_type(hw); |
| 866 | e1000_get_bus_info(hw); |
| 867 | |
| 868 | hw->wait_autoneg_complete = false; |
| 869 | hw->tbi_compatibility_en = true; |
| 870 | hw->adaptive_ifs = true; |
| 871 | |
| 872 | /* Copper options */ |
| 873 | |
| 874 | if (hw->media_type == e1000_media_type_copper) { |
| 875 | hw->mdix = AUTO_ALL_MODES; |
| 876 | hw->disable_polarity_correction = false; |
| 877 | hw->master_slave = E1000_MASTER_SLAVE; |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | * e1000_probe - Device Initialization Routine |
| 885 | * @pdev: PCI device information struct |
| 886 | * @ent: entry in e1000_pci_tbl |
| 887 | * |
| 888 | * Returns 0 on success, negative on failure |
| 889 | * |
| 890 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 891 | * The OS initialization, configuring of the adapter private structure, |
| 892 | * and a hardware reset occur. |
| 893 | **/ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 894 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 895 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
| 897 | struct net_device *netdev; |
| 898 | struct e1000_adapter *adapter; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 899 | struct e1000_hw *hw; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 902 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 903 | int i, err, pci_using_dac; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 904 | u16 eeprom_data = 0; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 905 | u16 tmp = 0; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 906 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 907 | int bars, need_ioport; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 908 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 909 | /* do not allocate ioport bars when not needed */ |
| 910 | need_ioport = e1000_is_need_ioport(pdev); |
| 911 | if (need_ioport) { |
| 912 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
| 913 | err = pci_enable_device(pdev); |
| 914 | } else { |
| 915 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
Karsten Keil | 4d7155b | 2009-02-03 15:18:01 -0800 | [diff] [blame] | 916 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 917 | } |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 918 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | return err; |
| 920 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 921 | err = pci_request_selected_regions(pdev, bars, e1000_driver_name); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 922 | if (err) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 923 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | pci_set_master(pdev); |
Nick Nunley | dbb5aae | 2010-02-03 14:49:48 +0000 | [diff] [blame] | 926 | err = pci_save_state(pdev); |
| 927 | if (err) |
| 928 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 930 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 932 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 936 | |
| 937 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 938 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | adapter->netdev = netdev; |
| 940 | adapter->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | adapter->msg_enable = (1 << debug) - 1; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 942 | adapter->bars = bars; |
| 943 | adapter->need_ioport = need_ioport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 945 | hw = &adapter->hw; |
| 946 | hw->back = adapter; |
| 947 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 948 | err = -EIO; |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 949 | hw->hw_addr = pci_ioremap_bar(pdev, BAR_0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 950 | if (!hw->hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 953 | if (adapter->need_ioport) { |
| 954 | for (i = BAR_1; i <= BAR_5; i++) { |
| 955 | if (pci_resource_len(pdev, i) == 0) |
| 956 | continue; |
| 957 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 958 | hw->io_base = pci_resource_start(pdev, i); |
| 959 | break; |
| 960 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 964 | /* make ready for any if (hw->...) below */ |
| 965 | err = e1000_init_hw_struct(adapter, hw); |
| 966 | if (err) |
| 967 | goto err_sw_init; |
| 968 | |
| 969 | /* |
| 970 | * there is a workaround being applied below that limits |
| 971 | * 64-bit DMA addresses to 64-bit hardware. There are some |
| 972 | * 32-bit adapters that Tx hang when given 64-bit DMA addresses |
| 973 | */ |
| 974 | pci_using_dac = 0; |
| 975 | if ((hw->bus_type == e1000_bus_type_pcix) && |
| 976 | !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
| 977 | /* |
| 978 | * according to DMA-API-HOWTO, coherent calls will always |
| 979 | * succeed if the set call did |
| 980 | */ |
| 981 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
| 982 | pci_using_dac = 1; |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 983 | } else { |
Dean Nelson | 19a0b67 | 2010-11-11 05:50:25 +0000 | [diff] [blame] | 984 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 985 | if (err) { |
| 986 | pr_err("No usable DMA config, aborting\n"); |
| 987 | goto err_dma; |
| 988 | } |
| 989 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 992 | netdev->netdev_ops = &e1000_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | e1000_set_ethtool_ops(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | netdev->watchdog_timeo = 5 * HZ; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 995 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 996 | |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 997 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | adapter->bd_number = cards_found; |
| 1000 | |
| 1001 | /* setup the private structure */ |
| 1002 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1003 | err = e1000_sw_init(adapter); |
| 1004 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | goto err_sw_init; |
| 1006 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1007 | err = -EIO; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1008 | if (hw->mac_type == e1000_ce4100) { |
| 1009 | ce4100_gbe_mdio_base_phy = pci_resource_start(pdev, BAR_1); |
| 1010 | ce4100_gbe_mdio_base_virt = ioremap(ce4100_gbe_mdio_base_phy, |
| 1011 | pci_resource_len(pdev, BAR_1)); |
| 1012 | |
| 1013 | if (!ce4100_gbe_mdio_base_virt) |
| 1014 | goto err_mdio_ioremap; |
| 1015 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1016 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1017 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | netdev->features = NETIF_F_SG | |
| 1019 | NETIF_F_HW_CSUM | |
| 1020 | NETIF_F_HW_VLAN_TX | |
| 1021 | NETIF_F_HW_VLAN_RX | |
| 1022 | NETIF_F_HW_VLAN_FILTER; |
| 1023 | } |
| 1024 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1025 | if ((hw->mac_type >= e1000_82544) && |
| 1026 | (hw->mac_type != e1000_82547)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1028 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 1029 | if (pci_using_dac) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 1031 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
Patrick McHardy | 20501a6 | 2008-10-11 12:25:59 -0700 | [diff] [blame] | 1034 | netdev->vlan_features |= NETIF_F_TSO; |
Patrick McHardy | 20501a6 | 2008-10-11 12:25:59 -0700 | [diff] [blame] | 1035 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 1036 | netdev->vlan_features |= NETIF_F_SG; |
| 1037 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1038 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1039 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1040 | /* initialize eeprom parameters */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1041 | if (e1000_init_eeprom_params(hw)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1042 | e_err(probe, "EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1043 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1046 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1048 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1049 | e1000_reset_hw(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
| 1051 | /* make sure the EEPROM is good */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1052 | if (e1000_validate_eeprom_checksum(hw) < 0) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1053 | e_err(probe, "The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1054 | e1000_dump_eeprom(adapter); |
| 1055 | /* |
| 1056 | * set MAC address to all zeroes to invalidate and temporary |
| 1057 | * disable this device for the user. This blocks regular |
| 1058 | * traffic while still permitting ethtool ioctls from reaching |
| 1059 | * the hardware as well as allowing the user to run the |
| 1060 | * interface after manually setting a hw addr using |
| 1061 | * `ip set address` |
| 1062 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1063 | memset(hw->mac_addr, 0, netdev->addr_len); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1064 | } else { |
| 1065 | /* copy the MAC address out of the EEPROM */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1066 | if (e1000_read_mac_addr(hw)) |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1067 | e_err(probe, "EEPROM Read Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1069 | /* don't block initalization here due to bad MAC address */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1070 | memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len); |
| 1071 | memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1073 | if (!is_valid_ether_addr(netdev->perm_addr)) |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1074 | e_err(probe, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | init_timer(&adapter->tx_fifo_stall_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 1077 | adapter->tx_fifo_stall_timer.function = e1000_82547_tx_fifo_stall; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1078 | adapter->tx_fifo_stall_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
| 1080 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 1081 | adapter->watchdog_timer.function = e1000_watchdog; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | init_timer(&adapter->phy_info_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 1085 | adapter->phy_info_timer.function = e1000_update_phy_info; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1086 | adapter->phy_info_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 1088 | INIT_WORK(&adapter->fifo_stall_task, e1000_82547_tx_fifo_stall_task); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1089 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 1090 | INIT_WORK(&adapter->phy_info_task, e1000_update_phy_info_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | e1000_check_options(adapter); |
| 1093 | |
| 1094 | /* Initial Wake on LAN setting |
| 1095 | * If APM wake is enabled in the EEPROM, |
| 1096 | * enable the ACPI Magic Packet filter |
| 1097 | */ |
| 1098 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1099 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | case e1000_82542_rev2_0: |
| 1101 | case e1000_82542_rev2_1: |
| 1102 | case e1000_82543: |
| 1103 | break; |
| 1104 | case e1000_82544: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1105 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1107 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1108 | break; |
| 1109 | case e1000_82546: |
| 1110 | case e1000_82546_rev_3: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1111 | if (er32(STATUS) & E1000_STATUS_FUNC_1){ |
| 1112 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1114 | break; |
| 1115 | } |
| 1116 | /* Fall Through */ |
| 1117 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1118 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1120 | break; |
| 1121 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1122 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1123 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1124 | |
| 1125 | /* now that we have the eeprom settings, apply the special cases |
| 1126 | * where the eeprom may be wrong or the board simply won't support |
| 1127 | * wake on lan on a particular port */ |
| 1128 | switch (pdev->device) { |
| 1129 | case E1000_DEV_ID_82546GB_PCIE: |
| 1130 | adapter->eeprom_wol = 0; |
| 1131 | break; |
| 1132 | case E1000_DEV_ID_82546EB_FIBER: |
| 1133 | case E1000_DEV_ID_82546GB_FIBER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1134 | /* Wake events only supported on port A for dual fiber |
| 1135 | * regardless of eeprom setting */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1136 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1137 | adapter->eeprom_wol = 0; |
| 1138 | break; |
| 1139 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1140 | /* if quad port adapter, disable WoL on all but port A */ |
| 1141 | if (global_quad_port_a != 0) |
| 1142 | adapter->eeprom_wol = 0; |
| 1143 | else |
| 1144 | adapter->quad_port_a = 1; |
| 1145 | /* Reset for multiple quad port adapters */ |
| 1146 | if (++global_quad_port_a == 4) |
| 1147 | global_quad_port_a = 0; |
| 1148 | break; |
| 1149 | } |
| 1150 | |
| 1151 | /* initialize the wol settings based on the eeprom settings */ |
| 1152 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | de12648 | 2008-11-07 20:30:19 +0000 | [diff] [blame] | 1153 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1155 | /* Auto detect PHY address */ |
| 1156 | if (hw->mac_type == e1000_ce4100) { |
| 1157 | for (i = 0; i < 32; i++) { |
| 1158 | hw->phy_addr = i; |
| 1159 | e1000_read_phy_reg(hw, PHY_ID2, &tmp); |
| 1160 | if (tmp == 0 || tmp == 0xFF) { |
| 1161 | if (i == 31) |
| 1162 | goto err_eeprom; |
| 1163 | continue; |
| 1164 | } else |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | /* reset the hardware with the new settings */ |
| 1170 | e1000_reset(adapter); |
| 1171 | |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1172 | strcpy(netdev->name, "eth%d"); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1173 | err = register_netdev(netdev); |
| 1174 | if (err) |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1175 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1176 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1177 | /* print bus type/speed/width info */ |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1178 | e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n", |
Joe Perches | 7837e58 | 2010-06-11 12:51:49 +0000 | [diff] [blame] | 1179 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""), |
| 1180 | ((hw->bus_speed == e1000_bus_speed_133) ? 133 : |
| 1181 | (hw->bus_speed == e1000_bus_speed_120) ? 120 : |
| 1182 | (hw->bus_speed == e1000_bus_speed_100) ? 100 : |
| 1183 | (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33), |
| 1184 | ((hw->bus_width == e1000_bus_width_64) ? 64 : 32), |
| 1185 | netdev->dev_addr); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1186 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1187 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 1188 | netif_carrier_off(netdev); |
| 1189 | |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1190 | e_info(probe, "Intel(R) PRO/1000 Network Connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | cards_found++; |
| 1193 | return 0; |
| 1194 | |
| 1195 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1196 | err_eeprom: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1197 | e1000_phy_hw_reset(hw); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1198 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1199 | if (hw->flash_address) |
| 1200 | iounmap(hw->flash_address); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1201 | kfree(adapter->tx_ring); |
| 1202 | kfree(adapter->rx_ring); |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 1203 | err_dma: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | err_sw_init: |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1205 | err_mdio_ioremap: |
| 1206 | iounmap(ce4100_gbe_mdio_base_virt); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1207 | iounmap(hw->hw_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | err_ioremap: |
| 1209 | free_netdev(netdev); |
| 1210 | err_alloc_etherdev: |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1211 | pci_release_selected_regions(pdev, bars); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1212 | err_pci_reg: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1213 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | return err; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * e1000_remove - Device Removal Routine |
| 1219 | * @pdev: PCI device information struct |
| 1220 | * |
| 1221 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1222 | * that it should release a PCI device. The could be caused by a |
| 1223 | * Hot-Plug event, or because the driver is going to be removed from |
| 1224 | * memory. |
| 1225 | **/ |
| 1226 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1227 | static void __devexit e1000_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
| 1229 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1230 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1231 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 1233 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1234 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 1235 | del_timer_sync(&adapter->watchdog_timer); |
| 1236 | del_timer_sync(&adapter->phy_info_timer); |
| 1237 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1238 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1239 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1240 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1242 | unregister_netdev(netdev); |
| 1243 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1244 | e1000_phy_hw_reset(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1246 | kfree(adapter->tx_ring); |
| 1247 | kfree(adapter->rx_ring); |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1248 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1249 | iounmap(hw->hw_addr); |
| 1250 | if (hw->flash_address) |
| 1251 | iounmap(hw->flash_address); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1252 | pci_release_selected_regions(pdev, adapter->bars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | |
| 1254 | free_netdev(netdev); |
| 1255 | |
| 1256 | pci_disable_device(pdev); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1261 | * @adapter: board private structure to initialize |
| 1262 | * |
| 1263 | * e1000_sw_init initializes the Adapter private data structure. |
Jesse Brandeburg | e508be1 | 2010-09-07 21:01:12 +0000 | [diff] [blame] | 1264 | * e1000_init_hw_struct MUST be called before this function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | **/ |
| 1266 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1267 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | { |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1269 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1271 | adapter->num_tx_queues = 1; |
| 1272 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1273 | |
| 1274 | if (e1000_alloc_queues(adapter)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1275 | e_err(probe, "Unable to allocate memory for queues\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1276 | return -ENOMEM; |
| 1277 | } |
| 1278 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1279 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1280 | e1000_irq_disable(adapter); |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1284 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1290 | * e1000_alloc_queues - Allocate memory for all rings |
| 1291 | * @adapter: board private structure to initialize |
| 1292 | * |
| 1293 | * We allocate one ring per queue at run-time since we don't know the |
Wang Chen | 3e1d7cd | 2008-12-03 22:07:10 -0800 | [diff] [blame] | 1294 | * number of queues at compile-time. |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1295 | **/ |
| 1296 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1297 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1298 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1299 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1300 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1301 | if (!adapter->tx_ring) |
| 1302 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1303 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1304 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1305 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1306 | if (!adapter->rx_ring) { |
| 1307 | kfree(adapter->tx_ring); |
| 1308 | return -ENOMEM; |
| 1309 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1310 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1311 | return E1000_SUCCESS; |
| 1312 | } |
| 1313 | |
| 1314 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | * e1000_open - Called when a network interface is made active |
| 1316 | * @netdev: network interface device structure |
| 1317 | * |
| 1318 | * Returns 0 on success, negative value on failure |
| 1319 | * |
| 1320 | * The open entry point is called when a network interface is made |
| 1321 | * active by the system (IFF_UP). At this point all resources needed |
| 1322 | * for transmit and receive operations are allocated, the interrupt |
| 1323 | * handler is registered with the OS, the watchdog timer is started, |
| 1324 | * and the stack is notified that the interface is ready. |
| 1325 | **/ |
| 1326 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1327 | static int e1000_open(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1329 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1330 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | int err; |
| 1332 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1333 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1334 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1335 | return -EBUSY; |
| 1336 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1337 | netif_carrier_off(netdev); |
| 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1340 | err = e1000_setup_all_tx_resources(adapter); |
| 1341 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | goto err_setup_tx; |
| 1343 | |
| 1344 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1345 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1346 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1347 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1348 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1349 | e1000_power_up_phy(adapter); |
| 1350 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1351 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1352 | if ((hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1353 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1354 | e1000_update_mng_vlan(adapter); |
| 1355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1357 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1358 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1359 | * as soon as we call pci_request_irq, so we have to setup our |
| 1360 | * clean_rx handler before we do so. */ |
| 1361 | e1000_configure(adapter); |
| 1362 | |
| 1363 | err = e1000_request_irq(adapter); |
| 1364 | if (err) |
| 1365 | goto err_req_irq; |
| 1366 | |
| 1367 | /* From here on the code is the same as e1000_up() */ |
| 1368 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1369 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1370 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1371 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1372 | e1000_irq_enable(adapter); |
| 1373 | |
Ben Hutchings | 076152d | 2008-07-18 17:50:57 -0700 | [diff] [blame] | 1374 | netif_start_queue(netdev); |
| 1375 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1376 | /* fire a link status change interrupt to start the watchdog */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1377 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | return E1000_SUCCESS; |
| 1380 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1381 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1382 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1383 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1385 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | err_setup_tx: |
| 1387 | e1000_reset(adapter); |
| 1388 | |
| 1389 | return err; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * e1000_close - Disables a network interface |
| 1394 | * @netdev: network interface device structure |
| 1395 | * |
| 1396 | * Returns 0, this is not allowed to fail |
| 1397 | * |
| 1398 | * The close entry point is called when an interface is de-activated |
| 1399 | * by the OS. The hardware is still under the drivers control, but |
| 1400 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1401 | * hardware, and all transmit and receive resources are freed. |
| 1402 | **/ |
| 1403 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1404 | static int e1000_close(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1406 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1407 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1409 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1411 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1412 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1414 | e1000_free_all_tx_resources(adapter); |
| 1415 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1417 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1418 | * the same ID is registered on the host OS (let 8021q kill it) */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1419 | if ((hw->mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1420 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1421 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1422 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1423 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1424 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1431 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1432 | * @start: address of beginning of memory |
| 1433 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1435 | static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start, |
| 1436 | unsigned long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1438 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1439 | unsigned long begin = (unsigned long)start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | unsigned long end = begin + len; |
| 1441 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1442 | /* First rev 82545 and 82546 need to not allow any memory |
| 1443 | * write location to cross 64k boundary due to errata 23 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1444 | if (hw->mac_type == e1000_82545 || |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1445 | hw->mac_type == e1000_ce4100 || |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1446 | hw->mac_type == e1000_82546) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1447 | return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1450 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1455 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1456 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | * |
| 1458 | * Return 0 on success, negative on failure |
| 1459 | **/ |
| 1460 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1461 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1462 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | struct pci_dev *pdev = adapter->pdev; |
| 1465 | int size; |
| 1466 | |
| 1467 | size = sizeof(struct e1000_buffer) * txdr->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 1468 | txdr->buffer_info = vzalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1469 | if (!txdr->buffer_info) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1470 | e_err(probe, "Unable to allocate memory for the Tx descriptor " |
| 1471 | "ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | return -ENOMEM; |
| 1473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
| 1475 | /* round up to nearest 4K */ |
| 1476 | |
| 1477 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1478 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1480 | txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma, |
| 1481 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1482 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | vfree(txdr->buffer_info); |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1485 | e_err(probe, "Unable to allocate memory for the Tx descriptor " |
| 1486 | "ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | return -ENOMEM; |
| 1488 | } |
| 1489 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1490 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1492 | void *olddesc = txdr->desc; |
| 1493 | dma_addr_t olddma = txdr->dma; |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1494 | e_err(tx_err, "txdr align check failed: %u bytes at %p\n", |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1495 | txdr->size, txdr->desc); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1496 | /* Try again, without freeing the previous */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1497 | txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, |
| 1498 | &txdr->dma, GFP_KERNEL); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1499 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1500 | if (!txdr->desc) { |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1501 | dma_free_coherent(&pdev->dev, txdr->size, olddesc, |
| 1502 | olddma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | goto setup_tx_desc_die; |
| 1504 | } |
| 1505 | |
| 1506 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1507 | /* give up */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1508 | dma_free_coherent(&pdev->dev, txdr->size, txdr->desc, |
| 1509 | txdr->dma); |
| 1510 | dma_free_coherent(&pdev->dev, txdr->size, olddesc, |
| 1511 | olddma); |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1512 | e_err(probe, "Unable to allocate aligned memory " |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1513 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | vfree(txdr->buffer_info); |
| 1515 | return -ENOMEM; |
| 1516 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1517 | /* Free old allocation, new allocation was successful */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1518 | dma_free_coherent(&pdev->dev, txdr->size, olddesc, |
| 1519 | olddma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | memset(txdr->desc, 0, txdr->size); |
| 1523 | |
| 1524 | txdr->next_to_use = 0; |
| 1525 | txdr->next_to_clean = 0; |
| 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1531 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1532 | * (Descriptors) for all queues |
| 1533 | * @adapter: board private structure |
| 1534 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1535 | * Return 0 on success, negative on failure |
| 1536 | **/ |
| 1537 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1538 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1539 | { |
| 1540 | int i, err = 0; |
| 1541 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1542 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1543 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1544 | if (err) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1545 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1546 | for (i-- ; i >= 0; i--) |
| 1547 | e1000_free_tx_resources(adapter, |
| 1548 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1549 | break; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | return err; |
| 1554 | } |
| 1555 | |
| 1556 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1558 | * @adapter: board private structure |
| 1559 | * |
| 1560 | * Configure the Tx unit of the MAC after a reset. |
| 1561 | **/ |
| 1562 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1563 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1565 | u64 tdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1566 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1567 | u32 tdlen, tctl, tipg; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1568 | u32 ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | |
| 1570 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1571 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1572 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1573 | case 1: |
| 1574 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1575 | tdba = adapter->tx_ring[0].dma; |
| 1576 | tdlen = adapter->tx_ring[0].count * |
| 1577 | sizeof(struct e1000_tx_desc); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1578 | ew32(TDLEN, tdlen); |
| 1579 | ew32(TDBAH, (tdba >> 32)); |
| 1580 | ew32(TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 1581 | ew32(TDT, 0); |
| 1582 | ew32(TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1583 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1584 | adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT); |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1585 | break; |
| 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
| 1588 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1589 | if ((hw->media_type == e1000_media_type_fiber || |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1590 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1591 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1592 | else |
| 1593 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1594 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1595 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | case e1000_82542_rev2_0: |
| 1597 | case e1000_82542_rev2_1: |
| 1598 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1599 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1600 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | break; |
| 1602 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1603 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1604 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1605 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1607 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1608 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1609 | ew32(TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
| 1611 | /* Set the Tx Interrupt Delay register */ |
| 1612 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1613 | ew32(TIDV, adapter->tx_int_delay); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1614 | if (hw->mac_type >= e1000_82540) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1615 | ew32(TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
| 1617 | /* Program the Transmit Control Register */ |
| 1618 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1619 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1621 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1623 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1624 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
| 1626 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1627 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1628 | |
| 1629 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1630 | if (adapter->tx_int_delay) |
| 1631 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1633 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1635 | else |
| 1636 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1637 | |
| 1638 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1639 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1640 | if (hw->mac_type == e1000_82544 && |
| 1641 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1643 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1644 | ew32(TCTL, tctl); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1650 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1651 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | * |
| 1653 | * Returns 0 on success, negative on failure |
| 1654 | **/ |
| 1655 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1656 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1657 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1660 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
| 1662 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 1663 | rxdr->buffer_info = vzalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1664 | if (!rxdr->buffer_info) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1665 | e_err(probe, "Unable to allocate memory for the Rx descriptor " |
| 1666 | "ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | return -ENOMEM; |
| 1668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1670 | desc_len = sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | /* Round up to nearest 4K */ |
| 1673 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1674 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1675 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1677 | rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma, |
| 1678 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1680 | if (!rxdr->desc) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1681 | e_err(probe, "Unable to allocate memory for the Rx descriptor " |
| 1682 | "ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | vfree(rxdr->buffer_info); |
| 1685 | return -ENOMEM; |
| 1686 | } |
| 1687 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1688 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1690 | void *olddesc = rxdr->desc; |
| 1691 | dma_addr_t olddma = rxdr->dma; |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1692 | e_err(rx_err, "rxdr align check failed: %u bytes at %p\n", |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1693 | rxdr->size, rxdr->desc); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1694 | /* Try again, without freeing the previous */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1695 | rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, |
| 1696 | &rxdr->dma, GFP_KERNEL); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1697 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1698 | if (!rxdr->desc) { |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1699 | dma_free_coherent(&pdev->dev, rxdr->size, olddesc, |
| 1700 | olddma); |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1701 | e_err(probe, "Unable to allocate memory for the Rx " |
| 1702 | "descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | goto setup_rx_desc_die; |
| 1704 | } |
| 1705 | |
| 1706 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1707 | /* give up */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1708 | dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc, |
| 1709 | rxdr->dma); |
| 1710 | dma_free_coherent(&pdev->dev, rxdr->size, olddesc, |
| 1711 | olddma); |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1712 | e_err(probe, "Unable to allocate aligned memory for " |
| 1713 | "the Rx descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1714 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1716 | /* Free old allocation, new allocation was successful */ |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1717 | dma_free_coherent(&pdev->dev, rxdr->size, olddesc, |
| 1718 | olddma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | memset(rxdr->desc, 0, rxdr->size); |
| 1722 | |
| 1723 | rxdr->next_to_clean = 0; |
| 1724 | rxdr->next_to_use = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 1725 | rxdr->rx_skb_top = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
| 1727 | return 0; |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1731 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1732 | * (Descriptors) for all queues |
| 1733 | * @adapter: board private structure |
| 1734 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1735 | * Return 0 on success, negative on failure |
| 1736 | **/ |
| 1737 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1738 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1739 | { |
| 1740 | int i, err = 0; |
| 1741 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1742 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1743 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1744 | if (err) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 1745 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1746 | for (i-- ; i >= 0; i--) |
| 1747 | e1000_free_rx_resources(adapter, |
| 1748 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1749 | break; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | return err; |
| 1754 | } |
| 1755 | |
| 1756 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1757 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | * @adapter: Board private structure |
| 1759 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1760 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1762 | struct e1000_hw *hw = &adapter->hw; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1763 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1765 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
| 1767 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1768 | |
| 1769 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1770 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1771 | (hw->mc_filter_type << E1000_RCTL_MO_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1773 | if (hw->tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | rctl |= E1000_RCTL_SBP; |
| 1775 | else |
| 1776 | rctl &= ~E1000_RCTL_SBP; |
| 1777 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1778 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1779 | rctl &= ~E1000_RCTL_LPE; |
| 1780 | else |
| 1781 | rctl |= E1000_RCTL_LPE; |
| 1782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1784 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1785 | rctl |= E1000_RCTL_BSEX; |
| 1786 | switch (adapter->rx_buffer_len) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1787 | case E1000_RXBUFFER_2048: |
| 1788 | default: |
| 1789 | rctl |= E1000_RCTL_SZ_2048; |
| 1790 | rctl &= ~E1000_RCTL_BSEX; |
| 1791 | break; |
| 1792 | case E1000_RXBUFFER_4096: |
| 1793 | rctl |= E1000_RCTL_SZ_4096; |
| 1794 | break; |
| 1795 | case E1000_RXBUFFER_8192: |
| 1796 | rctl |= E1000_RCTL_SZ_8192; |
| 1797 | break; |
| 1798 | case E1000_RXBUFFER_16384: |
| 1799 | rctl |= E1000_RCTL_SZ_16384; |
| 1800 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1803 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1808 | * @adapter: board private structure |
| 1809 | * |
| 1810 | * Configure the Rx unit of the MAC after a reset. |
| 1811 | **/ |
| 1812 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1813 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1815 | u64 rdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1816 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1817 | u32 rdlen, rctl, rxcsum; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1818 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 1819 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 1820 | rdlen = adapter->rx_ring[0].count * |
| 1821 | sizeof(struct e1000_rx_desc); |
| 1822 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 1823 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
| 1824 | } else { |
| 1825 | rdlen = adapter->rx_ring[0].count * |
| 1826 | sizeof(struct e1000_rx_desc); |
| 1827 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1828 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
| 1831 | /* disable receives while setting up the descriptors */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1832 | rctl = er32(RCTL); |
| 1833 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
| 1835 | /* set the Receive Delay Timer Register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1836 | ew32(RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1838 | if (hw->mac_type >= e1000_82540) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1839 | ew32(RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 1840 | if (adapter->itr_setting != 0) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1841 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1844 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1845 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1846 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1847 | case 1: |
| 1848 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1849 | rdba = adapter->rx_ring[0].dma; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1850 | ew32(RDLEN, rdlen); |
| 1851 | ew32(RDBAH, (rdba >> 32)); |
| 1852 | ew32(RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 1853 | ew32(RDT, 0); |
| 1854 | ew32(RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1855 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 1856 | adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1857 | break; |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1858 | } |
| 1859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1861 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1862 | rxcsum = er32(RXCSUM); |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1863 | if (adapter->rx_csum) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1864 | rxcsum |= E1000_RXCSUM_TUOFL; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1865 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1866 | /* don't need to clear IPPCSE as it defaults to 0 */ |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1867 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1868 | ew32(RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | /* Enable Receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1872 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1876 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 1877 | * @adapter: board private structure |
| 1878 | * @tx_ring: Tx descriptor ring for a specific queue |
| 1879 | * |
| 1880 | * Free all transmit software resources |
| 1881 | **/ |
| 1882 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1883 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 1884 | struct e1000_tx_ring *tx_ring) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1885 | { |
| 1886 | struct pci_dev *pdev = adapter->pdev; |
| 1887 | |
| 1888 | e1000_clean_tx_ring(adapter, tx_ring); |
| 1889 | |
| 1890 | vfree(tx_ring->buffer_info); |
| 1891 | tx_ring->buffer_info = NULL; |
| 1892 | |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1893 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 1894 | tx_ring->dma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1895 | |
| 1896 | tx_ring->desc = NULL; |
| 1897 | } |
| 1898 | |
| 1899 | /** |
| 1900 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | * @adapter: board private structure |
| 1902 | * |
| 1903 | * Free all transmit software resources |
| 1904 | **/ |
| 1905 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1906 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1908 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1910 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1911 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1914 | static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 1915 | struct e1000_buffer *buffer_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | { |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 1917 | if (buffer_info->dma) { |
| 1918 | if (buffer_info->mapped_as_page) |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1919 | dma_unmap_page(&adapter->pdev->dev, buffer_info->dma, |
| 1920 | buffer_info->length, DMA_TO_DEVICE); |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 1921 | else |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1922 | dma_unmap_single(&adapter->pdev->dev, buffer_info->dma, |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 1923 | buffer_info->length, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 1924 | DMA_TO_DEVICE); |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 1925 | buffer_info->dma = 0; |
| 1926 | } |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 1927 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 1929 | buffer_info->skb = NULL; |
| 1930 | } |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 1931 | buffer_info->time_stamp = 0; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 1932 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * e1000_clean_tx_ring - Free Tx Buffers |
| 1937 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1938 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | **/ |
| 1940 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1941 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 1942 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1944 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | struct e1000_buffer *buffer_info; |
| 1946 | unsigned long size; |
| 1947 | unsigned int i; |
| 1948 | |
| 1949 | /* Free all the Tx ring sk_buffs */ |
| 1950 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1951 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | buffer_info = &tx_ring->buffer_info[i]; |
| 1953 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 1954 | } |
| 1955 | |
| 1956 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 1957 | memset(tx_ring->buffer_info, 0, size); |
| 1958 | |
| 1959 | /* Zero out the descriptor ring */ |
| 1960 | |
| 1961 | memset(tx_ring->desc, 0, tx_ring->size); |
| 1962 | |
| 1963 | tx_ring->next_to_use = 0; |
| 1964 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1965 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1967 | writel(0, hw->hw_addr + tx_ring->tdh); |
| 1968 | writel(0, hw->hw_addr + tx_ring->tdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 1973 | * @adapter: board private structure |
| 1974 | **/ |
| 1975 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1976 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1977 | { |
| 1978 | int i; |
| 1979 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1980 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1981 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | /** |
| 1985 | * e1000_free_rx_resources - Free Rx Resources |
| 1986 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1987 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | * |
| 1989 | * Free all receive software resources |
| 1990 | **/ |
| 1991 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1992 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 1993 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | struct pci_dev *pdev = adapter->pdev; |
| 1996 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1997 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
| 1999 | vfree(rx_ring->buffer_info); |
| 2000 | rx_ring->buffer_info = NULL; |
| 2001 | |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2002 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2003 | rx_ring->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | |
| 2005 | rx_ring->desc = NULL; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2009 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2011 | * |
| 2012 | * Free all receive software resources |
| 2013 | **/ |
| 2014 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2015 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2016 | { |
| 2017 | int i; |
| 2018 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2019 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2020 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2025 | * @adapter: board private structure |
| 2026 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | **/ |
| 2028 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2029 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2030 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2032 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | struct e1000_buffer *buffer_info; |
| 2034 | struct pci_dev *pdev = adapter->pdev; |
| 2035 | unsigned long size; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2036 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
| 2038 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2039 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2041 | if (buffer_info->dma && |
| 2042 | adapter->clean_rx == e1000_clean_rx_irq) { |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2043 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2044 | buffer_info->length, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2045 | DMA_FROM_DEVICE); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2046 | } else if (buffer_info->dma && |
| 2047 | adapter->clean_rx == e1000_clean_jumbo_rx_irq) { |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2048 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
| 2049 | buffer_info->length, |
| 2050 | DMA_FROM_DEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2053 | buffer_info->dma = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2054 | if (buffer_info->page) { |
| 2055 | put_page(buffer_info->page); |
| 2056 | buffer_info->page = NULL; |
| 2057 | } |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2058 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | dev_kfree_skb(buffer_info->skb); |
| 2060 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2064 | /* there also may be some cached data from a chained receive */ |
| 2065 | if (rx_ring->rx_skb_top) { |
| 2066 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 2067 | rx_ring->rx_skb_top = NULL; |
| 2068 | } |
| 2069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2071 | memset(rx_ring->buffer_info, 0, size); |
| 2072 | |
| 2073 | /* Zero out the descriptor ring */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2075 | |
| 2076 | rx_ring->next_to_clean = 0; |
| 2077 | rx_ring->next_to_use = 0; |
| 2078 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2079 | writel(0, hw->hw_addr + rx_ring->rdh); |
| 2080 | writel(0, hw->hw_addr + rx_ring->rdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2085 | * @adapter: board private structure |
| 2086 | **/ |
| 2087 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2088 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2089 | { |
| 2090 | int i; |
| 2091 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2092 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2093 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2097 | * and memory write and invalidate disabled for certain operations |
| 2098 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2099 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2101 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2103 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2105 | e1000_pci_clear_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2107 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | rctl |= E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2109 | ew32(RCTL, rctl); |
| 2110 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | mdelay(5); |
| 2112 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2113 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2114 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2117 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2119 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2121 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2123 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | rctl &= ~E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2125 | ew32(RCTL, rctl); |
| 2126 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | mdelay(5); |
| 2128 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2129 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 2130 | e1000_pci_set_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2132 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2133 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2134 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2135 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2136 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2142 | * @netdev: network interface device structure |
| 2143 | * @p: pointer to an address structure |
| 2144 | * |
| 2145 | * Returns 0 on success, negative on failure |
| 2146 | **/ |
| 2147 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2148 | static int e1000_set_mac(struct net_device *netdev, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2150 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2151 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | struct sockaddr *addr = p; |
| 2153 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2154 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | return -EADDRNOTAVAIL; |
| 2156 | |
| 2157 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2158 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2159 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | e1000_enter_82542_rst(adapter); |
| 2161 | |
| 2162 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2163 | memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2165 | e1000_rar_set(hw, hw->mac_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2167 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | e1000_leave_82542_rst(adapter); |
| 2169 | |
| 2170 | return 0; |
| 2171 | } |
| 2172 | |
| 2173 | /** |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2174 | * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | * @netdev: network interface device structure |
| 2176 | * |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2177 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 2178 | * address lists or the network interface flags are updated. This routine is |
| 2179 | * responsible for configuring the hardware for proper unicast, multicast, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | * promiscuous mode, and all-multi behavior. |
| 2181 | **/ |
| 2182 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2183 | static void e1000_set_rx_mode(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2185 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2187 | struct netdev_hw_addr *ha; |
| 2188 | bool use_uc = false; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2189 | u32 rctl; |
| 2190 | u32 hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2191 | int i, rar_entries = E1000_RAR_ENTRIES; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2192 | int mta_reg_count = E1000_NUM_MTA_REGISTERS; |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2193 | u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC); |
| 2194 | |
| 2195 | if (!mcarray) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 2196 | e_err(probe, "memory allocation failed\n"); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2197 | return; |
| 2198 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2199 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2200 | /* Check for Promiscuous and All Multicast modes */ |
| 2201 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2202 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2204 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2206 | rctl &= ~E1000_RCTL_VFE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | } else { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2208 | if (netdev->flags & IFF_ALLMULTI) |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2209 | rctl |= E1000_RCTL_MPE; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2210 | else |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2211 | rctl &= ~E1000_RCTL_MPE; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2212 | /* Enable VLAN filter if there is a VLAN */ |
| 2213 | if (adapter->vlgrp) |
| 2214 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2215 | } |
| 2216 | |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 2217 | if (netdev_uc_count(netdev) > rar_entries - 1) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2218 | rctl |= E1000_RCTL_UPE; |
| 2219 | } else if (!(netdev->flags & IFF_PROMISC)) { |
| 2220 | rctl &= ~E1000_RCTL_UPE; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2221 | use_uc = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2224 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
| 2226 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2227 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2228 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | e1000_enter_82542_rst(adapter); |
| 2230 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2231 | /* load the first 14 addresses into the exact filters 1-14. Unicast |
| 2232 | * addresses take precedence to avoid disabling unicast filtering |
| 2233 | * when possible. |
| 2234 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 2235 | * RAR 0 is used for the station MAC address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | * if there are not 14 addresses, go ahead and clear the filters |
| 2237 | */ |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2238 | i = 1; |
| 2239 | if (use_uc) |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 2240 | netdev_for_each_uc_addr(ha, netdev) { |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2241 | if (i == rar_entries) |
| 2242 | break; |
| 2243 | e1000_rar_set(hw, ha->addr, i++); |
| 2244 | } |
| 2245 | |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2246 | netdev_for_each_mc_addr(ha, netdev) { |
Jiri Pirko | 7a81e9f | 2010-02-22 09:10:44 +0000 | [diff] [blame] | 2247 | if (i == rar_entries) { |
| 2248 | /* load any remaining addresses into the hash table */ |
| 2249 | u32 hash_reg, hash_bit, mta; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2250 | hash_value = e1000_hash_mc_addr(hw, ha->addr); |
Jiri Pirko | 7a81e9f | 2010-02-22 09:10:44 +0000 | [diff] [blame] | 2251 | hash_reg = (hash_value >> 5) & 0x7F; |
| 2252 | hash_bit = hash_value & 0x1F; |
| 2253 | mta = (1 << hash_bit); |
| 2254 | mcarray[hash_reg] |= mta; |
Jiri Pirko | 10886af | 2010-02-23 01:19:22 -0800 | [diff] [blame] | 2255 | } else { |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2256 | e1000_rar_set(hw, ha->addr, i++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | } |
| 2258 | } |
| 2259 | |
Jiri Pirko | 7a81e9f | 2010-02-22 09:10:44 +0000 | [diff] [blame] | 2260 | for (; i < rar_entries; i++) { |
| 2261 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
| 2262 | E1000_WRITE_FLUSH(); |
| 2263 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
| 2264 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2267 | /* write the hash table completely, write from bottom to avoid |
| 2268 | * both stupid write combining chipsets, and flushing each write */ |
| 2269 | for (i = mta_reg_count - 1; i >= 0 ; i--) { |
| 2270 | /* |
| 2271 | * If we are on an 82544 has an errata where writing odd |
| 2272 | * offsets overwrites the previous even offset, but writing |
| 2273 | * backwards over the range solves the issue by always |
| 2274 | * writing the odd offset first |
| 2275 | */ |
| 2276 | E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]); |
| 2277 | } |
| 2278 | E1000_WRITE_FLUSH(); |
| 2279 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2280 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | e1000_leave_82542_rst(adapter); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2282 | |
| 2283 | kfree(mcarray); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2287 | * the phy */ |
| 2288 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2289 | static void e1000_update_phy_info(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2291 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 2292 | schedule_work(&adapter->phy_info_task); |
| 2293 | } |
| 2294 | |
| 2295 | static void e1000_update_phy_info_task(struct work_struct *work) |
| 2296 | { |
| 2297 | struct e1000_adapter *adapter = container_of(work, |
| 2298 | struct e1000_adapter, |
| 2299 | phy_info_task); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2300 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 2301 | |
| 2302 | rtnl_lock(); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2303 | e1000_phy_get_info(hw, &adapter->phy_info); |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 2304 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2309 | * @data: pointer to adapter cast into an unsigned long |
| 2310 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2311 | static void e1000_82547_tx_fifo_stall(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2313 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Jesse Brandeburg | 5cf42fc | 2010-09-22 18:22:17 +0000 | [diff] [blame] | 2314 | schedule_work(&adapter->fifo_stall_task); |
| 2315 | } |
| 2316 | |
| 2317 | /** |
| 2318 | * e1000_82547_tx_fifo_stall_task - task to complete work |
| 2319 | * @work: work struct contained inside adapter struct |
| 2320 | **/ |
| 2321 | static void e1000_82547_tx_fifo_stall_task(struct work_struct *work) |
| 2322 | { |
| 2323 | struct e1000_adapter *adapter = container_of(work, |
| 2324 | struct e1000_adapter, |
| 2325 | fifo_stall_task); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2326 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2328 | u32 tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 2330 | rtnl_lock(); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2331 | if (atomic_read(&adapter->tx_fifo_stall)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2332 | if ((er32(TDT) == er32(TDH)) && |
| 2333 | (er32(TDFT) == er32(TDFH)) && |
| 2334 | (er32(TDFTS) == er32(TDFHS))) { |
| 2335 | tctl = er32(TCTL); |
| 2336 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 2337 | ew32(TDFT, adapter->tx_head_addr); |
| 2338 | ew32(TDFH, adapter->tx_head_addr); |
| 2339 | ew32(TDFTS, adapter->tx_head_addr); |
| 2340 | ew32(TDFHS, adapter->tx_head_addr); |
| 2341 | ew32(TCTL, tctl); |
| 2342 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | |
| 2344 | adapter->tx_fifo_head = 0; |
| 2345 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2346 | netif_wake_queue(netdev); |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 2347 | } else if (!test_bit(__E1000_DOWN, &adapter->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2349 | } |
| 2350 | } |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 2351 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
Nick Nunley | b548192 | 2010-02-03 14:49:28 +0000 | [diff] [blame] | 2354 | bool e1000_has_link(struct e1000_adapter *adapter) |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2355 | { |
| 2356 | struct e1000_hw *hw = &adapter->hw; |
| 2357 | bool link_active = false; |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2358 | |
| 2359 | /* get_link_status is set on LSC (link status) interrupt or |
| 2360 | * rx sequence error interrupt. get_link_status will stay |
| 2361 | * false until the e1000_check_for_link establishes link |
| 2362 | * for copper adapters ONLY |
| 2363 | */ |
| 2364 | switch (hw->media_type) { |
| 2365 | case e1000_media_type_copper: |
| 2366 | if (hw->get_link_status) { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2367 | e1000_check_for_link(hw); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2368 | link_active = !hw->get_link_status; |
| 2369 | } else { |
| 2370 | link_active = true; |
| 2371 | } |
| 2372 | break; |
| 2373 | case e1000_media_type_fiber: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2374 | e1000_check_for_link(hw); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2375 | link_active = !!(er32(STATUS) & E1000_STATUS_LU); |
| 2376 | break; |
| 2377 | case e1000_media_type_internal_serdes: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2378 | e1000_check_for_link(hw); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2379 | link_active = hw->serdes_has_link; |
| 2380 | break; |
| 2381 | default: |
| 2382 | break; |
| 2383 | } |
| 2384 | |
| 2385 | return link_active; |
| 2386 | } |
| 2387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | /** |
| 2389 | * e1000_watchdog - Timer Call-back |
| 2390 | * @data: pointer to adapter cast into an unsigned long |
| 2391 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2392 | static void e1000_watchdog(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2394 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2395 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2397 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2398 | u32 link, tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2400 | link = e1000_has_link(adapter); |
| 2401 | if ((netif_carrier_ok(netdev)) && link) |
| 2402 | goto link_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2404 | if (link) { |
| 2405 | if (!netif_carrier_ok(netdev)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2406 | u32 ctrl; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2407 | bool txb2b = true; |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2408 | /* update snapshot of PHY registers on LSC */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2409 | e1000_get_speed_and_duplex(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | &adapter->link_speed, |
| 2411 | &adapter->link_duplex); |
| 2412 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2413 | ctrl = er32(CTRL); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2414 | pr_info("%s NIC Link is Up %d Mbps %s, " |
| 2415 | "Flow Control: %s\n", |
| 2416 | netdev->name, |
| 2417 | adapter->link_speed, |
| 2418 | adapter->link_duplex == FULL_DUPLEX ? |
| 2419 | "Full Duplex" : "Half Duplex", |
| 2420 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2421 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2422 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2423 | E1000_CTRL_TFCE) ? "TX" : "None"))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Emil Tantilov | 39ca5f0 | 2010-03-26 11:25:58 +0000 | [diff] [blame] | 2425 | /* adjust timeout factor according to speed/duplex */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2426 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2427 | switch (adapter->link_speed) { |
| 2428 | case SPEED_10: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2429 | txb2b = false; |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2430 | adapter->tx_timeout_factor = 16; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2431 | break; |
| 2432 | case SPEED_100: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2433 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2434 | /* maybe add some timeout factor ? */ |
| 2435 | break; |
| 2436 | } |
| 2437 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2438 | /* enable transmits in the hardware */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2439 | tctl = er32(TCTL); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2440 | tctl |= E1000_TCTL_EN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2441 | ew32(TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | netif_carrier_on(netdev); |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 2444 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 2445 | mod_timer(&adapter->phy_info_timer, |
| 2446 | round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | adapter->smartspeed = 0; |
| 2448 | } |
| 2449 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2450 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | adapter->link_speed = 0; |
| 2452 | adapter->link_duplex = 0; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2453 | pr_info("%s NIC Link is Down\n", |
| 2454 | netdev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | netif_carrier_off(netdev); |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 2456 | |
| 2457 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 2458 | mod_timer(&adapter->phy_info_timer, |
| 2459 | round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | e1000_smartspeed(adapter); |
| 2463 | } |
| 2464 | |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2465 | link_up: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | e1000_update_stats(adapter); |
| 2467 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2468 | hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | adapter->tpt_old = adapter->stats.tpt; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2470 | hw->collision_delta = adapter->stats.colc - adapter->colc_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | adapter->colc_old = adapter->stats.colc; |
| 2472 | |
| 2473 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2474 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2475 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2476 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2477 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2478 | e1000_update_adaptive(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2480 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2481 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | /* We've lost link, so the controller stops DMA, |
| 2483 | * but we've got queued Tx work that's never going |
| 2484 | * to get done, so reset controller to flush Tx. |
| 2485 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2486 | adapter->tx_timeout_count++; |
| 2487 | schedule_work(&adapter->reset_task); |
Jesse Brandeburg | c2d5ab4 | 2009-05-07 11:07:35 +0000 | [diff] [blame] | 2488 | /* return immediately since reset is imminent */ |
| 2489 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | } |
| 2491 | } |
| 2492 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 2493 | /* Simple mode for Interrupt Throttle Rate (ITR) */ |
| 2494 | if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) { |
| 2495 | /* |
| 2496 | * Symmetric Tx/Rx gets a reduced ITR=2000; |
| 2497 | * Total asymmetrical Tx or Rx gets ITR=8000; |
| 2498 | * everyone else is between 2000-8000. |
| 2499 | */ |
| 2500 | u32 goc = (adapter->gotcl + adapter->gorcl) / 10000; |
| 2501 | u32 dif = (adapter->gotcl > adapter->gorcl ? |
| 2502 | adapter->gotcl - adapter->gorcl : |
| 2503 | adapter->gorcl - adapter->gotcl) / 10000; |
| 2504 | u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 2505 | |
| 2506 | ew32(ITR, 1000000000 / (itr * 256)); |
| 2507 | } |
| 2508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2510 | ew32(ICS, E1000_ICS_RXDMT0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2512 | /* Force detection of hung controller every watchdog period */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2513 | adapter->detect_tx_hung = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | |
| 2515 | /* Reset the timer */ |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 2516 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 2517 | mod_timer(&adapter->watchdog_timer, |
| 2518 | round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2521 | enum latency_range { |
| 2522 | lowest_latency = 0, |
| 2523 | low_latency = 1, |
| 2524 | bulk_latency = 2, |
| 2525 | latency_invalid = 255 |
| 2526 | }; |
| 2527 | |
| 2528 | /** |
| 2529 | * e1000_update_itr - update the dynamic ITR value based on statistics |
Jesse Brandeburg | 8fce473 | 2009-09-25 12:18:41 +0000 | [diff] [blame] | 2530 | * @adapter: pointer to adapter |
| 2531 | * @itr_setting: current adapter->itr |
| 2532 | * @packets: the number of packets during this measurement interval |
| 2533 | * @bytes: the number of bytes during this measurement interval |
| 2534 | * |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2535 | * Stores a new ITR value based on packets and byte |
| 2536 | * counts during the last interrupt. The advantage of per interrupt |
| 2537 | * computation is faster updates and more accurate ITR for the current |
| 2538 | * traffic pattern. Constants in this function were computed |
| 2539 | * based on theoretical maximum wire speed and thresholds were set based |
| 2540 | * on testing data as well as attempting to minimize response time |
| 2541 | * while increasing bulk throughput. |
| 2542 | * this functionality is controlled by the InterruptThrottleRate module |
| 2543 | * parameter (see e1000_param.c) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2544 | **/ |
| 2545 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2546 | u16 itr_setting, int packets, int bytes) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2547 | { |
| 2548 | unsigned int retval = itr_setting; |
| 2549 | struct e1000_hw *hw = &adapter->hw; |
| 2550 | |
| 2551 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2552 | goto update_itr_done; |
| 2553 | |
| 2554 | if (packets == 0) |
| 2555 | goto update_itr_done; |
| 2556 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2557 | switch (itr_setting) { |
| 2558 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2559 | /* jumbo frames get bulk treatment*/ |
| 2560 | if (bytes/packets > 8000) |
| 2561 | retval = bulk_latency; |
| 2562 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2563 | retval = low_latency; |
| 2564 | break; |
| 2565 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2566 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2567 | /* jumbo frames need bulk latency setting */ |
| 2568 | if (bytes/packets > 8000) |
| 2569 | retval = bulk_latency; |
| 2570 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2571 | retval = bulk_latency; |
| 2572 | else if ((packets > 35)) |
| 2573 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2574 | } else if (bytes/packets > 2000) |
| 2575 | retval = bulk_latency; |
| 2576 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2577 | retval = lowest_latency; |
| 2578 | break; |
| 2579 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2580 | if (bytes > 25000) { |
| 2581 | if (packets > 35) |
| 2582 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2583 | } else if (bytes < 6000) { |
| 2584 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2585 | } |
| 2586 | break; |
| 2587 | } |
| 2588 | |
| 2589 | update_itr_done: |
| 2590 | return retval; |
| 2591 | } |
| 2592 | |
| 2593 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2594 | { |
| 2595 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2596 | u16 current_itr; |
| 2597 | u32 new_itr = adapter->itr; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2598 | |
| 2599 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2600 | return; |
| 2601 | |
| 2602 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2603 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2604 | current_itr = 0; |
| 2605 | new_itr = 4000; |
| 2606 | goto set_itr_now; |
| 2607 | } |
| 2608 | |
| 2609 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2610 | adapter->tx_itr, |
| 2611 | adapter->total_tx_packets, |
| 2612 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2613 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2614 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2615 | adapter->tx_itr = low_latency; |
| 2616 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2617 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2618 | adapter->rx_itr, |
| 2619 | adapter->total_rx_packets, |
| 2620 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2621 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2622 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2623 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2624 | |
| 2625 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2626 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2627 | switch (current_itr) { |
| 2628 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2629 | case lowest_latency: |
| 2630 | new_itr = 70000; |
| 2631 | break; |
| 2632 | case low_latency: |
| 2633 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2634 | break; |
| 2635 | case bulk_latency: |
| 2636 | new_itr = 4000; |
| 2637 | break; |
| 2638 | default: |
| 2639 | break; |
| 2640 | } |
| 2641 | |
| 2642 | set_itr_now: |
| 2643 | if (new_itr != adapter->itr) { |
| 2644 | /* this attempts to bias the interrupt rate towards Bulk |
| 2645 | * by adding intermediate steps when interrupt rate is |
| 2646 | * increasing */ |
| 2647 | new_itr = new_itr > adapter->itr ? |
| 2648 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2649 | new_itr; |
| 2650 | adapter->itr = new_itr; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2651 | ew32(ITR, 1000000000 / (new_itr * 256)); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2652 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2653 | } |
| 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2656 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2657 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2658 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2660 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2661 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2662 | static int e1000_tso(struct e1000_adapter *adapter, |
| 2663 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2666 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2668 | u32 cmd_length = 0; |
| 2669 | u16 ipcse = 0, tucse, mss; |
| 2670 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | int err; |
| 2672 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2673 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | if (skb_header_cloned(skb)) { |
| 2675 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2676 | if (err) |
| 2677 | return err; |
| 2678 | } |
| 2679 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2680 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2681 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2682 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2683 | struct iphdr *iph = ip_hdr(skb); |
| 2684 | iph->tot_len = 0; |
| 2685 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2686 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2687 | iph->daddr, 0, |
| 2688 | IPPROTO_TCP, |
| 2689 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2690 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2691 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2692 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2693 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2694 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2695 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2696 | &ipv6_hdr(skb)->daddr, |
| 2697 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2698 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2699 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2700 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2701 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2702 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2703 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | tucse = 0; |
| 2705 | |
| 2706 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2707 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2709 | i = tx_ring->next_to_use; |
| 2710 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2711 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
| 2713 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2714 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2715 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2716 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2717 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2718 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2719 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2720 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2721 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2722 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2723 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2724 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2725 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2726 | if (++i == tx_ring->count) i = 0; |
| 2727 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2729 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2731 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2734 | static bool e1000_tx_csum(struct e1000_adapter *adapter, |
| 2735 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | { |
| 2737 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2738 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2740 | u8 css; |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2741 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2743 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 2744 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2746 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2747 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2748 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 2749 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2750 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2751 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2752 | /* XXX not handling all IPV6 headers */ |
| 2753 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 2754 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2755 | break; |
| 2756 | default: |
| 2757 | if (unlikely(net_ratelimit())) |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 2758 | e_warn(drv, "checksum_partial proto=%x!\n", |
| 2759 | skb->protocol); |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2760 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | } |
| 2762 | |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 2763 | css = skb_checksum_start_offset(skb); |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2764 | |
| 2765 | i = tx_ring->next_to_use; |
| 2766 | buffer_info = &tx_ring->buffer_info[i]; |
| 2767 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 2768 | |
| 2769 | context_desc->lower_setup.ip_config = 0; |
| 2770 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2771 | context_desc->upper_setup.tcp_fields.tucso = |
| 2772 | css + skb->csum_offset; |
| 2773 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2774 | context_desc->tcp_seg_setup.data = 0; |
| 2775 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 2776 | |
| 2777 | buffer_info->time_stamp = jiffies; |
| 2778 | buffer_info->next_to_watch = i; |
| 2779 | |
| 2780 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2781 | tx_ring->next_to_use = i; |
| 2782 | |
| 2783 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | #define E1000_MAX_TXD_PWR 12 |
| 2787 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2788 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2789 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 2790 | struct e1000_tx_ring *tx_ring, |
| 2791 | struct sk_buff *skb, unsigned int first, |
| 2792 | unsigned int max_per_txd, unsigned int nr_frags, |
| 2793 | unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2795 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2796 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2797 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2798 | unsigned int len = skb_headlen(skb); |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2799 | unsigned int offset = 0, size, count = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | |
| 2802 | i = tx_ring->next_to_use; |
| 2803 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2804 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2805 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2807 | /* Workaround for Controller erratum -- |
| 2808 | * descriptor for non-tso packet in a linear SKB that follows a |
| 2809 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2810 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2811 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2812 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2813 | tx_ring->last_tx_tso = 0; |
| 2814 | size -= 4; |
| 2815 | } |
| 2816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | /* Workaround for premature desc write-backs |
| 2818 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2819 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2821 | /* work-around for errata 10 and it applies |
| 2822 | * to all controllers in PCI-X mode |
| 2823 | * The fix is to make sure that the first descriptor of a |
| 2824 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 2825 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2826 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2827 | (size > 2015) && count == 0)) |
| 2828 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 2831 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2832 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 2834 | size > 4)) |
| 2835 | size -= 4; |
| 2836 | |
| 2837 | buffer_info->length = size; |
Jesse Brandeburg | cdd7549 | 2009-09-25 12:18:07 +0000 | [diff] [blame] | 2838 | /* set time_stamp *before* dma to help avoid a possible race */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2840 | buffer_info->mapped_as_page = false; |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2841 | buffer_info->dma = dma_map_single(&pdev->dev, |
| 2842 | skb->data + offset, |
| 2843 | size, DMA_TO_DEVICE); |
| 2844 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2845 | goto dma_error; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2846 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
| 2848 | len -= size; |
| 2849 | offset += size; |
| 2850 | count++; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2851 | if (len) { |
| 2852 | i++; |
| 2853 | if (unlikely(i == tx_ring->count)) |
| 2854 | i = 0; |
| 2855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2858 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | struct skb_frag_struct *frag; |
| 2860 | |
| 2861 | frag = &skb_shinfo(skb)->frags[f]; |
| 2862 | len = frag->size; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2863 | offset = frag->page_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2865 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2866 | i++; |
| 2867 | if (unlikely(i == tx_ring->count)) |
| 2868 | i = 0; |
| 2869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | buffer_info = &tx_ring->buffer_info[i]; |
| 2871 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | /* Workaround for premature desc write-backs |
| 2873 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2874 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | /* Workaround for potential 82544 hang in PCI-X. |
| 2877 | * Avoid terminating buffers within evenly-aligned |
| 2878 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2879 | if (unlikely(adapter->pcix_82544 && |
Jesse Brandeburg | 8fce473 | 2009-09-25 12:18:41 +0000 | [diff] [blame] | 2880 | !((unsigned long)(page_to_phys(frag->page) + offset |
| 2881 | + size - 1) & 4) && |
| 2882 | size > 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | size -= 4; |
| 2884 | |
| 2885 | buffer_info->length = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2887 | buffer_info->mapped_as_page = true; |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2888 | buffer_info->dma = dma_map_page(&pdev->dev, frag->page, |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2889 | offset, size, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 2890 | DMA_TO_DEVICE); |
| 2891 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2892 | goto dma_error; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2893 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | |
| 2895 | len -= size; |
| 2896 | offset += size; |
| 2897 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |
| 2899 | } |
| 2900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | tx_ring->buffer_info[i].skb = skb; |
| 2902 | tx_ring->buffer_info[first].next_to_watch = i; |
| 2903 | |
| 2904 | return count; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2905 | |
| 2906 | dma_error: |
| 2907 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 2908 | buffer_info->dma = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2909 | if (count) |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2910 | count--; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2911 | |
| 2912 | while (count--) { |
| 2913 | if (i==0) |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2914 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 2915 | i--; |
Alexander Duyck | 602c055 | 2009-12-02 16:46:00 +0000 | [diff] [blame] | 2916 | buffer_info = &tx_ring->buffer_info[i]; |
| 2917 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2918 | } |
| 2919 | |
| 2920 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2923 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 2924 | struct e1000_tx_ring *tx_ring, int tx_flags, |
| 2925 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2927 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | struct e1000_tx_desc *tx_desc = NULL; |
| 2929 | struct e1000_buffer *buffer_info; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2930 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | unsigned int i; |
| 2932 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2933 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 2935 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2936 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2937 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2938 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2939 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2942 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 2944 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2945 | } |
| 2946 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2947 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | txd_lower |= E1000_TXD_CMD_VLE; |
| 2949 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 2950 | } |
| 2951 | |
| 2952 | i = tx_ring->next_to_use; |
| 2953 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2954 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | buffer_info = &tx_ring->buffer_info[i]; |
| 2956 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 2957 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2958 | tx_desc->lower.data = |
| 2959 | cpu_to_le32(txd_lower | buffer_info->length); |
| 2960 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2961 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 2965 | |
| 2966 | /* Force memory writes to complete before letting h/w |
| 2967 | * know there are new descriptors to fetch. (Only |
| 2968 | * applicable for weak-ordered memory model archs, |
| 2969 | * such as IA-64). */ |
| 2970 | wmb(); |
| 2971 | |
| 2972 | tx_ring->next_to_use = i; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2973 | writel(i, hw->hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 2974 | /* we need this if more than one processor can write to our tail |
| 2975 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 2976 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | /** |
| 2980 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 2981 | * The workaround is to avoid queuing a large packet that would span |
| 2982 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 2983 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 2984 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 2985 | * to the beginning of the Tx FIFO. |
| 2986 | **/ |
| 2987 | |
| 2988 | #define E1000_FIFO_HDR 0x10 |
| 2989 | #define E1000_82547_PAD_LEN 0x3E0 |
| 2990 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2991 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 2992 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2994 | u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 2995 | u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 2997 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2999 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | goto no_fifo_stall_required; |
| 3001 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3002 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | return 1; |
| 3004 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3005 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3007 | return 1; |
| 3008 | } |
| 3009 | |
| 3010 | no_fifo_stall_required: |
| 3011 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3012 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3014 | return 0; |
| 3015 | } |
| 3016 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3017 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3018 | { |
| 3019 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3020 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3021 | |
| 3022 | netif_stop_queue(netdev); |
| 3023 | /* Herbert's original patch had: |
| 3024 | * smp_mb__after_netif_stop_queue(); |
| 3025 | * but since that doesn't exist yet, just open code it. */ |
| 3026 | smp_mb(); |
| 3027 | |
| 3028 | /* We need to check again in a case another CPU has just |
| 3029 | * made room available. */ |
| 3030 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3031 | return -EBUSY; |
| 3032 | |
| 3033 | /* A reprieve! */ |
| 3034 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3035 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3036 | return 0; |
| 3037 | } |
| 3038 | |
| 3039 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3040 | struct e1000_tx_ring *tx_ring, int size) |
| 3041 | { |
| 3042 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3043 | return 0; |
| 3044 | return __e1000_maybe_stop_tx(netdev, size); |
| 3045 | } |
| 3046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 3048 | static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, |
| 3049 | struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3051 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3052 | struct e1000_hw *hw = &adapter->hw; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3053 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3055 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3056 | unsigned int tx_flags = 0; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 3057 | unsigned int len = skb_headlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3058 | unsigned int nr_frags; |
| 3059 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3061 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3064 | /* This goes back to the question of how to logically map a tx queue |
| 3065 | * to a flow. Right now, performance is impacted slightly negatively |
| 3066 | * if using multiple tx queues. If the stack breaks away from a |
| 3067 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3068 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4 | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3069 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3070 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | dev_kfree_skb_any(skb); |
| 3072 | return NETDEV_TX_OK; |
| 3073 | } |
| 3074 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3075 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3076 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | * make sure there is enough room in the FIFO before |
| 3078 | * initiating the DMA for each buffer. The calc is: |
| 3079 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3080 | * overrun the FIFO, adjust the max buffer len if mss |
| 3081 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3082 | if (mss) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3083 | u8 hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | max_per_txd = min(mss << 2, max_per_txd); |
| 3085 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3086 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3087 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3088 | if (skb->data_len && hdr_len == len) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3089 | switch (hw->mac_type) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3090 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3091 | case e1000_82544: |
| 3092 | /* Make sure we have room to chop off 4 bytes, |
| 3093 | * and that the end alignment will work out to |
| 3094 | * this hardware's requirements |
| 3095 | * NOTE: this is a TSO only workaround |
| 3096 | * if end byte alignment not correct move us |
| 3097 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3098 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3099 | break; |
| 3100 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3101 | pull_size = min((unsigned int)4, skb->data_len); |
| 3102 | if (!__pskb_pull_tail(skb, pull_size)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3103 | e_err(drv, "__pskb_pull_tail " |
| 3104 | "failed.\n"); |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3105 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc7 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3106 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3107 | } |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 3108 | len = skb_headlen(skb); |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3109 | break; |
| 3110 | default: |
| 3111 | /* do nothing */ |
| 3112 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3113 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3117 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3118 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3120 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3121 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3122 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3123 | if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb)) |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3124 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3127 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3128 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | count++; |
| 3130 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3131 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3132 | * in PCI-X mode, so add one more descriptor to the count |
| 3133 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3134 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3135 | (len > 2015))) |
| 3136 | count++; |
| 3137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3139 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3141 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3142 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | count += nr_frags; |
| 3144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | /* need: count + 2 desc gap to keep tail from touching |
| 3146 | * head, otherwise try next time */ |
Alexander Duyck | 8017943 | 2009-01-21 14:42:47 -0800 | [diff] [blame] | 3147 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3150 | if (unlikely(hw->mac_type == e1000_82547)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3151 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | netif_stop_queue(netdev); |
Jesse Brandeburg | baa3474 | 2009-09-25 12:17:23 +0000 | [diff] [blame] | 3153 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3154 | mod_timer(&adapter->tx_fifo_stall_timer, |
| 3155 | jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | return NETDEV_TX_BUSY; |
| 3157 | } |
| 3158 | } |
| 3159 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 3160 | if (unlikely(vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3162 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3163 | } |
| 3164 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3165 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3166 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3167 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | if (tso < 0) { |
| 3169 | dev_kfree_skb_any(skb); |
| 3170 | return NETDEV_TX_OK; |
| 3171 | } |
| 3172 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3173 | if (likely(tso)) { |
Jesse Brandeburg | 8fce473 | 2009-09-25 12:18:41 +0000 | [diff] [blame] | 3174 | if (likely(hw->mac_type != e1000_82544)) |
| 3175 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3177 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3179 | |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3180 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3181 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3182 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3183 | count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd, |
| 3184 | nr_frags, mss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3186 | if (count) { |
| 3187 | e1000_tx_queue(adapter, tx_ring, tx_flags, count); |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3188 | /* Make sure there is space in the ring for the next send. */ |
| 3189 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3191 | } else { |
| 3192 | dev_kfree_skb_any(skb); |
| 3193 | tx_ring->buffer_info[first].time_stamp = 0; |
| 3194 | tx_ring->next_to_use = first; |
| 3195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | return NETDEV_TX_OK; |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3202 | * @netdev: network interface device structure |
| 3203 | **/ |
| 3204 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3205 | static void e1000_tx_timeout(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3207 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | |
| 3209 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3210 | adapter->tx_timeout_count++; |
| 3211 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3214 | static void e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3216 | struct e1000_adapter *adapter = |
| 3217 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | |
Jesse Brandeburg | 338c15e | 2010-09-22 18:22:42 +0000 | [diff] [blame] | 3219 | e1000_reinit_safe(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | /** |
| 3223 | * e1000_get_stats - Get System Network Statistics |
| 3224 | * @netdev: network interface device structure |
| 3225 | * |
| 3226 | * Returns the address of the device statistics structure. |
| 3227 | * The statistics are actually updated from the timer callback. |
| 3228 | **/ |
| 3229 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3230 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | { |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3232 | /* only return the current stats */ |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3233 | return &netdev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | /** |
| 3237 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3238 | * @netdev: network interface device structure |
| 3239 | * @new_mtu: new value for maximum frame size |
| 3240 | * |
| 3241 | * Returns 0 on success, negative on failure |
| 3242 | **/ |
| 3243 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3244 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3246 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3247 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 3249 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3250 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3251 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3252 | e_err(probe, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3253 | return -EINVAL; |
| 3254 | } |
| 3255 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3256 | /* Adapter-specific max frame size limits. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3257 | switch (hw->mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3258 | case e1000_undefined ... e1000_82542_rev2_1: |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 3259 | if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3260 | e_err(probe, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3261 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3262 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3263 | break; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3264 | default: |
| 3265 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3266 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
Jesse Brandeburg | 3d6114e | 2009-09-25 12:19:02 +0000 | [diff] [blame] | 3269 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 3270 | msleep(1); |
| 3271 | /* e1000_down has a dependency on max_frame_size */ |
| 3272 | hw->max_frame_size = max_frame; |
| 3273 | if (netif_running(netdev)) |
| 3274 | e1000_down(adapter); |
| 3275 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3276 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3277 | * means we reserve 2 more, this pushes us to allocate from the next |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3278 | * larger slab size. |
| 3279 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 3280 | * however with the new *_jumbo_rx* routines, jumbo receives will use |
| 3281 | * fragmented skbs */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3282 | |
Jesse Brandeburg | 9926146 | 2010-01-22 22:56:16 +0000 | [diff] [blame] | 3283 | if (max_frame <= E1000_RXBUFFER_2048) |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3284 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3285 | else |
| 3286 | #if (PAGE_SIZE >= E1000_RXBUFFER_16384) |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3287 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3288 | #elif (PAGE_SIZE >= E1000_RXBUFFER_4096) |
| 3289 | adapter->rx_buffer_len = PAGE_SIZE; |
| 3290 | #endif |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3291 | |
| 3292 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3293 | if (!hw->tbi_compatibility_on && |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame] | 3294 | ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) || |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3295 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3296 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3297 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3298 | pr_info("%s changing MTU from %d to %d\n", |
| 3299 | netdev->name, netdev->mtu, new_mtu); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3300 | netdev->mtu = new_mtu; |
| 3301 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3302 | if (netif_running(netdev)) |
Jesse Brandeburg | 3d6114e | 2009-09-25 12:19:02 +0000 | [diff] [blame] | 3303 | e1000_up(adapter); |
| 3304 | else |
| 3305 | e1000_reset(adapter); |
| 3306 | |
| 3307 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | return 0; |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * e1000_update_stats - Update the board statistics counters |
| 3314 | * @adapter: board private structure |
| 3315 | **/ |
| 3316 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3317 | void e1000_update_stats(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | { |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3319 | struct net_device *netdev = adapter->netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3321 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3323 | u16 phy_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | |
| 3325 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3326 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3327 | /* |
| 3328 | * Prevent stats update while adapter is being reset, or if the pci |
| 3329 | * connection is down. |
| 3330 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3331 | if (adapter->link_speed == 0) |
| 3332 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3333 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3334 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3337 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3338 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | * called from the interrupt context, so they must only |
| 3340 | * be written while holding adapter->stats_lock |
| 3341 | */ |
| 3342 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3343 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3344 | adapter->stats.gprc += er32(GPRC); |
| 3345 | adapter->stats.gorcl += er32(GORCL); |
| 3346 | adapter->stats.gorch += er32(GORCH); |
| 3347 | adapter->stats.bprc += er32(BPRC); |
| 3348 | adapter->stats.mprc += er32(MPRC); |
| 3349 | adapter->stats.roc += er32(ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3350 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3351 | adapter->stats.prc64 += er32(PRC64); |
| 3352 | adapter->stats.prc127 += er32(PRC127); |
| 3353 | adapter->stats.prc255 += er32(PRC255); |
| 3354 | adapter->stats.prc511 += er32(PRC511); |
| 3355 | adapter->stats.prc1023 += er32(PRC1023); |
| 3356 | adapter->stats.prc1522 += er32(PRC1522); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3358 | adapter->stats.symerrs += er32(SYMERRS); |
| 3359 | adapter->stats.mpc += er32(MPC); |
| 3360 | adapter->stats.scc += er32(SCC); |
| 3361 | adapter->stats.ecol += er32(ECOL); |
| 3362 | adapter->stats.mcc += er32(MCC); |
| 3363 | adapter->stats.latecol += er32(LATECOL); |
| 3364 | adapter->stats.dc += er32(DC); |
| 3365 | adapter->stats.sec += er32(SEC); |
| 3366 | adapter->stats.rlec += er32(RLEC); |
| 3367 | adapter->stats.xonrxc += er32(XONRXC); |
| 3368 | adapter->stats.xontxc += er32(XONTXC); |
| 3369 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3370 | adapter->stats.xofftxc += er32(XOFFTXC); |
| 3371 | adapter->stats.fcruc += er32(FCRUC); |
| 3372 | adapter->stats.gptc += er32(GPTC); |
| 3373 | adapter->stats.gotcl += er32(GOTCL); |
| 3374 | adapter->stats.gotch += er32(GOTCH); |
| 3375 | adapter->stats.rnbc += er32(RNBC); |
| 3376 | adapter->stats.ruc += er32(RUC); |
| 3377 | adapter->stats.rfc += er32(RFC); |
| 3378 | adapter->stats.rjc += er32(RJC); |
| 3379 | adapter->stats.torl += er32(TORL); |
| 3380 | adapter->stats.torh += er32(TORH); |
| 3381 | adapter->stats.totl += er32(TOTL); |
| 3382 | adapter->stats.toth += er32(TOTH); |
| 3383 | adapter->stats.tpr += er32(TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3384 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3385 | adapter->stats.ptc64 += er32(PTC64); |
| 3386 | adapter->stats.ptc127 += er32(PTC127); |
| 3387 | adapter->stats.ptc255 += er32(PTC255); |
| 3388 | adapter->stats.ptc511 += er32(PTC511); |
| 3389 | adapter->stats.ptc1023 += er32(PTC1023); |
| 3390 | adapter->stats.ptc1522 += er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3391 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3392 | adapter->stats.mptc += er32(MPTC); |
| 3393 | adapter->stats.bptc += er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | |
| 3395 | /* used for adaptive IFS */ |
| 3396 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3397 | hw->tx_packet_delta = er32(TPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | adapter->stats.tpt += hw->tx_packet_delta; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3399 | hw->collision_delta = er32(COLC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | adapter->stats.colc += hw->collision_delta; |
| 3401 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3402 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3403 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 3404 | adapter->stats.rxerrc += er32(RXERRC); |
| 3405 | adapter->stats.tncrs += er32(TNCRS); |
| 3406 | adapter->stats.cexterr += er32(CEXTERR); |
| 3407 | adapter->stats.tsctc += er32(TSCTC); |
| 3408 | adapter->stats.tsctfc += er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3412 | netdev->stats.multicast = adapter->stats.mprc; |
| 3413 | netdev->stats.collisions = adapter->stats.colc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | |
| 3415 | /* Rx Errors */ |
| 3416 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3417 | /* RLEC on some newer hardware can be incorrect so build |
| 3418 | * our own version based on RUC and ROC */ |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3419 | netdev->stats.rx_errors = adapter->stats.rxerrc + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3421 | adapter->stats.ruc + adapter->stats.roc + |
| 3422 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3423 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3424 | netdev->stats.rx_length_errors = adapter->stats.rlerrc; |
| 3425 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3426 | netdev->stats.rx_frame_errors = adapter->stats.algnerrc; |
| 3427 | netdev->stats.rx_missed_errors = adapter->stats.mpc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
| 3429 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3430 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3431 | netdev->stats.tx_errors = adapter->stats.txerrc; |
| 3432 | netdev->stats.tx_aborted_errors = adapter->stats.ecol; |
| 3433 | netdev->stats.tx_window_errors = adapter->stats.latecol; |
| 3434 | netdev->stats.tx_carrier_errors = adapter->stats.tncrs; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3435 | if (hw->bad_tx_carr_stats_fd && |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3436 | adapter->link_duplex == FULL_DUPLEX) { |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3437 | netdev->stats.tx_carrier_errors = 0; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3438 | adapter->stats.tncrs = 0; |
| 3439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | |
| 3441 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3442 | |
| 3443 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3444 | if (hw->media_type == e1000_media_type_copper) { |
| 3445 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3447 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3448 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3449 | } |
| 3450 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3451 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | (hw->phy_type == e1000_phy_m88) && |
| 3453 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3454 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3455 | } |
| 3456 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3457 | /* Management Stats */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3458 | if (hw->has_smbus) { |
| 3459 | adapter->stats.mgptc += er32(MGTPTC); |
| 3460 | adapter->stats.mgprc += er32(MGTPRC); |
| 3461 | adapter->stats.mgpdc += er32(MGTPDC); |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3462 | } |
| 3463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3465 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3466 | |
| 3467 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | * e1000_intr - Interrupt Handler |
| 3469 | * @irq: interrupt number |
| 3470 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | **/ |
| 3472 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3473 | static irqreturn_t e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | { |
| 3475 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3476 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3478 | u32 icr = er32(ICR); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 3479 | |
Jesse Brandeburg | 4c11b8a | 2011-01-13 07:48:13 +0000 | [diff] [blame] | 3480 | if (unlikely((!icr))) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3481 | return IRQ_NONE; /* Not our interrupt */ |
| 3482 | |
Jesse Brandeburg | 4c11b8a | 2011-01-13 07:48:13 +0000 | [diff] [blame] | 3483 | /* |
| 3484 | * we might have caused the interrupt, but the above |
| 3485 | * read cleared it, and just in case the driver is |
| 3486 | * down there is nothing to do so return handled |
| 3487 | */ |
| 3488 | if (unlikely(test_bit(__E1000_DOWN, &adapter->flags))) |
| 3489 | return IRQ_HANDLED; |
| 3490 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3491 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | hw->get_link_status = 1; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3493 | /* guard against interrupt when we're going down */ |
| 3494 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3495 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3498 | /* disable interrupts, without the synchronize_irq bit */ |
| 3499 | ew32(IMC, ~0); |
| 3500 | E1000_WRITE_FLUSH(); |
| 3501 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3502 | if (likely(napi_schedule_prep(&adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3503 | adapter->total_tx_bytes = 0; |
| 3504 | adapter->total_tx_packets = 0; |
| 3505 | adapter->total_rx_bytes = 0; |
| 3506 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3507 | __napi_schedule(&adapter->napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3508 | } else { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3509 | /* this really should not happen! if it does it is basically a |
| 3510 | * bug, but not a hard error, so enable ints and continue */ |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3511 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3512 | e1000_irq_enable(adapter); |
| 3513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | return IRQ_HANDLED; |
| 3516 | } |
| 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | /** |
| 3519 | * e1000_clean - NAPI Rx polling callback |
| 3520 | * @adapter: board private structure |
| 3521 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3522 | static int e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3524 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
Jesse Brandeburg | 650b5a5 | 2009-09-25 12:19:23 +0000 | [diff] [blame] | 3525 | int tx_clean_complete = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3526 | |
Jesse Brandeburg | 650b5a5 | 2009-09-25 12:19:23 +0000 | [diff] [blame] | 3527 | tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3528 | |
Jesse Brandeburg | 650b5a5 | 2009-09-25 12:19:23 +0000 | [diff] [blame] | 3529 | adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3530 | |
Jesse Brandeburg | 650b5a5 | 2009-09-25 12:19:23 +0000 | [diff] [blame] | 3531 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3532 | work_done = budget; |
| 3533 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3534 | /* If budget not fully consumed, exit the polling mode */ |
| 3535 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3536 | if (likely(adapter->itr_setting & 3)) |
| 3537 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3538 | napi_complete(napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3539 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3540 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3543 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | /** |
| 3547 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3548 | * @adapter: board private structure |
| 3549 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3550 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3551 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3553 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | struct net_device *netdev = adapter->netdev; |
| 3555 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3556 | struct e1000_buffer *buffer_info; |
| 3557 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3558 | unsigned int count = 0; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3559 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | |
| 3561 | i = tx_ring->next_to_clean; |
| 3562 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3563 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3564 | |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3565 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 3566 | (count < tx_ring->count)) { |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3567 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 3568 | rmb(); /* read buffer_info after eop_desc */ |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3569 | for ( ; !cleaned; count++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3571 | buffer_info = &tx_ring->buffer_info[i]; |
| 3572 | cleaned = (i == eop); |
| 3573 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3574 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3575 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3576 | unsigned int segs, bytecount; |
| 3577 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 3578 | /* multiply data chunks by size of headers */ |
| 3579 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 3580 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3581 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3582 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3583 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3584 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3585 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3587 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3591 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3592 | } |
| 3593 | |
| 3594 | tx_ring->next_to_clean = i; |
| 3595 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3596 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3597 | if (unlikely(count && netif_carrier_ok(netdev) && |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3598 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 3599 | /* Make sure that anybody stopping the queue after this |
| 3600 | * sees the new next_to_clean. |
| 3601 | */ |
| 3602 | smp_mb(); |
Jesse Brandeburg | cdd7549 | 2009-09-25 12:18:07 +0000 | [diff] [blame] | 3603 | |
| 3604 | if (netif_queue_stopped(netdev) && |
| 3605 | !(test_bit(__E1000_DOWN, &adapter->flags))) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3606 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3607 | ++adapter->restart_queue; |
| 3608 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3609 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3610 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3611 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3612 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | * check with the clearing of time_stamp and movement of i */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3614 | adapter->detect_tx_hung = false; |
Jesse Brandeburg | cdd7549 | 2009-09-25 12:18:07 +0000 | [diff] [blame] | 3615 | if (tx_ring->buffer_info[eop].time_stamp && |
| 3616 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 3617 | (adapter->tx_timeout_factor * HZ)) && |
| 3618 | !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3619 | |
| 3620 | /* detected Tx unit hang */ |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3621 | e_err(drv, "Detected Tx Unit Hang\n" |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3622 | " Tx Queue <%lu>\n" |
| 3623 | " TDH <%x>\n" |
| 3624 | " TDT <%x>\n" |
| 3625 | " next_to_use <%x>\n" |
| 3626 | " next_to_clean <%x>\n" |
| 3627 | "buffer_info[next_to_clean]\n" |
| 3628 | " time_stamp <%lx>\n" |
| 3629 | " next_to_watch <%x>\n" |
| 3630 | " jiffies <%lx>\n" |
| 3631 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3632 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3633 | sizeof(struct e1000_tx_ring)), |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3634 | readl(hw->hw_addr + tx_ring->tdh), |
| 3635 | readl(hw->hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3636 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3637 | tx_ring->next_to_clean, |
Jesse Brandeburg | cdd7549 | 2009-09-25 12:18:07 +0000 | [diff] [blame] | 3638 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3639 | eop, |
| 3640 | jiffies, |
| 3641 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3645 | adapter->total_tx_bytes += total_tx_bytes; |
| 3646 | adapter->total_tx_packets += total_tx_packets; |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3647 | netdev->stats.tx_bytes += total_tx_bytes; |
| 3648 | netdev->stats.tx_packets += total_tx_packets; |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 3649 | return count < tx_ring->count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | /** |
| 3653 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3654 | * @adapter: board private structure |
| 3655 | * @status_err: receive descriptor status and error fields |
| 3656 | * @csum: receive descriptor csum field |
| 3657 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | **/ |
| 3659 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3660 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 3661 | u32 csum, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3663 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3664 | u16 status = (u16)status_err; |
| 3665 | u8 errors = (u8)(status_err >> 24); |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 3666 | |
| 3667 | skb_checksum_none_assert(skb); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | /* 82543 or newer only */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3670 | if (unlikely(hw->mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3672 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3673 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3674 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3675 | /* let the stack verify checksum errors */ |
| 3676 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | return; |
| 3678 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3679 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3680 | if (!(status & E1000_RXD_STAT_TCPCS)) |
| 3681 | return; |
| 3682 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3683 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 3684 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | /* TCP checksum is good */ |
| 3686 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3688 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3692 | * e1000_consume_page - helper function |
| 3693 | **/ |
| 3694 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 3695 | u16 length) |
| 3696 | { |
| 3697 | bi->page = NULL; |
| 3698 | skb->len += length; |
| 3699 | skb->data_len += length; |
| 3700 | skb->truesize += length; |
| 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * e1000_receive_skb - helper function to handle rx indications |
| 3705 | * @adapter: board private structure |
| 3706 | * @status: descriptor status field as written by hardware |
| 3707 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 3708 | * @skb: pointer to sk_buff to be indicated to stack |
| 3709 | */ |
| 3710 | static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status, |
| 3711 | __le16 vlan, struct sk_buff *skb) |
| 3712 | { |
Jesse Brandeburg | 6a08d19 | 2010-09-22 18:23:05 +0000 | [diff] [blame] | 3713 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
| 3714 | |
| 3715 | if ((unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP)))) |
| 3716 | vlan_gro_receive(&adapter->napi, adapter->vlgrp, |
| 3717 | le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK, |
| 3718 | skb); |
| 3719 | else |
| 3720 | napi_gro_receive(&adapter->napi, skb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | /** |
| 3724 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 3725 | * @adapter: board private structure |
| 3726 | * @rx_ring: ring to clean |
| 3727 | * @work_done: amount of napi work completed this call |
| 3728 | * @work_to_do: max amount of work allowed for this call to do |
| 3729 | * |
| 3730 | * the return value indicates whether actual cleaning was done, there |
| 3731 | * is no guarantee that everything was cleaned |
| 3732 | */ |
| 3733 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 3734 | struct e1000_rx_ring *rx_ring, |
| 3735 | int *work_done, int work_to_do) |
| 3736 | { |
| 3737 | struct e1000_hw *hw = &adapter->hw; |
| 3738 | struct net_device *netdev = adapter->netdev; |
| 3739 | struct pci_dev *pdev = adapter->pdev; |
| 3740 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 3741 | struct e1000_buffer *buffer_info, *next_buffer; |
| 3742 | unsigned long irq_flags; |
| 3743 | u32 length; |
| 3744 | unsigned int i; |
| 3745 | int cleaned_count = 0; |
| 3746 | bool cleaned = false; |
| 3747 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 3748 | |
| 3749 | i = rx_ring->next_to_clean; |
| 3750 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 3751 | buffer_info = &rx_ring->buffer_info[i]; |
| 3752 | |
| 3753 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 3754 | struct sk_buff *skb; |
| 3755 | u8 status; |
| 3756 | |
| 3757 | if (*work_done >= work_to_do) |
| 3758 | break; |
| 3759 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 3760 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3761 | |
| 3762 | status = rx_desc->status; |
| 3763 | skb = buffer_info->skb; |
| 3764 | buffer_info->skb = NULL; |
| 3765 | |
| 3766 | if (++i == rx_ring->count) i = 0; |
| 3767 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 3768 | prefetch(next_rxd); |
| 3769 | |
| 3770 | next_buffer = &rx_ring->buffer_info[i]; |
| 3771 | |
| 3772 | cleaned = true; |
| 3773 | cleaned_count++; |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 3774 | dma_unmap_page(&pdev->dev, buffer_info->dma, |
| 3775 | buffer_info->length, DMA_FROM_DEVICE); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3776 | buffer_info->dma = 0; |
| 3777 | |
| 3778 | length = le16_to_cpu(rx_desc->length); |
| 3779 | |
| 3780 | /* errors is only valid for DD + EOP descriptors */ |
| 3781 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 3782 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 3783 | u8 last_byte = *(skb->data + length - 1); |
| 3784 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 3785 | last_byte)) { |
| 3786 | spin_lock_irqsave(&adapter->stats_lock, |
| 3787 | irq_flags); |
| 3788 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
| 3789 | length, skb->data); |
| 3790 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 3791 | irq_flags); |
| 3792 | length--; |
| 3793 | } else { |
| 3794 | /* recycle both page and skb */ |
| 3795 | buffer_info->skb = skb; |
| 3796 | /* an error means any chain goes out the window |
| 3797 | * too */ |
| 3798 | if (rx_ring->rx_skb_top) |
| 3799 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 3800 | rx_ring->rx_skb_top = NULL; |
| 3801 | goto next_desc; |
| 3802 | } |
| 3803 | } |
| 3804 | |
| 3805 | #define rxtop rx_ring->rx_skb_top |
| 3806 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 3807 | /* this descriptor is only the beginning (or middle) */ |
| 3808 | if (!rxtop) { |
| 3809 | /* this is the beginning of a chain */ |
| 3810 | rxtop = skb; |
| 3811 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 3812 | 0, length); |
| 3813 | } else { |
| 3814 | /* this is the middle of a chain */ |
| 3815 | skb_fill_page_desc(rxtop, |
| 3816 | skb_shinfo(rxtop)->nr_frags, |
| 3817 | buffer_info->page, 0, length); |
| 3818 | /* re-use the skb, only consumed the page */ |
| 3819 | buffer_info->skb = skb; |
| 3820 | } |
| 3821 | e1000_consume_page(buffer_info, rxtop, length); |
| 3822 | goto next_desc; |
| 3823 | } else { |
| 3824 | if (rxtop) { |
| 3825 | /* end of the chain */ |
| 3826 | skb_fill_page_desc(rxtop, |
| 3827 | skb_shinfo(rxtop)->nr_frags, |
| 3828 | buffer_info->page, 0, length); |
| 3829 | /* re-use the current skb, we only consumed the |
| 3830 | * page */ |
| 3831 | buffer_info->skb = skb; |
| 3832 | skb = rxtop; |
| 3833 | rxtop = NULL; |
| 3834 | e1000_consume_page(buffer_info, skb, length); |
| 3835 | } else { |
| 3836 | /* no chain, got EOP, this buf is the packet |
| 3837 | * copybreak to save the put_page/alloc_page */ |
| 3838 | if (length <= copybreak && |
| 3839 | skb_tailroom(skb) >= length) { |
| 3840 | u8 *vaddr; |
| 3841 | vaddr = kmap_atomic(buffer_info->page, |
| 3842 | KM_SKB_DATA_SOFTIRQ); |
| 3843 | memcpy(skb_tail_pointer(skb), vaddr, length); |
| 3844 | kunmap_atomic(vaddr, |
| 3845 | KM_SKB_DATA_SOFTIRQ); |
| 3846 | /* re-use the page, so don't erase |
| 3847 | * buffer_info->page */ |
| 3848 | skb_put(skb, length); |
| 3849 | } else { |
| 3850 | skb_fill_page_desc(skb, 0, |
| 3851 | buffer_info->page, 0, |
| 3852 | length); |
| 3853 | e1000_consume_page(buffer_info, skb, |
| 3854 | length); |
| 3855 | } |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 3860 | e1000_rx_checksum(adapter, |
| 3861 | (u32)(status) | |
| 3862 | ((u32)(rx_desc->errors) << 24), |
| 3863 | le16_to_cpu(rx_desc->csum), skb); |
| 3864 | |
| 3865 | pskb_trim(skb, skb->len - 4); |
| 3866 | |
| 3867 | /* probably a little skewed due to removing CRC */ |
| 3868 | total_rx_bytes += skb->len; |
| 3869 | total_rx_packets++; |
| 3870 | |
| 3871 | /* eth type trans needs skb->data to point to something */ |
| 3872 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3873 | e_err(drv, "pskb_may_pull failed.\n"); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3874 | dev_kfree_skb(skb); |
| 3875 | goto next_desc; |
| 3876 | } |
| 3877 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3878 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
| 3879 | |
| 3880 | next_desc: |
| 3881 | rx_desc->status = 0; |
| 3882 | |
| 3883 | /* return some buffers to hardware, one at a time is too slow */ |
| 3884 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 3885 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3886 | cleaned_count = 0; |
| 3887 | } |
| 3888 | |
| 3889 | /* use prefetched values */ |
| 3890 | rx_desc = next_rxd; |
| 3891 | buffer_info = next_buffer; |
| 3892 | } |
| 3893 | rx_ring->next_to_clean = i; |
| 3894 | |
| 3895 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 3896 | if (cleaned_count) |
| 3897 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3898 | |
| 3899 | adapter->total_rx_packets += total_rx_packets; |
| 3900 | adapter->total_rx_bytes += total_rx_bytes; |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 3901 | netdev->stats.rx_bytes += total_rx_bytes; |
| 3902 | netdev->stats.rx_packets += total_rx_packets; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3903 | return cleaned; |
| 3904 | } |
| 3905 | |
Joe Perches | 57bf6ee | 2010-05-13 15:26:17 +0000 | [diff] [blame] | 3906 | /* |
| 3907 | * this should improve performance for small packets with large amounts |
| 3908 | * of reassembly being done in the stack |
| 3909 | */ |
| 3910 | static void e1000_check_copybreak(struct net_device *netdev, |
| 3911 | struct e1000_buffer *buffer_info, |
| 3912 | u32 length, struct sk_buff **skb) |
| 3913 | { |
| 3914 | struct sk_buff *new_skb; |
| 3915 | |
| 3916 | if (length > copybreak) |
| 3917 | return; |
| 3918 | |
| 3919 | new_skb = netdev_alloc_skb_ip_align(netdev, length); |
| 3920 | if (!new_skb) |
| 3921 | return; |
| 3922 | |
| 3923 | skb_copy_to_linear_data_offset(new_skb, -NET_IP_ALIGN, |
| 3924 | (*skb)->data - NET_IP_ALIGN, |
| 3925 | length + NET_IP_ALIGN); |
| 3926 | /* save the skb in buffer_info as good */ |
| 3927 | buffer_info->skb = *skb; |
| 3928 | *skb = new_skb; |
| 3929 | } |
| 3930 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3931 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3932 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | * @adapter: board private structure |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3934 | * @rx_ring: ring to clean |
| 3935 | * @work_done: amount of napi work completed this call |
| 3936 | * @work_to_do: max amount of work allowed for this call to do |
| 3937 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3938 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 3939 | struct e1000_rx_ring *rx_ring, |
| 3940 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3942 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | struct net_device *netdev = adapter->netdev; |
| 3944 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3945 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 3946 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3948 | u32 length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3950 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3951 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3952 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | |
| 3954 | i = rx_ring->next_to_clean; |
| 3955 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3956 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3958 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 3959 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3960 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3961 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3962 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | break; |
| 3964 | (*work_done)++; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 3965 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 3966 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3967 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3968 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3969 | buffer_info->skb = NULL; |
| 3970 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3971 | prefetch(skb->data - NET_IP_ALIGN); |
| 3972 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3973 | if (++i == rx_ring->count) i = 0; |
| 3974 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3975 | prefetch(next_rxd); |
| 3976 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3977 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3978 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3979 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3980 | cleaned_count++; |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 3981 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
| 3982 | buffer_info->length, DMA_FROM_DEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 3983 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | length = le16_to_cpu(rx_desc->length); |
Neil Horman | ea30e11 | 2009-06-02 01:29:58 -0700 | [diff] [blame] | 3986 | /* !EOP means multiple descriptors were used to store a single |
Jesse Brandeburg | 40a14de | 2010-01-19 14:15:38 +0000 | [diff] [blame] | 3987 | * packet, if thats the case we need to toss it. In fact, we |
| 3988 | * to toss every packet with the EOP bit clear and the next |
| 3989 | * frame that _does_ have the EOP bit set, as it is by |
| 3990 | * definition only a frame fragment |
| 3991 | */ |
| 3992 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) |
| 3993 | adapter->discarding = true; |
| 3994 | |
| 3995 | if (adapter->discarding) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3996 | /* All receives must fit into a single buffer */ |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 3997 | e_dbg("Receive packet consumed multiple buffers\n"); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 3998 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3999 | buffer_info->skb = skb; |
Jesse Brandeburg | 40a14de | 2010-01-19 14:15:38 +0000 | [diff] [blame] | 4000 | if (status & E1000_RXD_STAT_EOP) |
| 4001 | adapter->discarding = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | goto next_desc; |
| 4003 | } |
| 4004 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4005 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4006 | u8 last_byte = *(skb->data + length - 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4007 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 4008 | last_byte)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4010 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | length, skb->data); |
| 4012 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4013 | flags); |
| 4014 | length--; |
| 4015 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4016 | /* recycle */ |
| 4017 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | goto next_desc; |
| 4019 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4022 | /* adjust length to remove Ethernet CRC, this must be |
| 4023 | * done after the TBI_ACCEPT workaround above */ |
| 4024 | length -= 4; |
| 4025 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4026 | /* probably a little skewed due to removing CRC */ |
| 4027 | total_rx_bytes += length; |
| 4028 | total_rx_packets++; |
| 4029 | |
Joe Perches | 57bf6ee | 2010-05-13 15:26:17 +0000 | [diff] [blame] | 4030 | e1000_check_copybreak(netdev, buffer_info, length, &skb); |
| 4031 | |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4032 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | |
| 4034 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4035 | e1000_rx_checksum(adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4036 | (u32)(status) | |
| 4037 | ((u32)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4038 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4039 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4040 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | next_desc: |
| 4043 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4045 | /* return some buffers to hardware, one at a time is too slow */ |
| 4046 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4047 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4048 | cleaned_count = 0; |
| 4049 | } |
| 4050 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4051 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4052 | rx_desc = next_rxd; |
| 4053 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4056 | |
| 4057 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4058 | if (cleaned_count) |
| 4059 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4061 | adapter->total_rx_packets += total_rx_packets; |
| 4062 | adapter->total_rx_bytes += total_rx_bytes; |
Ajit Khaparde | 5fe31de | 2009-10-07 02:42:23 +0000 | [diff] [blame] | 4063 | netdev->stats.rx_bytes += total_rx_bytes; |
| 4064 | netdev->stats.rx_packets += total_rx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | return cleaned; |
| 4066 | } |
| 4067 | |
| 4068 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4069 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 4070 | * @adapter: address of board private structure |
| 4071 | * @rx_ring: pointer to receive ring structure |
| 4072 | * @cleaned_count: number of buffers to allocate this pass |
| 4073 | **/ |
| 4074 | |
| 4075 | static void |
| 4076 | e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 4077 | struct e1000_rx_ring *rx_ring, int cleaned_count) |
| 4078 | { |
| 4079 | struct net_device *netdev = adapter->netdev; |
| 4080 | struct pci_dev *pdev = adapter->pdev; |
| 4081 | struct e1000_rx_desc *rx_desc; |
| 4082 | struct e1000_buffer *buffer_info; |
| 4083 | struct sk_buff *skb; |
| 4084 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4085 | unsigned int bufsz = 256 - 16 /*for skb_reserve */ ; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4086 | |
| 4087 | i = rx_ring->next_to_use; |
| 4088 | buffer_info = &rx_ring->buffer_info[i]; |
| 4089 | |
| 4090 | while (cleaned_count--) { |
| 4091 | skb = buffer_info->skb; |
| 4092 | if (skb) { |
| 4093 | skb_trim(skb, 0); |
| 4094 | goto check_page; |
| 4095 | } |
| 4096 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4097 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4098 | if (unlikely(!skb)) { |
| 4099 | /* Better luck next round */ |
| 4100 | adapter->alloc_rx_buff_failed++; |
| 4101 | break; |
| 4102 | } |
| 4103 | |
| 4104 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4105 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4106 | struct sk_buff *oldskb = skb; |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 4107 | e_err(rx_err, "skb align check failed: %u bytes at " |
| 4108 | "%p\n", bufsz, skb->data); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4109 | /* Try again, without freeing the previous */ |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4110 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4111 | /* Failed allocation, critical failure */ |
| 4112 | if (!skb) { |
| 4113 | dev_kfree_skb(oldskb); |
| 4114 | adapter->alloc_rx_buff_failed++; |
| 4115 | break; |
| 4116 | } |
| 4117 | |
| 4118 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4119 | /* give up */ |
| 4120 | dev_kfree_skb(skb); |
| 4121 | dev_kfree_skb(oldskb); |
| 4122 | break; /* while (cleaned_count--) */ |
| 4123 | } |
| 4124 | |
| 4125 | /* Use new allocation */ |
| 4126 | dev_kfree_skb(oldskb); |
| 4127 | } |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4128 | buffer_info->skb = skb; |
| 4129 | buffer_info->length = adapter->rx_buffer_len; |
| 4130 | check_page: |
| 4131 | /* allocate a new page if necessary */ |
| 4132 | if (!buffer_info->page) { |
| 4133 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 4134 | if (unlikely(!buffer_info->page)) { |
| 4135 | adapter->alloc_rx_buff_failed++; |
| 4136 | break; |
| 4137 | } |
| 4138 | } |
| 4139 | |
Anton Blanchard | b5abb02 | 2010-02-19 17:54:53 +0000 | [diff] [blame] | 4140 | if (!buffer_info->dma) { |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4141 | buffer_info->dma = dma_map_page(&pdev->dev, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4142 | buffer_info->page, 0, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4143 | buffer_info->length, |
| 4144 | DMA_FROM_DEVICE); |
| 4145 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Anton Blanchard | b5abb02 | 2010-02-19 17:54:53 +0000 | [diff] [blame] | 4146 | put_page(buffer_info->page); |
| 4147 | dev_kfree_skb(skb); |
| 4148 | buffer_info->page = NULL; |
| 4149 | buffer_info->skb = NULL; |
| 4150 | buffer_info->dma = 0; |
| 4151 | adapter->alloc_rx_buff_failed++; |
| 4152 | break; /* while !buffer_info->skb */ |
| 4153 | } |
| 4154 | } |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4155 | |
| 4156 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4157 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4158 | |
| 4159 | if (unlikely(++i == rx_ring->count)) |
| 4160 | i = 0; |
| 4161 | buffer_info = &rx_ring->buffer_info[i]; |
| 4162 | } |
| 4163 | |
| 4164 | if (likely(rx_ring->next_to_use != i)) { |
| 4165 | rx_ring->next_to_use = i; |
| 4166 | if (unlikely(i-- == 0)) |
| 4167 | i = (rx_ring->count - 1); |
| 4168 | |
| 4169 | /* Force memory writes to complete before letting h/w |
| 4170 | * know there are new descriptors to fetch. (Only |
| 4171 | * applicable for weak-ordered memory model archs, |
| 4172 | * such as IA-64). */ |
| 4173 | wmb(); |
| 4174 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4179 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | * @adapter: address of board private structure |
| 4181 | **/ |
| 4182 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4183 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
| 4184 | struct e1000_rx_ring *rx_ring, |
| 4185 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4187 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | struct net_device *netdev = adapter->netdev; |
| 4189 | struct pci_dev *pdev = adapter->pdev; |
| 4190 | struct e1000_rx_desc *rx_desc; |
| 4191 | struct e1000_buffer *buffer_info; |
| 4192 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4193 | unsigned int i; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4194 | unsigned int bufsz = adapter->rx_buffer_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | |
| 4196 | i = rx_ring->next_to_use; |
| 4197 | buffer_info = &rx_ring->buffer_info[i]; |
| 4198 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4199 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4200 | skb = buffer_info->skb; |
| 4201 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4202 | skb_trim(skb, 0); |
| 4203 | goto map_skb; |
| 4204 | } |
| 4205 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4206 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4207 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4209 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | break; |
| 4211 | } |
| 4212 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4213 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4215 | struct sk_buff *oldskb = skb; |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 4216 | e_err(rx_err, "skb align check failed: %u bytes at " |
| 4217 | "%p\n", bufsz, skb->data); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4218 | /* Try again, without freeing the previous */ |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 4219 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4220 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | if (!skb) { |
| 4222 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4223 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | break; |
| 4225 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4228 | /* give up */ |
| 4229 | dev_kfree_skb(skb); |
| 4230 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4231 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4234 | |
| 4235 | /* Use new allocation */ |
| 4236 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | buffer_info->skb = skb; |
| 4239 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4240 | map_skb: |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4241 | buffer_info->dma = dma_map_single(&pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | skb->data, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4243 | buffer_info->length, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4244 | DMA_FROM_DEVICE); |
| 4245 | if (dma_mapping_error(&pdev->dev, buffer_info->dma)) { |
Anton Blanchard | b5abb02 | 2010-02-19 17:54:53 +0000 | [diff] [blame] | 4246 | dev_kfree_skb(skb); |
| 4247 | buffer_info->skb = NULL; |
| 4248 | buffer_info->dma = 0; |
| 4249 | adapter->alloc_rx_buff_failed++; |
| 4250 | break; /* while !buffer_info->skb */ |
| 4251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4253 | /* |
| 4254 | * XXX if it was allocated cleanly it will never map to a |
| 4255 | * boundary crossing |
| 4256 | */ |
| 4257 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4258 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4259 | if (!e1000_check_64k_bound(adapter, |
| 4260 | (void *)(unsigned long)buffer_info->dma, |
| 4261 | adapter->rx_buffer_len)) { |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 4262 | e_err(rx_err, "dma align check failed: %u bytes at " |
| 4263 | "%p\n", adapter->rx_buffer_len, |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4264 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | dev_kfree_skb(skb); |
| 4266 | buffer_info->skb = NULL; |
| 4267 | |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4268 | dma_unmap_single(&pdev->dev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | adapter->rx_buffer_len, |
Nick Nunley | b16f53b | 2010-04-27 13:08:45 +0000 | [diff] [blame] | 4270 | DMA_FROM_DEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 4271 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4273 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | break; /* while !buffer_info->skb */ |
| 4275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4277 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4278 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4279 | if (unlikely(++i == rx_ring->count)) |
| 4280 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | buffer_info = &rx_ring->buffer_info[i]; |
| 4282 | } |
| 4283 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4284 | if (likely(rx_ring->next_to_use != i)) { |
| 4285 | rx_ring->next_to_use = i; |
| 4286 | if (unlikely(i-- == 0)) |
| 4287 | i = (rx_ring->count - 1); |
| 4288 | |
| 4289 | /* Force memory writes to complete before letting h/w |
| 4290 | * know there are new descriptors to fetch. (Only |
| 4291 | * applicable for weak-ordered memory model archs, |
| 4292 | * such as IA-64). */ |
| 4293 | wmb(); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4294 | writel(i, hw->hw_addr + rx_ring->rdt); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | /** |
| 4299 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4300 | * @adapter: |
| 4301 | **/ |
| 4302 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4303 | static void e1000_smartspeed(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4305 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4306 | u16 phy_status; |
| 4307 | u16 phy_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4309 | if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg || |
| 4310 | !(hw->autoneg_advertised & ADVERTISE_1000_FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | return; |
| 4312 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4313 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | /* If Master/Slave config fault is asserted twice, |
| 4315 | * we assume back-to-back */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4316 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4317 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4318 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4319 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4320 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4321 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4323 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | phy_ctrl); |
| 4325 | adapter->smartspeed++; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4326 | if (!e1000_phy_setup_autoneg(hw) && |
| 4327 | !e1000_read_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | &phy_ctrl)) { |
| 4329 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4330 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4331 | e1000_write_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | phy_ctrl); |
| 4333 | } |
| 4334 | } |
| 4335 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4336 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | /* If still no link, perhaps using 2/3 pair cable */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4338 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | phy_ctrl |= CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4340 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); |
| 4341 | if (!e1000_phy_setup_autoneg(hw) && |
| 4342 | !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4344 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4345 | e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4349 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | adapter->smartspeed = 0; |
| 4351 | } |
| 4352 | |
| 4353 | /** |
| 4354 | * e1000_ioctl - |
| 4355 | * @netdev: |
| 4356 | * @ifreq: |
| 4357 | * @cmd: |
| 4358 | **/ |
| 4359 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4360 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | { |
| 4362 | switch (cmd) { |
| 4363 | case SIOCGMIIPHY: |
| 4364 | case SIOCGMIIREG: |
| 4365 | case SIOCSMIIREG: |
| 4366 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4367 | default: |
| 4368 | return -EOPNOTSUPP; |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | /** |
| 4373 | * e1000_mii_ioctl - |
| 4374 | * @netdev: |
| 4375 | * @ifreq: |
| 4376 | * @cmd: |
| 4377 | **/ |
| 4378 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4379 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 4380 | int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4382 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4383 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4385 | int retval; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4386 | u16 mii_reg; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4387 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4389 | if (hw->media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | return -EOPNOTSUPP; |
| 4391 | |
| 4392 | switch (cmd) { |
| 4393 | case SIOCGMIIPHY: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4394 | data->phy_id = hw->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | break; |
| 4396 | case SIOCGMIIREG: |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4397 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4398 | if (e1000_read_phy_reg(hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4399 | &data->val_out)) { |
| 4400 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4402 | } |
| 4403 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | break; |
| 4405 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4406 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | return -EFAULT; |
| 4408 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4409 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4410 | if (e1000_write_phy_reg(hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4411 | mii_reg)) { |
| 4412 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4414 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4415 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4416 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | switch (data->reg_num) { |
| 4418 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4419 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4421 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4422 | hw->autoneg = 1; |
| 4423 | hw->autoneg_advertised = 0x2F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | } else { |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4425 | u32 speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | if (mii_reg & 0x40) |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4427 | speed = SPEED_1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | else if (mii_reg & 0x2000) |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4429 | speed = SPEED_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | else |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4431 | speed = SPEED_10; |
| 4432 | retval = e1000_set_spd_dplx( |
| 4433 | adapter, speed, |
| 4434 | ((mii_reg & 0x100) |
| 4435 | ? DUPLEX_FULL : |
| 4436 | DUPLEX_HALF)); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4437 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | return retval; |
| 4439 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4440 | if (netif_running(adapter->netdev)) |
| 4441 | e1000_reinit_locked(adapter); |
| 4442 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | e1000_reset(adapter); |
| 4444 | break; |
| 4445 | case M88E1000_PHY_SPEC_CTRL: |
| 4446 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4447 | if (e1000_phy_reset(hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | return -EIO; |
| 4449 | break; |
| 4450 | } |
| 4451 | } else { |
| 4452 | switch (data->reg_num) { |
| 4453 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4454 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4456 | if (netif_running(adapter->netdev)) |
| 4457 | e1000_reinit_locked(adapter); |
| 4458 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | e1000_reset(adapter); |
| 4460 | break; |
| 4461 | } |
| 4462 | } |
| 4463 | break; |
| 4464 | default: |
| 4465 | return -EOPNOTSUPP; |
| 4466 | } |
| 4467 | return E1000_SUCCESS; |
| 4468 | } |
| 4469 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4470 | void e1000_pci_set_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | { |
| 4472 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4473 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4475 | if (ret_val) |
Emil Tantilov | feb8f47 | 2010-07-26 23:37:21 -0700 | [diff] [blame] | 4476 | e_err(probe, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4479 | void e1000_pci_clear_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
| 4481 | struct e1000_adapter *adapter = hw->back; |
| 4482 | |
| 4483 | pci_clear_mwi(adapter->pdev); |
| 4484 | } |
| 4485 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4486 | int e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4487 | { |
| 4488 | struct e1000_adapter *adapter = hw->back; |
| 4489 | return pcix_get_mmrbc(adapter->pdev); |
| 4490 | } |
| 4491 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4492 | void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4493 | { |
| 4494 | struct e1000_adapter *adapter = hw->back; |
| 4495 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4496 | } |
| 4497 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4498 | void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | { |
| 4500 | outl(value, port); |
| 4501 | } |
| 4502 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4503 | static void e1000_vlan_rx_register(struct net_device *netdev, |
| 4504 | struct vlan_group *grp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4506 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4507 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4508 | u32 ctrl, rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4510 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4511 | e1000_irq_disable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | adapter->vlgrp = grp; |
| 4513 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4514 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | /* enable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4516 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | ctrl |= E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4518 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4520 | /* enable VLAN receive filtering */ |
| 4521 | rctl = er32(RCTL); |
| 4522 | rctl &= ~E1000_RCTL_CFIEN; |
| 4523 | if (!(netdev->flags & IFF_PROMISC)) |
| 4524 | rctl |= E1000_RCTL_VFE; |
| 4525 | ew32(RCTL, rctl); |
| 4526 | e1000_update_mng_vlan(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | } else { |
| 4528 | /* disable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4529 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | ctrl &= ~E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4531 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4533 | /* disable VLAN receive filtering */ |
| 4534 | rctl = er32(RCTL); |
| 4535 | rctl &= ~E1000_RCTL_VFE; |
| 4536 | ew32(RCTL, rctl); |
Graham, David | fd38d7a | 2009-08-31 14:12:51 +0000 | [diff] [blame] | 4537 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4538 | if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4539 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4540 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4544 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4545 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | } |
| 4547 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4548 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4550 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4551 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4552 | u32 vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4553 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4554 | if ((hw->mng_cookie.status & |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4555 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4556 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4557 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | /* add VID to filter table */ |
| 4559 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4560 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | vfta |= (1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4562 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4565 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4567 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4568 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4569 | u32 vfta, index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4571 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4572 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4573 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4574 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4575 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
| 4577 | /* remove VID from filter table */ |
| 4578 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4579 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | vfta &= ~(1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4581 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4584 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | { |
| 4586 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4587 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4588 | if (adapter->vlgrp) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4589 | u16 vid; |
Jesse Gross | b738127 | 2010-10-20 13:56:02 +0000 | [diff] [blame] | 4590 | for (vid = 0; vid < VLAN_N_VID; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4591 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | continue; |
| 4593 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4594 | } |
| 4595 | } |
| 4596 | } |
| 4597 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4598 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4600 | struct e1000_hw *hw = &adapter->hw; |
| 4601 | |
| 4602 | hw->autoneg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4604 | /* Make sure dplx is at most 1 bit and lsb of speed is not set |
| 4605 | * for the switch() below to work */ |
| 4606 | if ((spd & 1) || (dplx & ~1)) |
| 4607 | goto err_inval; |
| 4608 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4609 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4610 | if ((hw->media_type == e1000_media_type_fiber) && |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4611 | spd != SPEED_1000 && |
| 4612 | dplx != DUPLEX_FULL) |
| 4613 | goto err_inval; |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4614 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4615 | switch (spd + dplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | case SPEED_10 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4617 | hw->forced_speed_duplex = e1000_10_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | break; |
| 4619 | case SPEED_10 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4620 | hw->forced_speed_duplex = e1000_10_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | break; |
| 4622 | case SPEED_100 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4623 | hw->forced_speed_duplex = e1000_100_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | break; |
| 4625 | case SPEED_100 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4626 | hw->forced_speed_duplex = e1000_100_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | break; |
| 4628 | case SPEED_1000 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4629 | hw->autoneg = 1; |
| 4630 | hw->autoneg_advertised = ADVERTISE_1000_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | break; |
| 4632 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 4633 | default: |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4634 | goto err_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | } |
| 4636 | return 0; |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame^] | 4637 | |
| 4638 | err_inval: |
| 4639 | e_err(probe, "Unsupported Speed/Duplex configuration\n"); |
| 4640 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4643 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | { |
| 4645 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4646 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4647 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4648 | u32 ctrl, ctrl_ext, rctl, status; |
| 4649 | u32 wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4650 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4651 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4652 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | |
| 4654 | netif_device_detach(netdev); |
| 4655 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4656 | if (netif_running(netdev)) { |
| 4657 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4661 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 4662 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4663 | if (retval) |
| 4664 | return retval; |
| 4665 | #endif |
| 4666 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4667 | status = er32(STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4668 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | wufc &= ~E1000_WUFC_LNKC; |
| 4670 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4671 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | e1000_setup_rctl(adapter); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 4673 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | |
| 4675 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 4676 | if (wufc & E1000_WUFC_MC) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4677 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | rctl |= E1000_RCTL_MPE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4679 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4682 | if (hw->mac_type >= e1000_82540) { |
| 4683 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | /* advertise wake from D3Cold */ |
| 4685 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 4686 | /* phy power management enable */ |
| 4687 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 4688 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 4689 | E1000_CTRL_EN_PHY_PWR_MGMT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4690 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4693 | if (hw->media_type == e1000_media_type_fiber || |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4694 | hw->media_type == e1000_media_type_internal_serdes) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | /* keep the laser running in D3 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4696 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4698 | ew32(CTRL_EXT, ctrl_ext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4701 | ew32(WUC, E1000_WUC_PME_EN); |
| 4702 | ew32(WUFC, wufc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | } else { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4704 | ew32(WUC, 0); |
| 4705 | ew32(WUFC, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | } |
| 4707 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 4708 | e1000_release_manageability(adapter); |
| 4709 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4710 | *enable_wake = !!wufc; |
| 4711 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 4712 | /* make sure adapter isn't asleep if manageability is enabled */ |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4713 | if (adapter->en_mng_pt) |
| 4714 | *enable_wake = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 4716 | if (netif_running(netdev)) |
| 4717 | e1000_free_irq(adapter); |
| 4718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | return 0; |
| 4722 | } |
| 4723 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4724 | #ifdef CONFIG_PM |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4725 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4726 | { |
| 4727 | int retval; |
| 4728 | bool wake; |
| 4729 | |
| 4730 | retval = __e1000_shutdown(pdev, &wake); |
| 4731 | if (retval) |
| 4732 | return retval; |
| 4733 | |
| 4734 | if (wake) { |
| 4735 | pci_prepare_to_sleep(pdev); |
| 4736 | } else { |
| 4737 | pci_wake_from_d3(pdev, false); |
| 4738 | pci_set_power_state(pdev, PCI_D3hot); |
| 4739 | } |
| 4740 | |
| 4741 | return 0; |
| 4742 | } |
| 4743 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4744 | static int e1000_resume(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | { |
| 4746 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4747 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4748 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4749 | u32 err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 4751 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 4752 | pci_restore_state(pdev); |
Nick Nunley | dbb5aae | 2010-02-03 14:49:48 +0000 | [diff] [blame] | 4753 | pci_save_state(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 4754 | |
| 4755 | if (adapter->need_ioport) |
| 4756 | err = pci_enable_device(pdev); |
| 4757 | else |
| 4758 | err = pci_enable_device_mem(pdev); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 4759 | if (err) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4760 | pr_err("Cannot enable PCI device from suspend\n"); |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 4761 | return err; |
| 4762 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 4763 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 4765 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4766 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 4768 | if (netif_running(netdev)) { |
| 4769 | err = e1000_request_irq(adapter); |
| 4770 | if (err) |
| 4771 | return err; |
| 4772 | } |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 4773 | |
| 4774 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4776 | ew32(WUS, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 4778 | e1000_init_manageability(adapter); |
| 4779 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4780 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | e1000_up(adapter); |
| 4782 | |
| 4783 | netif_device_attach(netdev); |
| 4784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | return 0; |
| 4786 | } |
| 4787 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 4788 | |
| 4789 | static void e1000_shutdown(struct pci_dev *pdev) |
| 4790 | { |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4791 | bool wake; |
| 4792 | |
| 4793 | __e1000_shutdown(pdev, &wake); |
| 4794 | |
| 4795 | if (system_state == SYSTEM_POWER_OFF) { |
| 4796 | pci_wake_from_d3(pdev, wake); |
| 4797 | pci_set_power_state(pdev, PCI_D3hot); |
| 4798 | } |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4802 | /* |
| 4803 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 4804 | * without having to re-enable interrupts. It's not called while |
| 4805 | * the interrupt routine is executing. |
| 4806 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4807 | static void e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4809 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 4810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4812 | e1000_intr(adapter->pdev->irq, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | enable_irq(adapter->pdev->irq); |
| 4814 | } |
| 4815 | #endif |
| 4816 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4817 | /** |
| 4818 | * e1000_io_error_detected - called when PCI error is detected |
| 4819 | * @pdev: Pointer to PCI device |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4820 | * @state: The current pci connection state |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4821 | * |
| 4822 | * This function is called after a PCI bus error affecting |
| 4823 | * this device has been detected. |
| 4824 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4825 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 4826 | pci_channel_state_t state) |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4827 | { |
| 4828 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 4829 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4830 | |
| 4831 | netif_device_detach(netdev); |
| 4832 | |
Andre Detsch | eab6330 | 2009-06-30 12:46:13 +0000 | [diff] [blame] | 4833 | if (state == pci_channel_io_perm_failure) |
| 4834 | return PCI_ERS_RESULT_DISCONNECT; |
| 4835 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4836 | if (netif_running(netdev)) |
| 4837 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 4838 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4839 | |
| 4840 | /* Request a slot slot reset. */ |
| 4841 | return PCI_ERS_RESULT_NEED_RESET; |
| 4842 | } |
| 4843 | |
| 4844 | /** |
| 4845 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 4846 | * @pdev: Pointer to PCI device |
| 4847 | * |
| 4848 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 4849 | * resembles the first-half of the e1000_resume routine. |
| 4850 | */ |
| 4851 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 4852 | { |
| 4853 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 4854 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4855 | struct e1000_hw *hw = &adapter->hw; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 4856 | int err; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4857 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 4858 | if (adapter->need_ioport) |
| 4859 | err = pci_enable_device(pdev); |
| 4860 | else |
| 4861 | err = pci_enable_device_mem(pdev); |
| 4862 | if (err) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4863 | pr_err("Cannot re-enable PCI device after reset.\n"); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4864 | return PCI_ERS_RESULT_DISCONNECT; |
| 4865 | } |
| 4866 | pci_set_master(pdev); |
| 4867 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 4868 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4869 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4870 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4871 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4872 | ew32(WUS, ~0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4873 | |
| 4874 | return PCI_ERS_RESULT_RECOVERED; |
| 4875 | } |
| 4876 | |
| 4877 | /** |
| 4878 | * e1000_io_resume - called when traffic can start flowing again. |
| 4879 | * @pdev: Pointer to PCI device |
| 4880 | * |
| 4881 | * This callback is called when the error recovery driver tells us that |
| 4882 | * its OK to resume normal operation. Implementation resembles the |
| 4883 | * second-half of the e1000_resume routine. |
| 4884 | */ |
| 4885 | static void e1000_io_resume(struct pci_dev *pdev) |
| 4886 | { |
| 4887 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 4888 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 4889 | |
| 4890 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4891 | |
| 4892 | if (netif_running(netdev)) { |
| 4893 | if (e1000_up(adapter)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4894 | pr_info("can't bring device back up after reset\n"); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4895 | return; |
| 4896 | } |
| 4897 | } |
| 4898 | |
| 4899 | netif_device_attach(netdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | /* e1000_main.c */ |