1 /*******************************************************************************
3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
31 char ixgb_driver_name[] = "ixgb";
32 static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
34 #ifndef CONFIG_IXGB_NAPI
37 #define DRIVERNAPI "-NAPI"
39 #define DRV_VERSION "1.0.126-k4"DRIVERNAPI
40 const char ixgb_driver_version[] = DRV_VERSION;
41 static const char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
43 /* ixgb_pci_tbl - PCI Device ID Table
45 * Wildcard entries (PCI_ANY_ID) should come last
46 * Last entry must be all 0s
48 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
49 * Class, Class Mask, private data (not used) }
51 static struct pci_device_id ixgb_pci_tbl[] = {
52 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX,
53 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
54 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_CX4,
55 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
56 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR,
57 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
58 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR,
59 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
61 /* required last entry */
65 MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
67 /* Local Function Prototypes */
69 int ixgb_up(struct ixgb_adapter *adapter);
70 void ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog);
71 void ixgb_reset(struct ixgb_adapter *adapter);
72 int ixgb_setup_tx_resources(struct ixgb_adapter *adapter);
73 int ixgb_setup_rx_resources(struct ixgb_adapter *adapter);
74 void ixgb_free_tx_resources(struct ixgb_adapter *adapter);
75 void ixgb_free_rx_resources(struct ixgb_adapter *adapter);
76 void ixgb_update_stats(struct ixgb_adapter *adapter);
78 static int ixgb_init_module(void);
79 static void ixgb_exit_module(void);
80 static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
81 static void __devexit ixgb_remove(struct pci_dev *pdev);
82 static int ixgb_sw_init(struct ixgb_adapter *adapter);
83 static int ixgb_open(struct net_device *netdev);
84 static int ixgb_close(struct net_device *netdev);
85 static void ixgb_configure_tx(struct ixgb_adapter *adapter);
86 static void ixgb_configure_rx(struct ixgb_adapter *adapter);
87 static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
88 static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
89 static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
90 static void ixgb_set_multi(struct net_device *netdev);
91 static void ixgb_watchdog(unsigned long data);
92 static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
93 static struct net_device_stats *ixgb_get_stats(struct net_device *netdev);
94 static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
95 static int ixgb_set_mac(struct net_device *netdev, void *p);
96 static irqreturn_t ixgb_intr(int irq, void *data);
97 static bool ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
99 #ifdef CONFIG_IXGB_NAPI
100 static int ixgb_clean(struct napi_struct *napi, int budget);
101 static bool ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
102 int *work_done, int work_to_do);
104 static bool ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
106 static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter);
107 static void ixgb_tx_timeout(struct net_device *dev);
108 static void ixgb_tx_timeout_task(struct work_struct *work);
109 static void ixgb_vlan_rx_register(struct net_device *netdev,
110 struct vlan_group *grp);
111 static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
112 static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
113 static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
115 #ifdef CONFIG_NET_POLL_CONTROLLER
116 /* for netdump / net console */
117 static void ixgb_netpoll(struct net_device *dev);
120 static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
121 enum pci_channel_state state);
122 static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev);
123 static void ixgb_io_resume (struct pci_dev *pdev);
125 static struct pci_error_handlers ixgb_err_handler = {
126 .error_detected = ixgb_io_error_detected,
127 .slot_reset = ixgb_io_slot_reset,
128 .resume = ixgb_io_resume,
131 static struct pci_driver ixgb_driver = {
132 .name = ixgb_driver_name,
133 .id_table = ixgb_pci_tbl,
135 .remove = __devexit_p(ixgb_remove),
136 .err_handler = &ixgb_err_handler
139 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
141 MODULE_LICENSE("GPL");
142 MODULE_VERSION(DRV_VERSION);
144 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
145 static int debug = DEFAULT_DEBUG_LEVEL_SHIFT;
146 module_param(debug, int, 0);
147 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
149 /* some defines for controlling descriptor fetches in h/w */
150 #define RXDCTL_WTHRESH_DEFAULT 15 /* chip writes back at this many or RXT0 */
151 #define RXDCTL_PTHRESH_DEFAULT 0 /* chip considers prefech below
153 #define RXDCTL_HTHRESH_DEFAULT 0 /* chip will only prefetch if tail
154 * is pushed this many descriptors
158 * ixgb_init_module - Driver Registration Routine
160 * ixgb_init_module is the first routine called when the driver is
161 * loaded. All it does is register with the PCI subsystem.
165 ixgb_init_module(void)
167 printk(KERN_INFO "%s - version %s\n",
168 ixgb_driver_string, ixgb_driver_version);
170 printk(KERN_INFO "%s\n", ixgb_copyright);
172 return pci_register_driver(&ixgb_driver);
175 module_init(ixgb_init_module);
178 * ixgb_exit_module - Driver Exit Cleanup Routine
180 * ixgb_exit_module is called just before the driver is removed
185 ixgb_exit_module(void)
187 pci_unregister_driver(&ixgb_driver);
190 module_exit(ixgb_exit_module);
193 * ixgb_irq_disable - Mask off interrupt generation on the NIC
194 * @adapter: board private structure
198 ixgb_irq_disable(struct ixgb_adapter *adapter)
200 atomic_inc(&adapter->irq_sem);
201 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
202 IXGB_WRITE_FLUSH(&adapter->hw);
203 synchronize_irq(adapter->pdev->irq);
207 * ixgb_irq_enable - Enable default interrupt generation settings
208 * @adapter: board private structure
212 ixgb_irq_enable(struct ixgb_adapter *adapter)
214 if(atomic_dec_and_test(&adapter->irq_sem)) {
215 u32 val = IXGB_INT_RXT0 | IXGB_INT_RXDMT0 |
216 IXGB_INT_TXDW | IXGB_INT_LSC;
217 if (adapter->hw.subsystem_vendor_id == SUN_SUBVENDOR_ID)
218 val |= IXGB_INT_GPI0;
219 IXGB_WRITE_REG(&adapter->hw, IMS, val);
220 IXGB_WRITE_FLUSH(&adapter->hw);
225 ixgb_up(struct ixgb_adapter *adapter)
227 struct net_device *netdev = adapter->netdev;
228 int err, irq_flags = IRQF_SHARED;
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_rar_set(hw, netdev->dev_addr, 0);
235 ixgb_set_multi(netdev);
237 ixgb_restore_vlan(adapter);
239 ixgb_configure_tx(adapter);
240 ixgb_setup_rctl(adapter);
241 ixgb_configure_rx(adapter);
242 ixgb_alloc_rx_buffers(adapter);
244 /* disable interrupts and get the hardware into a known state */
245 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
247 /* only enable MSI if bus is in PCI-X mode */
248 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_PCIX_MODE) {
249 err = pci_enable_msi(adapter->pdev);
251 adapter->have_msi = 1;
254 /* proceed to try to request regular interrupt */
257 err = request_irq(adapter->pdev->irq, &ixgb_intr, irq_flags,
258 netdev->name, netdev);
260 if (adapter->have_msi)
261 pci_disable_msi(adapter->pdev);
263 "Unable to allocate interrupt Error: %d\n", err);
267 if((hw->max_frame_size != max_frame) ||
268 (hw->max_frame_size !=
269 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
271 hw->max_frame_size = max_frame;
273 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
275 if(hw->max_frame_size >
276 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
277 uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0);
279 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
280 ctrl0 |= IXGB_CTRL0_JFE;
281 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
286 clear_bit(__IXGB_DOWN, &adapter->flags);
288 #ifdef CONFIG_IXGB_NAPI
289 napi_enable(&adapter->napi);
291 ixgb_irq_enable(adapter);
293 mod_timer(&adapter->watchdog_timer, jiffies);
299 ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog)
301 struct net_device *netdev = adapter->netdev;
303 /* prevent the interrupt handler from restarting watchdog */
304 set_bit(__IXGB_DOWN, &adapter->flags);
306 #ifdef CONFIG_IXGB_NAPI
307 napi_disable(&adapter->napi);
308 atomic_set(&adapter->irq_sem, 0);
310 /* waiting for NAPI to complete can re-enable interrupts */
311 ixgb_irq_disable(adapter);
312 free_irq(adapter->pdev->irq, netdev);
314 if (adapter->have_msi)
315 pci_disable_msi(adapter->pdev);
318 del_timer_sync(&adapter->watchdog_timer);
320 adapter->link_speed = 0;
321 adapter->link_duplex = 0;
322 netif_carrier_off(netdev);
323 netif_stop_queue(netdev);
326 ixgb_clean_tx_ring(adapter);
327 ixgb_clean_rx_ring(adapter);
331 ixgb_reset(struct ixgb_adapter *adapter)
333 struct ixgb_hw *hw = &adapter->hw;
335 ixgb_adapter_stop(hw);
336 if (!ixgb_init_hw(hw))
337 DPRINTK(PROBE, ERR, "ixgb_init_hw failed.\n");
339 /* restore frame size information */
340 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
341 if (hw->max_frame_size >
342 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
343 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
344 if (!(ctrl0 & IXGB_CTRL0_JFE)) {
345 ctrl0 |= IXGB_CTRL0_JFE;
346 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
352 * ixgb_probe - Device Initialization Routine
353 * @pdev: PCI device information struct
354 * @ent: entry in ixgb_pci_tbl
356 * Returns 0 on success, negative on failure
358 * ixgb_probe initializes an adapter identified by a pci_dev structure.
359 * The OS initialization, configuring of the adapter private structure,
360 * and a hardware reset occur.
364 ixgb_probe(struct pci_dev *pdev,
365 const struct pci_device_id *ent)
367 struct net_device *netdev = NULL;
368 struct ixgb_adapter *adapter;
369 static int cards_found = 0;
370 unsigned long mmio_start;
376 if((err = pci_enable_device(pdev)))
379 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
380 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
383 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
384 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
386 "ixgb: No usable DMA configuration, aborting\n");
392 if((err = pci_request_regions(pdev, ixgb_driver_name)))
393 goto err_request_regions;
395 pci_set_master(pdev);
397 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
400 goto err_alloc_etherdev;
403 SET_NETDEV_DEV(netdev, &pdev->dev);
405 pci_set_drvdata(pdev, netdev);
406 adapter = netdev_priv(netdev);
407 adapter->netdev = netdev;
408 adapter->pdev = pdev;
409 adapter->hw.back = adapter;
410 adapter->msg_enable = netif_msg_init(debug, DEFAULT_DEBUG_LEVEL_SHIFT);
412 mmio_start = pci_resource_start(pdev, BAR_0);
413 mmio_len = pci_resource_len(pdev, BAR_0);
415 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
416 if(!adapter->hw.hw_addr) {
421 for(i = BAR_1; i <= BAR_5; i++) {
422 if(pci_resource_len(pdev, i) == 0)
424 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
425 adapter->hw.io_base = pci_resource_start(pdev, i);
430 netdev->open = &ixgb_open;
431 netdev->stop = &ixgb_close;
432 netdev->hard_start_xmit = &ixgb_xmit_frame;
433 netdev->get_stats = &ixgb_get_stats;
434 netdev->set_multicast_list = &ixgb_set_multi;
435 netdev->set_mac_address = &ixgb_set_mac;
436 netdev->change_mtu = &ixgb_change_mtu;
437 ixgb_set_ethtool_ops(netdev);
438 netdev->tx_timeout = &ixgb_tx_timeout;
439 netdev->watchdog_timeo = 5 * HZ;
440 #ifdef CONFIG_IXGB_NAPI
441 netif_napi_add(netdev, &adapter->napi, ixgb_clean, 64);
443 netdev->vlan_rx_register = ixgb_vlan_rx_register;
444 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
445 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
446 #ifdef CONFIG_NET_POLL_CONTROLLER
447 netdev->poll_controller = ixgb_netpoll;
450 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
451 netdev->mem_start = mmio_start;
452 netdev->mem_end = mmio_start + mmio_len;
453 netdev->base_addr = adapter->hw.io_base;
455 adapter->bd_number = cards_found;
456 adapter->link_speed = 0;
457 adapter->link_duplex = 0;
459 /* setup the private structure */
461 if((err = ixgb_sw_init(adapter)))
464 netdev->features = NETIF_F_SG |
468 NETIF_F_HW_VLAN_FILTER;
469 netdev->features |= NETIF_F_TSO;
471 netdev->features |= NETIF_F_LLTX;
475 netdev->features |= NETIF_F_HIGHDMA;
477 /* make sure the EEPROM is good */
479 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
480 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
485 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
486 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
488 if(!is_valid_ether_addr(netdev->perm_addr)) {
489 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
494 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
496 init_timer(&adapter->watchdog_timer);
497 adapter->watchdog_timer.function = &ixgb_watchdog;
498 adapter->watchdog_timer.data = (unsigned long)adapter;
500 INIT_WORK(&adapter->tx_timeout_task, ixgb_tx_timeout_task);
502 strcpy(netdev->name, "eth%d");
503 if((err = register_netdev(netdev)))
506 /* we're going to reset, so assume we have no link for now */
508 netif_carrier_off(netdev);
509 netif_stop_queue(netdev);
511 DPRINTK(PROBE, INFO, "Intel(R) PRO/10GbE Network Connection\n");
512 ixgb_check_options(adapter);
513 /* reset the hardware with the new settings */
523 iounmap(adapter->hw.hw_addr);
527 pci_release_regions(pdev);
530 pci_disable_device(pdev);
535 * ixgb_remove - Device Removal Routine
536 * @pdev: PCI device information struct
538 * ixgb_remove is called by the PCI subsystem to alert the driver
539 * that it should release a PCI device. The could be caused by a
540 * Hot-Plug event, or because the driver is going to be removed from
544 static void __devexit
545 ixgb_remove(struct pci_dev *pdev)
547 struct net_device *netdev = pci_get_drvdata(pdev);
548 struct ixgb_adapter *adapter = netdev_priv(netdev);
550 unregister_netdev(netdev);
552 iounmap(adapter->hw.hw_addr);
553 pci_release_regions(pdev);
559 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
560 * @adapter: board private structure to initialize
562 * ixgb_sw_init initializes the Adapter private data structure.
563 * Fields are initialized based on PCI device information and
564 * OS network device settings (MTU size).
568 ixgb_sw_init(struct ixgb_adapter *adapter)
570 struct ixgb_hw *hw = &adapter->hw;
571 struct net_device *netdev = adapter->netdev;
572 struct pci_dev *pdev = adapter->pdev;
574 /* PCI config space info */
576 hw->vendor_id = pdev->vendor;
577 hw->device_id = pdev->device;
578 hw->subsystem_vendor_id = pdev->subsystem_vendor;
579 hw->subsystem_id = pdev->subsystem_device;
581 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
582 adapter->rx_buffer_len = hw->max_frame_size;
584 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
585 || (hw->device_id == IXGB_DEVICE_ID_82597EX_CX4)
586 || (hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
587 || (hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
588 hw->mac_type = ixgb_82597;
590 /* should never have loaded on this device */
591 DPRINTK(PROBE, ERR, "unsupported device id\n");
594 /* enable flow control to be programmed */
597 atomic_set(&adapter->irq_sem, 1);
598 spin_lock_init(&adapter->tx_lock);
600 set_bit(__IXGB_DOWN, &adapter->flags);
605 * ixgb_open - Called when a network interface is made active
606 * @netdev: network interface device structure
608 * Returns 0 on success, negative value on failure
610 * The open entry point is called when a network interface is made
611 * active by the system (IFF_UP). At this point all resources needed
612 * for transmit and receive operations are allocated, the interrupt
613 * handler is registered with the OS, the watchdog timer is started,
614 * and the stack is notified that the interface is ready.
618 ixgb_open(struct net_device *netdev)
620 struct ixgb_adapter *adapter = netdev_priv(netdev);
623 /* allocate transmit descriptors */
625 if((err = ixgb_setup_tx_resources(adapter)))
628 /* allocate receive descriptors */
630 if((err = ixgb_setup_rx_resources(adapter)))
633 if((err = ixgb_up(adapter)))
639 ixgb_free_rx_resources(adapter);
641 ixgb_free_tx_resources(adapter);
649 * ixgb_close - Disables a network interface
650 * @netdev: network interface device structure
652 * Returns 0, this is not allowed to fail
654 * The close entry point is called when an interface is de-activated
655 * by the OS. The hardware is still under the drivers control, but
656 * needs to be disabled. A global MAC reset is issued to stop the
657 * hardware, and all transmit and receive resources are freed.
661 ixgb_close(struct net_device *netdev)
663 struct ixgb_adapter *adapter = netdev_priv(netdev);
665 ixgb_down(adapter, true);
667 ixgb_free_tx_resources(adapter);
668 ixgb_free_rx_resources(adapter);
674 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
675 * @adapter: board private structure
677 * Return 0 on success, negative on failure
681 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
683 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
684 struct pci_dev *pdev = adapter->pdev;
687 size = sizeof(struct ixgb_buffer) * txdr->count;
688 txdr->buffer_info = vmalloc(size);
689 if(!txdr->buffer_info) {
691 "Unable to allocate transmit descriptor ring memory\n");
694 memset(txdr->buffer_info, 0, size);
696 /* round up to nearest 4K */
698 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
699 txdr->size = ALIGN(txdr->size, 4096);
701 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
703 vfree(txdr->buffer_info);
705 "Unable to allocate transmit descriptor memory\n");
708 memset(txdr->desc, 0, txdr->size);
710 txdr->next_to_use = 0;
711 txdr->next_to_clean = 0;
717 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
718 * @adapter: board private structure
720 * Configure the Tx unit of the MAC after a reset.
724 ixgb_configure_tx(struct ixgb_adapter *adapter)
726 uint64_t tdba = adapter->tx_ring.dma;
727 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
729 struct ixgb_hw *hw = &adapter->hw;
731 /* Setup the Base and Length of the Tx Descriptor Ring
732 * tx_ring.dma can be either a 32 or 64 bit value
735 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
736 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
738 IXGB_WRITE_REG(hw, TDLEN, tdlen);
740 /* Setup the HW Tx Head and Tail descriptor pointers */
742 IXGB_WRITE_REG(hw, TDH, 0);
743 IXGB_WRITE_REG(hw, TDT, 0);
745 /* don't set up txdctl, it induces performance problems if configured
747 /* Set the Tx Interrupt Delay register */
749 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
751 /* Program the Transmit Control Register */
753 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
754 IXGB_WRITE_REG(hw, TCTL, tctl);
756 /* Setup Transmit Descriptor Settings for this adapter */
757 adapter->tx_cmd_type =
759 | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
763 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
764 * @adapter: board private structure
766 * Returns 0 on success, negative on failure
770 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
772 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
773 struct pci_dev *pdev = adapter->pdev;
776 size = sizeof(struct ixgb_buffer) * rxdr->count;
777 rxdr->buffer_info = vmalloc(size);
778 if(!rxdr->buffer_info) {
780 "Unable to allocate receive descriptor ring\n");
783 memset(rxdr->buffer_info, 0, size);
785 /* Round up to nearest 4K */
787 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
788 rxdr->size = ALIGN(rxdr->size, 4096);
790 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
793 vfree(rxdr->buffer_info);
795 "Unable to allocate receive descriptors\n");
798 memset(rxdr->desc, 0, rxdr->size);
800 rxdr->next_to_clean = 0;
801 rxdr->next_to_use = 0;
807 * ixgb_setup_rctl - configure the receive control register
808 * @adapter: Board private structure
812 ixgb_setup_rctl(struct ixgb_adapter *adapter)
816 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
818 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
821 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
822 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
823 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
825 rctl |= IXGB_RCTL_SECRC;
827 if (adapter->rx_buffer_len <= IXGB_RXBUFFER_2048)
828 rctl |= IXGB_RCTL_BSIZE_2048;
829 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_4096)
830 rctl |= IXGB_RCTL_BSIZE_4096;
831 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_8192)
832 rctl |= IXGB_RCTL_BSIZE_8192;
833 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_16384)
834 rctl |= IXGB_RCTL_BSIZE_16384;
836 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
840 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
841 * @adapter: board private structure
843 * Configure the Rx unit of the MAC after a reset.
847 ixgb_configure_rx(struct ixgb_adapter *adapter)
849 uint64_t rdba = adapter->rx_ring.dma;
850 uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
851 struct ixgb_hw *hw = &adapter->hw;
856 /* make sure receives are disabled while setting up the descriptors */
858 rctl = IXGB_READ_REG(hw, RCTL);
859 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
861 /* set the Receive Delay Timer Register */
863 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
865 /* Setup the Base and Length of the Rx Descriptor Ring */
867 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
868 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
870 IXGB_WRITE_REG(hw, RDLEN, rdlen);
872 /* Setup the HW Rx Head and Tail Descriptor Pointers */
873 IXGB_WRITE_REG(hw, RDH, 0);
874 IXGB_WRITE_REG(hw, RDT, 0);
876 /* set up pre-fetching of receive buffers so we get some before we
877 * run out (default hardware behavior is to run out before fetching
878 * more). This sets up to fetch if HTHRESH rx descriptors are avail
879 * and the descriptors in hw cache are below PTHRESH. This avoids
880 * the hardware behavior of fetching <=512 descriptors in a single
881 * burst that pre-empts all other activity, usually causing fifo
883 /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */
884 rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |
885 RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |
886 RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
887 IXGB_WRITE_REG(hw, RXDCTL, rxdctl);
889 /* Enable Receive Checksum Offload for TCP and UDP */
890 if (adapter->rx_csum) {
891 rxcsum = IXGB_READ_REG(hw, RXCSUM);
892 rxcsum |= IXGB_RXCSUM_TUOFL;
893 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
896 /* Enable Receives */
898 IXGB_WRITE_REG(hw, RCTL, rctl);
902 * ixgb_free_tx_resources - Free Tx Resources
903 * @adapter: board private structure
905 * Free all transmit software resources
909 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
911 struct pci_dev *pdev = adapter->pdev;
913 ixgb_clean_tx_ring(adapter);
915 vfree(adapter->tx_ring.buffer_info);
916 adapter->tx_ring.buffer_info = NULL;
918 pci_free_consistent(pdev, adapter->tx_ring.size,
919 adapter->tx_ring.desc, adapter->tx_ring.dma);
921 adapter->tx_ring.desc = NULL;
925 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
926 struct ixgb_buffer *buffer_info)
928 struct pci_dev *pdev = adapter->pdev;
930 if (buffer_info->dma)
931 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
934 if (buffer_info->skb)
935 dev_kfree_skb_any(buffer_info->skb);
937 buffer_info->skb = NULL;
938 buffer_info->dma = 0;
939 buffer_info->time_stamp = 0;
940 /* these fields must always be initialized in tx
941 * buffer_info->length = 0;
942 * buffer_info->next_to_watch = 0; */
946 * ixgb_clean_tx_ring - Free Tx Buffers
947 * @adapter: board private structure
951 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
953 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
954 struct ixgb_buffer *buffer_info;
958 /* Free all the Tx ring sk_buffs */
960 for(i = 0; i < tx_ring->count; i++) {
961 buffer_info = &tx_ring->buffer_info[i];
962 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
965 size = sizeof(struct ixgb_buffer) * tx_ring->count;
966 memset(tx_ring->buffer_info, 0, size);
968 /* Zero out the descriptor ring */
970 memset(tx_ring->desc, 0, tx_ring->size);
972 tx_ring->next_to_use = 0;
973 tx_ring->next_to_clean = 0;
975 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
976 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
980 * ixgb_free_rx_resources - Free Rx Resources
981 * @adapter: board private structure
983 * Free all receive software resources
987 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
989 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
990 struct pci_dev *pdev = adapter->pdev;
992 ixgb_clean_rx_ring(adapter);
994 vfree(rx_ring->buffer_info);
995 rx_ring->buffer_info = NULL;
997 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
999 rx_ring->desc = NULL;
1003 * ixgb_clean_rx_ring - Free Rx Buffers
1004 * @adapter: board private structure
1008 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
1010 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1011 struct ixgb_buffer *buffer_info;
1012 struct pci_dev *pdev = adapter->pdev;
1016 /* Free all the Rx ring sk_buffs */
1018 for(i = 0; i < rx_ring->count; i++) {
1019 buffer_info = &rx_ring->buffer_info[i];
1020 if(buffer_info->skb) {
1022 pci_unmap_single(pdev,
1024 buffer_info->length,
1025 PCI_DMA_FROMDEVICE);
1027 dev_kfree_skb(buffer_info->skb);
1029 buffer_info->skb = NULL;
1033 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1034 memset(rx_ring->buffer_info, 0, size);
1036 /* Zero out the descriptor ring */
1038 memset(rx_ring->desc, 0, rx_ring->size);
1040 rx_ring->next_to_clean = 0;
1041 rx_ring->next_to_use = 0;
1043 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1044 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1048 * ixgb_set_mac - Change the Ethernet Address of the NIC
1049 * @netdev: network interface device structure
1050 * @p: pointer to an address structure
1052 * Returns 0 on success, negative on failure
1056 ixgb_set_mac(struct net_device *netdev, void *p)
1058 struct ixgb_adapter *adapter = netdev_priv(netdev);
1059 struct sockaddr *addr = p;
1061 if(!is_valid_ether_addr(addr->sa_data))
1062 return -EADDRNOTAVAIL;
1064 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1066 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1072 * ixgb_set_multi - Multicast and Promiscuous mode set
1073 * @netdev: network interface device structure
1075 * The set_multi entry point is called whenever the multicast address
1076 * list or the network interface flags are updated. This routine is
1077 * responsible for configuring the hardware for proper multicast,
1078 * promiscuous mode, and all-multi behavior.
1082 ixgb_set_multi(struct net_device *netdev)
1084 struct ixgb_adapter *adapter = netdev_priv(netdev);
1085 struct ixgb_hw *hw = &adapter->hw;
1086 struct dev_mc_list *mc_ptr;
1090 /* Check for Promiscuous and All Multicast modes */
1092 rctl = IXGB_READ_REG(hw, RCTL);
1094 if(netdev->flags & IFF_PROMISC) {
1095 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1096 } else if(netdev->flags & IFF_ALLMULTI) {
1097 rctl |= IXGB_RCTL_MPE;
1098 rctl &= ~IXGB_RCTL_UPE;
1100 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1103 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1104 rctl |= IXGB_RCTL_MPE;
1105 IXGB_WRITE_REG(hw, RCTL, rctl);
1107 uint8_t mta[IXGB_MAX_NUM_MULTICAST_ADDRESSES *
1108 IXGB_ETH_LENGTH_OF_ADDRESS];
1110 IXGB_WRITE_REG(hw, RCTL, rctl);
1112 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1113 i++, mc_ptr = mc_ptr->next)
1114 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1115 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1117 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1122 * ixgb_watchdog - Timer Call-back
1123 * @data: pointer to netdev cast into an unsigned long
1127 ixgb_watchdog(unsigned long data)
1129 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1130 struct net_device *netdev = adapter->netdev;
1131 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1133 ixgb_check_for_link(&adapter->hw);
1135 if (ixgb_check_for_bad_link(&adapter->hw)) {
1136 /* force the reset path */
1137 netif_stop_queue(netdev);
1140 if(adapter->hw.link_up) {
1141 if(!netif_carrier_ok(netdev)) {
1143 "NIC Link is Up 10000 Mbps Full Duplex\n");
1144 adapter->link_speed = 10000;
1145 adapter->link_duplex = FULL_DUPLEX;
1146 netif_carrier_on(netdev);
1147 netif_wake_queue(netdev);
1150 if(netif_carrier_ok(netdev)) {
1151 adapter->link_speed = 0;
1152 adapter->link_duplex = 0;
1153 DPRINTK(LINK, INFO, "NIC Link is Down\n");
1154 netif_carrier_off(netdev);
1155 netif_stop_queue(netdev);
1160 ixgb_update_stats(adapter);
1162 if(!netif_carrier_ok(netdev)) {
1163 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1164 /* We've lost link, so the controller stops DMA,
1165 * but we've got queued Tx work that's never going
1166 * to get done, so reset controller to flush Tx.
1167 * (Do the reset outside of interrupt context). */
1168 schedule_work(&adapter->tx_timeout_task);
1172 /* Force detection of hung controller every watchdog period */
1173 adapter->detect_tx_hung = true;
1175 /* generate an interrupt to force clean up of any stragglers */
1176 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1178 /* Reset the timer */
1179 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1182 #define IXGB_TX_FLAGS_CSUM 0x00000001
1183 #define IXGB_TX_FLAGS_VLAN 0x00000002
1184 #define IXGB_TX_FLAGS_TSO 0x00000004
1187 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1189 struct ixgb_context_desc *context_desc;
1191 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1192 uint16_t ipcse, tucse, mss;
1195 if (likely(skb_is_gso(skb))) {
1196 struct ixgb_buffer *buffer_info;
1199 if (skb_header_cloned(skb)) {
1200 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1205 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1206 mss = skb_shinfo(skb)->gso_size;
1210 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
1213 ipcss = skb_network_offset(skb);
1214 ipcso = (void *)&(iph->check) - (void *)skb->data;
1215 ipcse = skb_transport_offset(skb) - 1;
1216 tucss = skb_transport_offset(skb);
1217 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
1220 i = adapter->tx_ring.next_to_use;
1221 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1222 buffer_info = &adapter->tx_ring.buffer_info[i];
1223 WARN_ON(buffer_info->dma != 0);
1225 context_desc->ipcss = ipcss;
1226 context_desc->ipcso = ipcso;
1227 context_desc->ipcse = cpu_to_le16(ipcse);
1228 context_desc->tucss = tucss;
1229 context_desc->tucso = tucso;
1230 context_desc->tucse = cpu_to_le16(tucse);
1231 context_desc->mss = cpu_to_le16(mss);
1232 context_desc->hdr_len = hdr_len;
1233 context_desc->status = 0;
1234 context_desc->cmd_type_len = cpu_to_le32(
1235 IXGB_CONTEXT_DESC_TYPE
1236 | IXGB_CONTEXT_DESC_CMD_TSE
1237 | IXGB_CONTEXT_DESC_CMD_IP
1238 | IXGB_CONTEXT_DESC_CMD_TCP
1239 | IXGB_CONTEXT_DESC_CMD_IDE
1240 | (skb->len - (hdr_len)));
1243 if(++i == adapter->tx_ring.count) i = 0;
1244 adapter->tx_ring.next_to_use = i;
1253 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1255 struct ixgb_context_desc *context_desc;
1259 if(likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
1260 struct ixgb_buffer *buffer_info;
1261 css = skb_transport_offset(skb);
1262 cso = css + skb->csum_offset;
1264 i = adapter->tx_ring.next_to_use;
1265 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1266 buffer_info = &adapter->tx_ring.buffer_info[i];
1267 WARN_ON(buffer_info->dma != 0);
1269 context_desc->tucss = css;
1270 context_desc->tucso = cso;
1271 context_desc->tucse = 0;
1272 /* zero out any previously existing data in one instruction */
1273 *(uint32_t *)&(context_desc->ipcss) = 0;
1274 context_desc->status = 0;
1275 context_desc->hdr_len = 0;
1276 context_desc->mss = 0;
1277 context_desc->cmd_type_len =
1278 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1279 | IXGB_TX_DESC_CMD_IDE);
1281 if(++i == adapter->tx_ring.count) i = 0;
1282 adapter->tx_ring.next_to_use = i;
1290 #define IXGB_MAX_TXD_PWR 14
1291 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1294 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1297 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1298 struct ixgb_buffer *buffer_info;
1300 unsigned int offset = 0, size, count = 0, i;
1301 unsigned int mss = skb_shinfo(skb)->gso_size;
1303 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1306 len -= skb->data_len;
1308 i = tx_ring->next_to_use;
1311 buffer_info = &tx_ring->buffer_info[i];
1312 size = min(len, IXGB_MAX_DATA_PER_TXD);
1313 /* Workaround for premature desc write-backs
1314 * in TSO mode. Append 4-byte sentinel desc */
1315 if (unlikely(mss && !nr_frags && size == len && size > 8))
1318 buffer_info->length = size;
1319 WARN_ON(buffer_info->dma != 0);
1321 pci_map_single(adapter->pdev,
1325 buffer_info->time_stamp = jiffies;
1326 buffer_info->next_to_watch = 0;
1331 if(++i == tx_ring->count) i = 0;
1334 for(f = 0; f < nr_frags; f++) {
1335 struct skb_frag_struct *frag;
1337 frag = &skb_shinfo(skb)->frags[f];
1342 buffer_info = &tx_ring->buffer_info[i];
1343 size = min(len, IXGB_MAX_DATA_PER_TXD);
1345 /* Workaround for premature desc write-backs
1346 * in TSO mode. Append 4-byte sentinel desc */
1347 if (unlikely(mss && (f == (nr_frags - 1))
1348 && size == len && size > 8))
1351 buffer_info->length = size;
1353 pci_map_page(adapter->pdev,
1355 frag->page_offset + offset,
1358 buffer_info->time_stamp = jiffies;
1359 buffer_info->next_to_watch = 0;
1364 if(++i == tx_ring->count) i = 0;
1367 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1368 tx_ring->buffer_info[i].skb = skb;
1369 tx_ring->buffer_info[first].next_to_watch = i;
1375 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1377 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1378 struct ixgb_tx_desc *tx_desc = NULL;
1379 struct ixgb_buffer *buffer_info;
1380 uint32_t cmd_type_len = adapter->tx_cmd_type;
1385 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1386 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1387 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1390 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1391 popts |= IXGB_TX_DESC_POPTS_TXSM;
1393 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1394 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1397 i = tx_ring->next_to_use;
1400 buffer_info = &tx_ring->buffer_info[i];
1401 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1402 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1403 tx_desc->cmd_type_len =
1404 cpu_to_le32(cmd_type_len | buffer_info->length);
1405 tx_desc->status = status;
1406 tx_desc->popts = popts;
1407 tx_desc->vlan = cpu_to_le16(vlan_id);
1409 if(++i == tx_ring->count) i = 0;
1412 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1413 | IXGB_TX_DESC_CMD_RS );
1415 /* Force memory writes to complete before letting h/w
1416 * know there are new descriptors to fetch. (Only
1417 * applicable for weak-ordered memory model archs,
1418 * such as IA-64). */
1421 tx_ring->next_to_use = i;
1422 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1425 static int __ixgb_maybe_stop_tx(struct net_device *netdev, int size)
1427 struct ixgb_adapter *adapter = netdev_priv(netdev);
1428 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1430 netif_stop_queue(netdev);
1431 /* Herbert's original patch had:
1432 * smp_mb__after_netif_stop_queue();
1433 * but since that doesn't exist yet, just open code it. */
1436 /* We need to check again in a case another CPU has just
1437 * made room available. */
1438 if (likely(IXGB_DESC_UNUSED(tx_ring) < size))
1442 netif_start_queue(netdev);
1443 ++adapter->restart_queue;
1447 static int ixgb_maybe_stop_tx(struct net_device *netdev,
1448 struct ixgb_desc_ring *tx_ring, int size)
1450 if (likely(IXGB_DESC_UNUSED(tx_ring) >= size))
1452 return __ixgb_maybe_stop_tx(netdev, size);
1456 /* Tx Descriptors needed, worst case */
1457 #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1458 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1459 #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) /* skb->date */ + \
1460 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 /* for context */ \
1461 + 1 /* one more needed for sentinel TSO workaround */
1464 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1466 struct ixgb_adapter *adapter = netdev_priv(netdev);
1468 unsigned int tx_flags = 0;
1469 unsigned long flags;
1473 if (test_bit(__IXGB_DOWN, &adapter->flags)) {
1475 return NETDEV_TX_OK;
1479 dev_kfree_skb_any(skb);
1484 if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
1485 /* Collision - tell upper layer to requeue */
1486 local_irq_restore(flags);
1487 return NETDEV_TX_LOCKED;
1490 spin_lock_irqsave(&adapter->tx_lock, flags);
1493 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
1495 netif_stop_queue(netdev);
1496 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1497 return NETDEV_TX_BUSY;
1500 #ifndef NETIF_F_LLTX
1501 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1504 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1505 tx_flags |= IXGB_TX_FLAGS_VLAN;
1506 vlan_id = vlan_tx_tag_get(skb);
1509 first = adapter->tx_ring.next_to_use;
1511 tso = ixgb_tso(adapter, skb);
1513 dev_kfree_skb_any(skb);
1515 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1517 return NETDEV_TX_OK;
1521 tx_flags |= IXGB_TX_FLAGS_TSO;
1522 else if(ixgb_tx_csum(adapter, skb))
1523 tx_flags |= IXGB_TX_FLAGS_CSUM;
1525 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1528 netdev->trans_start = jiffies;
1531 /* Make sure there is space in the ring for the next send. */
1532 ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, DESC_NEEDED);
1534 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1537 return NETDEV_TX_OK;
1541 * ixgb_tx_timeout - Respond to a Tx Hang
1542 * @netdev: network interface device structure
1546 ixgb_tx_timeout(struct net_device *netdev)
1548 struct ixgb_adapter *adapter = netdev_priv(netdev);
1550 /* Do the reset outside of interrupt context */
1551 schedule_work(&adapter->tx_timeout_task);
1555 ixgb_tx_timeout_task(struct work_struct *work)
1557 struct ixgb_adapter *adapter =
1558 container_of(work, struct ixgb_adapter, tx_timeout_task);
1560 adapter->tx_timeout_count++;
1561 ixgb_down(adapter, true);
1566 * ixgb_get_stats - Get System Network Statistics
1567 * @netdev: network interface device structure
1569 * Returns the address of the device statistics structure.
1570 * The statistics are actually updated from the timer callback.
1573 static struct net_device_stats *
1574 ixgb_get_stats(struct net_device *netdev)
1576 struct ixgb_adapter *adapter = netdev_priv(netdev);
1578 return &adapter->net_stats;
1582 * ixgb_change_mtu - Change the Maximum Transfer Unit
1583 * @netdev: network interface device structure
1584 * @new_mtu: new value for maximum frame size
1586 * Returns 0 on success, negative on failure
1590 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1592 struct ixgb_adapter *adapter = netdev_priv(netdev);
1593 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1594 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1597 if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1598 || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
1599 DPRINTK(PROBE, ERR, "Invalid MTU setting %d\n", new_mtu);
1603 adapter->rx_buffer_len = max_frame;
1605 netdev->mtu = new_mtu;
1607 if ((old_max_frame != max_frame) && netif_running(netdev)) {
1608 ixgb_down(adapter, true);
1616 * ixgb_update_stats - Update the board statistics counters.
1617 * @adapter: board private structure
1621 ixgb_update_stats(struct ixgb_adapter *adapter)
1623 struct net_device *netdev = adapter->netdev;
1624 struct pci_dev *pdev = adapter->pdev;
1626 /* Prevent stats update while adapter is being reset */
1627 if (pci_channel_offline(pdev))
1630 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1631 (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1632 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1633 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1634 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1635 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1637 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1638 /* fix up multicast stats by removing broadcasts */
1642 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1643 adapter->stats.mprch += (multi >> 32);
1644 adapter->stats.bprcl += bcast_l;
1645 adapter->stats.bprch += bcast_h;
1647 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1648 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1649 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1650 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1652 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1653 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1654 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1655 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1656 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1657 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1658 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1659 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1660 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1661 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1662 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1663 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1664 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1665 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1666 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1667 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1668 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1669 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1670 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1671 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1672 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1673 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1674 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1675 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1676 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1677 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1678 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1679 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1680 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1681 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1682 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1683 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1684 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1685 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1686 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1687 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1688 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1689 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1690 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1691 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1692 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1693 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1694 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1695 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1696 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1697 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1698 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1699 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1700 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1701 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1702 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1703 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1704 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1705 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1706 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1707 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1709 /* Fill out the OS statistics structure */
1711 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1712 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1713 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1714 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1715 adapter->net_stats.multicast = adapter->stats.mprcl;
1716 adapter->net_stats.collisions = 0;
1718 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1719 * with a length in the type/len field */
1720 adapter->net_stats.rx_errors =
1721 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1722 adapter->stats.ruc +
1723 adapter->stats.roc /*+ adapter->stats.rlec */ +
1724 adapter->stats.icbc +
1725 adapter->stats.ecbc + adapter->stats.mpc;
1728 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1731 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1732 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1733 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1734 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1736 adapter->net_stats.tx_errors = 0;
1737 adapter->net_stats.rx_frame_errors = 0;
1738 adapter->net_stats.tx_aborted_errors = 0;
1739 adapter->net_stats.tx_carrier_errors = 0;
1740 adapter->net_stats.tx_fifo_errors = 0;
1741 adapter->net_stats.tx_heartbeat_errors = 0;
1742 adapter->net_stats.tx_window_errors = 0;
1745 #define IXGB_MAX_INTR 10
1747 * ixgb_intr - Interrupt Handler
1748 * @irq: interrupt number
1749 * @data: pointer to a network interface device structure
1753 ixgb_intr(int irq, void *data)
1755 struct net_device *netdev = data;
1756 struct ixgb_adapter *adapter = netdev_priv(netdev);
1757 struct ixgb_hw *hw = &adapter->hw;
1758 uint32_t icr = IXGB_READ_REG(hw, ICR);
1759 #ifndef CONFIG_IXGB_NAPI
1764 return IRQ_NONE; /* Not our interrupt */
1766 if (unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)))
1767 if (!test_bit(__IXGB_DOWN, &adapter->flags))
1768 mod_timer(&adapter->watchdog_timer, jiffies);
1770 #ifdef CONFIG_IXGB_NAPI
1771 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1773 /* Disable interrupts and register for poll. The flush
1774 of the posted write is intentionally left out.
1777 atomic_inc(&adapter->irq_sem);
1778 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1779 __netif_rx_schedule(netdev, &adapter->napi);
1782 /* yes, that is actually a & and it is meant to make sure that
1783 * every pass through this for loop checks both receive and
1784 * transmit queues for completed descriptors, intended to
1785 * avoid starvation issues and assist tx/rx fairness. */
1786 for(i = 0; i < IXGB_MAX_INTR; i++)
1787 if(!ixgb_clean_rx_irq(adapter) &
1788 !ixgb_clean_tx_irq(adapter))
1794 #ifdef CONFIG_IXGB_NAPI
1796 * ixgb_clean - NAPI Rx polling callback
1797 * @adapter: board private structure
1801 ixgb_clean(struct napi_struct *napi, int budget)
1803 struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi);
1804 struct net_device *netdev = adapter->netdev;
1807 ixgb_clean_tx_irq(adapter);
1808 ixgb_clean_rx_irq(adapter, &work_done, budget);
1810 /* If budget not fully consumed, exit the polling mode */
1811 if (work_done < budget) {
1812 netif_rx_complete(netdev, napi);
1813 ixgb_irq_enable(adapter);
1821 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1822 * @adapter: board private structure
1826 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1828 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1829 struct net_device *netdev = adapter->netdev;
1830 struct ixgb_tx_desc *tx_desc, *eop_desc;
1831 struct ixgb_buffer *buffer_info;
1832 unsigned int i, eop;
1833 bool cleaned = false;
1835 i = tx_ring->next_to_clean;
1836 eop = tx_ring->buffer_info[i].next_to_watch;
1837 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1839 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1841 for (cleaned = false; !cleaned; ) {
1842 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1843 buffer_info = &tx_ring->buffer_info[i];
1846 & (IXGB_TX_DESC_POPTS_TXSM |
1847 IXGB_TX_DESC_POPTS_IXSM))
1848 adapter->hw_csum_tx_good++;
1850 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1852 *(uint32_t *)&(tx_desc->status) = 0;
1854 cleaned = (i == eop);
1855 if(++i == tx_ring->count) i = 0;
1858 eop = tx_ring->buffer_info[i].next_to_watch;
1859 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1862 tx_ring->next_to_clean = i;
1864 if (unlikely(netif_queue_stopped(netdev))) {
1865 spin_lock(&adapter->tx_lock);
1866 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1867 (IXGB_DESC_UNUSED(tx_ring) >= DESC_NEEDED))
1868 netif_wake_queue(netdev);
1869 spin_unlock(&adapter->tx_lock);
1872 if(adapter->detect_tx_hung) {
1873 /* detect a transmit hang in hardware, this serializes the
1874 * check with the clearing of time_stamp and movement of i */
1875 adapter->detect_tx_hung = false;
1876 if (tx_ring->buffer_info[eop].dma &&
1877 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + HZ)
1878 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1879 IXGB_STATUS_TXOFF)) {
1880 /* detected Tx unit hang */
1881 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
1884 " next_to_use <%x>\n"
1885 " next_to_clean <%x>\n"
1886 "buffer_info[next_to_clean]\n"
1887 " time_stamp <%lx>\n"
1888 " next_to_watch <%x>\n"
1890 " next_to_watch.status <%x>\n",
1891 IXGB_READ_REG(&adapter->hw, TDH),
1892 IXGB_READ_REG(&adapter->hw, TDT),
1893 tx_ring->next_to_use,
1894 tx_ring->next_to_clean,
1895 tx_ring->buffer_info[eop].time_stamp,
1899 netif_stop_queue(netdev);
1907 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1908 * @adapter: board private structure
1909 * @rx_desc: receive descriptor
1910 * @sk_buff: socket buffer with received data
1914 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1915 struct ixgb_rx_desc *rx_desc,
1916 struct sk_buff *skb)
1918 /* Ignore Checksum bit is set OR
1919 * TCP Checksum has not been calculated
1921 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1922 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1923 skb->ip_summed = CHECKSUM_NONE;
1927 /* At this point we know the hardware did the TCP checksum */
1928 /* now look at the TCP checksum error bit */
1929 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1930 /* let the stack verify checksum errors */
1931 skb->ip_summed = CHECKSUM_NONE;
1932 adapter->hw_csum_rx_error++;
1934 /* TCP checksum is good */
1935 skb->ip_summed = CHECKSUM_UNNECESSARY;
1936 adapter->hw_csum_rx_good++;
1941 * ixgb_clean_rx_irq - Send received data up the network stack,
1942 * @adapter: board private structure
1946 #ifdef CONFIG_IXGB_NAPI
1947 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1949 ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1952 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1953 struct net_device *netdev = adapter->netdev;
1954 struct pci_dev *pdev = adapter->pdev;
1955 struct ixgb_rx_desc *rx_desc, *next_rxd;
1956 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1959 bool cleaned = false;
1961 i = rx_ring->next_to_clean;
1962 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1963 buffer_info = &rx_ring->buffer_info[i];
1965 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1966 struct sk_buff *skb, *next_skb;
1969 #ifdef CONFIG_IXGB_NAPI
1970 if(*work_done >= work_to_do)
1975 status = rx_desc->status;
1976 skb = buffer_info->skb;
1977 buffer_info->skb = NULL;
1979 prefetch(skb->data);
1981 if(++i == rx_ring->count) i = 0;
1982 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1985 if((j = i + 1) == rx_ring->count) j = 0;
1986 next2_buffer = &rx_ring->buffer_info[j];
1987 prefetch(next2_buffer);
1989 next_buffer = &rx_ring->buffer_info[i];
1990 next_skb = next_buffer->skb;
1995 pci_unmap_single(pdev,
1997 buffer_info->length,
1998 PCI_DMA_FROMDEVICE);
2000 length = le16_to_cpu(rx_desc->length);
2002 if(unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
2004 /* All receives must fit into a single buffer */
2006 IXGB_DBG("Receive packet consumed multiple buffers "
2007 "length<%x>\n", length);
2009 dev_kfree_skb_irq(skb);
2013 if (unlikely(rx_desc->errors
2014 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
2015 | IXGB_RX_DESC_ERRORS_P |
2016 IXGB_RX_DESC_ERRORS_RXE))) {
2018 dev_kfree_skb_irq(skb);
2022 /* code added for copybreak, this should improve
2023 * performance for small packets with large amounts
2024 * of reassembly being done in the stack */
2025 #define IXGB_CB_LENGTH 256
2026 if (length < IXGB_CB_LENGTH) {
2027 struct sk_buff *new_skb =
2028 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
2030 skb_reserve(new_skb, NET_IP_ALIGN);
2031 skb_copy_to_linear_data_offset(new_skb,
2037 /* save the skb in buffer_info as good */
2038 buffer_info->skb = skb;
2042 /* end copybreak code */
2045 skb_put(skb, length);
2047 /* Receive Checksum Offload */
2048 ixgb_rx_checksum(adapter, rx_desc, skb);
2050 skb->protocol = eth_type_trans(skb, netdev);
2051 #ifdef CONFIG_IXGB_NAPI
2052 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
2053 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
2054 le16_to_cpu(rx_desc->special) &
2055 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
2057 netif_receive_skb(skb);
2059 #else /* CONFIG_IXGB_NAPI */
2060 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
2061 vlan_hwaccel_rx(skb, adapter->vlgrp,
2062 le16_to_cpu(rx_desc->special) &
2063 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
2067 #endif /* CONFIG_IXGB_NAPI */
2068 netdev->last_rx = jiffies;
2071 /* clean up descriptor, might be written over by hw */
2072 rx_desc->status = 0;
2074 /* use prefetched values */
2076 buffer_info = next_buffer;
2079 rx_ring->next_to_clean = i;
2081 ixgb_alloc_rx_buffers(adapter);
2087 * ixgb_alloc_rx_buffers - Replace used receive buffers
2088 * @adapter: address of board private structure
2092 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
2094 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
2095 struct net_device *netdev = adapter->netdev;
2096 struct pci_dev *pdev = adapter->pdev;
2097 struct ixgb_rx_desc *rx_desc;
2098 struct ixgb_buffer *buffer_info;
2099 struct sk_buff *skb;
2101 int num_group_tail_writes;
2104 i = rx_ring->next_to_use;
2105 buffer_info = &rx_ring->buffer_info[i];
2106 cleancount = IXGB_DESC_UNUSED(rx_ring);
2108 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
2110 /* leave three descriptors unused */
2111 while(--cleancount > 2) {
2112 /* recycle! its good for you */
2113 skb = buffer_info->skb;
2119 skb = netdev_alloc_skb(netdev, adapter->rx_buffer_len
2121 if (unlikely(!skb)) {
2122 /* Better luck next round */
2123 adapter->alloc_rx_buff_failed++;
2127 /* Make buffer alignment 2 beyond a 16 byte boundary
2128 * this will result in a 16 byte aligned IP header after
2129 * the 14 byte MAC header is removed
2131 skb_reserve(skb, NET_IP_ALIGN);
2133 buffer_info->skb = skb;
2134 buffer_info->length = adapter->rx_buffer_len;
2136 buffer_info->dma = pci_map_single(pdev,
2138 adapter->rx_buffer_len,
2139 PCI_DMA_FROMDEVICE);
2141 rx_desc = IXGB_RX_DESC(*rx_ring, i);
2142 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
2143 /* guarantee DD bit not set now before h/w gets descriptor
2144 * this is the rest of the workaround for h/w double
2146 rx_desc->status = 0;
2149 if(++i == rx_ring->count) i = 0;
2150 buffer_info = &rx_ring->buffer_info[i];
2153 if (likely(rx_ring->next_to_use != i)) {
2154 rx_ring->next_to_use = i;
2155 if (unlikely(i-- == 0))
2156 i = (rx_ring->count - 1);
2158 /* Force memory writes to complete before letting h/w
2159 * know there are new descriptors to fetch. (Only
2160 * applicable for weak-ordered memory model archs, such
2163 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2168 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2170 * @param netdev network interface device structure
2171 * @param grp indicates to enable or disable tagging/stripping
2174 ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2176 struct ixgb_adapter *adapter = netdev_priv(netdev);
2177 uint32_t ctrl, rctl;
2179 ixgb_irq_disable(adapter);
2180 adapter->vlgrp = grp;
2183 /* enable VLAN tag insert/strip */
2184 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2185 ctrl |= IXGB_CTRL0_VME;
2186 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2188 /* enable VLAN receive filtering */
2190 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2191 rctl |= IXGB_RCTL_VFE;
2192 rctl &= ~IXGB_RCTL_CFIEN;
2193 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2195 /* disable VLAN tag insert/strip */
2197 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2198 ctrl &= ~IXGB_CTRL0_VME;
2199 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2201 /* disable VLAN filtering */
2203 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2204 rctl &= ~IXGB_RCTL_VFE;
2205 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2208 /* don't enable interrupts unless we are UP */
2209 if (adapter->netdev->flags & IFF_UP)
2210 ixgb_irq_enable(adapter);
2214 ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
2216 struct ixgb_adapter *adapter = netdev_priv(netdev);
2217 uint32_t vfta, index;
2219 /* add VID to filter table */
2221 index = (vid >> 5) & 0x7F;
2222 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2223 vfta |= (1 << (vid & 0x1F));
2224 ixgb_write_vfta(&adapter->hw, index, vfta);
2228 ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2230 struct ixgb_adapter *adapter = netdev_priv(netdev);
2231 uint32_t vfta, index;
2233 ixgb_irq_disable(adapter);
2235 vlan_group_set_device(adapter->vlgrp, vid, NULL);
2237 /* don't enable interrupts unless we are UP */
2238 if (adapter->netdev->flags & IFF_UP)
2239 ixgb_irq_enable(adapter);
2241 /* remove VID from filter table */
2243 index = (vid >> 5) & 0x7F;
2244 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2245 vfta &= ~(1 << (vid & 0x1F));
2246 ixgb_write_vfta(&adapter->hw, index, vfta);
2250 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2252 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2254 if(adapter->vlgrp) {
2256 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2257 if(!vlan_group_get_device(adapter->vlgrp, vid))
2259 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2264 #ifdef CONFIG_NET_POLL_CONTROLLER
2266 * Polling 'interrupt' - used by things like netconsole to send skbs
2267 * without having to re-enable interrupts. It's not called while
2268 * the interrupt routine is executing.
2271 static void ixgb_netpoll(struct net_device *dev)
2273 struct ixgb_adapter *adapter = netdev_priv(dev);
2275 disable_irq(adapter->pdev->irq);
2276 ixgb_intr(adapter->pdev->irq, dev);
2277 enable_irq(adapter->pdev->irq);
2282 * ixgb_io_error_detected() - called when PCI error is detected
2283 * @pdev pointer to pci device with error
2284 * @state pci channel state after error
2286 * This callback is called by the PCI subsystem whenever
2287 * a PCI bus error is detected.
2289 static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
2290 enum pci_channel_state state)
2292 struct net_device *netdev = pci_get_drvdata(pdev);
2293 struct ixgb_adapter *adapter = netdev_priv(netdev);
2295 if(netif_running(netdev))
2296 ixgb_down(adapter, true);
2298 pci_disable_device(pdev);
2300 /* Request a slot reset. */
2301 return PCI_ERS_RESULT_NEED_RESET;
2305 * ixgb_io_slot_reset - called after the pci bus has been reset.
2306 * @pdev pointer to pci device with error
2308 * This callback is called after the PCI buss has been reset.
2309 * Basically, this tries to restart the card from scratch.
2310 * This is a shortened version of the device probe/discovery code,
2311 * it resembles the first-half of the ixgb_probe() routine.
2313 static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev)
2315 struct net_device *netdev = pci_get_drvdata(pdev);
2316 struct ixgb_adapter *adapter = netdev_priv(netdev);
2318 if(pci_enable_device(pdev)) {
2319 DPRINTK(PROBE, ERR, "Cannot re-enable PCI device after reset.\n");
2320 return PCI_ERS_RESULT_DISCONNECT;
2323 /* Perform card reset only on one instance of the card */
2324 if (0 != PCI_FUNC (pdev->devfn))
2325 return PCI_ERS_RESULT_RECOVERED;
2327 pci_set_master(pdev);
2329 netif_carrier_off(netdev);
2330 netif_stop_queue(netdev);
2331 ixgb_reset(adapter);
2333 /* Make sure the EEPROM is good */
2334 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
2335 DPRINTK(PROBE, ERR, "After reset, the EEPROM checksum is not valid.\n");
2336 return PCI_ERS_RESULT_DISCONNECT;
2338 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
2339 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
2341 if(!is_valid_ether_addr(netdev->perm_addr)) {
2342 DPRINTK(PROBE, ERR, "After reset, invalid MAC address.\n");
2343 return PCI_ERS_RESULT_DISCONNECT;
2346 return PCI_ERS_RESULT_RECOVERED;
2350 * ixgb_io_resume - called when its OK to resume normal operations
2351 * @pdev pointer to pci device with error
2353 * The error recovery driver tells us that its OK to resume
2354 * normal operation. Implementation resembles the second-half
2355 * of the ixgb_probe() routine.
2357 static void ixgb_io_resume (struct pci_dev *pdev)
2359 struct net_device *netdev = pci_get_drvdata(pdev);
2360 struct ixgb_adapter *adapter = netdev_priv(netdev);
2362 pci_set_master(pdev);
2364 if(netif_running(netdev)) {
2365 if(ixgb_up(adapter)) {
2366 printk ("ixgb: can't bring device back up after reset\n");
2371 netif_device_attach(netdev);
2372 mod_timer(&adapter->watchdog_timer, jiffies);