Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the Free |
| 8 | Software Foundation; either version 2 of the License, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License along with |
| 17 | this program; if not, write to the Free Software Foundation, Inc., 59 |
| 18 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | |
| 20 | The full GNU General Public License is included in this distribution in the |
| 21 | file called LICENSE. |
| 22 | |
| 23 | Contact Information: |
| 24 | Linux NICS <linux.nics@intel.com> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include "e1000.h" |
| 30 | |
| 31 | /* Change Log |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 32 | * 7.0.33 3-Feb-2006 |
| 33 | * o Added another fix for the pass false carrier bit |
| 34 | * 7.0.32 24-Jan-2006 |
| 35 | * o Need to rebuild with noew version number for the pass false carrier |
| 36 | * fix in e1000_hw.c |
| 37 | * 7.0.30 18-Jan-2006 |
| 38 | * o fixup for tso workaround to disable it for pci-x |
| 39 | * o fix mem leak on 82542 |
| 40 | * o fixes for 10 Mb/s connections and incorrect stats |
| 41 | * 7.0.28 01/06/2006 |
| 42 | * o hardware workaround to only set "speed mode" bit for 1G link. |
| 43 | * 7.0.26 12/23/2005 |
| 44 | * o wake on lan support modified for device ID 10B5 |
| 45 | * o fix dhcp + vlan issue not making it to the iAMT firmware |
| 46 | * 7.0.24 12/9/2005 |
| 47 | * o New hardware support for the Gigabit NIC embedded in the south bridge |
| 48 | * o Fixes to the recycling logic (skb->tail) from IBM LTC |
Jesse Brandeburg | 73629bb | 2006-01-18 13:01:41 -0800 | [diff] [blame] | 49 | * 6.3.9 12/16/2005 |
| 50 | * o incorporate fix for recycled skbs from IBM LTC |
| 51 | * 6.3.7 11/18/2005 |
| 52 | * o Honor eeprom setting for enabling/disabling Wake On Lan |
| 53 | * 6.3.5 11/17/2005 |
| 54 | * o Fix memory leak in rx ring handling for PCI Express adapters |
| 55 | * 6.3.4 11/8/05 |
| 56 | * o Patch from Jesper Juhl to remove redundant NULL checks for kfree |
| 57 | * 6.3.2 9/20/05 |
| 58 | * o Render logic that sets/resets DRV_LOAD as inline functions to |
| 59 | * avoid code replication. If f/w is AMT then set DRV_LOAD only when |
| 60 | * network interface is open. |
| 61 | * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs. |
| 62 | * o Adjust PBA partioning for Jumbo frames using MTU size and not |
| 63 | * rx_buffer_len |
| 64 | * 6.3.1 9/19/05 |
| 65 | * o Use adapter->tx_timeout_factor in Tx Hung Detect logic |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 66 | * (e1000_clean_tx_irq) |
Jesse Brandeburg | 73629bb | 2006-01-18 13:01:41 -0800 | [diff] [blame] | 67 | * o Support for 8086:10B5 device (Quad Port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | |
| 70 | char e1000_driver_name[] = "e1000"; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 71 | static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #ifndef CONFIG_E1000_NAPI |
| 73 | #define DRIVERNAPI |
| 74 | #else |
| 75 | #define DRIVERNAPI "-NAPI" |
| 76 | #endif |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 77 | #define DRV_VERSION "7.0.33-k2"DRIVERNAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | char e1000_driver_version[] = DRV_VERSION; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 79 | static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* e1000_pci_tbl - PCI Device ID Table |
| 82 | * |
| 83 | * Last entry must be all 0s |
| 84 | * |
| 85 | * Macro expands to... |
| 86 | * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
| 87 | */ |
| 88 | static struct pci_device_id e1000_pci_tbl[] = { |
| 89 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 90 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 91 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 92 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 93 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 94 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 95 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 96 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 97 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 98 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 99 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 100 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 101 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 102 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 103 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 104 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 105 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 106 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 107 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 108 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 110 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 111 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 112 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 113 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 114 | INTEL_E1000_ETHERNET_DEVICE(0x105E), |
| 115 | INTEL_E1000_ETHERNET_DEVICE(0x105F), |
| 116 | INTEL_E1000_ETHERNET_DEVICE(0x1060), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 118 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 119 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 120 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 121 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 122 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 123 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 124 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 125 | INTEL_E1000_ETHERNET_DEVICE(0x107D), |
| 126 | INTEL_E1000_ETHERNET_DEVICE(0x107E), |
| 127 | INTEL_E1000_ETHERNET_DEVICE(0x107F), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 129 | INTEL_E1000_ETHERNET_DEVICE(0x108B), |
| 130 | INTEL_E1000_ETHERNET_DEVICE(0x108C), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 131 | INTEL_E1000_ETHERNET_DEVICE(0x1096), |
| 132 | INTEL_E1000_ETHERNET_DEVICE(0x1098), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 133 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 134 | INTEL_E1000_ETHERNET_DEVICE(0x109A), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 135 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 136 | INTEL_E1000_ETHERNET_DEVICE(0x10B9), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* required last entry */ |
| 138 | {0,} |
| 139 | }; |
| 140 | |
| 141 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 142 | |
| 143 | int e1000_up(struct e1000_adapter *adapter); |
| 144 | void e1000_down(struct e1000_adapter *adapter); |
| 145 | void e1000_reset(struct e1000_adapter *adapter); |
| 146 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 147 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 148 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 149 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 150 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 151 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 152 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 153 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 154 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 155 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 156 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 157 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 158 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | void e1000_update_stats(struct e1000_adapter *adapter); |
| 160 | |
| 161 | /* Local Function Prototypes */ |
| 162 | |
| 163 | static int e1000_init_module(void); |
| 164 | static void e1000_exit_module(void); |
| 165 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 166 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 167 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 169 | static int e1000_open(struct net_device *netdev); |
| 170 | static int e1000_close(struct net_device *netdev); |
| 171 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 172 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 173 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 174 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 175 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 176 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 177 | struct e1000_tx_ring *tx_ring); |
| 178 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 179 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | static void e1000_set_multi(struct net_device *netdev); |
| 181 | static void e1000_update_phy_info(unsigned long data); |
| 182 | static void e1000_watchdog(unsigned long data); |
| 183 | static void e1000_watchdog_task(struct e1000_adapter *adapter); |
| 184 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 185 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 186 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 187 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 188 | static int e1000_set_mac(struct net_device *netdev, void *p); |
| 189 | static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 190 | static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 191 | struct e1000_tx_ring *tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 193 | static int e1000_clean(struct net_device *poll_dev, int *budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 195 | struct e1000_rx_ring *rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | int *work_done, int work_to_do); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 197 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 198 | struct e1000_rx_ring *rx_ring, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 199 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 201 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 202 | struct e1000_rx_ring *rx_ring); |
| 203 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 204 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 206 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 207 | struct e1000_rx_ring *rx_ring, |
| 208 | int cleaned_count); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 209 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 210 | struct e1000_rx_ring *rx_ring, |
| 211 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 213 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 214 | int cmd); |
| 215 | void e1000_set_ethtool_ops(struct net_device *netdev); |
| 216 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 217 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 218 | static void e1000_tx_timeout(struct net_device *dev); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 219 | static void e1000_reset_task(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
| 221 | static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 222 | struct sk_buff *skb); |
| 223 | |
| 224 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
| 225 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 226 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 227 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #ifdef CONFIG_PM |
Ashutosh Naik | 977e74b | 2005-10-28 15:14:53 -0700 | [diff] [blame] | 230 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static int e1000_resume(struct pci_dev *pdev); |
| 232 | #endif |
| 233 | |
| 234 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 235 | /* for netdump / net console */ |
| 236 | static void e1000_netpoll (struct net_device *netdev); |
| 237 | #endif |
| 238 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* Exported from other modules */ |
| 241 | |
| 242 | extern void e1000_check_options(struct e1000_adapter *adapter); |
| 243 | |
| 244 | static struct pci_driver e1000_driver = { |
| 245 | .name = e1000_driver_name, |
| 246 | .id_table = e1000_pci_tbl, |
| 247 | .probe = e1000_probe, |
| 248 | .remove = __devexit_p(e1000_remove), |
| 249 | /* Power Managment Hooks */ |
| 250 | #ifdef CONFIG_PM |
| 251 | .suspend = e1000_suspend, |
| 252 | .resume = e1000_resume |
| 253 | #endif |
| 254 | }; |
| 255 | |
| 256 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 257 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 258 | MODULE_LICENSE("GPL"); |
| 259 | MODULE_VERSION(DRV_VERSION); |
| 260 | |
| 261 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 262 | module_param(debug, int, 0); |
| 263 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 264 | |
| 265 | /** |
| 266 | * e1000_init_module - Driver Registration Routine |
| 267 | * |
| 268 | * e1000_init_module is the first routine called when the driver is |
| 269 | * loaded. All it does is register with the PCI subsystem. |
| 270 | **/ |
| 271 | |
| 272 | static int __init |
| 273 | e1000_init_module(void) |
| 274 | { |
| 275 | int ret; |
| 276 | printk(KERN_INFO "%s - version %s\n", |
| 277 | e1000_driver_string, e1000_driver_version); |
| 278 | |
| 279 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 280 | |
| 281 | ret = pci_module_init(&e1000_driver); |
Tony Luck | 8b378def | 2005-07-28 01:07:38 -0700 | [diff] [blame] | 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | module_init(e1000_init_module); |
| 287 | |
| 288 | /** |
| 289 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 290 | * |
| 291 | * e1000_exit_module is called just before the driver is removed |
| 292 | * from memory. |
| 293 | **/ |
| 294 | |
| 295 | static void __exit |
| 296 | e1000_exit_module(void) |
| 297 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | pci_unregister_driver(&e1000_driver); |
| 299 | } |
| 300 | |
| 301 | module_exit(e1000_exit_module); |
| 302 | |
| 303 | /** |
| 304 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 305 | * @adapter: board private structure |
| 306 | **/ |
| 307 | |
| 308 | static inline void |
| 309 | e1000_irq_disable(struct e1000_adapter *adapter) |
| 310 | { |
| 311 | atomic_inc(&adapter->irq_sem); |
| 312 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 313 | E1000_WRITE_FLUSH(&adapter->hw); |
| 314 | synchronize_irq(adapter->pdev->irq); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * e1000_irq_enable - Enable default interrupt generation settings |
| 319 | * @adapter: board private structure |
| 320 | **/ |
| 321 | |
| 322 | static inline void |
| 323 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 324 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 325 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 327 | E1000_WRITE_FLUSH(&adapter->hw); |
| 328 | } |
| 329 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 330 | |
| 331 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 332 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 333 | { |
| 334 | struct net_device *netdev = adapter->netdev; |
| 335 | uint16_t vid = adapter->hw.mng_cookie.vlan_id; |
| 336 | uint16_t old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 337 | if (adapter->vlgrp) { |
| 338 | if (!adapter->vlgrp->vlan_devices[vid]) { |
| 339 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 340 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 341 | e1000_vlan_rx_add_vid(netdev, vid); |
| 342 | adapter->mng_vlan_id = vid; |
| 343 | } else |
| 344 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 345 | |
| 346 | if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && |
| 347 | (vid != old_vid) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 348 | !adapter->vlgrp->vlan_devices[old_vid]) |
| 349 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 350 | } else |
| 351 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 352 | } |
| 353 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 354 | |
| 355 | /** |
| 356 | * e1000_release_hw_control - release control of the h/w to f/w |
| 357 | * @adapter: address of board private structure |
| 358 | * |
| 359 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 360 | * For ASF and Pass Through versions of f/w this means that the |
| 361 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 362 | * of the f/w this means that the netowrk i/f is closed. |
| 363 | * |
| 364 | **/ |
| 365 | |
| 366 | static inline void |
| 367 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 368 | { |
| 369 | uint32_t ctrl_ext; |
| 370 | uint32_t swsm; |
| 371 | |
| 372 | /* Let firmware taken over control of h/w */ |
| 373 | switch (adapter->hw.mac_type) { |
| 374 | case e1000_82571: |
| 375 | case e1000_82572: |
| 376 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 377 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 378 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 379 | break; |
| 380 | case e1000_82573: |
| 381 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 382 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 383 | swsm & ~E1000_SWSM_DRV_LOAD); |
| 384 | default: |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * e1000_get_hw_control - get control of the h/w from f/w |
| 391 | * @adapter: address of board private structure |
| 392 | * |
| 393 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 394 | * For ASF and Pass Through versions of f/w this means that |
| 395 | * the driver is loaded. For AMT version (only with 82573) |
| 396 | * of the f/w this means that the netowrk i/f is open. |
| 397 | * |
| 398 | **/ |
| 399 | |
| 400 | static inline void |
| 401 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 402 | { |
| 403 | uint32_t ctrl_ext; |
| 404 | uint32_t swsm; |
| 405 | /* Let firmware know the driver has taken over */ |
| 406 | switch (adapter->hw.mac_type) { |
| 407 | case e1000_82571: |
| 408 | case e1000_82572: |
| 409 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 410 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 411 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 412 | break; |
| 413 | case e1000_82573: |
| 414 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 415 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 416 | swsm | E1000_SWSM_DRV_LOAD); |
| 417 | break; |
| 418 | default: |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | int |
| 424 | e1000_up(struct e1000_adapter *adapter) |
| 425 | { |
| 426 | struct net_device *netdev = adapter->netdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 427 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | /* hardware has been reset, we need to reload some things */ |
| 430 | |
| 431 | /* Reset the PHY if it was previously powered down */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 432 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | uint16_t mii_reg; |
| 434 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 435 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | e1000_phy_reset(&adapter->hw); |
| 437 | } |
| 438 | |
| 439 | e1000_set_multi(netdev); |
| 440 | |
| 441 | e1000_restore_vlan(adapter); |
| 442 | |
| 443 | e1000_configure_tx(adapter); |
| 444 | e1000_setup_rctl(adapter); |
| 445 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 446 | /* call E1000_DESC_UNUSED which always leaves |
| 447 | * at least 1 descriptor unused to make sure |
| 448 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 449 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 450 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 451 | adapter->alloc_rx_buf(adapter, ring, |
| 452 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 455 | #ifdef CONFIG_PCI_MSI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 456 | if (adapter->hw.mac_type > e1000_82547_rev_2) { |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 457 | adapter->have_msi = TRUE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 458 | if ((err = pci_enable_msi(adapter->pdev))) { |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 459 | DPRINTK(PROBE, ERR, |
| 460 | "Unable to allocate MSI interrupt Error: %d\n", err); |
| 461 | adapter->have_msi = FALSE; |
| 462 | } |
| 463 | } |
| 464 | #endif |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 465 | if ((err = request_irq(adapter->pdev->irq, &e1000_intr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | SA_SHIRQ | SA_SAMPLE_RANDOM, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 467 | netdev->name, netdev))) { |
| 468 | DPRINTK(PROBE, ERR, |
| 469 | "Unable to allocate interrupt Error: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return err; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 473 | adapter->tx_queue_len = netdev->tx_queue_len; |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | mod_timer(&adapter->watchdog_timer, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | #ifdef CONFIG_E1000_NAPI |
| 478 | netif_poll_enable(netdev); |
| 479 | #endif |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 480 | e1000_irq_enable(adapter); |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | void |
| 486 | e1000_down(struct e1000_adapter *adapter) |
| 487 | { |
| 488 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 489 | boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) && |
| 490 | e1000_check_mng_mode(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | free_irq(adapter->pdev->irq, netdev); |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 495 | #ifdef CONFIG_PCI_MSI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 496 | if (adapter->hw.mac_type > e1000_82547_rev_2 && |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 497 | adapter->have_msi == TRUE) |
| 498 | pci_disable_msi(adapter->pdev); |
| 499 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 501 | del_timer_sync(&adapter->watchdog_timer); |
| 502 | del_timer_sync(&adapter->phy_info_timer); |
| 503 | |
| 504 | #ifdef CONFIG_E1000_NAPI |
| 505 | netif_poll_disable(netdev); |
| 506 | #endif |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 507 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | adapter->link_speed = 0; |
| 509 | adapter->link_duplex = 0; |
| 510 | netif_carrier_off(netdev); |
| 511 | netif_stop_queue(netdev); |
| 512 | |
| 513 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 514 | e1000_clean_all_tx_rings(adapter); |
| 515 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 517 | /* Power down the PHY so no link is implied when interface is down * |
| 518 | * The PHY cannot be powered down if any of the following is TRUE * |
| 519 | * (a) WoL is enabled |
| 520 | * (b) AMT is active |
| 521 | * (c) SoL/IDER session is active */ |
| 522 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 523 | adapter->hw.media_type == e1000_media_type_copper && |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 524 | !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) && |
| 525 | !mng_mode_enabled && |
| 526 | !e1000_check_phy_reset_block(&adapter->hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | uint16_t mii_reg; |
| 528 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 529 | mii_reg |= MII_CR_POWER_DOWN; |
| 530 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
Malli Chilakala | 4e48a2b | 2005-04-28 19:39:53 -0700 | [diff] [blame] | 531 | mdelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | void |
| 536 | e1000_reset(struct e1000_adapter *adapter) |
| 537 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 538 | uint32_t pba, manc; |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 539 | uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | /* Repartition Pba for greater than 9k mtu |
| 542 | * To take effect CTRL.RST is required. |
| 543 | */ |
| 544 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 545 | switch (adapter->hw.mac_type) { |
| 546 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 547 | case e1000_82547_rev_2: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 548 | pba = E1000_PBA_30K; |
| 549 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 550 | case e1000_82571: |
| 551 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 552 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 553 | pba = E1000_PBA_38K; |
| 554 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 555 | case e1000_82573: |
| 556 | pba = E1000_PBA_12K; |
| 557 | break; |
| 558 | default: |
| 559 | pba = E1000_PBA_48K; |
| 560 | break; |
| 561 | } |
| 562 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 563 | if ((adapter->hw.mac_type != e1000_82573) && |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 564 | (adapter->netdev->mtu > E1000_RXBUFFER_8192)) |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 565 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 566 | |
| 567 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 568 | if (adapter->hw.mac_type == e1000_82547) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | adapter->tx_fifo_head = 0; |
| 570 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 571 | adapter->tx_fifo_size = |
| 572 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 573 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 574 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 577 | |
| 578 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 579 | /* Set the FC high water mark to 90% of the FIFO size. |
| 580 | * Required to clear last 3 LSB */ |
| 581 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
| 582 | |
| 583 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 584 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 585 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 586 | adapter->hw.fc_pause_time = 0xFFFF; |
| 587 | else |
| 588 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | adapter->hw.fc_send_xon = 1; |
| 590 | adapter->hw.fc = adapter->hw.original_fc; |
| 591 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 592 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 594 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 596 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 598 | e1000_update_mng_vlan(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 600 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 601 | |
| 602 | e1000_reset_adaptive(&adapter->hw); |
| 603 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 604 | if (adapter->en_mng_pt) { |
| 605 | manc = E1000_READ_REG(&adapter->hw, MANC); |
| 606 | manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST); |
| 607 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
| 612 | * e1000_probe - Device Initialization Routine |
| 613 | * @pdev: PCI device information struct |
| 614 | * @ent: entry in e1000_pci_tbl |
| 615 | * |
| 616 | * Returns 0 on success, negative on failure |
| 617 | * |
| 618 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 619 | * The OS initialization, configuring of the adapter private structure, |
| 620 | * and a hardware reset occur. |
| 621 | **/ |
| 622 | |
| 623 | static int __devinit |
| 624 | e1000_probe(struct pci_dev *pdev, |
| 625 | const struct pci_device_id *ent) |
| 626 | { |
| 627 | struct net_device *netdev; |
| 628 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 629 | unsigned long mmio_start, mmio_len; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | static int cards_found = 0; |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 632 | static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 633 | int i, err, pci_using_dac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | uint16_t eeprom_data; |
| 635 | uint16_t eeprom_apme_mask = E1000_EEPROM_APME; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 636 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | return err; |
| 638 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 639 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | pci_using_dac = 1; |
| 641 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 642 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | E1000_ERR("No usable DMA configuration, aborting\n"); |
| 644 | return err; |
| 645 | } |
| 646 | pci_using_dac = 0; |
| 647 | } |
| 648 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 649 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return err; |
| 651 | |
| 652 | pci_set_master(pdev); |
| 653 | |
| 654 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 655 | if (!netdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | err = -ENOMEM; |
| 657 | goto err_alloc_etherdev; |
| 658 | } |
| 659 | |
| 660 | SET_MODULE_OWNER(netdev); |
| 661 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 662 | |
| 663 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 664 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | adapter->netdev = netdev; |
| 666 | adapter->pdev = pdev; |
| 667 | adapter->hw.back = adapter; |
| 668 | adapter->msg_enable = (1 << debug) - 1; |
| 669 | |
| 670 | mmio_start = pci_resource_start(pdev, BAR_0); |
| 671 | mmio_len = pci_resource_len(pdev, BAR_0); |
| 672 | |
| 673 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 674 | if (!adapter->hw.hw_addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | err = -EIO; |
| 676 | goto err_ioremap; |
| 677 | } |
| 678 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 679 | for (i = BAR_1; i <= BAR_5; i++) { |
| 680 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 682 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | netdev->open = &e1000_open; |
| 689 | netdev->stop = &e1000_close; |
| 690 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 691 | netdev->get_stats = &e1000_get_stats; |
| 692 | netdev->set_multicast_list = &e1000_set_multi; |
| 693 | netdev->set_mac_address = &e1000_set_mac; |
| 694 | netdev->change_mtu = &e1000_change_mtu; |
| 695 | netdev->do_ioctl = &e1000_ioctl; |
| 696 | e1000_set_ethtool_ops(netdev); |
| 697 | netdev->tx_timeout = &e1000_tx_timeout; |
| 698 | netdev->watchdog_timeo = 5 * HZ; |
| 699 | #ifdef CONFIG_E1000_NAPI |
| 700 | netdev->poll = &e1000_clean; |
| 701 | netdev->weight = 64; |
| 702 | #endif |
| 703 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 704 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 705 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 706 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 707 | netdev->poll_controller = e1000_netpoll; |
| 708 | #endif |
| 709 | strcpy(netdev->name, pci_name(pdev)); |
| 710 | |
| 711 | netdev->mem_start = mmio_start; |
| 712 | netdev->mem_end = mmio_start + mmio_len; |
| 713 | netdev->base_addr = adapter->hw.io_base; |
| 714 | |
| 715 | adapter->bd_number = cards_found; |
| 716 | |
| 717 | /* setup the private structure */ |
| 718 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 719 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | goto err_sw_init; |
| 721 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 722 | if ((err = e1000_check_phy_reset_block(&adapter->hw))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 723 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 724 | |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 725 | /* if ksp3, indicate if it's port a being setup */ |
| 726 | if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 && |
| 727 | e1000_ksp3_port_a == 0) |
| 728 | adapter->ksp3_port_a = 1; |
| 729 | e1000_ksp3_port_a++; |
| 730 | /* Reset for multiple KP3 adapters */ |
| 731 | if (e1000_ksp3_port_a == 4) |
| 732 | e1000_ksp3_port_a = 0; |
| 733 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 734 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | netdev->features = NETIF_F_SG | |
| 736 | NETIF_F_HW_CSUM | |
| 737 | NETIF_F_HW_VLAN_TX | |
| 738 | NETIF_F_HW_VLAN_RX | |
| 739 | NETIF_F_HW_VLAN_FILTER; |
| 740 | } |
| 741 | |
| 742 | #ifdef NETIF_F_TSO |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 743 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | (adapter->hw.mac_type != e1000_82547)) |
| 745 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 746 | |
| 747 | #ifdef NETIF_F_TSO_IPV6 |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 748 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 749 | netdev->features |= NETIF_F_TSO_IPV6; |
| 750 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | #endif |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 752 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | netdev->features |= NETIF_F_HIGHDMA; |
| 754 | |
| 755 | /* hard_start_xmit is safe against parallel locking */ |
| 756 | netdev->features |= NETIF_F_LLTX; |
| 757 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 758 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 759 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 760 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | e1000_reset_hw(&adapter->hw); |
| 764 | |
| 765 | /* make sure the EEPROM is good */ |
| 766 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 767 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
| 769 | err = -EIO; |
| 770 | goto err_eeprom; |
| 771 | } |
| 772 | |
| 773 | /* copy the MAC address out of the EEPROM */ |
| 774 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 775 | if (e1000_read_mac_addr(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
| 777 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 778 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 780 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
| 782 | err = -EIO; |
| 783 | goto err_eeprom; |
| 784 | } |
| 785 | |
| 786 | e1000_read_part_num(&adapter->hw, &(adapter->part_num)); |
| 787 | |
| 788 | e1000_get_bus_info(&adapter->hw); |
| 789 | |
| 790 | init_timer(&adapter->tx_fifo_stall_timer); |
| 791 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 792 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 793 | |
| 794 | init_timer(&adapter->watchdog_timer); |
| 795 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 796 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 797 | |
| 798 | INIT_WORK(&adapter->watchdog_task, |
| 799 | (void (*)(void *))e1000_watchdog_task, adapter); |
| 800 | |
| 801 | init_timer(&adapter->phy_info_timer); |
| 802 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 803 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 804 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 805 | INIT_WORK(&adapter->reset_task, |
| 806 | (void (*)(void *))e1000_reset_task, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
| 808 | /* we're going to reset, so assume we have no link for now */ |
| 809 | |
| 810 | netif_carrier_off(netdev); |
| 811 | netif_stop_queue(netdev); |
| 812 | |
| 813 | e1000_check_options(adapter); |
| 814 | |
| 815 | /* Initial Wake on LAN setting |
| 816 | * If APM wake is enabled in the EEPROM, |
| 817 | * enable the ACPI Magic Packet filter |
| 818 | */ |
| 819 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 820 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | case e1000_82542_rev2_0: |
| 822 | case e1000_82542_rev2_1: |
| 823 | case e1000_82543: |
| 824 | break; |
| 825 | case e1000_82544: |
| 826 | e1000_read_eeprom(&adapter->hw, |
| 827 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 828 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 829 | break; |
| 830 | case e1000_82546: |
| 831 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 832 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 833 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 834 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | e1000_read_eeprom(&adapter->hw, |
| 836 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 837 | break; |
| 838 | } |
| 839 | /* Fall Through */ |
| 840 | default: |
| 841 | e1000_read_eeprom(&adapter->hw, |
| 842 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 843 | break; |
| 844 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 845 | if (eeprom_data & eeprom_apme_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | adapter->wol |= E1000_WUFC_MAG; |
| 847 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 848 | /* print bus type/speed/width info */ |
| 849 | { |
| 850 | struct e1000_hw *hw = &adapter->hw; |
| 851 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 852 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 853 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 854 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 855 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 856 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 857 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 858 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 859 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 860 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 861 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 862 | "32-bit")); |
| 863 | } |
| 864 | |
| 865 | for (i = 0; i < 6; i++) |
| 866 | printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':'); |
| 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* reset the hardware with the new settings */ |
| 869 | e1000_reset(adapter); |
| 870 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 871 | /* If the controller is 82573 and f/w is AMT, do not set |
| 872 | * DRV_LOAD until the interface is up. For all other cases, |
| 873 | * let the f/w know that the h/w is now under the control |
| 874 | * of the driver. */ |
| 875 | if (adapter->hw.mac_type != e1000_82573 || |
| 876 | !e1000_check_mng_mode(&adapter->hw)) |
| 877 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | strcpy(netdev->name, "eth%d"); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 880 | if ((err = register_netdev(netdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | goto err_register; |
| 882 | |
| 883 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 884 | |
| 885 | cards_found++; |
| 886 | return 0; |
| 887 | |
| 888 | err_register: |
| 889 | err_sw_init: |
| 890 | err_eeprom: |
| 891 | iounmap(adapter->hw.hw_addr); |
| 892 | err_ioremap: |
| 893 | free_netdev(netdev); |
| 894 | err_alloc_etherdev: |
| 895 | pci_release_regions(pdev); |
| 896 | return err; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * e1000_remove - Device Removal Routine |
| 901 | * @pdev: PCI device information struct |
| 902 | * |
| 903 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 904 | * that it should release a PCI device. The could be caused by a |
| 905 | * Hot-Plug event, or because the driver is going to be removed from |
| 906 | * memory. |
| 907 | **/ |
| 908 | |
| 909 | static void __devexit |
| 910 | e1000_remove(struct pci_dev *pdev) |
| 911 | { |
| 912 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 913 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 914 | uint32_t manc; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 915 | #ifdef CONFIG_E1000_NAPI |
| 916 | int i; |
| 917 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 919 | flush_scheduled_work(); |
| 920 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 921 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | adapter->hw.media_type == e1000_media_type_copper) { |
| 923 | manc = E1000_READ_REG(&adapter->hw, MANC); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 924 | if (manc & E1000_MANC_SMBUS_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | manc |= E1000_MANC_ARP_EN; |
| 926 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 927 | } |
| 928 | } |
| 929 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 930 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 931 | * would have already happened in close and is redundant. */ |
| 932 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | unregister_netdev(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 935 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 936 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 937 | __dev_put(&adapter->polling_netdev[i]); |
| 938 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 940 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 941 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 943 | kfree(adapter->tx_ring); |
| 944 | kfree(adapter->rx_ring); |
| 945 | #ifdef CONFIG_E1000_NAPI |
| 946 | kfree(adapter->polling_netdev); |
| 947 | #endif |
| 948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | iounmap(adapter->hw.hw_addr); |
| 950 | pci_release_regions(pdev); |
| 951 | |
| 952 | free_netdev(netdev); |
| 953 | |
| 954 | pci_disable_device(pdev); |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 959 | * @adapter: board private structure to initialize |
| 960 | * |
| 961 | * e1000_sw_init initializes the Adapter private data structure. |
| 962 | * Fields are initialized based on PCI device information and |
| 963 | * OS network device settings (MTU size). |
| 964 | **/ |
| 965 | |
| 966 | static int __devinit |
| 967 | e1000_sw_init(struct e1000_adapter *adapter) |
| 968 | { |
| 969 | struct e1000_hw *hw = &adapter->hw; |
| 970 | struct net_device *netdev = adapter->netdev; |
| 971 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 972 | #ifdef CONFIG_E1000_NAPI |
| 973 | int i; |
| 974 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | /* PCI config space info */ |
| 977 | |
| 978 | hw->vendor_id = pdev->vendor; |
| 979 | hw->device_id = pdev->device; |
| 980 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 981 | hw->subsystem_id = pdev->subsystem_device; |
| 982 | |
| 983 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 984 | |
| 985 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 986 | |
| 987 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 988 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | hw->max_frame_size = netdev->mtu + |
| 990 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 991 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 992 | |
| 993 | /* identify the MAC */ |
| 994 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 995 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 997 | return -EIO; |
| 998 | } |
| 999 | |
| 1000 | /* initialize eeprom parameters */ |
| 1001 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1002 | if (e1000_init_eeprom_params(hw)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1003 | E1000_ERR("EEPROM initialization failed\n"); |
| 1004 | return -EIO; |
| 1005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1007 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | default: |
| 1009 | break; |
| 1010 | case e1000_82541: |
| 1011 | case e1000_82547: |
| 1012 | case e1000_82541_rev_2: |
| 1013 | case e1000_82547_rev_2: |
| 1014 | hw->phy_init_script = 1; |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | e1000_set_media_type(hw); |
| 1019 | |
| 1020 | hw->wait_autoneg_complete = FALSE; |
| 1021 | hw->tbi_compatibility_en = TRUE; |
| 1022 | hw->adaptive_ifs = TRUE; |
| 1023 | |
| 1024 | /* Copper options */ |
| 1025 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1026 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | hw->mdix = AUTO_ALL_MODES; |
| 1028 | hw->disable_polarity_correction = FALSE; |
| 1029 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1030 | } |
| 1031 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1032 | adapter->num_tx_queues = 1; |
| 1033 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1034 | |
| 1035 | if (e1000_alloc_queues(adapter)) { |
| 1036 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1037 | return -ENOMEM; |
| 1038 | } |
| 1039 | |
| 1040 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1041 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1042 | adapter->polling_netdev[i].priv = adapter; |
| 1043 | adapter->polling_netdev[i].poll = &e1000_clean; |
| 1044 | adapter->polling_netdev[i].weight = 64; |
| 1045 | dev_hold(&adapter->polling_netdev[i]); |
| 1046 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1047 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1048 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1049 | #endif |
| 1050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | atomic_set(&adapter->irq_sem, 1); |
| 1052 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1058 | * e1000_alloc_queues - Allocate memory for all rings |
| 1059 | * @adapter: board private structure to initialize |
| 1060 | * |
| 1061 | * We allocate one ring per queue at run-time since we don't know the |
| 1062 | * number of queues at compile-time. The polling_netdev array is |
| 1063 | * intended for Multiqueue, but should work fine with a single queue. |
| 1064 | **/ |
| 1065 | |
| 1066 | static int __devinit |
| 1067 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1068 | { |
| 1069 | int size; |
| 1070 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1071 | size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1072 | adapter->tx_ring = kmalloc(size, GFP_KERNEL); |
| 1073 | if (!adapter->tx_ring) |
| 1074 | return -ENOMEM; |
| 1075 | memset(adapter->tx_ring, 0, size); |
| 1076 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1077 | size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1078 | adapter->rx_ring = kmalloc(size, GFP_KERNEL); |
| 1079 | if (!adapter->rx_ring) { |
| 1080 | kfree(adapter->tx_ring); |
| 1081 | return -ENOMEM; |
| 1082 | } |
| 1083 | memset(adapter->rx_ring, 0, size); |
| 1084 | |
| 1085 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1086 | size = sizeof(struct net_device) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1087 | adapter->polling_netdev = kmalloc(size, GFP_KERNEL); |
| 1088 | if (!adapter->polling_netdev) { |
| 1089 | kfree(adapter->tx_ring); |
| 1090 | kfree(adapter->rx_ring); |
| 1091 | return -ENOMEM; |
| 1092 | } |
| 1093 | memset(adapter->polling_netdev, 0, size); |
| 1094 | #endif |
| 1095 | |
| 1096 | return E1000_SUCCESS; |
| 1097 | } |
| 1098 | |
| 1099 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | * e1000_open - Called when a network interface is made active |
| 1101 | * @netdev: network interface device structure |
| 1102 | * |
| 1103 | * Returns 0 on success, negative value on failure |
| 1104 | * |
| 1105 | * The open entry point is called when a network interface is made |
| 1106 | * active by the system (IFF_UP). At this point all resources needed |
| 1107 | * for transmit and receive operations are allocated, the interrupt |
| 1108 | * handler is registered with the OS, the watchdog timer is started, |
| 1109 | * and the stack is notified that the interface is ready. |
| 1110 | **/ |
| 1111 | |
| 1112 | static int |
| 1113 | e1000_open(struct net_device *netdev) |
| 1114 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1115 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | int err; |
| 1117 | |
| 1118 | /* allocate transmit descriptors */ |
| 1119 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1120 | if ((err = e1000_setup_all_tx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | goto err_setup_tx; |
| 1122 | |
| 1123 | /* allocate receive descriptors */ |
| 1124 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1125 | if ((err = e1000_setup_all_rx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | goto err_setup_rx; |
| 1127 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1128 | if ((err = e1000_up(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | goto err_up; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1130 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1131 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1132 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1133 | e1000_update_mng_vlan(adapter); |
| 1134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1136 | /* If AMT is enabled, let the firmware know that the network |
| 1137 | * interface is now open */ |
| 1138 | if (adapter->hw.mac_type == e1000_82573 && |
| 1139 | e1000_check_mng_mode(&adapter->hw)) |
| 1140 | e1000_get_hw_control(adapter); |
| 1141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | return E1000_SUCCESS; |
| 1143 | |
| 1144 | err_up: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1145 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1147 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | err_setup_tx: |
| 1149 | e1000_reset(adapter); |
| 1150 | |
| 1151 | return err; |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * e1000_close - Disables a network interface |
| 1156 | * @netdev: network interface device structure |
| 1157 | * |
| 1158 | * Returns 0, this is not allowed to fail |
| 1159 | * |
| 1160 | * The close entry point is called when an interface is de-activated |
| 1161 | * by the OS. The hardware is still under the drivers control, but |
| 1162 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1163 | * hardware, and all transmit and receive resources are freed. |
| 1164 | **/ |
| 1165 | |
| 1166 | static int |
| 1167 | e1000_close(struct net_device *netdev) |
| 1168 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1169 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
| 1171 | e1000_down(adapter); |
| 1172 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1173 | e1000_free_all_tx_resources(adapter); |
| 1174 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1176 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1177 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1178 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1179 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1180 | |
| 1181 | /* If AMT is enabled, let the firmware know that the network |
| 1182 | * interface is now closed */ |
| 1183 | if (adapter->hw.mac_type == e1000_82573 && |
| 1184 | e1000_check_mng_mode(&adapter->hw)) |
| 1185 | e1000_release_hw_control(adapter); |
| 1186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1192 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1193 | * @start: address of beginning of memory |
| 1194 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | **/ |
| 1196 | static inline boolean_t |
| 1197 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1198 | void *start, unsigned long len) |
| 1199 | { |
| 1200 | unsigned long begin = (unsigned long) start; |
| 1201 | unsigned long end = begin + len; |
| 1202 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1203 | /* First rev 82545 and 82546 need to not allow any memory |
| 1204 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1206 | adapter->hw.mac_type == e1000_82546) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; |
| 1208 | } |
| 1209 | |
| 1210 | return TRUE; |
| 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1215 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1216 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | * |
| 1218 | * Return 0 on success, negative on failure |
| 1219 | **/ |
| 1220 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1221 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1222 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1223 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | struct pci_dev *pdev = adapter->pdev; |
| 1226 | int size; |
| 1227 | |
| 1228 | size = sizeof(struct e1000_buffer) * txdr->count; |
Ravikiran G Thirumalai | a7ec15d | 2005-10-28 15:14:49 -0700 | [diff] [blame] | 1229 | |
| 1230 | txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1231 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1232 | DPRINTK(PROBE, ERR, |
| 1233 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | return -ENOMEM; |
| 1235 | } |
| 1236 | memset(txdr->buffer_info, 0, size); |
| 1237 | |
| 1238 | /* round up to nearest 4K */ |
| 1239 | |
| 1240 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
| 1241 | E1000_ROUNDUP(txdr->size, 4096); |
| 1242 | |
| 1243 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1244 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1247 | DPRINTK(PROBE, ERR, |
| 1248 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | return -ENOMEM; |
| 1250 | } |
| 1251 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1252 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1254 | void *olddesc = txdr->desc; |
| 1255 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1256 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1257 | "at %p\n", txdr->size, txdr->desc); |
| 1258 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1260 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1261 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1263 | goto setup_tx_desc_die; |
| 1264 | } |
| 1265 | |
| 1266 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1267 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1268 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1269 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1271 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1272 | "Unable to allocate aligned memory " |
| 1273 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | vfree(txdr->buffer_info); |
| 1275 | return -ENOMEM; |
| 1276 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1277 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1279 | } |
| 1280 | } |
| 1281 | memset(txdr->desc, 0, txdr->size); |
| 1282 | |
| 1283 | txdr->next_to_use = 0; |
| 1284 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1285 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1291 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1292 | * (Descriptors) for all queues |
| 1293 | * @adapter: board private structure |
| 1294 | * |
| 1295 | * If this function returns with an error, then it's possible one or |
| 1296 | * more of the rings is populated (while the rest are not). It is the |
| 1297 | * callers duty to clean those orphaned rings. |
| 1298 | * |
| 1299 | * Return 0 on success, negative on failure |
| 1300 | **/ |
| 1301 | |
| 1302 | int |
| 1303 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1304 | { |
| 1305 | int i, err = 0; |
| 1306 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1307 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1308 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1309 | if (err) { |
| 1310 | DPRINTK(PROBE, ERR, |
| 1311 | "Allocation for Tx Queue %u failed\n", i); |
| 1312 | break; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | return err; |
| 1317 | } |
| 1318 | |
| 1319 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1321 | * @adapter: board private structure |
| 1322 | * |
| 1323 | * Configure the Tx unit of the MAC after a reset. |
| 1324 | **/ |
| 1325 | |
| 1326 | static void |
| 1327 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1328 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1329 | uint64_t tdba; |
| 1330 | struct e1000_hw *hw = &adapter->hw; |
| 1331 | uint32_t tdlen, tctl, tipg, tarc; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1332 | uint32_t ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
| 1334 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1335 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1336 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1337 | case 1: |
| 1338 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1339 | tdba = adapter->tx_ring[0].dma; |
| 1340 | tdlen = adapter->tx_ring[0].count * |
| 1341 | sizeof(struct e1000_tx_desc); |
| 1342 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 1343 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1344 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
| 1345 | E1000_WRITE_REG(hw, TDH, 0); |
| 1346 | E1000_WRITE_REG(hw, TDT, 0); |
| 1347 | adapter->tx_ring[0].tdh = E1000_TDH; |
| 1348 | adapter->tx_ring[0].tdt = E1000_TDT; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1349 | break; |
| 1350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
| 1352 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 1353 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1354 | if (hw->media_type == e1000_media_type_fiber || |
| 1355 | hw->media_type == e1000_media_type_internal_serdes) |
| 1356 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1357 | else |
| 1358 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1359 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1360 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | case e1000_82542_rev2_0: |
| 1362 | case e1000_82542_rev2_1: |
| 1363 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1364 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1365 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1367 | case e1000_80003es2lan: |
| 1368 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1369 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1370 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1372 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1373 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1374 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1376 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1377 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1378 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
| 1380 | /* Set the Tx Interrupt Delay register */ |
| 1381 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1382 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1383 | if (hw->mac_type >= e1000_82540) |
| 1384 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
| 1386 | /* Program the Transmit Control Register */ |
| 1387 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1388 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
| 1390 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1391 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1393 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1394 | #ifdef DISABLE_MULR |
| 1395 | /* disable Multiple Reads for debugging */ |
| 1396 | tctl &= ~E1000_TCTL_MULR; |
| 1397 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1399 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1400 | tarc = E1000_READ_REG(hw, TARC0); |
| 1401 | tarc |= ((1 << 25) | (1 << 21)); |
| 1402 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1403 | tarc = E1000_READ_REG(hw, TARC1); |
| 1404 | tarc |= (1 << 25); |
| 1405 | if (tctl & E1000_TCTL_MULR) |
| 1406 | tarc &= ~(1 << 28); |
| 1407 | else |
| 1408 | tarc |= (1 << 28); |
| 1409 | E1000_WRITE_REG(hw, TARC1, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1410 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1411 | tarc = E1000_READ_REG(hw, TARC0); |
| 1412 | tarc |= 1; |
| 1413 | if (hw->media_type == e1000_media_type_internal_serdes) |
| 1414 | tarc |= (1 << 20); |
| 1415 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1416 | tarc = E1000_READ_REG(hw, TARC1); |
| 1417 | tarc |= 1; |
| 1418 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1421 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
| 1423 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 1424 | adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP | |
| 1425 | E1000_TXD_CMD_IFCS; |
| 1426 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1427 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1429 | else |
| 1430 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1431 | |
| 1432 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1433 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1434 | if (hw->mac_type == e1000_82544 && |
| 1435 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1437 | |
| 1438 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | /** |
| 1443 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1444 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1445 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | * |
| 1447 | * Returns 0 on success, negative on failure |
| 1448 | **/ |
| 1449 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1450 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1451 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1452 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1455 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
| 1457 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Ravikiran G Thirumalai | a7ec15d | 2005-10-28 15:14:49 -0700 | [diff] [blame] | 1458 | rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1459 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1460 | DPRINTK(PROBE, ERR, |
| 1461 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | return -ENOMEM; |
| 1463 | } |
| 1464 | memset(rxdr->buffer_info, 0, size); |
| 1465 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1466 | size = sizeof(struct e1000_ps_page) * rxdr->count; |
| 1467 | rxdr->ps_page = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1468 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1469 | vfree(rxdr->buffer_info); |
| 1470 | DPRINTK(PROBE, ERR, |
| 1471 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1472 | return -ENOMEM; |
| 1473 | } |
| 1474 | memset(rxdr->ps_page, 0, size); |
| 1475 | |
| 1476 | size = sizeof(struct e1000_ps_page_dma) * rxdr->count; |
| 1477 | rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1478 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1479 | vfree(rxdr->buffer_info); |
| 1480 | kfree(rxdr->ps_page); |
| 1481 | DPRINTK(PROBE, ERR, |
| 1482 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1483 | return -ENOMEM; |
| 1484 | } |
| 1485 | memset(rxdr->ps_page_dma, 0, size); |
| 1486 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1487 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1488 | desc_len = sizeof(struct e1000_rx_desc); |
| 1489 | else |
| 1490 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | /* Round up to nearest 4K */ |
| 1493 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1494 | rxdr->size = rxdr->count * desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | E1000_ROUNDUP(rxdr->size, 4096); |
| 1496 | |
| 1497 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1498 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1499 | if (!rxdr->desc) { |
| 1500 | DPRINTK(PROBE, ERR, |
| 1501 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1504 | kfree(rxdr->ps_page); |
| 1505 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | return -ENOMEM; |
| 1507 | } |
| 1508 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1509 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1511 | void *olddesc = rxdr->desc; |
| 1512 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1513 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1514 | "at %p\n", rxdr->size, rxdr->desc); |
| 1515 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1517 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1518 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1520 | DPRINTK(PROBE, ERR, |
| 1521 | "Unable to allocate memory " |
| 1522 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | goto setup_rx_desc_die; |
| 1524 | } |
| 1525 | |
| 1526 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1527 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1528 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1529 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1531 | DPRINTK(PROBE, ERR, |
| 1532 | "Unable to allocate aligned memory " |
| 1533 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1534 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1536 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1538 | } |
| 1539 | } |
| 1540 | memset(rxdr->desc, 0, rxdr->size); |
| 1541 | |
| 1542 | rxdr->next_to_clean = 0; |
| 1543 | rxdr->next_to_use = 0; |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1549 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1550 | * (Descriptors) for all queues |
| 1551 | * @adapter: board private structure |
| 1552 | * |
| 1553 | * If this function returns with an error, then it's possible one or |
| 1554 | * more of the rings is populated (while the rest are not). It is the |
| 1555 | * callers duty to clean those orphaned rings. |
| 1556 | * |
| 1557 | * Return 0 on success, negative on failure |
| 1558 | **/ |
| 1559 | |
| 1560 | int |
| 1561 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1562 | { |
| 1563 | int i, err = 0; |
| 1564 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1565 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1566 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1567 | if (err) { |
| 1568 | DPRINTK(PROBE, ERR, |
| 1569 | "Allocation for Rx Queue %u failed\n", i); |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | return err; |
| 1575 | } |
| 1576 | |
| 1577 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1578 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | * @adapter: Board private structure |
| 1580 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1581 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1582 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | static void |
| 1584 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1585 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1586 | uint32_t rctl, rfctl; |
| 1587 | uint32_t psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1588 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1589 | uint32_t pages = 0; |
| 1590 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
| 1592 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1593 | |
| 1594 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1595 | |
| 1596 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1597 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1598 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1599 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1600 | if (adapter->hw.mac_type > e1000_82543) |
| 1601 | rctl |= E1000_RCTL_SECRC; |
| 1602 | |
| 1603 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | rctl |= E1000_RCTL_SBP; |
| 1605 | else |
| 1606 | rctl &= ~E1000_RCTL_SBP; |
| 1607 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1608 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1609 | rctl &= ~E1000_RCTL_LPE; |
| 1610 | else |
| 1611 | rctl |= E1000_RCTL_LPE; |
| 1612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | /* Setup buffer sizes */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1614 | if (adapter->hw.mac_type >= e1000_82571) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1615 | /* We can now specify buffers in 1K increments. |
| 1616 | * BSIZE and BSEX are ignored in this case. */ |
| 1617 | rctl |= adapter->rx_buffer_len << 0x11; |
| 1618 | } else { |
| 1619 | rctl &= ~E1000_RCTL_SZ_4096; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1620 | rctl |= E1000_RCTL_BSEX; |
| 1621 | switch (adapter->rx_buffer_len) { |
| 1622 | case E1000_RXBUFFER_2048: |
| 1623 | default: |
| 1624 | rctl |= E1000_RCTL_SZ_2048; |
| 1625 | rctl &= ~E1000_RCTL_BSEX; |
| 1626 | break; |
| 1627 | case E1000_RXBUFFER_4096: |
| 1628 | rctl |= E1000_RCTL_SZ_4096; |
| 1629 | break; |
| 1630 | case E1000_RXBUFFER_8192: |
| 1631 | rctl |= E1000_RCTL_SZ_8192; |
| 1632 | break; |
| 1633 | case E1000_RXBUFFER_16384: |
| 1634 | rctl |= E1000_RCTL_SZ_16384; |
| 1635 | break; |
| 1636 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1639 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1640 | /* 82571 and greater support packet-split where the protocol |
| 1641 | * header is placed in skb->data and the packet data is |
| 1642 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 1643 | * In the case of a non-split, skb->data is linearly filled, |
| 1644 | * followed by the page buffers. Therefore, skb->data is |
| 1645 | * sized to hold the largest protocol header. |
| 1646 | */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1647 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
| 1648 | if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) && |
| 1649 | PAGE_SIZE <= 16384) |
| 1650 | adapter->rx_ps_pages = pages; |
| 1651 | else |
| 1652 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1653 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1654 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1655 | /* Configure extra packet-split registers */ |
| 1656 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 1657 | rfctl |= E1000_RFCTL_EXTEN; |
| 1658 | /* disable IPv6 packet split support */ |
| 1659 | rfctl |= E1000_RFCTL_IPV6_DIS; |
| 1660 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 1661 | |
| 1662 | rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1663 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1664 | psrctl |= adapter->rx_ps_bsize0 >> |
| 1665 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1666 | |
| 1667 | switch (adapter->rx_ps_pages) { |
| 1668 | case 3: |
| 1669 | psrctl |= PAGE_SIZE << |
| 1670 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 1671 | case 2: |
| 1672 | psrctl |= PAGE_SIZE << |
| 1673 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 1674 | case 1: |
| 1675 | psrctl |= PAGE_SIZE >> |
| 1676 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 1677 | break; |
| 1678 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1679 | |
| 1680 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1688 | * @adapter: board private structure |
| 1689 | * |
| 1690 | * Configure the Rx unit of the MAC after a reset. |
| 1691 | **/ |
| 1692 | |
| 1693 | static void |
| 1694 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 1695 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1696 | uint64_t rdba; |
| 1697 | struct e1000_hw *hw = &adapter->hw; |
| 1698 | uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1699 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1700 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 1701 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1702 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1703 | sizeof(union e1000_rx_desc_packet_split); |
| 1704 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 1705 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 1706 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1707 | rdlen = adapter->rx_ring[0].count * |
| 1708 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1709 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1710 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1714 | rctl = E1000_READ_REG(hw, RCTL); |
| 1715 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
| 1717 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1718 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1720 | if (hw->mac_type >= e1000_82540) { |
| 1721 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1722 | if (adapter->itr > 1) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1723 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | 1000000000 / (adapter->itr * 256)); |
| 1725 | } |
| 1726 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1727 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1728 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1729 | /* Reset delay timers after every interrupt */ |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1730 | ctrl_ext |= E1000_CTRL_EXT_CANC; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1731 | #ifdef CONFIG_E1000_NAPI |
| 1732 | /* Auto-Mask interrupts upon ICR read. */ |
| 1733 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 1734 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1735 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1736 | E1000_WRITE_REG(hw, IAM, ~0); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1737 | E1000_WRITE_FLUSH(hw); |
| 1738 | } |
| 1739 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1740 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1741 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1742 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1743 | case 1: |
| 1744 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1745 | rdba = adapter->rx_ring[0].dma; |
| 1746 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 1747 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 1748 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
| 1749 | E1000_WRITE_REG(hw, RDH, 0); |
| 1750 | E1000_WRITE_REG(hw, RDT, 0); |
| 1751 | adapter->rx_ring[0].rdh = E1000_RDH; |
| 1752 | adapter->rx_ring[0].rdt = E1000_RDT; |
| 1753 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1757 | if (hw->mac_type >= e1000_82543) { |
| 1758 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1759 | if (adapter->rx_csum == TRUE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1760 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 1761 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1762 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1763 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1764 | if ((hw->mac_type >= e1000_82571) && |
| 1765 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1766 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 1767 | } |
| 1768 | } else { |
| 1769 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 1770 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 1771 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1772 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1775 | if (hw->mac_type == e1000_82573) |
| 1776 | E1000_WRITE_REG(hw, ERT, 0x0100); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1779 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1783 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 1784 | * @adapter: board private structure |
| 1785 | * @tx_ring: Tx descriptor ring for a specific queue |
| 1786 | * |
| 1787 | * Free all transmit software resources |
| 1788 | **/ |
| 1789 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1790 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1791 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 1792 | struct e1000_tx_ring *tx_ring) |
| 1793 | { |
| 1794 | struct pci_dev *pdev = adapter->pdev; |
| 1795 | |
| 1796 | e1000_clean_tx_ring(adapter, tx_ring); |
| 1797 | |
| 1798 | vfree(tx_ring->buffer_info); |
| 1799 | tx_ring->buffer_info = NULL; |
| 1800 | |
| 1801 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 1802 | |
| 1803 | tx_ring->desc = NULL; |
| 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | * @adapter: board private structure |
| 1809 | * |
| 1810 | * Free all transmit software resources |
| 1811 | **/ |
| 1812 | |
| 1813 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1814 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1816 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1818 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1819 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | static inline void |
| 1823 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 1824 | struct e1000_buffer *buffer_info) |
| 1825 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1826 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1827 | pci_unmap_page(adapter->pdev, |
| 1828 | buffer_info->dma, |
| 1829 | buffer_info->length, |
| 1830 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | } |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 1832 | if (buffer_info->skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | dev_kfree_skb_any(buffer_info->skb); |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 1834 | memset(buffer_info, 0, sizeof(struct e1000_buffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * e1000_clean_tx_ring - Free Tx Buffers |
| 1839 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1840 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | **/ |
| 1842 | |
| 1843 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1844 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 1845 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | struct e1000_buffer *buffer_info; |
| 1848 | unsigned long size; |
| 1849 | unsigned int i; |
| 1850 | |
| 1851 | /* Free all the Tx ring sk_buffs */ |
| 1852 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1853 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | buffer_info = &tx_ring->buffer_info[i]; |
| 1855 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 1856 | } |
| 1857 | |
| 1858 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 1859 | memset(tx_ring->buffer_info, 0, size); |
| 1860 | |
| 1861 | /* Zero out the descriptor ring */ |
| 1862 | |
| 1863 | memset(tx_ring->desc, 0, tx_ring->size); |
| 1864 | |
| 1865 | tx_ring->next_to_use = 0; |
| 1866 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1867 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1869 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 1870 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 1871 | } |
| 1872 | |
| 1873 | /** |
| 1874 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 1875 | * @adapter: board private structure |
| 1876 | **/ |
| 1877 | |
| 1878 | static void |
| 1879 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 1880 | { |
| 1881 | int i; |
| 1882 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1883 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1884 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * e1000_free_rx_resources - Free Rx Resources |
| 1889 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1890 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | * |
| 1892 | * Free all receive software resources |
| 1893 | **/ |
| 1894 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1895 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1896 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 1897 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | struct pci_dev *pdev = adapter->pdev; |
| 1900 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1901 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | |
| 1903 | vfree(rx_ring->buffer_info); |
| 1904 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1905 | kfree(rx_ring->ps_page); |
| 1906 | rx_ring->ps_page = NULL; |
| 1907 | kfree(rx_ring->ps_page_dma); |
| 1908 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | |
| 1910 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 1911 | |
| 1912 | rx_ring->desc = NULL; |
| 1913 | } |
| 1914 | |
| 1915 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1916 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1918 | * |
| 1919 | * Free all receive software resources |
| 1920 | **/ |
| 1921 | |
| 1922 | void |
| 1923 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 1924 | { |
| 1925 | int i; |
| 1926 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1927 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1928 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1933 | * @adapter: board private structure |
| 1934 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | **/ |
| 1936 | |
| 1937 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1938 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 1939 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1942 | struct e1000_ps_page *ps_page; |
| 1943 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | struct pci_dev *pdev = adapter->pdev; |
| 1945 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1946 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
| 1948 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1949 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1951 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | pci_unmap_single(pdev, |
| 1953 | buffer_info->dma, |
| 1954 | buffer_info->length, |
| 1955 | PCI_DMA_FROMDEVICE); |
| 1956 | |
| 1957 | dev_kfree_skb(buffer_info->skb); |
| 1958 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 1959 | } |
| 1960 | ps_page = &rx_ring->ps_page[i]; |
| 1961 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 1962 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 1963 | if (!ps_page->ps_page[j]) break; |
| 1964 | pci_unmap_page(pdev, |
| 1965 | ps_page_dma->ps_page_dma[j], |
| 1966 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 1967 | ps_page_dma->ps_page_dma[j] = 0; |
| 1968 | put_page(ps_page->ps_page[j]); |
| 1969 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 1974 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1975 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 1976 | memset(rx_ring->ps_page, 0, size); |
| 1977 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 1978 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
| 1980 | /* Zero out the descriptor ring */ |
| 1981 | |
| 1982 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1983 | |
| 1984 | rx_ring->next_to_clean = 0; |
| 1985 | rx_ring->next_to_use = 0; |
| 1986 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1987 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 1988 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 1993 | * @adapter: board private structure |
| 1994 | **/ |
| 1995 | |
| 1996 | static void |
| 1997 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 1998 | { |
| 1999 | int i; |
| 2000 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2001 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2002 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2006 | * and memory write and invalidate disabled for certain operations |
| 2007 | */ |
| 2008 | static void |
| 2009 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 2010 | { |
| 2011 | struct net_device *netdev = adapter->netdev; |
| 2012 | uint32_t rctl; |
| 2013 | |
| 2014 | e1000_pci_clear_mwi(&adapter->hw); |
| 2015 | |
| 2016 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2017 | rctl |= E1000_RCTL_RST; |
| 2018 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2019 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2020 | mdelay(5); |
| 2021 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2022 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2023 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | static void |
| 2027 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2028 | { |
| 2029 | struct net_device *netdev = adapter->netdev; |
| 2030 | uint32_t rctl; |
| 2031 | |
| 2032 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2033 | rctl &= ~E1000_RCTL_RST; |
| 2034 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2035 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2036 | mdelay(5); |
| 2037 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2038 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | e1000_pci_set_mwi(&adapter->hw); |
| 2040 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2041 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2042 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2043 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2044 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2045 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | /** |
| 2050 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2051 | * @netdev: network interface device structure |
| 2052 | * @p: pointer to an address structure |
| 2053 | * |
| 2054 | * Returns 0 on success, negative on failure |
| 2055 | **/ |
| 2056 | |
| 2057 | static int |
| 2058 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2059 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2060 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | struct sockaddr *addr = p; |
| 2062 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2063 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | return -EADDRNOTAVAIL; |
| 2065 | |
| 2066 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2067 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2068 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | e1000_enter_82542_rst(adapter); |
| 2070 | |
| 2071 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2072 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2073 | |
| 2074 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2075 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2076 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2077 | * due to controller reset from the other port. */ |
| 2078 | if (adapter->hw.mac_type == e1000_82571) { |
| 2079 | /* activate the work around */ |
| 2080 | adapter->hw.laa_is_present = 1; |
| 2081 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2082 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2083 | * between the time RAR[0] gets clobbered and the time it |
| 2084 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2085 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2086 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2087 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2088 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2089 | E1000_RAR_ENTRIES - 1); |
| 2090 | } |
| 2091 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2092 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | e1000_leave_82542_rst(adapter); |
| 2094 | |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 2100 | * @netdev: network interface device structure |
| 2101 | * |
| 2102 | * The set_multi entry point is called whenever the multicast address |
| 2103 | * list or the network interface flags are updated. This routine is |
| 2104 | * responsible for configuring the hardware for proper multicast, |
| 2105 | * promiscuous mode, and all-multi behavior. |
| 2106 | **/ |
| 2107 | |
| 2108 | static void |
| 2109 | e1000_set_multi(struct net_device *netdev) |
| 2110 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2111 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | struct e1000_hw *hw = &adapter->hw; |
| 2113 | struct dev_mc_list *mc_ptr; |
| 2114 | uint32_t rctl; |
| 2115 | uint32_t hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2116 | int i, rar_entries = E1000_RAR_ENTRIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2118 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2119 | if (adapter->hw.mac_type == e1000_82571) |
| 2120 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2122 | /* Check for Promiscuous and All Multicast modes */ |
| 2123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | rctl = E1000_READ_REG(hw, RCTL); |
| 2125 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2126 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2128 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | rctl |= E1000_RCTL_MPE; |
| 2130 | rctl &= ~E1000_RCTL_UPE; |
| 2131 | } else { |
| 2132 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 2133 | } |
| 2134 | |
| 2135 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2136 | |
| 2137 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2138 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2139 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | e1000_enter_82542_rst(adapter); |
| 2141 | |
| 2142 | /* load the first 14 multicast address into the exact filters 1-14 |
| 2143 | * RAR 0 is used for the station MAC adddress |
| 2144 | * if there are not 14 addresses, go ahead and clear the filters |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2145 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | */ |
| 2147 | mc_ptr = netdev->mc_list; |
| 2148 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2149 | for (i = 1; i < rar_entries; i++) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2150 | if (mc_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | e1000_rar_set(hw, mc_ptr->dmi_addr, i); |
| 2152 | mc_ptr = mc_ptr->next; |
| 2153 | } else { |
| 2154 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
| 2155 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | /* clear the old settings from the multicast hash table */ |
| 2160 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2161 | for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
| 2163 | |
| 2164 | /* load any remaining addresses into the hash table */ |
| 2165 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2166 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr); |
| 2168 | e1000_mta_set(hw, hash_value); |
| 2169 | } |
| 2170 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2171 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2176 | * the phy */ |
| 2177 | |
| 2178 | static void |
| 2179 | e1000_update_phy_info(unsigned long data) |
| 2180 | { |
| 2181 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2182 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2187 | * @data: pointer to adapter cast into an unsigned long |
| 2188 | **/ |
| 2189 | |
| 2190 | static void |
| 2191 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2192 | { |
| 2193 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2194 | struct net_device *netdev = adapter->netdev; |
| 2195 | uint32_t tctl; |
| 2196 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2197 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2198 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2200 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2201 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2202 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2203 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2204 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2205 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2206 | tctl & ~E1000_TCTL_EN); |
| 2207 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2208 | adapter->tx_head_addr); |
| 2209 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2210 | adapter->tx_head_addr); |
| 2211 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2212 | adapter->tx_head_addr); |
| 2213 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2214 | adapter->tx_head_addr); |
| 2215 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2216 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2217 | |
| 2218 | adapter->tx_fifo_head = 0; |
| 2219 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2220 | netif_wake_queue(netdev); |
| 2221 | } else { |
| 2222 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * e1000_watchdog - Timer Call-back |
| 2229 | * @data: pointer to adapter cast into an unsigned long |
| 2230 | **/ |
| 2231 | static void |
| 2232 | e1000_watchdog(unsigned long data) |
| 2233 | { |
| 2234 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2235 | |
| 2236 | /* Do the rest outside of interrupt context */ |
| 2237 | schedule_work(&adapter->watchdog_task); |
| 2238 | } |
| 2239 | |
| 2240 | static void |
| 2241 | e1000_watchdog_task(struct e1000_adapter *adapter) |
| 2242 | { |
| 2243 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2244 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2245 | uint32_t link, tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | |
| 2247 | e1000_check_for_link(&adapter->hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2248 | if (adapter->hw.mac_type == e1000_82573) { |
| 2249 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2250 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2251 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2254 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2256 | link = !adapter->hw.serdes_link_down; |
| 2257 | else |
| 2258 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2259 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2260 | if (link) { |
| 2261 | if (!netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2263 | &adapter->link_speed, |
| 2264 | &adapter->link_duplex); |
| 2265 | |
| 2266 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n", |
| 2267 | adapter->link_speed, |
| 2268 | adapter->link_duplex == FULL_DUPLEX ? |
| 2269 | "Full Duplex" : "Half Duplex"); |
| 2270 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2271 | /* tweak tx_queue_len according to speed/duplex |
| 2272 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2273 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2274 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2275 | adapter->txb2b = 1; |
| 2276 | switch (adapter->link_speed) { |
| 2277 | case SPEED_10: |
| 2278 | adapter->txb2b = 0; |
| 2279 | netdev->tx_queue_len = 10; |
| 2280 | adapter->tx_timeout_factor = 8; |
| 2281 | break; |
| 2282 | case SPEED_100: |
| 2283 | adapter->txb2b = 0; |
| 2284 | netdev->tx_queue_len = 100; |
| 2285 | /* maybe add some timeout factor ? */ |
| 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | if ((adapter->hw.mac_type == e1000_82571 || |
| 2290 | adapter->hw.mac_type == e1000_82572) && |
| 2291 | adapter->txb2b == 0) { |
| 2292 | #define SPEED_MODE_BIT (1 << 21) |
| 2293 | uint32_t tarc0; |
| 2294 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
| 2295 | tarc0 &= ~SPEED_MODE_BIT; |
| 2296 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2297 | } |
| 2298 | |
| 2299 | #ifdef NETIF_F_TSO |
| 2300 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2301 | * some hardware issues */ |
| 2302 | if (!adapter->tso_force && |
| 2303 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2304 | switch (adapter->link_speed) { |
| 2305 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2306 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2307 | DPRINTK(PROBE,INFO, |
| 2308 | "10/100 speed: disabling TSO\n"); |
| 2309 | netdev->features &= ~NETIF_F_TSO; |
| 2310 | break; |
| 2311 | case SPEED_1000: |
| 2312 | netdev->features |= NETIF_F_TSO; |
| 2313 | break; |
| 2314 | default: |
| 2315 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2316 | break; |
| 2317 | } |
| 2318 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2319 | #endif |
| 2320 | |
| 2321 | /* enable transmits in the hardware, need to do this |
| 2322 | * after setting TARC0 */ |
| 2323 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2324 | tctl |= E1000_TCTL_EN; |
| 2325 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | netif_carrier_on(netdev); |
| 2328 | netif_wake_queue(netdev); |
| 2329 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
| 2330 | adapter->smartspeed = 0; |
| 2331 | } |
| 2332 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2333 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | adapter->link_speed = 0; |
| 2335 | adapter->link_duplex = 0; |
| 2336 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2337 | netif_carrier_off(netdev); |
| 2338 | netif_stop_queue(netdev); |
| 2339 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2340 | |
| 2341 | /* 80003ES2LAN workaround-- |
| 2342 | * For packet buffer work-around on link down event; |
| 2343 | * disable receives in the ISR and |
| 2344 | * reset device here in the watchdog |
| 2345 | */ |
| 2346 | if (adapter->hw.mac_type == e1000_80003es2lan) { |
| 2347 | /* reset device */ |
| 2348 | schedule_work(&adapter->reset_task); |
| 2349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | e1000_smartspeed(adapter); |
| 2353 | } |
| 2354 | |
| 2355 | e1000_update_stats(adapter); |
| 2356 | |
| 2357 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2358 | adapter->tpt_old = adapter->stats.tpt; |
| 2359 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2360 | adapter->colc_old = adapter->stats.colc; |
| 2361 | |
| 2362 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2363 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2364 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2365 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2366 | |
| 2367 | e1000_update_adaptive(&adapter->hw); |
| 2368 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2369 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2370 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | /* We've lost link, so the controller stops DMA, |
| 2372 | * but we've got queued Tx work that's never going |
| 2373 | * to get done, so reset controller to flush Tx. |
| 2374 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2375 | adapter->tx_timeout_count++; |
| 2376 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | /* Dynamic mode for Interrupt Throttle Rate (ITR) */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2381 | if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | /* Symmetric Tx/Rx gets a reduced ITR=2000; Total |
| 2383 | * asymmetrical Tx or Rx gets ITR=8000; everyone |
| 2384 | * else is between 2000-8000. */ |
| 2385 | uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2386 | uint32_t dif = (adapter->gotcl > adapter->gorcl ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | adapter->gotcl - adapter->gorcl : |
| 2388 | adapter->gorcl - adapter->gotcl) / 10000; |
| 2389 | uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 2390 | E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256)); |
| 2391 | } |
| 2392 | |
| 2393 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2394 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2395 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2396 | /* Force detection of hung controller every watchdog period */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | adapter->detect_tx_hung = TRUE; |
| 2398 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2399 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2400 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2401 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2402 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | /* Reset the timer */ |
| 2405 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 2406 | } |
| 2407 | |
| 2408 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2409 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2410 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2411 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2413 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2414 | |
| 2415 | static inline int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2416 | e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2417 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | { |
| 2419 | #ifdef NETIF_F_TSO |
| 2420 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2421 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | unsigned int i; |
| 2423 | uint32_t cmd_length = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2424 | uint16_t ipcse = 0, tucse, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 2426 | int err; |
| 2427 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2428 | if (skb_shinfo(skb)->tso_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | if (skb_header_cloned(skb)) { |
| 2430 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2431 | if (err) |
| 2432 | return err; |
| 2433 | } |
| 2434 | |
| 2435 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
| 2436 | mss = skb_shinfo(skb)->tso_size; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2437 | if (skb->protocol == ntohs(ETH_P_IP)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2438 | skb->nh.iph->tot_len = 0; |
| 2439 | skb->nh.iph->check = 0; |
| 2440 | skb->h.th->check = |
| 2441 | ~csum_tcpudp_magic(skb->nh.iph->saddr, |
| 2442 | skb->nh.iph->daddr, |
| 2443 | 0, |
| 2444 | IPPROTO_TCP, |
| 2445 | 0); |
| 2446 | cmd_length = E1000_TXD_CMD_IP; |
| 2447 | ipcse = skb->h.raw - skb->data - 1; |
| 2448 | #ifdef NETIF_F_TSO_IPV6 |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2449 | } else if (skb->protocol == ntohs(ETH_P_IPV6)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2450 | skb->nh.ipv6h->payload_len = 0; |
| 2451 | skb->h.th->check = |
| 2452 | ~csum_ipv6_magic(&skb->nh.ipv6h->saddr, |
| 2453 | &skb->nh.ipv6h->daddr, |
| 2454 | 0, |
| 2455 | IPPROTO_TCP, |
| 2456 | 0); |
| 2457 | ipcse = 0; |
| 2458 | #endif |
| 2459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | ipcss = skb->nh.raw - skb->data; |
| 2461 | ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | tucss = skb->h.raw - skb->data; |
| 2463 | tucso = (void *)&(skb->h.th->check) - (void *)skb->data; |
| 2464 | tucse = 0; |
| 2465 | |
| 2466 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2467 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2469 | i = tx_ring->next_to_use; |
| 2470 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2471 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
| 2473 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2474 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2475 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2476 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2477 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2478 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2479 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2480 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2481 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2482 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2483 | buffer_info->time_stamp = jiffies; |
| 2484 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2485 | if (++i == tx_ring->count) i = 0; |
| 2486 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2488 | return TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | } |
| 2490 | #endif |
| 2491 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2492 | return FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | static inline boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2496 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2497 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | { |
| 2499 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2500 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | unsigned int i; |
| 2502 | uint8_t css; |
| 2503 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2504 | if (likely(skb->ip_summed == CHECKSUM_HW)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | css = skb->h.raw - skb->data; |
| 2506 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2507 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2508 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2509 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
| 2511 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2512 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum; |
| 2513 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2514 | context_desc->tcp_seg_setup.data = 0; |
| 2515 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 2516 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2517 | buffer_info->time_stamp = jiffies; |
| 2518 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2519 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2520 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | |
| 2522 | return TRUE; |
| 2523 | } |
| 2524 | |
| 2525 | return FALSE; |
| 2526 | } |
| 2527 | |
| 2528 | #define E1000_MAX_TXD_PWR 12 |
| 2529 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2530 | |
| 2531 | static inline int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2532 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2533 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 2534 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | struct e1000_buffer *buffer_info; |
| 2537 | unsigned int len = skb->len; |
| 2538 | unsigned int offset = 0, size, count = 0, i; |
| 2539 | unsigned int f; |
| 2540 | len -= skb->data_len; |
| 2541 | |
| 2542 | i = tx_ring->next_to_use; |
| 2543 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2544 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | buffer_info = &tx_ring->buffer_info[i]; |
| 2546 | size = min(len, max_per_txd); |
| 2547 | #ifdef NETIF_F_TSO |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2548 | /* Workaround for Controller erratum -- |
| 2549 | * descriptor for non-tso packet in a linear SKB that follows a |
| 2550 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2551 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2552 | if (!skb->data_len && tx_ring->last_tx_tso && |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2553 | !skb_shinfo(skb)->tso_size) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2554 | tx_ring->last_tx_tso = 0; |
| 2555 | size -= 4; |
| 2556 | } |
| 2557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | /* Workaround for premature desc write-backs |
| 2559 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2560 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | size -= 4; |
| 2562 | #endif |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2563 | /* work-around for errata 10 and it applies |
| 2564 | * to all controllers in PCI-X mode |
| 2565 | * The fix is to make sure that the first descriptor of a |
| 2566 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 2567 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2568 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2569 | (size > 2015) && count == 0)) |
| 2570 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 2573 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2574 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 2576 | size > 4)) |
| 2577 | size -= 4; |
| 2578 | |
| 2579 | buffer_info->length = size; |
| 2580 | buffer_info->dma = |
| 2581 | pci_map_single(adapter->pdev, |
| 2582 | skb->data + offset, |
| 2583 | size, |
| 2584 | PCI_DMA_TODEVICE); |
| 2585 | buffer_info->time_stamp = jiffies; |
| 2586 | |
| 2587 | len -= size; |
| 2588 | offset += size; |
| 2589 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2590 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2593 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | struct skb_frag_struct *frag; |
| 2595 | |
| 2596 | frag = &skb_shinfo(skb)->frags[f]; |
| 2597 | len = frag->size; |
| 2598 | offset = frag->page_offset; |
| 2599 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2600 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | buffer_info = &tx_ring->buffer_info[i]; |
| 2602 | size = min(len, max_per_txd); |
| 2603 | #ifdef NETIF_F_TSO |
| 2604 | /* Workaround for premature desc write-backs |
| 2605 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2606 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | size -= 4; |
| 2608 | #endif |
| 2609 | /* Workaround for potential 82544 hang in PCI-X. |
| 2610 | * Avoid terminating buffers within evenly-aligned |
| 2611 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2612 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 2614 | size > 4)) |
| 2615 | size -= 4; |
| 2616 | |
| 2617 | buffer_info->length = size; |
| 2618 | buffer_info->dma = |
| 2619 | pci_map_page(adapter->pdev, |
| 2620 | frag->page, |
| 2621 | offset, |
| 2622 | size, |
| 2623 | PCI_DMA_TODEVICE); |
| 2624 | buffer_info->time_stamp = jiffies; |
| 2625 | |
| 2626 | len -= size; |
| 2627 | offset += size; |
| 2628 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2629 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 2634 | tx_ring->buffer_info[i].skb = skb; |
| 2635 | tx_ring->buffer_info[first].next_to_watch = i; |
| 2636 | |
| 2637 | return count; |
| 2638 | } |
| 2639 | |
| 2640 | static inline void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2641 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2642 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | struct e1000_tx_desc *tx_desc = NULL; |
| 2645 | struct e1000_buffer *buffer_info; |
| 2646 | uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 2647 | unsigned int i; |
| 2648 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2649 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 2651 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2652 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2653 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2654 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2655 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2658 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 2660 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2661 | } |
| 2662 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2663 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | txd_lower |= E1000_TXD_CMD_VLE; |
| 2665 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 2666 | } |
| 2667 | |
| 2668 | i = tx_ring->next_to_use; |
| 2669 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2670 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | buffer_info = &tx_ring->buffer_info[i]; |
| 2672 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 2673 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2674 | tx_desc->lower.data = |
| 2675 | cpu_to_le32(txd_lower | buffer_info->length); |
| 2676 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2677 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 2681 | |
| 2682 | /* Force memory writes to complete before letting h/w |
| 2683 | * know there are new descriptors to fetch. (Only |
| 2684 | * applicable for weak-ordered memory model archs, |
| 2685 | * such as IA-64). */ |
| 2686 | wmb(); |
| 2687 | |
| 2688 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2689 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /** |
| 2693 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 2694 | * The workaround is to avoid queuing a large packet that would span |
| 2695 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 2696 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 2697 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 2698 | * to the beginning of the Tx FIFO. |
| 2699 | **/ |
| 2700 | |
| 2701 | #define E1000_FIFO_HDR 0x10 |
| 2702 | #define E1000_82547_PAD_LEN 0x3E0 |
| 2703 | |
| 2704 | static inline int |
| 2705 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 2706 | { |
| 2707 | uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 2708 | uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
| 2709 | |
| 2710 | E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR); |
| 2711 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2712 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | goto no_fifo_stall_required; |
| 2714 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2715 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | return 1; |
| 2717 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2718 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 2720 | return 1; |
| 2721 | } |
| 2722 | |
| 2723 | no_fifo_stall_required: |
| 2724 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2725 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2730 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 2731 | static inline int |
| 2732 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 2733 | { |
| 2734 | struct e1000_hw *hw = &adapter->hw; |
| 2735 | uint16_t length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2736 | if (vlan_tx_tag_present(skb)) { |
| 2737 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2738 | ( adapter->hw.mng_cookie.status & |
| 2739 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 2740 | return 0; |
| 2741 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 2742 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2743 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2744 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 2745 | const struct iphdr *ip = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2746 | (struct iphdr *)((uint8_t *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2747 | if (IPPROTO_UDP == ip->protocol) { |
| 2748 | struct udphdr *udp = |
| 2749 | (struct udphdr *)((uint8_t *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2750 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2751 | if (ntohs(udp->dest) == 67) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2752 | offset = (uint8_t *)udp + 8 - skb->data; |
| 2753 | length = skb->len - offset; |
| 2754 | |
| 2755 | return e1000_mng_write_dhcp_info(hw, |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2756 | (uint8_t *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2757 | length); |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | } |
| 2762 | return 0; |
| 2763 | } |
| 2764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 2766 | static int |
| 2767 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 2768 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2769 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2770 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 2772 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 2773 | unsigned int tx_flags = 0; |
| 2774 | unsigned int len = skb->len; |
| 2775 | unsigned long flags; |
| 2776 | unsigned int nr_frags = 0; |
| 2777 | unsigned int mss = 0; |
| 2778 | int count = 0; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2779 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | unsigned int f; |
| 2781 | len -= skb->data_len; |
| 2782 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2783 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2784 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2785 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | dev_kfree_skb_any(skb); |
| 2787 | return NETDEV_TX_OK; |
| 2788 | } |
| 2789 | |
| 2790 | #ifdef NETIF_F_TSO |
| 2791 | mss = skb_shinfo(skb)->tso_size; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2792 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | * make sure there is enough room in the FIFO before |
| 2794 | * initiating the DMA for each buffer. The calc is: |
| 2795 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 2796 | * overrun the FIFO, adjust the max buffer len if mss |
| 2797 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2798 | if (mss) { |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2799 | uint8_t hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | max_per_txd = min(mss << 2, max_per_txd); |
| 2801 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2802 | |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2803 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2804 | * points to just header, pull a few bytes of payload from |
| 2805 | * frags into skb->data */ |
| 2806 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2807 | if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { |
| 2808 | switch (adapter->hw.mac_type) { |
| 2809 | unsigned int pull_size; |
| 2810 | case e1000_82571: |
| 2811 | case e1000_82572: |
| 2812 | case e1000_82573: |
| 2813 | pull_size = min((unsigned int)4, skb->data_len); |
| 2814 | if (!__pskb_pull_tail(skb, pull_size)) { |
| 2815 | printk(KERN_ERR |
| 2816 | "__pskb_pull_tail failed.\n"); |
| 2817 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame^] | 2818 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2819 | } |
| 2820 | len = skb->len - skb->data_len; |
| 2821 | break; |
| 2822 | default: |
| 2823 | /* do nothing */ |
| 2824 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 2825 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2829 | /* reserve a descriptor for the offload context */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2830 | if ((mss) || (skb->ip_summed == CHECKSUM_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2832 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | #else |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2834 | if (skb->ip_summed == CHECKSUM_HW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | count++; |
| 2836 | #endif |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2837 | |
| 2838 | #ifdef NETIF_F_TSO |
| 2839 | /* Controller Erratum workaround */ |
| 2840 | if (!skb->data_len && tx_ring->last_tx_tso && |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2841 | !skb_shinfo(skb)->tso_size) |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2842 | count++; |
| 2843 | #endif |
| 2844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 2846 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2847 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | count++; |
| 2849 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2850 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2851 | * in PCI-X mode, so add one more descriptor to the count |
| 2852 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2853 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2854 | (len > 2015))) |
| 2855 | count++; |
| 2856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | nr_frags = skb_shinfo(skb)->nr_frags; |
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 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 2860 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2861 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | count += nr_frags; |
| 2863 | |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2864 | |
| 2865 | if (adapter->hw.tx_pkt_filtering && |
| 2866 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2867 | e1000_transfer_dhcp_info(adapter, skb); |
| 2868 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2869 | local_irq_save(flags); |
| 2870 | if (!spin_trylock(&tx_ring->tx_lock)) { |
| 2871 | /* Collision - tell upper layer to requeue */ |
| 2872 | local_irq_restore(flags); |
| 2873 | return NETDEV_TX_LOCKED; |
| 2874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | |
| 2876 | /* need: count + 2 desc gap to keep tail from touching |
| 2877 | * head, otherwise try next time */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2878 | if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | netif_stop_queue(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2880 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | return NETDEV_TX_BUSY; |
| 2882 | } |
| 2883 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2884 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 2885 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | netif_stop_queue(netdev); |
| 2887 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2888 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | return NETDEV_TX_BUSY; |
| 2890 | } |
| 2891 | } |
| 2892 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2893 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 2895 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 2896 | } |
| 2897 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2898 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2899 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2900 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | if (tso < 0) { |
| 2902 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2903 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | return NETDEV_TX_OK; |
| 2905 | } |
| 2906 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2907 | if (likely(tso)) { |
| 2908 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2910 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 2912 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2913 | /* Old method was to assume IPv4 packet by default if TSO was enabled. |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2914 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2915 | * no longer assume, we must. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2916 | if (likely(skb->protocol == ntohs(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2917 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 2918 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2919 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 2920 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 2921 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | |
| 2923 | netdev->trans_start = jiffies; |
| 2924 | |
| 2925 | /* Make sure there is space in the ring for the next send. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2926 | if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | netif_stop_queue(netdev); |
| 2928 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2929 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | return NETDEV_TX_OK; |
| 2931 | } |
| 2932 | |
| 2933 | /** |
| 2934 | * e1000_tx_timeout - Respond to a Tx Hang |
| 2935 | * @netdev: network interface device structure |
| 2936 | **/ |
| 2937 | |
| 2938 | static void |
| 2939 | e1000_tx_timeout(struct net_device *netdev) |
| 2940 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2941 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | |
| 2943 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2944 | adapter->tx_timeout_count++; |
| 2945 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | static void |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2949 | e1000_reset_task(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2951 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | |
| 2953 | e1000_down(adapter); |
| 2954 | e1000_up(adapter); |
| 2955 | } |
| 2956 | |
| 2957 | /** |
| 2958 | * e1000_get_stats - Get System Network Statistics |
| 2959 | * @netdev: network interface device structure |
| 2960 | * |
| 2961 | * Returns the address of the device statistics structure. |
| 2962 | * The statistics are actually updated from the timer callback. |
| 2963 | **/ |
| 2964 | |
| 2965 | static struct net_device_stats * |
| 2966 | e1000_get_stats(struct net_device *netdev) |
| 2967 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2968 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 2970 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | return &adapter->net_stats; |
| 2972 | } |
| 2973 | |
| 2974 | /** |
| 2975 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 2976 | * @netdev: network interface device structure |
| 2977 | * @new_mtu: new value for maximum frame size |
| 2978 | * |
| 2979 | * Returns 0 on success, negative on failure |
| 2980 | **/ |
| 2981 | |
| 2982 | static int |
| 2983 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 2984 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2985 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 2987 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2989 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 2990 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 2991 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2992 | return -EINVAL; |
| 2993 | } |
| 2994 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2995 | /* Adapter-specific max frame size limits. */ |
| 2996 | switch (adapter->hw.mac_type) { |
| 2997 | case e1000_82542_rev2_0: |
| 2998 | case e1000_82542_rev2_1: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2999 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3000 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3001 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3002 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3003 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3004 | case e1000_82573: |
| 3005 | /* only enable jumbo frames if ASPM is disabled completely |
| 3006 | * this means both bits must be zero in 0x1A bits 3:2 */ |
| 3007 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 3008 | &eeprom_data); |
| 3009 | if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) { |
| 3010 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3011 | DPRINTK(PROBE, ERR, |
| 3012 | "Jumbo Frames not supported.\n"); |
| 3013 | return -EINVAL; |
| 3014 | } |
| 3015 | break; |
| 3016 | } |
| 3017 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3018 | case e1000_82571: |
| 3019 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3020 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3021 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3022 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3023 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3024 | return -EINVAL; |
| 3025 | } |
| 3026 | break; |
| 3027 | default: |
| 3028 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3029 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3032 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3033 | if (adapter->hw.mac_type > e1000_82547_rev_2) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3034 | adapter->rx_buffer_len = max_frame; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3035 | E1000_ROUNDUP(adapter->rx_buffer_len, 1024); |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3036 | } else { |
| 3037 | if(unlikely((adapter->hw.mac_type < e1000_82543) && |
| 3038 | (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) { |
| 3039 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported " |
| 3040 | "on 82542\n"); |
| 3041 | return -EINVAL; |
| 3042 | } else { |
| 3043 | if(max_frame <= E1000_RXBUFFER_2048) |
| 3044 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3045 | else if(max_frame <= E1000_RXBUFFER_4096) |
| 3046 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3047 | else if(max_frame <= E1000_RXBUFFER_8192) |
| 3048 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3049 | else if(max_frame <= E1000_RXBUFFER_16384) |
| 3050 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3051 | } |
| 3052 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3053 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3054 | netdev->mtu = new_mtu; |
| 3055 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3056 | if (netif_running(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | e1000_down(adapter); |
| 3058 | e1000_up(adapter); |
| 3059 | } |
| 3060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | adapter->hw.max_frame_size = max_frame; |
| 3062 | |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
| 3066 | /** |
| 3067 | * e1000_update_stats - Update the board statistics counters |
| 3068 | * @adapter: board private structure |
| 3069 | **/ |
| 3070 | |
| 3071 | void |
| 3072 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3073 | { |
| 3074 | struct e1000_hw *hw = &adapter->hw; |
| 3075 | unsigned long flags; |
| 3076 | uint16_t phy_tmp; |
| 3077 | |
| 3078 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3079 | |
| 3080 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3081 | |
| 3082 | /* these counters are modified from e1000_adjust_tbi_stats, |
| 3083 | * called from the interrupt context, so they must only |
| 3084 | * be written while holding adapter->stats_lock |
| 3085 | */ |
| 3086 | |
| 3087 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3088 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3089 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3090 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3091 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3092 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3093 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
| 3094 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3095 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3096 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3097 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3098 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3099 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
| 3100 | |
| 3101 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3102 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3103 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3104 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3105 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3106 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3107 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3108 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3109 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3110 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3111 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3112 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3113 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3114 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3115 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3116 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3117 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3118 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3119 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3120 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3121 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3122 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3123 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3124 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3125 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3126 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
| 3127 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3128 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3129 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3130 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3131 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3132 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
| 3133 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3134 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3135 | |
| 3136 | /* used for adaptive IFS */ |
| 3137 | |
| 3138 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3139 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3140 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3141 | adapter->stats.colc += hw->collision_delta; |
| 3142 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3143 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3145 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3146 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3147 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3148 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3149 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3150 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3151 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3152 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3153 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
| 3154 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3155 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3156 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3157 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3158 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3159 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3160 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
| 3161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | |
| 3163 | /* Fill out the OS statistics structure */ |
| 3164 | |
| 3165 | adapter->net_stats.rx_packets = adapter->stats.gprc; |
| 3166 | adapter->net_stats.tx_packets = adapter->stats.gptc; |
| 3167 | adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
| 3168 | adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
| 3169 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3170 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3171 | |
| 3172 | /* Rx Errors */ |
| 3173 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3174 | /* RLEC on some newer hardware can be incorrect so build |
| 3175 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3177 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3178 | adapter->stats.ruc + adapter->stats.roc + |
| 3179 | adapter->stats.cexterr; |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3180 | adapter->net_stats.rx_dropped = 0; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3181 | adapter->net_stats.rx_length_errors = adapter->stats.ruc + |
| 3182 | adapter->stats.roc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3184 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3186 | |
| 3187 | /* Tx Errors */ |
| 3188 | |
| 3189 | adapter->net_stats.tx_errors = adapter->stats.ecol + |
| 3190 | adapter->stats.latecol; |
| 3191 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3192 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3193 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
| 3194 | |
| 3195 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3196 | |
| 3197 | /* Phy Stats */ |
| 3198 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3199 | if (hw->media_type == e1000_media_type_copper) { |
| 3200 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3202 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3203 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3204 | } |
| 3205 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3206 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | (hw->phy_type == e1000_phy_m88) && |
| 3208 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3209 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3210 | } |
| 3211 | |
| 3212 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * e1000_intr - Interrupt Handler |
| 3217 | * @irq: interrupt number |
| 3218 | * @data: pointer to a network interface device structure |
| 3219 | * @pt_regs: CPU registers structure |
| 3220 | **/ |
| 3221 | |
| 3222 | static irqreturn_t |
| 3223 | e1000_intr(int irq, void *data, struct pt_regs *regs) |
| 3224 | { |
| 3225 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3226 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3228 | uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3229 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3230 | int i; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3231 | #else |
| 3232 | /* Interrupt Auto-Mask...upon reading ICR, |
| 3233 | * interrupts are masked. No need for the |
| 3234 | * IMC write, but it does mean we should |
| 3235 | * account for it ASAP. */ |
| 3236 | if (likely(hw->mac_type >= e1000_82571)) |
| 3237 | atomic_inc(&adapter->irq_sem); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3238 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3240 | if (unlikely(!icr)) { |
| 3241 | #ifdef CONFIG_E1000_NAPI |
| 3242 | if (hw->mac_type >= e1000_82571) |
| 3243 | e1000_irq_enable(adapter); |
| 3244 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | return IRQ_NONE; /* Not our interrupt */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3248 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3250 | /* 80003ES2LAN workaround-- |
| 3251 | * For packet buffer work-around on link down event; |
| 3252 | * disable receives here in the ISR and |
| 3253 | * reset adapter in watchdog |
| 3254 | */ |
| 3255 | if (netif_carrier_ok(netdev) && |
| 3256 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3257 | /* disable receives */ |
| 3258 | rctl = E1000_READ_REG(hw, RCTL); |
| 3259 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 3262 | } |
| 3263 | |
| 3264 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3265 | if (unlikely(hw->mac_type < e1000_82571)) { |
| 3266 | atomic_inc(&adapter->irq_sem); |
| 3267 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3268 | E1000_WRITE_FLUSH(hw); |
| 3269 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3270 | if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0]))) |
| 3271 | __netif_rx_schedule(&adapter->polling_netdev[0]); |
| 3272 | else |
| 3273 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3274 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3276 | * Due to Hub Link bus being occupied, an interrupt |
| 3277 | * de-assertion message is not able to be sent. |
| 3278 | * When an interrupt assertion message is generated later, |
| 3279 | * two messages are re-ordered and sent out. |
| 3280 | * That causes APIC to think 82547 is in de-assertion |
| 3281 | * state, while 82547 is in assertion state, resulting |
| 3282 | * in dead lock. Writing IMC forces 82547 into |
| 3283 | * de-assertion state. |
| 3284 | */ |
| 3285 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | atomic_inc(&adapter->irq_sem); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3287 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3290 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3291 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3292 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | break; |
| 3294 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3295 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3297 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3298 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | |
| 3300 | return IRQ_HANDLED; |
| 3301 | } |
| 3302 | |
| 3303 | #ifdef CONFIG_E1000_NAPI |
| 3304 | /** |
| 3305 | * e1000_clean - NAPI Rx polling callback |
| 3306 | * @adapter: board private structure |
| 3307 | **/ |
| 3308 | |
| 3309 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3310 | e1000_clean(struct net_device *poll_dev, int *budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3312 | struct e1000_adapter *adapter; |
| 3313 | int work_to_do = min(*budget, poll_dev->quota); |
Jeff Kirsher | 38bd3b2 | 2006-01-12 16:51:37 -0800 | [diff] [blame] | 3314 | int tx_cleaned = 0, i = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3315 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3316 | /* Must NOT use netdev_priv macro here. */ |
| 3317 | adapter = poll_dev->priv; |
| 3318 | |
| 3319 | /* Keep link state information with original netdev */ |
| 3320 | if (!netif_carrier_ok(adapter->netdev)) |
| 3321 | goto quit_polling; |
| 3322 | |
| 3323 | while (poll_dev != &adapter->polling_netdev[i]) { |
| 3324 | i++; |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 3325 | if (unlikely(i == adapter->num_rx_queues)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3326 | BUG(); |
| 3327 | } |
| 3328 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 3329 | if (likely(adapter->num_tx_queues == 1)) { |
| 3330 | /* e1000_clean is called per-cpu. This lock protects |
| 3331 | * tx_ring[0] from being cleaned by multiple cpus |
| 3332 | * simultaneously. A failure obtaining the lock means |
| 3333 | * tx_ring[0] is currently being cleaned anyway. */ |
| 3334 | if (spin_trylock(&adapter->tx_queue_lock)) { |
| 3335 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 3336 | &adapter->tx_ring[0]); |
| 3337 | spin_unlock(&adapter->tx_queue_lock); |
| 3338 | } |
| 3339 | } else |
| 3340 | tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]); |
| 3341 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3342 | adapter->clean_rx(adapter, &adapter->rx_ring[i], |
| 3343 | &work_done, work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | |
| 3345 | *budget -= work_done; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3346 | poll_dev->quota -= work_done; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3347 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 3348 | /* If no Tx and not enough Rx work done, exit the polling mode */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3349 | if ((!tx_cleaned && (work_done == 0)) || |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3350 | !netif_running(adapter->netdev)) { |
| 3351 | quit_polling: |
| 3352 | netif_rx_complete(poll_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | e1000_irq_enable(adapter); |
| 3354 | return 0; |
| 3355 | } |
| 3356 | |
| 3357 | return 1; |
| 3358 | } |
| 3359 | |
| 3360 | #endif |
| 3361 | /** |
| 3362 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3363 | * @adapter: board private structure |
| 3364 | **/ |
| 3365 | |
| 3366 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3367 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3368 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | struct net_device *netdev = adapter->netdev; |
| 3371 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3372 | struct e1000_buffer *buffer_info; |
| 3373 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3374 | #ifdef CONFIG_E1000_NAPI |
| 3375 | unsigned int count = 0; |
| 3376 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | boolean_t cleaned = FALSE; |
| 3378 | |
| 3379 | i = tx_ring->next_to_clean; |
| 3380 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3381 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3382 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3383 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3384 | for (cleaned = FALSE; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3386 | buffer_info = &tx_ring->buffer_info[i]; |
| 3387 | cleaned = (i == eop); |
| 3388 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3389 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 3390 | memset(tx_desc, 0, sizeof(struct e1000_tx_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3392 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3394 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3397 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3398 | #ifdef CONFIG_E1000_NAPI |
| 3399 | #define E1000_TX_WEIGHT 64 |
| 3400 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
| 3401 | if (count++ == E1000_TX_WEIGHT) break; |
| 3402 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | tx_ring->next_to_clean = i; |
| 3406 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3407 | spin_lock(&tx_ring->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3409 | if (unlikely(cleaned && netif_queue_stopped(netdev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | netif_carrier_ok(netdev))) |
| 3411 | netif_wake_queue(netdev); |
| 3412 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3413 | spin_unlock(&tx_ring->tx_lock); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3414 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3415 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3416 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | * check with the clearing of time_stamp and movement of i */ |
| 3418 | adapter->detect_tx_hung = FALSE; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3419 | if (tx_ring->buffer_info[eop].dma && |
| 3420 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 3421 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3422 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3423 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3424 | |
| 3425 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 3426 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3427 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3428 | " TDH <%x>\n" |
| 3429 | " TDT <%x>\n" |
| 3430 | " next_to_use <%x>\n" |
| 3431 | " next_to_clean <%x>\n" |
| 3432 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3433 | " time_stamp <%lx>\n" |
| 3434 | " next_to_watch <%x>\n" |
| 3435 | " jiffies <%lx>\n" |
| 3436 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3437 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3438 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3439 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 3440 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3441 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3442 | tx_ring->next_to_clean, |
| 3443 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3444 | eop, |
| 3445 | jiffies, |
| 3446 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | return cleaned; |
| 3451 | } |
| 3452 | |
| 3453 | /** |
| 3454 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3455 | * @adapter: board private structure |
| 3456 | * @status_err: receive descriptor status and error fields |
| 3457 | * @csum: receive descriptor csum field |
| 3458 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | **/ |
| 3460 | |
| 3461 | static inline void |
| 3462 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3463 | uint32_t status_err, uint32_t csum, |
| 3464 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3466 | uint16_t status = (uint16_t)status_err; |
| 3467 | uint8_t errors = (uint8_t)(status_err >> 24); |
| 3468 | skb->ip_summed = CHECKSUM_NONE; |
| 3469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3471 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3473 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3474 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3475 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3476 | /* let the stack verify checksum errors */ |
| 3477 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | return; |
| 3479 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3480 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3481 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 3482 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3483 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3485 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3486 | return; |
| 3487 | } |
| 3488 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 3489 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | /* TCP checksum is good */ |
| 3491 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3492 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 3493 | /* IP fragment with UDP payload */ |
| 3494 | /* Hardware complements the payload checksum, so we undo it |
| 3495 | * and then put the value in host order for further stack use. |
| 3496 | */ |
| 3497 | csum = ntohl(csum ^ 0xFFFF); |
| 3498 | skb->csum = csum; |
| 3499 | skb->ip_summed = CHECKSUM_HW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3501 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3505 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | * @adapter: board private structure |
| 3507 | **/ |
| 3508 | |
| 3509 | static boolean_t |
| 3510 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3511 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 3512 | struct e1000_rx_ring *rx_ring, |
| 3513 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3515 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 3516 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | #endif |
| 3518 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | struct net_device *netdev = adapter->netdev; |
| 3520 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3521 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 3522 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | unsigned long flags; |
| 3524 | uint32_t length; |
| 3525 | uint8_t last_byte; |
| 3526 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3527 | int cleaned_count = 0; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3528 | boolean_t cleaned = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | |
| 3530 | i = rx_ring->next_to_clean; |
| 3531 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3532 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3534 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3535 | struct sk_buff *skb, *next_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3536 | u8 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3538 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | break; |
| 3540 | (*work_done)++; |
| 3541 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3542 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3543 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3544 | buffer_info->skb = NULL; |
| 3545 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3546 | prefetch(skb->data - NET_IP_ALIGN); |
| 3547 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3548 | if (++i == rx_ring->count) i = 0; |
| 3549 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3550 | prefetch(next_rxd); |
| 3551 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3552 | next_buffer = &rx_ring->buffer_info[i]; |
| 3553 | next_skb = next_buffer->skb; |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3554 | prefetch(next_skb->data - NET_IP_ALIGN); |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3555 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3556 | cleaned = TRUE; |
| 3557 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3558 | pci_unmap_single(pdev, |
| 3559 | buffer_info->dma, |
| 3560 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | PCI_DMA_FROMDEVICE); |
| 3562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | length = le16_to_cpu(rx_desc->length); |
| 3564 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3565 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 3566 | /* All receives must fit into a single buffer */ |
| 3567 | E1000_DBG("%s: Receive packet consumed multiple" |
| 3568 | " buffers\n", netdev->name); |
| 3569 | dev_kfree_skb_irq(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | goto next_desc; |
| 3571 | } |
| 3572 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3573 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3575 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | rx_desc->errors, length, last_byte)) { |
| 3577 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3578 | e1000_tbi_adjust_stats(&adapter->hw, |
| 3579 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | length, skb->data); |
| 3581 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 3582 | flags); |
| 3583 | length--; |
| 3584 | } else { |
| 3585 | dev_kfree_skb_irq(skb); |
| 3586 | goto next_desc; |
| 3587 | } |
| 3588 | } |
| 3589 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3590 | /* code added for copybreak, this should improve |
| 3591 | * performance for small packets with large amounts |
| 3592 | * of reassembly being done in the stack */ |
| 3593 | #define E1000_CB_LENGTH 256 |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3594 | if (length < E1000_CB_LENGTH) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3595 | struct sk_buff *new_skb = |
| 3596 | dev_alloc_skb(length + NET_IP_ALIGN); |
| 3597 | if (new_skb) { |
| 3598 | skb_reserve(new_skb, NET_IP_ALIGN); |
| 3599 | new_skb->dev = netdev; |
| 3600 | memcpy(new_skb->data - NET_IP_ALIGN, |
| 3601 | skb->data - NET_IP_ALIGN, |
| 3602 | length + NET_IP_ALIGN); |
| 3603 | /* save the skb in buffer_info as good */ |
| 3604 | buffer_info->skb = skb; |
| 3605 | skb = new_skb; |
| 3606 | skb_put(skb, length); |
| 3607 | } |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3608 | } else |
| 3609 | skb_put(skb, length); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3610 | |
| 3611 | /* end copybreak code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | |
| 3613 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3614 | e1000_rx_checksum(adapter, |
| 3615 | (uint32_t)(status) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3616 | ((uint32_t)(rx_desc->errors) << 24), |
| 3617 | rx_desc->csum, skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | skb->protocol = eth_type_trans(skb, netdev); |
| 3620 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3621 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3622 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3624 | le16_to_cpu(rx_desc->special) & |
| 3625 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } else { |
| 3627 | netif_receive_skb(skb); |
| 3628 | } |
| 3629 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3630 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3631 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 3633 | le16_to_cpu(rx_desc->special) & |
| 3634 | E1000_RXD_SPC_VLAN_MASK); |
| 3635 | } else { |
| 3636 | netif_rx(skb); |
| 3637 | } |
| 3638 | #endif /* CONFIG_E1000_NAPI */ |
| 3639 | netdev->last_rx = jiffies; |
| 3640 | |
| 3641 | next_desc: |
| 3642 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3644 | /* return some buffers to hardware, one at a time is too slow */ |
| 3645 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 3646 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3647 | cleaned_count = 0; |
| 3648 | } |
| 3649 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3650 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3651 | rx_desc = next_rxd; |
| 3652 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3655 | |
| 3656 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 3657 | if (cleaned_count) |
| 3658 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | |
| 3660 | return cleaned; |
| 3661 | } |
| 3662 | |
| 3663 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3664 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 3665 | * @adapter: board private structure |
| 3666 | **/ |
| 3667 | |
| 3668 | static boolean_t |
| 3669 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3670 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 3671 | struct e1000_rx_ring *rx_ring, |
| 3672 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3673 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3674 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 3675 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3676 | #endif |
| 3677 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3678 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3679 | struct net_device *netdev = adapter->netdev; |
| 3680 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3681 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3682 | struct e1000_ps_page *ps_page; |
| 3683 | struct e1000_ps_page_dma *ps_page_dma; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3684 | struct sk_buff *skb, *next_skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3685 | unsigned int i, j; |
| 3686 | uint32_t length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3687 | int cleaned_count = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3688 | boolean_t cleaned = FALSE; |
| 3689 | |
| 3690 | i = rx_ring->next_to_clean; |
| 3691 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3692 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3693 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3694 | while (staterr & E1000_RXD_STAT_DD) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3695 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3696 | ps_page = &rx_ring->ps_page[i]; |
| 3697 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 3698 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3699 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3700 | break; |
| 3701 | (*work_done)++; |
| 3702 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3703 | skb = buffer_info->skb; |
| 3704 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3705 | /* in the packet split case this is header only */ |
| 3706 | prefetch(skb->data - NET_IP_ALIGN); |
| 3707 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3708 | if (++i == rx_ring->count) i = 0; |
| 3709 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3710 | prefetch(next_rxd); |
| 3711 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3712 | next_buffer = &rx_ring->buffer_info[i]; |
| 3713 | next_skb = next_buffer->skb; |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3714 | prefetch(next_skb->data - NET_IP_ALIGN); |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3715 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3716 | cleaned = TRUE; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3717 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3718 | pci_unmap_single(pdev, buffer_info->dma, |
| 3719 | buffer_info->length, |
| 3720 | PCI_DMA_FROMDEVICE); |
| 3721 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3722 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3723 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 3724 | " the full packet\n", netdev->name); |
| 3725 | dev_kfree_skb_irq(skb); |
| 3726 | goto next_desc; |
| 3727 | } |
| 3728 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3729 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3730 | dev_kfree_skb_irq(skb); |
| 3731 | goto next_desc; |
| 3732 | } |
| 3733 | |
| 3734 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 3735 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3736 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3737 | E1000_DBG("%s: Last part of the packet spanning" |
| 3738 | " multiple descriptors\n", netdev->name); |
| 3739 | dev_kfree_skb_irq(skb); |
| 3740 | goto next_desc; |
| 3741 | } |
| 3742 | |
| 3743 | /* Good Receive */ |
| 3744 | skb_put(skb, length); |
| 3745 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 3746 | { |
| 3747 | /* this looks ugly, but it seems compiler issues make it |
| 3748 | more efficient than reusing j */ |
| 3749 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 3750 | |
| 3751 | /* page alloc/put takes too long and effects small packet |
| 3752 | * throughput, so unsplit small packets and save the alloc/put*/ |
| 3753 | if (l1 && ((length + l1) < E1000_CB_LENGTH)) { |
| 3754 | u8 *vaddr; |
| 3755 | /* there is no documentation about how to call |
| 3756 | * kmap_atomic, so we can't hold the mapping |
| 3757 | * very long */ |
| 3758 | pci_dma_sync_single_for_cpu(pdev, |
| 3759 | ps_page_dma->ps_page_dma[0], |
| 3760 | PAGE_SIZE, |
| 3761 | PCI_DMA_FROMDEVICE); |
| 3762 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 3763 | KM_SKB_DATA_SOFTIRQ); |
| 3764 | memcpy(skb->tail, vaddr, l1); |
| 3765 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 3766 | pci_dma_sync_single_for_device(pdev, |
| 3767 | ps_page_dma->ps_page_dma[0], |
| 3768 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 3769 | skb_put(skb, l1); |
| 3770 | length += l1; |
| 3771 | goto copydone; |
| 3772 | } /* if */ |
| 3773 | } |
| 3774 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3775 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3776 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3777 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3778 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 3779 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 3780 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 3781 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 3782 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3783 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3784 | skb->len += length; |
| 3785 | skb->data_len += length; |
| 3786 | } |
| 3787 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 3788 | copydone: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3789 | e1000_rx_checksum(adapter, staterr, |
| 3790 | rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); |
| 3791 | skb->protocol = eth_type_trans(skb, netdev); |
| 3792 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3793 | if (likely(rx_desc->wb.upper.header_status & |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3794 | E1000_RXDPS_HDRSTAT_HDRSP)) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3795 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3796 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3797 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3798 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3799 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 3800 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3801 | } else { |
| 3802 | netif_receive_skb(skb); |
| 3803 | } |
| 3804 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3805 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3806 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3807 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 3808 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3809 | } else { |
| 3810 | netif_rx(skb); |
| 3811 | } |
| 3812 | #endif /* CONFIG_E1000_NAPI */ |
| 3813 | netdev->last_rx = jiffies; |
| 3814 | |
| 3815 | next_desc: |
| 3816 | rx_desc->wb.middle.status_error &= ~0xFF; |
| 3817 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3818 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3819 | /* return some buffers to hardware, one at a time is too slow */ |
| 3820 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 3821 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3822 | cleaned_count = 0; |
| 3823 | } |
| 3824 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3825 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3826 | rx_desc = next_rxd; |
| 3827 | buffer_info = next_buffer; |
| 3828 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3829 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3830 | } |
| 3831 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3832 | |
| 3833 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 3834 | if (cleaned_count) |
| 3835 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3836 | |
| 3837 | return cleaned; |
| 3838 | } |
| 3839 | |
| 3840 | /** |
| 3841 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | * @adapter: address of board private structure |
| 3843 | **/ |
| 3844 | |
| 3845 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3846 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3847 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3848 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | struct net_device *netdev = adapter->netdev; |
| 3851 | struct pci_dev *pdev = adapter->pdev; |
| 3852 | struct e1000_rx_desc *rx_desc; |
| 3853 | struct e1000_buffer *buffer_info; |
| 3854 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3855 | unsigned int i; |
| 3856 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | |
| 3858 | i = rx_ring->next_to_use; |
| 3859 | buffer_info = &rx_ring->buffer_info[i]; |
| 3860 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3861 | while (cleaned_count--) { |
| 3862 | if (!(skb = buffer_info->skb)) |
| 3863 | skb = dev_alloc_skb(bufsz); |
| 3864 | else { |
| 3865 | skb_trim(skb, 0); |
| 3866 | goto map_skb; |
| 3867 | } |
| 3868 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3869 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3871 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | break; |
| 3873 | } |
| 3874 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3875 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 3877 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3878 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 3879 | "at %p\n", bufsz, skb->data); |
| 3880 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | skb = dev_alloc_skb(bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3882 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | if (!skb) { |
| 3884 | dev_kfree_skb(oldskb); |
| 3885 | break; |
| 3886 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 3889 | /* give up */ |
| 3890 | dev_kfree_skb(skb); |
| 3891 | dev_kfree_skb(oldskb); |
| 3892 | break; /* while !buffer_info->skb */ |
| 3893 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3894 | /* Use new allocation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | dev_kfree_skb(oldskb); |
| 3896 | } |
| 3897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 3899 | * this will result in a 16 byte aligned IP header after |
| 3900 | * the 14 byte MAC header is removed |
| 3901 | */ |
| 3902 | skb_reserve(skb, NET_IP_ALIGN); |
| 3903 | |
| 3904 | skb->dev = netdev; |
| 3905 | |
| 3906 | buffer_info->skb = skb; |
| 3907 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3908 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | buffer_info->dma = pci_map_single(pdev, |
| 3910 | skb->data, |
| 3911 | adapter->rx_buffer_len, |
| 3912 | PCI_DMA_FROMDEVICE); |
| 3913 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3914 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 3915 | if (!e1000_check_64k_bound(adapter, |
| 3916 | (void *)(unsigned long)buffer_info->dma, |
| 3917 | adapter->rx_buffer_len)) { |
| 3918 | DPRINTK(RX_ERR, ERR, |
| 3919 | "dma align check failed: %u bytes at %p\n", |
| 3920 | adapter->rx_buffer_len, |
| 3921 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | dev_kfree_skb(skb); |
| 3923 | buffer_info->skb = NULL; |
| 3924 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3925 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | adapter->rx_buffer_len, |
| 3927 | PCI_DMA_FROMDEVICE); |
| 3928 | |
| 3929 | break; /* while !buffer_info->skb */ |
| 3930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 3932 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3933 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3934 | if (unlikely(++i == rx_ring->count)) |
| 3935 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | buffer_info = &rx_ring->buffer_info[i]; |
| 3937 | } |
| 3938 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3939 | if (likely(rx_ring->next_to_use != i)) { |
| 3940 | rx_ring->next_to_use = i; |
| 3941 | if (unlikely(i-- == 0)) |
| 3942 | i = (rx_ring->count - 1); |
| 3943 | |
| 3944 | /* Force memory writes to complete before letting h/w |
| 3945 | * know there are new descriptors to fetch. (Only |
| 3946 | * applicable for weak-ordered memory model archs, |
| 3947 | * such as IA-64). */ |
| 3948 | wmb(); |
| 3949 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 3950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3954 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 3955 | * @adapter: address of board private structure |
| 3956 | **/ |
| 3957 | |
| 3958 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3959 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3960 | struct e1000_rx_ring *rx_ring, |
| 3961 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3962 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3963 | struct net_device *netdev = adapter->netdev; |
| 3964 | struct pci_dev *pdev = adapter->pdev; |
| 3965 | union e1000_rx_desc_packet_split *rx_desc; |
| 3966 | struct e1000_buffer *buffer_info; |
| 3967 | struct e1000_ps_page *ps_page; |
| 3968 | struct e1000_ps_page_dma *ps_page_dma; |
| 3969 | struct sk_buff *skb; |
| 3970 | unsigned int i, j; |
| 3971 | |
| 3972 | i = rx_ring->next_to_use; |
| 3973 | buffer_info = &rx_ring->buffer_info[i]; |
| 3974 | ps_page = &rx_ring->ps_page[i]; |
| 3975 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 3976 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3977 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3978 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 3979 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3980 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3981 | if (j < adapter->rx_ps_pages) { |
| 3982 | if (likely(!ps_page->ps_page[j])) { |
| 3983 | ps_page->ps_page[j] = |
| 3984 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3985 | if (unlikely(!ps_page->ps_page[j])) { |
| 3986 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3987 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3988 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3989 | ps_page_dma->ps_page_dma[j] = |
| 3990 | pci_map_page(pdev, |
| 3991 | ps_page->ps_page[j], |
| 3992 | 0, PAGE_SIZE, |
| 3993 | PCI_DMA_FROMDEVICE); |
| 3994 | } |
| 3995 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3996 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3997 | * this info. |
| 3998 | */ |
| 3999 | rx_desc->read.buffer_addr[j+1] = |
| 4000 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 4001 | } else |
| 4002 | rx_desc->read.buffer_addr[j+1] = ~0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
| 4006 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4007 | if (unlikely(!skb)) { |
| 4008 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4009 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4010 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4011 | |
| 4012 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4013 | * this will result in a 16 byte aligned IP header after |
| 4014 | * the 14 byte MAC header is removed |
| 4015 | */ |
| 4016 | skb_reserve(skb, NET_IP_ALIGN); |
| 4017 | |
| 4018 | skb->dev = netdev; |
| 4019 | |
| 4020 | buffer_info->skb = skb; |
| 4021 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4022 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4023 | adapter->rx_ps_bsize0, |
| 4024 | PCI_DMA_FROMDEVICE); |
| 4025 | |
| 4026 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4027 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4028 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4029 | buffer_info = &rx_ring->buffer_info[i]; |
| 4030 | ps_page = &rx_ring->ps_page[i]; |
| 4031 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4032 | } |
| 4033 | |
| 4034 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4035 | if (likely(rx_ring->next_to_use != i)) { |
| 4036 | rx_ring->next_to_use = i; |
| 4037 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4038 | |
| 4039 | /* Force memory writes to complete before letting h/w |
| 4040 | * know there are new descriptors to fetch. (Only |
| 4041 | * applicable for weak-ordered memory model archs, |
| 4042 | * such as IA-64). */ |
| 4043 | wmb(); |
| 4044 | /* Hardware increments by 16 bytes, but packet split |
| 4045 | * descriptors are 32 bytes...so we increment tail |
| 4046 | * twice as much. |
| 4047 | */ |
| 4048 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4049 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4054 | * @adapter: |
| 4055 | **/ |
| 4056 | |
| 4057 | static void |
| 4058 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4059 | { |
| 4060 | uint16_t phy_status; |
| 4061 | uint16_t phy_ctrl; |
| 4062 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4063 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4065 | return; |
| 4066 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4067 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | /* If Master/Slave config fault is asserted twice, |
| 4069 | * we assume back-to-back */ |
| 4070 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4071 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4073 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4075 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4077 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4078 | phy_ctrl); |
| 4079 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4080 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4082 | &phy_ctrl)) { |
| 4083 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4084 | MII_CR_RESTART_AUTO_NEG); |
| 4085 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4086 | phy_ctrl); |
| 4087 | } |
| 4088 | } |
| 4089 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4090 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4092 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4093 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4094 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4095 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4097 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4098 | MII_CR_RESTART_AUTO_NEG); |
| 4099 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4100 | } |
| 4101 | } |
| 4102 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4103 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | adapter->smartspeed = 0; |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * e1000_ioctl - |
| 4109 | * @netdev: |
| 4110 | * @ifreq: |
| 4111 | * @cmd: |
| 4112 | **/ |
| 4113 | |
| 4114 | static int |
| 4115 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4116 | { |
| 4117 | switch (cmd) { |
| 4118 | case SIOCGMIIPHY: |
| 4119 | case SIOCGMIIREG: |
| 4120 | case SIOCSMIIREG: |
| 4121 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4122 | default: |
| 4123 | return -EOPNOTSUPP; |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | /** |
| 4128 | * e1000_mii_ioctl - |
| 4129 | * @netdev: |
| 4130 | * @ifreq: |
| 4131 | * @cmd: |
| 4132 | **/ |
| 4133 | |
| 4134 | static int |
| 4135 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4136 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4137 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4139 | int retval; |
| 4140 | uint16_t mii_reg; |
| 4141 | uint16_t spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4142 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4144 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | return -EOPNOTSUPP; |
| 4146 | |
| 4147 | switch (cmd) { |
| 4148 | case SIOCGMIIPHY: |
| 4149 | data->phy_id = adapter->hw.phy_addr; |
| 4150 | break; |
| 4151 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4152 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4154 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4155 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4156 | &data->val_out)) { |
| 4157 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4159 | } |
| 4160 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | break; |
| 4162 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4163 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4165 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | return -EFAULT; |
| 4167 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4168 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4169 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4170 | mii_reg)) { |
| 4171 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4173 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4174 | if (adapter->hw.phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | switch (data->reg_num) { |
| 4176 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4177 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4179 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | adapter->hw.autoneg = 1; |
| 4181 | adapter->hw.autoneg_advertised = 0x2F; |
| 4182 | } else { |
| 4183 | if (mii_reg & 0x40) |
| 4184 | spddplx = SPEED_1000; |
| 4185 | else if (mii_reg & 0x2000) |
| 4186 | spddplx = SPEED_100; |
| 4187 | else |
| 4188 | spddplx = SPEED_10; |
| 4189 | spddplx += (mii_reg & 0x100) |
| 4190 | ? FULL_DUPLEX : |
| 4191 | HALF_DUPLEX; |
| 4192 | retval = e1000_set_spd_dplx(adapter, |
| 4193 | spddplx); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4194 | if (retval) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4195 | spin_unlock_irqrestore( |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4196 | &adapter->stats_lock, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4197 | flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | return retval; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4201 | if (netif_running(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | e1000_down(adapter); |
| 4203 | e1000_up(adapter); |
| 4204 | } else |
| 4205 | e1000_reset(adapter); |
| 4206 | break; |
| 4207 | case M88E1000_PHY_SPEC_CTRL: |
| 4208 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4209 | if (e1000_phy_reset(&adapter->hw)) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4210 | spin_unlock_irqrestore( |
| 4211 | &adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | break; |
| 4215 | } |
| 4216 | } else { |
| 4217 | switch (data->reg_num) { |
| 4218 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4219 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4221 | if (netif_running(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | e1000_down(adapter); |
| 4223 | e1000_up(adapter); |
| 4224 | } else |
| 4225 | e1000_reset(adapter); |
| 4226 | break; |
| 4227 | } |
| 4228 | } |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4229 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | break; |
| 4231 | default: |
| 4232 | return -EOPNOTSUPP; |
| 4233 | } |
| 4234 | return E1000_SUCCESS; |
| 4235 | } |
| 4236 | |
| 4237 | void |
| 4238 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4239 | { |
| 4240 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4241 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4243 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4244 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | void |
| 4248 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4249 | { |
| 4250 | struct e1000_adapter *adapter = hw->back; |
| 4251 | |
| 4252 | pci_clear_mwi(adapter->pdev); |
| 4253 | } |
| 4254 | |
| 4255 | void |
| 4256 | e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4257 | { |
| 4258 | struct e1000_adapter *adapter = hw->back; |
| 4259 | |
| 4260 | pci_read_config_word(adapter->pdev, reg, value); |
| 4261 | } |
| 4262 | |
| 4263 | void |
| 4264 | e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4265 | { |
| 4266 | struct e1000_adapter *adapter = hw->back; |
| 4267 | |
| 4268 | pci_write_config_word(adapter->pdev, reg, *value); |
| 4269 | } |
| 4270 | |
| 4271 | uint32_t |
| 4272 | e1000_io_read(struct e1000_hw *hw, unsigned long port) |
| 4273 | { |
| 4274 | return inl(port); |
| 4275 | } |
| 4276 | |
| 4277 | void |
| 4278 | e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
| 4279 | { |
| 4280 | outl(value, port); |
| 4281 | } |
| 4282 | |
| 4283 | static void |
| 4284 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 4285 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4286 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | uint32_t ctrl, rctl; |
| 4288 | |
| 4289 | e1000_irq_disable(adapter); |
| 4290 | adapter->vlgrp = grp; |
| 4291 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4292 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | /* enable VLAN tag insert/strip */ |
| 4294 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4295 | ctrl |= E1000_CTRL_VME; |
| 4296 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4297 | |
| 4298 | /* enable VLAN receive filtering */ |
| 4299 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4300 | rctl |= E1000_RCTL_VFE; |
| 4301 | rctl &= ~E1000_RCTL_CFIEN; |
| 4302 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4303 | e1000_update_mng_vlan(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | } else { |
| 4305 | /* disable VLAN tag insert/strip */ |
| 4306 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4307 | ctrl &= ~E1000_CTRL_VME; |
| 4308 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4309 | |
| 4310 | /* disable VLAN filtering */ |
| 4311 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4312 | rctl &= ~E1000_RCTL_VFE; |
| 4313 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4314 | if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4315 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 4316 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | e1000_irq_enable(adapter); |
| 4321 | } |
| 4322 | |
| 4323 | static void |
| 4324 | e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 4325 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4326 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | uint32_t vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4328 | |
| 4329 | if ((adapter->hw.mng_cookie.status & |
| 4330 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4331 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4332 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | /* add VID to filter table */ |
| 4334 | index = (vid >> 5) & 0x7F; |
| 4335 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4336 | vfta |= (1 << (vid & 0x1F)); |
| 4337 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4338 | } |
| 4339 | |
| 4340 | static void |
| 4341 | e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 4342 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4343 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | uint32_t vfta, index; |
| 4345 | |
| 4346 | e1000_irq_disable(adapter); |
| 4347 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4348 | if (adapter->vlgrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | adapter->vlgrp->vlan_devices[vid] = NULL; |
| 4350 | |
| 4351 | e1000_irq_enable(adapter); |
| 4352 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4353 | if ((adapter->hw.mng_cookie.status & |
| 4354 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4355 | (vid == adapter->mng_vlan_id)) { |
| 4356 | /* release control to f/w */ |
| 4357 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4358 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | /* remove VID from filter table */ |
| 4362 | index = (vid >> 5) & 0x7F; |
| 4363 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4364 | vfta &= ~(1 << (vid & 0x1F)); |
| 4365 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4366 | } |
| 4367 | |
| 4368 | static void |
| 4369 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 4370 | { |
| 4371 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4372 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4373 | if (adapter->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | uint16_t vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4375 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 4376 | if (!adapter->vlgrp->vlan_devices[vid]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | continue; |
| 4378 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | int |
| 4384 | e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
| 4385 | { |
| 4386 | adapter->hw.autoneg = 0; |
| 4387 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4388 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4389 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4390 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 4391 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 4392 | return -EINVAL; |
| 4393 | } |
| 4394 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4395 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | case SPEED_10 + DUPLEX_HALF: |
| 4397 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 4398 | break; |
| 4399 | case SPEED_10 + DUPLEX_FULL: |
| 4400 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 4401 | break; |
| 4402 | case SPEED_100 + DUPLEX_HALF: |
| 4403 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 4404 | break; |
| 4405 | case SPEED_100 + DUPLEX_FULL: |
| 4406 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 4407 | break; |
| 4408 | case SPEED_1000 + DUPLEX_FULL: |
| 4409 | adapter->hw.autoneg = 1; |
| 4410 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 4411 | break; |
| 4412 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 4413 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4414 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | return -EINVAL; |
| 4416 | } |
| 4417 | return 0; |
| 4418 | } |
| 4419 | |
Martin J. Bligh | b6a1d5f | 2005-10-28 15:14:44 -0700 | [diff] [blame] | 4420 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4421 | /* Save/restore 16 or 64 dwords of PCI config space depending on which |
| 4422 | * bus we're on (PCI(X) vs. PCI-E) |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4423 | */ |
| 4424 | #define PCIE_CONFIG_SPACE_LEN 256 |
| 4425 | #define PCI_CONFIG_SPACE_LEN 64 |
| 4426 | static int |
| 4427 | e1000_pci_save_state(struct e1000_adapter *adapter) |
| 4428 | { |
| 4429 | struct pci_dev *dev = adapter->pdev; |
| 4430 | int size; |
| 4431 | int i; |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4432 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4433 | if (adapter->hw.mac_type >= e1000_82571) |
| 4434 | size = PCIE_CONFIG_SPACE_LEN; |
| 4435 | else |
| 4436 | size = PCI_CONFIG_SPACE_LEN; |
| 4437 | |
| 4438 | WARN_ON(adapter->config_space != NULL); |
| 4439 | |
| 4440 | adapter->config_space = kmalloc(size, GFP_KERNEL); |
| 4441 | if (!adapter->config_space) { |
| 4442 | DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size); |
| 4443 | return -ENOMEM; |
| 4444 | } |
| 4445 | for (i = 0; i < (size / 4); i++) |
| 4446 | pci_read_config_dword(dev, i * 4, &adapter->config_space[i]); |
| 4447 | return 0; |
| 4448 | } |
| 4449 | |
| 4450 | static void |
| 4451 | e1000_pci_restore_state(struct e1000_adapter *adapter) |
| 4452 | { |
| 4453 | struct pci_dev *dev = adapter->pdev; |
| 4454 | int size; |
| 4455 | int i; |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4456 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4457 | if (adapter->config_space == NULL) |
| 4458 | return; |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4459 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4460 | if (adapter->hw.mac_type >= e1000_82571) |
| 4461 | size = PCIE_CONFIG_SPACE_LEN; |
| 4462 | else |
| 4463 | size = PCI_CONFIG_SPACE_LEN; |
| 4464 | for (i = 0; i < (size / 4); i++) |
| 4465 | pci_write_config_dword(dev, i * 4, adapter->config_space[i]); |
| 4466 | kfree(adapter->config_space); |
| 4467 | adapter->config_space = NULL; |
| 4468 | return; |
| 4469 | } |
| 4470 | #endif /* CONFIG_PM */ |
| 4471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 4473 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4476 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4477 | uint32_t ctrl, ctrl_ext, rctl, manc, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | uint32_t wufc = adapter->wol; |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4479 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | |
| 4481 | netif_device_detach(netdev); |
| 4482 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4483 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | e1000_down(adapter); |
| 4485 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4486 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4487 | /* Implement our own version of pci_save_state(pdev) because pci- |
| 4488 | * express adapters have 256-byte config spaces. */ |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4489 | retval = e1000_pci_save_state(adapter); |
| 4490 | if (retval) |
| 4491 | return retval; |
| 4492 | #endif |
| 4493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4495 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | wufc &= ~E1000_WUFC_LNKC; |
| 4497 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4498 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | e1000_setup_rctl(adapter); |
| 4500 | e1000_set_multi(netdev); |
| 4501 | |
| 4502 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4503 | if (adapter->wol & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4505 | rctl |= E1000_RCTL_MPE; |
| 4506 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4507 | } |
| 4508 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4509 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4511 | /* advertise wake from D3Cold */ |
| 4512 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 4513 | /* phy power management enable */ |
| 4514 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 4515 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 4516 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 4517 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4518 | } |
| 4519 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4520 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 4522 | /* keep the laser running in D3 */ |
| 4523 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 4524 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 4525 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 4526 | } |
| 4527 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4528 | /* Allow time for pending master requests to run */ |
| 4529 | e1000_disable_pciex_master(&adapter->hw); |
| 4530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 4532 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4533 | retval = pci_enable_wake(pdev, PCI_D3hot, 1); |
| 4534 | if (retval) |
| 4535 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4536 | retval = pci_enable_wake(pdev, PCI_D3cold, 1); |
| 4537 | if (retval) |
| 4538 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | } else { |
| 4540 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 4541 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4542 | retval = pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4543 | if (retval) |
| 4544 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4545 | retval = pci_enable_wake(pdev, PCI_D3cold, 0); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4546 | if (retval) |
| 4547 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4550 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | adapter->hw.media_type == e1000_media_type_copper) { |
| 4552 | manc = E1000_READ_REG(&adapter->hw, MANC); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4553 | if (manc & E1000_MANC_SMBUS_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | manc |= E1000_MANC_ARP_EN; |
| 4555 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4556 | retval = pci_enable_wake(pdev, PCI_D3hot, 1); |
| 4557 | if (retval) |
| 4558 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4559 | retval = pci_enable_wake(pdev, PCI_D3cold, 1); |
| 4560 | if (retval) |
Jeff Kirsher | 0f15a8fa | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4561 | DPRINTK(PROBE, ERR, |
| 4562 | "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4566 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 4567 | * would have already happened in close and is redundant. */ |
| 4568 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4571 | |
| 4572 | retval = pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 4573 | if (retval) |
| 4574 | DPRINTK(PROBE, ERR, "Error in setting power state\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | |
| 4576 | return 0; |
| 4577 | } |
| 4578 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4579 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | static int |
| 4581 | e1000_resume(struct pci_dev *pdev) |
| 4582 | { |
| 4583 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4584 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4585 | int retval; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4586 | uint32_t manc, ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4588 | retval = pci_set_power_state(pdev, PCI_D0); |
| 4589 | if (retval) |
| 4590 | DPRINTK(PROBE, ERR, "Error in setting power state\n"); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4591 | e1000_pci_restore_state(adapter); |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 4592 | ret_val = pci_enable_device(pdev); |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 4593 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4595 | retval = pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4596 | if (retval) |
| 4597 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4598 | retval = pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4599 | if (retval) |
| 4600 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | |
| 4602 | e1000_reset(adapter); |
| 4603 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 4604 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4605 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | e1000_up(adapter); |
| 4607 | |
| 4608 | netif_device_attach(netdev); |
| 4609 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4610 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | adapter->hw.media_type == e1000_media_type_copper) { |
| 4612 | manc = E1000_READ_REG(&adapter->hw, MANC); |
| 4613 | manc &= ~(E1000_MANC_ARP_EN); |
| 4614 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 4615 | } |
| 4616 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4617 | /* If the controller is 82573 and f/w is AMT, do not set |
| 4618 | * DRV_LOAD until the interface is up. For all other cases, |
| 4619 | * let the f/w know that the h/w is now under the control |
| 4620 | * of the driver. */ |
| 4621 | if (adapter->hw.mac_type != e1000_82573 || |
| 4622 | !e1000_check_mng_mode(&adapter->hw)) |
| 4623 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | return 0; |
| 4626 | } |
| 4627 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4629 | /* |
| 4630 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 4631 | * without having to re-enable interrupts. It's not called while |
| 4632 | * the interrupt routine is executing. |
| 4633 | */ |
| 4634 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4635 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4637 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | disable_irq(adapter->pdev->irq); |
| 4639 | e1000_intr(adapter->pdev->irq, netdev, NULL); |
Andrew Morton | c4cfe56 | 2005-10-15 00:32:29 -0700 | [diff] [blame] | 4640 | e1000_clean_tx_irq(adapter, adapter->tx_ring); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 4641 | #ifndef CONFIG_E1000_NAPI |
| 4642 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 4643 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | enable_irq(adapter->pdev->irq); |
| 4645 | } |
| 4646 | #endif |
| 4647 | |
| 4648 | /* e1000_main.c */ |