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)
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
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
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
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
36 * - reset buffer_info->dma in Tx resource cleanup logic
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
48 #define DRIVERNAPI "-NAPI"
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 */
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);
111 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
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 #ifdef CONFIG_NET_POLL_CONTROLLER
124 /* for netdump / net console */
125 static void ixgb_netpoll(struct net_device *dev);
128 /* Exported from other modules */
130 extern void ixgb_check_options(struct ixgb_adapter *adapter);
132 static struct pci_driver ixgb_driver = {
133 .name = ixgb_driver_name,
134 .id_table = ixgb_pci_tbl,
136 .remove = __devexit_p(ixgb_remove),
139 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
141 MODULE_LICENSE("GPL");
143 /* some defines for controlling descriptor fetches in h/w */
144 #define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
145 #define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is
146 pushed this many descriptors from head */
147 #define RXDCTL_WTHRESH_DEFAULT 16 /* chip writes back at this many or RXT0 */
150 * ixgb_init_module - Driver Registration Routine
152 * ixgb_init_module is the first routine called when the driver is
153 * loaded. All it does is register with the PCI subsystem.
157 ixgb_init_module(void)
159 printk(KERN_INFO "%s - version %s\n",
160 ixgb_driver_string, ixgb_driver_version);
162 printk(KERN_INFO "%s\n", ixgb_copyright);
164 return pci_module_init(&ixgb_driver);
167 module_init(ixgb_init_module);
170 * ixgb_exit_module - Driver Exit Cleanup Routine
172 * ixgb_exit_module is called just before the driver is removed
177 ixgb_exit_module(void)
179 pci_unregister_driver(&ixgb_driver);
182 module_exit(ixgb_exit_module);
185 * ixgb_irq_disable - Mask off interrupt generation on the NIC
186 * @adapter: board private structure
190 ixgb_irq_disable(struct ixgb_adapter *adapter)
192 atomic_inc(&adapter->irq_sem);
193 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
194 IXGB_WRITE_FLUSH(&adapter->hw);
195 synchronize_irq(adapter->pdev->irq);
199 * ixgb_irq_enable - Enable default interrupt generation settings
200 * @adapter: board private structure
204 ixgb_irq_enable(struct ixgb_adapter *adapter)
206 if(atomic_dec_and_test(&adapter->irq_sem)) {
207 IXGB_WRITE_REG(&adapter->hw, IMS,
208 IXGB_INT_RXT0 | IXGB_INT_RXDMT0 | IXGB_INT_TXDW |
210 IXGB_WRITE_FLUSH(&adapter->hw);
215 ixgb_up(struct ixgb_adapter *adapter)
217 struct net_device *netdev = adapter->netdev;
219 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
220 struct ixgb_hw *hw = &adapter->hw;
222 /* hardware has been reset, we need to reload some things */
224 ixgb_set_multi(netdev);
226 ixgb_restore_vlan(adapter);
228 ixgb_configure_tx(adapter);
229 ixgb_setup_rctl(adapter);
230 ixgb_configure_rx(adapter);
231 ixgb_alloc_rx_buffers(adapter);
233 #ifdef CONFIG_PCI_MSI
235 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) &
236 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE;
237 adapter->have_msi = TRUE;
240 adapter->have_msi = FALSE;
241 else if((err = pci_enable_msi(adapter->pdev))) {
243 "Unable to allocate MSI interrupt Error: %d\n", err);
244 adapter->have_msi = FALSE;
245 /* proceed to try to request regular interrupt */
250 if((err = request_irq(adapter->pdev->irq, &ixgb_intr,
251 SA_SHIRQ | SA_SAMPLE_RANDOM,
252 netdev->name, netdev)))
255 /* disable interrupts and get the hardware into a known state */
256 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
258 if((hw->max_frame_size != max_frame) ||
259 (hw->max_frame_size !=
260 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
262 hw->max_frame_size = max_frame;
264 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
266 if(hw->max_frame_size >
267 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
268 uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0);
270 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
271 ctrl0 |= IXGB_CTRL0_JFE;
272 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
277 mod_timer(&adapter->watchdog_timer, jiffies);
278 ixgb_irq_enable(adapter);
280 #ifdef CONFIG_IXGB_NAPI
281 netif_poll_enable(netdev);
287 ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
289 struct net_device *netdev = adapter->netdev;
291 ixgb_irq_disable(adapter);
292 free_irq(adapter->pdev->irq, netdev);
293 #ifdef CONFIG_PCI_MSI
294 if(adapter->have_msi == TRUE)
295 pci_disable_msi(adapter->pdev);
299 del_timer_sync(&adapter->watchdog_timer);
300 #ifdef CONFIG_IXGB_NAPI
301 netif_poll_disable(netdev);
303 adapter->link_speed = 0;
304 adapter->link_duplex = 0;
305 netif_carrier_off(netdev);
306 netif_stop_queue(netdev);
309 ixgb_clean_tx_ring(adapter);
310 ixgb_clean_rx_ring(adapter);
314 ixgb_reset(struct ixgb_adapter *adapter)
317 ixgb_adapter_stop(&adapter->hw);
318 if(!ixgb_init_hw(&adapter->hw))
319 IXGB_DBG("ixgb_init_hw failed.\n");
323 * ixgb_probe - Device Initialization Routine
324 * @pdev: PCI device information struct
325 * @ent: entry in ixgb_pci_tbl
327 * Returns 0 on success, negative on failure
329 * ixgb_probe initializes an adapter identified by a pci_dev structure.
330 * The OS initialization, configuring of the adapter private structure,
331 * and a hardware reset occur.
335 ixgb_probe(struct pci_dev *pdev,
336 const struct pci_device_id *ent)
338 struct net_device *netdev = NULL;
339 struct ixgb_adapter *adapter;
340 static int cards_found = 0;
341 unsigned long mmio_start;
347 if((err = pci_enable_device(pdev)))
350 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
353 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
354 IXGB_ERR("No usable DMA configuration, aborting\n");
360 if((err = pci_request_regions(pdev, ixgb_driver_name)))
363 pci_set_master(pdev);
365 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
368 goto err_alloc_etherdev;
371 SET_MODULE_OWNER(netdev);
372 SET_NETDEV_DEV(netdev, &pdev->dev);
374 pci_set_drvdata(pdev, netdev);
375 adapter = netdev->priv;
376 adapter->netdev = netdev;
377 adapter->pdev = pdev;
378 adapter->hw.back = adapter;
380 mmio_start = pci_resource_start(pdev, BAR_0);
381 mmio_len = pci_resource_len(pdev, BAR_0);
383 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
384 if(!adapter->hw.hw_addr) {
389 for(i = BAR_1; i <= BAR_5; i++) {
390 if(pci_resource_len(pdev, i) == 0)
392 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
393 adapter->hw.io_base = pci_resource_start(pdev, i);
398 netdev->open = &ixgb_open;
399 netdev->stop = &ixgb_close;
400 netdev->hard_start_xmit = &ixgb_xmit_frame;
401 netdev->get_stats = &ixgb_get_stats;
402 netdev->set_multicast_list = &ixgb_set_multi;
403 netdev->set_mac_address = &ixgb_set_mac;
404 netdev->change_mtu = &ixgb_change_mtu;
405 ixgb_set_ethtool_ops(netdev);
406 netdev->tx_timeout = &ixgb_tx_timeout;
407 netdev->watchdog_timeo = HZ;
408 #ifdef CONFIG_IXGB_NAPI
409 netdev->poll = &ixgb_clean;
412 netdev->vlan_rx_register = ixgb_vlan_rx_register;
413 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
414 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
415 #ifdef CONFIG_NET_POLL_CONTROLLER
416 netdev->poll_controller = ixgb_netpoll;
419 netdev->mem_start = mmio_start;
420 netdev->mem_end = mmio_start + mmio_len;
421 netdev->base_addr = adapter->hw.io_base;
423 adapter->bd_number = cards_found;
424 adapter->link_speed = 0;
425 adapter->link_duplex = 0;
427 /* setup the private structure */
429 if((err = ixgb_sw_init(adapter)))
432 netdev->features = NETIF_F_SG |
436 NETIF_F_HW_VLAN_FILTER;
438 netdev->features |= NETIF_F_TSO;
442 netdev->features |= NETIF_F_HIGHDMA;
444 /* make sure the EEPROM is good */
446 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
447 printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n");
452 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
454 if(!is_valid_ether_addr(netdev->dev_addr)) {
459 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
461 init_timer(&adapter->watchdog_timer);
462 adapter->watchdog_timer.function = &ixgb_watchdog;
463 adapter->watchdog_timer.data = (unsigned long)adapter;
465 INIT_WORK(&adapter->tx_timeout_task,
466 (void (*)(void *))ixgb_tx_timeout_task, netdev);
468 if((err = register_netdev(netdev)))
471 /* we're going to reset, so assume we have no link for now */
473 netif_carrier_off(netdev);
474 netif_stop_queue(netdev);
476 printk(KERN_INFO "%s: Intel(R) PRO/10GbE Network Connection\n",
478 ixgb_check_options(adapter);
479 /* reset the hardware with the new settings */
489 iounmap(adapter->hw.hw_addr);
493 pci_release_regions(pdev);
498 * ixgb_remove - Device Removal Routine
499 * @pdev: PCI device information struct
501 * ixgb_remove is called by the PCI subsystem to alert the driver
502 * that it should release a PCI device. The could be caused by a
503 * Hot-Plug event, or because the driver is going to be removed from
507 static void __devexit
508 ixgb_remove(struct pci_dev *pdev)
510 struct net_device *netdev = pci_get_drvdata(pdev);
511 struct ixgb_adapter *adapter = netdev->priv;
513 unregister_netdev(netdev);
515 iounmap(adapter->hw.hw_addr);
516 pci_release_regions(pdev);
522 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
523 * @adapter: board private structure to initialize
525 * ixgb_sw_init initializes the Adapter private data structure.
526 * Fields are initialized based on PCI device information and
527 * OS network device settings (MTU size).
531 ixgb_sw_init(struct ixgb_adapter *adapter)
533 struct ixgb_hw *hw = &adapter->hw;
534 struct net_device *netdev = adapter->netdev;
535 struct pci_dev *pdev = adapter->pdev;
537 /* PCI config space info */
539 hw->vendor_id = pdev->vendor;
540 hw->device_id = pdev->device;
541 hw->subsystem_vendor_id = pdev->subsystem_vendor;
542 hw->subsystem_id = pdev->subsystem_device;
544 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
546 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
548 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
549 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
550 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
551 hw->mac_type = ixgb_82597;
553 /* should never have loaded on this device */
554 printk(KERN_ERR "ixgb: unsupported device id\n");
557 /* enable flow control to be programmed */
560 atomic_set(&adapter->irq_sem, 1);
561 spin_lock_init(&adapter->tx_lock);
567 * ixgb_open - Called when a network interface is made active
568 * @netdev: network interface device structure
570 * Returns 0 on success, negative value on failure
572 * The open entry point is called when a network interface is made
573 * active by the system (IFF_UP). At this point all resources needed
574 * for transmit and receive operations are allocated, the interrupt
575 * handler is registered with the OS, the watchdog timer is started,
576 * and the stack is notified that the interface is ready.
580 ixgb_open(struct net_device *netdev)
582 struct ixgb_adapter *adapter = netdev->priv;
585 /* allocate transmit descriptors */
587 if((err = ixgb_setup_tx_resources(adapter)))
590 /* allocate receive descriptors */
592 if((err = ixgb_setup_rx_resources(adapter)))
595 if((err = ixgb_up(adapter)))
601 ixgb_free_rx_resources(adapter);
603 ixgb_free_tx_resources(adapter);
611 * ixgb_close - Disables a network interface
612 * @netdev: network interface device structure
614 * Returns 0, this is not allowed to fail
616 * The close entry point is called when an interface is de-activated
617 * by the OS. The hardware is still under the drivers control, but
618 * needs to be disabled. A global MAC reset is issued to stop the
619 * hardware, and all transmit and receive resources are freed.
623 ixgb_close(struct net_device *netdev)
625 struct ixgb_adapter *adapter = netdev->priv;
627 ixgb_down(adapter, TRUE);
629 ixgb_free_tx_resources(adapter);
630 ixgb_free_rx_resources(adapter);
636 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
637 * @adapter: board private structure
639 * Return 0 on success, negative on failure
643 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
645 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
646 struct pci_dev *pdev = adapter->pdev;
649 size = sizeof(struct ixgb_buffer) * txdr->count;
650 txdr->buffer_info = vmalloc(size);
651 if(!txdr->buffer_info) {
654 memset(txdr->buffer_info, 0, size);
656 /* round up to nearest 4K */
658 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
659 IXGB_ROUNDUP(txdr->size, 4096);
661 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
663 vfree(txdr->buffer_info);
666 memset(txdr->desc, 0, txdr->size);
668 txdr->next_to_use = 0;
669 txdr->next_to_clean = 0;
675 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
676 * @adapter: board private structure
678 * Configure the Tx unit of the MAC after a reset.
682 ixgb_configure_tx(struct ixgb_adapter *adapter)
684 uint64_t tdba = adapter->tx_ring.dma;
685 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
687 struct ixgb_hw *hw = &adapter->hw;
689 /* Setup the Base and Length of the Tx Descriptor Ring
690 * tx_ring.dma can be either a 32 or 64 bit value
693 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
694 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
696 IXGB_WRITE_REG(hw, TDLEN, tdlen);
698 /* Setup the HW Tx Head and Tail descriptor pointers */
700 IXGB_WRITE_REG(hw, TDH, 0);
701 IXGB_WRITE_REG(hw, TDT, 0);
703 /* don't set up txdctl, it induces performance problems if configured
705 /* Set the Tx Interrupt Delay register */
707 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
709 /* Program the Transmit Control Register */
711 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
712 IXGB_WRITE_REG(hw, TCTL, tctl);
714 /* Setup Transmit Descriptor Settings for this adapter */
715 adapter->tx_cmd_type =
717 | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
721 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
722 * @adapter: board private structure
724 * Returns 0 on success, negative on failure
728 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
730 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
731 struct pci_dev *pdev = adapter->pdev;
734 size = sizeof(struct ixgb_buffer) * rxdr->count;
735 rxdr->buffer_info = vmalloc(size);
736 if(!rxdr->buffer_info) {
739 memset(rxdr->buffer_info, 0, size);
741 /* Round up to nearest 4K */
743 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
744 IXGB_ROUNDUP(rxdr->size, 4096);
746 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
749 vfree(rxdr->buffer_info);
752 memset(rxdr->desc, 0, rxdr->size);
754 rxdr->next_to_clean = 0;
755 rxdr->next_to_use = 0;
761 * ixgb_setup_rctl - configure the receive control register
762 * @adapter: Board private structure
766 ixgb_setup_rctl(struct ixgb_adapter *adapter)
770 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
772 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
775 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
776 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
777 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
779 rctl |= IXGB_RCTL_SECRC;
781 switch (adapter->rx_buffer_len) {
782 case IXGB_RXBUFFER_2048:
784 rctl |= IXGB_RCTL_BSIZE_2048;
786 case IXGB_RXBUFFER_4096:
787 rctl |= IXGB_RCTL_BSIZE_4096;
789 case IXGB_RXBUFFER_8192:
790 rctl |= IXGB_RCTL_BSIZE_8192;
792 case IXGB_RXBUFFER_16384:
793 rctl |= IXGB_RCTL_BSIZE_16384;
797 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
801 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
802 * @adapter: board private structure
804 * Configure the Rx unit of the MAC after a reset.
808 ixgb_configure_rx(struct ixgb_adapter *adapter)
810 uint64_t rdba = adapter->rx_ring.dma;
811 uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
812 struct ixgb_hw *hw = &adapter->hw;
817 /* make sure receives are disabled while setting up the descriptors */
819 rctl = IXGB_READ_REG(hw, RCTL);
820 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
822 /* set the Receive Delay Timer Register */
824 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
826 /* Setup the Base and Length of the Rx Descriptor Ring */
828 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
829 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
831 IXGB_WRITE_REG(hw, RDLEN, rdlen);
833 /* Setup the HW Rx Head and Tail Descriptor Pointers */
834 IXGB_WRITE_REG(hw, RDH, 0);
835 IXGB_WRITE_REG(hw, RDT, 0);
837 /* set up pre-fetching of receive buffers so we get some before we
838 * run out (default hardware behavior is to run out before fetching
839 * more). This sets up to fetch if HTHRESH rx descriptors are avail
840 * and the descriptors in hw cache are below PTHRESH. This avoids
841 * the hardware behavior of fetching <=512 descriptors in a single
842 * burst that pre-empts all other activity, usually causing fifo
844 /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */
845 rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |
846 RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |
847 RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
848 IXGB_WRITE_REG(hw, RXDCTL, rxdctl);
850 /* Enable Receive Checksum Offload for TCP and UDP */
851 if(adapter->rx_csum == TRUE) {
852 rxcsum = IXGB_READ_REG(hw, RXCSUM);
853 rxcsum |= IXGB_RXCSUM_TUOFL;
854 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
857 /* Enable Receives */
859 IXGB_WRITE_REG(hw, RCTL, rctl);
863 * ixgb_free_tx_resources - Free Tx Resources
864 * @adapter: board private structure
866 * Free all transmit software resources
870 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
872 struct pci_dev *pdev = adapter->pdev;
874 ixgb_clean_tx_ring(adapter);
876 vfree(adapter->tx_ring.buffer_info);
877 adapter->tx_ring.buffer_info = NULL;
879 pci_free_consistent(pdev, adapter->tx_ring.size,
880 adapter->tx_ring.desc, adapter->tx_ring.dma);
882 adapter->tx_ring.desc = NULL;
886 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
887 struct ixgb_buffer *buffer_info)
889 struct pci_dev *pdev = adapter->pdev;
890 if(buffer_info->dma) {
895 buffer_info->dma = 0;
897 if(buffer_info->skb) {
898 dev_kfree_skb_any(buffer_info->skb);
899 buffer_info->skb = NULL;
904 * ixgb_clean_tx_ring - Free Tx Buffers
905 * @adapter: board private structure
909 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
911 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
912 struct ixgb_buffer *buffer_info;
916 /* Free all the Tx ring sk_buffs */
918 for(i = 0; i < tx_ring->count; i++) {
919 buffer_info = &tx_ring->buffer_info[i];
920 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
923 size = sizeof(struct ixgb_buffer) * tx_ring->count;
924 memset(tx_ring->buffer_info, 0, size);
926 /* Zero out the descriptor ring */
928 memset(tx_ring->desc, 0, tx_ring->size);
930 tx_ring->next_to_use = 0;
931 tx_ring->next_to_clean = 0;
933 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
934 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
938 * ixgb_free_rx_resources - Free Rx Resources
939 * @adapter: board private structure
941 * Free all receive software resources
945 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
947 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
948 struct pci_dev *pdev = adapter->pdev;
950 ixgb_clean_rx_ring(adapter);
952 vfree(rx_ring->buffer_info);
953 rx_ring->buffer_info = NULL;
955 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
957 rx_ring->desc = NULL;
961 * ixgb_clean_rx_ring - Free Rx Buffers
962 * @adapter: board private structure
966 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
968 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
969 struct ixgb_buffer *buffer_info;
970 struct pci_dev *pdev = adapter->pdev;
974 /* Free all the Rx ring sk_buffs */
976 for(i = 0; i < rx_ring->count; i++) {
977 buffer_info = &rx_ring->buffer_info[i];
978 if(buffer_info->skb) {
980 pci_unmap_single(pdev,
985 dev_kfree_skb(buffer_info->skb);
987 buffer_info->skb = NULL;
991 size = sizeof(struct ixgb_buffer) * rx_ring->count;
992 memset(rx_ring->buffer_info, 0, size);
994 /* Zero out the descriptor ring */
996 memset(rx_ring->desc, 0, rx_ring->size);
998 rx_ring->next_to_clean = 0;
999 rx_ring->next_to_use = 0;
1001 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1002 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1006 * ixgb_set_mac - Change the Ethernet Address of the NIC
1007 * @netdev: network interface device structure
1008 * @p: pointer to an address structure
1010 * Returns 0 on success, negative on failure
1014 ixgb_set_mac(struct net_device *netdev, void *p)
1016 struct ixgb_adapter *adapter = netdev->priv;
1017 struct sockaddr *addr = p;
1019 if(!is_valid_ether_addr(addr->sa_data))
1020 return -EADDRNOTAVAIL;
1022 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1024 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1030 * ixgb_set_multi - Multicast and Promiscuous mode set
1031 * @netdev: network interface device structure
1033 * The set_multi entry point is called whenever the multicast address
1034 * list or the network interface flags are updated. This routine is
1035 * responsible for configuring the hardware for proper multicast,
1036 * promiscuous mode, and all-multi behavior.
1040 ixgb_set_multi(struct net_device *netdev)
1042 struct ixgb_adapter *adapter = netdev->priv;
1043 struct ixgb_hw *hw = &adapter->hw;
1044 struct dev_mc_list *mc_ptr;
1048 /* Check for Promiscuous and All Multicast modes */
1050 rctl = IXGB_READ_REG(hw, RCTL);
1052 if(netdev->flags & IFF_PROMISC) {
1053 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1054 } else if(netdev->flags & IFF_ALLMULTI) {
1055 rctl |= IXGB_RCTL_MPE;
1056 rctl &= ~IXGB_RCTL_UPE;
1058 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1061 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1062 rctl |= IXGB_RCTL_MPE;
1063 IXGB_WRITE_REG(hw, RCTL, rctl);
1065 uint8_t mta[netdev->mc_count * IXGB_ETH_LENGTH_OF_ADDRESS];
1067 IXGB_WRITE_REG(hw, RCTL, rctl);
1069 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1070 i++, mc_ptr = mc_ptr->next)
1071 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1072 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1074 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1079 * ixgb_watchdog - Timer Call-back
1080 * @data: pointer to netdev cast into an unsigned long
1084 ixgb_watchdog(unsigned long data)
1086 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1087 struct net_device *netdev = adapter->netdev;
1088 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1090 ixgb_check_for_link(&adapter->hw);
1092 if (ixgb_check_for_bad_link(&adapter->hw)) {
1093 /* force the reset path */
1094 netif_stop_queue(netdev);
1097 if(adapter->hw.link_up) {
1098 if(!netif_carrier_ok(netdev)) {
1099 printk(KERN_INFO "ixgb: %s NIC Link is Up %d Mbps %s\n",
1100 netdev->name, 10000, "Full Duplex");
1101 adapter->link_speed = 10000;
1102 adapter->link_duplex = FULL_DUPLEX;
1103 netif_carrier_on(netdev);
1104 netif_wake_queue(netdev);
1107 if(netif_carrier_ok(netdev)) {
1108 adapter->link_speed = 0;
1109 adapter->link_duplex = 0;
1111 "ixgb: %s NIC Link is Down\n",
1113 netif_carrier_off(netdev);
1114 netif_stop_queue(netdev);
1119 ixgb_update_stats(adapter);
1121 if(!netif_carrier_ok(netdev)) {
1122 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1123 /* We've lost link, so the controller stops DMA,
1124 * but we've got queued Tx work that's never going
1125 * to get done, so reset controller to flush Tx.
1126 * (Do the reset outside of interrupt context). */
1127 schedule_work(&adapter->tx_timeout_task);
1131 /* Force detection of hung controller every watchdog period */
1132 adapter->detect_tx_hung = TRUE;
1134 /* generate an interrupt to force clean up of any stragglers */
1135 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1137 /* Reset the timer */
1138 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1141 #define IXGB_TX_FLAGS_CSUM 0x00000001
1142 #define IXGB_TX_FLAGS_VLAN 0x00000002
1143 #define IXGB_TX_FLAGS_TSO 0x00000004
1146 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1149 struct ixgb_context_desc *context_desc;
1151 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1152 uint16_t ipcse, tucse, mss;
1155 if(likely(skb_shinfo(skb)->tso_size)) {
1156 if (skb_header_cloned(skb)) {
1157 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1162 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1163 mss = skb_shinfo(skb)->tso_size;
1164 skb->nh.iph->tot_len = 0;
1165 skb->nh.iph->check = 0;
1166 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1169 ipcss = skb->nh.raw - skb->data;
1170 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1171 ipcse = skb->h.raw - skb->data - 1;
1172 tucss = skb->h.raw - skb->data;
1173 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1176 i = adapter->tx_ring.next_to_use;
1177 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1179 context_desc->ipcss = ipcss;
1180 context_desc->ipcso = ipcso;
1181 context_desc->ipcse = cpu_to_le16(ipcse);
1182 context_desc->tucss = tucss;
1183 context_desc->tucso = tucso;
1184 context_desc->tucse = cpu_to_le16(tucse);
1185 context_desc->mss = cpu_to_le16(mss);
1186 context_desc->hdr_len = hdr_len;
1187 context_desc->status = 0;
1188 context_desc->cmd_type_len = cpu_to_le32(
1189 IXGB_CONTEXT_DESC_TYPE
1190 | IXGB_CONTEXT_DESC_CMD_TSE
1191 | IXGB_CONTEXT_DESC_CMD_IP
1192 | IXGB_CONTEXT_DESC_CMD_TCP
1193 | IXGB_CONTEXT_DESC_CMD_IDE
1194 | (skb->len - (hdr_len)));
1197 if(++i == adapter->tx_ring.count) i = 0;
1198 adapter->tx_ring.next_to_use = i;
1207 static inline boolean_t
1208 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1210 struct ixgb_context_desc *context_desc;
1214 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1215 css = skb->h.raw - skb->data;
1216 cso = (skb->h.raw + skb->csum) - skb->data;
1218 i = adapter->tx_ring.next_to_use;
1219 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1221 context_desc->tucss = css;
1222 context_desc->tucso = cso;
1223 context_desc->tucse = 0;
1224 /* zero out any previously existing data in one instruction */
1225 *(uint32_t *)&(context_desc->ipcss) = 0;
1226 context_desc->status = 0;
1227 context_desc->hdr_len = 0;
1228 context_desc->mss = 0;
1229 context_desc->cmd_type_len =
1230 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1231 | IXGB_TX_DESC_CMD_IDE);
1233 if(++i == adapter->tx_ring.count) i = 0;
1234 adapter->tx_ring.next_to_use = i;
1242 #define IXGB_MAX_TXD_PWR 14
1243 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1246 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1249 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1250 struct ixgb_buffer *buffer_info;
1252 unsigned int offset = 0, size, count = 0, i;
1254 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1256 len -= skb->data_len;
1258 i = tx_ring->next_to_use;
1261 buffer_info = &tx_ring->buffer_info[i];
1262 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1263 buffer_info->length = size;
1265 pci_map_single(adapter->pdev,
1269 buffer_info->time_stamp = jiffies;
1274 if(++i == tx_ring->count) i = 0;
1277 for(f = 0; f < nr_frags; f++) {
1278 struct skb_frag_struct *frag;
1280 frag = &skb_shinfo(skb)->frags[f];
1285 buffer_info = &tx_ring->buffer_info[i];
1286 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1287 buffer_info->length = size;
1289 pci_map_page(adapter->pdev,
1291 frag->page_offset + offset,
1294 buffer_info->time_stamp = jiffies;
1299 if(++i == tx_ring->count) i = 0;
1302 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1303 tx_ring->buffer_info[i].skb = skb;
1304 tx_ring->buffer_info[first].next_to_watch = i;
1310 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1312 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1313 struct ixgb_tx_desc *tx_desc = NULL;
1314 struct ixgb_buffer *buffer_info;
1315 uint32_t cmd_type_len = adapter->tx_cmd_type;
1320 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1321 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1322 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1325 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1326 popts |= IXGB_TX_DESC_POPTS_TXSM;
1328 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1329 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1332 i = tx_ring->next_to_use;
1335 buffer_info = &tx_ring->buffer_info[i];
1336 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1337 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1338 tx_desc->cmd_type_len =
1339 cpu_to_le32(cmd_type_len | buffer_info->length);
1340 tx_desc->status = status;
1341 tx_desc->popts = popts;
1342 tx_desc->vlan = cpu_to_le16(vlan_id);
1344 if(++i == tx_ring->count) i = 0;
1347 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1348 | IXGB_TX_DESC_CMD_RS );
1350 /* Force memory writes to complete before letting h/w
1351 * know there are new descriptors to fetch. (Only
1352 * applicable for weak-ordered memory model archs,
1353 * such as IA-64). */
1356 tx_ring->next_to_use = i;
1357 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1360 /* Tx Descriptors needed, worst case */
1361 #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1362 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1363 #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \
1364 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1
1367 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1369 struct ixgb_adapter *adapter = netdev->priv;
1371 unsigned int tx_flags = 0;
1372 unsigned long flags;
1377 dev_kfree_skb_any(skb);
1381 spin_lock_irqsave(&adapter->tx_lock, flags);
1382 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) {
1383 netif_stop_queue(netdev);
1384 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1387 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1389 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1390 tx_flags |= IXGB_TX_FLAGS_VLAN;
1391 vlan_id = vlan_tx_tag_get(skb);
1394 first = adapter->tx_ring.next_to_use;
1396 tso = ixgb_tso(adapter, skb);
1398 dev_kfree_skb_any(skb);
1399 return NETDEV_TX_OK;
1403 tx_flags |= IXGB_TX_FLAGS_TSO;
1404 else if(ixgb_tx_csum(adapter, skb))
1405 tx_flags |= IXGB_TX_FLAGS_CSUM;
1407 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1410 netdev->trans_start = jiffies;
1416 * ixgb_tx_timeout - Respond to a Tx Hang
1417 * @netdev: network interface device structure
1421 ixgb_tx_timeout(struct net_device *netdev)
1423 struct ixgb_adapter *adapter = netdev->priv;
1425 /* Do the reset outside of interrupt context */
1426 schedule_work(&adapter->tx_timeout_task);
1430 ixgb_tx_timeout_task(struct net_device *netdev)
1432 struct ixgb_adapter *adapter = netdev->priv;
1434 ixgb_down(adapter, TRUE);
1439 * ixgb_get_stats - Get System Network Statistics
1440 * @netdev: network interface device structure
1442 * Returns the address of the device statistics structure.
1443 * The statistics are actually updated from the timer callback.
1446 static struct net_device_stats *
1447 ixgb_get_stats(struct net_device *netdev)
1449 struct ixgb_adapter *adapter = netdev->priv;
1451 return &adapter->net_stats;
1455 * ixgb_change_mtu - Change the Maximum Transfer Unit
1456 * @netdev: network interface device structure
1457 * @new_mtu: new value for maximum frame size
1459 * Returns 0 on success, negative on failure
1463 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1465 struct ixgb_adapter *adapter = netdev->priv;
1466 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1467 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1470 if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1471 || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
1472 IXGB_ERR("Invalid MTU setting\n");
1476 if((max_frame <= IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1477 || (max_frame <= IXGB_RXBUFFER_2048)) {
1478 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
1480 } else if(max_frame <= IXGB_RXBUFFER_4096) {
1481 adapter->rx_buffer_len = IXGB_RXBUFFER_4096;
1483 } else if(max_frame <= IXGB_RXBUFFER_8192) {
1484 adapter->rx_buffer_len = IXGB_RXBUFFER_8192;
1487 adapter->rx_buffer_len = IXGB_RXBUFFER_16384;
1490 netdev->mtu = new_mtu;
1492 if(old_max_frame != max_frame && netif_running(netdev)) {
1494 ixgb_down(adapter, TRUE);
1502 * ixgb_update_stats - Update the board statistics counters.
1503 * @adapter: board private structure
1507 ixgb_update_stats(struct ixgb_adapter *adapter)
1509 struct net_device *netdev = adapter->netdev;
1511 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1512 (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1513 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1514 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1515 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1516 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1518 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1519 /* fix up multicast stats by removing broadcasts */
1522 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1523 adapter->stats.mprch += (multi >> 32);
1524 adapter->stats.bprcl += bcast_l;
1525 adapter->stats.bprch += bcast_h;
1527 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1528 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1529 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1530 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1532 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1533 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1534 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1535 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1536 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1537 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1538 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1539 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1540 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1541 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1542 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1543 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1544 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1545 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1546 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1547 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1548 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1549 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1550 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1551 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1552 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1553 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1554 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1555 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1556 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1557 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1558 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1559 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1560 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1561 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1562 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1563 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1564 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1565 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1566 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1567 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1568 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1569 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1570 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1571 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1572 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1573 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1574 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1575 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1576 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1577 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1578 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1579 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1580 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1581 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1582 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1583 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1584 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1585 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1586 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1587 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1589 /* Fill out the OS statistics structure */
1591 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1592 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1593 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1594 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1595 adapter->net_stats.multicast = adapter->stats.mprcl;
1596 adapter->net_stats.collisions = 0;
1598 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1599 * with a length in the type/len field */
1600 adapter->net_stats.rx_errors =
1601 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1602 adapter->stats.ruc +
1603 adapter->stats.roc /*+ adapter->stats.rlec */ +
1604 adapter->stats.icbc +
1605 adapter->stats.ecbc + adapter->stats.mpc;
1607 adapter->net_stats.rx_dropped = adapter->stats.mpc;
1610 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1613 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1614 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1615 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1616 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1618 adapter->net_stats.tx_errors = 0;
1619 adapter->net_stats.rx_frame_errors = 0;
1620 adapter->net_stats.tx_aborted_errors = 0;
1621 adapter->net_stats.tx_carrier_errors = 0;
1622 adapter->net_stats.tx_fifo_errors = 0;
1623 adapter->net_stats.tx_heartbeat_errors = 0;
1624 adapter->net_stats.tx_window_errors = 0;
1627 #define IXGB_MAX_INTR 10
1629 * ixgb_intr - Interrupt Handler
1630 * @irq: interrupt number
1631 * @data: pointer to a network interface device structure
1632 * @pt_regs: CPU registers structure
1636 ixgb_intr(int irq, void *data, struct pt_regs *regs)
1638 struct net_device *netdev = data;
1639 struct ixgb_adapter *adapter = netdev->priv;
1640 struct ixgb_hw *hw = &adapter->hw;
1641 uint32_t icr = IXGB_READ_REG(hw, ICR);
1642 #ifndef CONFIG_IXGB_NAPI
1647 return IRQ_NONE; /* Not our interrupt */
1649 if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) {
1650 mod_timer(&adapter->watchdog_timer, jiffies);
1653 #ifdef CONFIG_IXGB_NAPI
1654 if(netif_rx_schedule_prep(netdev)) {
1656 /* Disable interrupts and register for poll. The flush
1657 of the posted write is intentionally left out.
1660 atomic_inc(&adapter->irq_sem);
1661 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1662 __netif_rx_schedule(netdev);
1665 /* yes, that is actually a & and it is meant to make sure that
1666 * every pass through this for loop checks both receive and
1667 * transmit queues for completed descriptors, intended to
1668 * avoid starvation issues and assist tx/rx fairness. */
1669 for(i = 0; i < IXGB_MAX_INTR; i++)
1670 if(!ixgb_clean_rx_irq(adapter) &
1671 !ixgb_clean_tx_irq(adapter))
1677 #ifdef CONFIG_IXGB_NAPI
1679 * ixgb_clean - NAPI Rx polling callback
1680 * @adapter: board private structure
1684 ixgb_clean(struct net_device *netdev, int *budget)
1686 struct ixgb_adapter *adapter = netdev->priv;
1687 int work_to_do = min(*budget, netdev->quota);
1691 tx_cleaned = ixgb_clean_tx_irq(adapter);
1692 ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
1694 *budget -= work_done;
1695 netdev->quota -= work_done;
1697 /* if no Tx and not enough Rx work done, exit the polling mode */
1698 if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
1699 netif_rx_complete(netdev);
1700 ixgb_irq_enable(adapter);
1709 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1710 * @adapter: board private structure
1714 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1716 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1717 struct net_device *netdev = adapter->netdev;
1718 struct ixgb_tx_desc *tx_desc, *eop_desc;
1719 struct ixgb_buffer *buffer_info;
1720 unsigned int i, eop;
1721 boolean_t cleaned = FALSE;
1723 i = tx_ring->next_to_clean;
1724 eop = tx_ring->buffer_info[i].next_to_watch;
1725 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1727 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1729 for(cleaned = FALSE; !cleaned; ) {
1730 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1731 buffer_info = &tx_ring->buffer_info[i];
1734 & (IXGB_TX_DESC_POPTS_TXSM |
1735 IXGB_TX_DESC_POPTS_IXSM))
1736 adapter->hw_csum_tx_good++;
1738 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1740 *(uint32_t *)&(tx_desc->status) = 0;
1742 cleaned = (i == eop);
1743 if(++i == tx_ring->count) i = 0;
1746 eop = tx_ring->buffer_info[i].next_to_watch;
1747 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1750 tx_ring->next_to_clean = i;
1752 spin_lock(&adapter->tx_lock);
1753 if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1754 (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) {
1756 netif_wake_queue(netdev);
1758 spin_unlock(&adapter->tx_lock);
1760 if(adapter->detect_tx_hung) {
1761 /* detect a transmit hang in hardware, this serializes the
1762 * check with the clearing of time_stamp and movement of i */
1763 adapter->detect_tx_hung = FALSE;
1764 if(tx_ring->buffer_info[i].dma &&
1765 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
1766 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1768 netif_stop_queue(netdev);
1775 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1776 * @adapter: board private structure
1777 * @rx_desc: receive descriptor
1778 * @sk_buff: socket buffer with received data
1782 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1783 struct ixgb_rx_desc *rx_desc,
1784 struct sk_buff *skb)
1786 /* Ignore Checksum bit is set OR
1787 * TCP Checksum has not been calculated
1789 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1790 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1791 skb->ip_summed = CHECKSUM_NONE;
1795 /* At this point we know the hardware did the TCP checksum */
1796 /* now look at the TCP checksum error bit */
1797 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1798 /* let the stack verify checksum errors */
1799 skb->ip_summed = CHECKSUM_NONE;
1800 adapter->hw_csum_rx_error++;
1802 /* TCP checksum is good */
1803 skb->ip_summed = CHECKSUM_UNNECESSARY;
1804 adapter->hw_csum_rx_good++;
1809 * ixgb_clean_rx_irq - Send received data up the network stack,
1810 * @adapter: board private structure
1814 #ifdef CONFIG_IXGB_NAPI
1815 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1817 ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1820 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1821 struct net_device *netdev = adapter->netdev;
1822 struct pci_dev *pdev = adapter->pdev;
1823 struct ixgb_rx_desc *rx_desc, *next_rxd;
1824 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1825 struct sk_buff *skb, *next_skb;
1828 boolean_t cleaned = FALSE;
1830 i = rx_ring->next_to_clean;
1831 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1832 buffer_info = &rx_ring->buffer_info[i];
1834 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1836 #ifdef CONFIG_IXGB_NAPI
1837 if(*work_done >= work_to_do)
1842 skb = buffer_info->skb;
1843 prefetch(skb->data);
1845 if(++i == rx_ring->count) i = 0;
1846 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1849 if((j = i + 1) == rx_ring->count) j = 0;
1850 next2_buffer = &rx_ring->buffer_info[j];
1851 prefetch(next2_buffer);
1853 next_buffer = &rx_ring->buffer_info[i];
1854 next_skb = next_buffer->skb;
1860 pci_unmap_single(pdev,
1862 buffer_info->length,
1863 PCI_DMA_FROMDEVICE);
1865 length = le16_to_cpu(rx_desc->length);
1867 if(unlikely(!(rx_desc->status & IXGB_RX_DESC_STATUS_EOP))) {
1869 /* All receives must fit into a single buffer */
1871 IXGB_DBG("Receive packet consumed multiple buffers "
1872 "length<%x>\n", length);
1874 dev_kfree_skb_irq(skb);
1875 rx_desc->status = 0;
1876 buffer_info->skb = NULL;
1879 buffer_info = next_buffer;
1883 if (unlikely(rx_desc->errors
1884 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1885 | IXGB_RX_DESC_ERRORS_P |
1886 IXGB_RX_DESC_ERRORS_RXE))) {
1888 dev_kfree_skb_irq(skb);
1889 rx_desc->status = 0;
1890 buffer_info->skb = NULL;
1893 buffer_info = next_buffer;
1898 skb_put(skb, length);
1900 /* Receive Checksum Offload */
1901 ixgb_rx_checksum(adapter, rx_desc, skb);
1903 skb->protocol = eth_type_trans(skb, netdev);
1904 #ifdef CONFIG_IXGB_NAPI
1905 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1906 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
1907 le16_to_cpu(rx_desc->special) &
1908 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1910 netif_receive_skb(skb);
1912 #else /* CONFIG_IXGB_NAPI */
1913 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1914 vlan_hwaccel_rx(skb, adapter->vlgrp,
1915 le16_to_cpu(rx_desc->special) &
1916 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1920 #endif /* CONFIG_IXGB_NAPI */
1921 netdev->last_rx = jiffies;
1923 rx_desc->status = 0;
1924 buffer_info->skb = NULL;
1927 buffer_info = next_buffer;
1930 rx_ring->next_to_clean = i;
1932 ixgb_alloc_rx_buffers(adapter);
1938 * ixgb_alloc_rx_buffers - Replace used receive buffers
1939 * @adapter: address of board private structure
1943 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
1945 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1946 struct net_device *netdev = adapter->netdev;
1947 struct pci_dev *pdev = adapter->pdev;
1948 struct ixgb_rx_desc *rx_desc;
1949 struct ixgb_buffer *buffer_info;
1950 struct sk_buff *skb;
1952 int num_group_tail_writes;
1955 i = rx_ring->next_to_use;
1956 buffer_info = &rx_ring->buffer_info[i];
1957 cleancount = IXGB_DESC_UNUSED(rx_ring);
1959 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
1961 /* leave three descriptors unused */
1962 while(--cleancount > 2) {
1963 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1965 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1967 if(unlikely(!skb)) {
1968 /* Better luck next round */
1972 /* Make buffer alignment 2 beyond a 16 byte boundary
1973 * this will result in a 16 byte aligned IP header after
1974 * the 14 byte MAC header is removed
1976 skb_reserve(skb, NET_IP_ALIGN);
1980 buffer_info->skb = skb;
1981 buffer_info->length = adapter->rx_buffer_len;
1983 pci_map_single(pdev,
1985 adapter->rx_buffer_len,
1986 PCI_DMA_FROMDEVICE);
1988 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1989 /* guarantee DD bit not set now before h/w gets descriptor
1990 * this is the rest of the workaround for h/w double
1992 rx_desc->status = 0;
1994 if((i & ~(num_group_tail_writes- 1)) == i) {
1995 /* Force memory writes to complete before letting h/w
1996 * know there are new descriptors to fetch. (Only
1997 * applicable for weak-ordered memory model archs,
1998 * such as IA-64). */
2001 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2004 if(++i == rx_ring->count) i = 0;
2005 buffer_info = &rx_ring->buffer_info[i];
2008 rx_ring->next_to_use = i;
2012 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2014 * @param netdev network interface device structure
2015 * @param grp indicates to enable or disable tagging/stripping
2018 ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2020 struct ixgb_adapter *adapter = netdev->priv;
2021 uint32_t ctrl, rctl;
2023 ixgb_irq_disable(adapter);
2024 adapter->vlgrp = grp;
2027 /* enable VLAN tag insert/strip */
2028 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2029 ctrl |= IXGB_CTRL0_VME;
2030 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2032 /* enable VLAN receive filtering */
2034 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2035 rctl |= IXGB_RCTL_VFE;
2036 rctl &= ~IXGB_RCTL_CFIEN;
2037 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2039 /* disable VLAN tag insert/strip */
2041 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2042 ctrl &= ~IXGB_CTRL0_VME;
2043 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2045 /* disable VLAN filtering */
2047 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2048 rctl &= ~IXGB_RCTL_VFE;
2049 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2052 ixgb_irq_enable(adapter);
2056 ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
2058 struct ixgb_adapter *adapter = netdev->priv;
2059 uint32_t vfta, index;
2061 /* add VID to filter table */
2063 index = (vid >> 5) & 0x7F;
2064 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2065 vfta |= (1 << (vid & 0x1F));
2066 ixgb_write_vfta(&adapter->hw, index, vfta);
2070 ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2072 struct ixgb_adapter *adapter = netdev->priv;
2073 uint32_t vfta, index;
2075 ixgb_irq_disable(adapter);
2078 adapter->vlgrp->vlan_devices[vid] = NULL;
2080 ixgb_irq_enable(adapter);
2082 /* remove VID from filter table*/
2084 index = (vid >> 5) & 0x7F;
2085 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2086 vfta &= ~(1 << (vid & 0x1F));
2087 ixgb_write_vfta(&adapter->hw, index, vfta);
2091 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2093 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2095 if(adapter->vlgrp) {
2097 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2098 if(!adapter->vlgrp->vlan_devices[vid])
2100 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2105 #ifdef CONFIG_NET_POLL_CONTROLLER
2107 * Polling 'interrupt' - used by things like netconsole to send skbs
2108 * without having to re-enable interrupts. It's not called while
2109 * the interrupt routine is executing.
2112 static void ixgb_netpoll(struct net_device *dev)
2114 struct ixgb_adapter *adapter = dev->priv;
2115 disable_irq(adapter->pdev->irq);
2116 ixgb_intr(adapter->pdev->irq, dev, NULL);
2117 enable_irq(adapter->pdev->irq);