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