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