[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / net / ixgb / ixgb_main.c
blob7d26623d859278bd1ad6369648de9ed41a112493
1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
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.
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.
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.
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include "ixgb.h"
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
42 char ixgb_driver_name[] = "ixgb";
43 char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
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.";
53 /* ixgb_pci_tbl - PCI Device ID Table
55 * Wildcard entries (PCI_ANY_ID) should come last
56 * Last entry must be all 0s
58 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
59 * Class, Class Mask, private data (not used) }
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},
69 /* required last entry */
70 {0,}
73 MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
75 /* Local Function Prototypes */
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);
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);
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);
127 #ifdef CONFIG_NET_POLL_CONTROLLER
128 /* for netdump / net console */
129 static void ixgb_netpoll(struct net_device *dev);
130 #endif
132 struct notifier_block ixgb_notifier_reboot = {
133 .notifier_call = ixgb_notify_reboot,
134 .next = NULL,
135 .priority = 0
138 /* Exported from other modules */
140 extern void ixgb_check_options(struct ixgb_adapter *adapter);
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
152 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
153 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
154 MODULE_LICENSE("GPL");
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 */
163 * ixgb_init_module - Driver Registration Routine
165 * ixgb_init_module is the first routine called when the driver is
166 * loaded. All it does is register with the PCI subsystem.
169 static int __init
170 ixgb_init_module(void)
172 int ret;
173 printk(KERN_INFO "%s - version %s\n",
174 ixgb_driver_string, ixgb_driver_version);
176 printk(KERN_INFO "%s\n", ixgb_copyright);
178 ret = pci_module_init(&ixgb_driver);
179 if(ret >= 0) {
180 register_reboot_notifier(&ixgb_notifier_reboot);
182 return ret;
185 module_init(ixgb_init_module);
188 * ixgb_exit_module - Driver Exit Cleanup Routine
190 * ixgb_exit_module is called just before the driver is removed
191 * from memory.
194 static void __exit
195 ixgb_exit_module(void)
197 unregister_reboot_notifier(&ixgb_notifier_reboot);
198 pci_unregister_driver(&ixgb_driver);
201 module_exit(ixgb_exit_module);
204 * ixgb_irq_disable - Mask off interrupt generation on the NIC
205 * @adapter: board private structure
208 static inline void
209 ixgb_irq_disable(struct ixgb_adapter *adapter)
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);
218 * ixgb_irq_enable - Enable default interrupt generation settings
219 * @adapter: board private structure
222 static inline void
223 ixgb_irq_enable(struct ixgb_adapter *adapter)
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);
234 ixgb_up(struct ixgb_adapter *adapter)
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;
241 /* hardware has been reset, we need to reload some things */
243 ixgb_set_multi(netdev);
245 ixgb_restore_vlan(adapter);
247 ixgb_configure_tx(adapter);
248 ixgb_setup_rctl(adapter);
249 ixgb_configure_rx(adapter);
250 ixgb_alloc_rx_buffers(adapter);
252 #ifdef CONFIG_PCI_MSI
254 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) &
255 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE;
256 adapter->have_msi = TRUE;
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 */
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;
274 /* disable interrupts and get the hardware into a known state */
275 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
277 if((hw->max_frame_size != max_frame) ||
278 (hw->max_frame_size !=
279 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
281 hw->max_frame_size = max_frame;
283 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
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);
289 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
290 ctrl0 |= IXGB_CTRL0_JFE;
291 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
296 mod_timer(&adapter->watchdog_timer, jiffies);
297 ixgb_irq_enable(adapter);
299 #ifdef CONFIG_IXGB_NAPI
300 netif_poll_enable(netdev);
301 #endif
302 return 0;
305 void
306 ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
308 struct net_device *netdev = adapter->netdev;
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);
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);
327 ixgb_reset(adapter);
328 ixgb_clean_tx_ring(adapter);
329 ixgb_clean_rx_ring(adapter);
332 void
333 ixgb_reset(struct ixgb_adapter *adapter)
336 ixgb_adapter_stop(&adapter->hw);
337 if(!ixgb_init_hw(&adapter->hw))
338 IXGB_DBG("ixgb_init_hw failed.\n");
342 * ixgb_probe - Device Initialization Routine
343 * @pdev: PCI device information struct
344 * @ent: entry in ixgb_pci_tbl
346 * Returns 0 on success, negative on failure
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.
353 static int __devinit
354 ixgb_probe(struct pci_dev *pdev,
355 const struct pci_device_id *ent)
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;
366 if((err = pci_enable_device(pdev)))
367 return err;
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;
376 pci_using_dac = 0;
379 if((err = pci_request_regions(pdev, ixgb_driver_name)))
380 return err;
382 pci_set_master(pdev);
384 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
385 if(!netdev) {
386 err = -ENOMEM;
387 goto err_alloc_etherdev;
390 SET_MODULE_OWNER(netdev);
391 SET_NETDEV_DEV(netdev, &pdev->dev);
393 pci_set_drvdata(pdev, netdev);
394 adapter = netdev->priv;
395 adapter->netdev = netdev;
396 adapter->pdev = pdev;
397 adapter->hw.back = adapter;
399 mmio_start = pci_resource_start(pdev, BAR_0);
400 mmio_len = pci_resource_len(pdev, BAR_0);
402 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
403 if(!adapter->hw.hw_addr) {
404 err = -EIO;
405 goto err_ioremap;
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;
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
438 netdev->mem_start = mmio_start;
439 netdev->mem_end = mmio_start + mmio_len;
440 netdev->base_addr = adapter->hw.io_base;
442 adapter->bd_number = cards_found;
443 adapter->link_speed = 0;
444 adapter->link_duplex = 0;
446 /* setup the private structure */
448 if((err = ixgb_sw_init(adapter)))
449 goto err_sw_init;
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
460 if(pci_using_dac)
461 netdev->features |= NETIF_F_HIGHDMA;
463 /* make sure the EEPROM is good */
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;
471 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
473 if(!is_valid_ether_addr(netdev->dev_addr)) {
474 err = -EIO;
475 goto err_eeprom;
478 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
480 init_timer(&adapter->watchdog_timer);
481 adapter->watchdog_timer.function = &ixgb_watchdog;
482 adapter->watchdog_timer.data = (unsigned long)adapter;
484 INIT_WORK(&adapter->tx_timeout_task,
485 (void (*)(void *))ixgb_tx_timeout_task, netdev);
487 if((err = register_netdev(netdev)))
488 goto err_register;
490 /* we're going to reset, so assume we have no link for now */
492 netif_carrier_off(netdev);
493 netif_stop_queue(netdev);
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 */
500 ixgb_reset(adapter);
502 cards_found++;
503 return 0;
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;
517 * ixgb_remove - Device Removal Routine
518 * @pdev: PCI device information struct
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.
526 static void __devexit
527 ixgb_remove(struct pci_dev *pdev)
529 struct net_device *netdev = pci_get_drvdata(pdev);
530 struct ixgb_adapter *adapter = netdev->priv;
532 unregister_netdev(netdev);
534 iounmap(adapter->hw.hw_addr);
535 pci_release_regions(pdev);
537 free_netdev(netdev);
541 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
542 * @adapter: board private structure to initialize
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).
549 static int __devinit
550 ixgb_sw_init(struct ixgb_adapter *adapter)
552 struct ixgb_hw *hw = &adapter->hw;
553 struct net_device *netdev = adapter->netdev;
554 struct pci_dev *pdev = adapter->pdev;
556 /* PCI config space info */
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;
563 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
565 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
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");
576 /* enable flow control to be programmed */
577 hw->fc.send_xon = 1;
579 atomic_set(&adapter->irq_sem, 1);
580 spin_lock_init(&adapter->tx_lock);
582 return 0;
586 * ixgb_open - Called when a network interface is made active
587 * @netdev: network interface device structure
589 * Returns 0 on success, negative value on failure
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.
598 static int
599 ixgb_open(struct net_device *netdev)
601 struct ixgb_adapter *adapter = netdev->priv;
602 int err;
604 /* allocate transmit descriptors */
606 if((err = ixgb_setup_tx_resources(adapter)))
607 goto err_setup_tx;
609 /* allocate receive descriptors */
611 if((err = ixgb_setup_rx_resources(adapter)))
612 goto err_setup_rx;
614 if((err = ixgb_up(adapter)))
615 goto err_up;
617 return 0;
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);
626 return err;
630 * ixgb_close - Disables a network interface
631 * @netdev: network interface device structure
633 * Returns 0, this is not allowed to fail
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.
641 static int
642 ixgb_close(struct net_device *netdev)
644 struct ixgb_adapter *adapter = netdev->priv;
646 ixgb_down(adapter, TRUE);
648 ixgb_free_tx_resources(adapter);
649 ixgb_free_rx_resources(adapter);
651 return 0;
655 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
656 * @adapter: board private structure
658 * Return 0 on success, negative on failure
662 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
664 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
665 struct pci_dev *pdev = adapter->pdev;
666 int size;
668 size = sizeof(struct ixgb_buffer) * txdr->count;
669 txdr->buffer_info = vmalloc(size);
670 if(!txdr->buffer_info) {
671 return -ENOMEM;
673 memset(txdr->buffer_info, 0, size);
675 /* round up to nearest 4K */
677 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
678 IXGB_ROUNDUP(txdr->size, 4096);
680 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
681 if(!txdr->desc) {
682 vfree(txdr->buffer_info);
683 return -ENOMEM;
685 memset(txdr->desc, 0, txdr->size);
687 txdr->next_to_use = 0;
688 txdr->next_to_clean = 0;
690 return 0;
694 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
695 * @adapter: board private structure
697 * Configure the Tx unit of the MAC after a reset.
700 static void
701 ixgb_configure_tx(struct ixgb_adapter *adapter)
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;
708 /* Setup the Base and Length of the Tx Descriptor Ring
709 * tx_ring.dma can be either a 32 or 64 bit value
712 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
713 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
715 IXGB_WRITE_REG(hw, TDLEN, tdlen);
717 /* Setup the HW Tx Head and Tail descriptor pointers */
719 IXGB_WRITE_REG(hw, TDH, 0);
720 IXGB_WRITE_REG(hw, TDT, 0);
722 /* don't set up txdctl, it induces performance problems if configured
723 * incorrectly */
724 /* Set the Tx Interrupt Delay register */
726 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
728 /* Program the Transmit Control Register */
730 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
731 IXGB_WRITE_REG(hw, TCTL, tctl);
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);
740 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
741 * @adapter: board private structure
743 * Returns 0 on success, negative on failure
747 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
749 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
750 struct pci_dev *pdev = adapter->pdev;
751 int size;
753 size = sizeof(struct ixgb_buffer) * rxdr->count;
754 rxdr->buffer_info = vmalloc(size);
755 if(!rxdr->buffer_info) {
756 return -ENOMEM;
758 memset(rxdr->buffer_info, 0, size);
760 /* Round up to nearest 4K */
762 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
763 IXGB_ROUNDUP(rxdr->size, 4096);
765 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
767 if(!rxdr->desc) {
768 vfree(rxdr->buffer_info);
769 return -ENOMEM;
771 memset(rxdr->desc, 0, rxdr->size);
773 rxdr->next_to_clean = 0;
774 rxdr->next_to_use = 0;
776 return 0;
780 * ixgb_setup_rctl - configure the receive control register
781 * @adapter: Board private structure
784 static void
785 ixgb_setup_rctl(struct ixgb_adapter *adapter)
787 uint32_t rctl;
789 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
791 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
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);
798 rctl |= IXGB_RCTL_SECRC;
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;
816 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
820 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
821 * @adapter: board private structure
823 * Configure the Rx unit of the MAC after a reset.
826 static void
827 ixgb_configure_rx(struct ixgb_adapter *adapter)
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;
836 /* make sure receives are disabled while setting up the descriptors */
838 rctl = IXGB_READ_REG(hw, RCTL);
839 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
841 /* set the Receive Delay Timer Register */
843 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
845 /* Setup the Base and Length of the Rx Descriptor Ring */
847 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
848 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
850 IXGB_WRITE_REG(hw, RDLEN, rdlen);
852 /* Setup the HW Rx Head and Tail Descriptor Pointers */
853 IXGB_WRITE_REG(hw, RDH, 0);
854 IXGB_WRITE_REG(hw, RDT, 0);
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);
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);
876 /* Enable Receives */
878 IXGB_WRITE_REG(hw, RCTL, rctl);
882 * ixgb_free_tx_resources - Free Tx Resources
883 * @adapter: board private structure
885 * Free all transmit software resources
888 void
889 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
891 struct pci_dev *pdev = adapter->pdev;
893 ixgb_clean_tx_ring(adapter);
895 vfree(adapter->tx_ring.buffer_info);
896 adapter->tx_ring.buffer_info = NULL;
898 pci_free_consistent(pdev, adapter->tx_ring.size,
899 adapter->tx_ring.desc, adapter->tx_ring.dma);
901 adapter->tx_ring.desc = NULL;
904 static inline void
905 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
906 struct ixgb_buffer *buffer_info)
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;
916 if(buffer_info->skb) {
917 dev_kfree_skb_any(buffer_info->skb);
918 buffer_info->skb = NULL;
923 * ixgb_clean_tx_ring - Free Tx Buffers
924 * @adapter: board private structure
927 static void
928 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
930 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
931 struct ixgb_buffer *buffer_info;
932 unsigned long size;
933 unsigned int i;
935 /* Free all the Tx ring sk_buffs */
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);
942 size = sizeof(struct ixgb_buffer) * tx_ring->count;
943 memset(tx_ring->buffer_info, 0, size);
945 /* Zero out the descriptor ring */
947 memset(tx_ring->desc, 0, tx_ring->size);
949 tx_ring->next_to_use = 0;
950 tx_ring->next_to_clean = 0;
952 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
953 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
957 * ixgb_free_rx_resources - Free Rx Resources
958 * @adapter: board private structure
960 * Free all receive software resources
963 void
964 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
966 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
967 struct pci_dev *pdev = adapter->pdev;
969 ixgb_clean_rx_ring(adapter);
971 vfree(rx_ring->buffer_info);
972 rx_ring->buffer_info = NULL;
974 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
976 rx_ring->desc = NULL;
980 * ixgb_clean_rx_ring - Free Rx Buffers
981 * @adapter: board private structure
984 static void
985 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
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;
993 /* Free all the Rx ring sk_buffs */
995 for(i = 0; i < rx_ring->count; i++) {
996 buffer_info = &rx_ring->buffer_info[i];
997 if(buffer_info->skb) {
999 pci_unmap_single(pdev,
1000 buffer_info->dma,
1001 buffer_info->length,
1002 PCI_DMA_FROMDEVICE);
1004 dev_kfree_skb(buffer_info->skb);
1006 buffer_info->skb = NULL;
1010 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1011 memset(rx_ring->buffer_info, 0, size);
1013 /* Zero out the descriptor ring */
1015 memset(rx_ring->desc, 0, rx_ring->size);
1017 rx_ring->next_to_clean = 0;
1018 rx_ring->next_to_use = 0;
1020 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1021 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1025 * ixgb_set_mac - Change the Ethernet Address of the NIC
1026 * @netdev: network interface device structure
1027 * @p: pointer to an address structure
1029 * Returns 0 on success, negative on failure
1032 static int
1033 ixgb_set_mac(struct net_device *netdev, void *p)
1035 struct ixgb_adapter *adapter = netdev->priv;
1036 struct sockaddr *addr = p;
1038 if(!is_valid_ether_addr(addr->sa_data))
1039 return -EADDRNOTAVAIL;
1041 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1043 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1045 return 0;
1049 * ixgb_set_multi - Multicast and Promiscuous mode set
1050 * @netdev: network interface device structure
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.
1058 static void
1059 ixgb_set_multi(struct net_device *netdev)
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;
1067 /* Check for Promiscuous and All Multicast modes */
1069 rctl = IXGB_READ_REG(hw, RCTL);
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);
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];
1086 IXGB_WRITE_REG(hw, RCTL, rctl);
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);
1093 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1098 * ixgb_watchdog - Timer Call-back
1099 * @data: pointer to netdev cast into an unsigned long
1102 static void
1103 ixgb_watchdog(unsigned long data)
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;
1109 ixgb_check_for_link(&adapter->hw);
1111 if (ixgb_check_for_bad_link(&adapter->hw)) {
1112 /* force the reset path */
1113 netif_stop_queue(netdev);
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);
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);
1138 ixgb_update_stats(adapter);
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);
1150 /* Force detection of hung controller every watchdog period */
1151 adapter->detect_tx_hung = TRUE;
1153 /* generate an interrupt to force clean up of any stragglers */
1154 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1156 /* Reset the timer */
1157 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1160 #define IXGB_TX_FLAGS_CSUM 0x00000001
1161 #define IXGB_TX_FLAGS_VLAN 0x00000002
1162 #define IXGB_TX_FLAGS_TSO 0x00000004
1164 static inline int
1165 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
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;
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;
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;
1195 i = adapter->tx_ring.next_to_use;
1196 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
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)));
1216 if(++i == adapter->tx_ring.count) i = 0;
1217 adapter->tx_ring.next_to_use = i;
1219 return 1;
1221 #endif
1223 return 0;
1226 static inline boolean_t
1227 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1229 struct ixgb_context_desc *context_desc;
1230 unsigned int i;
1231 uint8_t css, cso;
1233 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1234 css = skb->h.raw - skb->data;
1235 cso = (skb->h.raw + skb->csum) - skb->data;
1237 i = adapter->tx_ring.next_to_use;
1238 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
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);
1253 if(++i == adapter->tx_ring.count) i = 0;
1254 adapter->tx_ring.next_to_use = i;
1256 return TRUE;
1259 return FALSE;
1262 #define IXGB_MAX_TXD_PWR 14
1263 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1265 static inline int
1266 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1267 unsigned int first)
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;
1274 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1275 unsigned int f;
1276 len -= skb->data_len;
1278 i = tx_ring->next_to_use;
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;
1291 len -= size;
1292 offset += size;
1293 count++;
1294 if(++i == tx_ring->count) i = 0;
1297 for(f = 0; f < nr_frags; f++) {
1298 struct skb_frag_struct *frag;
1300 frag = &skb_shinfo(skb)->frags[f];
1301 len = frag->size;
1302 offset = 0;
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;
1316 len -= size;
1317 offset += size;
1318 count++;
1319 if(++i == tx_ring->count) i = 0;
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;
1326 return count;
1329 static inline void
1330 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
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;
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);
1345 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1346 popts |= IXGB_TX_DESC_POPTS_TXSM;
1348 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1349 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1352 i = tx_ring->next_to_use;
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);
1364 if(++i == tx_ring->count) i = 0;
1367 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1368 | IXGB_TX_DESC_CMD_RS );
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();
1376 tx_ring->next_to_use = i;
1377 IXGB_WRITE_REG(&adapter->hw, TDT, i);
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
1386 static int
1387 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
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;
1396 if(skb->len <= 0) {
1397 dev_kfree_skb_any(skb);
1398 return 0;
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;
1407 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1409 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1410 tx_flags |= IXGB_TX_FLAGS_VLAN;
1411 vlan_id = vlan_tx_tag_get(skb);
1414 first = adapter->tx_ring.next_to_use;
1416 tso = ixgb_tso(adapter, skb);
1417 if (tso < 0) {
1418 dev_kfree_skb_any(skb);
1419 return NETDEV_TX_OK;
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;
1427 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1428 tx_flags);
1430 netdev->trans_start = jiffies;
1432 return 0;
1436 * ixgb_tx_timeout - Respond to a Tx Hang
1437 * @netdev: network interface device structure
1440 static void
1441 ixgb_tx_timeout(struct net_device *netdev)
1443 struct ixgb_adapter *adapter = netdev->priv;
1445 /* Do the reset outside of interrupt context */
1446 schedule_work(&adapter->tx_timeout_task);
1449 static void
1450 ixgb_tx_timeout_task(struct net_device *netdev)
1452 struct ixgb_adapter *adapter = netdev->priv;
1454 ixgb_down(adapter, TRUE);
1455 ixgb_up(adapter);
1459 * ixgb_get_stats - Get System Network Statistics
1460 * @netdev: network interface device structure
1462 * Returns the address of the device statistics structure.
1463 * The statistics are actually updated from the timer callback.
1466 static struct net_device_stats *
1467 ixgb_get_stats(struct net_device *netdev)
1469 struct ixgb_adapter *adapter = netdev->priv;
1471 return &adapter->net_stats;
1475 * ixgb_change_mtu - Change the Maximum Transfer Unit
1476 * @netdev: network interface device structure
1477 * @new_mtu: new value for maximum frame size
1479 * Returns 0 on success, negative on failure
1482 static int
1483 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
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;
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;
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;
1500 } else if(max_frame <= IXGB_RXBUFFER_4096) {
1501 adapter->rx_buffer_len = IXGB_RXBUFFER_4096;
1503 } else if(max_frame <= IXGB_RXBUFFER_8192) {
1504 adapter->rx_buffer_len = IXGB_RXBUFFER_8192;
1506 } else {
1507 adapter->rx_buffer_len = IXGB_RXBUFFER_16384;
1510 netdev->mtu = new_mtu;
1512 if(old_max_frame != max_frame && netif_running(netdev)) {
1514 ixgb_down(adapter, TRUE);
1515 ixgb_up(adapter);
1518 return 0;
1522 * ixgb_update_stats - Update the board statistics counters.
1523 * @adapter: board private structure
1526 void
1527 ixgb_update_stats(struct ixgb_adapter *adapter)
1529 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1530 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1531 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1532 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1533 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1534 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1535 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1536 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1537 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1538 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1539 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1540 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1541 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1542 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1543 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1544 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1545 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1546 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1547 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1548 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1549 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1550 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1551 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1552 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1553 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1554 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1555 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1556 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1557 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1558 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1559 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1560 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1561 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1562 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1563 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1564 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1565 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1566 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1567 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1568 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1569 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1570 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1571 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1572 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1573 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1574 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1575 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1576 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1577 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1578 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1579 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1580 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1581 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1582 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1583 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1584 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1585 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1586 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1587 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1588 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1590 /* Fill out the OS statistics structure */
1592 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1593 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1594 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1595 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1596 adapter->net_stats.multicast = adapter->stats.mprcl;
1597 adapter->net_stats.collisions = 0;
1599 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1600 * with a length in the type/len field */
1601 adapter->net_stats.rx_errors =
1602 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1603 adapter->stats.ruc +
1604 adapter->stats.roc /*+ adapter->stats.rlec */ +
1605 adapter->stats.icbc +
1606 adapter->stats.ecbc + adapter->stats.mpc;
1608 adapter->net_stats.rx_dropped = adapter->stats.mpc;
1610 /* see above
1611 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1614 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1615 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1616 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1617 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1619 adapter->net_stats.tx_errors = 0;
1620 adapter->net_stats.rx_frame_errors = 0;
1621 adapter->net_stats.tx_aborted_errors = 0;
1622 adapter->net_stats.tx_carrier_errors = 0;
1623 adapter->net_stats.tx_fifo_errors = 0;
1624 adapter->net_stats.tx_heartbeat_errors = 0;
1625 adapter->net_stats.tx_window_errors = 0;
1628 #define IXGB_MAX_INTR 10
1630 * ixgb_intr - Interrupt Handler
1631 * @irq: interrupt number
1632 * @data: pointer to a network interface device structure
1633 * @pt_regs: CPU registers structure
1636 static irqreturn_t
1637 ixgb_intr(int irq, void *data, struct pt_regs *regs)
1639 struct net_device *netdev = data;
1640 struct ixgb_adapter *adapter = netdev->priv;
1641 struct ixgb_hw *hw = &adapter->hw;
1642 uint32_t icr = IXGB_READ_REG(hw, ICR);
1643 #ifndef CONFIG_IXGB_NAPI
1644 unsigned int i;
1645 #endif
1647 if(unlikely(!icr))
1648 return IRQ_NONE; /* Not our interrupt */
1650 if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) {
1651 mod_timer(&adapter->watchdog_timer, jiffies);
1654 #ifdef CONFIG_IXGB_NAPI
1655 if(netif_rx_schedule_prep(netdev)) {
1657 /* Disable interrupts and register for poll. The flush
1658 of the posted write is intentionally left out.
1661 atomic_inc(&adapter->irq_sem);
1662 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1663 __netif_rx_schedule(netdev);
1665 #else
1666 /* yes, that is actually a & and it is meant to make sure that
1667 * every pass through this for loop checks both receive and
1668 * transmit queues for completed descriptors, intended to
1669 * avoid starvation issues and assist tx/rx fairness. */
1670 for(i = 0; i < IXGB_MAX_INTR; i++)
1671 if(!ixgb_clean_rx_irq(adapter) &
1672 !ixgb_clean_tx_irq(adapter))
1673 break;
1674 #endif
1675 return IRQ_HANDLED;
1678 #ifdef CONFIG_IXGB_NAPI
1680 * ixgb_clean - NAPI Rx polling callback
1681 * @adapter: board private structure
1684 static int
1685 ixgb_clean(struct net_device *netdev, int *budget)
1687 struct ixgb_adapter *adapter = netdev->priv;
1688 int work_to_do = min(*budget, netdev->quota);
1689 int tx_cleaned;
1690 int work_done = 0;
1692 tx_cleaned = ixgb_clean_tx_irq(adapter);
1693 ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
1695 *budget -= work_done;
1696 netdev->quota -= work_done;
1698 /* if no Tx and not enough Rx work done, exit the polling mode */
1699 if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
1700 netif_rx_complete(netdev);
1701 ixgb_irq_enable(adapter);
1702 return 0;
1705 return 1;
1707 #endif
1710 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1711 * @adapter: board private structure
1714 static boolean_t
1715 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1717 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1718 struct net_device *netdev = adapter->netdev;
1719 struct ixgb_tx_desc *tx_desc, *eop_desc;
1720 struct ixgb_buffer *buffer_info;
1721 unsigned int i, eop;
1722 boolean_t cleaned = FALSE;
1724 i = tx_ring->next_to_clean;
1725 eop = tx_ring->buffer_info[i].next_to_watch;
1726 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1728 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1730 for(cleaned = FALSE; !cleaned; ) {
1731 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1732 buffer_info = &tx_ring->buffer_info[i];
1734 if (tx_desc->popts
1735 & (IXGB_TX_DESC_POPTS_TXSM |
1736 IXGB_TX_DESC_POPTS_IXSM))
1737 adapter->hw_csum_tx_good++;
1739 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1741 *(uint32_t *)&(tx_desc->status) = 0;
1743 cleaned = (i == eop);
1744 if(++i == tx_ring->count) i = 0;
1747 eop = tx_ring->buffer_info[i].next_to_watch;
1748 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1751 tx_ring->next_to_clean = i;
1753 spin_lock(&adapter->tx_lock);
1754 if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1755 (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) {
1757 netif_wake_queue(netdev);
1759 spin_unlock(&adapter->tx_lock);
1761 if(adapter->detect_tx_hung) {
1762 /* detect a transmit hang in hardware, this serializes the
1763 * check with the clearing of time_stamp and movement of i */
1764 adapter->detect_tx_hung = FALSE;
1765 if(tx_ring->buffer_info[i].dma &&
1766 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
1767 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1768 IXGB_STATUS_TXOFF))
1769 netif_stop_queue(netdev);
1772 return cleaned;
1776 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1777 * @adapter: board private structure
1778 * @rx_desc: receive descriptor
1779 * @sk_buff: socket buffer with received data
1782 static inline void
1783 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1784 struct ixgb_rx_desc *rx_desc,
1785 struct sk_buff *skb)
1787 /* Ignore Checksum bit is set OR
1788 * TCP Checksum has not been calculated
1790 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1791 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1792 skb->ip_summed = CHECKSUM_NONE;
1793 return;
1796 /* At this point we know the hardware did the TCP checksum */
1797 /* now look at the TCP checksum error bit */
1798 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1799 /* let the stack verify checksum errors */
1800 skb->ip_summed = CHECKSUM_NONE;
1801 adapter->hw_csum_rx_error++;
1802 } else {
1803 /* TCP checksum is good */
1804 skb->ip_summed = CHECKSUM_UNNECESSARY;
1805 adapter->hw_csum_rx_good++;
1810 * ixgb_clean_rx_irq - Send received data up the network stack,
1811 * @adapter: board private structure
1814 static boolean_t
1815 #ifdef CONFIG_IXGB_NAPI
1816 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1817 #else
1818 ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1819 #endif
1821 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1822 struct net_device *netdev = adapter->netdev;
1823 struct pci_dev *pdev = adapter->pdev;
1824 struct ixgb_rx_desc *rx_desc, *next_rxd;
1825 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1826 struct sk_buff *skb, *next_skb;
1827 uint32_t length;
1828 unsigned int i, j;
1829 boolean_t cleaned = FALSE;
1831 i = rx_ring->next_to_clean;
1832 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1833 buffer_info = &rx_ring->buffer_info[i];
1835 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1837 #ifdef CONFIG_IXGB_NAPI
1838 if(*work_done >= work_to_do)
1839 break;
1841 (*work_done)++;
1842 #endif
1843 skb = buffer_info->skb;
1844 prefetch(skb->data);
1846 if(++i == rx_ring->count) i = 0;
1847 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1848 prefetch(next_rxd);
1850 if((j = i + 1) == rx_ring->count) j = 0;
1851 next2_buffer = &rx_ring->buffer_info[j];
1852 prefetch(next2_buffer);
1854 next_buffer = &rx_ring->buffer_info[i];
1855 next_skb = next_buffer->skb;
1856 prefetch(next_skb);
1859 cleaned = TRUE;
1861 pci_unmap_single(pdev,
1862 buffer_info->dma,
1863 buffer_info->length,
1864 PCI_DMA_FROMDEVICE);
1866 length = le16_to_cpu(rx_desc->length);
1868 if(unlikely(!(rx_desc->status & IXGB_RX_DESC_STATUS_EOP))) {
1870 /* All receives must fit into a single buffer */
1872 IXGB_DBG("Receive packet consumed multiple buffers "
1873 "length<%x>\n", length);
1875 dev_kfree_skb_irq(skb);
1876 rx_desc->status = 0;
1877 buffer_info->skb = NULL;
1879 rx_desc = next_rxd;
1880 buffer_info = next_buffer;
1881 continue;
1884 if (unlikely(rx_desc->errors
1885 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1886 | IXGB_RX_DESC_ERRORS_P |
1887 IXGB_RX_DESC_ERRORS_RXE))) {
1889 dev_kfree_skb_irq(skb);
1890 rx_desc->status = 0;
1891 buffer_info->skb = NULL;
1893 rx_desc = next_rxd;
1894 buffer_info = next_buffer;
1895 continue;
1898 /* Good Receive */
1899 skb_put(skb, length);
1901 /* Receive Checksum Offload */
1902 ixgb_rx_checksum(adapter, rx_desc, skb);
1904 skb->protocol = eth_type_trans(skb, netdev);
1905 #ifdef CONFIG_IXGB_NAPI
1906 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1907 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
1908 le16_to_cpu(rx_desc->special) &
1909 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1910 } else {
1911 netif_receive_skb(skb);
1913 #else /* CONFIG_IXGB_NAPI */
1914 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1915 vlan_hwaccel_rx(skb, adapter->vlgrp,
1916 le16_to_cpu(rx_desc->special) &
1917 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1918 } else {
1919 netif_rx(skb);
1921 #endif /* CONFIG_IXGB_NAPI */
1922 netdev->last_rx = jiffies;
1924 rx_desc->status = 0;
1925 buffer_info->skb = NULL;
1927 rx_desc = next_rxd;
1928 buffer_info = next_buffer;
1931 rx_ring->next_to_clean = i;
1933 ixgb_alloc_rx_buffers(adapter);
1935 return cleaned;
1939 * ixgb_alloc_rx_buffers - Replace used receive buffers
1940 * @adapter: address of board private structure
1943 static void
1944 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
1946 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1947 struct net_device *netdev = adapter->netdev;
1948 struct pci_dev *pdev = adapter->pdev;
1949 struct ixgb_rx_desc *rx_desc;
1950 struct ixgb_buffer *buffer_info;
1951 struct sk_buff *skb;
1952 unsigned int i;
1953 int num_group_tail_writes;
1954 long cleancount;
1956 i = rx_ring->next_to_use;
1957 buffer_info = &rx_ring->buffer_info[i];
1958 cleancount = IXGB_DESC_UNUSED(rx_ring);
1960 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
1962 /* leave one descriptor unused */
1963 while(--cleancount > 0) {
1964 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1966 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1968 if(unlikely(!skb)) {
1969 /* Better luck next round */
1970 break;
1973 /* Make buffer alignment 2 beyond a 16 byte boundary
1974 * this will result in a 16 byte aligned IP header after
1975 * the 14 byte MAC header is removed
1977 skb_reserve(skb, NET_IP_ALIGN);
1979 skb->dev = netdev;
1981 buffer_info->skb = skb;
1982 buffer_info->length = adapter->rx_buffer_len;
1983 buffer_info->dma =
1984 pci_map_single(pdev,
1985 skb->data,
1986 adapter->rx_buffer_len,
1987 PCI_DMA_FROMDEVICE);
1989 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1991 if((i & ~(num_group_tail_writes- 1)) == i) {
1992 /* Force memory writes to complete before letting h/w
1993 * know there are new descriptors to fetch. (Only
1994 * applicable for weak-ordered memory model archs,
1995 * such as IA-64). */
1996 wmb();
1998 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2001 if(++i == rx_ring->count) i = 0;
2002 buffer_info = &rx_ring->buffer_info[i];
2005 rx_ring->next_to_use = i;
2009 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2011 * @param netdev network interface device structure
2012 * @param grp indicates to enable or disable tagging/stripping
2014 static void
2015 ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2017 struct ixgb_adapter *adapter = netdev->priv;
2018 uint32_t ctrl, rctl;
2020 ixgb_irq_disable(adapter);
2021 adapter->vlgrp = grp;
2023 if(grp) {
2024 /* enable VLAN tag insert/strip */
2025 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2026 ctrl |= IXGB_CTRL0_VME;
2027 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2029 /* enable VLAN receive filtering */
2031 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2032 rctl |= IXGB_RCTL_VFE;
2033 rctl &= ~IXGB_RCTL_CFIEN;
2034 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2035 } else {
2036 /* disable VLAN tag insert/strip */
2038 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2039 ctrl &= ~IXGB_CTRL0_VME;
2040 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2042 /* disable VLAN filtering */
2044 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2045 rctl &= ~IXGB_RCTL_VFE;
2046 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2049 ixgb_irq_enable(adapter);
2052 static void
2053 ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
2055 struct ixgb_adapter *adapter = netdev->priv;
2056 uint32_t vfta, index;
2058 /* add VID to filter table */
2060 index = (vid >> 5) & 0x7F;
2061 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2062 vfta |= (1 << (vid & 0x1F));
2063 ixgb_write_vfta(&adapter->hw, index, vfta);
2066 static void
2067 ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2069 struct ixgb_adapter *adapter = netdev->priv;
2070 uint32_t vfta, index;
2072 ixgb_irq_disable(adapter);
2074 if(adapter->vlgrp)
2075 adapter->vlgrp->vlan_devices[vid] = NULL;
2077 ixgb_irq_enable(adapter);
2079 /* remove VID from filter table*/
2081 index = (vid >> 5) & 0x7F;
2082 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2083 vfta &= ~(1 << (vid & 0x1F));
2084 ixgb_write_vfta(&adapter->hw, index, vfta);
2087 static void
2088 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2090 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2092 if(adapter->vlgrp) {
2093 uint16_t vid;
2094 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2095 if(!adapter->vlgrp->vlan_devices[vid])
2096 continue;
2097 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2103 * ixgb_notify_reboot - handles OS notification of reboot event.
2104 * @param nb notifier block, unused
2105 * @param event Event being passed to driver to act upon
2106 * @param p A pointer to our net device
2108 static int
2109 ixgb_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2111 struct pci_dev *pdev = NULL;
2113 switch(event) {
2114 case SYS_DOWN:
2115 case SYS_HALT:
2116 case SYS_POWER_OFF:
2117 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
2118 if (pci_dev_driver(pdev) == &ixgb_driver)
2119 ixgb_suspend(pdev, 3);
2122 return NOTIFY_DONE;
2126 * ixgb_suspend - driver suspend function called from notify.
2127 * @param pdev pci driver structure used for passing to
2128 * @param state power state to enter
2130 static int
2131 ixgb_suspend(struct pci_dev *pdev, uint32_t state)
2133 struct net_device *netdev = pci_get_drvdata(pdev);
2134 struct ixgb_adapter *adapter = netdev->priv;
2136 netif_device_detach(netdev);
2138 if(netif_running(netdev))
2139 ixgb_down(adapter, TRUE);
2141 pci_save_state(pdev);
2143 state = (state > 0) ? 3 : 0;
2144 pci_set_power_state(pdev, state);
2145 msec_delay(200);
2147 return 0;
2150 #ifdef CONFIG_NET_POLL_CONTROLLER
2152 * Polling 'interrupt' - used by things like netconsole to send skbs
2153 * without having to re-enable interrupts. It's not called while
2154 * the interrupt routine is executing.
2157 static void ixgb_netpoll(struct net_device *dev)
2159 struct ixgb_adapter *adapter = dev->priv;
2160 disable_irq(adapter->pdev->irq);
2161 ixgb_intr(adapter->pdev->irq, dev, NULL);
2162 enable_irq(adapter->pdev->irq);
2164 #endif
2166 /* ixgb_main.c */