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