1 /*******************************************************************************
3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2008 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 *******************************************************************************/
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/prefetch.h>
34 char ixgb_driver_name[] = "ixgb";
35 static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
37 #define DRIVERNAPI "-NAPI"
38 #define DRV_VERSION "1.0.135-k2" DRIVERNAPI
39 const char ixgb_driver_version[] = DRV_VERSION;
40 static const char ixgb_copyright[] = "Copyright (c) 1999-2008 Intel Corporation.";
42 #define IXGB_CB_LENGTH 256
43 static unsigned int copybreak __read_mostly = IXGB_CB_LENGTH;
44 module_param(copybreak, uint, 0644);
45 MODULE_PARM_DESC(copybreak,
46 "Maximum size of packet that is copied to a new buffer on receive");
48 /* ixgb_pci_tbl - PCI Device ID Table
50 * Wildcard entries (PCI_ANY_ID) should come last
51 * Last entry must be all 0s
53 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
54 * Class, Class Mask, private data (not used) }
56 static const struct pci_device_id ixgb_pci_tbl[] = {
57 {PCI_VENDOR_ID_INTEL, IXGB_DEVICE_ID_82597EX,
58 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
59 {PCI_VENDOR_ID_INTEL, IXGB_DEVICE_ID_82597EX_CX4,
60 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
61 {PCI_VENDOR_ID_INTEL, IXGB_DEVICE_ID_82597EX_SR,
62 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
63 {PCI_VENDOR_ID_INTEL, IXGB_DEVICE_ID_82597EX_LR,
64 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
66 /* required last entry */
70 MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
72 /* Local Function Prototypes */
73 static int ixgb_init_module(void);
74 static void ixgb_exit_module(void);
75 static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
76 static void ixgb_remove(struct pci_dev *pdev);
77 static int ixgb_sw_init(struct ixgb_adapter *adapter);
78 static int ixgb_open(struct net_device *netdev);
79 static int ixgb_close(struct net_device *netdev);
80 static void ixgb_configure_tx(struct ixgb_adapter *adapter);
81 static void ixgb_configure_rx(struct ixgb_adapter *adapter);
82 static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
83 static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
84 static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
85 static void ixgb_set_multi(struct net_device *netdev);
86 static void ixgb_watchdog(unsigned long data);
87 static netdev_tx_t ixgb_xmit_frame(struct sk_buff *skb,
88 struct net_device *netdev);
89 static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
90 static int ixgb_set_mac(struct net_device *netdev, void *p);
91 static irqreturn_t ixgb_intr(int irq, void *data);
92 static bool ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
94 static int ixgb_clean(struct napi_struct *, int);
95 static bool ixgb_clean_rx_irq(struct ixgb_adapter *, int *, int);
96 static void ixgb_alloc_rx_buffers(struct ixgb_adapter *, int);
98 static void ixgb_tx_timeout(struct net_device *dev);
99 static void ixgb_tx_timeout_task(struct work_struct *work);
101 static void ixgb_vlan_strip_enable(struct ixgb_adapter *adapter);
102 static void ixgb_vlan_strip_disable(struct ixgb_adapter *adapter);
103 static int ixgb_vlan_rx_add_vid(struct net_device *netdev,
104 __be16 proto, u16 vid);
105 static int ixgb_vlan_rx_kill_vid(struct net_device *netdev,
106 __be16 proto, u16 vid);
107 static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
109 #ifdef CONFIG_NET_POLL_CONTROLLER
110 /* for netdump / net console */
111 static void ixgb_netpoll(struct net_device *dev);
114 static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
115 enum pci_channel_state state);
116 static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev);
117 static void ixgb_io_resume (struct pci_dev *pdev);
119 static const struct pci_error_handlers ixgb_err_handler = {
120 .error_detected = ixgb_io_error_detected,
121 .slot_reset = ixgb_io_slot_reset,
122 .resume = ixgb_io_resume,
125 static struct pci_driver ixgb_driver = {
126 .name = ixgb_driver_name,
127 .id_table = ixgb_pci_tbl,
129 .remove = ixgb_remove,
130 .err_handler = &ixgb_err_handler
133 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
134 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
135 MODULE_LICENSE("GPL");
136 MODULE_VERSION(DRV_VERSION);
138 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
139 static int debug = -1;
140 module_param(debug, int, 0);
141 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
144 * ixgb_init_module - Driver Registration Routine
146 * ixgb_init_module is the first routine called when the driver is
147 * loaded. All it does is register with the PCI subsystem.
151 ixgb_init_module(void)
153 pr_info("%s - version %s\n", ixgb_driver_string, ixgb_driver_version);
154 pr_info("%s\n", ixgb_copyright);
156 return pci_register_driver(&ixgb_driver);
159 module_init(ixgb_init_module);
162 * ixgb_exit_module - Driver Exit Cleanup Routine
164 * ixgb_exit_module is called just before the driver is removed
169 ixgb_exit_module(void)
171 pci_unregister_driver(&ixgb_driver);
174 module_exit(ixgb_exit_module);
177 * ixgb_irq_disable - Mask off interrupt generation on the NIC
178 * @adapter: board private structure
182 ixgb_irq_disable(struct ixgb_adapter *adapter)
184 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
185 IXGB_WRITE_FLUSH(&adapter->hw);
186 synchronize_irq(adapter->pdev->irq);
190 * ixgb_irq_enable - Enable default interrupt generation settings
191 * @adapter: board private structure
195 ixgb_irq_enable(struct ixgb_adapter *adapter)
197 u32 val = IXGB_INT_RXT0 | IXGB_INT_RXDMT0 |
198 IXGB_INT_TXDW | IXGB_INT_LSC;
199 if (adapter->hw.subsystem_vendor_id == PCI_VENDOR_ID_SUN)
200 val |= IXGB_INT_GPI0;
201 IXGB_WRITE_REG(&adapter->hw, IMS, val);
202 IXGB_WRITE_FLUSH(&adapter->hw);
206 ixgb_up(struct ixgb_adapter *adapter)
208 struct net_device *netdev = adapter->netdev;
209 int err, irq_flags = IRQF_SHARED;
210 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
211 struct ixgb_hw *hw = &adapter->hw;
213 /* hardware has been reset, we need to reload some things */
215 ixgb_rar_set(hw, netdev->dev_addr, 0);
216 ixgb_set_multi(netdev);
218 ixgb_restore_vlan(adapter);
220 ixgb_configure_tx(adapter);
221 ixgb_setup_rctl(adapter);
222 ixgb_configure_rx(adapter);
223 ixgb_alloc_rx_buffers(adapter, IXGB_DESC_UNUSED(&adapter->rx_ring));
225 /* disable interrupts and get the hardware into a known state */
226 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
228 /* only enable MSI if bus is in PCI-X mode */
229 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_PCIX_MODE) {
230 err = pci_enable_msi(adapter->pdev);
232 adapter->have_msi = true;
235 /* proceed to try to request regular interrupt */
238 err = request_irq(adapter->pdev->irq, ixgb_intr, irq_flags,
239 netdev->name, netdev);
241 if (adapter->have_msi)
242 pci_disable_msi(adapter->pdev);
243 netif_err(adapter, probe, adapter->netdev,
244 "Unable to allocate interrupt Error: %d\n", err);
248 if ((hw->max_frame_size != max_frame) ||
249 (hw->max_frame_size !=
250 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
252 hw->max_frame_size = max_frame;
254 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
256 if (hw->max_frame_size >
257 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
258 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
260 if (!(ctrl0 & IXGB_CTRL0_JFE)) {
261 ctrl0 |= IXGB_CTRL0_JFE;
262 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
267 clear_bit(__IXGB_DOWN, &adapter->flags);
269 napi_enable(&adapter->napi);
270 ixgb_irq_enable(adapter);
272 netif_wake_queue(netdev);
274 mod_timer(&adapter->watchdog_timer, jiffies);
280 ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog)
282 struct net_device *netdev = adapter->netdev;
284 /* prevent the interrupt handler from restarting watchdog */
285 set_bit(__IXGB_DOWN, &adapter->flags);
287 netif_carrier_off(netdev);
289 napi_disable(&adapter->napi);
290 /* waiting for NAPI to complete can re-enable interrupts */
291 ixgb_irq_disable(adapter);
292 free_irq(adapter->pdev->irq, netdev);
294 if (adapter->have_msi)
295 pci_disable_msi(adapter->pdev);
298 del_timer_sync(&adapter->watchdog_timer);
300 adapter->link_speed = 0;
301 adapter->link_duplex = 0;
302 netif_stop_queue(netdev);
305 ixgb_clean_tx_ring(adapter);
306 ixgb_clean_rx_ring(adapter);
310 ixgb_reset(struct ixgb_adapter *adapter)
312 struct ixgb_hw *hw = &adapter->hw;
314 ixgb_adapter_stop(hw);
315 if (!ixgb_init_hw(hw))
316 netif_err(adapter, probe, adapter->netdev, "ixgb_init_hw failed\n");
318 /* restore frame size information */
319 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
320 if (hw->max_frame_size >
321 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
322 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
323 if (!(ctrl0 & IXGB_CTRL0_JFE)) {
324 ctrl0 |= IXGB_CTRL0_JFE;
325 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
330 static netdev_features_t
331 ixgb_fix_features(struct net_device *netdev, netdev_features_t features)
334 * Tx VLAN insertion does not work per HW design when Rx stripping is
337 if (!(features & NETIF_F_HW_VLAN_CTAG_RX))
338 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
344 ixgb_set_features(struct net_device *netdev, netdev_features_t features)
346 struct ixgb_adapter *adapter = netdev_priv(netdev);
347 netdev_features_t changed = features ^ netdev->features;
349 if (!(changed & (NETIF_F_RXCSUM|NETIF_F_HW_VLAN_CTAG_RX)))
352 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
354 if (netif_running(netdev)) {
355 ixgb_down(adapter, true);
357 ixgb_set_speed_duplex(netdev);
365 static const struct net_device_ops ixgb_netdev_ops = {
366 .ndo_open = ixgb_open,
367 .ndo_stop = ixgb_close,
368 .ndo_start_xmit = ixgb_xmit_frame,
369 .ndo_set_rx_mode = ixgb_set_multi,
370 .ndo_validate_addr = eth_validate_addr,
371 .ndo_set_mac_address = ixgb_set_mac,
372 .ndo_change_mtu = ixgb_change_mtu,
373 .ndo_tx_timeout = ixgb_tx_timeout,
374 .ndo_vlan_rx_add_vid = ixgb_vlan_rx_add_vid,
375 .ndo_vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid,
376 #ifdef CONFIG_NET_POLL_CONTROLLER
377 .ndo_poll_controller = ixgb_netpoll,
379 .ndo_fix_features = ixgb_fix_features,
380 .ndo_set_features = ixgb_set_features,
384 * ixgb_probe - Device Initialization Routine
385 * @pdev: PCI device information struct
386 * @ent: entry in ixgb_pci_tbl
388 * Returns 0 on success, negative on failure
390 * ixgb_probe initializes an adapter identified by a pci_dev structure.
391 * The OS initialization, configuring of the adapter private structure,
392 * and a hardware reset occur.
396 ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
398 struct net_device *netdev = NULL;
399 struct ixgb_adapter *adapter;
400 static int cards_found = 0;
405 err = pci_enable_device(pdev);
410 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
414 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
416 pr_err("No usable DMA configuration, aborting\n");
421 err = pci_request_regions(pdev, ixgb_driver_name);
423 goto err_request_regions;
425 pci_set_master(pdev);
427 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
430 goto err_alloc_etherdev;
433 SET_NETDEV_DEV(netdev, &pdev->dev);
435 pci_set_drvdata(pdev, netdev);
436 adapter = netdev_priv(netdev);
437 adapter->netdev = netdev;
438 adapter->pdev = pdev;
439 adapter->hw.back = adapter;
440 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
442 adapter->hw.hw_addr = pci_ioremap_bar(pdev, BAR_0);
443 if (!adapter->hw.hw_addr) {
448 for (i = BAR_1; i <= BAR_5; i++) {
449 if (pci_resource_len(pdev, i) == 0)
451 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
452 adapter->hw.io_base = pci_resource_start(pdev, i);
457 netdev->netdev_ops = &ixgb_netdev_ops;
458 ixgb_set_ethtool_ops(netdev);
459 netdev->watchdog_timeo = 5 * HZ;
460 netif_napi_add(netdev, &adapter->napi, ixgb_clean, 64);
462 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
464 adapter->bd_number = cards_found;
465 adapter->link_speed = 0;
466 adapter->link_duplex = 0;
468 /* setup the private structure */
470 err = ixgb_sw_init(adapter);
474 netdev->hw_features = NETIF_F_SG |
477 NETIF_F_HW_VLAN_CTAG_TX |
478 NETIF_F_HW_VLAN_CTAG_RX;
479 netdev->features = netdev->hw_features |
480 NETIF_F_HW_VLAN_CTAG_FILTER;
481 netdev->hw_features |= NETIF_F_RXCSUM;
484 netdev->features |= NETIF_F_HIGHDMA;
485 netdev->vlan_features |= NETIF_F_HIGHDMA;
488 /* MTU range: 68 - 16114 */
489 netdev->min_mtu = ETH_MIN_MTU;
490 netdev->max_mtu = IXGB_MAX_JUMBO_FRAME_SIZE - ETH_HLEN;
492 /* make sure the EEPROM is good */
494 if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
495 netif_err(adapter, probe, adapter->netdev,
496 "The EEPROM Checksum Is Not Valid\n");
501 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
503 if (!is_valid_ether_addr(netdev->dev_addr)) {
504 netif_err(adapter, probe, adapter->netdev, "Invalid MAC Address\n");
509 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
511 init_timer(&adapter->watchdog_timer);
512 adapter->watchdog_timer.function = ixgb_watchdog;
513 adapter->watchdog_timer.data = (unsigned long)adapter;
515 INIT_WORK(&adapter->tx_timeout_task, ixgb_tx_timeout_task);
517 strcpy(netdev->name, "eth%d");
518 err = register_netdev(netdev);
522 /* carrier off reporting is important to ethtool even BEFORE open */
523 netif_carrier_off(netdev);
525 netif_info(adapter, probe, adapter->netdev,
526 "Intel(R) PRO/10GbE Network Connection\n");
527 ixgb_check_options(adapter);
528 /* reset the hardware with the new settings */
538 iounmap(adapter->hw.hw_addr);
542 pci_release_regions(pdev);
545 pci_disable_device(pdev);
550 * ixgb_remove - Device Removal Routine
551 * @pdev: PCI device information struct
553 * ixgb_remove is called by the PCI subsystem to alert the driver
554 * that it should release a PCI device. The could be caused by a
555 * Hot-Plug event, or because the driver is going to be removed from
560 ixgb_remove(struct pci_dev *pdev)
562 struct net_device *netdev = pci_get_drvdata(pdev);
563 struct ixgb_adapter *adapter = netdev_priv(netdev);
565 cancel_work_sync(&adapter->tx_timeout_task);
567 unregister_netdev(netdev);
569 iounmap(adapter->hw.hw_addr);
570 pci_release_regions(pdev);
573 pci_disable_device(pdev);
577 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
578 * @adapter: board private structure to initialize
580 * ixgb_sw_init initializes the Adapter private data structure.
581 * Fields are initialized based on PCI device information and
582 * OS network device settings (MTU size).
586 ixgb_sw_init(struct ixgb_adapter *adapter)
588 struct ixgb_hw *hw = &adapter->hw;
589 struct net_device *netdev = adapter->netdev;
590 struct pci_dev *pdev = adapter->pdev;
592 /* PCI config space info */
594 hw->vendor_id = pdev->vendor;
595 hw->device_id = pdev->device;
596 hw->subsystem_vendor_id = pdev->subsystem_vendor;
597 hw->subsystem_id = pdev->subsystem_device;
599 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
600 adapter->rx_buffer_len = hw->max_frame_size + 8; /* + 8 for errata */
602 if ((hw->device_id == IXGB_DEVICE_ID_82597EX) ||
603 (hw->device_id == IXGB_DEVICE_ID_82597EX_CX4) ||
604 (hw->device_id == IXGB_DEVICE_ID_82597EX_LR) ||
605 (hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
606 hw->mac_type = ixgb_82597;
608 /* should never have loaded on this device */
609 netif_err(adapter, probe, adapter->netdev, "unsupported device id\n");
612 /* enable flow control to be programmed */
615 set_bit(__IXGB_DOWN, &adapter->flags);
620 * ixgb_open - Called when a network interface is made active
621 * @netdev: network interface device structure
623 * Returns 0 on success, negative value on failure
625 * The open entry point is called when a network interface is made
626 * active by the system (IFF_UP). At this point all resources needed
627 * for transmit and receive operations are allocated, the interrupt
628 * handler is registered with the OS, the watchdog timer is started,
629 * and the stack is notified that the interface is ready.
633 ixgb_open(struct net_device *netdev)
635 struct ixgb_adapter *adapter = netdev_priv(netdev);
638 /* allocate transmit descriptors */
639 err = ixgb_setup_tx_resources(adapter);
643 netif_carrier_off(netdev);
645 /* allocate receive descriptors */
647 err = ixgb_setup_rx_resources(adapter);
651 err = ixgb_up(adapter);
655 netif_start_queue(netdev);
660 ixgb_free_rx_resources(adapter);
662 ixgb_free_tx_resources(adapter);
670 * ixgb_close - Disables a network interface
671 * @netdev: network interface device structure
673 * Returns 0, this is not allowed to fail
675 * The close entry point is called when an interface is de-activated
676 * by the OS. The hardware is still under the drivers control, but
677 * needs to be disabled. A global MAC reset is issued to stop the
678 * hardware, and all transmit and receive resources are freed.
682 ixgb_close(struct net_device *netdev)
684 struct ixgb_adapter *adapter = netdev_priv(netdev);
686 ixgb_down(adapter, true);
688 ixgb_free_tx_resources(adapter);
689 ixgb_free_rx_resources(adapter);
695 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
696 * @adapter: board private structure
698 * Return 0 on success, negative on failure
702 ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
704 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
705 struct pci_dev *pdev = adapter->pdev;
708 size = sizeof(struct ixgb_buffer) * txdr->count;
709 txdr->buffer_info = vzalloc(size);
710 if (!txdr->buffer_info)
713 /* round up to nearest 4K */
715 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
716 txdr->size = ALIGN(txdr->size, 4096);
718 txdr->desc = dma_zalloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
721 vfree(txdr->buffer_info);
725 txdr->next_to_use = 0;
726 txdr->next_to_clean = 0;
732 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
733 * @adapter: board private structure
735 * Configure the Tx unit of the MAC after a reset.
739 ixgb_configure_tx(struct ixgb_adapter *adapter)
741 u64 tdba = adapter->tx_ring.dma;
742 u32 tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
744 struct ixgb_hw *hw = &adapter->hw;
746 /* Setup the Base and Length of the Tx Descriptor Ring
747 * tx_ring.dma can be either a 32 or 64 bit value
750 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
751 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
753 IXGB_WRITE_REG(hw, TDLEN, tdlen);
755 /* Setup the HW Tx Head and Tail descriptor pointers */
757 IXGB_WRITE_REG(hw, TDH, 0);
758 IXGB_WRITE_REG(hw, TDT, 0);
760 /* don't set up txdctl, it induces performance problems if configured
762 /* Set the Tx Interrupt Delay register */
764 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
766 /* Program the Transmit Control Register */
768 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
769 IXGB_WRITE_REG(hw, TCTL, tctl);
771 /* Setup Transmit Descriptor Settings for this adapter */
772 adapter->tx_cmd_type =
774 (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
778 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
779 * @adapter: board private structure
781 * Returns 0 on success, negative on failure
785 ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
787 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
788 struct pci_dev *pdev = adapter->pdev;
791 size = sizeof(struct ixgb_buffer) * rxdr->count;
792 rxdr->buffer_info = vzalloc(size);
793 if (!rxdr->buffer_info)
796 /* Round up to nearest 4K */
798 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
799 rxdr->size = ALIGN(rxdr->size, 4096);
801 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
805 vfree(rxdr->buffer_info);
808 memset(rxdr->desc, 0, rxdr->size);
810 rxdr->next_to_clean = 0;
811 rxdr->next_to_use = 0;
817 * ixgb_setup_rctl - configure the receive control register
818 * @adapter: Board private structure
822 ixgb_setup_rctl(struct ixgb_adapter *adapter)
826 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
828 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
831 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
832 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
833 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
835 rctl |= IXGB_RCTL_SECRC;
837 if (adapter->rx_buffer_len <= IXGB_RXBUFFER_2048)
838 rctl |= IXGB_RCTL_BSIZE_2048;
839 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_4096)
840 rctl |= IXGB_RCTL_BSIZE_4096;
841 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_8192)
842 rctl |= IXGB_RCTL_BSIZE_8192;
843 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_16384)
844 rctl |= IXGB_RCTL_BSIZE_16384;
846 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
850 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
851 * @adapter: board private structure
853 * Configure the Rx unit of the MAC after a reset.
857 ixgb_configure_rx(struct ixgb_adapter *adapter)
859 u64 rdba = adapter->rx_ring.dma;
860 u32 rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
861 struct ixgb_hw *hw = &adapter->hw;
865 /* make sure receives are disabled while setting up the descriptors */
867 rctl = IXGB_READ_REG(hw, RCTL);
868 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
870 /* set the Receive Delay Timer Register */
872 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
874 /* Setup the Base and Length of the Rx Descriptor Ring */
876 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
877 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
879 IXGB_WRITE_REG(hw, RDLEN, rdlen);
881 /* Setup the HW Rx Head and Tail Descriptor Pointers */
882 IXGB_WRITE_REG(hw, RDH, 0);
883 IXGB_WRITE_REG(hw, RDT, 0);
885 /* due to the hardware errata with RXDCTL, we are unable to use any of
886 * the performance enhancing features of it without causing other
887 * subtle bugs, some of the bugs could include receive length
888 * corruption at high data rates (WTHRESH > 0) and/or receive
889 * descriptor ring irregularites (particularly in hardware cache) */
890 IXGB_WRITE_REG(hw, RXDCTL, 0);
892 /* Enable Receive Checksum Offload for TCP and UDP */
893 if (adapter->rx_csum) {
894 rxcsum = IXGB_READ_REG(hw, RXCSUM);
895 rxcsum |= IXGB_RXCSUM_TUOFL;
896 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
899 /* Enable Receives */
901 IXGB_WRITE_REG(hw, RCTL, rctl);
905 * ixgb_free_tx_resources - Free Tx Resources
906 * @adapter: board private structure
908 * Free all transmit software resources
912 ixgb_free_tx_resources(struct ixgb_adapter *adapter)
914 struct pci_dev *pdev = adapter->pdev;
916 ixgb_clean_tx_ring(adapter);
918 vfree(adapter->tx_ring.buffer_info);
919 adapter->tx_ring.buffer_info = NULL;
921 dma_free_coherent(&pdev->dev, adapter->tx_ring.size,
922 adapter->tx_ring.desc, adapter->tx_ring.dma);
924 adapter->tx_ring.desc = NULL;
928 ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
929 struct ixgb_buffer *buffer_info)
931 if (buffer_info->dma) {
932 if (buffer_info->mapped_as_page)
933 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
934 buffer_info->length, DMA_TO_DEVICE);
936 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
937 buffer_info->length, DMA_TO_DEVICE);
938 buffer_info->dma = 0;
941 if (buffer_info->skb) {
942 dev_kfree_skb_any(buffer_info->skb);
943 buffer_info->skb = NULL;
945 buffer_info->time_stamp = 0;
946 /* these fields must always be initialized in tx
947 * buffer_info->length = 0;
948 * buffer_info->next_to_watch = 0; */
952 * ixgb_clean_tx_ring - Free Tx Buffers
953 * @adapter: board private structure
957 ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
959 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
960 struct ixgb_buffer *buffer_info;
964 /* Free all the Tx ring sk_buffs */
966 for (i = 0; i < tx_ring->count; i++) {
967 buffer_info = &tx_ring->buffer_info[i];
968 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
971 size = sizeof(struct ixgb_buffer) * tx_ring->count;
972 memset(tx_ring->buffer_info, 0, size);
974 /* Zero out the descriptor ring */
976 memset(tx_ring->desc, 0, tx_ring->size);
978 tx_ring->next_to_use = 0;
979 tx_ring->next_to_clean = 0;
981 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
982 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
986 * ixgb_free_rx_resources - Free Rx Resources
987 * @adapter: board private structure
989 * Free all receive software resources
993 ixgb_free_rx_resources(struct ixgb_adapter *adapter)
995 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
996 struct pci_dev *pdev = adapter->pdev;
998 ixgb_clean_rx_ring(adapter);
1000 vfree(rx_ring->buffer_info);
1001 rx_ring->buffer_info = NULL;
1003 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1006 rx_ring->desc = NULL;
1010 * ixgb_clean_rx_ring - Free Rx Buffers
1011 * @adapter: board private structure
1015 ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
1017 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1018 struct ixgb_buffer *buffer_info;
1019 struct pci_dev *pdev = adapter->pdev;
1023 /* Free all the Rx ring sk_buffs */
1025 for (i = 0; i < rx_ring->count; i++) {
1026 buffer_info = &rx_ring->buffer_info[i];
1027 if (buffer_info->dma) {
1028 dma_unmap_single(&pdev->dev,
1030 buffer_info->length,
1032 buffer_info->dma = 0;
1033 buffer_info->length = 0;
1036 if (buffer_info->skb) {
1037 dev_kfree_skb(buffer_info->skb);
1038 buffer_info->skb = NULL;
1042 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1043 memset(rx_ring->buffer_info, 0, size);
1045 /* Zero out the descriptor ring */
1047 memset(rx_ring->desc, 0, rx_ring->size);
1049 rx_ring->next_to_clean = 0;
1050 rx_ring->next_to_use = 0;
1052 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1053 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1057 * ixgb_set_mac - Change the Ethernet Address of the NIC
1058 * @netdev: network interface device structure
1059 * @p: pointer to an address structure
1061 * Returns 0 on success, negative on failure
1065 ixgb_set_mac(struct net_device *netdev, void *p)
1067 struct ixgb_adapter *adapter = netdev_priv(netdev);
1068 struct sockaddr *addr = p;
1070 if (!is_valid_ether_addr(addr->sa_data))
1071 return -EADDRNOTAVAIL;
1073 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1075 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1081 * ixgb_set_multi - Multicast and Promiscuous mode set
1082 * @netdev: network interface device structure
1084 * The set_multi entry point is called whenever the multicast address
1085 * list or the network interface flags are updated. This routine is
1086 * responsible for configuring the hardware for proper multicast,
1087 * promiscuous mode, and all-multi behavior.
1091 ixgb_set_multi(struct net_device *netdev)
1093 struct ixgb_adapter *adapter = netdev_priv(netdev);
1094 struct ixgb_hw *hw = &adapter->hw;
1095 struct netdev_hw_addr *ha;
1098 /* Check for Promiscuous and All Multicast modes */
1100 rctl = IXGB_READ_REG(hw, RCTL);
1102 if (netdev->flags & IFF_PROMISC) {
1103 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1104 /* disable VLAN filtering */
1105 rctl &= ~IXGB_RCTL_CFIEN;
1106 rctl &= ~IXGB_RCTL_VFE;
1108 if (netdev->flags & IFF_ALLMULTI) {
1109 rctl |= IXGB_RCTL_MPE;
1110 rctl &= ~IXGB_RCTL_UPE;
1112 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1114 /* enable VLAN filtering */
1115 rctl |= IXGB_RCTL_VFE;
1116 rctl &= ~IXGB_RCTL_CFIEN;
1119 if (netdev_mc_count(netdev) > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1120 rctl |= IXGB_RCTL_MPE;
1121 IXGB_WRITE_REG(hw, RCTL, rctl);
1123 u8 *mta = kmalloc(IXGB_MAX_NUM_MULTICAST_ADDRESSES *
1124 ETH_ALEN, GFP_ATOMIC);
1129 IXGB_WRITE_REG(hw, RCTL, rctl);
1132 netdev_for_each_mc_addr(ha, netdev) {
1133 memcpy(addr, ha->addr, ETH_ALEN);
1137 ixgb_mc_addr_list_update(hw, mta, netdev_mc_count(netdev), 0);
1142 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
1143 ixgb_vlan_strip_enable(adapter);
1145 ixgb_vlan_strip_disable(adapter);
1150 * ixgb_watchdog - Timer Call-back
1151 * @data: pointer to netdev cast into an unsigned long
1155 ixgb_watchdog(unsigned long data)
1157 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1158 struct net_device *netdev = adapter->netdev;
1159 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1161 ixgb_check_for_link(&adapter->hw);
1163 if (ixgb_check_for_bad_link(&adapter->hw)) {
1164 /* force the reset path */
1165 netif_stop_queue(netdev);
1168 if (adapter->hw.link_up) {
1169 if (!netif_carrier_ok(netdev)) {
1171 "NIC Link is Up 10 Gbps Full Duplex, Flow Control: %s\n",
1172 (adapter->hw.fc.type == ixgb_fc_full) ?
1174 (adapter->hw.fc.type == ixgb_fc_rx_pause) ?
1176 (adapter->hw.fc.type == ixgb_fc_tx_pause) ?
1178 adapter->link_speed = 10000;
1179 adapter->link_duplex = FULL_DUPLEX;
1180 netif_carrier_on(netdev);
1183 if (netif_carrier_ok(netdev)) {
1184 adapter->link_speed = 0;
1185 adapter->link_duplex = 0;
1186 netdev_info(netdev, "NIC Link is Down\n");
1187 netif_carrier_off(netdev);
1191 ixgb_update_stats(adapter);
1193 if (!netif_carrier_ok(netdev)) {
1194 if (IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1195 /* We've lost link, so the controller stops DMA,
1196 * but we've got queued Tx work that's never going
1197 * to get done, so reset controller to flush Tx.
1198 * (Do the reset outside of interrupt context). */
1199 schedule_work(&adapter->tx_timeout_task);
1200 /* return immediately since reset is imminent */
1205 /* Force detection of hung controller every watchdog period */
1206 adapter->detect_tx_hung = true;
1208 /* generate an interrupt to force clean up of any stragglers */
1209 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1211 /* Reset the timer */
1212 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1215 #define IXGB_TX_FLAGS_CSUM 0x00000001
1216 #define IXGB_TX_FLAGS_VLAN 0x00000002
1217 #define IXGB_TX_FLAGS_TSO 0x00000004
1220 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1222 struct ixgb_context_desc *context_desc;
1224 u8 ipcss, ipcso, tucss, tucso, hdr_len;
1225 u16 ipcse, tucse, mss;
1227 if (likely(skb_is_gso(skb))) {
1228 struct ixgb_buffer *buffer_info;
1232 err = skb_cow_head(skb, 0);
1236 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1237 mss = skb_shinfo(skb)->gso_size;
1241 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
1244 ipcss = skb_network_offset(skb);
1245 ipcso = (void *)&(iph->check) - (void *)skb->data;
1246 ipcse = skb_transport_offset(skb) - 1;
1247 tucss = skb_transport_offset(skb);
1248 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
1251 i = adapter->tx_ring.next_to_use;
1252 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1253 buffer_info = &adapter->tx_ring.buffer_info[i];
1254 WARN_ON(buffer_info->dma != 0);
1256 context_desc->ipcss = ipcss;
1257 context_desc->ipcso = ipcso;
1258 context_desc->ipcse = cpu_to_le16(ipcse);
1259 context_desc->tucss = tucss;
1260 context_desc->tucso = tucso;
1261 context_desc->tucse = cpu_to_le16(tucse);
1262 context_desc->mss = cpu_to_le16(mss);
1263 context_desc->hdr_len = hdr_len;
1264 context_desc->status = 0;
1265 context_desc->cmd_type_len = cpu_to_le32(
1266 IXGB_CONTEXT_DESC_TYPE
1267 | IXGB_CONTEXT_DESC_CMD_TSE
1268 | IXGB_CONTEXT_DESC_CMD_IP
1269 | IXGB_CONTEXT_DESC_CMD_TCP
1270 | IXGB_CONTEXT_DESC_CMD_IDE
1271 | (skb->len - (hdr_len)));
1274 if (++i == adapter->tx_ring.count) i = 0;
1275 adapter->tx_ring.next_to_use = i;
1284 ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1286 struct ixgb_context_desc *context_desc;
1290 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
1291 struct ixgb_buffer *buffer_info;
1292 css = skb_checksum_start_offset(skb);
1293 cso = css + skb->csum_offset;
1295 i = adapter->tx_ring.next_to_use;
1296 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1297 buffer_info = &adapter->tx_ring.buffer_info[i];
1298 WARN_ON(buffer_info->dma != 0);
1300 context_desc->tucss = css;
1301 context_desc->tucso = cso;
1302 context_desc->tucse = 0;
1303 /* zero out any previously existing data in one instruction */
1304 *(u32 *)&(context_desc->ipcss) = 0;
1305 context_desc->status = 0;
1306 context_desc->hdr_len = 0;
1307 context_desc->mss = 0;
1308 context_desc->cmd_type_len =
1309 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1310 | IXGB_TX_DESC_CMD_IDE);
1312 if (++i == adapter->tx_ring.count) i = 0;
1313 adapter->tx_ring.next_to_use = i;
1321 #define IXGB_MAX_TXD_PWR 14
1322 #define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1325 ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1328 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1329 struct pci_dev *pdev = adapter->pdev;
1330 struct ixgb_buffer *buffer_info;
1331 int len = skb_headlen(skb);
1332 unsigned int offset = 0, size, count = 0, i;
1333 unsigned int mss = skb_shinfo(skb)->gso_size;
1334 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1337 i = tx_ring->next_to_use;
1340 buffer_info = &tx_ring->buffer_info[i];
1341 size = min(len, IXGB_MAX_DATA_PER_TXD);
1342 /* Workaround for premature desc write-backs
1343 * in TSO mode. Append 4-byte sentinel desc */
1344 if (unlikely(mss && !nr_frags && size == len && size > 8))
1347 buffer_info->length = size;
1348 WARN_ON(buffer_info->dma != 0);
1349 buffer_info->time_stamp = jiffies;
1350 buffer_info->mapped_as_page = false;
1351 buffer_info->dma = dma_map_single(&pdev->dev,
1353 size, DMA_TO_DEVICE);
1354 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
1356 buffer_info->next_to_watch = 0;
1363 if (i == tx_ring->count)
1368 for (f = 0; f < nr_frags; f++) {
1369 const struct skb_frag_struct *frag;
1371 frag = &skb_shinfo(skb)->frags[f];
1372 len = skb_frag_size(frag);
1377 if (i == tx_ring->count)
1380 buffer_info = &tx_ring->buffer_info[i];
1381 size = min(len, IXGB_MAX_DATA_PER_TXD);
1383 /* Workaround for premature desc write-backs
1384 * in TSO mode. Append 4-byte sentinel desc */
1385 if (unlikely(mss && (f == (nr_frags - 1))
1386 && size == len && size > 8))
1389 buffer_info->length = size;
1390 buffer_info->time_stamp = jiffies;
1391 buffer_info->mapped_as_page = true;
1393 skb_frag_dma_map(&pdev->dev, frag, offset, size,
1395 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
1397 buffer_info->next_to_watch = 0;
1404 tx_ring->buffer_info[i].skb = skb;
1405 tx_ring->buffer_info[first].next_to_watch = i;
1410 dev_err(&pdev->dev, "TX DMA map failed\n");
1411 buffer_info->dma = 0;
1417 i += tx_ring->count;
1419 buffer_info = &tx_ring->buffer_info[i];
1420 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1427 ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1429 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1430 struct ixgb_tx_desc *tx_desc = NULL;
1431 struct ixgb_buffer *buffer_info;
1432 u32 cmd_type_len = adapter->tx_cmd_type;
1437 if (tx_flags & IXGB_TX_FLAGS_TSO) {
1438 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1439 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1442 if (tx_flags & IXGB_TX_FLAGS_CSUM)
1443 popts |= IXGB_TX_DESC_POPTS_TXSM;
1445 if (tx_flags & IXGB_TX_FLAGS_VLAN)
1446 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1448 i = tx_ring->next_to_use;
1451 buffer_info = &tx_ring->buffer_info[i];
1452 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1453 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1454 tx_desc->cmd_type_len =
1455 cpu_to_le32(cmd_type_len | buffer_info->length);
1456 tx_desc->status = status;
1457 tx_desc->popts = popts;
1458 tx_desc->vlan = cpu_to_le16(vlan_id);
1460 if (++i == tx_ring->count) i = 0;
1463 tx_desc->cmd_type_len |=
1464 cpu_to_le32(IXGB_TX_DESC_CMD_EOP | IXGB_TX_DESC_CMD_RS);
1466 /* Force memory writes to complete before letting h/w
1467 * know there are new descriptors to fetch. (Only
1468 * applicable for weak-ordered memory model archs,
1469 * such as IA-64). */
1472 tx_ring->next_to_use = i;
1473 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1476 static int __ixgb_maybe_stop_tx(struct net_device *netdev, int size)
1478 struct ixgb_adapter *adapter = netdev_priv(netdev);
1479 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1481 netif_stop_queue(netdev);
1482 /* Herbert's original patch had:
1483 * smp_mb__after_netif_stop_queue();
1484 * but since that doesn't exist yet, just open code it. */
1487 /* We need to check again in a case another CPU has just
1488 * made room available. */
1489 if (likely(IXGB_DESC_UNUSED(tx_ring) < size))
1493 netif_start_queue(netdev);
1494 ++adapter->restart_queue;
1498 static int ixgb_maybe_stop_tx(struct net_device *netdev,
1499 struct ixgb_desc_ring *tx_ring, int size)
1501 if (likely(IXGB_DESC_UNUSED(tx_ring) >= size))
1503 return __ixgb_maybe_stop_tx(netdev, size);
1507 /* Tx Descriptors needed, worst case */
1508 #define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1509 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1510 #define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) /* skb->date */ + \
1511 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 /* for context */ \
1512 + 1 /* one more needed for sentinel TSO workaround */
1515 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1517 struct ixgb_adapter *adapter = netdev_priv(netdev);
1519 unsigned int tx_flags = 0;
1524 if (test_bit(__IXGB_DOWN, &adapter->flags)) {
1525 dev_kfree_skb_any(skb);
1526 return NETDEV_TX_OK;
1529 if (skb->len <= 0) {
1530 dev_kfree_skb_any(skb);
1531 return NETDEV_TX_OK;
1534 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
1536 return NETDEV_TX_BUSY;
1538 if (skb_vlan_tag_present(skb)) {
1539 tx_flags |= IXGB_TX_FLAGS_VLAN;
1540 vlan_id = skb_vlan_tag_get(skb);
1543 first = adapter->tx_ring.next_to_use;
1545 tso = ixgb_tso(adapter, skb);
1547 dev_kfree_skb_any(skb);
1548 return NETDEV_TX_OK;
1552 tx_flags |= IXGB_TX_FLAGS_TSO;
1553 else if (ixgb_tx_csum(adapter, skb))
1554 tx_flags |= IXGB_TX_FLAGS_CSUM;
1556 count = ixgb_tx_map(adapter, skb, first);
1559 ixgb_tx_queue(adapter, count, vlan_id, tx_flags);
1560 /* Make sure there is space in the ring for the next send. */
1561 ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, DESC_NEEDED);
1564 dev_kfree_skb_any(skb);
1565 adapter->tx_ring.buffer_info[first].time_stamp = 0;
1566 adapter->tx_ring.next_to_use = first;
1569 return NETDEV_TX_OK;
1573 * ixgb_tx_timeout - Respond to a Tx Hang
1574 * @netdev: network interface device structure
1578 ixgb_tx_timeout(struct net_device *netdev)
1580 struct ixgb_adapter *adapter = netdev_priv(netdev);
1582 /* Do the reset outside of interrupt context */
1583 schedule_work(&adapter->tx_timeout_task);
1587 ixgb_tx_timeout_task(struct work_struct *work)
1589 struct ixgb_adapter *adapter =
1590 container_of(work, struct ixgb_adapter, tx_timeout_task);
1592 adapter->tx_timeout_count++;
1593 ixgb_down(adapter, true);
1598 * ixgb_change_mtu - Change the Maximum Transfer Unit
1599 * @netdev: network interface device structure
1600 * @new_mtu: new value for maximum frame size
1602 * Returns 0 on success, negative on failure
1606 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1608 struct ixgb_adapter *adapter = netdev_priv(netdev);
1609 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1611 if (netif_running(netdev))
1612 ixgb_down(adapter, true);
1614 adapter->rx_buffer_len = max_frame + 8; /* + 8 for errata */
1616 netdev->mtu = new_mtu;
1618 if (netif_running(netdev))
1625 * ixgb_update_stats - Update the board statistics counters.
1626 * @adapter: board private structure
1630 ixgb_update_stats(struct ixgb_adapter *adapter)
1632 struct net_device *netdev = adapter->netdev;
1633 struct pci_dev *pdev = adapter->pdev;
1635 /* Prevent stats update while adapter is being reset */
1636 if (pci_channel_offline(pdev))
1639 if ((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1640 (netdev_mc_count(netdev) > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1641 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1642 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1643 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1644 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1646 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1647 /* fix up multicast stats by removing broadcasts */
1651 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1652 adapter->stats.mprch += (multi >> 32);
1653 adapter->stats.bprcl += bcast_l;
1654 adapter->stats.bprch += bcast_h;
1656 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1657 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1658 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1659 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1661 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1662 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1663 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1664 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1665 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1666 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1667 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1668 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1669 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1670 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1671 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1672 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1673 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1674 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1675 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1676 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1677 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1678 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1679 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1680 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1681 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1682 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1683 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1684 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1685 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1686 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1687 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1688 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1689 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1690 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1691 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1692 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1693 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1694 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1695 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1696 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1697 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1698 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1699 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1700 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1701 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1702 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1703 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1704 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1705 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1706 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1707 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1708 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1709 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1710 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1711 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1712 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1713 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1714 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1715 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1716 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1718 /* Fill out the OS statistics structure */
1720 netdev->stats.rx_packets = adapter->stats.gprcl;
1721 netdev->stats.tx_packets = adapter->stats.gptcl;
1722 netdev->stats.rx_bytes = adapter->stats.gorcl;
1723 netdev->stats.tx_bytes = adapter->stats.gotcl;
1724 netdev->stats.multicast = adapter->stats.mprcl;
1725 netdev->stats.collisions = 0;
1727 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1728 * with a length in the type/len field */
1729 netdev->stats.rx_errors =
1730 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1731 adapter->stats.ruc +
1732 adapter->stats.roc /*+ adapter->stats.rlec */ +
1733 adapter->stats.icbc +
1734 adapter->stats.ecbc + adapter->stats.mpc;
1737 * netdev->stats.rx_length_errors = adapter->stats.rlec;
1740 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
1741 netdev->stats.rx_fifo_errors = adapter->stats.mpc;
1742 netdev->stats.rx_missed_errors = adapter->stats.mpc;
1743 netdev->stats.rx_over_errors = adapter->stats.mpc;
1745 netdev->stats.tx_errors = 0;
1746 netdev->stats.rx_frame_errors = 0;
1747 netdev->stats.tx_aborted_errors = 0;
1748 netdev->stats.tx_carrier_errors = 0;
1749 netdev->stats.tx_fifo_errors = 0;
1750 netdev->stats.tx_heartbeat_errors = 0;
1751 netdev->stats.tx_window_errors = 0;
1754 #define IXGB_MAX_INTR 10
1756 * ixgb_intr - Interrupt Handler
1757 * @irq: interrupt number
1758 * @data: pointer to a network interface device structure
1762 ixgb_intr(int irq, void *data)
1764 struct net_device *netdev = data;
1765 struct ixgb_adapter *adapter = netdev_priv(netdev);
1766 struct ixgb_hw *hw = &adapter->hw;
1767 u32 icr = IXGB_READ_REG(hw, ICR);
1770 return IRQ_NONE; /* Not our interrupt */
1772 if (unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)))
1773 if (!test_bit(__IXGB_DOWN, &adapter->flags))
1774 mod_timer(&adapter->watchdog_timer, jiffies);
1776 if (napi_schedule_prep(&adapter->napi)) {
1778 /* Disable interrupts and register for poll. The flush
1779 of the posted write is intentionally left out.
1782 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1783 __napi_schedule(&adapter->napi);
1789 * ixgb_clean - NAPI Rx polling callback
1790 * @adapter: board private structure
1794 ixgb_clean(struct napi_struct *napi, int budget)
1796 struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi);
1799 ixgb_clean_tx_irq(adapter);
1800 ixgb_clean_rx_irq(adapter, &work_done, budget);
1802 /* If budget not fully consumed, exit the polling mode */
1803 if (work_done < budget) {
1804 napi_complete_done(napi, work_done);
1805 if (!test_bit(__IXGB_DOWN, &adapter->flags))
1806 ixgb_irq_enable(adapter);
1813 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1814 * @adapter: board private structure
1818 ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1820 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1821 struct net_device *netdev = adapter->netdev;
1822 struct ixgb_tx_desc *tx_desc, *eop_desc;
1823 struct ixgb_buffer *buffer_info;
1824 unsigned int i, eop;
1825 bool cleaned = false;
1827 i = tx_ring->next_to_clean;
1828 eop = tx_ring->buffer_info[i].next_to_watch;
1829 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1831 while (eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1833 rmb(); /* read buffer_info after eop_desc */
1834 for (cleaned = false; !cleaned; ) {
1835 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1836 buffer_info = &tx_ring->buffer_info[i];
1838 if (tx_desc->popts &
1839 (IXGB_TX_DESC_POPTS_TXSM |
1840 IXGB_TX_DESC_POPTS_IXSM))
1841 adapter->hw_csum_tx_good++;
1843 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1845 *(u32 *)&(tx_desc->status) = 0;
1847 cleaned = (i == eop);
1848 if (++i == tx_ring->count) i = 0;
1851 eop = tx_ring->buffer_info[i].next_to_watch;
1852 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1855 tx_ring->next_to_clean = i;
1857 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
1858 IXGB_DESC_UNUSED(tx_ring) >= DESC_NEEDED)) {
1859 /* Make sure that anybody stopping the queue after this
1860 * sees the new next_to_clean. */
1863 if (netif_queue_stopped(netdev) &&
1864 !(test_bit(__IXGB_DOWN, &adapter->flags))) {
1865 netif_wake_queue(netdev);
1866 ++adapter->restart_queue;
1870 if (adapter->detect_tx_hung) {
1871 /* detect a transmit hang in hardware, this serializes the
1872 * check with the clearing of time_stamp and movement of i */
1873 adapter->detect_tx_hung = false;
1874 if (tx_ring->buffer_info[eop].time_stamp &&
1875 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + HZ)
1876 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1877 IXGB_STATUS_TXOFF)) {
1878 /* detected Tx unit hang */
1879 netif_err(adapter, drv, adapter->netdev,
1880 "Detected Tx Unit Hang\n"
1883 " next_to_use <%x>\n"
1884 " next_to_clean <%x>\n"
1885 "buffer_info[next_to_clean]\n"
1886 " time_stamp <%lx>\n"
1887 " next_to_watch <%x>\n"
1889 " next_to_watch.status <%x>\n",
1890 IXGB_READ_REG(&adapter->hw, TDH),
1891 IXGB_READ_REG(&adapter->hw, TDT),
1892 tx_ring->next_to_use,
1893 tx_ring->next_to_clean,
1894 tx_ring->buffer_info[eop].time_stamp,
1898 netif_stop_queue(netdev);
1906 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1907 * @adapter: board private structure
1908 * @rx_desc: receive descriptor
1909 * @sk_buff: socket buffer with received data
1913 ixgb_rx_checksum(struct ixgb_adapter *adapter,
1914 struct ixgb_rx_desc *rx_desc,
1915 struct sk_buff *skb)
1917 /* Ignore Checksum bit is set OR
1918 * TCP Checksum has not been calculated
1920 if ((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1921 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1922 skb_checksum_none_assert(skb);
1926 /* At this point we know the hardware did the TCP checksum */
1927 /* now look at the TCP checksum error bit */
1928 if (rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1929 /* let the stack verify checksum errors */
1930 skb_checksum_none_assert(skb);
1931 adapter->hw_csum_rx_error++;
1933 /* TCP checksum is good */
1934 skb->ip_summed = CHECKSUM_UNNECESSARY;
1935 adapter->hw_csum_rx_good++;
1940 * this should improve performance for small packets with large amounts
1941 * of reassembly being done in the stack
1943 static void ixgb_check_copybreak(struct napi_struct *napi,
1944 struct ixgb_buffer *buffer_info,
1945 u32 length, struct sk_buff **skb)
1947 struct sk_buff *new_skb;
1949 if (length > copybreak)
1952 new_skb = napi_alloc_skb(napi, length);
1956 skb_copy_to_linear_data_offset(new_skb, -NET_IP_ALIGN,
1957 (*skb)->data - NET_IP_ALIGN,
1958 length + NET_IP_ALIGN);
1959 /* save the skb in buffer_info as good */
1960 buffer_info->skb = *skb;
1965 * ixgb_clean_rx_irq - Send received data up the network stack,
1966 * @adapter: board private structure
1970 ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1972 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1973 struct net_device *netdev = adapter->netdev;
1974 struct pci_dev *pdev = adapter->pdev;
1975 struct ixgb_rx_desc *rx_desc, *next_rxd;
1976 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1979 int cleaned_count = 0;
1980 bool cleaned = false;
1982 i = rx_ring->next_to_clean;
1983 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1984 buffer_info = &rx_ring->buffer_info[i];
1986 while (rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1987 struct sk_buff *skb;
1990 if (*work_done >= work_to_do)
1994 rmb(); /* read descriptor and rx_buffer_info after status DD */
1995 status = rx_desc->status;
1996 skb = buffer_info->skb;
1997 buffer_info->skb = NULL;
1999 prefetch(skb->data - NET_IP_ALIGN);
2001 if (++i == rx_ring->count)
2003 next_rxd = IXGB_RX_DESC(*rx_ring, i);
2007 if (j == rx_ring->count)
2009 next2_buffer = &rx_ring->buffer_info[j];
2010 prefetch(next2_buffer);
2012 next_buffer = &rx_ring->buffer_info[i];
2017 dma_unmap_single(&pdev->dev,
2019 buffer_info->length,
2021 buffer_info->dma = 0;
2023 length = le16_to_cpu(rx_desc->length);
2024 rx_desc->length = 0;
2026 if (unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
2028 /* All receives must fit into a single buffer */
2030 pr_debug("Receive packet consumed multiple buffers length<%x>\n",
2033 dev_kfree_skb_irq(skb);
2037 if (unlikely(rx_desc->errors &
2038 (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE |
2039 IXGB_RX_DESC_ERRORS_P | IXGB_RX_DESC_ERRORS_RXE))) {
2040 dev_kfree_skb_irq(skb);
2044 ixgb_check_copybreak(&adapter->napi, buffer_info, length, &skb);
2047 skb_put(skb, length);
2049 /* Receive Checksum Offload */
2050 ixgb_rx_checksum(adapter, rx_desc, skb);
2052 skb->protocol = eth_type_trans(skb, netdev);
2053 if (status & IXGB_RX_DESC_STATUS_VP)
2054 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2055 le16_to_cpu(rx_desc->special));
2057 netif_receive_skb(skb);
2060 /* clean up descriptor, might be written over by hw */
2061 rx_desc->status = 0;
2063 /* return some buffers to hardware, one at a time is too slow */
2064 if (unlikely(cleaned_count >= IXGB_RX_BUFFER_WRITE)) {
2065 ixgb_alloc_rx_buffers(adapter, cleaned_count);
2069 /* use prefetched values */
2071 buffer_info = next_buffer;
2074 rx_ring->next_to_clean = i;
2076 cleaned_count = IXGB_DESC_UNUSED(rx_ring);
2078 ixgb_alloc_rx_buffers(adapter, cleaned_count);
2084 * ixgb_alloc_rx_buffers - Replace used receive buffers
2085 * @adapter: address of board private structure
2089 ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter, int cleaned_count)
2091 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
2092 struct net_device *netdev = adapter->netdev;
2093 struct pci_dev *pdev = adapter->pdev;
2094 struct ixgb_rx_desc *rx_desc;
2095 struct ixgb_buffer *buffer_info;
2096 struct sk_buff *skb;
2100 i = rx_ring->next_to_use;
2101 buffer_info = &rx_ring->buffer_info[i];
2102 cleancount = IXGB_DESC_UNUSED(rx_ring);
2105 /* leave three descriptors unused */
2106 while (--cleancount > 2 && cleaned_count--) {
2107 /* recycle! its good for you */
2108 skb = buffer_info->skb;
2114 skb = netdev_alloc_skb_ip_align(netdev, adapter->rx_buffer_len);
2115 if (unlikely(!skb)) {
2116 /* Better luck next round */
2117 adapter->alloc_rx_buff_failed++;
2121 buffer_info->skb = skb;
2122 buffer_info->length = adapter->rx_buffer_len;
2124 buffer_info->dma = dma_map_single(&pdev->dev,
2126 adapter->rx_buffer_len,
2128 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
2129 adapter->alloc_rx_buff_failed++;
2133 rx_desc = IXGB_RX_DESC(*rx_ring, i);
2134 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
2135 /* guarantee DD bit not set now before h/w gets descriptor
2136 * this is the rest of the workaround for h/w double
2138 rx_desc->status = 0;
2141 if (++i == rx_ring->count)
2143 buffer_info = &rx_ring->buffer_info[i];
2146 if (likely(rx_ring->next_to_use != i)) {
2147 rx_ring->next_to_use = i;
2148 if (unlikely(i-- == 0))
2149 i = (rx_ring->count - 1);
2151 /* Force memory writes to complete before letting h/w
2152 * know there are new descriptors to fetch. (Only
2153 * applicable for weak-ordered memory model archs, such
2156 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2161 ixgb_vlan_strip_enable(struct ixgb_adapter *adapter)
2165 /* enable VLAN tag insert/strip */
2166 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2167 ctrl |= IXGB_CTRL0_VME;
2168 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2172 ixgb_vlan_strip_disable(struct ixgb_adapter *adapter)
2176 /* disable VLAN tag insert/strip */
2177 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2178 ctrl &= ~IXGB_CTRL0_VME;
2179 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2183 ixgb_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
2185 struct ixgb_adapter *adapter = netdev_priv(netdev);
2188 /* add VID to filter table */
2190 index = (vid >> 5) & 0x7F;
2191 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2192 vfta |= (1 << (vid & 0x1F));
2193 ixgb_write_vfta(&adapter->hw, index, vfta);
2194 set_bit(vid, adapter->active_vlans);
2200 ixgb_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
2202 struct ixgb_adapter *adapter = netdev_priv(netdev);
2205 /* remove VID from filter table */
2207 index = (vid >> 5) & 0x7F;
2208 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2209 vfta &= ~(1 << (vid & 0x1F));
2210 ixgb_write_vfta(&adapter->hw, index, vfta);
2211 clear_bit(vid, adapter->active_vlans);
2217 ixgb_restore_vlan(struct ixgb_adapter *adapter)
2221 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
2222 ixgb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
2225 #ifdef CONFIG_NET_POLL_CONTROLLER
2227 * Polling 'interrupt' - used by things like netconsole to send skbs
2228 * without having to re-enable interrupts. It's not called while
2229 * the interrupt routine is executing.
2232 static void ixgb_netpoll(struct net_device *dev)
2234 struct ixgb_adapter *adapter = netdev_priv(dev);
2236 disable_irq(adapter->pdev->irq);
2237 ixgb_intr(adapter->pdev->irq, dev);
2238 enable_irq(adapter->pdev->irq);
2243 * ixgb_io_error_detected - called when PCI error is detected
2244 * @pdev: pointer to pci device with error
2245 * @state: pci channel state after error
2247 * This callback is called by the PCI subsystem whenever
2248 * a PCI bus error is detected.
2250 static pci_ers_result_t ixgb_io_error_detected(struct pci_dev *pdev,
2251 enum pci_channel_state state)
2253 struct net_device *netdev = pci_get_drvdata(pdev);
2254 struct ixgb_adapter *adapter = netdev_priv(netdev);
2256 netif_device_detach(netdev);
2258 if (state == pci_channel_io_perm_failure)
2259 return PCI_ERS_RESULT_DISCONNECT;
2261 if (netif_running(netdev))
2262 ixgb_down(adapter, true);
2264 pci_disable_device(pdev);
2266 /* Request a slot reset. */
2267 return PCI_ERS_RESULT_NEED_RESET;
2271 * ixgb_io_slot_reset - called after the pci bus has been reset.
2272 * @pdev pointer to pci device with error
2274 * This callback is called after the PCI bus has been reset.
2275 * Basically, this tries to restart the card from scratch.
2276 * This is a shortened version of the device probe/discovery code,
2277 * it resembles the first-half of the ixgb_probe() routine.
2279 static pci_ers_result_t ixgb_io_slot_reset(struct pci_dev *pdev)
2281 struct net_device *netdev = pci_get_drvdata(pdev);
2282 struct ixgb_adapter *adapter = netdev_priv(netdev);
2284 if (pci_enable_device(pdev)) {
2285 netif_err(adapter, probe, adapter->netdev,
2286 "Cannot re-enable PCI device after reset\n");
2287 return PCI_ERS_RESULT_DISCONNECT;
2290 /* Perform card reset only on one instance of the card */
2291 if (0 != PCI_FUNC (pdev->devfn))
2292 return PCI_ERS_RESULT_RECOVERED;
2294 pci_set_master(pdev);
2296 netif_carrier_off(netdev);
2297 netif_stop_queue(netdev);
2298 ixgb_reset(adapter);
2300 /* Make sure the EEPROM is good */
2301 if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
2302 netif_err(adapter, probe, adapter->netdev,
2303 "After reset, the EEPROM checksum is not valid\n");
2304 return PCI_ERS_RESULT_DISCONNECT;
2306 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
2307 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
2309 if (!is_valid_ether_addr(netdev->perm_addr)) {
2310 netif_err(adapter, probe, adapter->netdev,
2311 "After reset, invalid MAC address\n");
2312 return PCI_ERS_RESULT_DISCONNECT;
2315 return PCI_ERS_RESULT_RECOVERED;
2319 * ixgb_io_resume - called when its OK to resume normal operations
2320 * @pdev pointer to pci device with error
2322 * The error recovery driver tells us that its OK to resume
2323 * normal operation. Implementation resembles the second-half
2324 * of the ixgb_probe() routine.
2326 static void ixgb_io_resume(struct pci_dev *pdev)
2328 struct net_device *netdev = pci_get_drvdata(pdev);
2329 struct ixgb_adapter *adapter = netdev_priv(netdev);
2331 pci_set_master(pdev);
2333 if (netif_running(netdev)) {
2334 if (ixgb_up(adapter)) {
2335 pr_err("can't bring device back up after reset\n");
2340 netif_device_attach(netdev);
2341 mod_timer(&adapter->watchdog_timer, jiffies);