Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | |
| 4 | Copyright(c) 1999 - 2005 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 "ixgb.h" |
| 30 | |
| 31 | /* Change Log |
| 32 | * 1.0.88 01/05/05 |
| 33 | * - include fix to the condition that determines when to quit NAPI - Robert Olsson |
| 34 | * - use netif_poll_{disable/enable} to synchronize between NAPI and i/f up/down |
| 35 | * 1.0.84 10/26/04 |
| 36 | * - reset buffer_info->dma in Tx resource cleanup logic |
| 37 | * 1.0.83 10/12/04 |
| 38 | * - sparse cleanup - shemminger@osdl.org |
| 39 | * - fix tx resource cleanup logic |
| 40 | */ |
| 41 | |
| 42 | char ixgb_driver_name[] = "ixgb"; |
| 43 | char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver"; |
| 44 | |
| 45 | #ifndef CONFIG_IXGB_NAPI |
| 46 | #define DRIVERNAPI |
| 47 | #else |
| 48 | #define DRIVERNAPI "-NAPI" |
| 49 | #endif |
| 50 | char ixgb_driver_version[] = "1.0.90-k2"DRIVERNAPI; |
| 51 | char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; |
| 52 | |
| 53 | /* ixgb_pci_tbl - PCI Device ID Table |
| 54 | * |
| 55 | * Wildcard entries (PCI_ANY_ID) should come last |
| 56 | * Last entry must be all 0s |
| 57 | * |
| 58 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 59 | * Class, Class Mask, private data (not used) } |
| 60 | */ |
| 61 | static struct pci_device_id ixgb_pci_tbl[] = { |
| 62 | {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX, |
| 63 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 64 | {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR, |
| 65 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 66 | {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR, |
| 67 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 68 | |
| 69 | /* required last entry */ |
| 70 | {0,} |
| 71 | }; |
| 72 | |
| 73 | MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl); |
| 74 | |
| 75 | /* Local Function Prototypes */ |
| 76 | |
| 77 | int ixgb_up(struct ixgb_adapter *adapter); |
| 78 | void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog); |
| 79 | void ixgb_reset(struct ixgb_adapter *adapter); |
| 80 | int ixgb_setup_tx_resources(struct ixgb_adapter *adapter); |
| 81 | int ixgb_setup_rx_resources(struct ixgb_adapter *adapter); |
| 82 | void ixgb_free_tx_resources(struct ixgb_adapter *adapter); |
| 83 | void ixgb_free_rx_resources(struct ixgb_adapter *adapter); |
| 84 | void ixgb_update_stats(struct ixgb_adapter *adapter); |
| 85 | |
| 86 | static int ixgb_init_module(void); |
| 87 | static void ixgb_exit_module(void); |
| 88 | static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 89 | static void __devexit ixgb_remove(struct pci_dev *pdev); |
| 90 | static int ixgb_sw_init(struct ixgb_adapter *adapter); |
| 91 | static int ixgb_open(struct net_device *netdev); |
| 92 | static int ixgb_close(struct net_device *netdev); |
| 93 | static void ixgb_configure_tx(struct ixgb_adapter *adapter); |
| 94 | static void ixgb_configure_rx(struct ixgb_adapter *adapter); |
| 95 | static void ixgb_setup_rctl(struct ixgb_adapter *adapter); |
| 96 | static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter); |
| 97 | static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter); |
| 98 | static void ixgb_set_multi(struct net_device *netdev); |
| 99 | static void ixgb_watchdog(unsigned long data); |
| 100 | static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 101 | static struct net_device_stats *ixgb_get_stats(struct net_device *netdev); |
| 102 | static int ixgb_change_mtu(struct net_device *netdev, int new_mtu); |
| 103 | static int ixgb_set_mac(struct net_device *netdev, void *p); |
| 104 | static irqreturn_t ixgb_intr(int irq, void *data, struct pt_regs *regs); |
| 105 | static boolean_t ixgb_clean_tx_irq(struct ixgb_adapter *adapter); |
| 106 | #ifdef CONFIG_IXGB_NAPI |
| 107 | static int ixgb_clean(struct net_device *netdev, int *budget); |
| 108 | static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter, |
| 109 | int *work_done, int work_to_do); |
| 110 | #else |
| 111 | static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter); |
| 112 | #endif |
| 113 | static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter); |
| 114 | void ixgb_set_ethtool_ops(struct net_device *netdev); |
| 115 | static void ixgb_tx_timeout(struct net_device *dev); |
| 116 | static void ixgb_tx_timeout_task(struct net_device *dev); |
| 117 | static void ixgb_vlan_rx_register(struct net_device *netdev, |
| 118 | struct vlan_group *grp); |
| 119 | static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 120 | static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 121 | static void ixgb_restore_vlan(struct ixgb_adapter *adapter); |
| 122 | |
| 123 | static int ixgb_notify_reboot(struct notifier_block *, unsigned long event, |
| 124 | void *ptr); |
| 125 | static int ixgb_suspend(struct pci_dev *pdev, uint32_t state); |
| 126 | |
| 127 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 128 | /* for netdump / net console */ |
| 129 | static void ixgb_netpoll(struct net_device *dev); |
| 130 | #endif |
| 131 | |
| 132 | struct notifier_block ixgb_notifier_reboot = { |
| 133 | .notifier_call = ixgb_notify_reboot, |
| 134 | .next = NULL, |
| 135 | .priority = 0 |
| 136 | }; |
| 137 | |
| 138 | /* Exported from other modules */ |
| 139 | |
| 140 | extern void ixgb_check_options(struct ixgb_adapter *adapter); |
| 141 | |
| 142 | static struct pci_driver ixgb_driver = { |
| 143 | .name = ixgb_driver_name, |
| 144 | .id_table = ixgb_pci_tbl, |
| 145 | .probe = ixgb_probe, |
| 146 | .remove = __devexit_p(ixgb_remove), |
| 147 | /* Power Managment Hooks */ |
| 148 | .suspend = NULL, |
| 149 | .resume = NULL |
| 150 | }; |
| 151 | |
| 152 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 153 | MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver"); |
| 154 | MODULE_LICENSE("GPL"); |
| 155 | |
| 156 | /* some defines for controlling descriptor fetches in h/w */ |
| 157 | #define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */ |
| 158 | #define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is |
| 159 | pushed this many descriptors from head */ |
| 160 | #define RXDCTL_WTHRESH_DEFAULT 16 /* chip writes back at this many or RXT0 */ |
| 161 | |
| 162 | /** |
| 163 | * ixgb_init_module - Driver Registration Routine |
| 164 | * |
| 165 | * ixgb_init_module is the first routine called when the driver is |
| 166 | * loaded. All it does is register with the PCI subsystem. |
| 167 | **/ |
| 168 | |
| 169 | static int __init |
| 170 | ixgb_init_module(void) |
| 171 | { |
| 172 | int ret; |
| 173 | printk(KERN_INFO "%s - version %s\n", |
| 174 | ixgb_driver_string, ixgb_driver_version); |
| 175 | |
| 176 | printk(KERN_INFO "%s\n", ixgb_copyright); |
| 177 | |
| 178 | ret = pci_module_init(&ixgb_driver); |
| 179 | if(ret >= 0) { |
| 180 | register_reboot_notifier(&ixgb_notifier_reboot); |
| 181 | } |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | module_init(ixgb_init_module); |
| 186 | |
| 187 | /** |
| 188 | * ixgb_exit_module - Driver Exit Cleanup Routine |
| 189 | * |
| 190 | * ixgb_exit_module is called just before the driver is removed |
| 191 | * from memory. |
| 192 | **/ |
| 193 | |
| 194 | static void __exit |
| 195 | ixgb_exit_module(void) |
| 196 | { |
| 197 | unregister_reboot_notifier(&ixgb_notifier_reboot); |
| 198 | pci_unregister_driver(&ixgb_driver); |
| 199 | } |
| 200 | |
| 201 | module_exit(ixgb_exit_module); |
| 202 | |
| 203 | /** |
| 204 | * ixgb_irq_disable - Mask off interrupt generation on the NIC |
| 205 | * @adapter: board private structure |
| 206 | **/ |
| 207 | |
| 208 | static inline void |
| 209 | ixgb_irq_disable(struct ixgb_adapter *adapter) |
| 210 | { |
| 211 | atomic_inc(&adapter->irq_sem); |
| 212 | IXGB_WRITE_REG(&adapter->hw, IMC, ~0); |
| 213 | IXGB_WRITE_FLUSH(&adapter->hw); |
| 214 | synchronize_irq(adapter->pdev->irq); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * ixgb_irq_enable - Enable default interrupt generation settings |
| 219 | * @adapter: board private structure |
| 220 | **/ |
| 221 | |
| 222 | static inline void |
| 223 | ixgb_irq_enable(struct ixgb_adapter *adapter) |
| 224 | { |
| 225 | if(atomic_dec_and_test(&adapter->irq_sem)) { |
| 226 | IXGB_WRITE_REG(&adapter->hw, IMS, |
| 227 | IXGB_INT_RXT0 | IXGB_INT_RXDMT0 | IXGB_INT_TXDW | |
| 228 | IXGB_INT_RXO | IXGB_INT_LSC); |
| 229 | IXGB_WRITE_FLUSH(&adapter->hw); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | int |
| 234 | ixgb_up(struct ixgb_adapter *adapter) |
| 235 | { |
| 236 | struct net_device *netdev = adapter->netdev; |
| 237 | int err; |
| 238 | int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH; |
| 239 | struct ixgb_hw *hw = &adapter->hw; |
| 240 | |
| 241 | /* hardware has been reset, we need to reload some things */ |
| 242 | |
| 243 | ixgb_set_multi(netdev); |
| 244 | |
| 245 | ixgb_restore_vlan(adapter); |
| 246 | |
| 247 | ixgb_configure_tx(adapter); |
| 248 | ixgb_setup_rctl(adapter); |
| 249 | ixgb_configure_rx(adapter); |
| 250 | ixgb_alloc_rx_buffers(adapter); |
| 251 | |
| 252 | #ifdef CONFIG_PCI_MSI |
| 253 | { |
| 254 | boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) & |
| 255 | IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE; |
| 256 | adapter->have_msi = TRUE; |
| 257 | |
| 258 | if (!pcix) |
| 259 | adapter->have_msi = FALSE; |
| 260 | else if((err = pci_enable_msi(adapter->pdev))) { |
| 261 | printk (KERN_ERR |
| 262 | "Unable to allocate MSI interrupt Error: %d\n", err); |
| 263 | adapter->have_msi = FALSE; |
| 264 | /* proceed to try to request regular interrupt */ |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | #endif |
| 269 | if((err = request_irq(adapter->pdev->irq, &ixgb_intr, |
| 270 | SA_SHIRQ | SA_SAMPLE_RANDOM, |
| 271 | netdev->name, netdev))) |
| 272 | return err; |
| 273 | |
| 274 | /* disable interrupts and get the hardware into a known state */ |
| 275 | IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff); |
| 276 | |
| 277 | if((hw->max_frame_size != max_frame) || |
| 278 | (hw->max_frame_size != |
| 279 | (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) { |
| 280 | |
| 281 | hw->max_frame_size = max_frame; |
| 282 | |
| 283 | IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT); |
| 284 | |
| 285 | if(hw->max_frame_size > |
| 286 | IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) { |
| 287 | uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0); |
| 288 | |
| 289 | if(!(ctrl0 & IXGB_CTRL0_JFE)) { |
| 290 | ctrl0 |= IXGB_CTRL0_JFE; |
| 291 | IXGB_WRITE_REG(hw, CTRL0, ctrl0); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 297 | ixgb_irq_enable(adapter); |
| 298 | |
| 299 | #ifdef CONFIG_IXGB_NAPI |
| 300 | netif_poll_enable(netdev); |
| 301 | #endif |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | void |
| 306 | ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog) |
| 307 | { |
| 308 | struct net_device *netdev = adapter->netdev; |
| 309 | |
| 310 | ixgb_irq_disable(adapter); |
| 311 | free_irq(adapter->pdev->irq, netdev); |
| 312 | #ifdef CONFIG_PCI_MSI |
| 313 | if(adapter->have_msi == TRUE) |
| 314 | pci_disable_msi(adapter->pdev); |
| 315 | |
| 316 | #endif |
| 317 | if(kill_watchdog) |
| 318 | del_timer_sync(&adapter->watchdog_timer); |
| 319 | #ifdef CONFIG_IXGB_NAPI |
| 320 | netif_poll_disable(netdev); |
| 321 | #endif |
| 322 | adapter->link_speed = 0; |
| 323 | adapter->link_duplex = 0; |
| 324 | netif_carrier_off(netdev); |
| 325 | netif_stop_queue(netdev); |
| 326 | |
| 327 | ixgb_reset(adapter); |
| 328 | ixgb_clean_tx_ring(adapter); |
| 329 | ixgb_clean_rx_ring(adapter); |
| 330 | } |
| 331 | |
| 332 | void |
| 333 | ixgb_reset(struct ixgb_adapter *adapter) |
| 334 | { |
| 335 | |
| 336 | ixgb_adapter_stop(&adapter->hw); |
| 337 | if(!ixgb_init_hw(&adapter->hw)) |
| 338 | IXGB_DBG("ixgb_init_hw failed.\n"); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * ixgb_probe - Device Initialization Routine |
| 343 | * @pdev: PCI device information struct |
| 344 | * @ent: entry in ixgb_pci_tbl |
| 345 | * |
| 346 | * Returns 0 on success, negative on failure |
| 347 | * |
| 348 | * ixgb_probe initializes an adapter identified by a pci_dev structure. |
| 349 | * The OS initialization, configuring of the adapter private structure, |
| 350 | * and a hardware reset occur. |
| 351 | **/ |
| 352 | |
| 353 | static int __devinit |
| 354 | ixgb_probe(struct pci_dev *pdev, |
| 355 | const struct pci_device_id *ent) |
| 356 | { |
| 357 | struct net_device *netdev = NULL; |
| 358 | struct ixgb_adapter *adapter; |
| 359 | static int cards_found = 0; |
| 360 | unsigned long mmio_start; |
| 361 | int mmio_len; |
| 362 | int pci_using_dac; |
| 363 | int i; |
| 364 | int err; |
| 365 | |
| 366 | if((err = pci_enable_device(pdev))) |
| 367 | return err; |
| 368 | |
| 369 | if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { |
| 370 | pci_using_dac = 1; |
| 371 | } else { |
| 372 | if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { |
| 373 | IXGB_ERR("No usable DMA configuration, aborting\n"); |
| 374 | return err; |
| 375 | } |
| 376 | pci_using_dac = 0; |
| 377 | } |
| 378 | |
| 379 | if((err = pci_request_regions(pdev, ixgb_driver_name))) |
| 380 | return err; |
| 381 | |
| 382 | pci_set_master(pdev); |
| 383 | |
| 384 | netdev = alloc_etherdev(sizeof(struct ixgb_adapter)); |
| 385 | if(!netdev) { |
| 386 | err = -ENOMEM; |
| 387 | goto err_alloc_etherdev; |
| 388 | } |
| 389 | |
| 390 | SET_MODULE_OWNER(netdev); |
| 391 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 392 | |
| 393 | pci_set_drvdata(pdev, netdev); |
| 394 | adapter = netdev->priv; |
| 395 | adapter->netdev = netdev; |
| 396 | adapter->pdev = pdev; |
| 397 | adapter->hw.back = adapter; |
| 398 | |
| 399 | mmio_start = pci_resource_start(pdev, BAR_0); |
| 400 | mmio_len = pci_resource_len(pdev, BAR_0); |
| 401 | |
| 402 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
| 403 | if(!adapter->hw.hw_addr) { |
| 404 | err = -EIO; |
| 405 | goto err_ioremap; |
| 406 | } |
| 407 | |
| 408 | for(i = BAR_1; i <= BAR_5; i++) { |
| 409 | if(pci_resource_len(pdev, i) == 0) |
| 410 | continue; |
| 411 | if(pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 412 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | netdev->open = &ixgb_open; |
| 418 | netdev->stop = &ixgb_close; |
| 419 | netdev->hard_start_xmit = &ixgb_xmit_frame; |
| 420 | netdev->get_stats = &ixgb_get_stats; |
| 421 | netdev->set_multicast_list = &ixgb_set_multi; |
| 422 | netdev->set_mac_address = &ixgb_set_mac; |
| 423 | netdev->change_mtu = &ixgb_change_mtu; |
| 424 | ixgb_set_ethtool_ops(netdev); |
| 425 | netdev->tx_timeout = &ixgb_tx_timeout; |
| 426 | netdev->watchdog_timeo = HZ; |
| 427 | #ifdef CONFIG_IXGB_NAPI |
| 428 | netdev->poll = &ixgb_clean; |
| 429 | netdev->weight = 64; |
| 430 | #endif |
| 431 | netdev->vlan_rx_register = ixgb_vlan_rx_register; |
| 432 | netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid; |
| 433 | netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid; |
| 434 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 435 | netdev->poll_controller = ixgb_netpoll; |
| 436 | #endif |
| 437 | |
| 438 | netdev->mem_start = mmio_start; |
| 439 | netdev->mem_end = mmio_start + mmio_len; |
| 440 | netdev->base_addr = adapter->hw.io_base; |
| 441 | |
| 442 | adapter->bd_number = cards_found; |
| 443 | adapter->link_speed = 0; |
| 444 | adapter->link_duplex = 0; |
| 445 | |
| 446 | /* setup the private structure */ |
| 447 | |
| 448 | if((err = ixgb_sw_init(adapter))) |
| 449 | goto err_sw_init; |
| 450 | |
| 451 | netdev->features = NETIF_F_SG | |
| 452 | NETIF_F_HW_CSUM | |
| 453 | NETIF_F_HW_VLAN_TX | |
| 454 | NETIF_F_HW_VLAN_RX | |
| 455 | NETIF_F_HW_VLAN_FILTER; |
| 456 | #ifdef NETIF_F_TSO |
| 457 | netdev->features |= NETIF_F_TSO; |
| 458 | #endif |
| 459 | |
| 460 | if(pci_using_dac) |
| 461 | netdev->features |= NETIF_F_HIGHDMA; |
| 462 | |
| 463 | /* make sure the EEPROM is good */ |
| 464 | |
| 465 | if(!ixgb_validate_eeprom_checksum(&adapter->hw)) { |
| 466 | printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n"); |
| 467 | err = -EIO; |
| 468 | goto err_eeprom; |
| 469 | } |
| 470 | |
| 471 | ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr); |
| 472 | |
| 473 | if(!is_valid_ether_addr(netdev->dev_addr)) { |
| 474 | err = -EIO; |
| 475 | goto err_eeprom; |
| 476 | } |
| 477 | |
| 478 | adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw); |
| 479 | |
| 480 | init_timer(&adapter->watchdog_timer); |
| 481 | adapter->watchdog_timer.function = &ixgb_watchdog; |
| 482 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 483 | |
| 484 | INIT_WORK(&adapter->tx_timeout_task, |
| 485 | (void (*)(void *))ixgb_tx_timeout_task, netdev); |
| 486 | |
| 487 | if((err = register_netdev(netdev))) |
| 488 | goto err_register; |
| 489 | |
| 490 | /* we're going to reset, so assume we have no link for now */ |
| 491 | |
| 492 | netif_carrier_off(netdev); |
| 493 | netif_stop_queue(netdev); |
| 494 | |
| 495 | printk(KERN_INFO "%s: Intel(R) PRO/10GbE Network Connection\n", |
| 496 | netdev->name); |
| 497 | ixgb_check_options(adapter); |
| 498 | /* reset the hardware with the new settings */ |
| 499 | |
| 500 | ixgb_reset(adapter); |
| 501 | |
| 502 | cards_found++; |
| 503 | return 0; |
| 504 | |
| 505 | err_register: |
| 506 | err_sw_init: |
| 507 | err_eeprom: |
| 508 | iounmap(adapter->hw.hw_addr); |
| 509 | err_ioremap: |
| 510 | free_netdev(netdev); |
| 511 | err_alloc_etherdev: |
| 512 | pci_release_regions(pdev); |
| 513 | return err; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * ixgb_remove - Device Removal Routine |
| 518 | * @pdev: PCI device information struct |
| 519 | * |
| 520 | * ixgb_remove is called by the PCI subsystem to alert the driver |
| 521 | * that it should release a PCI device. The could be caused by a |
| 522 | * Hot-Plug event, or because the driver is going to be removed from |
| 523 | * memory. |
| 524 | **/ |
| 525 | |
| 526 | static void __devexit |
| 527 | ixgb_remove(struct pci_dev *pdev) |
| 528 | { |
| 529 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 530 | struct ixgb_adapter *adapter = netdev->priv; |
| 531 | |
| 532 | unregister_netdev(netdev); |
| 533 | |
| 534 | iounmap(adapter->hw.hw_addr); |
| 535 | pci_release_regions(pdev); |
| 536 | |
| 537 | free_netdev(netdev); |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter) |
| 542 | * @adapter: board private structure to initialize |
| 543 | * |
| 544 | * ixgb_sw_init initializes the Adapter private data structure. |
| 545 | * Fields are initialized based on PCI device information and |
| 546 | * OS network device settings (MTU size). |
| 547 | **/ |
| 548 | |
| 549 | static int __devinit |
| 550 | ixgb_sw_init(struct ixgb_adapter *adapter) |
| 551 | { |
| 552 | struct ixgb_hw *hw = &adapter->hw; |
| 553 | struct net_device *netdev = adapter->netdev; |
| 554 | struct pci_dev *pdev = adapter->pdev; |
| 555 | |
| 556 | /* PCI config space info */ |
| 557 | |
| 558 | hw->vendor_id = pdev->vendor; |
| 559 | hw->device_id = pdev->device; |
| 560 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 561 | hw->subsystem_id = pdev->subsystem_device; |
| 562 | |
| 563 | adapter->rx_buffer_len = IXGB_RXBUFFER_2048; |
| 564 | |
| 565 | hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH; |
| 566 | |
| 567 | if((hw->device_id == IXGB_DEVICE_ID_82597EX) |
| 568 | ||(hw->device_id == IXGB_DEVICE_ID_82597EX_LR) |
| 569 | ||(hw->device_id == IXGB_DEVICE_ID_82597EX_SR)) |
| 570 | hw->mac_type = ixgb_82597; |
| 571 | else { |
| 572 | /* should never have loaded on this device */ |
| 573 | printk(KERN_ERR "ixgb: unsupported device id\n"); |
| 574 | } |
| 575 | |
| 576 | /* enable flow control to be programmed */ |
| 577 | hw->fc.send_xon = 1; |
| 578 | |
| 579 | atomic_set(&adapter->irq_sem, 1); |
| 580 | spin_lock_init(&adapter->tx_lock); |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * ixgb_open - Called when a network interface is made active |
| 587 | * @netdev: network interface device structure |
| 588 | * |
| 589 | * Returns 0 on success, negative value on failure |
| 590 | * |
| 591 | * The open entry point is called when a network interface is made |
| 592 | * active by the system (IFF_UP). At this point all resources needed |
| 593 | * for transmit and receive operations are allocated, the interrupt |
| 594 | * handler is registered with the OS, the watchdog timer is started, |
| 595 | * and the stack is notified that the interface is ready. |
| 596 | **/ |
| 597 | |
| 598 | static int |
| 599 | ixgb_open(struct net_device *netdev) |
| 600 | { |
| 601 | struct ixgb_adapter *adapter = netdev->priv; |
| 602 | int err; |
| 603 | |
| 604 | /* allocate transmit descriptors */ |
| 605 | |
| 606 | if((err = ixgb_setup_tx_resources(adapter))) |
| 607 | goto err_setup_tx; |
| 608 | |
| 609 | /* allocate receive descriptors */ |
| 610 | |
| 611 | if((err = ixgb_setup_rx_resources(adapter))) |
| 612 | goto err_setup_rx; |
| 613 | |
| 614 | if((err = ixgb_up(adapter))) |
| 615 | goto err_up; |
| 616 | |
| 617 | return 0; |
| 618 | |
| 619 | err_up: |
| 620 | ixgb_free_rx_resources(adapter); |
| 621 | err_setup_rx: |
| 622 | ixgb_free_tx_resources(adapter); |
| 623 | err_setup_tx: |
| 624 | ixgb_reset(adapter); |
| 625 | |
| 626 | return err; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * ixgb_close - Disables a network interface |
| 631 | * @netdev: network interface device structure |
| 632 | * |
| 633 | * Returns 0, this is not allowed to fail |
| 634 | * |
| 635 | * The close entry point is called when an interface is de-activated |
| 636 | * by the OS. The hardware is still under the drivers control, but |
| 637 | * needs to be disabled. A global MAC reset is issued to stop the |
| 638 | * hardware, and all transmit and receive resources are freed. |
| 639 | **/ |
| 640 | |
| 641 | static int |
| 642 | ixgb_close(struct net_device *netdev) |
| 643 | { |
| 644 | struct ixgb_adapter *adapter = netdev->priv; |
| 645 | |
| 646 | ixgb_down(adapter, TRUE); |
| 647 | |
| 648 | ixgb_free_tx_resources(adapter); |
| 649 | ixgb_free_rx_resources(adapter); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * ixgb_setup_tx_resources - allocate Tx resources (Descriptors) |
| 656 | * @adapter: board private structure |
| 657 | * |
| 658 | * Return 0 on success, negative on failure |
| 659 | **/ |
| 660 | |
| 661 | int |
| 662 | ixgb_setup_tx_resources(struct ixgb_adapter *adapter) |
| 663 | { |
| 664 | struct ixgb_desc_ring *txdr = &adapter->tx_ring; |
| 665 | struct pci_dev *pdev = adapter->pdev; |
| 666 | int size; |
| 667 | |
| 668 | size = sizeof(struct ixgb_buffer) * txdr->count; |
| 669 | txdr->buffer_info = vmalloc(size); |
| 670 | if(!txdr->buffer_info) { |
| 671 | return -ENOMEM; |
| 672 | } |
| 673 | memset(txdr->buffer_info, 0, size); |
| 674 | |
| 675 | /* round up to nearest 4K */ |
| 676 | |
| 677 | txdr->size = txdr->count * sizeof(struct ixgb_tx_desc); |
| 678 | IXGB_ROUNDUP(txdr->size, 4096); |
| 679 | |
| 680 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
| 681 | if(!txdr->desc) { |
| 682 | vfree(txdr->buffer_info); |
| 683 | return -ENOMEM; |
| 684 | } |
| 685 | memset(txdr->desc, 0, txdr->size); |
| 686 | |
| 687 | txdr->next_to_use = 0; |
| 688 | txdr->next_to_clean = 0; |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset. |
| 695 | * @adapter: board private structure |
| 696 | * |
| 697 | * Configure the Tx unit of the MAC after a reset. |
| 698 | **/ |
| 699 | |
| 700 | static void |
| 701 | ixgb_configure_tx(struct ixgb_adapter *adapter) |
| 702 | { |
| 703 | uint64_t tdba = adapter->tx_ring.dma; |
| 704 | uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc); |
| 705 | uint32_t tctl; |
| 706 | struct ixgb_hw *hw = &adapter->hw; |
| 707 | |
| 708 | /* Setup the Base and Length of the Tx Descriptor Ring |
| 709 | * tx_ring.dma can be either a 32 or 64 bit value |
| 710 | */ |
| 711 | |
| 712 | IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 713 | IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 714 | |
| 715 | IXGB_WRITE_REG(hw, TDLEN, tdlen); |
| 716 | |
| 717 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 718 | |
| 719 | IXGB_WRITE_REG(hw, TDH, 0); |
| 720 | IXGB_WRITE_REG(hw, TDT, 0); |
| 721 | |
| 722 | /* don't set up txdctl, it induces performance problems if configured |
| 723 | * incorrectly */ |
| 724 | /* Set the Tx Interrupt Delay register */ |
| 725 | |
| 726 | IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 727 | |
| 728 | /* Program the Transmit Control Register */ |
| 729 | |
| 730 | tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE; |
| 731 | IXGB_WRITE_REG(hw, TCTL, tctl); |
| 732 | |
| 733 | /* Setup Transmit Descriptor Settings for this adapter */ |
| 734 | adapter->tx_cmd_type = |
| 735 | IXGB_TX_DESC_TYPE |
| 736 | | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0); |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * ixgb_setup_rx_resources - allocate Rx resources (Descriptors) |
| 741 | * @adapter: board private structure |
| 742 | * |
| 743 | * Returns 0 on success, negative on failure |
| 744 | **/ |
| 745 | |
| 746 | int |
| 747 | ixgb_setup_rx_resources(struct ixgb_adapter *adapter) |
| 748 | { |
| 749 | struct ixgb_desc_ring *rxdr = &adapter->rx_ring; |
| 750 | struct pci_dev *pdev = adapter->pdev; |
| 751 | int size; |
| 752 | |
| 753 | size = sizeof(struct ixgb_buffer) * rxdr->count; |
| 754 | rxdr->buffer_info = vmalloc(size); |
| 755 | if(!rxdr->buffer_info) { |
| 756 | return -ENOMEM; |
| 757 | } |
| 758 | memset(rxdr->buffer_info, 0, size); |
| 759 | |
| 760 | /* Round up to nearest 4K */ |
| 761 | |
| 762 | rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc); |
| 763 | IXGB_ROUNDUP(rxdr->size, 4096); |
| 764 | |
| 765 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 766 | |
| 767 | if(!rxdr->desc) { |
| 768 | vfree(rxdr->buffer_info); |
| 769 | return -ENOMEM; |
| 770 | } |
| 771 | memset(rxdr->desc, 0, rxdr->size); |
| 772 | |
| 773 | rxdr->next_to_clean = 0; |
| 774 | rxdr->next_to_use = 0; |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * ixgb_setup_rctl - configure the receive control register |
| 781 | * @adapter: Board private structure |
| 782 | **/ |
| 783 | |
| 784 | static void |
| 785 | ixgb_setup_rctl(struct ixgb_adapter *adapter) |
| 786 | { |
| 787 | uint32_t rctl; |
| 788 | |
| 789 | rctl = IXGB_READ_REG(&adapter->hw, RCTL); |
| 790 | |
| 791 | rctl &= ~(3 << IXGB_RCTL_MO_SHIFT); |
| 792 | |
| 793 | rctl |= |
| 794 | IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | |
| 795 | IXGB_RCTL_RXEN | IXGB_RCTL_CFF | |
| 796 | (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT); |
| 797 | |
| 798 | rctl |= IXGB_RCTL_SECRC; |
| 799 | |
| 800 | switch (adapter->rx_buffer_len) { |
| 801 | case IXGB_RXBUFFER_2048: |
| 802 | default: |
| 803 | rctl |= IXGB_RCTL_BSIZE_2048; |
| 804 | break; |
| 805 | case IXGB_RXBUFFER_4096: |
| 806 | rctl |= IXGB_RCTL_BSIZE_4096; |
| 807 | break; |
| 808 | case IXGB_RXBUFFER_8192: |
| 809 | rctl |= IXGB_RCTL_BSIZE_8192; |
| 810 | break; |
| 811 | case IXGB_RXBUFFER_16384: |
| 812 | rctl |= IXGB_RCTL_BSIZE_16384; |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | IXGB_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * ixgb_configure_rx - Configure 82597 Receive Unit after Reset. |
| 821 | * @adapter: board private structure |
| 822 | * |
| 823 | * Configure the Rx unit of the MAC after a reset. |
| 824 | **/ |
| 825 | |
| 826 | static void |
| 827 | ixgb_configure_rx(struct ixgb_adapter *adapter) |
| 828 | { |
| 829 | uint64_t rdba = adapter->rx_ring.dma; |
| 830 | uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc); |
| 831 | struct ixgb_hw *hw = &adapter->hw; |
| 832 | uint32_t rctl; |
| 833 | uint32_t rxcsum; |
| 834 | uint32_t rxdctl; |
| 835 | |
| 836 | /* make sure receives are disabled while setting up the descriptors */ |
| 837 | |
| 838 | rctl = IXGB_READ_REG(hw, RCTL); |
| 839 | IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN); |
| 840 | |
| 841 | /* set the Receive Delay Timer Register */ |
| 842 | |
| 843 | IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
| 844 | |
| 845 | /* Setup the Base and Length of the Rx Descriptor Ring */ |
| 846 | |
| 847 | IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 848 | IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 849 | |
| 850 | IXGB_WRITE_REG(hw, RDLEN, rdlen); |
| 851 | |
| 852 | /* Setup the HW Rx Head and Tail Descriptor Pointers */ |
| 853 | IXGB_WRITE_REG(hw, RDH, 0); |
| 854 | IXGB_WRITE_REG(hw, RDT, 0); |
| 855 | |
| 856 | /* set up pre-fetching of receive buffers so we get some before we |
| 857 | * run out (default hardware behavior is to run out before fetching |
| 858 | * more). This sets up to fetch if HTHRESH rx descriptors are avail |
| 859 | * and the descriptors in hw cache are below PTHRESH. This avoids |
| 860 | * the hardware behavior of fetching <=512 descriptors in a single |
| 861 | * burst that pre-empts all other activity, usually causing fifo |
| 862 | * overflows. */ |
| 863 | /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */ |
| 864 | rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT | |
| 865 | RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT | |
| 866 | RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT; |
| 867 | IXGB_WRITE_REG(hw, RXDCTL, rxdctl); |
| 868 | |
| 869 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 870 | if(adapter->rx_csum == TRUE) { |
| 871 | rxcsum = IXGB_READ_REG(hw, RXCSUM); |
| 872 | rxcsum |= IXGB_RXCSUM_TUOFL; |
| 873 | IXGB_WRITE_REG(hw, RXCSUM, rxcsum); |
| 874 | } |
| 875 | |
| 876 | /* Enable Receives */ |
| 877 | |
| 878 | IXGB_WRITE_REG(hw, RCTL, rctl); |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * ixgb_free_tx_resources - Free Tx Resources |
| 883 | * @adapter: board private structure |
| 884 | * |
| 885 | * Free all transmit software resources |
| 886 | **/ |
| 887 | |
| 888 | void |
| 889 | ixgb_free_tx_resources(struct ixgb_adapter *adapter) |
| 890 | { |
| 891 | struct pci_dev *pdev = adapter->pdev; |
| 892 | |
| 893 | ixgb_clean_tx_ring(adapter); |
| 894 | |
| 895 | vfree(adapter->tx_ring.buffer_info); |
| 896 | adapter->tx_ring.buffer_info = NULL; |
| 897 | |
| 898 | pci_free_consistent(pdev, adapter->tx_ring.size, |
| 899 | adapter->tx_ring.desc, adapter->tx_ring.dma); |
| 900 | |
| 901 | adapter->tx_ring.desc = NULL; |
| 902 | } |
| 903 | |
| 904 | static inline void |
| 905 | ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter, |
| 906 | struct ixgb_buffer *buffer_info) |
| 907 | { |
| 908 | struct pci_dev *pdev = adapter->pdev; |
| 909 | if(buffer_info->dma) { |
| 910 | pci_unmap_page(pdev, |
| 911 | buffer_info->dma, |
| 912 | buffer_info->length, |
| 913 | PCI_DMA_TODEVICE); |
| 914 | buffer_info->dma = 0; |
| 915 | } |
| 916 | if(buffer_info->skb) { |
| 917 | dev_kfree_skb_any(buffer_info->skb); |
| 918 | buffer_info->skb = NULL; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * ixgb_clean_tx_ring - Free Tx Buffers |
| 924 | * @adapter: board private structure |
| 925 | **/ |
| 926 | |
| 927 | static void |
| 928 | ixgb_clean_tx_ring(struct ixgb_adapter *adapter) |
| 929 | { |
| 930 | struct ixgb_desc_ring *tx_ring = &adapter->tx_ring; |
| 931 | struct ixgb_buffer *buffer_info; |
| 932 | unsigned long size; |
| 933 | unsigned int i; |
| 934 | |
| 935 | /* Free all the Tx ring sk_buffs */ |
| 936 | |
| 937 | for(i = 0; i < tx_ring->count; i++) { |
| 938 | buffer_info = &tx_ring->buffer_info[i]; |
| 939 | ixgb_unmap_and_free_tx_resource(adapter, buffer_info); |
| 940 | } |
| 941 | |
| 942 | size = sizeof(struct ixgb_buffer) * tx_ring->count; |
| 943 | memset(tx_ring->buffer_info, 0, size); |
| 944 | |
| 945 | /* Zero out the descriptor ring */ |
| 946 | |
| 947 | memset(tx_ring->desc, 0, tx_ring->size); |
| 948 | |
| 949 | tx_ring->next_to_use = 0; |
| 950 | tx_ring->next_to_clean = 0; |
| 951 | |
| 952 | IXGB_WRITE_REG(&adapter->hw, TDH, 0); |
| 953 | IXGB_WRITE_REG(&adapter->hw, TDT, 0); |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * ixgb_free_rx_resources - Free Rx Resources |
| 958 | * @adapter: board private structure |
| 959 | * |
| 960 | * Free all receive software resources |
| 961 | **/ |
| 962 | |
| 963 | void |
| 964 | ixgb_free_rx_resources(struct ixgb_adapter *adapter) |
| 965 | { |
| 966 | struct ixgb_desc_ring *rx_ring = &adapter->rx_ring; |
| 967 | struct pci_dev *pdev = adapter->pdev; |
| 968 | |
| 969 | ixgb_clean_rx_ring(adapter); |
| 970 | |
| 971 | vfree(rx_ring->buffer_info); |
| 972 | rx_ring->buffer_info = NULL; |
| 973 | |
| 974 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 975 | |
| 976 | rx_ring->desc = NULL; |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * ixgb_clean_rx_ring - Free Rx Buffers |
| 981 | * @adapter: board private structure |
| 982 | **/ |
| 983 | |
| 984 | static void |
| 985 | ixgb_clean_rx_ring(struct ixgb_adapter *adapter) |
| 986 | { |
| 987 | struct ixgb_desc_ring *rx_ring = &adapter->rx_ring; |
| 988 | struct ixgb_buffer *buffer_info; |
| 989 | struct pci_dev *pdev = adapter->pdev; |
| 990 | unsigned long size; |
| 991 | unsigned int i; |
| 992 | |
| 993 | /* Free all the Rx ring sk_buffs */ |
| 994 | |
| 995 | for(i = 0; i < rx_ring->count; i++) { |
| 996 | buffer_info = &rx_ring->buffer_info[i]; |
| 997 | if(buffer_info->skb) { |
| 998 | |
| 999 | pci_unmap_single(pdev, |
| 1000 | buffer_info->dma, |
| 1001 | buffer_info->length, |
| 1002 | PCI_DMA_FROMDEVICE); |
| 1003 | |
| 1004 | dev_kfree_skb(buffer_info->skb); |
| 1005 | |
| 1006 | buffer_info->skb = NULL; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | size = sizeof(struct ixgb_buffer) * rx_ring->count; |
| 1011 | memset(rx_ring->buffer_info, 0, size); |
| 1012 | |
| 1013 | /* Zero out the descriptor ring */ |
| 1014 | |
| 1015 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1016 | |
| 1017 | rx_ring->next_to_clean = 0; |
| 1018 | rx_ring->next_to_use = 0; |
| 1019 | |
| 1020 | IXGB_WRITE_REG(&adapter->hw, RDH, 0); |
| 1021 | IXGB_WRITE_REG(&adapter->hw, RDT, 0); |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * ixgb_set_mac - Change the Ethernet Address of the NIC |
| 1026 | * @netdev: network interface device structure |
| 1027 | * @p: pointer to an address structure |
| 1028 | * |
| 1029 | * Returns 0 on success, negative on failure |
| 1030 | **/ |
| 1031 | |
| 1032 | static int |
| 1033 | ixgb_set_mac(struct net_device *netdev, void *p) |
| 1034 | { |
| 1035 | struct ixgb_adapter *adapter = netdev->priv; |
| 1036 | struct sockaddr *addr = p; |
| 1037 | |
| 1038 | if(!is_valid_ether_addr(addr->sa_data)) |
| 1039 | return -EADDRNOTAVAIL; |
| 1040 | |
| 1041 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 1042 | |
| 1043 | ixgb_rar_set(&adapter->hw, addr->sa_data, 0); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * ixgb_set_multi - Multicast and Promiscuous mode set |
| 1050 | * @netdev: network interface device structure |
| 1051 | * |
| 1052 | * The set_multi entry point is called whenever the multicast address |
| 1053 | * list or the network interface flags are updated. This routine is |
| 1054 | * responsible for configuring the hardware for proper multicast, |
| 1055 | * promiscuous mode, and all-multi behavior. |
| 1056 | **/ |
| 1057 | |
| 1058 | static void |
| 1059 | ixgb_set_multi(struct net_device *netdev) |
| 1060 | { |
| 1061 | struct ixgb_adapter *adapter = netdev->priv; |
| 1062 | struct ixgb_hw *hw = &adapter->hw; |
| 1063 | struct dev_mc_list *mc_ptr; |
| 1064 | uint32_t rctl; |
| 1065 | int i; |
| 1066 | |
| 1067 | /* Check for Promiscuous and All Multicast modes */ |
| 1068 | |
| 1069 | rctl = IXGB_READ_REG(hw, RCTL); |
| 1070 | |
| 1071 | if(netdev->flags & IFF_PROMISC) { |
| 1072 | rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE); |
| 1073 | } else if(netdev->flags & IFF_ALLMULTI) { |
| 1074 | rctl |= IXGB_RCTL_MPE; |
| 1075 | rctl &= ~IXGB_RCTL_UPE; |
| 1076 | } else { |
| 1077 | rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE); |
| 1078 | } |
| 1079 | |
| 1080 | if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) { |
| 1081 | rctl |= IXGB_RCTL_MPE; |
| 1082 | IXGB_WRITE_REG(hw, RCTL, rctl); |
| 1083 | } else { |
| 1084 | uint8_t mta[netdev->mc_count * IXGB_ETH_LENGTH_OF_ADDRESS]; |
| 1085 | |
| 1086 | IXGB_WRITE_REG(hw, RCTL, rctl); |
| 1087 | |
| 1088 | for(i = 0, mc_ptr = netdev->mc_list; mc_ptr; |
| 1089 | i++, mc_ptr = mc_ptr->next) |
| 1090 | memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS], |
| 1091 | mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS); |
| 1092 | |
| 1093 | ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * ixgb_watchdog - Timer Call-back |
| 1099 | * @data: pointer to netdev cast into an unsigned long |
| 1100 | **/ |
| 1101 | |
| 1102 | static void |
| 1103 | ixgb_watchdog(unsigned long data) |
| 1104 | { |
| 1105 | struct ixgb_adapter *adapter = (struct ixgb_adapter *)data; |
| 1106 | struct net_device *netdev = adapter->netdev; |
| 1107 | struct ixgb_desc_ring *txdr = &adapter->tx_ring; |
| 1108 | |
| 1109 | ixgb_check_for_link(&adapter->hw); |
| 1110 | |
| 1111 | if (ixgb_check_for_bad_link(&adapter->hw)) { |
| 1112 | /* force the reset path */ |
| 1113 | netif_stop_queue(netdev); |
| 1114 | } |
| 1115 | |
| 1116 | if(adapter->hw.link_up) { |
| 1117 | if(!netif_carrier_ok(netdev)) { |
| 1118 | printk(KERN_INFO "ixgb: %s NIC Link is Up %d Mbps %s\n", |
| 1119 | netdev->name, 10000, "Full Duplex"); |
| 1120 | adapter->link_speed = 10000; |
| 1121 | adapter->link_duplex = FULL_DUPLEX; |
| 1122 | netif_carrier_on(netdev); |
| 1123 | netif_wake_queue(netdev); |
| 1124 | } |
| 1125 | } else { |
| 1126 | if(netif_carrier_ok(netdev)) { |
| 1127 | adapter->link_speed = 0; |
| 1128 | adapter->link_duplex = 0; |
| 1129 | printk(KERN_INFO |
| 1130 | "ixgb: %s NIC Link is Down\n", |
| 1131 | netdev->name); |
| 1132 | netif_carrier_off(netdev); |
| 1133 | netif_stop_queue(netdev); |
| 1134 | |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | ixgb_update_stats(adapter); |
| 1139 | |
| 1140 | if(!netif_carrier_ok(netdev)) { |
| 1141 | if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) { |
| 1142 | /* We've lost link, so the controller stops DMA, |
| 1143 | * but we've got queued Tx work that's never going |
| 1144 | * to get done, so reset controller to flush Tx. |
| 1145 | * (Do the reset outside of interrupt context). */ |
| 1146 | schedule_work(&adapter->tx_timeout_task); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | /* Force detection of hung controller every watchdog period */ |
| 1151 | adapter->detect_tx_hung = TRUE; |
| 1152 | |
| 1153 | /* generate an interrupt to force clean up of any stragglers */ |
| 1154 | IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW); |
| 1155 | |
| 1156 | /* Reset the timer */ |
| 1157 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1158 | } |
| 1159 | |
| 1160 | #define IXGB_TX_FLAGS_CSUM 0x00000001 |
| 1161 | #define IXGB_TX_FLAGS_VLAN 0x00000002 |
| 1162 | #define IXGB_TX_FLAGS_TSO 0x00000004 |
| 1163 | |
| 1164 | static inline int |
| 1165 | ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb) |
| 1166 | { |
| 1167 | #ifdef NETIF_F_TSO |
| 1168 | struct ixgb_context_desc *context_desc; |
| 1169 | unsigned int i; |
| 1170 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 1171 | uint16_t ipcse, tucse, mss; |
| 1172 | int err; |
| 1173 | |
| 1174 | if(likely(skb_shinfo(skb)->tso_size)) { |
| 1175 | if (skb_header_cloned(skb)) { |
| 1176 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 1177 | if (err) |
| 1178 | return err; |
| 1179 | } |
| 1180 | |
| 1181 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
| 1182 | mss = skb_shinfo(skb)->tso_size; |
| 1183 | skb->nh.iph->tot_len = 0; |
| 1184 | skb->nh.iph->check = 0; |
| 1185 | skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr, |
| 1186 | skb->nh.iph->daddr, |
| 1187 | 0, IPPROTO_TCP, 0); |
| 1188 | ipcss = skb->nh.raw - skb->data; |
| 1189 | ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; |
| 1190 | ipcse = skb->h.raw - skb->data - 1; |
| 1191 | tucss = skb->h.raw - skb->data; |
| 1192 | tucso = (void *)&(skb->h.th->check) - (void *)skb->data; |
| 1193 | tucse = 0; |
| 1194 | |
| 1195 | i = adapter->tx_ring.next_to_use; |
| 1196 | context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i); |
| 1197 | |
| 1198 | context_desc->ipcss = ipcss; |
| 1199 | context_desc->ipcso = ipcso; |
| 1200 | context_desc->ipcse = cpu_to_le16(ipcse); |
| 1201 | context_desc->tucss = tucss; |
| 1202 | context_desc->tucso = tucso; |
| 1203 | context_desc->tucse = cpu_to_le16(tucse); |
| 1204 | context_desc->mss = cpu_to_le16(mss); |
| 1205 | context_desc->hdr_len = hdr_len; |
| 1206 | context_desc->status = 0; |
| 1207 | context_desc->cmd_type_len = cpu_to_le32( |
| 1208 | IXGB_CONTEXT_DESC_TYPE |
| 1209 | | IXGB_CONTEXT_DESC_CMD_TSE |
| 1210 | | IXGB_CONTEXT_DESC_CMD_IP |
| 1211 | | IXGB_CONTEXT_DESC_CMD_TCP |
| 1212 | | IXGB_CONTEXT_DESC_CMD_RS |
| 1213 | | IXGB_CONTEXT_DESC_CMD_IDE |
| 1214 | | (skb->len - (hdr_len))); |
| 1215 | |
| 1216 | if(++i == adapter->tx_ring.count) i = 0; |
| 1217 | adapter->tx_ring.next_to_use = i; |
| 1218 | |
| 1219 | return 1; |
| 1220 | } |
| 1221 | #endif |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static inline boolean_t |
| 1227 | ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb) |
| 1228 | { |
| 1229 | struct ixgb_context_desc *context_desc; |
| 1230 | unsigned int i; |
| 1231 | uint8_t css, cso; |
| 1232 | |
| 1233 | if(likely(skb->ip_summed == CHECKSUM_HW)) { |
| 1234 | css = skb->h.raw - skb->data; |
| 1235 | cso = (skb->h.raw + skb->csum) - skb->data; |
| 1236 | |
| 1237 | i = adapter->tx_ring.next_to_use; |
| 1238 | context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i); |
| 1239 | |
| 1240 | context_desc->tucss = css; |
| 1241 | context_desc->tucso = cso; |
| 1242 | context_desc->tucse = 0; |
| 1243 | /* zero out any previously existing data in one instruction */ |
| 1244 | *(uint32_t *)&(context_desc->ipcss) = 0; |
| 1245 | context_desc->status = 0; |
| 1246 | context_desc->hdr_len = 0; |
| 1247 | context_desc->mss = 0; |
| 1248 | context_desc->cmd_type_len = |
| 1249 | cpu_to_le32(IXGB_CONTEXT_DESC_TYPE |
| 1250 | | IXGB_TX_DESC_CMD_RS |
| 1251 | | IXGB_TX_DESC_CMD_IDE); |
| 1252 | |
| 1253 | if(++i == adapter->tx_ring.count) i = 0; |
| 1254 | adapter->tx_ring.next_to_use = i; |
| 1255 | |
| 1256 | return TRUE; |
| 1257 | } |
| 1258 | |
| 1259 | return FALSE; |
| 1260 | } |
| 1261 | |
| 1262 | #define IXGB_MAX_TXD_PWR 14 |
| 1263 | #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR) |
| 1264 | |
| 1265 | static inline int |
| 1266 | ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb, |
| 1267 | unsigned int first) |
| 1268 | { |
| 1269 | struct ixgb_desc_ring *tx_ring = &adapter->tx_ring; |
| 1270 | struct ixgb_buffer *buffer_info; |
| 1271 | int len = skb->len; |
| 1272 | unsigned int offset = 0, size, count = 0, i; |
| 1273 | |
| 1274 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 1275 | unsigned int f; |
| 1276 | len -= skb->data_len; |
| 1277 | |
| 1278 | i = tx_ring->next_to_use; |
| 1279 | |
| 1280 | while(len) { |
| 1281 | buffer_info = &tx_ring->buffer_info[i]; |
| 1282 | size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE); |
| 1283 | buffer_info->length = size; |
| 1284 | buffer_info->dma = |
| 1285 | pci_map_single(adapter->pdev, |
| 1286 | skb->data + offset, |
| 1287 | size, |
| 1288 | PCI_DMA_TODEVICE); |
| 1289 | buffer_info->time_stamp = jiffies; |
| 1290 | |
| 1291 | len -= size; |
| 1292 | offset += size; |
| 1293 | count++; |
| 1294 | if(++i == tx_ring->count) i = 0; |
| 1295 | } |
| 1296 | |
| 1297 | for(f = 0; f < nr_frags; f++) { |
| 1298 | struct skb_frag_struct *frag; |
| 1299 | |
| 1300 | frag = &skb_shinfo(skb)->frags[f]; |
| 1301 | len = frag->size; |
| 1302 | offset = 0; |
| 1303 | |
| 1304 | while(len) { |
| 1305 | buffer_info = &tx_ring->buffer_info[i]; |
| 1306 | size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE); |
| 1307 | buffer_info->length = size; |
| 1308 | buffer_info->dma = |
| 1309 | pci_map_page(adapter->pdev, |
| 1310 | frag->page, |
| 1311 | frag->page_offset + offset, |
| 1312 | size, |
| 1313 | PCI_DMA_TODEVICE); |
| 1314 | buffer_info->time_stamp = jiffies; |
| 1315 | |
| 1316 | len -= size; |
| 1317 | offset += size; |
| 1318 | count++; |
| 1319 | if(++i == tx_ring->count) i = 0; |
| 1320 | } |
| 1321 | } |
| 1322 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 1323 | tx_ring->buffer_info[i].skb = skb; |
| 1324 | tx_ring->buffer_info[first].next_to_watch = i; |
| 1325 | |
| 1326 | return count; |
| 1327 | } |
| 1328 | |
| 1329 | static inline void |
| 1330 | ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags) |
| 1331 | { |
| 1332 | struct ixgb_desc_ring *tx_ring = &adapter->tx_ring; |
| 1333 | struct ixgb_tx_desc *tx_desc = NULL; |
| 1334 | struct ixgb_buffer *buffer_info; |
| 1335 | uint32_t cmd_type_len = adapter->tx_cmd_type; |
| 1336 | uint8_t status = 0; |
| 1337 | uint8_t popts = 0; |
| 1338 | unsigned int i; |
| 1339 | |
| 1340 | if(tx_flags & IXGB_TX_FLAGS_TSO) { |
| 1341 | cmd_type_len |= IXGB_TX_DESC_CMD_TSE; |
| 1342 | popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM); |
| 1343 | } |
| 1344 | |
| 1345 | if(tx_flags & IXGB_TX_FLAGS_CSUM) |
| 1346 | popts |= IXGB_TX_DESC_POPTS_TXSM; |
| 1347 | |
| 1348 | if(tx_flags & IXGB_TX_FLAGS_VLAN) { |
| 1349 | cmd_type_len |= IXGB_TX_DESC_CMD_VLE; |
| 1350 | } |
| 1351 | |
| 1352 | i = tx_ring->next_to_use; |
| 1353 | |
| 1354 | while(count--) { |
| 1355 | buffer_info = &tx_ring->buffer_info[i]; |
| 1356 | tx_desc = IXGB_TX_DESC(*tx_ring, i); |
| 1357 | tx_desc->buff_addr = cpu_to_le64(buffer_info->dma); |
| 1358 | tx_desc->cmd_type_len = |
| 1359 | cpu_to_le32(cmd_type_len | buffer_info->length); |
| 1360 | tx_desc->status = status; |
| 1361 | tx_desc->popts = popts; |
| 1362 | tx_desc->vlan = cpu_to_le16(vlan_id); |
| 1363 | |
| 1364 | if(++i == tx_ring->count) i = 0; |
| 1365 | } |
| 1366 | |
| 1367 | tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP |
| 1368 | | IXGB_TX_DESC_CMD_RS ); |
| 1369 | |
| 1370 | /* Force memory writes to complete before letting h/w |
| 1371 | * know there are new descriptors to fetch. (Only |
| 1372 | * applicable for weak-ordered memory model archs, |
| 1373 | * such as IA-64). */ |
| 1374 | wmb(); |
| 1375 | |
| 1376 | tx_ring->next_to_use = i; |
| 1377 | IXGB_WRITE_REG(&adapter->hw, TDT, i); |
| 1378 | } |
| 1379 | |
| 1380 | /* Tx Descriptors needed, worst case */ |
| 1381 | #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \ |
| 1382 | (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 1383 | #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \ |
| 1384 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 |
| 1385 | |
| 1386 | static int |
| 1387 | ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 1388 | { |
| 1389 | struct ixgb_adapter *adapter = netdev->priv; |
| 1390 | unsigned int first; |
| 1391 | unsigned int tx_flags = 0; |
| 1392 | unsigned long flags; |
| 1393 | int vlan_id = 0; |
| 1394 | int tso; |
| 1395 | |
| 1396 | if(skb->len <= 0) { |
| 1397 | dev_kfree_skb_any(skb); |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | spin_lock_irqsave(&adapter->tx_lock, flags); |
| 1402 | if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) { |
| 1403 | netif_stop_queue(netdev); |
| 1404 | spin_unlock_irqrestore(&adapter->tx_lock, flags); |
| 1405 | return 1; |
| 1406 | } |
| 1407 | spin_unlock_irqrestore(&adapter->tx_lock, flags); |
| 1408 | |
| 1409 | if(adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 1410 | tx_flags |= IXGB_TX_FLAGS_VLAN; |
| 1411 | vlan_id = vlan_tx_tag_get(skb); |
| 1412 | } |
| 1413 | |
| 1414 | first = adapter->tx_ring.next_to_use; |
| 1415 | |
| 1416 | tso = ixgb_tso(adapter, skb); |
| 1417 | if (tso < 0) { |
| 1418 | dev_kfree_skb_any(skb); |
| 1419 | return NETDEV_TX_OK; |
| 1420 | } |
| 1421 | |
| 1422 | if (tso) |
| 1423 | tx_flags |= IXGB_TX_FLAGS_TSO; |
| 1424 | else if(ixgb_tx_csum(adapter, skb)) |
| 1425 | tx_flags |= IXGB_TX_FLAGS_CSUM; |
| 1426 | |
| 1427 | ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id, |
| 1428 | tx_flags); |
| 1429 | |
| 1430 | netdev->trans_start = jiffies; |
| 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
| 1435 | /** |
| 1436 | * ixgb_tx_timeout - Respond to a Tx Hang |
| 1437 | * @netdev: network interface device structure |
| 1438 | **/ |
| 1439 | |
| 1440 | static void |
| 1441 | ixgb_tx_timeout(struct net_device *netdev) |
| 1442 | { |
| 1443 | struct ixgb_adapter *adapter = netdev->priv; |
| 1444 | |
| 1445 | /* Do the reset outside of interrupt context */ |
| 1446 | schedule_work(&adapter->tx_timeout_task); |
| 1447 | } |
| 1448 | |
| 1449 | static void |
| 1450 | ixgb_tx_timeout_task(struct net_device *netdev) |
| 1451 | { |
| 1452 | struct ixgb_adapter *adapter = netdev->priv; |
| 1453 | |
| 1454 | ixgb_down(adapter, TRUE); |
| 1455 | ixgb_up(adapter); |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * ixgb_get_stats - Get System Network Statistics |
| 1460 | * @netdev: network interface device structure |
| 1461 | * |
| 1462 | * Returns the address of the device statistics structure. |
| 1463 | * The statistics are actually updated from the timer callback. |
| 1464 | **/ |
| 1465 | |
| 1466 | static struct net_device_stats * |
| 1467 | ixgb_get_stats(struct net_device *netdev) |
| 1468 | { |
| 1469 | struct ixgb_adapter *adapter = netdev->priv; |
| 1470 | |
| 1471 | return &adapter->net_stats; |
| 1472 | } |
| 1473 | |
| 1474 | /** |
| 1475 | * ixgb_change_mtu - Change the Maximum Transfer Unit |
| 1476 | * @netdev: network interface device structure |
| 1477 | * @new_mtu: new value for maximum frame size |
| 1478 | * |
| 1479 | * Returns 0 on success, negative on failure |
| 1480 | **/ |
| 1481 | |
| 1482 | static int |
| 1483 | ixgb_change_mtu(struct net_device *netdev, int new_mtu) |
| 1484 | { |
| 1485 | struct ixgb_adapter *adapter = netdev->priv; |
| 1486 | int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH; |
| 1487 | int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH; |
| 1488 | |
| 1489 | |
| 1490 | if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) |
| 1491 | || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) { |
| 1492 | IXGB_ERR("Invalid MTU setting\n"); |
| 1493 | return -EINVAL; |
| 1494 | } |
| 1495 | |
| 1496 | if((max_frame <= IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) |
| 1497 | || (max_frame <= IXGB_RXBUFFER_2048)) { |
| 1498 | adapter->rx_buffer_len = IXGB_RXBUFFER_2048; |
| 1499 | |
| 1500 | } else if(max_frame <= IXGB_RXBUFFER_4096) { |
| 1501 | adapter->rx_buffer_len = IXGB_RXBUFFER_4096; |
| 1502 | |
| 1503 | } else if(max_frame <= IXGB_RXBUFFER_8192) { |
| 1504 | adapter->rx_buffer_len = IXGB_RXBUFFER_8192; |
| 1505 | |
| 1506 | } else { |
| 1507 | adapter->rx_buffer_len = IXGB_RXBUFFER_16384; |
| 1508 | } |
| 1509 | |
| 1510 | netdev->mtu = new_mtu; |
| 1511 | |
| 1512 | if(old_max_frame != max_frame && netif_running(netdev)) { |
| 1513 | |
| 1514 | ixgb_down(adapter, TRUE); |
| 1515 | ixgb_up(adapter); |
| 1516 | } |
| 1517 | |
| 1518 | return 0; |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * ixgb_update_stats - Update the board statistics counters. |
| 1523 | * @adapter: board private structure |
| 1524 | **/ |
| 1525 | |
| 1526 | void |
| 1527 | ixgb_update_stats(struct ixgb_adapter *adapter) |
| 1528 | { |
Malli Chilakala | 5633684 | 2005-04-28 18:45:50 -0700 | [diff] [blame^] | 1529 | struct net_device *netdev = adapter->netdev; |
| 1530 | |
| 1531 | if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) || |
| 1532 | (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) { |
| 1533 | u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL); |
| 1534 | u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL); |
| 1535 | u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH); |
| 1536 | u64 bcast = ((u64)bcast_h << 32) | bcast_l; |
| 1537 | |
| 1538 | multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32); |
| 1539 | /* fix up multicast stats by removing broadcasts */ |
| 1540 | multi -= bcast; |
| 1541 | |
| 1542 | adapter->stats.mprcl += (multi & 0xFFFFFFFF); |
| 1543 | adapter->stats.mprch += (multi >> 32); |
| 1544 | adapter->stats.bprcl += bcast_l; |
| 1545 | adapter->stats.bprch += bcast_h; |
| 1546 | } else { |
| 1547 | adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL); |
| 1548 | adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH); |
| 1549 | adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL); |
| 1550 | adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH); |
| 1551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL); |
| 1553 | adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH); |
| 1554 | adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL); |
| 1555 | adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL); |
| 1557 | adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH); |
| 1558 | adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL); |
| 1559 | adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH); |
| 1560 | adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL); |
| 1561 | adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH); |
| 1562 | adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL); |
| 1563 | adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH); |
| 1564 | adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL); |
| 1565 | adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH); |
| 1566 | adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC); |
| 1567 | adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC); |
| 1568 | adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC); |
| 1569 | adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC); |
| 1570 | adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS); |
| 1571 | adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC); |
| 1572 | adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC); |
| 1573 | adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC); |
| 1574 | adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL); |
| 1575 | adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH); |
| 1576 | adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL); |
| 1577 | adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH); |
| 1578 | adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL); |
| 1579 | adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH); |
| 1580 | adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL); |
| 1581 | adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH); |
| 1582 | adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL); |
| 1583 | adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH); |
| 1584 | adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL); |
| 1585 | adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH); |
| 1586 | adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL); |
| 1587 | adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH); |
| 1588 | adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL); |
| 1589 | adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH); |
| 1590 | adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL); |
| 1591 | adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH); |
| 1592 | adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC); |
| 1593 | adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C); |
| 1594 | adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC); |
| 1595 | adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC); |
| 1596 | adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC); |
| 1597 | adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC); |
| 1598 | adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC); |
| 1599 | adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC); |
| 1600 | adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC); |
| 1601 | adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC); |
| 1602 | adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC); |
| 1603 | adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC); |
| 1604 | adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC); |
| 1605 | adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC); |
| 1606 | adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC); |
| 1607 | adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC); |
| 1608 | |
| 1609 | /* Fill out the OS statistics structure */ |
| 1610 | |
| 1611 | adapter->net_stats.rx_packets = adapter->stats.gprcl; |
| 1612 | adapter->net_stats.tx_packets = adapter->stats.gptcl; |
| 1613 | adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
| 1614 | adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
| 1615 | adapter->net_stats.multicast = adapter->stats.mprcl; |
| 1616 | adapter->net_stats.collisions = 0; |
| 1617 | |
| 1618 | /* ignore RLEC as it reports errors for padded (<64bytes) frames |
| 1619 | * with a length in the type/len field */ |
| 1620 | adapter->net_stats.rx_errors = |
| 1621 | /* adapter->stats.rnbc + */ adapter->stats.crcerrs + |
| 1622 | adapter->stats.ruc + |
| 1623 | adapter->stats.roc /*+ adapter->stats.rlec */ + |
| 1624 | adapter->stats.icbc + |
| 1625 | adapter->stats.ecbc + adapter->stats.mpc; |
| 1626 | |
| 1627 | adapter->net_stats.rx_dropped = adapter->stats.mpc; |
| 1628 | |
| 1629 | /* see above |
| 1630 | * adapter->net_stats.rx_length_errors = adapter->stats.rlec; |
| 1631 | */ |
| 1632 | |
| 1633 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 1634 | adapter->net_stats.rx_fifo_errors = adapter->stats.mpc; |
| 1635 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 1636 | adapter->net_stats.rx_over_errors = adapter->stats.mpc; |
| 1637 | |
| 1638 | adapter->net_stats.tx_errors = 0; |
| 1639 | adapter->net_stats.rx_frame_errors = 0; |
| 1640 | adapter->net_stats.tx_aborted_errors = 0; |
| 1641 | adapter->net_stats.tx_carrier_errors = 0; |
| 1642 | adapter->net_stats.tx_fifo_errors = 0; |
| 1643 | adapter->net_stats.tx_heartbeat_errors = 0; |
| 1644 | adapter->net_stats.tx_window_errors = 0; |
| 1645 | } |
| 1646 | |
| 1647 | #define IXGB_MAX_INTR 10 |
| 1648 | /** |
| 1649 | * ixgb_intr - Interrupt Handler |
| 1650 | * @irq: interrupt number |
| 1651 | * @data: pointer to a network interface device structure |
| 1652 | * @pt_regs: CPU registers structure |
| 1653 | **/ |
| 1654 | |
| 1655 | static irqreturn_t |
| 1656 | ixgb_intr(int irq, void *data, struct pt_regs *regs) |
| 1657 | { |
| 1658 | struct net_device *netdev = data; |
| 1659 | struct ixgb_adapter *adapter = netdev->priv; |
| 1660 | struct ixgb_hw *hw = &adapter->hw; |
| 1661 | uint32_t icr = IXGB_READ_REG(hw, ICR); |
| 1662 | #ifndef CONFIG_IXGB_NAPI |
| 1663 | unsigned int i; |
| 1664 | #endif |
| 1665 | |
| 1666 | if(unlikely(!icr)) |
| 1667 | return IRQ_NONE; /* Not our interrupt */ |
| 1668 | |
| 1669 | if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) { |
| 1670 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 1671 | } |
| 1672 | |
| 1673 | #ifdef CONFIG_IXGB_NAPI |
| 1674 | if(netif_rx_schedule_prep(netdev)) { |
| 1675 | |
| 1676 | /* Disable interrupts and register for poll. The flush |
| 1677 | of the posted write is intentionally left out. |
| 1678 | */ |
| 1679 | |
| 1680 | atomic_inc(&adapter->irq_sem); |
| 1681 | IXGB_WRITE_REG(&adapter->hw, IMC, ~0); |
| 1682 | __netif_rx_schedule(netdev); |
| 1683 | } |
| 1684 | #else |
| 1685 | /* yes, that is actually a & and it is meant to make sure that |
| 1686 | * every pass through this for loop checks both receive and |
| 1687 | * transmit queues for completed descriptors, intended to |
| 1688 | * avoid starvation issues and assist tx/rx fairness. */ |
| 1689 | for(i = 0; i < IXGB_MAX_INTR; i++) |
| 1690 | if(!ixgb_clean_rx_irq(adapter) & |
| 1691 | !ixgb_clean_tx_irq(adapter)) |
| 1692 | break; |
| 1693 | #endif |
| 1694 | return IRQ_HANDLED; |
| 1695 | } |
| 1696 | |
| 1697 | #ifdef CONFIG_IXGB_NAPI |
| 1698 | /** |
| 1699 | * ixgb_clean - NAPI Rx polling callback |
| 1700 | * @adapter: board private structure |
| 1701 | **/ |
| 1702 | |
| 1703 | static int |
| 1704 | ixgb_clean(struct net_device *netdev, int *budget) |
| 1705 | { |
| 1706 | struct ixgb_adapter *adapter = netdev->priv; |
| 1707 | int work_to_do = min(*budget, netdev->quota); |
| 1708 | int tx_cleaned; |
| 1709 | int work_done = 0; |
| 1710 | |
| 1711 | tx_cleaned = ixgb_clean_tx_irq(adapter); |
| 1712 | ixgb_clean_rx_irq(adapter, &work_done, work_to_do); |
| 1713 | |
| 1714 | *budget -= work_done; |
| 1715 | netdev->quota -= work_done; |
| 1716 | |
| 1717 | /* if no Tx and not enough Rx work done, exit the polling mode */ |
| 1718 | if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) { |
| 1719 | netif_rx_complete(netdev); |
| 1720 | ixgb_irq_enable(adapter); |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | return 1; |
| 1725 | } |
| 1726 | #endif |
| 1727 | |
| 1728 | /** |
| 1729 | * ixgb_clean_tx_irq - Reclaim resources after transmit completes |
| 1730 | * @adapter: board private structure |
| 1731 | **/ |
| 1732 | |
| 1733 | static boolean_t |
| 1734 | ixgb_clean_tx_irq(struct ixgb_adapter *adapter) |
| 1735 | { |
| 1736 | struct ixgb_desc_ring *tx_ring = &adapter->tx_ring; |
| 1737 | struct net_device *netdev = adapter->netdev; |
| 1738 | struct ixgb_tx_desc *tx_desc, *eop_desc; |
| 1739 | struct ixgb_buffer *buffer_info; |
| 1740 | unsigned int i, eop; |
| 1741 | boolean_t cleaned = FALSE; |
| 1742 | |
| 1743 | i = tx_ring->next_to_clean; |
| 1744 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1745 | eop_desc = IXGB_TX_DESC(*tx_ring, eop); |
| 1746 | |
| 1747 | while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) { |
| 1748 | |
| 1749 | for(cleaned = FALSE; !cleaned; ) { |
| 1750 | tx_desc = IXGB_TX_DESC(*tx_ring, i); |
| 1751 | buffer_info = &tx_ring->buffer_info[i]; |
| 1752 | |
| 1753 | if (tx_desc->popts |
| 1754 | & (IXGB_TX_DESC_POPTS_TXSM | |
| 1755 | IXGB_TX_DESC_POPTS_IXSM)) |
| 1756 | adapter->hw_csum_tx_good++; |
| 1757 | |
| 1758 | ixgb_unmap_and_free_tx_resource(adapter, buffer_info); |
| 1759 | |
| 1760 | *(uint32_t *)&(tx_desc->status) = 0; |
| 1761 | |
| 1762 | cleaned = (i == eop); |
| 1763 | if(++i == tx_ring->count) i = 0; |
| 1764 | } |
| 1765 | |
| 1766 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 1767 | eop_desc = IXGB_TX_DESC(*tx_ring, eop); |
| 1768 | } |
| 1769 | |
| 1770 | tx_ring->next_to_clean = i; |
| 1771 | |
| 1772 | spin_lock(&adapter->tx_lock); |
| 1773 | if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) && |
| 1774 | (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) { |
| 1775 | |
| 1776 | netif_wake_queue(netdev); |
| 1777 | } |
| 1778 | spin_unlock(&adapter->tx_lock); |
| 1779 | |
| 1780 | if(adapter->detect_tx_hung) { |
| 1781 | /* detect a transmit hang in hardware, this serializes the |
| 1782 | * check with the clearing of time_stamp and movement of i */ |
| 1783 | adapter->detect_tx_hung = FALSE; |
| 1784 | if(tx_ring->buffer_info[i].dma && |
| 1785 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ) |
| 1786 | && !(IXGB_READ_REG(&adapter->hw, STATUS) & |
| 1787 | IXGB_STATUS_TXOFF)) |
| 1788 | netif_stop_queue(netdev); |
| 1789 | } |
| 1790 | |
| 1791 | return cleaned; |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * ixgb_rx_checksum - Receive Checksum Offload for 82597. |
| 1796 | * @adapter: board private structure |
| 1797 | * @rx_desc: receive descriptor |
| 1798 | * @sk_buff: socket buffer with received data |
| 1799 | **/ |
| 1800 | |
| 1801 | static inline void |
| 1802 | ixgb_rx_checksum(struct ixgb_adapter *adapter, |
| 1803 | struct ixgb_rx_desc *rx_desc, |
| 1804 | struct sk_buff *skb) |
| 1805 | { |
| 1806 | /* Ignore Checksum bit is set OR |
| 1807 | * TCP Checksum has not been calculated |
| 1808 | */ |
| 1809 | if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) || |
| 1810 | (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) { |
| 1811 | skb->ip_summed = CHECKSUM_NONE; |
| 1812 | return; |
| 1813 | } |
| 1814 | |
| 1815 | /* At this point we know the hardware did the TCP checksum */ |
| 1816 | /* now look at the TCP checksum error bit */ |
| 1817 | if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) { |
| 1818 | /* let the stack verify checksum errors */ |
| 1819 | skb->ip_summed = CHECKSUM_NONE; |
| 1820 | adapter->hw_csum_rx_error++; |
| 1821 | } else { |
| 1822 | /* TCP checksum is good */ |
| 1823 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1824 | adapter->hw_csum_rx_good++; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * ixgb_clean_rx_irq - Send received data up the network stack, |
| 1830 | * @adapter: board private structure |
| 1831 | **/ |
| 1832 | |
| 1833 | static boolean_t |
| 1834 | #ifdef CONFIG_IXGB_NAPI |
| 1835 | ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do) |
| 1836 | #else |
| 1837 | ixgb_clean_rx_irq(struct ixgb_adapter *adapter) |
| 1838 | #endif |
| 1839 | { |
| 1840 | struct ixgb_desc_ring *rx_ring = &adapter->rx_ring; |
| 1841 | struct net_device *netdev = adapter->netdev; |
| 1842 | struct pci_dev *pdev = adapter->pdev; |
| 1843 | struct ixgb_rx_desc *rx_desc, *next_rxd; |
| 1844 | struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer; |
| 1845 | struct sk_buff *skb, *next_skb; |
| 1846 | uint32_t length; |
| 1847 | unsigned int i, j; |
| 1848 | boolean_t cleaned = FALSE; |
| 1849 | |
| 1850 | i = rx_ring->next_to_clean; |
| 1851 | rx_desc = IXGB_RX_DESC(*rx_ring, i); |
| 1852 | buffer_info = &rx_ring->buffer_info[i]; |
| 1853 | |
| 1854 | while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) { |
| 1855 | |
| 1856 | #ifdef CONFIG_IXGB_NAPI |
| 1857 | if(*work_done >= work_to_do) |
| 1858 | break; |
| 1859 | |
| 1860 | (*work_done)++; |
| 1861 | #endif |
| 1862 | skb = buffer_info->skb; |
| 1863 | prefetch(skb->data); |
| 1864 | |
| 1865 | if(++i == rx_ring->count) i = 0; |
| 1866 | next_rxd = IXGB_RX_DESC(*rx_ring, i); |
| 1867 | prefetch(next_rxd); |
| 1868 | |
| 1869 | if((j = i + 1) == rx_ring->count) j = 0; |
| 1870 | next2_buffer = &rx_ring->buffer_info[j]; |
| 1871 | prefetch(next2_buffer); |
| 1872 | |
| 1873 | next_buffer = &rx_ring->buffer_info[i]; |
| 1874 | next_skb = next_buffer->skb; |
| 1875 | prefetch(next_skb); |
| 1876 | |
| 1877 | |
| 1878 | cleaned = TRUE; |
| 1879 | |
| 1880 | pci_unmap_single(pdev, |
| 1881 | buffer_info->dma, |
| 1882 | buffer_info->length, |
| 1883 | PCI_DMA_FROMDEVICE); |
| 1884 | |
| 1885 | length = le16_to_cpu(rx_desc->length); |
| 1886 | |
| 1887 | if(unlikely(!(rx_desc->status & IXGB_RX_DESC_STATUS_EOP))) { |
| 1888 | |
| 1889 | /* All receives must fit into a single buffer */ |
| 1890 | |
| 1891 | IXGB_DBG("Receive packet consumed multiple buffers " |
| 1892 | "length<%x>\n", length); |
| 1893 | |
| 1894 | dev_kfree_skb_irq(skb); |
| 1895 | rx_desc->status = 0; |
| 1896 | buffer_info->skb = NULL; |
| 1897 | |
| 1898 | rx_desc = next_rxd; |
| 1899 | buffer_info = next_buffer; |
| 1900 | continue; |
| 1901 | } |
| 1902 | |
| 1903 | if (unlikely(rx_desc->errors |
| 1904 | & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE |
| 1905 | | IXGB_RX_DESC_ERRORS_P | |
| 1906 | IXGB_RX_DESC_ERRORS_RXE))) { |
| 1907 | |
| 1908 | dev_kfree_skb_irq(skb); |
| 1909 | rx_desc->status = 0; |
| 1910 | buffer_info->skb = NULL; |
| 1911 | |
| 1912 | rx_desc = next_rxd; |
| 1913 | buffer_info = next_buffer; |
| 1914 | continue; |
| 1915 | } |
| 1916 | |
| 1917 | /* Good Receive */ |
| 1918 | skb_put(skb, length); |
| 1919 | |
| 1920 | /* Receive Checksum Offload */ |
| 1921 | ixgb_rx_checksum(adapter, rx_desc, skb); |
| 1922 | |
| 1923 | skb->protocol = eth_type_trans(skb, netdev); |
| 1924 | #ifdef CONFIG_IXGB_NAPI |
| 1925 | if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) { |
| 1926 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
| 1927 | le16_to_cpu(rx_desc->special) & |
| 1928 | IXGB_RX_DESC_SPECIAL_VLAN_MASK); |
| 1929 | } else { |
| 1930 | netif_receive_skb(skb); |
| 1931 | } |
| 1932 | #else /* CONFIG_IXGB_NAPI */ |
| 1933 | if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) { |
| 1934 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 1935 | le16_to_cpu(rx_desc->special) & |
| 1936 | IXGB_RX_DESC_SPECIAL_VLAN_MASK); |
| 1937 | } else { |
| 1938 | netif_rx(skb); |
| 1939 | } |
| 1940 | #endif /* CONFIG_IXGB_NAPI */ |
| 1941 | netdev->last_rx = jiffies; |
| 1942 | |
| 1943 | rx_desc->status = 0; |
| 1944 | buffer_info->skb = NULL; |
| 1945 | |
| 1946 | rx_desc = next_rxd; |
| 1947 | buffer_info = next_buffer; |
| 1948 | } |
| 1949 | |
| 1950 | rx_ring->next_to_clean = i; |
| 1951 | |
| 1952 | ixgb_alloc_rx_buffers(adapter); |
| 1953 | |
| 1954 | return cleaned; |
| 1955 | } |
| 1956 | |
| 1957 | /** |
| 1958 | * ixgb_alloc_rx_buffers - Replace used receive buffers |
| 1959 | * @adapter: address of board private structure |
| 1960 | **/ |
| 1961 | |
| 1962 | static void |
| 1963 | ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter) |
| 1964 | { |
| 1965 | struct ixgb_desc_ring *rx_ring = &adapter->rx_ring; |
| 1966 | struct net_device *netdev = adapter->netdev; |
| 1967 | struct pci_dev *pdev = adapter->pdev; |
| 1968 | struct ixgb_rx_desc *rx_desc; |
| 1969 | struct ixgb_buffer *buffer_info; |
| 1970 | struct sk_buff *skb; |
| 1971 | unsigned int i; |
| 1972 | int num_group_tail_writes; |
| 1973 | long cleancount; |
| 1974 | |
| 1975 | i = rx_ring->next_to_use; |
| 1976 | buffer_info = &rx_ring->buffer_info[i]; |
| 1977 | cleancount = IXGB_DESC_UNUSED(rx_ring); |
| 1978 | |
| 1979 | num_group_tail_writes = IXGB_RX_BUFFER_WRITE; |
| 1980 | |
| 1981 | /* leave one descriptor unused */ |
| 1982 | while(--cleancount > 0) { |
| 1983 | rx_desc = IXGB_RX_DESC(*rx_ring, i); |
| 1984 | |
| 1985 | skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN); |
| 1986 | |
| 1987 | if(unlikely(!skb)) { |
| 1988 | /* Better luck next round */ |
| 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 1993 | * this will result in a 16 byte aligned IP header after |
| 1994 | * the 14 byte MAC header is removed |
| 1995 | */ |
| 1996 | skb_reserve(skb, NET_IP_ALIGN); |
| 1997 | |
| 1998 | skb->dev = netdev; |
| 1999 | |
| 2000 | buffer_info->skb = skb; |
| 2001 | buffer_info->length = adapter->rx_buffer_len; |
| 2002 | buffer_info->dma = |
| 2003 | pci_map_single(pdev, |
| 2004 | skb->data, |
| 2005 | adapter->rx_buffer_len, |
| 2006 | PCI_DMA_FROMDEVICE); |
| 2007 | |
| 2008 | rx_desc->buff_addr = cpu_to_le64(buffer_info->dma); |
| 2009 | |
| 2010 | if((i & ~(num_group_tail_writes- 1)) == i) { |
| 2011 | /* Force memory writes to complete before letting h/w |
| 2012 | * know there are new descriptors to fetch. (Only |
| 2013 | * applicable for weak-ordered memory model archs, |
| 2014 | * such as IA-64). */ |
| 2015 | wmb(); |
| 2016 | |
| 2017 | IXGB_WRITE_REG(&adapter->hw, RDT, i); |
| 2018 | } |
| 2019 | |
| 2020 | if(++i == rx_ring->count) i = 0; |
| 2021 | buffer_info = &rx_ring->buffer_info[i]; |
| 2022 | } |
| 2023 | |
| 2024 | rx_ring->next_to_use = i; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping. |
| 2029 | * |
| 2030 | * @param netdev network interface device structure |
| 2031 | * @param grp indicates to enable or disable tagging/stripping |
| 2032 | **/ |
| 2033 | static void |
| 2034 | ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 2035 | { |
| 2036 | struct ixgb_adapter *adapter = netdev->priv; |
| 2037 | uint32_t ctrl, rctl; |
| 2038 | |
| 2039 | ixgb_irq_disable(adapter); |
| 2040 | adapter->vlgrp = grp; |
| 2041 | |
| 2042 | if(grp) { |
| 2043 | /* enable VLAN tag insert/strip */ |
| 2044 | ctrl = IXGB_READ_REG(&adapter->hw, CTRL0); |
| 2045 | ctrl |= IXGB_CTRL0_VME; |
| 2046 | IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl); |
| 2047 | |
| 2048 | /* enable VLAN receive filtering */ |
| 2049 | |
| 2050 | rctl = IXGB_READ_REG(&adapter->hw, RCTL); |
| 2051 | rctl |= IXGB_RCTL_VFE; |
| 2052 | rctl &= ~IXGB_RCTL_CFIEN; |
| 2053 | IXGB_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2054 | } else { |
| 2055 | /* disable VLAN tag insert/strip */ |
| 2056 | |
| 2057 | ctrl = IXGB_READ_REG(&adapter->hw, CTRL0); |
| 2058 | ctrl &= ~IXGB_CTRL0_VME; |
| 2059 | IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl); |
| 2060 | |
| 2061 | /* disable VLAN filtering */ |
| 2062 | |
| 2063 | rctl = IXGB_READ_REG(&adapter->hw, RCTL); |
| 2064 | rctl &= ~IXGB_RCTL_VFE; |
| 2065 | IXGB_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2066 | } |
| 2067 | |
| 2068 | ixgb_irq_enable(adapter); |
| 2069 | } |
| 2070 | |
| 2071 | static void |
| 2072 | ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 2073 | { |
| 2074 | struct ixgb_adapter *adapter = netdev->priv; |
| 2075 | uint32_t vfta, index; |
| 2076 | |
| 2077 | /* add VID to filter table */ |
| 2078 | |
| 2079 | index = (vid >> 5) & 0x7F; |
| 2080 | vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 2081 | vfta |= (1 << (vid & 0x1F)); |
| 2082 | ixgb_write_vfta(&adapter->hw, index, vfta); |
| 2083 | } |
| 2084 | |
| 2085 | static void |
| 2086 | ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 2087 | { |
| 2088 | struct ixgb_adapter *adapter = netdev->priv; |
| 2089 | uint32_t vfta, index; |
| 2090 | |
| 2091 | ixgb_irq_disable(adapter); |
| 2092 | |
| 2093 | if(adapter->vlgrp) |
| 2094 | adapter->vlgrp->vlan_devices[vid] = NULL; |
| 2095 | |
| 2096 | ixgb_irq_enable(adapter); |
| 2097 | |
| 2098 | /* remove VID from filter table*/ |
| 2099 | |
| 2100 | index = (vid >> 5) & 0x7F; |
| 2101 | vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 2102 | vfta &= ~(1 << (vid & 0x1F)); |
| 2103 | ixgb_write_vfta(&adapter->hw, index, vfta); |
| 2104 | } |
| 2105 | |
| 2106 | static void |
| 2107 | ixgb_restore_vlan(struct ixgb_adapter *adapter) |
| 2108 | { |
| 2109 | ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2110 | |
| 2111 | if(adapter->vlgrp) { |
| 2112 | uint16_t vid; |
| 2113 | for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2114 | if(!adapter->vlgrp->vlan_devices[vid]) |
| 2115 | continue; |
| 2116 | ixgb_vlan_rx_add_vid(adapter->netdev, vid); |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * ixgb_notify_reboot - handles OS notification of reboot event. |
| 2123 | * @param nb notifier block, unused |
| 2124 | * @param event Event being passed to driver to act upon |
| 2125 | * @param p A pointer to our net device |
| 2126 | **/ |
| 2127 | static int |
| 2128 | ixgb_notify_reboot(struct notifier_block *nb, unsigned long event, void *p) |
| 2129 | { |
| 2130 | struct pci_dev *pdev = NULL; |
| 2131 | |
| 2132 | switch(event) { |
| 2133 | case SYS_DOWN: |
| 2134 | case SYS_HALT: |
| 2135 | case SYS_POWER_OFF: |
| 2136 | while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) { |
| 2137 | if (pci_dev_driver(pdev) == &ixgb_driver) |
| 2138 | ixgb_suspend(pdev, 3); |
| 2139 | } |
| 2140 | } |
| 2141 | return NOTIFY_DONE; |
| 2142 | } |
| 2143 | |
| 2144 | /** |
| 2145 | * ixgb_suspend - driver suspend function called from notify. |
| 2146 | * @param pdev pci driver structure used for passing to |
| 2147 | * @param state power state to enter |
| 2148 | **/ |
| 2149 | static int |
| 2150 | ixgb_suspend(struct pci_dev *pdev, uint32_t state) |
| 2151 | { |
| 2152 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2153 | struct ixgb_adapter *adapter = netdev->priv; |
| 2154 | |
| 2155 | netif_device_detach(netdev); |
| 2156 | |
| 2157 | if(netif_running(netdev)) |
| 2158 | ixgb_down(adapter, TRUE); |
| 2159 | |
| 2160 | pci_save_state(pdev); |
| 2161 | |
| 2162 | state = (state > 0) ? 3 : 0; |
| 2163 | pci_set_power_state(pdev, state); |
| 2164 | msec_delay(200); |
| 2165 | |
| 2166 | return 0; |
| 2167 | } |
| 2168 | |
| 2169 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2170 | /* |
| 2171 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 2172 | * without having to re-enable interrupts. It's not called while |
| 2173 | * the interrupt routine is executing. |
| 2174 | */ |
| 2175 | |
| 2176 | static void ixgb_netpoll(struct net_device *dev) |
| 2177 | { |
| 2178 | struct ixgb_adapter *adapter = dev->priv; |
| 2179 | disable_irq(adapter->pdev->irq); |
| 2180 | ixgb_intr(adapter->pdev->irq, dev, NULL); |
| 2181 | enable_irq(adapter->pdev->irq); |
| 2182 | } |
| 2183 | #endif |
| 2184 | |
| 2185 | /* ixgb_main.c */ |