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.95-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);
107 #ifdef CONFIG_IXGB_NAPI
108 static int ixgb_clean(struct net_device *netdev, int *budget);
109 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
110 int *work_done, int work_to_do);
112 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
114 static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter);
115 void ixgb_set_ethtool_ops(struct net_device *netdev);
116 static void ixgb_tx_timeout(struct net_device *dev);
117 static void ixgb_tx_timeout_task(struct net_device *dev);
118 static void ixgb_vlan_rx_register(struct net_device *netdev,
119 struct vlan_group *grp);
120 static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
121 static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
122 static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
124 #ifdef CONFIG_NET_POLL_CONTROLLER
125 /* for netdump / net console */
126 static void ixgb_netpoll(struct net_device *dev);
129 /* Exported from other modules */
131 extern void ixgb_check_options(struct ixgb_adapter *adapter);
133 static struct pci_driver ixgb_driver = {
134 .name = ixgb_driver_name,
135 .id_table = ixgb_pci_tbl,
137 .remove = __devexit_p(ixgb_remove),
140 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
141 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
142 MODULE_LICENSE("GPL");
144 /* some defines for controlling descriptor fetches in h/w */
145 #define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
146 #define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is
147 pushed this many descriptors from head */
148 #define RXDCTL_WTHRESH_DEFAULT 16 /* chip writes back at this many or RXT0 */
151 * ixgb_init_module - Driver Registration Routine
153 * ixgb_init_module is the first routine called when the driver is
154 * loaded. All it does is register with the PCI subsystem.
158 ixgb_init_module(void)
160 printk(KERN_INFO "%s - version %s\n",
161 ixgb_driver_string, ixgb_driver_version);
163 printk(KERN_INFO "%s\n", ixgb_copyright);
165 return pci_module_init(&ixgb_driver);
168 module_init(ixgb_init_module);
171 * ixgb_exit_module - Driver Exit Cleanup Routine
173 * ixgb_exit_module is called just before the driver is removed
178 ixgb_exit_module(void)
180 pci_unregister_driver(&ixgb_driver);
183 module_exit(ixgb_exit_module);
186 * ixgb_irq_disable - Mask off interrupt generation on the NIC
187 * @adapter: board private structure
191 ixgb_irq_disable(struct ixgb_adapter *adapter)
193 atomic_inc(&adapter->irq_sem);
194 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
195 IXGB_WRITE_FLUSH(&adapter->hw);
196 synchronize_irq(adapter->pdev->irq);
200 * ixgb_irq_enable - Enable default interrupt generation settings
201 * @adapter: board private structure
205 ixgb_irq_enable(struct ixgb_adapter *adapter)
207 if(atomic_dec_and_test(&adapter->irq_sem)) {
208 IXGB_WRITE_REG(&adapter->hw, IMS,
209 IXGB_INT_RXT0 | IXGB_INT_RXDMT0 | IXGB_INT_TXDW |
211 IXGB_WRITE_FLUSH(&adapter->hw);
216 ixgb_up(struct ixgb_adapter *adapter)
218 struct net_device *netdev = adapter->netdev;
220 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
221 struct ixgb_hw *hw = &adapter->hw;
223 /* hardware has been reset, we need to reload some things */
225 ixgb_set_multi(netdev);
227 ixgb_restore_vlan(adapter);
229 ixgb_configure_tx(adapter);
230 ixgb_setup_rctl(adapter);
231 ixgb_configure_rx(adapter);
232 ixgb_alloc_rx_buffers(adapter);
234 #ifdef CONFIG_PCI_MSI
236 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) &
237 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE;
238 adapter->have_msi = TRUE;
241 adapter->have_msi = FALSE;
242 else if((err = pci_enable_msi(adapter->pdev))) {
244 "Unable to allocate MSI interrupt Error: %d\n", err);
245 adapter->have_msi = FALSE;
246 /* proceed to try to request regular interrupt */
251 if((err = request_irq(adapter->pdev->irq, &ixgb_intr,
252 SA_SHIRQ | SA_SAMPLE_RANDOM,
253 netdev->name, netdev)))
256 /* disable interrupts and get the hardware into a known state */
257 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
259 if((hw->max_frame_size != max_frame) ||
260 (hw->max_frame_size !=
261 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
263 hw->max_frame_size = max_frame;
265 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
267 if(hw->max_frame_size >
268 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
269 uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0);
271 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
272 ctrl0 |= IXGB_CTRL0_JFE;
273 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
278 mod_timer(&adapter->watchdog_timer, jiffies);
279 ixgb_irq_enable(adapter);
281 #ifdef CONFIG_IXGB_NAPI
282 netif_poll_enable(netdev);
288 ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
290 struct net_device *netdev = adapter->netdev;
292 ixgb_irq_disable(adapter);
293 free_irq(adapter->pdev->irq, netdev);
294 #ifdef CONFIG_PCI_MSI
295 if(adapter->have_msi == TRUE)
296 pci_disable_msi(adapter->pdev);
300 del_timer_sync(&adapter->watchdog_timer);
301 #ifdef CONFIG_IXGB_NAPI
302 netif_poll_disable(netdev);
304 adapter->link_speed = 0;
305 adapter->link_duplex = 0;
306 netif_carrier_off(netdev);
307 netif_stop_queue(netdev);
310 ixgb_clean_tx_ring(adapter);
311 ixgb_clean_rx_ring(adapter);
315 ixgb_reset(struct ixgb_adapter *adapter)
318 ixgb_adapter_stop(&adapter->hw);
319 if(!ixgb_init_hw(&adapter->hw))
320 IXGB_DBG("ixgb_init_hw failed.\n");
324 * ixgb_probe - Device Initialization Routine
325 * @pdev: PCI device information struct
326 * @ent: entry in ixgb_pci_tbl
328 * Returns 0 on success, negative on failure
330 * ixgb_probe initializes an adapter identified by a pci_dev structure.
331 * The OS initialization, configuring of the adapter private structure,
332 * and a hardware reset occur.
336 ixgb_probe(struct pci_dev *pdev,
337 const struct pci_device_id *ent)
339 struct net_device *netdev = NULL;
340 struct ixgb_adapter *adapter;
341 static int cards_found = 0;
342 unsigned long mmio_start;
348 if((err = pci_enable_device(pdev)))
351 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
354 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
355 IXGB_ERR("No usable DMA configuration, aborting\n");
361 if((err = pci_request_regions(pdev, ixgb_driver_name)))
364 pci_set_master(pdev);
366 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
369 goto err_alloc_etherdev;
372 SET_MODULE_OWNER(netdev);
373 SET_NETDEV_DEV(netdev, &pdev->dev);
375 pci_set_drvdata(pdev, netdev);
376 adapter = netdev->priv;
377 adapter->netdev = netdev;
378 adapter->pdev = pdev;
379 adapter->hw.back = adapter;
381 mmio_start = pci_resource_start(pdev, BAR_0);
382 mmio_len = pci_resource_len(pdev, BAR_0);
384 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
385 if(!adapter->hw.hw_addr) {
390 for(i = BAR_1; i <= BAR_5; i++) {
391 if(pci_resource_len(pdev, i) == 0)
393 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
394 adapter->hw.io_base = pci_resource_start(pdev, i);
399 netdev->open = &ixgb_open;
400 netdev->stop = &ixgb_close;
401 netdev->hard_start_xmit = &ixgb_xmit_frame;
402 netdev->get_stats = &ixgb_get_stats;
403 netdev->set_multicast_list = &ixgb_set_multi;
404 netdev->set_mac_address = &ixgb_set_mac;
405 netdev->change_mtu = &ixgb_change_mtu;
406 ixgb_set_ethtool_ops(netdev);
407 netdev->tx_timeout = &ixgb_tx_timeout;
408 netdev->watchdog_timeo = HZ;
409 #ifdef CONFIG_IXGB_NAPI
410 netdev->poll = &ixgb_clean;
413 netdev->vlan_rx_register = ixgb_vlan_rx_register;
414 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
415 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
416 #ifdef CONFIG_NET_POLL_CONTROLLER
417 netdev->poll_controller = ixgb_netpoll;
420 netdev->mem_start = mmio_start;
421 netdev->mem_end = mmio_start + mmio_len;
422 netdev->base_addr = adapter->hw.io_base;
424 adapter->bd_number = cards_found;
425 adapter->link_speed = 0;
426 adapter->link_duplex = 0;
428 /* setup the private structure */
430 if((err = ixgb_sw_init(adapter)))
433 netdev->features = NETIF_F_SG |
437 NETIF_F_HW_VLAN_FILTER;
439 netdev->features |= NETIF_F_TSO;
443 netdev->features |= NETIF_F_HIGHDMA;
445 /* make sure the EEPROM is good */
447 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
448 printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n");
453 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
455 if(!is_valid_ether_addr(netdev->dev_addr)) {
460 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
462 init_timer(&adapter->watchdog_timer);
463 adapter->watchdog_timer.function = &ixgb_watchdog;
464 adapter->watchdog_timer.data = (unsigned long)adapter;
466 INIT_WORK(&adapter->tx_timeout_task,
467 (void (*)(void *))ixgb_tx_timeout_task, netdev);
469 if((err = register_netdev(netdev)))
472 /* we're going to reset, so assume we have no link for now */
474 netif_carrier_off(netdev);
475 netif_stop_queue(netdev);
477 printk(KERN_INFO "%s: Intel(R) PRO/10GbE Network Connection\n",
479 ixgb_check_options(adapter);
480 /* reset the hardware with the new settings */
490 iounmap(adapter->hw.hw_addr);
494 pci_release_regions(pdev);
499 * ixgb_remove - Device Removal Routine
500 * @pdev: PCI device information struct
502 * ixgb_remove is called by the PCI subsystem to alert the driver
503 * that it should release a PCI device. The could be caused by a
504 * Hot-Plug event, or because the driver is going to be removed from
508 static void __devexit
509 ixgb_remove(struct pci_dev *pdev)
511 struct net_device *netdev = pci_get_drvdata(pdev);
512 struct ixgb_adapter *adapter = netdev->priv;
514 unregister_netdev(netdev);
516 iounmap(adapter->hw.hw_addr);
517 pci_release_regions(pdev);
523 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
524 * @adapter: board private structure to initialize
526 * ixgb_sw_init initializes the Adapter private data structure.
527 * Fields are initialized based on PCI device information and
528 * OS network device settings (MTU size).
532 ixgb_sw_init(struct ixgb_adapter *adapter)
534 struct ixgb_hw *hw = &adapter->hw;
535 struct net_device *netdev = adapter->netdev;
536 struct pci_dev *pdev = adapter->pdev;
538 /* PCI config space info */
540 hw->vendor_id = pdev->vendor;
541 hw->device_id = pdev->device;
542 hw->subsystem_vendor_id = pdev->subsystem_vendor;
543 hw->subsystem_id = pdev->subsystem_device;
545 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
547 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
549 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
550 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
551 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
552 hw->mac_type = ixgb_82597;
554 /* should never have loaded on this device */
555 printk(KERN_ERR "ixgb: unsupported device id\n");
558 /* enable flow control to be programmed */
561 atomic_set(&adapter->irq_sem, 1);
562 spin_lock_init(&adapter->tx_lock);
568 * ixgb_open - Called when a network interface is made active
569 * @netdev: network interface device structure
571 * Returns 0 on success, negative value on failure
573 * The open entry point is called when a network interface is made
574 * active by the system (IFF_UP). At this point all resources needed
575 * for transmit and receive operations are allocated, the interrupt
576 * handler is registered with the OS, the watchdog timer is started,
577 * and the stack is notified that the interface is ready.
581 ixgb_open(struct net_device *netdev)
583 struct ixgb_adapter *adapter = netdev->priv;
586 /* allocate transmit descriptors */
588 if((err = ixgb_setup_tx_resources(adapter)))
591 /* allocate receive descriptors */
593 if((err = ixgb_setup_rx_resources(adapter)))
596 if((err = ixgb_up(adapter)))
602 ixgb_free_rx_resources(adapter);
604 ixgb_free_tx_resources(adapter);
612 * ixgb_close - Disables a network interface
613 * @netdev: network interface device structure
615 * Returns 0, this is not allowed to fail
617 * The close entry point is called when an interface is de-activated
618 * by the OS. The hardware is still under the drivers control, but
619 * needs to be disabled. A global MAC reset is issued to stop the
620 * hardware, and all transmit and receive resources are freed.
624 ixgb_close(struct net_device *netdev)
626 struct ixgb_adapter *adapter = netdev->priv;
628 ixgb_down(adapter, TRUE);
630 ixgb_free_tx_resources(adapter);
631 ixgb_free_rx_resources(adapter);
637 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
638 * @adapter: board private structure
640 * Return 0 on success, negative on failure
644 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
646 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
647 struct pci_dev *pdev = adapter->pdev;
650 size = sizeof(struct ixgb_buffer) * txdr->count;
651 txdr->buffer_info = vmalloc(size);
652 if(!txdr->buffer_info) {
655 memset(txdr->buffer_info, 0, size);
657 /* round up to nearest 4K */
659 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
660 IXGB_ROUNDUP(txdr->size, 4096);
662 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
664 vfree(txdr->buffer_info);
667 memset(txdr->desc, 0, txdr->size);
669 txdr->next_to_use = 0;
670 txdr->next_to_clean = 0;
676 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
677 * @adapter: board private structure
679 * Configure the Tx unit of the MAC after a reset.
683 ixgb_configure_tx(struct ixgb_adapter *adapter)
685 uint64_t tdba = adapter->tx_ring.dma;
686 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
688 struct ixgb_hw *hw = &adapter->hw;
690 /* Setup the Base and Length of the Tx Descriptor Ring
691 * tx_ring.dma can be either a 32 or 64 bit value
694 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
695 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
697 IXGB_WRITE_REG(hw, TDLEN, tdlen);
699 /* Setup the HW Tx Head and Tail descriptor pointers */
701 IXGB_WRITE_REG(hw, TDH, 0);
702 IXGB_WRITE_REG(hw, TDT, 0);
704 /* don't set up txdctl, it induces performance problems if configured
706 /* Set the Tx Interrupt Delay register */
708 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
710 /* Program the Transmit Control Register */
712 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
713 IXGB_WRITE_REG(hw, TCTL, tctl);
715 /* Setup Transmit Descriptor Settings for this adapter */
716 adapter->tx_cmd_type =
718 | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
722 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
723 * @adapter: board private structure
725 * Returns 0 on success, negative on failure
729 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
731 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
732 struct pci_dev *pdev = adapter->pdev;
735 size = sizeof(struct ixgb_buffer) * rxdr->count;
736 rxdr->buffer_info = vmalloc(size);
737 if(!rxdr->buffer_info) {
740 memset(rxdr->buffer_info, 0, size);
742 /* Round up to nearest 4K */
744 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
745 IXGB_ROUNDUP(rxdr->size, 4096);
747 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
750 vfree(rxdr->buffer_info);
753 memset(rxdr->desc, 0, rxdr->size);
755 rxdr->next_to_clean = 0;
756 rxdr->next_to_use = 0;
762 * ixgb_setup_rctl - configure the receive control register
763 * @adapter: Board private structure
767 ixgb_setup_rctl(struct ixgb_adapter *adapter)
771 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
773 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
776 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
777 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
778 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
780 rctl |= IXGB_RCTL_SECRC;
782 switch (adapter->rx_buffer_len) {
783 case IXGB_RXBUFFER_2048:
785 rctl |= IXGB_RCTL_BSIZE_2048;
787 case IXGB_RXBUFFER_4096:
788 rctl |= IXGB_RCTL_BSIZE_4096;
790 case IXGB_RXBUFFER_8192:
791 rctl |= IXGB_RCTL_BSIZE_8192;
793 case IXGB_RXBUFFER_16384:
794 rctl |= IXGB_RCTL_BSIZE_16384;
798 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
802 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
803 * @adapter: board private structure
805 * Configure the Rx unit of the MAC after a reset.
809 ixgb_configure_rx(struct ixgb_adapter *adapter)
811 uint64_t rdba = adapter->rx_ring.dma;
812 uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
813 struct ixgb_hw *hw = &adapter->hw;
818 /* make sure receives are disabled while setting up the descriptors */
820 rctl = IXGB_READ_REG(hw, RCTL);
821 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
823 /* set the Receive Delay Timer Register */
825 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
827 /* Setup the Base and Length of the Rx Descriptor Ring */
829 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
830 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
832 IXGB_WRITE_REG(hw, RDLEN, rdlen);
834 /* Setup the HW Rx Head and Tail Descriptor Pointers */
835 IXGB_WRITE_REG(hw, RDH, 0);
836 IXGB_WRITE_REG(hw, RDT, 0);
838 /* set up pre-fetching of receive buffers so we get some before we
839 * run out (default hardware behavior is to run out before fetching
840 * more). This sets up to fetch if HTHRESH rx descriptors are avail
841 * and the descriptors in hw cache are below PTHRESH. This avoids
842 * the hardware behavior of fetching <=512 descriptors in a single
843 * burst that pre-empts all other activity, usually causing fifo
845 /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */
846 rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |
847 RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |
848 RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
849 IXGB_WRITE_REG(hw, RXDCTL, rxdctl);
851 /* Enable Receive Checksum Offload for TCP and UDP */
852 if(adapter->rx_csum == TRUE) {
853 rxcsum = IXGB_READ_REG(hw, RXCSUM);
854 rxcsum |= IXGB_RXCSUM_TUOFL;
855 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
858 /* Enable Receives */
860 IXGB_WRITE_REG(hw, RCTL, rctl);
864 * ixgb_free_tx_resources - Free Tx Resources
865 * @adapter: board private structure
867 * Free all transmit software resources
871 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
873 struct pci_dev *pdev = adapter->pdev;
875 ixgb_clean_tx_ring(adapter);
877 vfree(adapter->tx_ring.buffer_info);
878 adapter->tx_ring.buffer_info = NULL;
880 pci_free_consistent(pdev, adapter->tx_ring.size,
881 adapter->tx_ring.desc, adapter->tx_ring.dma);
883 adapter->tx_ring.desc = NULL;
887 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
888 struct ixgb_buffer *buffer_info)
890 struct pci_dev *pdev = adapter->pdev;
891 if(buffer_info->dma) {
896 buffer_info->dma = 0;
898 if(buffer_info->skb) {
899 dev_kfree_skb_any(buffer_info->skb);
900 buffer_info->skb = NULL;
905 * ixgb_clean_tx_ring - Free Tx Buffers
906 * @adapter: board private structure
910 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
912 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
913 struct ixgb_buffer *buffer_info;
917 /* Free all the Tx ring sk_buffs */
919 for(i = 0; i < tx_ring->count; i++) {
920 buffer_info = &tx_ring->buffer_info[i];
921 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
924 size = sizeof(struct ixgb_buffer) * tx_ring->count;
925 memset(tx_ring->buffer_info, 0, size);
927 /* Zero out the descriptor ring */
929 memset(tx_ring->desc, 0, tx_ring->size);
931 tx_ring->next_to_use = 0;
932 tx_ring->next_to_clean = 0;
934 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
935 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
939 * ixgb_free_rx_resources - Free Rx Resources
940 * @adapter: board private structure
942 * Free all receive software resources
946 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
948 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
949 struct pci_dev *pdev = adapter->pdev;
951 ixgb_clean_rx_ring(adapter);
953 vfree(rx_ring->buffer_info);
954 rx_ring->buffer_info = NULL;
956 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
958 rx_ring->desc = NULL;
962 * ixgb_clean_rx_ring - Free Rx Buffers
963 * @adapter: board private structure
967 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
969 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
970 struct ixgb_buffer *buffer_info;
971 struct pci_dev *pdev = adapter->pdev;
975 /* Free all the Rx ring sk_buffs */
977 for(i = 0; i < rx_ring->count; i++) {
978 buffer_info = &rx_ring->buffer_info[i];
979 if(buffer_info->skb) {
981 pci_unmap_single(pdev,
986 dev_kfree_skb(buffer_info->skb);
988 buffer_info->skb = NULL;
992 size = sizeof(struct ixgb_buffer) * rx_ring->count;
993 memset(rx_ring->buffer_info, 0, size);
995 /* Zero out the descriptor ring */
997 memset(rx_ring->desc, 0, rx_ring->size);
999 rx_ring->next_to_clean = 0;
1000 rx_ring->next_to_use = 0;
1002 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1003 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1007 * ixgb_set_mac - Change the Ethernet Address of the NIC
1008 * @netdev: network interface device structure
1009 * @p: pointer to an address structure
1011 * Returns 0 on success, negative on failure
1015 ixgb_set_mac(struct net_device *netdev, void *p)
1017 struct ixgb_adapter *adapter = netdev->priv;
1018 struct sockaddr *addr = p;
1020 if(!is_valid_ether_addr(addr->sa_data))
1021 return -EADDRNOTAVAIL;
1023 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1025 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1031 * ixgb_set_multi - Multicast and Promiscuous mode set
1032 * @netdev: network interface device structure
1034 * The set_multi entry point is called whenever the multicast address
1035 * list or the network interface flags are updated. This routine is
1036 * responsible for configuring the hardware for proper multicast,
1037 * promiscuous mode, and all-multi behavior.
1041 ixgb_set_multi(struct net_device *netdev)
1043 struct ixgb_adapter *adapter = netdev->priv;
1044 struct ixgb_hw *hw = &adapter->hw;
1045 struct dev_mc_list *mc_ptr;
1049 /* Check for Promiscuous and All Multicast modes */
1051 rctl = IXGB_READ_REG(hw, RCTL);
1053 if(netdev->flags & IFF_PROMISC) {
1054 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1055 } else if(netdev->flags & IFF_ALLMULTI) {
1056 rctl |= IXGB_RCTL_MPE;
1057 rctl &= ~IXGB_RCTL_UPE;
1059 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1062 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1063 rctl |= IXGB_RCTL_MPE;
1064 IXGB_WRITE_REG(hw, RCTL, rctl);
1066 uint8_t mta[netdev->mc_count * IXGB_ETH_LENGTH_OF_ADDRESS];
1068 IXGB_WRITE_REG(hw, RCTL, rctl);
1070 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1071 i++, mc_ptr = mc_ptr->next)
1072 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1073 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1075 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1080 * ixgb_watchdog - Timer Call-back
1081 * @data: pointer to netdev cast into an unsigned long
1085 ixgb_watchdog(unsigned long data)
1087 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1088 struct net_device *netdev = adapter->netdev;
1089 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1091 ixgb_check_for_link(&adapter->hw);
1093 if (ixgb_check_for_bad_link(&adapter->hw)) {
1094 /* force the reset path */
1095 netif_stop_queue(netdev);
1098 if(adapter->hw.link_up) {
1099 if(!netif_carrier_ok(netdev)) {
1100 printk(KERN_INFO "ixgb: %s NIC Link is Up %d Mbps %s\n",
1101 netdev->name, 10000, "Full Duplex");
1102 adapter->link_speed = 10000;
1103 adapter->link_duplex = FULL_DUPLEX;
1104 netif_carrier_on(netdev);
1105 netif_wake_queue(netdev);
1108 if(netif_carrier_ok(netdev)) {
1109 adapter->link_speed = 0;
1110 adapter->link_duplex = 0;
1112 "ixgb: %s NIC Link is Down\n",
1114 netif_carrier_off(netdev);
1115 netif_stop_queue(netdev);
1120 ixgb_update_stats(adapter);
1122 if(!netif_carrier_ok(netdev)) {
1123 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1124 /* We've lost link, so the controller stops DMA,
1125 * but we've got queued Tx work that's never going
1126 * to get done, so reset controller to flush Tx.
1127 * (Do the reset outside of interrupt context). */
1128 schedule_work(&adapter->tx_timeout_task);
1132 /* Force detection of hung controller every watchdog period */
1133 adapter->detect_tx_hung = TRUE;
1135 /* generate an interrupt to force clean up of any stragglers */
1136 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1138 /* Reset the timer */
1139 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1142 #define IXGB_TX_FLAGS_CSUM 0x00000001
1143 #define IXGB_TX_FLAGS_VLAN 0x00000002
1144 #define IXGB_TX_FLAGS_TSO 0x00000004
1147 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1150 struct ixgb_context_desc *context_desc;
1152 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1153 uint16_t ipcse, tucse, mss;
1156 if(likely(skb_shinfo(skb)->tso_size)) {
1157 if (skb_header_cloned(skb)) {
1158 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1163 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1164 mss = skb_shinfo(skb)->tso_size;
1165 skb->nh.iph->tot_len = 0;
1166 skb->nh.iph->check = 0;
1167 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1170 ipcss = skb->nh.raw - skb->data;
1171 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1172 ipcse = skb->h.raw - skb->data - 1;
1173 tucss = skb->h.raw - skb->data;
1174 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1177 i = adapter->tx_ring.next_to_use;
1178 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1180 context_desc->ipcss = ipcss;
1181 context_desc->ipcso = ipcso;
1182 context_desc->ipcse = cpu_to_le16(ipcse);
1183 context_desc->tucss = tucss;
1184 context_desc->tucso = tucso;
1185 context_desc->tucse = cpu_to_le16(tucse);
1186 context_desc->mss = cpu_to_le16(mss);
1187 context_desc->hdr_len = hdr_len;
1188 context_desc->status = 0;
1189 context_desc->cmd_type_len = cpu_to_le32(
1190 IXGB_CONTEXT_DESC_TYPE
1191 | IXGB_CONTEXT_DESC_CMD_TSE
1192 | IXGB_CONTEXT_DESC_CMD_IP
1193 | IXGB_CONTEXT_DESC_CMD_TCP
1194 | IXGB_CONTEXT_DESC_CMD_IDE
1195 | (skb->len - (hdr_len)));
1198 if(++i == adapter->tx_ring.count) i = 0;
1199 adapter->tx_ring.next_to_use = i;
1208 static inline boolean_t
1209 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1211 struct ixgb_context_desc *context_desc;
1215 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1216 css = skb->h.raw - skb->data;
1217 cso = (skb->h.raw + skb->csum) - skb->data;
1219 i = adapter->tx_ring.next_to_use;
1220 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1222 context_desc->tucss = css;
1223 context_desc->tucso = cso;
1224 context_desc->tucse = 0;
1225 /* zero out any previously existing data in one instruction */
1226 *(uint32_t *)&(context_desc->ipcss) = 0;
1227 context_desc->status = 0;
1228 context_desc->hdr_len = 0;
1229 context_desc->mss = 0;
1230 context_desc->cmd_type_len =
1231 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1232 | IXGB_TX_DESC_CMD_IDE);
1234 if(++i == adapter->tx_ring.count) i = 0;
1235 adapter->tx_ring.next_to_use = i;
1243 #define IXGB_MAX_TXD_PWR 14
1244 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1247 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1250 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1251 struct ixgb_buffer *buffer_info;
1253 unsigned int offset = 0, size, count = 0, i;
1255 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1258 len -= skb->data_len;
1260 i = tx_ring->next_to_use;
1263 buffer_info = &tx_ring->buffer_info[i];
1264 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1265 buffer_info->length = size;
1267 pci_map_single(adapter->pdev,
1271 buffer_info->time_stamp = jiffies;
1276 if(++i == tx_ring->count) i = 0;
1279 for(f = 0; f < nr_frags; f++) {
1280 struct skb_frag_struct *frag;
1282 frag = &skb_shinfo(skb)->frags[f];
1287 buffer_info = &tx_ring->buffer_info[i];
1288 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1289 buffer_info->length = size;
1291 pci_map_page(adapter->pdev,
1293 frag->page_offset + offset,
1296 buffer_info->time_stamp = jiffies;
1301 if(++i == tx_ring->count) i = 0;
1304 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1305 tx_ring->buffer_info[i].skb = skb;
1306 tx_ring->buffer_info[first].next_to_watch = i;
1312 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1314 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1315 struct ixgb_tx_desc *tx_desc = NULL;
1316 struct ixgb_buffer *buffer_info;
1317 uint32_t cmd_type_len = adapter->tx_cmd_type;
1322 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1323 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1324 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1327 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1328 popts |= IXGB_TX_DESC_POPTS_TXSM;
1330 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1331 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1334 i = tx_ring->next_to_use;
1337 buffer_info = &tx_ring->buffer_info[i];
1338 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1339 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1340 tx_desc->cmd_type_len =
1341 cpu_to_le32(cmd_type_len | buffer_info->length);
1342 tx_desc->status = status;
1343 tx_desc->popts = popts;
1344 tx_desc->vlan = cpu_to_le16(vlan_id);
1346 if(++i == tx_ring->count) i = 0;
1349 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1350 | IXGB_TX_DESC_CMD_RS );
1352 /* Force memory writes to complete before letting h/w
1353 * know there are new descriptors to fetch. (Only
1354 * applicable for weak-ordered memory model archs,
1355 * such as IA-64). */
1358 tx_ring->next_to_use = i;
1359 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1362 /* Tx Descriptors needed, worst case */
1363 #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1364 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1365 #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \
1366 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1
1369 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1371 struct ixgb_adapter *adapter = netdev->priv;
1373 unsigned int tx_flags = 0;
1374 unsigned long flags;
1379 dev_kfree_skb_any(skb);
1383 spin_lock_irqsave(&adapter->tx_lock, flags);
1384 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) {
1385 netif_stop_queue(netdev);
1386 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1389 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1391 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1392 tx_flags |= IXGB_TX_FLAGS_VLAN;
1393 vlan_id = vlan_tx_tag_get(skb);
1396 first = adapter->tx_ring.next_to_use;
1398 tso = ixgb_tso(adapter, skb);
1400 dev_kfree_skb_any(skb);
1401 return NETDEV_TX_OK;
1405 tx_flags |= IXGB_TX_FLAGS_TSO;
1406 else if(ixgb_tx_csum(adapter, skb))
1407 tx_flags |= IXGB_TX_FLAGS_CSUM;
1409 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1412 netdev->trans_start = jiffies;
1418 * ixgb_tx_timeout - Respond to a Tx Hang
1419 * @netdev: network interface device structure
1423 ixgb_tx_timeout(struct net_device *netdev)
1425 struct ixgb_adapter *adapter = netdev->priv;
1427 /* Do the reset outside of interrupt context */
1428 schedule_work(&adapter->tx_timeout_task);
1432 ixgb_tx_timeout_task(struct net_device *netdev)
1434 struct ixgb_adapter *adapter = netdev->priv;
1436 ixgb_down(adapter, TRUE);
1441 * ixgb_get_stats - Get System Network Statistics
1442 * @netdev: network interface device structure
1444 * Returns the address of the device statistics structure.
1445 * The statistics are actually updated from the timer callback.
1448 static struct net_device_stats *
1449 ixgb_get_stats(struct net_device *netdev)
1451 struct ixgb_adapter *adapter = netdev->priv;
1453 return &adapter->net_stats;
1457 * ixgb_change_mtu - Change the Maximum Transfer Unit
1458 * @netdev: network interface device structure
1459 * @new_mtu: new value for maximum frame size
1461 * Returns 0 on success, negative on failure
1465 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1467 struct ixgb_adapter *adapter = netdev->priv;
1468 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1469 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1472 if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1473 || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
1474 IXGB_ERR("Invalid MTU setting\n");
1478 if((max_frame <= IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1479 || (max_frame <= IXGB_RXBUFFER_2048)) {
1480 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
1482 } else if(max_frame <= IXGB_RXBUFFER_4096) {
1483 adapter->rx_buffer_len = IXGB_RXBUFFER_4096;
1485 } else if(max_frame <= IXGB_RXBUFFER_8192) {
1486 adapter->rx_buffer_len = IXGB_RXBUFFER_8192;
1489 adapter->rx_buffer_len = IXGB_RXBUFFER_16384;
1492 netdev->mtu = new_mtu;
1494 if(old_max_frame != max_frame && netif_running(netdev)) {
1496 ixgb_down(adapter, TRUE);
1504 * ixgb_update_stats - Update the board statistics counters.
1505 * @adapter: board private structure
1509 ixgb_update_stats(struct ixgb_adapter *adapter)
1511 struct net_device *netdev = adapter->netdev;
1513 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1514 (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1515 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1516 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1517 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1518 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1520 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1521 /* fix up multicast stats by removing broadcasts */
1524 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1525 adapter->stats.mprch += (multi >> 32);
1526 adapter->stats.bprcl += bcast_l;
1527 adapter->stats.bprch += bcast_h;
1529 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1530 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1531 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1532 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1534 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1535 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1536 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1537 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1538 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1539 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1540 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1541 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1542 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1543 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1544 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1545 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1546 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1547 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1548 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1549 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1550 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1551 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1552 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1553 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1554 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1555 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1556 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1557 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1558 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1559 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1560 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1561 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1562 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1563 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1564 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1565 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1566 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1567 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1568 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1569 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1570 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1571 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1572 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1573 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1574 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1575 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1576 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1577 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1578 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1579 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1580 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1581 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1582 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1583 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1584 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1585 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1586 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1587 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1588 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1589 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1591 /* Fill out the OS statistics structure */
1593 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1594 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1595 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1596 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1597 adapter->net_stats.multicast = adapter->stats.mprcl;
1598 adapter->net_stats.collisions = 0;
1600 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1601 * with a length in the type/len field */
1602 adapter->net_stats.rx_errors =
1603 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1604 adapter->stats.ruc +
1605 adapter->stats.roc /*+ adapter->stats.rlec */ +
1606 adapter->stats.icbc +
1607 adapter->stats.ecbc + adapter->stats.mpc;
1609 adapter->net_stats.rx_dropped = adapter->stats.mpc;
1612 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1615 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1616 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1617 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1618 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1620 adapter->net_stats.tx_errors = 0;
1621 adapter->net_stats.rx_frame_errors = 0;
1622 adapter->net_stats.tx_aborted_errors = 0;
1623 adapter->net_stats.tx_carrier_errors = 0;
1624 adapter->net_stats.tx_fifo_errors = 0;
1625 adapter->net_stats.tx_heartbeat_errors = 0;
1626 adapter->net_stats.tx_window_errors = 0;
1629 #define IXGB_MAX_INTR 10
1631 * ixgb_intr - Interrupt Handler
1632 * @irq: interrupt number
1633 * @data: pointer to a network interface device structure
1634 * @pt_regs: CPU registers structure
1638 ixgb_intr(int irq, void *data, struct pt_regs *regs)
1640 struct net_device *netdev = data;
1641 struct ixgb_adapter *adapter = netdev->priv;
1642 struct ixgb_hw *hw = &adapter->hw;
1643 uint32_t icr = IXGB_READ_REG(hw, ICR);
1644 #ifndef CONFIG_IXGB_NAPI
1649 return IRQ_NONE; /* Not our interrupt */
1651 if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) {
1652 mod_timer(&adapter->watchdog_timer, jiffies);
1655 #ifdef CONFIG_IXGB_NAPI
1656 if(netif_rx_schedule_prep(netdev)) {
1658 /* Disable interrupts and register for poll. The flush
1659 of the posted write is intentionally left out.
1662 atomic_inc(&adapter->irq_sem);
1663 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1664 __netif_rx_schedule(netdev);
1667 /* yes, that is actually a & and it is meant to make sure that
1668 * every pass through this for loop checks both receive and
1669 * transmit queues for completed descriptors, intended to
1670 * avoid starvation issues and assist tx/rx fairness. */
1671 for(i = 0; i < IXGB_MAX_INTR; i++)
1672 if(!ixgb_clean_rx_irq(adapter) &
1673 !ixgb_clean_tx_irq(adapter))
1679 #ifdef CONFIG_IXGB_NAPI
1681 * ixgb_clean - NAPI Rx polling callback
1682 * @adapter: board private structure
1686 ixgb_clean(struct net_device *netdev, int *budget)
1688 struct ixgb_adapter *adapter = netdev->priv;
1689 int work_to_do = min(*budget, netdev->quota);
1693 tx_cleaned = ixgb_clean_tx_irq(adapter);
1694 ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
1696 *budget -= work_done;
1697 netdev->quota -= work_done;
1699 /* if no Tx and not enough Rx work done, exit the polling mode */
1700 if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
1701 netif_rx_complete(netdev);
1702 ixgb_irq_enable(adapter);
1711 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1712 * @adapter: board private structure
1716 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1718 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1719 struct net_device *netdev = adapter->netdev;
1720 struct ixgb_tx_desc *tx_desc, *eop_desc;
1721 struct ixgb_buffer *buffer_info;
1722 unsigned int i, eop;
1723 boolean_t cleaned = FALSE;
1725 i = tx_ring->next_to_clean;
1726 eop = tx_ring->buffer_info[i].next_to_watch;
1727 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1729 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1731 for(cleaned = FALSE; !cleaned; ) {
1732 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1733 buffer_info = &tx_ring->buffer_info[i];
1736 & (IXGB_TX_DESC_POPTS_TXSM |
1737 IXGB_TX_DESC_POPTS_IXSM))
1738 adapter->hw_csum_tx_good++;
1740 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1742 *(uint32_t *)&(tx_desc->status) = 0;
1744 cleaned = (i == eop);
1745 if(++i == tx_ring->count) i = 0;
1748 eop = tx_ring->buffer_info[i].next_to_watch;
1749 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1752 tx_ring->next_to_clean = i;
1754 spin_lock(&adapter->tx_lock);
1755 if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1756 (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) {
1758 netif_wake_queue(netdev);
1760 spin_unlock(&adapter->tx_lock);
1762 if(adapter->detect_tx_hung) {
1763 /* detect a transmit hang in hardware, this serializes the
1764 * check with the clearing of time_stamp and movement of i */
1765 adapter->detect_tx_hung = FALSE;
1766 if(tx_ring->buffer_info[i].dma &&
1767 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
1768 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1770 netif_stop_queue(netdev);
1777 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1778 * @adapter: board private structure
1779 * @rx_desc: receive descriptor
1780 * @sk_buff: socket buffer with received data
1784 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1785 struct ixgb_rx_desc *rx_desc,
1786 struct sk_buff *skb)
1788 /* Ignore Checksum bit is set OR
1789 * TCP Checksum has not been calculated
1791 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1792 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1793 skb->ip_summed = CHECKSUM_NONE;
1797 /* At this point we know the hardware did the TCP checksum */
1798 /* now look at the TCP checksum error bit */
1799 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1800 /* let the stack verify checksum errors */
1801 skb->ip_summed = CHECKSUM_NONE;
1802 adapter->hw_csum_rx_error++;
1804 /* TCP checksum is good */
1805 skb->ip_summed = CHECKSUM_UNNECESSARY;
1806 adapter->hw_csum_rx_good++;
1811 * ixgb_clean_rx_irq - Send received data up the network stack,
1812 * @adapter: board private structure
1816 #ifdef CONFIG_IXGB_NAPI
1817 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1819 ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1822 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1823 struct net_device *netdev = adapter->netdev;
1824 struct pci_dev *pdev = adapter->pdev;
1825 struct ixgb_rx_desc *rx_desc, *next_rxd;
1826 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
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) {
1836 struct sk_buff *skb, *next_skb;
1839 #ifdef CONFIG_IXGB_NAPI
1840 if(*work_done >= work_to_do)
1845 status = rx_desc->status;
1846 skb = buffer_info->skb;
1848 prefetch(skb->data);
1850 if(++i == rx_ring->count) i = 0;
1851 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1854 if((j = i + 1) == rx_ring->count) j = 0;
1855 next2_buffer = &rx_ring->buffer_info[j];
1856 prefetch(next2_buffer);
1858 next_buffer = &rx_ring->buffer_info[i];
1859 next_skb = next_buffer->skb;
1864 pci_unmap_single(pdev,
1866 buffer_info->length,
1867 PCI_DMA_FROMDEVICE);
1869 length = le16_to_cpu(rx_desc->length);
1871 if(unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
1873 /* All receives must fit into a single buffer */
1875 IXGB_DBG("Receive packet consumed multiple buffers "
1876 "length<%x>\n", length);
1878 dev_kfree_skb_irq(skb);
1882 if (unlikely(rx_desc->errors
1883 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1884 | IXGB_RX_DESC_ERRORS_P |
1885 IXGB_RX_DESC_ERRORS_RXE))) {
1887 dev_kfree_skb_irq(skb);
1892 skb_put(skb, length);
1894 /* Receive Checksum Offload */
1895 ixgb_rx_checksum(adapter, rx_desc, skb);
1897 skb->protocol = eth_type_trans(skb, netdev);
1898 #ifdef CONFIG_IXGB_NAPI
1899 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1900 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
1901 le16_to_cpu(rx_desc->special) &
1902 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1904 netif_receive_skb(skb);
1906 #else /* CONFIG_IXGB_NAPI */
1907 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1908 vlan_hwaccel_rx(skb, adapter->vlgrp,
1909 le16_to_cpu(rx_desc->special) &
1910 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1914 #endif /* CONFIG_IXGB_NAPI */
1915 netdev->last_rx = jiffies;
1918 /* clean up descriptor, might be written over by hw */
1919 rx_desc->status = 0;
1920 buffer_info->skb = NULL;
1922 /* use prefetched values */
1924 buffer_info = next_buffer;
1927 rx_ring->next_to_clean = i;
1929 ixgb_alloc_rx_buffers(adapter);
1935 * ixgb_alloc_rx_buffers - Replace used receive buffers
1936 * @adapter: address of board private structure
1940 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
1942 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1943 struct net_device *netdev = adapter->netdev;
1944 struct pci_dev *pdev = adapter->pdev;
1945 struct ixgb_rx_desc *rx_desc;
1946 struct ixgb_buffer *buffer_info;
1947 struct sk_buff *skb;
1949 int num_group_tail_writes;
1952 i = rx_ring->next_to_use;
1953 buffer_info = &rx_ring->buffer_info[i];
1954 cleancount = IXGB_DESC_UNUSED(rx_ring);
1956 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
1958 /* leave three descriptors unused */
1959 while(--cleancount > 2) {
1960 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1962 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1964 if(unlikely(!skb)) {
1965 /* Better luck next round */
1969 /* Make buffer alignment 2 beyond a 16 byte boundary
1970 * this will result in a 16 byte aligned IP header after
1971 * the 14 byte MAC header is removed
1973 skb_reserve(skb, NET_IP_ALIGN);
1977 buffer_info->skb = skb;
1978 buffer_info->length = adapter->rx_buffer_len;
1980 pci_map_single(pdev,
1982 adapter->rx_buffer_len,
1983 PCI_DMA_FROMDEVICE);
1985 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1986 /* guarantee DD bit not set now before h/w gets descriptor
1987 * this is the rest of the workaround for h/w double
1989 rx_desc->status = 0;
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). */
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
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;
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);
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);
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);
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);
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);
2088 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2090 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2092 if(adapter->vlgrp) {
2094 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2095 if(!adapter->vlgrp->vlan_devices[vid])
2097 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2102 #ifdef CONFIG_NET_POLL_CONTROLLER
2104 * Polling 'interrupt' - used by things like netconsole to send skbs
2105 * without having to re-enable interrupts. It's not called while
2106 * the interrupt routine is executing.
2109 static void ixgb_netpoll(struct net_device *dev)
2111 struct ixgb_adapter *adapter = dev->priv;
2113 disable_irq(adapter->pdev->irq);
2114 ixgb_intr(adapter->pdev->irq, dev, NULL);
2115 enable_irq(adapter->pdev->irq);