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