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 * - Make needlessly global code static -- bunk@stusta.de
34 * - ethtool cleanup -- shemminger@osdl.org
35 * - Support for MODULE_VERSION -- linville@tuxdriver.com
36 * - add skb_header_cloned check to the tso path -- herbert@apana.org.au
38 * - include fix to the condition that determines when to quit NAPI - Robert Olsson
39 * - use netif_poll_{disable/enable} to synchronize between NAPI and i/f up/down
41 * - reset buffer_info->dma in Tx resource cleanup logic
43 * - sparse cleanup - shemminger@osdl.org
44 * - fix tx resource cleanup logic
47 char ixgb_driver_name[] = "ixgb";
48 static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
50 #ifndef CONFIG_IXGB_NAPI
53 #define DRIVERNAPI "-NAPI"
55 #define DRV_VERSION "1.0.100-k2"DRIVERNAPI
56 char ixgb_driver_version[] = DRV_VERSION;
57 static char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
59 /* ixgb_pci_tbl - PCI Device ID Table
61 * Wildcard entries (PCI_ANY_ID) should come last
62 * Last entry must be all 0s
64 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
65 * Class, Class Mask, private data (not used) }
67 static struct pci_device_id ixgb_pci_tbl[] = {
68 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX,
69 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
70 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR,
71 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
72 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR,
73 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
75 /* required last entry */
79 MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
81 /* Local Function Prototypes */
83 int ixgb_up(struct ixgb_adapter *adapter);
84 void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog);
85 void ixgb_reset(struct ixgb_adapter *adapter);
86 int ixgb_setup_tx_resources(struct ixgb_adapter *adapter);
87 int ixgb_setup_rx_resources(struct ixgb_adapter *adapter);
88 void ixgb_free_tx_resources(struct ixgb_adapter *adapter);
89 void ixgb_free_rx_resources(struct ixgb_adapter *adapter);
90 void ixgb_update_stats(struct ixgb_adapter *adapter);
92 static int ixgb_init_module(void);
93 static void ixgb_exit_module(void);
94 static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
95 static void __devexit ixgb_remove(struct pci_dev *pdev);
96 static int ixgb_sw_init(struct ixgb_adapter *adapter);
97 static int ixgb_open(struct net_device *netdev);
98 static int ixgb_close(struct net_device *netdev);
99 static void ixgb_configure_tx(struct ixgb_adapter *adapter);
100 static void ixgb_configure_rx(struct ixgb_adapter *adapter);
101 static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
102 static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
103 static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
104 static void ixgb_set_multi(struct net_device *netdev);
105 static void ixgb_watchdog(unsigned long data);
106 static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
107 static struct net_device_stats *ixgb_get_stats(struct net_device *netdev);
108 static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
109 static int ixgb_set_mac(struct net_device *netdev, void *p);
110 static irqreturn_t ixgb_intr(int irq, void *data, struct pt_regs *regs);
111 static boolean_t ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
113 #ifdef CONFIG_IXGB_NAPI
114 static int ixgb_clean(struct net_device *netdev, int *budget);
115 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
116 int *work_done, int work_to_do);
118 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
120 static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter);
121 void ixgb_set_ethtool_ops(struct net_device *netdev);
122 static void ixgb_tx_timeout(struct net_device *dev);
123 static void ixgb_tx_timeout_task(struct net_device *dev);
124 static void ixgb_vlan_rx_register(struct net_device *netdev,
125 struct vlan_group *grp);
126 static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
127 static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
128 static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
130 #ifdef CONFIG_NET_POLL_CONTROLLER
131 /* for netdump / net console */
132 static void ixgb_netpoll(struct net_device *dev);
135 /* Exported from other modules */
137 extern void ixgb_check_options(struct ixgb_adapter *adapter);
139 static struct pci_driver ixgb_driver = {
140 .name = ixgb_driver_name,
141 .id_table = ixgb_pci_tbl,
143 .remove = __devexit_p(ixgb_remove),
146 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
147 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
148 MODULE_LICENSE("GPL");
149 MODULE_VERSION(DRV_VERSION);
151 /* some defines for controlling descriptor fetches in h/w */
152 #define RXDCTL_WTHRESH_DEFAULT 16 /* chip writes back at this many or RXT0 */
153 #define RXDCTL_PTHRESH_DEFAULT 0 /* chip considers prefech below
155 #define RXDCTL_HTHRESH_DEFAULT 0 /* chip will only prefetch if tail
156 * is pushed this many descriptors
160 * ixgb_init_module - Driver Registration Routine
162 * ixgb_init_module is the first routine called when the driver is
163 * loaded. All it does is register with the PCI subsystem.
167 ixgb_init_module(void)
169 printk(KERN_INFO "%s - version %s\n",
170 ixgb_driver_string, ixgb_driver_version);
172 printk(KERN_INFO "%s\n", ixgb_copyright);
174 return pci_module_init(&ixgb_driver);
177 module_init(ixgb_init_module);
180 * ixgb_exit_module - Driver Exit Cleanup Routine
182 * ixgb_exit_module is called just before the driver is removed
187 ixgb_exit_module(void)
189 pci_unregister_driver(&ixgb_driver);
192 module_exit(ixgb_exit_module);
195 * ixgb_irq_disable - Mask off interrupt generation on the NIC
196 * @adapter: board private structure
200 ixgb_irq_disable(struct ixgb_adapter *adapter)
202 atomic_inc(&adapter->irq_sem);
203 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
204 IXGB_WRITE_FLUSH(&adapter->hw);
205 synchronize_irq(adapter->pdev->irq);
209 * ixgb_irq_enable - Enable default interrupt generation settings
210 * @adapter: board private structure
214 ixgb_irq_enable(struct ixgb_adapter *adapter)
216 if(atomic_dec_and_test(&adapter->irq_sem)) {
217 IXGB_WRITE_REG(&adapter->hw, IMS,
218 IXGB_INT_RXT0 | IXGB_INT_RXDMT0 | IXGB_INT_TXDW |
220 IXGB_WRITE_FLUSH(&adapter->hw);
225 ixgb_up(struct ixgb_adapter *adapter)
227 struct net_device *netdev = adapter->netdev;
229 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
230 struct ixgb_hw *hw = &adapter->hw;
232 /* hardware has been reset, we need to reload some things */
234 ixgb_set_multi(netdev);
236 ixgb_restore_vlan(adapter);
238 ixgb_configure_tx(adapter);
239 ixgb_setup_rctl(adapter);
240 ixgb_configure_rx(adapter);
241 ixgb_alloc_rx_buffers(adapter);
243 #ifdef CONFIG_PCI_MSI
245 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) &
246 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE;
247 adapter->have_msi = TRUE;
250 adapter->have_msi = FALSE;
251 else if((err = pci_enable_msi(adapter->pdev))) {
253 "Unable to allocate MSI interrupt Error: %d\n", err);
254 adapter->have_msi = FALSE;
255 /* proceed to try to request regular interrupt */
260 if((err = request_irq(adapter->pdev->irq, &ixgb_intr,
261 SA_SHIRQ | SA_SAMPLE_RANDOM,
262 netdev->name, netdev)))
265 /* disable interrupts and get the hardware into a known state */
266 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
268 if((hw->max_frame_size != max_frame) ||
269 (hw->max_frame_size !=
270 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
272 hw->max_frame_size = max_frame;
274 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
276 if(hw->max_frame_size >
277 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
278 uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0);
280 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
281 ctrl0 |= IXGB_CTRL0_JFE;
282 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
287 mod_timer(&adapter->watchdog_timer, jiffies);
288 ixgb_irq_enable(adapter);
290 #ifdef CONFIG_IXGB_NAPI
291 netif_poll_enable(netdev);
297 ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
299 struct net_device *netdev = adapter->netdev;
301 ixgb_irq_disable(adapter);
302 free_irq(adapter->pdev->irq, netdev);
303 #ifdef CONFIG_PCI_MSI
304 if(adapter->have_msi == TRUE)
305 pci_disable_msi(adapter->pdev);
309 del_timer_sync(&adapter->watchdog_timer);
310 #ifdef CONFIG_IXGB_NAPI
311 netif_poll_disable(netdev);
313 adapter->link_speed = 0;
314 adapter->link_duplex = 0;
315 netif_carrier_off(netdev);
316 netif_stop_queue(netdev);
319 ixgb_clean_tx_ring(adapter);
320 ixgb_clean_rx_ring(adapter);
324 ixgb_reset(struct ixgb_adapter *adapter)
327 ixgb_adapter_stop(&adapter->hw);
328 if(!ixgb_init_hw(&adapter->hw))
329 IXGB_DBG("ixgb_init_hw failed.\n");
333 * ixgb_probe - Device Initialization Routine
334 * @pdev: PCI device information struct
335 * @ent: entry in ixgb_pci_tbl
337 * Returns 0 on success, negative on failure
339 * ixgb_probe initializes an adapter identified by a pci_dev structure.
340 * The OS initialization, configuring of the adapter private structure,
341 * and a hardware reset occur.
345 ixgb_probe(struct pci_dev *pdev,
346 const struct pci_device_id *ent)
348 struct net_device *netdev = NULL;
349 struct ixgb_adapter *adapter;
350 static int cards_found = 0;
351 unsigned long mmio_start;
357 if((err = pci_enable_device(pdev)))
360 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
363 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
364 IXGB_ERR("No usable DMA configuration, aborting\n");
370 if((err = pci_request_regions(pdev, ixgb_driver_name)))
373 pci_set_master(pdev);
375 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
378 goto err_alloc_etherdev;
381 SET_MODULE_OWNER(netdev);
382 SET_NETDEV_DEV(netdev, &pdev->dev);
384 pci_set_drvdata(pdev, netdev);
385 adapter = netdev_priv(netdev);
386 adapter->netdev = netdev;
387 adapter->pdev = pdev;
388 adapter->hw.back = adapter;
390 mmio_start = pci_resource_start(pdev, BAR_0);
391 mmio_len = pci_resource_len(pdev, BAR_0);
393 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
394 if(!adapter->hw.hw_addr) {
399 for(i = BAR_1; i <= BAR_5; i++) {
400 if(pci_resource_len(pdev, i) == 0)
402 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
403 adapter->hw.io_base = pci_resource_start(pdev, i);
408 netdev->open = &ixgb_open;
409 netdev->stop = &ixgb_close;
410 netdev->hard_start_xmit = &ixgb_xmit_frame;
411 netdev->get_stats = &ixgb_get_stats;
412 netdev->set_multicast_list = &ixgb_set_multi;
413 netdev->set_mac_address = &ixgb_set_mac;
414 netdev->change_mtu = &ixgb_change_mtu;
415 ixgb_set_ethtool_ops(netdev);
416 netdev->tx_timeout = &ixgb_tx_timeout;
417 netdev->watchdog_timeo = HZ;
418 #ifdef CONFIG_IXGB_NAPI
419 netdev->poll = &ixgb_clean;
422 netdev->vlan_rx_register = ixgb_vlan_rx_register;
423 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
424 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
425 #ifdef CONFIG_NET_POLL_CONTROLLER
426 netdev->poll_controller = ixgb_netpoll;
429 netdev->mem_start = mmio_start;
430 netdev->mem_end = mmio_start + mmio_len;
431 netdev->base_addr = adapter->hw.io_base;
433 adapter->bd_number = cards_found;
434 adapter->link_speed = 0;
435 adapter->link_duplex = 0;
437 /* setup the private structure */
439 if((err = ixgb_sw_init(adapter)))
442 netdev->features = NETIF_F_SG |
446 NETIF_F_HW_VLAN_FILTER;
448 netdev->features |= NETIF_F_TSO;
452 netdev->features |= NETIF_F_HIGHDMA;
454 /* make sure the EEPROM is good */
456 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
457 printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n");
462 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
463 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
465 if(!is_valid_ether_addr(netdev->perm_addr)) {
470 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
472 init_timer(&adapter->watchdog_timer);
473 adapter->watchdog_timer.function = &ixgb_watchdog;
474 adapter->watchdog_timer.data = (unsigned long)adapter;
476 INIT_WORK(&adapter->tx_timeout_task,
477 (void (*)(void *))ixgb_tx_timeout_task, netdev);
479 if((err = register_netdev(netdev)))
482 /* we're going to reset, so assume we have no link for now */
484 netif_carrier_off(netdev);
485 netif_stop_queue(netdev);
487 printk(KERN_INFO "%s: Intel(R) PRO/10GbE Network Connection\n",
489 ixgb_check_options(adapter);
490 /* reset the hardware with the new settings */
500 iounmap(adapter->hw.hw_addr);
504 pci_release_regions(pdev);
509 * ixgb_remove - Device Removal Routine
510 * @pdev: PCI device information struct
512 * ixgb_remove is called by the PCI subsystem to alert the driver
513 * that it should release a PCI device. The could be caused by a
514 * Hot-Plug event, or because the driver is going to be removed from
518 static void __devexit
519 ixgb_remove(struct pci_dev *pdev)
521 struct net_device *netdev = pci_get_drvdata(pdev);
522 struct ixgb_adapter *adapter = netdev_priv(netdev);
524 unregister_netdev(netdev);
526 iounmap(adapter->hw.hw_addr);
527 pci_release_regions(pdev);
533 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
534 * @adapter: board private structure to initialize
536 * ixgb_sw_init initializes the Adapter private data structure.
537 * Fields are initialized based on PCI device information and
538 * OS network device settings (MTU size).
542 ixgb_sw_init(struct ixgb_adapter *adapter)
544 struct ixgb_hw *hw = &adapter->hw;
545 struct net_device *netdev = adapter->netdev;
546 struct pci_dev *pdev = adapter->pdev;
548 /* PCI config space info */
550 hw->vendor_id = pdev->vendor;
551 hw->device_id = pdev->device;
552 hw->subsystem_vendor_id = pdev->subsystem_vendor;
553 hw->subsystem_id = pdev->subsystem_device;
555 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
557 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
559 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
560 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
561 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
562 hw->mac_type = ixgb_82597;
564 /* should never have loaded on this device */
565 printk(KERN_ERR "ixgb: unsupported device id\n");
568 /* enable flow control to be programmed */
571 atomic_set(&adapter->irq_sem, 1);
572 spin_lock_init(&adapter->tx_lock);
578 * ixgb_open - Called when a network interface is made active
579 * @netdev: network interface device structure
581 * Returns 0 on success, negative value on failure
583 * The open entry point is called when a network interface is made
584 * active by the system (IFF_UP). At this point all resources needed
585 * for transmit and receive operations are allocated, the interrupt
586 * handler is registered with the OS, the watchdog timer is started,
587 * and the stack is notified that the interface is ready.
591 ixgb_open(struct net_device *netdev)
593 struct ixgb_adapter *adapter = netdev_priv(netdev);
596 /* allocate transmit descriptors */
598 if((err = ixgb_setup_tx_resources(adapter)))
601 /* allocate receive descriptors */
603 if((err = ixgb_setup_rx_resources(adapter)))
606 if((err = ixgb_up(adapter)))
612 ixgb_free_rx_resources(adapter);
614 ixgb_free_tx_resources(adapter);
622 * ixgb_close - Disables a network interface
623 * @netdev: network interface device structure
625 * Returns 0, this is not allowed to fail
627 * The close entry point is called when an interface is de-activated
628 * by the OS. The hardware is still under the drivers control, but
629 * needs to be disabled. A global MAC reset is issued to stop the
630 * hardware, and all transmit and receive resources are freed.
634 ixgb_close(struct net_device *netdev)
636 struct ixgb_adapter *adapter = netdev_priv(netdev);
638 ixgb_down(adapter, TRUE);
640 ixgb_free_tx_resources(adapter);
641 ixgb_free_rx_resources(adapter);
647 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
648 * @adapter: board private structure
650 * Return 0 on success, negative on failure
654 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
656 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
657 struct pci_dev *pdev = adapter->pdev;
660 size = sizeof(struct ixgb_buffer) * txdr->count;
661 txdr->buffer_info = vmalloc(size);
662 if(!txdr->buffer_info) {
665 memset(txdr->buffer_info, 0, size);
667 /* round up to nearest 4K */
669 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
670 IXGB_ROUNDUP(txdr->size, 4096);
672 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
674 vfree(txdr->buffer_info);
677 memset(txdr->desc, 0, txdr->size);
679 txdr->next_to_use = 0;
680 txdr->next_to_clean = 0;
686 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
687 * @adapter: board private structure
689 * Configure the Tx unit of the MAC after a reset.
693 ixgb_configure_tx(struct ixgb_adapter *adapter)
695 uint64_t tdba = adapter->tx_ring.dma;
696 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
698 struct ixgb_hw *hw = &adapter->hw;
700 /* Setup the Base and Length of the Tx Descriptor Ring
701 * tx_ring.dma can be either a 32 or 64 bit value
704 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
705 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
707 IXGB_WRITE_REG(hw, TDLEN, tdlen);
709 /* Setup the HW Tx Head and Tail descriptor pointers */
711 IXGB_WRITE_REG(hw, TDH, 0);
712 IXGB_WRITE_REG(hw, TDT, 0);
714 /* don't set up txdctl, it induces performance problems if configured
716 /* Set the Tx Interrupt Delay register */
718 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
720 /* Program the Transmit Control Register */
722 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
723 IXGB_WRITE_REG(hw, TCTL, tctl);
725 /* Setup Transmit Descriptor Settings for this adapter */
726 adapter->tx_cmd_type =
728 | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
732 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
733 * @adapter: board private structure
735 * Returns 0 on success, negative on failure
739 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
741 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
742 struct pci_dev *pdev = adapter->pdev;
745 size = sizeof(struct ixgb_buffer) * rxdr->count;
746 rxdr->buffer_info = vmalloc(size);
747 if(!rxdr->buffer_info) {
750 memset(rxdr->buffer_info, 0, size);
752 /* Round up to nearest 4K */
754 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
755 IXGB_ROUNDUP(rxdr->size, 4096);
757 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
760 vfree(rxdr->buffer_info);
763 memset(rxdr->desc, 0, rxdr->size);
765 rxdr->next_to_clean = 0;
766 rxdr->next_to_use = 0;
772 * ixgb_setup_rctl - configure the receive control register
773 * @adapter: Board private structure
777 ixgb_setup_rctl(struct ixgb_adapter *adapter)
781 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
783 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
786 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
787 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
788 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
790 rctl |= IXGB_RCTL_SECRC;
792 switch (adapter->rx_buffer_len) {
793 case IXGB_RXBUFFER_2048:
795 rctl |= IXGB_RCTL_BSIZE_2048;
797 case IXGB_RXBUFFER_4096:
798 rctl |= IXGB_RCTL_BSIZE_4096;
800 case IXGB_RXBUFFER_8192:
801 rctl |= IXGB_RCTL_BSIZE_8192;
803 case IXGB_RXBUFFER_16384:
804 rctl |= IXGB_RCTL_BSIZE_16384;
808 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
812 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
813 * @adapter: board private structure
815 * Configure the Rx unit of the MAC after a reset.
819 ixgb_configure_rx(struct ixgb_adapter *adapter)
821 uint64_t rdba = adapter->rx_ring.dma;
822 uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
823 struct ixgb_hw *hw = &adapter->hw;
828 /* make sure receives are disabled while setting up the descriptors */
830 rctl = IXGB_READ_REG(hw, RCTL);
831 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
833 /* set the Receive Delay Timer Register */
835 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
837 /* Setup the Base and Length of the Rx Descriptor Ring */
839 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
840 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
842 IXGB_WRITE_REG(hw, RDLEN, rdlen);
844 /* Setup the HW Rx Head and Tail Descriptor Pointers */
845 IXGB_WRITE_REG(hw, RDH, 0);
846 IXGB_WRITE_REG(hw, RDT, 0);
848 /* set up pre-fetching of receive buffers so we get some before we
849 * run out (default hardware behavior is to run out before fetching
850 * more). This sets up to fetch if HTHRESH rx descriptors are avail
851 * and the descriptors in hw cache are below PTHRESH. This avoids
852 * the hardware behavior of fetching <=512 descriptors in a single
853 * burst that pre-empts all other activity, usually causing fifo
855 /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */
856 rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |
857 RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |
858 RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
859 IXGB_WRITE_REG(hw, RXDCTL, rxdctl);
861 /* Enable Receive Checksum Offload for TCP and UDP */
862 if(adapter->rx_csum == TRUE) {
863 rxcsum = IXGB_READ_REG(hw, RXCSUM);
864 rxcsum |= IXGB_RXCSUM_TUOFL;
865 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
868 /* Enable Receives */
870 IXGB_WRITE_REG(hw, RCTL, rctl);
874 * ixgb_free_tx_resources - Free Tx Resources
875 * @adapter: board private structure
877 * Free all transmit software resources
881 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
883 struct pci_dev *pdev = adapter->pdev;
885 ixgb_clean_tx_ring(adapter);
887 vfree(adapter->tx_ring.buffer_info);
888 adapter->tx_ring.buffer_info = NULL;
890 pci_free_consistent(pdev, adapter->tx_ring.size,
891 adapter->tx_ring.desc, adapter->tx_ring.dma);
893 adapter->tx_ring.desc = NULL;
897 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
898 struct ixgb_buffer *buffer_info)
900 struct pci_dev *pdev = adapter->pdev;
901 if(buffer_info->dma) {
906 buffer_info->dma = 0;
908 if(buffer_info->skb) {
909 dev_kfree_skb_any(buffer_info->skb);
910 buffer_info->skb = NULL;
915 * ixgb_clean_tx_ring - Free Tx Buffers
916 * @adapter: board private structure
920 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
922 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
923 struct ixgb_buffer *buffer_info;
927 /* Free all the Tx ring sk_buffs */
929 for(i = 0; i < tx_ring->count; i++) {
930 buffer_info = &tx_ring->buffer_info[i];
931 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
934 size = sizeof(struct ixgb_buffer) * tx_ring->count;
935 memset(tx_ring->buffer_info, 0, size);
937 /* Zero out the descriptor ring */
939 memset(tx_ring->desc, 0, tx_ring->size);
941 tx_ring->next_to_use = 0;
942 tx_ring->next_to_clean = 0;
944 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
945 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
949 * ixgb_free_rx_resources - Free Rx Resources
950 * @adapter: board private structure
952 * Free all receive software resources
956 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
958 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
959 struct pci_dev *pdev = adapter->pdev;
961 ixgb_clean_rx_ring(adapter);
963 vfree(rx_ring->buffer_info);
964 rx_ring->buffer_info = NULL;
966 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
968 rx_ring->desc = NULL;
972 * ixgb_clean_rx_ring - Free Rx Buffers
973 * @adapter: board private structure
977 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
979 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
980 struct ixgb_buffer *buffer_info;
981 struct pci_dev *pdev = adapter->pdev;
985 /* Free all the Rx ring sk_buffs */
987 for(i = 0; i < rx_ring->count; i++) {
988 buffer_info = &rx_ring->buffer_info[i];
989 if(buffer_info->skb) {
991 pci_unmap_single(pdev,
996 dev_kfree_skb(buffer_info->skb);
998 buffer_info->skb = NULL;
1002 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1003 memset(rx_ring->buffer_info, 0, size);
1005 /* Zero out the descriptor ring */
1007 memset(rx_ring->desc, 0, rx_ring->size);
1009 rx_ring->next_to_clean = 0;
1010 rx_ring->next_to_use = 0;
1012 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1013 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1017 * ixgb_set_mac - Change the Ethernet Address of the NIC
1018 * @netdev: network interface device structure
1019 * @p: pointer to an address structure
1021 * Returns 0 on success, negative on failure
1025 ixgb_set_mac(struct net_device *netdev, void *p)
1027 struct ixgb_adapter *adapter = netdev_priv(netdev);
1028 struct sockaddr *addr = p;
1030 if(!is_valid_ether_addr(addr->sa_data))
1031 return -EADDRNOTAVAIL;
1033 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1035 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1041 * ixgb_set_multi - Multicast and Promiscuous mode set
1042 * @netdev: network interface device structure
1044 * The set_multi entry point is called whenever the multicast address
1045 * list or the network interface flags are updated. This routine is
1046 * responsible for configuring the hardware for proper multicast,
1047 * promiscuous mode, and all-multi behavior.
1051 ixgb_set_multi(struct net_device *netdev)
1053 struct ixgb_adapter *adapter = netdev_priv(netdev);
1054 struct ixgb_hw *hw = &adapter->hw;
1055 struct dev_mc_list *mc_ptr;
1059 /* Check for Promiscuous and All Multicast modes */
1061 rctl = IXGB_READ_REG(hw, RCTL);
1063 if(netdev->flags & IFF_PROMISC) {
1064 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1065 } else if(netdev->flags & IFF_ALLMULTI) {
1066 rctl |= IXGB_RCTL_MPE;
1067 rctl &= ~IXGB_RCTL_UPE;
1069 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1072 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1073 rctl |= IXGB_RCTL_MPE;
1074 IXGB_WRITE_REG(hw, RCTL, rctl);
1076 uint8_t mta[netdev->mc_count * IXGB_ETH_LENGTH_OF_ADDRESS];
1078 IXGB_WRITE_REG(hw, RCTL, rctl);
1080 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1081 i++, mc_ptr = mc_ptr->next)
1082 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1083 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1085 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1090 * ixgb_watchdog - Timer Call-back
1091 * @data: pointer to netdev cast into an unsigned long
1095 ixgb_watchdog(unsigned long data)
1097 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1098 struct net_device *netdev = adapter->netdev;
1099 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1101 ixgb_check_for_link(&adapter->hw);
1103 if (ixgb_check_for_bad_link(&adapter->hw)) {
1104 /* force the reset path */
1105 netif_stop_queue(netdev);
1108 if(adapter->hw.link_up) {
1109 if(!netif_carrier_ok(netdev)) {
1110 printk(KERN_INFO "ixgb: %s NIC Link is Up %d Mbps %s\n",
1111 netdev->name, 10000, "Full Duplex");
1112 adapter->link_speed = 10000;
1113 adapter->link_duplex = FULL_DUPLEX;
1114 netif_carrier_on(netdev);
1115 netif_wake_queue(netdev);
1118 if(netif_carrier_ok(netdev)) {
1119 adapter->link_speed = 0;
1120 adapter->link_duplex = 0;
1122 "ixgb: %s NIC Link is Down\n",
1124 netif_carrier_off(netdev);
1125 netif_stop_queue(netdev);
1130 ixgb_update_stats(adapter);
1132 if(!netif_carrier_ok(netdev)) {
1133 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1134 /* We've lost link, so the controller stops DMA,
1135 * but we've got queued Tx work that's never going
1136 * to get done, so reset controller to flush Tx.
1137 * (Do the reset outside of interrupt context). */
1138 schedule_work(&adapter->tx_timeout_task);
1142 /* Force detection of hung controller every watchdog period */
1143 adapter->detect_tx_hung = TRUE;
1145 /* generate an interrupt to force clean up of any stragglers */
1146 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1148 /* Reset the timer */
1149 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1152 #define IXGB_TX_FLAGS_CSUM 0x00000001
1153 #define IXGB_TX_FLAGS_VLAN 0x00000002
1154 #define IXGB_TX_FLAGS_TSO 0x00000004
1157 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1160 struct ixgb_context_desc *context_desc;
1162 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1163 uint16_t ipcse, tucse, mss;
1166 if(likely(skb_shinfo(skb)->tso_size)) {
1167 if (skb_header_cloned(skb)) {
1168 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1173 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1174 mss = skb_shinfo(skb)->tso_size;
1175 skb->nh.iph->tot_len = 0;
1176 skb->nh.iph->check = 0;
1177 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1180 ipcss = skb->nh.raw - skb->data;
1181 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1182 ipcse = skb->h.raw - skb->data - 1;
1183 tucss = skb->h.raw - skb->data;
1184 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1187 i = adapter->tx_ring.next_to_use;
1188 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1190 context_desc->ipcss = ipcss;
1191 context_desc->ipcso = ipcso;
1192 context_desc->ipcse = cpu_to_le16(ipcse);
1193 context_desc->tucss = tucss;
1194 context_desc->tucso = tucso;
1195 context_desc->tucse = cpu_to_le16(tucse);
1196 context_desc->mss = cpu_to_le16(mss);
1197 context_desc->hdr_len = hdr_len;
1198 context_desc->status = 0;
1199 context_desc->cmd_type_len = cpu_to_le32(
1200 IXGB_CONTEXT_DESC_TYPE
1201 | IXGB_CONTEXT_DESC_CMD_TSE
1202 | IXGB_CONTEXT_DESC_CMD_IP
1203 | IXGB_CONTEXT_DESC_CMD_TCP
1204 | IXGB_CONTEXT_DESC_CMD_IDE
1205 | (skb->len - (hdr_len)));
1208 if(++i == adapter->tx_ring.count) i = 0;
1209 adapter->tx_ring.next_to_use = i;
1218 static inline boolean_t
1219 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1221 struct ixgb_context_desc *context_desc;
1225 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1226 css = skb->h.raw - skb->data;
1227 cso = (skb->h.raw + skb->csum) - skb->data;
1229 i = adapter->tx_ring.next_to_use;
1230 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1232 context_desc->tucss = css;
1233 context_desc->tucso = cso;
1234 context_desc->tucse = 0;
1235 /* zero out any previously existing data in one instruction */
1236 *(uint32_t *)&(context_desc->ipcss) = 0;
1237 context_desc->status = 0;
1238 context_desc->hdr_len = 0;
1239 context_desc->mss = 0;
1240 context_desc->cmd_type_len =
1241 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1242 | IXGB_TX_DESC_CMD_IDE);
1244 if(++i == adapter->tx_ring.count) i = 0;
1245 adapter->tx_ring.next_to_use = i;
1253 #define IXGB_MAX_TXD_PWR 14
1254 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1257 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1260 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1261 struct ixgb_buffer *buffer_info;
1263 unsigned int offset = 0, size, count = 0, i;
1265 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1268 len -= skb->data_len;
1270 i = tx_ring->next_to_use;
1273 buffer_info = &tx_ring->buffer_info[i];
1274 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1275 buffer_info->length = size;
1277 pci_map_single(adapter->pdev,
1281 buffer_info->time_stamp = jiffies;
1286 if(++i == tx_ring->count) i = 0;
1289 for(f = 0; f < nr_frags; f++) {
1290 struct skb_frag_struct *frag;
1292 frag = &skb_shinfo(skb)->frags[f];
1297 buffer_info = &tx_ring->buffer_info[i];
1298 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1299 buffer_info->length = size;
1301 pci_map_page(adapter->pdev,
1303 frag->page_offset + offset,
1306 buffer_info->time_stamp = jiffies;
1311 if(++i == tx_ring->count) i = 0;
1314 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1315 tx_ring->buffer_info[i].skb = skb;
1316 tx_ring->buffer_info[first].next_to_watch = i;
1322 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1324 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1325 struct ixgb_tx_desc *tx_desc = NULL;
1326 struct ixgb_buffer *buffer_info;
1327 uint32_t cmd_type_len = adapter->tx_cmd_type;
1332 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1333 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1334 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1337 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1338 popts |= IXGB_TX_DESC_POPTS_TXSM;
1340 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1341 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1344 i = tx_ring->next_to_use;
1347 buffer_info = &tx_ring->buffer_info[i];
1348 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1349 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1350 tx_desc->cmd_type_len =
1351 cpu_to_le32(cmd_type_len | buffer_info->length);
1352 tx_desc->status = status;
1353 tx_desc->popts = popts;
1354 tx_desc->vlan = cpu_to_le16(vlan_id);
1356 if(++i == tx_ring->count) i = 0;
1359 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1360 | IXGB_TX_DESC_CMD_RS );
1362 /* Force memory writes to complete before letting h/w
1363 * know there are new descriptors to fetch. (Only
1364 * applicable for weak-ordered memory model archs,
1365 * such as IA-64). */
1368 tx_ring->next_to_use = i;
1369 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1372 /* Tx Descriptors needed, worst case */
1373 #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1374 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1375 #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \
1376 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1
1379 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1381 struct ixgb_adapter *adapter = netdev_priv(netdev);
1383 unsigned int tx_flags = 0;
1384 unsigned long flags;
1389 dev_kfree_skb_any(skb);
1393 spin_lock_irqsave(&adapter->tx_lock, flags);
1394 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) {
1395 netif_stop_queue(netdev);
1396 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1399 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1401 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1402 tx_flags |= IXGB_TX_FLAGS_VLAN;
1403 vlan_id = vlan_tx_tag_get(skb);
1406 first = adapter->tx_ring.next_to_use;
1408 tso = ixgb_tso(adapter, skb);
1410 dev_kfree_skb_any(skb);
1411 return NETDEV_TX_OK;
1415 tx_flags |= IXGB_TX_FLAGS_TSO;
1416 else if(ixgb_tx_csum(adapter, skb))
1417 tx_flags |= IXGB_TX_FLAGS_CSUM;
1419 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1422 netdev->trans_start = jiffies;
1428 * ixgb_tx_timeout - Respond to a Tx Hang
1429 * @netdev: network interface device structure
1433 ixgb_tx_timeout(struct net_device *netdev)
1435 struct ixgb_adapter *adapter = netdev_priv(netdev);
1437 /* Do the reset outside of interrupt context */
1438 schedule_work(&adapter->tx_timeout_task);
1442 ixgb_tx_timeout_task(struct net_device *netdev)
1444 struct ixgb_adapter *adapter = netdev_priv(netdev);
1446 ixgb_down(adapter, TRUE);
1451 * ixgb_get_stats - Get System Network Statistics
1452 * @netdev: network interface device structure
1454 * Returns the address of the device statistics structure.
1455 * The statistics are actually updated from the timer callback.
1458 static struct net_device_stats *
1459 ixgb_get_stats(struct net_device *netdev)
1461 struct ixgb_adapter *adapter = netdev_priv(netdev);
1463 return &adapter->net_stats;
1467 * ixgb_change_mtu - Change the Maximum Transfer Unit
1468 * @netdev: network interface device structure
1469 * @new_mtu: new value for maximum frame size
1471 * Returns 0 on success, negative on failure
1475 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1477 struct ixgb_adapter *adapter = netdev_priv(netdev);
1478 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1479 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1482 if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1483 || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
1484 IXGB_ERR("Invalid MTU setting\n");
1488 if((max_frame <= IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1489 || (max_frame <= IXGB_RXBUFFER_2048)) {
1490 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
1492 } else if(max_frame <= IXGB_RXBUFFER_4096) {
1493 adapter->rx_buffer_len = IXGB_RXBUFFER_4096;
1495 } else if(max_frame <= IXGB_RXBUFFER_8192) {
1496 adapter->rx_buffer_len = IXGB_RXBUFFER_8192;
1499 adapter->rx_buffer_len = IXGB_RXBUFFER_16384;
1502 netdev->mtu = new_mtu;
1504 if(old_max_frame != max_frame && netif_running(netdev)) {
1506 ixgb_down(adapter, TRUE);
1514 * ixgb_update_stats - Update the board statistics counters.
1515 * @adapter: board private structure
1519 ixgb_update_stats(struct ixgb_adapter *adapter)
1521 struct net_device *netdev = adapter->netdev;
1523 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1524 (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1525 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1526 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1527 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1528 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1530 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1531 /* fix up multicast stats by removing broadcasts */
1535 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1536 adapter->stats.mprch += (multi >> 32);
1537 adapter->stats.bprcl += bcast_l;
1538 adapter->stats.bprch += bcast_h;
1540 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1541 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1542 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1543 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1545 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1546 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1547 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1548 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1549 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1550 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1551 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1552 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1553 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1554 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1555 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1556 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1557 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1558 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1559 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1560 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1561 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1562 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1563 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1564 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1565 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1566 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1567 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1568 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1569 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1570 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1571 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1572 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1573 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1574 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1575 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1576 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1577 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1578 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1579 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1580 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1581 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1582 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1583 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1584 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1585 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1586 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1587 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1588 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1589 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1590 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1591 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1592 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1593 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1594 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1595 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1596 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1597 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1598 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1599 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1600 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1602 /* Fill out the OS statistics structure */
1604 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1605 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1606 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1607 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1608 adapter->net_stats.multicast = adapter->stats.mprcl;
1609 adapter->net_stats.collisions = 0;
1611 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1612 * with a length in the type/len field */
1613 adapter->net_stats.rx_errors =
1614 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1615 adapter->stats.ruc +
1616 adapter->stats.roc /*+ adapter->stats.rlec */ +
1617 adapter->stats.icbc +
1618 adapter->stats.ecbc + adapter->stats.mpc;
1621 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1624 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1625 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1626 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1627 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1629 adapter->net_stats.tx_errors = 0;
1630 adapter->net_stats.rx_frame_errors = 0;
1631 adapter->net_stats.tx_aborted_errors = 0;
1632 adapter->net_stats.tx_carrier_errors = 0;
1633 adapter->net_stats.tx_fifo_errors = 0;
1634 adapter->net_stats.tx_heartbeat_errors = 0;
1635 adapter->net_stats.tx_window_errors = 0;
1638 #define IXGB_MAX_INTR 10
1640 * ixgb_intr - Interrupt Handler
1641 * @irq: interrupt number
1642 * @data: pointer to a network interface device structure
1643 * @pt_regs: CPU registers structure
1647 ixgb_intr(int irq, void *data, struct pt_regs *regs)
1649 struct net_device *netdev = data;
1650 struct ixgb_adapter *adapter = netdev_priv(netdev);
1651 struct ixgb_hw *hw = &adapter->hw;
1652 uint32_t icr = IXGB_READ_REG(hw, ICR);
1653 #ifndef CONFIG_IXGB_NAPI
1658 return IRQ_NONE; /* Not our interrupt */
1660 if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) {
1661 mod_timer(&adapter->watchdog_timer, jiffies);
1664 #ifdef CONFIG_IXGB_NAPI
1665 if(netif_rx_schedule_prep(netdev)) {
1667 /* Disable interrupts and register for poll. The flush
1668 of the posted write is intentionally left out.
1671 atomic_inc(&adapter->irq_sem);
1672 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1673 __netif_rx_schedule(netdev);
1676 /* yes, that is actually a & and it is meant to make sure that
1677 * every pass through this for loop checks both receive and
1678 * transmit queues for completed descriptors, intended to
1679 * avoid starvation issues and assist tx/rx fairness. */
1680 for(i = 0; i < IXGB_MAX_INTR; i++)
1681 if(!ixgb_clean_rx_irq(adapter) &
1682 !ixgb_clean_tx_irq(adapter))
1688 #ifdef CONFIG_IXGB_NAPI
1690 * ixgb_clean - NAPI Rx polling callback
1691 * @adapter: board private structure
1695 ixgb_clean(struct net_device *netdev, int *budget)
1697 struct ixgb_adapter *adapter = netdev_priv(netdev);
1698 int work_to_do = min(*budget, netdev->quota);
1702 tx_cleaned = ixgb_clean_tx_irq(adapter);
1703 ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
1705 *budget -= work_done;
1706 netdev->quota -= work_done;
1708 /* if no Tx and not enough Rx work done, exit the polling mode */
1709 if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
1710 netif_rx_complete(netdev);
1711 ixgb_irq_enable(adapter);
1720 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1721 * @adapter: board private structure
1725 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1727 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1728 struct net_device *netdev = adapter->netdev;
1729 struct ixgb_tx_desc *tx_desc, *eop_desc;
1730 struct ixgb_buffer *buffer_info;
1731 unsigned int i, eop;
1732 boolean_t cleaned = FALSE;
1734 i = tx_ring->next_to_clean;
1735 eop = tx_ring->buffer_info[i].next_to_watch;
1736 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1738 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1740 for(cleaned = FALSE; !cleaned; ) {
1741 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1742 buffer_info = &tx_ring->buffer_info[i];
1745 & (IXGB_TX_DESC_POPTS_TXSM |
1746 IXGB_TX_DESC_POPTS_IXSM))
1747 adapter->hw_csum_tx_good++;
1749 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1751 *(uint32_t *)&(tx_desc->status) = 0;
1753 cleaned = (i == eop);
1754 if(++i == tx_ring->count) i = 0;
1757 eop = tx_ring->buffer_info[i].next_to_watch;
1758 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1761 tx_ring->next_to_clean = i;
1763 spin_lock(&adapter->tx_lock);
1764 if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1765 (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) {
1767 netif_wake_queue(netdev);
1769 spin_unlock(&adapter->tx_lock);
1771 if(adapter->detect_tx_hung) {
1772 /* detect a transmit hang in hardware, this serializes the
1773 * check with the clearing of time_stamp and movement of i */
1774 adapter->detect_tx_hung = FALSE;
1775 if(tx_ring->buffer_info[i].dma &&
1776 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
1777 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1779 netif_stop_queue(netdev);
1786 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1787 * @adapter: board private structure
1788 * @rx_desc: receive descriptor
1789 * @sk_buff: socket buffer with received data
1793 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1794 struct ixgb_rx_desc *rx_desc,
1795 struct sk_buff *skb)
1797 /* Ignore Checksum bit is set OR
1798 * TCP Checksum has not been calculated
1800 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1801 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1802 skb->ip_summed = CHECKSUM_NONE;
1806 /* At this point we know the hardware did the TCP checksum */
1807 /* now look at the TCP checksum error bit */
1808 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1809 /* let the stack verify checksum errors */
1810 skb->ip_summed = CHECKSUM_NONE;
1811 adapter->hw_csum_rx_error++;
1813 /* TCP checksum is good */
1814 skb->ip_summed = CHECKSUM_UNNECESSARY;
1815 adapter->hw_csum_rx_good++;
1820 * ixgb_clean_rx_irq - Send received data up the network stack,
1821 * @adapter: board private structure
1825 #ifdef CONFIG_IXGB_NAPI
1826 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1828 ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1831 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1832 struct net_device *netdev = adapter->netdev;
1833 struct pci_dev *pdev = adapter->pdev;
1834 struct ixgb_rx_desc *rx_desc, *next_rxd;
1835 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1838 boolean_t cleaned = FALSE;
1840 i = rx_ring->next_to_clean;
1841 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1842 buffer_info = &rx_ring->buffer_info[i];
1844 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1845 struct sk_buff *skb, *next_skb;
1848 #ifdef CONFIG_IXGB_NAPI
1849 if(*work_done >= work_to_do)
1854 status = rx_desc->status;
1855 skb = buffer_info->skb;
1857 prefetch(skb->data);
1859 if(++i == rx_ring->count) i = 0;
1860 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1863 if((j = i + 1) == rx_ring->count) j = 0;
1864 next2_buffer = &rx_ring->buffer_info[j];
1865 prefetch(next2_buffer);
1867 next_buffer = &rx_ring->buffer_info[i];
1868 next_skb = next_buffer->skb;
1873 pci_unmap_single(pdev,
1875 buffer_info->length,
1876 PCI_DMA_FROMDEVICE);
1878 length = le16_to_cpu(rx_desc->length);
1880 if(unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
1882 /* All receives must fit into a single buffer */
1884 IXGB_DBG("Receive packet consumed multiple buffers "
1885 "length<%x>\n", length);
1887 dev_kfree_skb_irq(skb);
1891 if (unlikely(rx_desc->errors
1892 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1893 | IXGB_RX_DESC_ERRORS_P |
1894 IXGB_RX_DESC_ERRORS_RXE))) {
1896 dev_kfree_skb_irq(skb);
1901 skb_put(skb, length);
1903 /* Receive Checksum Offload */
1904 ixgb_rx_checksum(adapter, rx_desc, skb);
1906 skb->protocol = eth_type_trans(skb, netdev);
1907 #ifdef CONFIG_IXGB_NAPI
1908 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1909 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
1910 le16_to_cpu(rx_desc->special) &
1911 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1913 netif_receive_skb(skb);
1915 #else /* CONFIG_IXGB_NAPI */
1916 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1917 vlan_hwaccel_rx(skb, adapter->vlgrp,
1918 le16_to_cpu(rx_desc->special) &
1919 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1923 #endif /* CONFIG_IXGB_NAPI */
1924 netdev->last_rx = jiffies;
1927 /* clean up descriptor, might be written over by hw */
1928 rx_desc->status = 0;
1929 buffer_info->skb = NULL;
1931 /* use prefetched values */
1933 buffer_info = next_buffer;
1936 rx_ring->next_to_clean = i;
1938 ixgb_alloc_rx_buffers(adapter);
1944 * ixgb_alloc_rx_buffers - Replace used receive buffers
1945 * @adapter: address of board private structure
1949 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
1951 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1952 struct net_device *netdev = adapter->netdev;
1953 struct pci_dev *pdev = adapter->pdev;
1954 struct ixgb_rx_desc *rx_desc;
1955 struct ixgb_buffer *buffer_info;
1956 struct sk_buff *skb;
1958 int num_group_tail_writes;
1961 i = rx_ring->next_to_use;
1962 buffer_info = &rx_ring->buffer_info[i];
1963 cleancount = IXGB_DESC_UNUSED(rx_ring);
1965 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
1967 /* leave three descriptors unused */
1968 while(--cleancount > 2) {
1969 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1971 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1973 if(unlikely(!skb)) {
1974 /* Better luck next round */
1978 /* Make buffer alignment 2 beyond a 16 byte boundary
1979 * this will result in a 16 byte aligned IP header after
1980 * the 14 byte MAC header is removed
1982 skb_reserve(skb, NET_IP_ALIGN);
1986 buffer_info->skb = skb;
1987 buffer_info->length = adapter->rx_buffer_len;
1989 pci_map_single(pdev,
1991 adapter->rx_buffer_len,
1992 PCI_DMA_FROMDEVICE);
1994 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1995 /* guarantee DD bit not set now before h/w gets descriptor
1996 * this is the rest of the workaround for h/w double
1998 rx_desc->status = 0;
2000 if((i & ~(num_group_tail_writes- 1)) == i) {
2001 /* Force memory writes to complete before letting h/w
2002 * know there are new descriptors to fetch. (Only
2003 * applicable for weak-ordered memory model archs,
2004 * such as IA-64). */
2007 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2010 if(++i == rx_ring->count) i = 0;
2011 buffer_info = &rx_ring->buffer_info[i];
2014 rx_ring->next_to_use = i;
2018 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2020 * @param netdev network interface device structure
2021 * @param grp indicates to enable or disable tagging/stripping
2024 ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2026 struct ixgb_adapter *adapter = netdev_priv(netdev);
2027 uint32_t ctrl, rctl;
2029 ixgb_irq_disable(adapter);
2030 adapter->vlgrp = grp;
2033 /* enable VLAN tag insert/strip */
2034 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2035 ctrl |= IXGB_CTRL0_VME;
2036 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2038 /* enable VLAN receive filtering */
2040 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2041 rctl |= IXGB_RCTL_VFE;
2042 rctl &= ~IXGB_RCTL_CFIEN;
2043 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2045 /* disable VLAN tag insert/strip */
2047 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2048 ctrl &= ~IXGB_CTRL0_VME;
2049 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2051 /* disable VLAN filtering */
2053 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2054 rctl &= ~IXGB_RCTL_VFE;
2055 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2058 ixgb_irq_enable(adapter);
2062 ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
2064 struct ixgb_adapter *adapter = netdev_priv(netdev);
2065 uint32_t vfta, index;
2067 /* add VID to filter table */
2069 index = (vid >> 5) & 0x7F;
2070 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2071 vfta |= (1 << (vid & 0x1F));
2072 ixgb_write_vfta(&adapter->hw, index, vfta);
2076 ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2078 struct ixgb_adapter *adapter = netdev_priv(netdev);
2079 uint32_t vfta, index;
2081 ixgb_irq_disable(adapter);
2084 adapter->vlgrp->vlan_devices[vid] = NULL;
2086 ixgb_irq_enable(adapter);
2088 /* remove VID from filter table*/
2090 index = (vid >> 5) & 0x7F;
2091 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2092 vfta &= ~(1 << (vid & 0x1F));
2093 ixgb_write_vfta(&adapter->hw, index, vfta);
2097 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2099 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2101 if(adapter->vlgrp) {
2103 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2104 if(!adapter->vlgrp->vlan_devices[vid])
2106 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2111 #ifdef CONFIG_NET_POLL_CONTROLLER
2113 * Polling 'interrupt' - used by things like netconsole to send skbs
2114 * without having to re-enable interrupts. It's not called while
2115 * the interrupt routine is executing.
2118 static void ixgb_netpoll(struct net_device *dev)
2120 struct ixgb_adapter *adapter = dev->priv;
2122 disable_irq(adapter->pdev->irq);
2123 ixgb_intr(adapter->pdev->irq, dev, NULL);
2124 enable_irq(adapter->pdev->irq);