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