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