fp@2685: /* Intel(R) Gigabit Ethernet Linux driver
fp@2685: * Copyright(c) 2007-2014 Intel Corporation.
fp@2685: *
fp@2685: * This program is free software; you can redistribute it and/or modify it
fp@2685: * under the terms and conditions of the GNU General Public License,
fp@2685: * version 2, as published by the Free Software Foundation.
fp@2685: *
fp@2685: * This program is distributed in the hope it will be useful, but WITHOUT
fp@2685: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2685: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
fp@2685: * more details.
fp@2685: *
fp@2685: * You should have received a copy of the GNU General Public License along with
fp@2685: * this program; if not, see .
fp@2685: *
fp@2685: * The full GNU General Public License is included in this distribution in
fp@2685: * the file called "COPYING".
fp@2685: *
fp@2685: * Contact Information:
fp@2685: * e1000-devel Mailing List
fp@2685: * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2686: *
fp@2686: * vim: noexpandtab
fp@2685: */
fp@2685:
fp@2685: #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
fp@2685:
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: #include
fp@2685: #endif
fp@2685: #include
fp@2685: #include "igb-3.18-ethercat.h"
fp@2685:
fp@2685: #define MAJ 5
fp@2685: #define MIN 2
fp@2685: #define BUILD 15
fp@2685: #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
fp@2686: __stringify(BUILD) "-k-EtherCAT"
fp@2686: char igb_driver_name[] = "ec_igb";
fp@2685: char igb_driver_version[] = DRV_VERSION;
fp@2685: static const char igb_driver_string[] =
fp@2686: "Intel(R) Gigabit Ethernet Network Driver (EtherCAT-enabled)";
fp@2685: static const char igb_copyright[] =
fp@2685: "Copyright (c) 2007-2014 Intel Corporation.";
fp@2685:
fp@2685: static const struct e1000_info *igb_info_tbl[] = {
fp@2685: [board_82575] = &e1000_82575_info,
fp@2685: };
fp@2685:
fp@2685: static const struct pci_device_id igb_pci_tbl[] = {
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER_FLASHLESS), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES_FLASHLESS), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
fp@2685: { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
fp@2685: /* required last entry */
fp@2685: {0, }
fp@2685: };
fp@2685:
fp@2686: // MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
fp@2685:
fp@2685: static int igb_setup_all_tx_resources(struct igb_adapter *);
fp@2685: static int igb_setup_all_rx_resources(struct igb_adapter *);
fp@2685: static void igb_free_all_tx_resources(struct igb_adapter *);
fp@2685: static void igb_free_all_rx_resources(struct igb_adapter *);
fp@2685: static void igb_setup_mrqc(struct igb_adapter *);
fp@2685: static int igb_probe(struct pci_dev *, const struct pci_device_id *);
fp@2685: static void igb_remove(struct pci_dev *pdev);
fp@2685: static int igb_sw_init(struct igb_adapter *);
fp@2685: static int igb_open(struct net_device *);
fp@2685: static int igb_close(struct net_device *);
fp@2685: static void igb_configure(struct igb_adapter *);
fp@2685: static void igb_configure_tx(struct igb_adapter *);
fp@2685: static void igb_configure_rx(struct igb_adapter *);
fp@2685: static void igb_clean_all_tx_rings(struct igb_adapter *);
fp@2685: static void igb_clean_all_rx_rings(struct igb_adapter *);
fp@2685: static void igb_clean_tx_ring(struct igb_ring *);
fp@2685: static void igb_clean_rx_ring(struct igb_ring *);
fp@2685: static void igb_set_rx_mode(struct net_device *);
fp@2685: static void igb_update_phy_info(unsigned long);
fp@2685: static void igb_watchdog(unsigned long);
fp@2685: static void igb_watchdog_task(struct work_struct *);
fp@2685: static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
fp@2685: static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
fp@2685: struct rtnl_link_stats64 *stats);
fp@2685: static int igb_change_mtu(struct net_device *, int);
fp@2685: static int igb_set_mac(struct net_device *, void *);
fp@2685: static void igb_set_uta(struct igb_adapter *adapter);
fp@2685: static irqreturn_t igb_intr(int irq, void *);
fp@2685: static irqreturn_t igb_intr_msi(int irq, void *);
fp@2685: static irqreturn_t igb_msix_other(int irq, void *);
fp@2685: static irqreturn_t igb_msix_ring(int irq, void *);
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: static void igb_update_dca(struct igb_q_vector *);
fp@2685: static void igb_setup_dca(struct igb_adapter *);
fp@2685: #endif /* CONFIG_IGB_DCA */
fp@2685: static int igb_poll(struct napi_struct *, int);
fp@2685: static bool igb_clean_tx_irq(struct igb_q_vector *);
fp@2685: static bool igb_clean_rx_irq(struct igb_q_vector *, int);
fp@2685: static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
fp@2685: static void igb_tx_timeout(struct net_device *);
fp@2685: static void igb_reset_task(struct work_struct *);
fp@2685: static void igb_vlan_mode(struct net_device *netdev,
fp@2685: netdev_features_t features);
fp@2685: static int igb_vlan_rx_add_vid(struct net_device *, __be16, u16);
fp@2685: static int igb_vlan_rx_kill_vid(struct net_device *, __be16, u16);
fp@2685: static void igb_restore_vlan(struct igb_adapter *);
fp@2685: static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
fp@2685: static void igb_ping_all_vfs(struct igb_adapter *);
fp@2685: static void igb_msg_task(struct igb_adapter *);
fp@2685: static void igb_vmm_control(struct igb_adapter *);
fp@2685: static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
fp@2685: static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
fp@2685: static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
fp@2685: static int igb_ndo_set_vf_vlan(struct net_device *netdev,
fp@2685: int vf, u16 vlan, u8 qos);
fp@2685: static int igb_ndo_set_vf_bw(struct net_device *, int, int, int);
fp@2685: static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
fp@2685: bool setting);
fp@2685: static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
fp@2685: struct ifla_vf_info *ivi);
fp@2685: static void igb_check_vf_rate_limit(struct igb_adapter *);
fp@2685:
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: static int igb_vf_configure(struct igb_adapter *adapter, int vf);
fp@2685: static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs);
fp@2685: #endif
fp@2685:
fp@2685: #ifdef CONFIG_PM
fp@2685: #ifdef CONFIG_PM_SLEEP
fp@2685: static int igb_suspend(struct device *);
fp@2685: #endif
fp@2685: static int igb_resume(struct device *);
fp@2685: #ifdef CONFIG_PM_RUNTIME
fp@2685: static int igb_runtime_suspend(struct device *dev);
fp@2685: static int igb_runtime_resume(struct device *dev);
fp@2685: static int igb_runtime_idle(struct device *dev);
fp@2685: #endif
fp@2685: static const struct dev_pm_ops igb_pm_ops = {
fp@2685: SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
fp@2685: SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
fp@2685: igb_runtime_idle)
fp@2685: };
fp@2685: #endif
fp@2685: static void igb_shutdown(struct pci_dev *);
fp@2685: static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs);
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
fp@2685: static struct notifier_block dca_notifier = {
fp@2685: .notifier_call = igb_notify_dca,
fp@2685: .next = NULL,
fp@2685: .priority = 0
fp@2685: };
fp@2685: #endif
fp@2685: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@2685: /* for netdump / net console */
fp@2685: static void igb_netpoll(struct net_device *);
fp@2685: #endif
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: static unsigned int max_vfs;
fp@2685: module_param(max_vfs, uint, 0);
fp@2685: MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate per physical function");
fp@2685: #endif /* CONFIG_PCI_IOV */
fp@2685:
fp@2685: static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
fp@2685: pci_channel_state_t);
fp@2685: static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
fp@2685: static void igb_io_resume(struct pci_dev *);
fp@2685:
fp@2685: static const struct pci_error_handlers igb_err_handler = {
fp@2685: .error_detected = igb_io_error_detected,
fp@2685: .slot_reset = igb_io_slot_reset,
fp@2685: .resume = igb_io_resume,
fp@2685: };
fp@2685:
fp@2685: static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
fp@2685:
fp@2685: static struct pci_driver igb_driver = {
fp@2685: .name = igb_driver_name,
fp@2685: .id_table = igb_pci_tbl,
fp@2685: .probe = igb_probe,
fp@2685: .remove = igb_remove,
fp@2685: #ifdef CONFIG_PM
fp@2685: .driver.pm = &igb_pm_ops,
fp@2685: #endif
fp@2685: .shutdown = igb_shutdown,
fp@2685: .sriov_configure = igb_pci_sriov_configure,
fp@2685: .err_handler = &igb_err_handler
fp@2685: };
fp@2685:
fp@2685: MODULE_AUTHOR("Intel Corporation, ");
fp@2685: MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
fp@2685: MODULE_LICENSE("GPL");
fp@2685: MODULE_VERSION(DRV_VERSION);
fp@2685:
fp@2685: #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
fp@2685: static int debug = -1;
fp@2685: module_param(debug, int, 0);
fp@2685: MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
fp@2685:
fp@2685: struct igb_reg_info {
fp@2685: u32 ofs;
fp@2685: char *name;
fp@2685: };
fp@2685:
fp@2685: static const struct igb_reg_info igb_reg_info_tbl[] = {
fp@2685:
fp@2685: /* General Registers */
fp@2685: {E1000_CTRL, "CTRL"},
fp@2685: {E1000_STATUS, "STATUS"},
fp@2685: {E1000_CTRL_EXT, "CTRL_EXT"},
fp@2685:
fp@2685: /* Interrupt Registers */
fp@2685: {E1000_ICR, "ICR"},
fp@2685:
fp@2685: /* RX Registers */
fp@2685: {E1000_RCTL, "RCTL"},
fp@2685: {E1000_RDLEN(0), "RDLEN"},
fp@2685: {E1000_RDH(0), "RDH"},
fp@2685: {E1000_RDT(0), "RDT"},
fp@2685: {E1000_RXDCTL(0), "RXDCTL"},
fp@2685: {E1000_RDBAL(0), "RDBAL"},
fp@2685: {E1000_RDBAH(0), "RDBAH"},
fp@2685:
fp@2685: /* TX Registers */
fp@2685: {E1000_TCTL, "TCTL"},
fp@2685: {E1000_TDBAL(0), "TDBAL"},
fp@2685: {E1000_TDBAH(0), "TDBAH"},
fp@2685: {E1000_TDLEN(0), "TDLEN"},
fp@2685: {E1000_TDH(0), "TDH"},
fp@2685: {E1000_TDT(0), "TDT"},
fp@2685: {E1000_TXDCTL(0), "TXDCTL"},
fp@2685: {E1000_TDFH, "TDFH"},
fp@2685: {E1000_TDFT, "TDFT"},
fp@2685: {E1000_TDFHS, "TDFHS"},
fp@2685: {E1000_TDFPC, "TDFPC"},
fp@2685:
fp@2685: /* List Terminator */
fp@2685: {}
fp@2685: };
fp@2685:
fp@2685: /* igb_regdump - register printout routine */
fp@2685: static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
fp@2685: {
fp@2685: int n = 0;
fp@2685: char rname[16];
fp@2685: u32 regs[8];
fp@2685:
fp@2685: switch (reginfo->ofs) {
fp@2685: case E1000_RDLEN(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDLEN(n));
fp@2685: break;
fp@2685: case E1000_RDH(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDH(n));
fp@2685: break;
fp@2685: case E1000_RDT(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDT(n));
fp@2685: break;
fp@2685: case E1000_RXDCTL(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RXDCTL(n));
fp@2685: break;
fp@2685: case E1000_RDBAL(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDBAL(n));
fp@2685: break;
fp@2685: case E1000_RDBAH(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDBAH(n));
fp@2685: break;
fp@2685: case E1000_TDBAL(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_RDBAL(n));
fp@2685: break;
fp@2685: case E1000_TDBAH(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_TDBAH(n));
fp@2685: break;
fp@2685: case E1000_TDLEN(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_TDLEN(n));
fp@2685: break;
fp@2685: case E1000_TDH(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_TDH(n));
fp@2685: break;
fp@2685: case E1000_TDT(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_TDT(n));
fp@2685: break;
fp@2685: case E1000_TXDCTL(0):
fp@2685: for (n = 0; n < 4; n++)
fp@2685: regs[n] = rd32(E1000_TXDCTL(n));
fp@2685: break;
fp@2685: default:
fp@2685: pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
fp@2685: return;
fp@2685: }
fp@2685:
fp@2685: snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
fp@2685: pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
fp@2685: regs[2], regs[3]);
fp@2685: }
fp@2685:
fp@2685: /* igb_dump - Print registers, Tx-rings and Rx-rings */
fp@2685: static void igb_dump(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct igb_reg_info *reginfo;
fp@2685: struct igb_ring *tx_ring;
fp@2685: union e1000_adv_tx_desc *tx_desc;
fp@2685: struct my_u0 { u64 a; u64 b; } *u0;
fp@2685: struct igb_ring *rx_ring;
fp@2685: union e1000_adv_rx_desc *rx_desc;
fp@2685: u32 staterr;
fp@2685: u16 i, n;
fp@2685:
fp@2685: if (!netif_msg_hw(adapter))
fp@2685: return;
fp@2685:
fp@2685: /* Print netdevice Info */
fp@2685: if (netdev) {
fp@2685: dev_info(&adapter->pdev->dev, "Net device Info\n");
fp@2685: pr_info("Device Name state trans_start last_rx\n");
fp@2685: pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
fp@2685: netdev->state, netdev->trans_start, netdev->last_rx);
fp@2685: }
fp@2685:
fp@2685: /* Print Registers */
fp@2685: dev_info(&adapter->pdev->dev, "Register Dump\n");
fp@2685: pr_info(" Register Name Value\n");
fp@2685: for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
fp@2685: reginfo->name; reginfo++) {
fp@2685: igb_regdump(hw, reginfo);
fp@2685: }
fp@2685:
fp@2685: /* Print TX Ring Summary */
fp@2685: if (!netdev || !netif_running(netdev))
fp@2685: goto exit;
fp@2685:
fp@2685: dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
fp@2685: pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
fp@2685: for (n = 0; n < adapter->num_tx_queues; n++) {
fp@2685: struct igb_tx_buffer *buffer_info;
fp@2685: tx_ring = adapter->tx_ring[n];
fp@2685: buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
fp@2685: pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
fp@2685: n, tx_ring->next_to_use, tx_ring->next_to_clean,
fp@2685: (u64)dma_unmap_addr(buffer_info, dma),
fp@2685: dma_unmap_len(buffer_info, len),
fp@2685: buffer_info->next_to_watch,
fp@2685: (u64)buffer_info->time_stamp);
fp@2685: }
fp@2685:
fp@2685: /* Print TX Rings */
fp@2685: if (!netif_msg_tx_done(adapter))
fp@2685: goto rx_ring_summary;
fp@2685:
fp@2685: dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
fp@2685:
fp@2685: /* Transmit Descriptor Formats
fp@2685: *
fp@2685: * Advanced Transmit Descriptor
fp@2685: * +--------------------------------------------------------------+
fp@2685: * 0 | Buffer Address [63:0] |
fp@2685: * +--------------------------------------------------------------+
fp@2685: * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
fp@2685: * +--------------------------------------------------------------+
fp@2685: * 63 46 45 40 39 38 36 35 32 31 24 15 0
fp@2685: */
fp@2685:
fp@2685: for (n = 0; n < adapter->num_tx_queues; n++) {
fp@2685: tx_ring = adapter->tx_ring[n];
fp@2685: pr_info("------------------------------------\n");
fp@2685: pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
fp@2685: pr_info("------------------------------------\n");
fp@2685: pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] [bi->dma ] leng ntw timestamp bi->skb\n");
fp@2685:
fp@2685: for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
fp@2685: const char *next_desc;
fp@2685: struct igb_tx_buffer *buffer_info;
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, i);
fp@2685: buffer_info = &tx_ring->tx_buffer_info[i];
fp@2685: u0 = (struct my_u0 *)tx_desc;
fp@2685: if (i == tx_ring->next_to_use &&
fp@2685: i == tx_ring->next_to_clean)
fp@2685: next_desc = " NTC/U";
fp@2685: else if (i == tx_ring->next_to_use)
fp@2685: next_desc = " NTU";
fp@2685: else if (i == tx_ring->next_to_clean)
fp@2685: next_desc = " NTC";
fp@2685: else
fp@2685: next_desc = "";
fp@2685:
fp@2685: pr_info("T [0x%03X] %016llX %016llX %016llX %04X %p %016llX %p%s\n",
fp@2685: i, le64_to_cpu(u0->a),
fp@2685: le64_to_cpu(u0->b),
fp@2685: (u64)dma_unmap_addr(buffer_info, dma),
fp@2685: dma_unmap_len(buffer_info, len),
fp@2685: buffer_info->next_to_watch,
fp@2685: (u64)buffer_info->time_stamp,
fp@2685: buffer_info->skb, next_desc);
fp@2685:
fp@2685: if (netif_msg_pktdata(adapter) && buffer_info->skb)
fp@2685: print_hex_dump(KERN_INFO, "",
fp@2685: DUMP_PREFIX_ADDRESS,
fp@2685: 16, 1, buffer_info->skb->data,
fp@2685: dma_unmap_len(buffer_info, len),
fp@2685: true);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /* Print RX Rings Summary */
fp@2685: rx_ring_summary:
fp@2685: dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
fp@2685: pr_info("Queue [NTU] [NTC]\n");
fp@2685: for (n = 0; n < adapter->num_rx_queues; n++) {
fp@2685: rx_ring = adapter->rx_ring[n];
fp@2685: pr_info(" %5d %5X %5X\n",
fp@2685: n, rx_ring->next_to_use, rx_ring->next_to_clean);
fp@2685: }
fp@2685:
fp@2685: /* Print RX Rings */
fp@2685: if (!netif_msg_rx_status(adapter))
fp@2685: goto exit;
fp@2685:
fp@2685: dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
fp@2685:
fp@2685: /* Advanced Receive Descriptor (Read) Format
fp@2685: * 63 1 0
fp@2685: * +-----------------------------------------------------+
fp@2685: * 0 | Packet Buffer Address [63:1] |A0/NSE|
fp@2685: * +----------------------------------------------+------+
fp@2685: * 8 | Header Buffer Address [63:1] | DD |
fp@2685: * +-----------------------------------------------------+
fp@2685: *
fp@2685: *
fp@2685: * Advanced Receive Descriptor (Write-Back) Format
fp@2685: *
fp@2685: * 63 48 47 32 31 30 21 20 17 16 4 3 0
fp@2685: * +------------------------------------------------------+
fp@2685: * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
fp@2685: * | Checksum Ident | | | | Type | Type |
fp@2685: * +------------------------------------------------------+
fp@2685: * 8 | VLAN Tag | Length | Extended Error | Extended Status |
fp@2685: * +------------------------------------------------------+
fp@2685: * 63 48 47 32 31 20 19 0
fp@2685: */
fp@2685:
fp@2685: for (n = 0; n < adapter->num_rx_queues; n++) {
fp@2685: rx_ring = adapter->rx_ring[n];
fp@2685: pr_info("------------------------------------\n");
fp@2685: pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
fp@2685: pr_info("------------------------------------\n");
fp@2685: pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] [bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
fp@2685: pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
fp@2685:
fp@2685: for (i = 0; i < rx_ring->count; i++) {
fp@2685: const char *next_desc;
fp@2685: struct igb_rx_buffer *buffer_info;
fp@2685: buffer_info = &rx_ring->rx_buffer_info[i];
fp@2685: rx_desc = IGB_RX_DESC(rx_ring, i);
fp@2685: u0 = (struct my_u0 *)rx_desc;
fp@2685: staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
fp@2685:
fp@2685: if (i == rx_ring->next_to_use)
fp@2685: next_desc = " NTU";
fp@2685: else if (i == rx_ring->next_to_clean)
fp@2685: next_desc = " NTC";
fp@2685: else
fp@2685: next_desc = "";
fp@2685:
fp@2685: if (staterr & E1000_RXD_STAT_DD) {
fp@2685: /* Descriptor Done */
fp@2685: pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
fp@2685: "RWB", i,
fp@2685: le64_to_cpu(u0->a),
fp@2685: le64_to_cpu(u0->b),
fp@2685: next_desc);
fp@2685: } else {
fp@2685: pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
fp@2685: "R ", i,
fp@2685: le64_to_cpu(u0->a),
fp@2685: le64_to_cpu(u0->b),
fp@2685: (u64)buffer_info->dma,
fp@2685: next_desc);
fp@2685:
fp@2685: if (netif_msg_pktdata(adapter) &&
fp@2685: buffer_info->dma && buffer_info->page) {
fp@2685: print_hex_dump(KERN_INFO, "",
fp@2685: DUMP_PREFIX_ADDRESS,
fp@2685: 16, 1,
fp@2685: page_address(buffer_info->page) +
fp@2685: buffer_info->page_offset,
fp@2685: IGB_RX_BUFSZ, true);
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: exit:
fp@2685: return;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_get_i2c_data - Reads the I2C SDA data bit
fp@2685: * @hw: pointer to hardware structure
fp@2685: * @i2cctl: Current value of I2CCTL register
fp@2685: *
fp@2685: * Returns the I2C data bit value
fp@2685: **/
fp@2685: static int igb_get_i2c_data(void *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *)data;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: s32 i2cctl = rd32(E1000_I2CPARAMS);
fp@2685:
fp@2685: return !!(i2cctl & E1000_I2C_DATA_IN);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_i2c_data - Sets the I2C data bit
fp@2685: * @data: pointer to hardware structure
fp@2685: * @state: I2C data value (0 or 1) to set
fp@2685: *
fp@2685: * Sets the I2C data bit
fp@2685: **/
fp@2685: static void igb_set_i2c_data(void *data, int state)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *)data;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: s32 i2cctl = rd32(E1000_I2CPARAMS);
fp@2685:
fp@2685: if (state)
fp@2685: i2cctl |= E1000_I2C_DATA_OUT;
fp@2685: else
fp@2685: i2cctl &= ~E1000_I2C_DATA_OUT;
fp@2685:
fp@2685: i2cctl &= ~E1000_I2C_DATA_OE_N;
fp@2685: i2cctl |= E1000_I2C_CLK_OE_N;
fp@2685: wr32(E1000_I2CPARAMS, i2cctl);
fp@2685: wrfl();
fp@2685:
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_i2c_clk - Sets the I2C SCL clock
fp@2685: * @data: pointer to hardware structure
fp@2685: * @state: state to set clock
fp@2685: *
fp@2685: * Sets the I2C clock line to state
fp@2685: **/
fp@2685: static void igb_set_i2c_clk(void *data, int state)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *)data;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: s32 i2cctl = rd32(E1000_I2CPARAMS);
fp@2685:
fp@2685: if (state) {
fp@2685: i2cctl |= E1000_I2C_CLK_OUT;
fp@2685: i2cctl &= ~E1000_I2C_CLK_OE_N;
fp@2685: } else {
fp@2685: i2cctl &= ~E1000_I2C_CLK_OUT;
fp@2685: i2cctl &= ~E1000_I2C_CLK_OE_N;
fp@2685: }
fp@2685: wr32(E1000_I2CPARAMS, i2cctl);
fp@2685: wrfl();
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_get_i2c_clk - Gets the I2C SCL clock state
fp@2685: * @data: pointer to hardware structure
fp@2685: *
fp@2685: * Gets the I2C clock state
fp@2685: **/
fp@2685: static int igb_get_i2c_clk(void *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *)data;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: s32 i2cctl = rd32(E1000_I2CPARAMS);
fp@2685:
fp@2685: return !!(i2cctl & E1000_I2C_CLK_IN);
fp@2685: }
fp@2685:
fp@2685: static const struct i2c_algo_bit_data igb_i2c_algo = {
fp@2685: .setsda = igb_set_i2c_data,
fp@2685: .setscl = igb_set_i2c_clk,
fp@2685: .getsda = igb_get_i2c_data,
fp@2685: .getscl = igb_get_i2c_clk,
fp@2685: .udelay = 5,
fp@2685: .timeout = 20,
fp@2685: };
fp@2685:
fp@2685: /**
fp@2685: * igb_get_hw_dev - return device
fp@2685: * @hw: pointer to hardware structure
fp@2685: *
fp@2685: * used by hardware layer to print debugging information
fp@2685: **/
fp@2685: struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
fp@2685: {
fp@2685: struct igb_adapter *adapter = hw->back;
fp@2685: return adapter->netdev;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_init_module - Driver Registration Routine
fp@2685: *
fp@2685: * igb_init_module is the first routine called when the driver is
fp@2685: * loaded. All it does is register with the PCI subsystem.
fp@2685: **/
fp@2685: static int __init igb_init_module(void)
fp@2685: {
fp@2685: int ret;
fp@2685:
fp@2685: pr_info("%s - version %s\n",
fp@2685: igb_driver_string, igb_driver_version);
fp@2685: pr_info("%s\n", igb_copyright);
fp@2685:
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: dca_register_notify(&dca_notifier);
fp@2685: #endif
fp@2685: ret = pci_register_driver(&igb_driver);
fp@2685: return ret;
fp@2685: }
fp@2685:
fp@2685: module_init(igb_init_module);
fp@2685:
fp@2685: /**
fp@2685: * igb_exit_module - Driver Exit Cleanup Routine
fp@2685: *
fp@2685: * igb_exit_module is called just before the driver is removed
fp@2685: * from memory.
fp@2685: **/
fp@2685: static void __exit igb_exit_module(void)
fp@2685: {
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: dca_unregister_notify(&dca_notifier);
fp@2685: #endif
fp@2685: pci_unregister_driver(&igb_driver);
fp@2685: }
fp@2685:
fp@2685: module_exit(igb_exit_module);
fp@2685:
fp@2685: #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
fp@2685: /**
fp@2685: * igb_cache_ring_register - Descriptor ring to register mapping
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * Once we know the feature-set enabled for the device, we'll cache
fp@2685: * the register offset the descriptor ring is assigned to.
fp@2685: **/
fp@2685: static void igb_cache_ring_register(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i = 0, j = 0;
fp@2685: u32 rbase_offset = adapter->vfs_allocated_count;
fp@2685:
fp@2685: switch (adapter->hw.mac.type) {
fp@2685: case e1000_82576:
fp@2685: /* The queues are allocated for virtualization such that VF 0
fp@2685: * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
fp@2685: * In order to avoid collision we start at the first free queue
fp@2685: * and continue consuming queues in the same sequence
fp@2685: */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: for (; i < adapter->rss_queues; i++)
fp@2685: adapter->rx_ring[i]->reg_idx = rbase_offset +
fp@2685: Q_IDX_82576(i);
fp@2685: }
fp@2685: /* Fall through */
fp@2685: case e1000_82575:
fp@2685: case e1000_82580:
fp@2685: case e1000_i350:
fp@2685: case e1000_i354:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: /* Fall through */
fp@2685: default:
fp@2685: for (; i < adapter->num_rx_queues; i++)
fp@2685: adapter->rx_ring[i]->reg_idx = rbase_offset + i;
fp@2685: for (; j < adapter->num_tx_queues; j++)
fp@2685: adapter->tx_ring[j]->reg_idx = rbase_offset + j;
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: u32 igb_rd32(struct e1000_hw *hw, u32 reg)
fp@2685: {
fp@2685: struct igb_adapter *igb = container_of(hw, struct igb_adapter, hw);
fp@2685: u8 __iomem *hw_addr = ACCESS_ONCE(hw->hw_addr);
fp@2685: u32 value = 0;
fp@2685:
fp@2685: if (E1000_REMOVED(hw_addr))
fp@2685: return ~value;
fp@2685:
fp@2685: value = readl(&hw_addr[reg]);
fp@2685:
fp@2685: /* reads should not return all F's */
fp@2685: if (!(~value) && (!reg || !(~readl(hw_addr)))) {
fp@2685: struct net_device *netdev = igb->netdev;
fp@2685: hw->hw_addr = NULL;
fp@2685: netif_device_detach(netdev);
fp@2685: netdev_err(netdev, "PCIe link lost, device now detached\n");
fp@2685: }
fp@2685:
fp@2685: return value;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_write_ivar - configure ivar for given MSI-X vector
fp@2685: * @hw: pointer to the HW structure
fp@2685: * @msix_vector: vector number we are allocating to a given ring
fp@2685: * @index: row index of IVAR register to write within IVAR table
fp@2685: * @offset: column offset of in IVAR, should be multiple of 8
fp@2685: *
fp@2685: * This function is intended to handle the writing of the IVAR register
fp@2685: * for adapters 82576 and newer. The IVAR table consists of 2 columns,
fp@2685: * each containing an cause allocation for an Rx and Tx ring, and a
fp@2685: * variable number of rows depending on the number of queues supported.
fp@2685: **/
fp@2685: static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
fp@2685: int index, int offset)
fp@2685: {
fp@2685: u32 ivar = array_rd32(E1000_IVAR0, index);
fp@2685:
fp@2685: /* clear any bits that are currently set */
fp@2685: ivar &= ~((u32)0xFF << offset);
fp@2685:
fp@2685: /* write vector and valid bit */
fp@2685: ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
fp@2685:
fp@2685: array_wr32(E1000_IVAR0, index, ivar);
fp@2685: }
fp@2685:
fp@2685: #define IGB_N0_QUEUE -1
fp@2685: static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int rx_queue = IGB_N0_QUEUE;
fp@2685: int tx_queue = IGB_N0_QUEUE;
fp@2685: u32 msixbm = 0;
fp@2685:
fp@2685: if (q_vector->rx.ring)
fp@2685: rx_queue = q_vector->rx.ring->reg_idx;
fp@2685: if (q_vector->tx.ring)
fp@2685: tx_queue = q_vector->tx.ring->reg_idx;
fp@2685:
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82575:
fp@2685: /* The 82575 assigns vectors using a bitmask, which matches the
fp@2685: * bitmask for the EICR/EIMS/EIMC registers. To assign one
fp@2685: * or more queues to a vector, we write the appropriate bits
fp@2685: * into the MSIXBM register for that vector.
fp@2685: */
fp@2685: if (rx_queue > IGB_N0_QUEUE)
fp@2685: msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
fp@2685: if (tx_queue > IGB_N0_QUEUE)
fp@2685: msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
fp@2685: if (!(adapter->flags & IGB_FLAG_HAS_MSIX) && msix_vector == 0)
fp@2685: msixbm |= E1000_EIMS_OTHER;
fp@2685: array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
fp@2685: q_vector->eims_value = msixbm;
fp@2685: break;
fp@2685: case e1000_82576:
fp@2685: /* 82576 uses a table that essentially consists of 2 columns
fp@2685: * with 8 rows. The ordering is column-major so we use the
fp@2685: * lower 3 bits as the row index, and the 4th bit as the
fp@2685: * column offset.
fp@2685: */
fp@2685: if (rx_queue > IGB_N0_QUEUE)
fp@2685: igb_write_ivar(hw, msix_vector,
fp@2685: rx_queue & 0x7,
fp@2685: (rx_queue & 0x8) << 1);
fp@2685: if (tx_queue > IGB_N0_QUEUE)
fp@2685: igb_write_ivar(hw, msix_vector,
fp@2685: tx_queue & 0x7,
fp@2685: ((tx_queue & 0x8) << 1) + 8);
fp@2685: q_vector->eims_value = 1 << msix_vector;
fp@2685: break;
fp@2685: case e1000_82580:
fp@2685: case e1000_i350:
fp@2685: case e1000_i354:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: /* On 82580 and newer adapters the scheme is similar to 82576
fp@2685: * however instead of ordering column-major we have things
fp@2685: * ordered row-major. So we traverse the table by using
fp@2685: * bit 0 as the column offset, and the remaining bits as the
fp@2685: * row index.
fp@2685: */
fp@2685: if (rx_queue > IGB_N0_QUEUE)
fp@2685: igb_write_ivar(hw, msix_vector,
fp@2685: rx_queue >> 1,
fp@2685: (rx_queue & 0x1) << 4);
fp@2685: if (tx_queue > IGB_N0_QUEUE)
fp@2685: igb_write_ivar(hw, msix_vector,
fp@2685: tx_queue >> 1,
fp@2685: ((tx_queue & 0x1) << 4) + 8);
fp@2685: q_vector->eims_value = 1 << msix_vector;
fp@2685: break;
fp@2685: default:
fp@2685: BUG();
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: /* add q_vector eims value to global eims_enable_mask */
fp@2685: adapter->eims_enable_mask |= q_vector->eims_value;
fp@2685:
fp@2685: /* configure q_vector to set itr on first interrupt */
fp@2685: q_vector->set_itr = 1;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure_msix - Configure MSI-X hardware
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * igb_configure_msix sets up the hardware to properly
fp@2685: * generate MSI-X interrupts.
fp@2685: **/
fp@2685: static void igb_configure_msix(struct igb_adapter *adapter)
fp@2685: {
fp@2685: u32 tmp;
fp@2685: int i, vector = 0;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: adapter->eims_enable_mask = 0;
fp@2685:
fp@2685: /* set vector for other causes, i.e. link changes */
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82575:
fp@2685: tmp = rd32(E1000_CTRL_EXT);
fp@2685: /* enable MSI-X PBA support*/
fp@2685: tmp |= E1000_CTRL_EXT_PBA_CLR;
fp@2685:
fp@2685: /* Auto-Mask interrupts upon ICR read. */
fp@2685: tmp |= E1000_CTRL_EXT_EIAME;
fp@2685: tmp |= E1000_CTRL_EXT_IRCA;
fp@2685:
fp@2685: wr32(E1000_CTRL_EXT, tmp);
fp@2685:
fp@2685: /* enable msix_other interrupt */
fp@2685: array_wr32(E1000_MSIXBM(0), vector++, E1000_EIMS_OTHER);
fp@2685: adapter->eims_other = E1000_EIMS_OTHER;
fp@2685:
fp@2685: break;
fp@2685:
fp@2685: case e1000_82576:
fp@2685: case e1000_82580:
fp@2685: case e1000_i350:
fp@2685: case e1000_i354:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: /* Turn on MSI-X capability first, or our settings
fp@2685: * won't stick. And it will take days to debug.
fp@2685: */
fp@2685: wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
fp@2685: E1000_GPIE_PBA | E1000_GPIE_EIAME |
fp@2685: E1000_GPIE_NSICR);
fp@2685:
fp@2685: /* enable msix_other interrupt */
fp@2685: adapter->eims_other = 1 << vector;
fp@2685: tmp = (vector++ | E1000_IVAR_VALID) << 8;
fp@2685:
fp@2685: wr32(E1000_IVAR_MISC, tmp);
fp@2685: break;
fp@2685: default:
fp@2685: /* do nothing, since nothing else supports MSI-X */
fp@2685: break;
fp@2685: } /* switch (hw->mac.type) */
fp@2685:
fp@2685: adapter->eims_enable_mask |= adapter->eims_other;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2685: igb_assign_vector(adapter->q_vector[i], vector++);
fp@2685:
fp@2685: wrfl();
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_request_msix - Initialize MSI-X interrupts
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * igb_request_msix allocates MSI-X vectors and requests interrupts from the
fp@2685: * kernel.
fp@2685: **/
fp@2685: static int igb_request_msix(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int i, err = 0, vector = 0, free_vector = 0;
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: /* avoid requesting MSI-X. */
fp@2686: return 0;
fp@2686: }
fp@2686:
fp@2685: err = request_irq(adapter->msix_entries[vector].vector,
fp@2685: igb_msix_other, 0, netdev->name, adapter);
fp@2685: if (err)
fp@2685: goto err_out;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++) {
fp@2685: struct igb_q_vector *q_vector = adapter->q_vector[i];
fp@2685:
fp@2685: vector++;
fp@2685:
fp@2685: q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
fp@2685:
fp@2685: if (q_vector->rx.ring && q_vector->tx.ring)
fp@2685: sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
fp@2685: q_vector->rx.ring->queue_index);
fp@2685: else if (q_vector->tx.ring)
fp@2685: sprintf(q_vector->name, "%s-tx-%u", netdev->name,
fp@2685: q_vector->tx.ring->queue_index);
fp@2685: else if (q_vector->rx.ring)
fp@2685: sprintf(q_vector->name, "%s-rx-%u", netdev->name,
fp@2685: q_vector->rx.ring->queue_index);
fp@2685: else
fp@2685: sprintf(q_vector->name, "%s-unused", netdev->name);
fp@2685:
fp@2685: err = request_irq(adapter->msix_entries[vector].vector,
fp@2685: igb_msix_ring, 0, q_vector->name,
fp@2685: q_vector);
fp@2685: if (err)
fp@2685: goto err_free;
fp@2685: }
fp@2685:
fp@2685: igb_configure_msix(adapter);
fp@2685: return 0;
fp@2685:
fp@2685: err_free:
fp@2685: /* free already assigned IRQs */
fp@2685: free_irq(adapter->msix_entries[free_vector++].vector, adapter);
fp@2685:
fp@2685: vector--;
fp@2685: for (i = 0; i < vector; i++) {
fp@2685: free_irq(adapter->msix_entries[free_vector++].vector,
fp@2685: adapter->q_vector[i]);
fp@2685: }
fp@2685: err_out:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_q_vector - Free memory allocated for specific interrupt vector
fp@2685: * @adapter: board private structure to initialize
fp@2685: * @v_idx: Index of vector to be freed
fp@2685: *
fp@2685: * This function frees the memory allocated to the q_vector.
fp@2685: **/
fp@2685: static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
fp@2685: {
fp@2685: struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
fp@2685:
fp@2685: adapter->q_vector[v_idx] = NULL;
fp@2685:
fp@2685: /* igb_get_stats64() might access the rings on this vector,
fp@2685: * we must wait a grace period before freeing it.
fp@2685: */
fp@2685: if (q_vector)
fp@2685: kfree_rcu(q_vector, rcu);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_reset_q_vector - Reset config for interrupt vector
fp@2685: * @adapter: board private structure to initialize
fp@2685: * @v_idx: Index of vector to be reset
fp@2685: *
fp@2685: * If NAPI is enabled it will delete any references to the
fp@2685: * NAPI struct. This is preparation for igb_free_q_vector.
fp@2685: **/
fp@2685: static void igb_reset_q_vector(struct igb_adapter *adapter, int v_idx)
fp@2685: {
fp@2685: struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
fp@2685:
fp@2685: /* Coming from igb_set_interrupt_capability, the vectors are not yet
fp@2685: * allocated. So, q_vector is NULL so we should stop here.
fp@2685: */
fp@2685: if (!q_vector)
fp@2685: return;
fp@2685:
fp@2685: if (q_vector->tx.ring)
fp@2685: adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
fp@2685:
fp@2685: if (q_vector->rx.ring)
fp@2685: adapter->tx_ring[q_vector->rx.ring->queue_index] = NULL;
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_napi_del(&q_vector->napi);
fp@2686: }
fp@2685:
fp@2685: }
fp@2685:
fp@2685: static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int v_idx = adapter->num_q_vectors;
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX)
fp@2685: pci_disable_msix(adapter->pdev);
fp@2685: else if (adapter->flags & IGB_FLAG_HAS_MSI)
fp@2685: pci_disable_msi(adapter->pdev);
fp@2685:
fp@2685: while (v_idx--)
fp@2685: igb_reset_q_vector(adapter, v_idx);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_q_vectors - Free memory allocated for interrupt vectors
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * This function frees the memory allocated to the q_vectors. In addition if
fp@2685: * NAPI is enabled it will delete any references to the NAPI struct prior
fp@2685: * to freeing the q_vector.
fp@2685: **/
fp@2685: static void igb_free_q_vectors(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int v_idx = adapter->num_q_vectors;
fp@2685:
fp@2685: adapter->num_tx_queues = 0;
fp@2685: adapter->num_rx_queues = 0;
fp@2685: adapter->num_q_vectors = 0;
fp@2685:
fp@2685: while (v_idx--) {
fp@2685: igb_reset_q_vector(adapter, v_idx);
fp@2685: igb_free_q_vector(adapter, v_idx);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * This function resets the device so that it has 0 Rx queues, Tx queues, and
fp@2685: * MSI-X interrupts allocated.
fp@2685: */
fp@2685: static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
fp@2685: {
fp@2685: igb_free_q_vectors(adapter);
fp@2685: igb_reset_interrupt_capability(adapter);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_interrupt_capability - set MSI or MSI-X if supported
fp@2685: * @adapter: board private structure to initialize
fp@2685: * @msix: boolean value of MSIX capability
fp@2685: *
fp@2685: * Attempt to configure interrupts using the best available
fp@2685: * capabilities of the hardware and kernel.
fp@2685: **/
fp@2685: static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
fp@2685: {
fp@2685: int err;
fp@2685: int numvecs, i;
fp@2685:
fp@2685: if (!msix)
fp@2685: goto msi_only;
fp@2685: adapter->flags |= IGB_FLAG_HAS_MSIX;
fp@2685:
fp@2685: /* Number of supported queues. */
fp@2685: adapter->num_rx_queues = adapter->rss_queues;
fp@2685: if (adapter->vfs_allocated_count)
fp@2685: adapter->num_tx_queues = 1;
fp@2685: else
fp@2685: adapter->num_tx_queues = adapter->rss_queues;
fp@2685:
fp@2685: /* start with one vector for every Rx queue */
fp@2685: numvecs = adapter->num_rx_queues;
fp@2685:
fp@2685: /* if Tx handler is separate add 1 for every Tx queue */
fp@2685: if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
fp@2685: numvecs += adapter->num_tx_queues;
fp@2685:
fp@2685: /* store the number of vectors reserved for queues */
fp@2685: adapter->num_q_vectors = numvecs;
fp@2685:
fp@2685: /* add 1 vector for link status interrupts */
fp@2685: numvecs++;
fp@2685: for (i = 0; i < numvecs; i++)
fp@2685: adapter->msix_entries[i].entry = i;
fp@2685:
fp@2685: err = pci_enable_msix_range(adapter->pdev,
fp@2685: adapter->msix_entries,
fp@2685: numvecs,
fp@2685: numvecs);
fp@2685: if (err > 0)
fp@2685: return;
fp@2685:
fp@2685: igb_reset_interrupt_capability(adapter);
fp@2685:
fp@2685: /* If we can't do MSI-X, try MSI */
fp@2685: msi_only:
fp@2685: adapter->flags &= ~IGB_FLAG_HAS_MSIX;
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: /* disable SR-IOV for non MSI-X configurations */
fp@2685: if (adapter->vf_data) {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: /* disable iov and allow time for transactions to clear */
fp@2685: pci_disable_sriov(adapter->pdev);
fp@2685: msleep(500);
fp@2685:
fp@2685: kfree(adapter->vf_data);
fp@2685: adapter->vf_data = NULL;
fp@2685: wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
fp@2685: wrfl();
fp@2685: msleep(100);
fp@2685: dev_info(&adapter->pdev->dev, "IOV Disabled\n");
fp@2685: }
fp@2685: #endif
fp@2685: adapter->vfs_allocated_count = 0;
fp@2685: adapter->rss_queues = 1;
fp@2685: adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
fp@2685: adapter->num_rx_queues = 1;
fp@2685: adapter->num_tx_queues = 1;
fp@2685: adapter->num_q_vectors = 1;
fp@2685: if (!pci_enable_msi(adapter->pdev))
fp@2685: adapter->flags |= IGB_FLAG_HAS_MSI;
fp@2685: }
fp@2685:
fp@2685: static void igb_add_ring(struct igb_ring *ring,
fp@2685: struct igb_ring_container *head)
fp@2685: {
fp@2685: head->ring = ring;
fp@2685: head->count++;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_alloc_q_vector - Allocate memory for a single interrupt vector
fp@2685: * @adapter: board private structure to initialize
fp@2685: * @v_count: q_vectors allocated on adapter, used for ring interleaving
fp@2685: * @v_idx: index of vector in adapter struct
fp@2685: * @txr_count: total number of Tx rings to allocate
fp@2685: * @txr_idx: index of first Tx ring to allocate
fp@2685: * @rxr_count: total number of Rx rings to allocate
fp@2685: * @rxr_idx: index of first Rx ring to allocate
fp@2685: *
fp@2685: * We allocate one q_vector. If allocation fails we return -ENOMEM.
fp@2685: **/
fp@2685: static int igb_alloc_q_vector(struct igb_adapter *adapter,
fp@2685: int v_count, int v_idx,
fp@2685: int txr_count, int txr_idx,
fp@2685: int rxr_count, int rxr_idx)
fp@2685: {
fp@2685: struct igb_q_vector *q_vector;
fp@2685: struct igb_ring *ring;
fp@2685: int ring_count, size;
fp@2685:
fp@2685: /* igb only supports 1 Tx and/or 1 Rx queue per vector */
fp@2685: if (txr_count > 1 || rxr_count > 1)
fp@2685: return -ENOMEM;
fp@2685:
fp@2685: ring_count = txr_count + rxr_count;
fp@2685: size = sizeof(struct igb_q_vector) +
fp@2685: (sizeof(struct igb_ring) * ring_count);
fp@2685:
fp@2685: /* allocate q_vector and rings */
fp@2685: q_vector = adapter->q_vector[v_idx];
fp@2685: if (!q_vector)
fp@2685: q_vector = kzalloc(size, GFP_KERNEL);
fp@2685: if (!q_vector)
fp@2685: return -ENOMEM;
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: /* initialize NAPI */
fp@2686: netif_napi_add(adapter->netdev, &q_vector->napi,
fp@2686: igb_poll, 64);
fp@2686: }
fp@2685:
fp@2685: /* tie q_vector and adapter together */
fp@2685: adapter->q_vector[v_idx] = q_vector;
fp@2685: q_vector->adapter = adapter;
fp@2685:
fp@2685: /* initialize work limits */
fp@2685: q_vector->tx.work_limit = adapter->tx_work_limit;
fp@2685:
fp@2685: /* initialize ITR configuration */
fp@2685: q_vector->itr_register = adapter->hw.hw_addr + E1000_EITR(0);
fp@2685: q_vector->itr_val = IGB_START_ITR;
fp@2685:
fp@2685: /* initialize pointer to rings */
fp@2685: ring = q_vector->ring;
fp@2685:
fp@2685: /* intialize ITR */
fp@2685: if (rxr_count) {
fp@2685: /* rx or rx/tx vector */
fp@2685: if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
fp@2685: q_vector->itr_val = adapter->rx_itr_setting;
fp@2685: } else {
fp@2685: /* tx only vector */
fp@2685: if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
fp@2685: q_vector->itr_val = adapter->tx_itr_setting;
fp@2685: }
fp@2685:
fp@2685: if (txr_count) {
fp@2685: /* assign generic ring traits */
fp@2685: ring->dev = &adapter->pdev->dev;
fp@2685: ring->netdev = adapter->netdev;
fp@2685:
fp@2685: /* configure backlink on ring */
fp@2685: ring->q_vector = q_vector;
fp@2685:
fp@2685: /* update q_vector Tx values */
fp@2685: igb_add_ring(ring, &q_vector->tx);
fp@2685:
fp@2685: /* For 82575, context index must be unique per ring. */
fp@2685: if (adapter->hw.mac.type == e1000_82575)
fp@2685: set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
fp@2685:
fp@2685: /* apply Tx specific ring traits */
fp@2685: ring->count = adapter->tx_ring_count;
fp@2685: ring->queue_index = txr_idx;
fp@2685:
fp@2685: u64_stats_init(&ring->tx_syncp);
fp@2685: u64_stats_init(&ring->tx_syncp2);
fp@2685:
fp@2685: /* assign ring to adapter */
fp@2685: adapter->tx_ring[txr_idx] = ring;
fp@2685:
fp@2685: /* push pointer to next ring */
fp@2685: ring++;
fp@2685: }
fp@2685:
fp@2685: if (rxr_count) {
fp@2685: /* assign generic ring traits */
fp@2685: ring->dev = &adapter->pdev->dev;
fp@2685: ring->netdev = adapter->netdev;
fp@2685:
fp@2685: /* configure backlink on ring */
fp@2685: ring->q_vector = q_vector;
fp@2685:
fp@2685: /* update q_vector Rx values */
fp@2685: igb_add_ring(ring, &q_vector->rx);
fp@2685:
fp@2685: /* set flag indicating ring supports SCTP checksum offload */
fp@2685: if (adapter->hw.mac.type >= e1000_82576)
fp@2685: set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
fp@2685:
fp@2685: /* On i350, i354, i210, and i211, loopback VLAN packets
fp@2685: * have the tag byte-swapped.
fp@2685: */
fp@2685: if (adapter->hw.mac.type >= e1000_i350)
fp@2685: set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
fp@2685:
fp@2685: /* apply Rx specific ring traits */
fp@2685: ring->count = adapter->rx_ring_count;
fp@2685: ring->queue_index = rxr_idx;
fp@2685:
fp@2685: u64_stats_init(&ring->rx_syncp);
fp@2685:
fp@2685: /* assign ring to adapter */
fp@2685: adapter->rx_ring[rxr_idx] = ring;
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685:
fp@2685: /**
fp@2685: * igb_alloc_q_vectors - Allocate memory for interrupt vectors
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * We allocate one q_vector per queue interrupt. If allocation fails we
fp@2685: * return -ENOMEM.
fp@2685: **/
fp@2685: static int igb_alloc_q_vectors(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int q_vectors = adapter->num_q_vectors;
fp@2685: int rxr_remaining = adapter->num_rx_queues;
fp@2685: int txr_remaining = adapter->num_tx_queues;
fp@2685: int rxr_idx = 0, txr_idx = 0, v_idx = 0;
fp@2685: int err;
fp@2685:
fp@2685: if (q_vectors >= (rxr_remaining + txr_remaining)) {
fp@2685: for (; rxr_remaining; v_idx++) {
fp@2685: err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
fp@2685: 0, 0, 1, rxr_idx);
fp@2685:
fp@2685: if (err)
fp@2685: goto err_out;
fp@2685:
fp@2685: /* update counts and index */
fp@2685: rxr_remaining--;
fp@2685: rxr_idx++;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: for (; v_idx < q_vectors; v_idx++) {
fp@2685: int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
fp@2685: int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
fp@2685:
fp@2685: err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
fp@2685: tqpv, txr_idx, rqpv, rxr_idx);
fp@2685:
fp@2685: if (err)
fp@2685: goto err_out;
fp@2685:
fp@2685: /* update counts and index */
fp@2685: rxr_remaining -= rqpv;
fp@2685: txr_remaining -= tqpv;
fp@2685: rxr_idx++;
fp@2685: txr_idx++;
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err_out:
fp@2685: adapter->num_tx_queues = 0;
fp@2685: adapter->num_rx_queues = 0;
fp@2685: adapter->num_q_vectors = 0;
fp@2685:
fp@2685: while (v_idx--)
fp@2685: igb_free_q_vector(adapter, v_idx);
fp@2685:
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
fp@2685: * @adapter: board private structure to initialize
fp@2685: * @msix: boolean value of MSIX capability
fp@2685: *
fp@2685: * This function initializes the interrupts and allocates all of the queues.
fp@2685: **/
fp@2685: static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int err;
fp@2685:
fp@2685: igb_set_interrupt_capability(adapter, msix);
fp@2685:
fp@2685: err = igb_alloc_q_vectors(adapter);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
fp@2685: goto err_alloc_q_vectors;
fp@2685: }
fp@2685:
fp@2685: igb_cache_ring_register(adapter);
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err_alloc_q_vectors:
fp@2685: igb_reset_interrupt_capability(adapter);
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_request_irq - initialize interrupts
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * Attempts to configure interrupts using the best available
fp@2685: * capabilities of the hardware and kernel.
fp@2685: **/
fp@2685: static int igb_request_irq(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int err = 0;
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: err = igb_request_msix(adapter);
fp@2685: if (!err)
fp@2685: goto request_done;
fp@2685: /* fall back to MSI */
fp@2685: igb_free_all_tx_resources(adapter);
fp@2685: igb_free_all_rx_resources(adapter);
fp@2685:
fp@2685: igb_clear_interrupt_scheme(adapter);
fp@2685: err = igb_init_interrupt_scheme(adapter, false);
fp@2685: if (err)
fp@2685: goto request_done;
fp@2685:
fp@2685: igb_setup_all_tx_resources(adapter);
fp@2685: igb_setup_all_rx_resources(adapter);
fp@2685: igb_configure(adapter);
fp@2685: }
fp@2685:
fp@2685: igb_assign_vector(adapter->q_vector[0], 0);
fp@2685:
fp@2686: if (!adapter->ecdev && adapter->flags & IGB_FLAG_HAS_MSI) {
fp@2685: err = request_irq(pdev->irq, igb_intr_msi, 0,
fp@2685: netdev->name, adapter);
fp@2685: if (!err)
fp@2685: goto request_done;
fp@2685:
fp@2685: /* fall back to legacy interrupts */
fp@2685: igb_reset_interrupt_capability(adapter);
fp@2685: adapter->flags &= ~IGB_FLAG_HAS_MSI;
fp@2685: }
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
fp@2686: netdev->name, adapter);
fp@2686:
fp@2686: if (err)
fp@2686: dev_err(&pdev->dev, "Error %d getting interrupt\n",
fp@2686: err);
fp@2686: }
fp@2685:
fp@2685: request_done:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static void igb_free_irq(struct igb_adapter *adapter)
fp@2685: {
fp@2686: if (adapter->ecdev) {
fp@2686: /* no IRQ to free in EtherCAT operation */
fp@2686: return;
fp@2686: }
fp@2686:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: int vector = 0, i;
fp@2685:
fp@2685: free_irq(adapter->msix_entries[vector++].vector, adapter);
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2685: free_irq(adapter->msix_entries[vector++].vector,
fp@2685: adapter->q_vector[i]);
fp@2685: } else {
fp@2685: free_irq(adapter->pdev->irq, adapter);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_irq_disable - Mask off interrupt generation on the NIC
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: static void igb_irq_disable(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* we need to be careful when disabling interrupts. The VFs are also
fp@2685: * mapped into these registers and so clearing the bits can cause
fp@2685: * issues on the VF drivers so we only need to clear what we set
fp@2685: */
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: u32 regval = rd32(E1000_EIAM);
fp@2685:
fp@2685: wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
fp@2685: wr32(E1000_EIMC, adapter->eims_enable_mask);
fp@2685: regval = rd32(E1000_EIAC);
fp@2685: wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_IAM, 0);
fp@2685: wr32(E1000_IMC, ~0);
fp@2685: wrfl();
fp@2686:
fp@2686: if (adapter->ecdev) {
fp@2686: /* skip synchonizing IRQs */
fp@2686: return;
fp@2686: }
fp@2686:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2685: synchronize_irq(adapter->msix_entries[i].vector);
fp@2685: } else {
fp@2685: synchronize_irq(adapter->pdev->irq);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_irq_enable - Enable default interrupt generation settings
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: static void igb_irq_enable(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: /* skip enabling interrupts */
fp@2686: return;
fp@2686: }
fp@2686:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
fp@2685: u32 regval = rd32(E1000_EIAC);
fp@2685:
fp@2685: wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
fp@2685: regval = rd32(E1000_EIAM);
fp@2685: wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
fp@2685: wr32(E1000_EIMS, adapter->eims_enable_mask);
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: wr32(E1000_MBVFIMR, 0xFF);
fp@2685: ims |= E1000_IMS_VMMB;
fp@2685: }
fp@2685: wr32(E1000_IMS, ims);
fp@2685: } else {
fp@2685: wr32(E1000_IMS, IMS_ENABLE_MASK |
fp@2685: E1000_IMS_DRSTA);
fp@2685: wr32(E1000_IAM, IMS_ENABLE_MASK |
fp@2685: E1000_IMS_DRSTA);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_update_mng_vlan(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u16 vid = adapter->hw.mng_cookie.vlan_id;
fp@2685: u16 old_vid = adapter->mng_vlan_id;
fp@2685:
fp@2685: if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
fp@2685: /* add VID to filter table */
fp@2685: igb_vfta_set(hw, vid, true);
fp@2685: adapter->mng_vlan_id = vid;
fp@2685: } else {
fp@2685: adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
fp@2685: }
fp@2685:
fp@2685: if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
fp@2685: (vid != old_vid) &&
fp@2685: !test_bit(old_vid, adapter->active_vlans)) {
fp@2685: /* remove VID from filter table */
fp@2685: igb_vfta_set(hw, old_vid, false);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_release_hw_control - release control of the h/w to f/w
fp@2685: * @adapter: address of board private structure
fp@2685: *
fp@2685: * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
fp@2685: * For ASF and Pass Through versions of f/w this means that the
fp@2685: * driver is no longer loaded.
fp@2685: **/
fp@2685: static void igb_release_hw_control(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ctrl_ext;
fp@2685:
fp@2685: /* Let firmware take over control of h/w */
fp@2685: ctrl_ext = rd32(E1000_CTRL_EXT);
fp@2685: wr32(E1000_CTRL_EXT,
fp@2685: ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_get_hw_control - get control of the h/w from f/w
fp@2685: * @adapter: address of board private structure
fp@2685: *
fp@2685: * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
fp@2685: * For ASF and Pass Through versions of f/w this means that
fp@2685: * the driver is loaded.
fp@2685: **/
fp@2685: static void igb_get_hw_control(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ctrl_ext;
fp@2685:
fp@2685: /* Let firmware know the driver has taken over */
fp@2685: ctrl_ext = rd32(E1000_CTRL_EXT);
fp@2685: wr32(E1000_CTRL_EXT,
fp@2685: ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure - configure the hardware for RX and TX
fp@2685: * @adapter: private board structure
fp@2685: **/
fp@2685: static void igb_configure(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: int i;
fp@2685:
fp@2685: igb_get_hw_control(adapter);
fp@2685: igb_set_rx_mode(netdev);
fp@2685:
fp@2685: igb_restore_vlan(adapter);
fp@2685:
fp@2685: igb_setup_tctl(adapter);
fp@2685: igb_setup_mrqc(adapter);
fp@2685: igb_setup_rctl(adapter);
fp@2685:
fp@2685: igb_configure_tx(adapter);
fp@2685: igb_configure_rx(adapter);
fp@2685:
fp@2685: igb_rx_fifo_flush_82575(&adapter->hw);
fp@2685:
fp@2685: /* call igb_desc_unused which always leaves
fp@2685: * at least 1 descriptor unused to make sure
fp@2685: * next_to_use != next_to_clean
fp@2685: */
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++) {
fp@2685: struct igb_ring *ring = adapter->rx_ring[i];
fp@2685: igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_power_up_link - Power up the phy/serdes link
fp@2685: * @adapter: address of board private structure
fp@2685: **/
fp@2685: void igb_power_up_link(struct igb_adapter *adapter)
fp@2685: {
fp@2685: igb_reset_phy(&adapter->hw);
fp@2685:
fp@2685: if (adapter->hw.phy.media_type == e1000_media_type_copper)
fp@2685: igb_power_up_phy_copper(&adapter->hw);
fp@2685: else
fp@2685: igb_power_up_serdes_link_82575(&adapter->hw);
fp@2685:
fp@2685: igb_setup_link(&adapter->hw);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_power_down_link - Power down the phy/serdes link
fp@2685: * @adapter: address of board private structure
fp@2685: */
fp@2685: static void igb_power_down_link(struct igb_adapter *adapter)
fp@2685: {
fp@2685: if (adapter->hw.phy.media_type == e1000_media_type_copper)
fp@2685: igb_power_down_phy_copper_82575(&adapter->hw);
fp@2685: else
fp@2685: igb_shutdown_serdes_link_82575(&adapter->hw);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * Detect and switch function for Media Auto Sense
fp@2685: * @adapter: address of the board private structure
fp@2685: **/
fp@2685: static void igb_check_swap_media(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ctrl_ext, connsw;
fp@2685: bool swap_now = false;
fp@2685:
fp@2685: ctrl_ext = rd32(E1000_CTRL_EXT);
fp@2685: connsw = rd32(E1000_CONNSW);
fp@2685:
fp@2685: /* need to live swap if current media is copper and we have fiber/serdes
fp@2685: * to go to.
fp@2685: */
fp@2685:
fp@2685: if ((hw->phy.media_type == e1000_media_type_copper) &&
fp@2685: (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
fp@2685: swap_now = true;
fp@2685: } else if (!(connsw & E1000_CONNSW_SERDESD)) {
fp@2685: /* copper signal takes time to appear */
fp@2685: if (adapter->copper_tries < 4) {
fp@2685: adapter->copper_tries++;
fp@2685: connsw |= E1000_CONNSW_AUTOSENSE_CONF;
fp@2685: wr32(E1000_CONNSW, connsw);
fp@2685: return;
fp@2685: } else {
fp@2685: adapter->copper_tries = 0;
fp@2685: if ((connsw & E1000_CONNSW_PHYSD) &&
fp@2685: (!(connsw & E1000_CONNSW_PHY_PDN))) {
fp@2685: swap_now = true;
fp@2685: connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
fp@2685: wr32(E1000_CONNSW, connsw);
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: if (!swap_now)
fp@2685: return;
fp@2685:
fp@2685: switch (hw->phy.media_type) {
fp@2685: case e1000_media_type_copper:
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: changing media to fiber/serdes\n");
fp@2685: ctrl_ext |=
fp@2685: E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
fp@2685: adapter->flags |= IGB_FLAG_MEDIA_RESET;
fp@2685: adapter->copper_tries = 0;
fp@2685: break;
fp@2685: case e1000_media_type_internal_serdes:
fp@2685: case e1000_media_type_fiber:
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: changing media to copper\n");
fp@2685: ctrl_ext &=
fp@2685: ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
fp@2685: adapter->flags |= IGB_FLAG_MEDIA_RESET;
fp@2685: break;
fp@2685: default:
fp@2685: /* shouldn't get here during regular operation */
fp@2685: netdev_err(adapter->netdev,
fp@2685: "AMS: Invalid media type found, returning\n");
fp@2685: break;
fp@2685: }
fp@2685: wr32(E1000_CTRL_EXT, ctrl_ext);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_up - Open the interface and prepare it to handle traffic
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: int igb_up(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int i;
fp@2685:
fp@2685: /* hardware has been reset, we need to reload some things */
fp@2685: igb_configure(adapter);
fp@2685:
fp@2685: clear_bit(__IGB_DOWN, &adapter->state);
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2686: napi_enable(&(adapter->q_vector[i]->napi));
fp@2686: }
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX)
fp@2685: igb_configure_msix(adapter);
fp@2685: else
fp@2685: igb_assign_vector(adapter->q_vector[0], 0);
fp@2685:
fp@2685: /* Clear any pending interrupts. */
fp@2685: rd32(E1000_ICR);
fp@2685: igb_irq_enable(adapter);
fp@2685:
fp@2685: /* notify VFs that reset has been completed */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: u32 reg_data = rd32(E1000_CTRL_EXT);
fp@2685:
fp@2685: reg_data |= E1000_CTRL_EXT_PFRSTD;
fp@2685: wr32(E1000_CTRL_EXT, reg_data);
fp@2685: }
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_tx_start_all_queues(adapter->netdev);
fp@2686:
fp@2686: /* start the watchdog. */
fp@2686: hw->mac.get_link_status = 1;
fp@2686: schedule_work(&adapter->watchdog_task);
fp@2686: }
fp@2685:
fp@2685: if ((adapter->flags & IGB_FLAG_EEE) &&
fp@2685: (!hw->dev_spec._82575.eee_disable))
fp@2685: adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: void igb_down(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 tctl, rctl;
fp@2685: int i;
fp@2685:
fp@2685: /* signal that we're down so the interrupt handler does not
fp@2685: * reschedule our watchdog timer
fp@2685: */
fp@2685: set_bit(__IGB_DOWN, &adapter->state);
fp@2685:
fp@2685: /* disable receives in the hardware */
fp@2685: rctl = rd32(E1000_RCTL);
fp@2685: wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
fp@2685: /* flush and sleep below */
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_tx_stop_all_queues(netdev);
fp@2686: }
fp@2685:
fp@2685: /* disable transmits in the hardware */
fp@2685: tctl = rd32(E1000_TCTL);
fp@2685: tctl &= ~E1000_TCTL_EN;
fp@2685: wr32(E1000_TCTL, tctl);
fp@2685: /* flush both disables and wait for them to finish */
fp@2685: wrfl();
fp@2685: usleep_range(10000, 11000);
fp@2685:
fp@2685: igb_irq_disable(adapter);
fp@2685:
fp@2685: adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++) {
fp@2686: if (!adapter->ecdev && adapter->q_vector[i]) {
fp@2685: napi_synchronize(&adapter->q_vector[i]->napi);
fp@2685: napi_disable(&adapter->q_vector[i]->napi);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685:
fp@2685: del_timer_sync(&adapter->watchdog_timer);
fp@2685: del_timer_sync(&adapter->phy_info_timer);
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_carrier_off(netdev);
fp@2686: }
fp@2685:
fp@2685: /* record the stats before reset*/
fp@2685: spin_lock(&adapter->stats64_lock);
fp@2685: igb_update_stats(adapter, &adapter->stats64);
fp@2685: spin_unlock(&adapter->stats64_lock);
fp@2685:
fp@2685: adapter->link_speed = 0;
fp@2685: adapter->link_duplex = 0;
fp@2685:
fp@2685: if (!pci_channel_offline(adapter->pdev))
fp@2685: igb_reset(adapter);
fp@2685: igb_clean_all_tx_rings(adapter);
fp@2685: igb_clean_all_rx_rings(adapter);
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685:
fp@2685: /* since we reset the hardware DCA settings were cleared */
fp@2685: igb_setup_dca(adapter);
fp@2685: #endif
fp@2685: }
fp@2685:
fp@2685: void igb_reinit_locked(struct igb_adapter *adapter)
fp@2685: {
fp@2685: WARN_ON(in_interrupt());
fp@2685: while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
fp@2685: usleep_range(1000, 2000);
fp@2685: igb_down(adapter);
fp@2685: igb_up(adapter);
fp@2685: clear_bit(__IGB_RESETTING, &adapter->state);
fp@2685: }
fp@2685:
fp@2685: /** igb_enable_mas - Media Autosense re-enable after swap
fp@2685: *
fp@2685: * @adapter: adapter struct
fp@2685: **/
fp@2685: static s32 igb_enable_mas(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 connsw;
fp@2685: s32 ret_val = 0;
fp@2685:
fp@2685: connsw = rd32(E1000_CONNSW);
fp@2685: if (!(hw->phy.media_type == e1000_media_type_copper))
fp@2685: return ret_val;
fp@2685:
fp@2685: /* configure for SerDes media detect */
fp@2685: if (!(connsw & E1000_CONNSW_SERDESD)) {
fp@2685: connsw |= E1000_CONNSW_ENRGSRC;
fp@2685: connsw |= E1000_CONNSW_AUTOSENSE_EN;
fp@2685: wr32(E1000_CONNSW, connsw);
fp@2685: wrfl();
fp@2685: } else if (connsw & E1000_CONNSW_SERDESD) {
fp@2685: /* already SerDes, no need to enable anything */
fp@2685: return ret_val;
fp@2685: } else {
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: Unable to configure feature, disabling..\n");
fp@2685: adapter->flags &= ~IGB_FLAG_MAS_ENABLE;
fp@2685: }
fp@2685: return ret_val;
fp@2685: }
fp@2685:
fp@2685: void igb_reset(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct e1000_mac_info *mac = &hw->mac;
fp@2685: struct e1000_fc_info *fc = &hw->fc;
fp@2685: u32 pba = 0, tx_space, min_tx_space, min_rx_space, hwm;
fp@2685:
fp@2685: /* Repartition Pba for greater than 9k mtu
fp@2685: * To take effect CTRL.RST is required.
fp@2685: */
fp@2685: switch (mac->type) {
fp@2685: case e1000_i350:
fp@2685: case e1000_i354:
fp@2685: case e1000_82580:
fp@2685: pba = rd32(E1000_RXPBS);
fp@2685: pba = igb_rxpbs_adjust_82580(pba);
fp@2685: break;
fp@2685: case e1000_82576:
fp@2685: pba = rd32(E1000_RXPBS);
fp@2685: pba &= E1000_RXPBS_SIZE_MASK_82576;
fp@2685: break;
fp@2685: case e1000_82575:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: default:
fp@2685: pba = E1000_PBA_34K;
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
fp@2685: (mac->type < e1000_82576)) {
fp@2685: /* adjust PBA for jumbo frames */
fp@2685: wr32(E1000_PBA, pba);
fp@2685:
fp@2685: /* To maintain wire speed transmits, the Tx FIFO should be
fp@2685: * large enough to accommodate two full transmit packets,
fp@2685: * rounded up to the next 1KB and expressed in KB. Likewise,
fp@2685: * the Rx FIFO should be large enough to accommodate at least
fp@2685: * one full receive packet and is similarly rounded up and
fp@2685: * expressed in KB.
fp@2685: */
fp@2685: pba = rd32(E1000_PBA);
fp@2685: /* upper 16 bits has Tx packet buffer allocation size in KB */
fp@2685: tx_space = pba >> 16;
fp@2685: /* lower 16 bits has Rx packet buffer allocation size in KB */
fp@2685: pba &= 0xffff;
fp@2685: /* the Tx fifo also stores 16 bytes of information about the Tx
fp@2685: * but don't include ethernet FCS because hardware appends it
fp@2685: */
fp@2685: min_tx_space = (adapter->max_frame_size +
fp@2685: sizeof(union e1000_adv_tx_desc) -
fp@2685: ETH_FCS_LEN) * 2;
fp@2685: min_tx_space = ALIGN(min_tx_space, 1024);
fp@2685: min_tx_space >>= 10;
fp@2685: /* software strips receive CRC, so leave room for it */
fp@2685: min_rx_space = adapter->max_frame_size;
fp@2685: min_rx_space = ALIGN(min_rx_space, 1024);
fp@2685: min_rx_space >>= 10;
fp@2685:
fp@2685: /* If current Tx allocation is less than the min Tx FIFO size,
fp@2685: * and the min Tx FIFO size is less than the current Rx FIFO
fp@2685: * allocation, take space away from current Rx allocation
fp@2685: */
fp@2685: if (tx_space < min_tx_space &&
fp@2685: ((min_tx_space - tx_space) < pba)) {
fp@2685: pba = pba - (min_tx_space - tx_space);
fp@2685:
fp@2685: /* if short on Rx space, Rx wins and must trump Tx
fp@2685: * adjustment
fp@2685: */
fp@2685: if (pba < min_rx_space)
fp@2685: pba = min_rx_space;
fp@2685: }
fp@2685: wr32(E1000_PBA, pba);
fp@2685: }
fp@2685:
fp@2685: /* flow control settings */
fp@2685: /* The high water mark must be low enough to fit one full frame
fp@2685: * (or the size used for early receive) above it in the Rx FIFO.
fp@2685: * Set it to the lower of:
fp@2685: * - 90% of the Rx FIFO size, or
fp@2685: * - the full Rx FIFO size minus one full frame
fp@2685: */
fp@2685: hwm = min(((pba << 10) * 9 / 10),
fp@2685: ((pba << 10) - 2 * adapter->max_frame_size));
fp@2685:
fp@2685: fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
fp@2685: fc->low_water = fc->high_water - 16;
fp@2685: fc->pause_time = 0xFFFF;
fp@2685: fc->send_xon = 1;
fp@2685: fc->current_mode = fc->requested_mode;
fp@2685:
fp@2685: /* disable receive for all VFs and wait one second */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0 ; i < adapter->vfs_allocated_count; i++)
fp@2685: adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
fp@2685:
fp@2685: /* ping all the active vfs to let them know we are going down */
fp@2685: igb_ping_all_vfs(adapter);
fp@2685:
fp@2685: /* disable transmits and receives */
fp@2685: wr32(E1000_VFRE, 0);
fp@2685: wr32(E1000_VFTE, 0);
fp@2685: }
fp@2685:
fp@2685: /* Allow time for pending master requests to run */
fp@2685: hw->mac.ops.reset_hw(hw);
fp@2685: wr32(E1000_WUC, 0);
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
fp@2685: /* need to resetup here after media swap */
fp@2685: adapter->ei.get_invariants(hw);
fp@2685: adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
fp@2685: }
fp@2685: if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
fp@2685: if (igb_enable_mas(adapter))
fp@2685: dev_err(&pdev->dev,
fp@2685: "Error enabling Media Auto Sense\n");
fp@2685: }
fp@2685: if (hw->mac.ops.init_hw(hw))
fp@2685: dev_err(&pdev->dev, "Hardware Error\n");
fp@2685:
fp@2685: /* Flow control settings reset on hardware reset, so guarantee flow
fp@2685: * control is off when forcing speed.
fp@2685: */
fp@2685: if (!hw->mac.autoneg)
fp@2685: igb_force_mac_fc(hw);
fp@2685:
fp@2685: igb_init_dmac(adapter, pba);
fp@2685: #ifdef CONFIG_IGB_HWMON
fp@2685: /* Re-initialize the thermal sensor on i350 devices. */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state)) {
fp@2685: if (mac->type == e1000_i350 && hw->bus.func == 0) {
fp@2685: /* If present, re-initialize the external thermal sensor
fp@2685: * interface.
fp@2685: */
fp@2685: if (adapter->ets)
fp@2685: mac->ops.init_thermal_sensor_thresh(hw);
fp@2685: }
fp@2685: }
fp@2685: #endif
fp@2685: /* Re-establish EEE setting */
fp@2685: if (hw->phy.media_type == e1000_media_type_copper) {
fp@2685: switch (mac->type) {
fp@2685: case e1000_i350:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: igb_set_eee_i350(hw, true, true);
fp@2685: break;
fp@2685: case e1000_i354:
fp@2685: igb_set_eee_i354(hw, true, true);
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2686: if (!adapter->ecdev && !netif_running(adapter->netdev))
fp@2685: igb_power_down_link(adapter);
fp@2685:
fp@2685: igb_update_mng_vlan(adapter);
fp@2685:
fp@2685: /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
fp@2685: wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
fp@2685:
fp@2685: /* Re-enable PTP, where applicable. */
fp@2685: igb_ptp_reset(adapter);
fp@2685:
fp@2685: igb_get_phy_info(hw);
fp@2685: }
fp@2685:
fp@2685: static netdev_features_t igb_fix_features(struct net_device *netdev,
fp@2685: netdev_features_t features)
fp@2685: {
fp@2685: /* Since there is no support for separate Rx/Tx vlan accel
fp@2685: * enable/disable make sure Tx flag is always in same state as Rx.
fp@2685: */
fp@2685: if (features & NETIF_F_HW_VLAN_CTAG_RX)
fp@2685: features |= NETIF_F_HW_VLAN_CTAG_TX;
fp@2685: else
fp@2685: features &= ~NETIF_F_HW_VLAN_CTAG_TX;
fp@2685:
fp@2685: return features;
fp@2685: }
fp@2685:
fp@2685: static int igb_set_features(struct net_device *netdev,
fp@2685: netdev_features_t features)
fp@2685: {
fp@2685: netdev_features_t changed = netdev->features ^ features;
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: if (changed & NETIF_F_HW_VLAN_CTAG_RX)
fp@2685: igb_vlan_mode(netdev, features);
fp@2685:
fp@2685: if (!(changed & NETIF_F_RXALL))
fp@2685: return 0;
fp@2685:
fp@2685: netdev->features = features;
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_reinit_locked(adapter);
fp@2685: else
fp@2685: igb_reset(adapter);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static const struct net_device_ops igb_netdev_ops = {
fp@2685: .ndo_open = igb_open,
fp@2685: .ndo_stop = igb_close,
fp@2685: .ndo_start_xmit = igb_xmit_frame,
fp@2685: .ndo_get_stats64 = igb_get_stats64,
fp@2685: .ndo_set_rx_mode = igb_set_rx_mode,
fp@2685: .ndo_set_mac_address = igb_set_mac,
fp@2685: .ndo_change_mtu = igb_change_mtu,
fp@2685: .ndo_do_ioctl = igb_ioctl,
fp@2685: .ndo_tx_timeout = igb_tx_timeout,
fp@2685: .ndo_validate_addr = eth_validate_addr,
fp@2685: .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
fp@2685: .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
fp@2685: .ndo_set_vf_mac = igb_ndo_set_vf_mac,
fp@2685: .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
fp@2685: .ndo_set_vf_rate = igb_ndo_set_vf_bw,
fp@2685: .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
fp@2685: .ndo_get_vf_config = igb_ndo_get_vf_config,
fp@2685: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@2685: .ndo_poll_controller = igb_netpoll,
fp@2685: #endif
fp@2685: .ndo_fix_features = igb_fix_features,
fp@2685: .ndo_set_features = igb_set_features,
fp@2685: };
fp@2685:
fp@2685: /**
fp@2686: * ec_poll - EtherCAT poll routine
fp@2686: * @netdev: net device structure
fp@2686: *
fp@2686: * This function can never fail.
fp@2686: *
fp@2686: **/
fp@2686: void ec_poll(struct net_device *netdev)
fp@2686: {
fp@2686: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2686: int i;
fp@2686: int budget = 64;
fp@2686:
fp@2686: if (jiffies - adapter->ec_watchdog_jiffies >= 2 * HZ) {
fp@2686: struct e1000_hw *hw = &adapter->hw;
fp@2686: bool link;
fp@2686: hw->mac.get_link_status = true;
fp@2686: link = igb_has_link(adapter);
fp@2686: ecdev_set_link(adapter->ecdev, link);
fp@2686: adapter->ec_watchdog_jiffies = jiffies;
fp@2686: }
fp@2686:
fp@2686: for (i = 0; i < adapter->num_q_vectors; i++) {
fp@2686: struct igb_q_vector *q_vector = adapter->q_vector[i];
fp@2686: if (q_vector->tx.ring) {
fp@2686: igb_clean_tx_irq(q_vector);
fp@2686: }
fp@2686:
fp@2686: if (q_vector->rx.ring) {
fp@2686: igb_clean_rx_irq(q_vector, budget);
fp@2686: }
fp@2686: }
fp@2686: }
fp@2686:
fp@2686: /**
fp@2685: * igb_set_fw_version - Configure version string for ethtool
fp@2685: * @adapter: adapter struct
fp@2685: **/
fp@2685: void igb_set_fw_version(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct e1000_fw_version fw;
fp@2685:
fp@2685: igb_get_fw_version(hw, &fw);
fp@2685:
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: if (!(igb_get_flash_presence_i210(hw))) {
fp@2685: snprintf(adapter->fw_version,
fp@2685: sizeof(adapter->fw_version),
fp@2685: "%2d.%2d-%d",
fp@2685: fw.invm_major, fw.invm_minor,
fp@2685: fw.invm_img_type);
fp@2685: break;
fp@2685: }
fp@2685: /* fall through */
fp@2685: default:
fp@2685: /* if option is rom valid, display its version too */
fp@2685: if (fw.or_valid) {
fp@2685: snprintf(adapter->fw_version,
fp@2685: sizeof(adapter->fw_version),
fp@2685: "%d.%d, 0x%08x, %d.%d.%d",
fp@2685: fw.eep_major, fw.eep_minor, fw.etrack_id,
fp@2685: fw.or_major, fw.or_build, fw.or_patch);
fp@2685: /* no option rom */
fp@2685: } else if (fw.etrack_id != 0X0000) {
fp@2685: snprintf(adapter->fw_version,
fp@2685: sizeof(adapter->fw_version),
fp@2685: "%d.%d, 0x%08x",
fp@2685: fw.eep_major, fw.eep_minor, fw.etrack_id);
fp@2685: } else {
fp@2685: snprintf(adapter->fw_version,
fp@2685: sizeof(adapter->fw_version),
fp@2685: "%d.%d.%d",
fp@2685: fw.eep_major, fw.eep_minor, fw.eep_build);
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_init_mas - init Media Autosense feature if enabled in the NVM
fp@2685: *
fp@2685: * @adapter: adapter struct
fp@2685: **/
fp@2685: static void igb_init_mas(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u16 eeprom_data;
fp@2685:
fp@2685: hw->nvm.ops.read(hw, NVM_COMPAT, 1, &eeprom_data);
fp@2685: switch (hw->bus.func) {
fp@2685: case E1000_FUNC_0:
fp@2685: if (eeprom_data & IGB_MAS_ENABLE_0) {
fp@2685: adapter->flags |= IGB_FLAG_MAS_ENABLE;
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: Enabling Media Autosense for port %d\n",
fp@2685: hw->bus.func);
fp@2685: }
fp@2685: break;
fp@2685: case E1000_FUNC_1:
fp@2685: if (eeprom_data & IGB_MAS_ENABLE_1) {
fp@2685: adapter->flags |= IGB_FLAG_MAS_ENABLE;
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: Enabling Media Autosense for port %d\n",
fp@2685: hw->bus.func);
fp@2685: }
fp@2685: break;
fp@2685: case E1000_FUNC_2:
fp@2685: if (eeprom_data & IGB_MAS_ENABLE_2) {
fp@2685: adapter->flags |= IGB_FLAG_MAS_ENABLE;
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: Enabling Media Autosense for port %d\n",
fp@2685: hw->bus.func);
fp@2685: }
fp@2685: break;
fp@2685: case E1000_FUNC_3:
fp@2685: if (eeprom_data & IGB_MAS_ENABLE_3) {
fp@2685: adapter->flags |= IGB_FLAG_MAS_ENABLE;
fp@2685: netdev_info(adapter->netdev,
fp@2685: "MAS: Enabling Media Autosense for port %d\n",
fp@2685: hw->bus.func);
fp@2685: }
fp@2685: break;
fp@2685: default:
fp@2685: /* Shouldn't get here */
fp@2685: netdev_err(adapter->netdev,
fp@2685: "MAS: Invalid port configuration, returning\n");
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_init_i2c - Init I2C interface
fp@2685: * @adapter: pointer to adapter structure
fp@2685: **/
fp@2685: static s32 igb_init_i2c(struct igb_adapter *adapter)
fp@2685: {
fp@2685: s32 status = 0;
fp@2685:
fp@2685: /* I2C interface supported on i350 devices */
fp@2685: if (adapter->hw.mac.type != e1000_i350)
fp@2685: return 0;
fp@2685:
fp@2685: /* Initialize the i2c bus which is controlled by the registers.
fp@2685: * This bus will use the i2c_algo_bit structue that implements
fp@2685: * the protocol through toggling of the 4 bits in the register.
fp@2685: */
fp@2685: adapter->i2c_adap.owner = THIS_MODULE;
fp@2685: adapter->i2c_algo = igb_i2c_algo;
fp@2685: adapter->i2c_algo.data = adapter;
fp@2685: adapter->i2c_adap.algo_data = &adapter->i2c_algo;
fp@2685: adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
fp@2685: strlcpy(adapter->i2c_adap.name, "igb BB",
fp@2685: sizeof(adapter->i2c_adap.name));
fp@2685: status = i2c_bit_add_bus(&adapter->i2c_adap);
fp@2685: return status;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_probe - Device Initialization Routine
fp@2685: * @pdev: PCI device information struct
fp@2685: * @ent: entry in igb_pci_tbl
fp@2685: *
fp@2685: * Returns 0 on success, negative on failure
fp@2685: *
fp@2685: * igb_probe initializes an adapter identified by a pci_dev structure.
fp@2685: * The OS initialization, configuring of the adapter private structure,
fp@2685: * and a hardware reset occur.
fp@2685: **/
fp@2685: static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
fp@2685: {
fp@2685: struct net_device *netdev;
fp@2685: struct igb_adapter *adapter;
fp@2685: struct e1000_hw *hw;
fp@2685: u16 eeprom_data = 0;
fp@2685: s32 ret_val;
fp@2685: static int global_quad_port_a; /* global quad port a indication */
fp@2685: const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
fp@2685: int err, pci_using_dac;
fp@2685: u8 part_str[E1000_PBANUM_LENGTH];
fp@2685:
fp@2685: /* Catch broken hardware that put the wrong VF device ID in
fp@2685: * the PCIe SR-IOV capability.
fp@2685: */
fp@2685: if (pdev->is_virtfn) {
fp@2685: WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
fp@2685: pci_name(pdev), pdev->vendor, pdev->device);
fp@2685: return -EINVAL;
fp@2685: }
fp@2685:
fp@2685: err = pci_enable_device_mem(pdev);
fp@2685: if (err)
fp@2685: return err;
fp@2685:
fp@2685: pci_using_dac = 0;
fp@2685: err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
fp@2685: if (!err) {
fp@2685: pci_using_dac = 1;
fp@2685: } else {
fp@2685: err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "No usable DMA configuration, aborting\n");
fp@2685: goto err_dma;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
fp@2685: IORESOURCE_MEM),
fp@2685: igb_driver_name);
fp@2685: if (err)
fp@2685: goto err_pci_reg;
fp@2685:
fp@2685: pci_enable_pcie_error_reporting(pdev);
fp@2685:
fp@2685: pci_set_master(pdev);
fp@2685: pci_save_state(pdev);
fp@2685:
fp@2685: err = -ENOMEM;
fp@2685: netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
fp@2685: IGB_MAX_TX_QUEUES);
fp@2685: if (!netdev)
fp@2685: goto err_alloc_etherdev;
fp@2685:
fp@2685: SET_NETDEV_DEV(netdev, &pdev->dev);
fp@2685:
fp@2685: pci_set_drvdata(pdev, netdev);
fp@2685: adapter = netdev_priv(netdev);
fp@2685: adapter->netdev = netdev;
fp@2685: adapter->pdev = pdev;
fp@2685: hw = &adapter->hw;
fp@2685: hw->back = adapter;
fp@2685: adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
fp@2685:
fp@2685: err = -EIO;
fp@2685: hw->hw_addr = pci_iomap(pdev, 0, 0);
fp@2685: if (!hw->hw_addr)
fp@2685: goto err_ioremap;
fp@2685:
fp@2685: netdev->netdev_ops = &igb_netdev_ops;
fp@2685: igb_set_ethtool_ops(netdev);
fp@2685: netdev->watchdog_timeo = 5 * HZ;
fp@2685:
fp@2685: strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
fp@2685:
fp@2685: netdev->mem_start = pci_resource_start(pdev, 0);
fp@2685: netdev->mem_end = pci_resource_end(pdev, 0);
fp@2685:
fp@2685: /* PCI config space info */
fp@2685: hw->vendor_id = pdev->vendor;
fp@2685: hw->device_id = pdev->device;
fp@2685: hw->revision_id = pdev->revision;
fp@2685: hw->subsystem_vendor_id = pdev->subsystem_vendor;
fp@2685: hw->subsystem_device_id = pdev->subsystem_device;
fp@2685:
fp@2685: /* Copy the default MAC, PHY and NVM function pointers */
fp@2685: memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
fp@2685: memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
fp@2685: memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
fp@2685: /* Initialize skew-specific constants */
fp@2685: err = ei->get_invariants(hw);
fp@2685: if (err)
fp@2685: goto err_sw_init;
fp@2685:
fp@2685: /* setup the private structure */
fp@2685: err = igb_sw_init(adapter);
fp@2685: if (err)
fp@2685: goto err_sw_init;
fp@2685:
fp@2685: igb_get_bus_info_pcie(hw);
fp@2685:
fp@2685: hw->phy.autoneg_wait_to_complete = false;
fp@2685:
fp@2685: /* Copper options */
fp@2685: if (hw->phy.media_type == e1000_media_type_copper) {
fp@2685: hw->phy.mdix = AUTO_ALL_MODES;
fp@2685: hw->phy.disable_polarity_correction = false;
fp@2685: hw->phy.ms_type = e1000_ms_hw_default;
fp@2685: }
fp@2685:
fp@2685: if (igb_check_reset_block(hw))
fp@2685: dev_info(&pdev->dev,
fp@2685: "PHY reset is blocked due to SOL/IDER session.\n");
fp@2685:
fp@2685: /* features is initialized to 0 in allocation, it might have bits
fp@2685: * set by igb_sw_init so we should use an or instead of an
fp@2685: * assignment.
fp@2685: */
fp@2685: netdev->features |= NETIF_F_SG |
fp@2685: NETIF_F_IP_CSUM |
fp@2685: NETIF_F_IPV6_CSUM |
fp@2685: NETIF_F_TSO |
fp@2685: NETIF_F_TSO6 |
fp@2685: NETIF_F_RXHASH |
fp@2685: NETIF_F_RXCSUM |
fp@2685: NETIF_F_HW_VLAN_CTAG_RX |
fp@2685: NETIF_F_HW_VLAN_CTAG_TX;
fp@2685:
fp@2685: /* copy netdev features into list of user selectable features */
fp@2685: netdev->hw_features |= netdev->features;
fp@2685: netdev->hw_features |= NETIF_F_RXALL;
fp@2685:
fp@2685: /* set this bit last since it cannot be part of hw_features */
fp@2685: netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
fp@2685:
fp@2685: netdev->vlan_features |= NETIF_F_TSO |
fp@2685: NETIF_F_TSO6 |
fp@2685: NETIF_F_IP_CSUM |
fp@2685: NETIF_F_IPV6_CSUM |
fp@2685: NETIF_F_SG;
fp@2685:
fp@2685: netdev->priv_flags |= IFF_SUPP_NOFCS;
fp@2685:
fp@2685: if (pci_using_dac) {
fp@2685: netdev->features |= NETIF_F_HIGHDMA;
fp@2685: netdev->vlan_features |= NETIF_F_HIGHDMA;
fp@2685: }
fp@2685:
fp@2685: if (hw->mac.type >= e1000_82576) {
fp@2685: netdev->hw_features |= NETIF_F_SCTP_CSUM;
fp@2685: netdev->features |= NETIF_F_SCTP_CSUM;
fp@2685: }
fp@2685:
fp@2685: netdev->priv_flags |= IFF_UNICAST_FLT;
fp@2685:
fp@2685: adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
fp@2685:
fp@2685: /* before reading the NVM, reset the controller to put the device in a
fp@2685: * known good starting state
fp@2685: */
fp@2685: hw->mac.ops.reset_hw(hw);
fp@2685:
fp@2685: /* make sure the NVM is good , i211/i210 parts can have special NVM
fp@2685: * that doesn't contain a checksum
fp@2685: */
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: if (igb_get_flash_presence_i210(hw)) {
fp@2685: if (hw->nvm.ops.validate(hw) < 0) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "The NVM Checksum Is Not Valid\n");
fp@2685: err = -EIO;
fp@2685: goto err_eeprom;
fp@2685: }
fp@2685: }
fp@2685: break;
fp@2685: default:
fp@2685: if (hw->nvm.ops.validate(hw) < 0) {
fp@2685: dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
fp@2685: err = -EIO;
fp@2685: goto err_eeprom;
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: /* copy the MAC address out of the NVM */
fp@2685: if (hw->mac.ops.read_mac_addr(hw))
fp@2685: dev_err(&pdev->dev, "NVM Read Error\n");
fp@2685:
fp@2685: memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
fp@2685:
fp@2685: if (!is_valid_ether_addr(netdev->dev_addr)) {
fp@2685: dev_err(&pdev->dev, "Invalid MAC Address\n");
fp@2685: err = -EIO;
fp@2685: goto err_eeprom;
fp@2685: }
fp@2685:
fp@2685: /* get firmware version for ethtool -i */
fp@2685: igb_set_fw_version(adapter);
fp@2685:
fp@2685: /* configure RXPBSIZE and TXPBSIZE */
fp@2685: if (hw->mac.type == e1000_i210) {
fp@2685: wr32(E1000_RXPBS, I210_RXPBSIZE_DEFAULT);
fp@2685: wr32(E1000_TXPBS, I210_TXPBSIZE_DEFAULT);
fp@2685: }
fp@2685:
fp@2685: setup_timer(&adapter->watchdog_timer, igb_watchdog,
fp@2685: (unsigned long) adapter);
fp@2685: setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
fp@2685: (unsigned long) adapter);
fp@2685:
fp@2685: INIT_WORK(&adapter->reset_task, igb_reset_task);
fp@2685: INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
fp@2685:
fp@2685: /* Initialize link properties that are user-changeable */
fp@2685: adapter->fc_autoneg = true;
fp@2685: hw->mac.autoneg = true;
fp@2685: hw->phy.autoneg_advertised = 0x2f;
fp@2685:
fp@2685: hw->fc.requested_mode = e1000_fc_default;
fp@2685: hw->fc.current_mode = e1000_fc_default;
fp@2685:
fp@2685: igb_validate_mdi_setting(hw);
fp@2685:
fp@2685: /* By default, support wake on port A */
fp@2685: if (hw->bus.func == 0)
fp@2685: adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
fp@2685:
fp@2685: /* Check the NVM for wake support on non-port A ports */
fp@2685: if (hw->mac.type >= e1000_82580)
fp@2685: hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
fp@2685: NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
fp@2685: &eeprom_data);
fp@2685: else if (hw->bus.func == 1)
fp@2685: hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
fp@2685:
fp@2685: if (eeprom_data & IGB_EEPROM_APME)
fp@2685: adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
fp@2685:
fp@2685: /* now that we have the eeprom settings, apply the special cases where
fp@2685: * the eeprom may be wrong or the board simply won't support wake on
fp@2685: * lan on a particular port
fp@2685: */
fp@2685: switch (pdev->device) {
fp@2685: case E1000_DEV_ID_82575GB_QUAD_COPPER:
fp@2685: adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
fp@2685: break;
fp@2685: case E1000_DEV_ID_82575EB_FIBER_SERDES:
fp@2685: case E1000_DEV_ID_82576_FIBER:
fp@2685: case E1000_DEV_ID_82576_SERDES:
fp@2685: /* Wake events only supported on port A for dual fiber
fp@2685: * regardless of eeprom setting
fp@2685: */
fp@2685: if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
fp@2685: adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
fp@2685: break;
fp@2685: case E1000_DEV_ID_82576_QUAD_COPPER:
fp@2685: case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
fp@2685: /* if quad port adapter, disable WoL on all but port A */
fp@2685: if (global_quad_port_a != 0)
fp@2685: adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
fp@2685: else
fp@2685: adapter->flags |= IGB_FLAG_QUAD_PORT_A;
fp@2685: /* Reset for multiple quad port adapters */
fp@2685: if (++global_quad_port_a == 4)
fp@2685: global_quad_port_a = 0;
fp@2685: break;
fp@2685: default:
fp@2685: /* If the device can't wake, don't set software support */
fp@2685: if (!device_can_wakeup(&adapter->pdev->dev))
fp@2685: adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
fp@2685: }
fp@2685:
fp@2685: /* initialize the wol settings based on the eeprom settings */
fp@2685: if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
fp@2685: adapter->wol |= E1000_WUFC_MAG;
fp@2685:
fp@2685: /* Some vendors want WoL disabled by default, but still supported */
fp@2685: if ((hw->mac.type == e1000_i350) &&
fp@2685: (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
fp@2685: adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
fp@2685: adapter->wol = 0;
fp@2685: }
fp@2685:
fp@2685: device_set_wakeup_enable(&adapter->pdev->dev,
fp@2685: adapter->flags & IGB_FLAG_WOL_SUPPORTED);
fp@2685:
fp@2685: /* reset the hardware with the new settings */
fp@2685: igb_reset(adapter);
fp@2685:
fp@2685: /* Init the I2C interface */
fp@2685: err = igb_init_i2c(adapter);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev, "failed to init i2c interface\n");
fp@2685: goto err_eeprom;
fp@2685: }
fp@2685:
fp@2685: /* let the f/w know that the h/w is now under the control of the
fp@2685: * driver.
fp@2685: */
fp@2685: igb_get_hw_control(adapter);
fp@2685:
fp@2686: adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE);
fp@2686: if (adapter->ecdev) {
fp@2686: err = ecdev_open(adapter->ecdev);
fp@2686: if (err) {
fp@2686: ecdev_withdraw(adapter->ecdev);
fp@2686: goto err_register;
fp@2686: }
fp@2686: adapter->ec_watchdog_jiffies = jiffies;
fp@2686: } else {
fp@2686: strcpy(netdev->name, "eth%d");
fp@2686: err = register_netdev(netdev);
fp@2686: if (err)
fp@2686: goto err_register;
fp@2686:
fp@2686: /* carrier off reporting is important to ethtool even BEFORE open */
fp@2686: netif_carrier_off(netdev);
fp@2686: }
fp@2685:
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: if (dca_add_requester(&pdev->dev) == 0) {
fp@2685: adapter->flags |= IGB_FLAG_DCA_ENABLED;
fp@2685: dev_info(&pdev->dev, "DCA enabled\n");
fp@2685: igb_setup_dca(adapter);
fp@2685: }
fp@2685:
fp@2685: #endif
fp@2685: #ifdef CONFIG_IGB_HWMON
fp@2685: /* Initialize the thermal sensor on i350 devices. */
fp@2685: if (hw->mac.type == e1000_i350 && hw->bus.func == 0) {
fp@2685: u16 ets_word;
fp@2685:
fp@2685: /* Read the NVM to determine if this i350 device supports an
fp@2685: * external thermal sensor.
fp@2685: */
fp@2685: hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_word);
fp@2685: if (ets_word != 0x0000 && ets_word != 0xFFFF)
fp@2685: adapter->ets = true;
fp@2685: else
fp@2685: adapter->ets = false;
fp@2685: if (igb_sysfs_init(adapter))
fp@2685: dev_err(&pdev->dev,
fp@2685: "failed to allocate sysfs resources\n");
fp@2685: } else {
fp@2685: adapter->ets = false;
fp@2685: }
fp@2685: #endif
fp@2685: /* Check if Media Autosense is enabled */
fp@2685: adapter->ei = *ei;
fp@2685: if (hw->dev_spec._82575.mas_capable)
fp@2685: igb_init_mas(adapter);
fp@2685:
fp@2685: /* do hw tstamp init after resetting */
fp@2685: igb_ptp_init(adapter);
fp@2685:
fp@2685: dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
fp@2685: /* print bus type/speed/width info, not applicable to i354 */
fp@2685: if (hw->mac.type != e1000_i354) {
fp@2685: dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
fp@2685: netdev->name,
fp@2685: ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
fp@2685: (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
fp@2685: "unknown"),
fp@2685: ((hw->bus.width == e1000_bus_width_pcie_x4) ?
fp@2685: "Width x4" :
fp@2685: (hw->bus.width == e1000_bus_width_pcie_x2) ?
fp@2685: "Width x2" :
fp@2685: (hw->bus.width == e1000_bus_width_pcie_x1) ?
fp@2685: "Width x1" : "unknown"), netdev->dev_addr);
fp@2685: }
fp@2685:
fp@2685: if ((hw->mac.type >= e1000_i210 ||
fp@2685: igb_get_flash_presence_i210(hw))) {
fp@2685: ret_val = igb_read_part_string(hw, part_str,
fp@2685: E1000_PBANUM_LENGTH);
fp@2685: } else {
fp@2685: ret_val = -E1000_ERR_INVM_VALUE_NOT_FOUND;
fp@2685: }
fp@2685:
fp@2685: if (ret_val)
fp@2685: strcpy(part_str, "Unknown");
fp@2685: dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
fp@2685: dev_info(&pdev->dev,
fp@2685: "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
fp@2685: (adapter->flags & IGB_FLAG_HAS_MSIX) ? "MSI-X" :
fp@2685: (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
fp@2685: adapter->num_rx_queues, adapter->num_tx_queues);
fp@2685: if (hw->phy.media_type == e1000_media_type_copper) {
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_i350:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: /* Enable EEE for internal copper PHY devices */
fp@2685: err = igb_set_eee_i350(hw, true, true);
fp@2685: if ((!err) &&
fp@2685: (!hw->dev_spec._82575.eee_disable)) {
fp@2685: adapter->eee_advert =
fp@2685: MDIO_EEE_100TX | MDIO_EEE_1000T;
fp@2685: adapter->flags |= IGB_FLAG_EEE;
fp@2685: }
fp@2685: break;
fp@2685: case e1000_i354:
fp@2685: if ((rd32(E1000_CTRL_EXT) &
fp@2685: E1000_CTRL_EXT_LINK_MODE_SGMII)) {
fp@2685: err = igb_set_eee_i354(hw, true, true);
fp@2685: if ((!err) &&
fp@2685: (!hw->dev_spec._82575.eee_disable)) {
fp@2685: adapter->eee_advert =
fp@2685: MDIO_EEE_100TX | MDIO_EEE_1000T;
fp@2685: adapter->flags |= IGB_FLAG_EEE;
fp@2685: }
fp@2685: }
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685: pm_runtime_put_noidle(&pdev->dev);
fp@2685: return 0;
fp@2685:
fp@2685: err_register:
fp@2685: igb_release_hw_control(adapter);
fp@2685: memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
fp@2685: err_eeprom:
fp@2685: if (!igb_check_reset_block(hw))
fp@2685: igb_reset_phy(hw);
fp@2685:
fp@2685: if (hw->flash_address)
fp@2685: iounmap(hw->flash_address);
fp@2685: err_sw_init:
fp@2685: igb_clear_interrupt_scheme(adapter);
fp@2685: pci_iounmap(pdev, hw->hw_addr);
fp@2685: err_ioremap:
fp@2685: free_netdev(netdev);
fp@2685: err_alloc_etherdev:
fp@2685: pci_release_selected_regions(pdev,
fp@2685: pci_select_bars(pdev, IORESOURCE_MEM));
fp@2685: err_pci_reg:
fp@2685: err_dma:
fp@2685: pci_disable_device(pdev);
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: static int igb_disable_sriov(struct pci_dev *pdev)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* reclaim resources allocated to VFs */
fp@2685: if (adapter->vf_data) {
fp@2685: /* disable iov and allow time for transactions to clear */
fp@2685: if (pci_vfs_assigned(pdev)) {
fp@2685: dev_warn(&pdev->dev,
fp@2685: "Cannot deallocate SR-IOV virtual functions while they are assigned - VFs will not be deallocated\n");
fp@2685: return -EPERM;
fp@2685: } else {
fp@2685: pci_disable_sriov(pdev);
fp@2685: msleep(500);
fp@2685: }
fp@2685:
fp@2685: kfree(adapter->vf_data);
fp@2685: adapter->vf_data = NULL;
fp@2685: adapter->vfs_allocated_count = 0;
fp@2685: wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
fp@2685: wrfl();
fp@2685: msleep(100);
fp@2685: dev_info(&pdev->dev, "IOV Disabled\n");
fp@2685:
fp@2685: /* Re-enable DMA Coalescing flag since IOV is turned off */
fp@2685: adapter->flags |= IGB_FLAG_DMAC;
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: int old_vfs = pci_num_vf(pdev);
fp@2685: int err = 0;
fp@2685: int i;
fp@2685:
fp@2685: if (!(adapter->flags & IGB_FLAG_HAS_MSIX) || num_vfs > 7) {
fp@2685: err = -EPERM;
fp@2685: goto out;
fp@2685: }
fp@2685: if (!num_vfs)
fp@2685: goto out;
fp@2685:
fp@2685: if (old_vfs) {
fp@2685: dev_info(&pdev->dev, "%d pre-allocated VFs found - override max_vfs setting of %d\n",
fp@2685: old_vfs, max_vfs);
fp@2685: adapter->vfs_allocated_count = old_vfs;
fp@2685: } else
fp@2685: adapter->vfs_allocated_count = num_vfs;
fp@2685:
fp@2685: adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
fp@2685: sizeof(struct vf_data_storage), GFP_KERNEL);
fp@2685:
fp@2685: /* if allocation failed then we do not support SR-IOV */
fp@2685: if (!adapter->vf_data) {
fp@2685: adapter->vfs_allocated_count = 0;
fp@2685: dev_err(&pdev->dev,
fp@2685: "Unable to allocate memory for VF Data Storage\n");
fp@2685: err = -ENOMEM;
fp@2685: goto out;
fp@2685: }
fp@2685:
fp@2685: /* only call pci_enable_sriov() if no VFs are allocated already */
fp@2685: if (!old_vfs) {
fp@2685: err = pci_enable_sriov(pdev, adapter->vfs_allocated_count);
fp@2685: if (err)
fp@2685: goto err_out;
fp@2685: }
fp@2685: dev_info(&pdev->dev, "%d VFs allocated\n",
fp@2685: adapter->vfs_allocated_count);
fp@2685: for (i = 0; i < adapter->vfs_allocated_count; i++)
fp@2685: igb_vf_configure(adapter, i);
fp@2685:
fp@2685: /* DMA Coalescing is not supported in IOV mode. */
fp@2685: adapter->flags &= ~IGB_FLAG_DMAC;
fp@2685: goto out;
fp@2685:
fp@2685: err_out:
fp@2685: kfree(adapter->vf_data);
fp@2685: adapter->vf_data = NULL;
fp@2685: adapter->vfs_allocated_count = 0;
fp@2685: out:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: #endif
fp@2685: /**
fp@2685: * igb_remove_i2c - Cleanup I2C interface
fp@2685: * @adapter: pointer to adapter structure
fp@2685: **/
fp@2685: static void igb_remove_i2c(struct igb_adapter *adapter)
fp@2685: {
fp@2685: /* free the adapter bus structure */
fp@2685: i2c_del_adapter(&adapter->i2c_adap);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_remove - Device Removal Routine
fp@2685: * @pdev: PCI device information struct
fp@2685: *
fp@2685: * igb_remove is called by the PCI subsystem to alert the driver
fp@2685: * that it should release a PCI device. The could be caused by a
fp@2685: * Hot-Plug event, or because the driver is going to be removed from
fp@2685: * memory.
fp@2685: **/
fp@2685: static void igb_remove(struct pci_dev *pdev)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: ecdev_close(adapter->ecdev);
fp@2686: ecdev_withdraw(adapter->ecdev);
fp@2686: }
fp@2686:
fp@2685: pm_runtime_get_noresume(&pdev->dev);
fp@2685: #ifdef CONFIG_IGB_HWMON
fp@2685: igb_sysfs_exit(adapter);
fp@2685: #endif
fp@2685: igb_remove_i2c(adapter);
fp@2685: igb_ptp_stop(adapter);
fp@2685: /* The watchdog timer may be rescheduled, so explicitly
fp@2685: * disable watchdog from being rescheduled.
fp@2685: */
fp@2685: set_bit(__IGB_DOWN, &adapter->state);
fp@2685: del_timer_sync(&adapter->watchdog_timer);
fp@2685: del_timer_sync(&adapter->phy_info_timer);
fp@2685:
fp@2685: cancel_work_sync(&adapter->reset_task);
fp@2685: cancel_work_sync(&adapter->watchdog_task);
fp@2685:
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
fp@2685: dev_info(&pdev->dev, "DCA disabled\n");
fp@2685: dca_remove_requester(&pdev->dev);
fp@2685: adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
fp@2685: wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
fp@2685: }
fp@2685: #endif
fp@2685:
fp@2685: /* Release control of h/w to f/w. If f/w is AMT enabled, this
fp@2685: * would have already happened in close and is redundant.
fp@2685: */
fp@2685: igb_release_hw_control(adapter);
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: unregister_netdev(netdev);
fp@2686: }
fp@2685:
fp@2685: igb_clear_interrupt_scheme(adapter);
fp@2685:
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: igb_disable_sriov(pdev);
fp@2685: #endif
fp@2685:
fp@2685: pci_iounmap(pdev, hw->hw_addr);
fp@2685: if (hw->flash_address)
fp@2685: iounmap(hw->flash_address);
fp@2685: pci_release_selected_regions(pdev,
fp@2685: pci_select_bars(pdev, IORESOURCE_MEM));
fp@2685:
fp@2685: kfree(adapter->shadow_vfta);
fp@2685: free_netdev(netdev);
fp@2685:
fp@2685: pci_disable_pcie_error_reporting(pdev);
fp@2685:
fp@2685: pci_disable_device(pdev);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * This function initializes the vf specific data storage and then attempts to
fp@2685: * allocate the VFs. The reason for ordering it this way is because it is much
fp@2685: * mor expensive time wise to disable SR-IOV than it is to allocate and free
fp@2685: * the memory for the VFs.
fp@2685: **/
fp@2685: static void igb_probe_vfs(struct igb_adapter *adapter)
fp@2685: {
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* Virtualization features not supported on i210 family. */
fp@2685: if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
fp@2685: return;
fp@2685:
fp@2685: pci_sriov_set_totalvfs(pdev, 7);
fp@2685: igb_pci_enable_sriov(pdev, max_vfs);
fp@2685:
fp@2685: #endif /* CONFIG_PCI_IOV */
fp@2685: }
fp@2685:
fp@2685: static void igb_init_queue_configuration(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 max_rss_queues;
fp@2685:
fp@2685: /* Determine the maximum number of RSS queues supported. */
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_i211:
fp@2685: max_rss_queues = IGB_MAX_RX_QUEUES_I211;
fp@2685: break;
fp@2685: case e1000_82575:
fp@2685: case e1000_i210:
fp@2685: max_rss_queues = IGB_MAX_RX_QUEUES_82575;
fp@2685: break;
fp@2685: case e1000_i350:
fp@2685: /* I350 cannot do RSS and SR-IOV at the same time */
fp@2685: if (!!adapter->vfs_allocated_count) {
fp@2685: max_rss_queues = 1;
fp@2685: break;
fp@2685: }
fp@2685: /* fall through */
fp@2685: case e1000_82576:
fp@2685: if (!!adapter->vfs_allocated_count) {
fp@2685: max_rss_queues = 2;
fp@2685: break;
fp@2685: }
fp@2685: /* fall through */
fp@2685: case e1000_82580:
fp@2685: case e1000_i354:
fp@2685: default:
fp@2685: max_rss_queues = IGB_MAX_RX_QUEUES;
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: adapter->rss_queues = min_t(u32, max_rss_queues, num_online_cpus());
fp@2685:
fp@2685: /* Determine if we need to pair queues. */
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82575:
fp@2685: case e1000_i211:
fp@2685: /* Device supports enough interrupts without queue pairing. */
fp@2685: break;
fp@2685: case e1000_82576:
fp@2685: /* If VFs are going to be allocated with RSS queues then we
fp@2685: * should pair the queues in order to conserve interrupts due
fp@2685: * to limited supply.
fp@2685: */
fp@2685: if ((adapter->rss_queues > 1) &&
fp@2685: (adapter->vfs_allocated_count > 6))
fp@2685: adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
fp@2685: /* fall through */
fp@2685: case e1000_82580:
fp@2685: case e1000_i350:
fp@2685: case e1000_i354:
fp@2685: case e1000_i210:
fp@2685: default:
fp@2685: /* If rss_queues > half of max_rss_queues, pair the queues in
fp@2685: * order to conserve interrupts due to limited supply.
fp@2685: */
fp@2685: if (adapter->rss_queues > (max_rss_queues / 2))
fp@2685: adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_sw_init - Initialize general software structures (struct igb_adapter)
fp@2685: * @adapter: board private structure to initialize
fp@2685: *
fp@2685: * igb_sw_init initializes the Adapter private data structure.
fp@2685: * Fields are initialized based on PCI device information and
fp@2685: * OS network device settings (MTU size).
fp@2685: **/
fp@2685: static int igb_sw_init(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685:
fp@2685: pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
fp@2685:
fp@2685: /* set default ring sizes */
fp@2685: adapter->tx_ring_count = IGB_DEFAULT_TXD;
fp@2685: adapter->rx_ring_count = IGB_DEFAULT_RXD;
fp@2685:
fp@2685: /* set default ITR values */
fp@2685: adapter->rx_itr_setting = IGB_DEFAULT_ITR;
fp@2685: adapter->tx_itr_setting = IGB_DEFAULT_ITR;
fp@2685:
fp@2685: /* set default work limits */
fp@2685: adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
fp@2685:
fp@2685: adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
fp@2685: VLAN_HLEN;
fp@2685: adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
fp@2685:
fp@2685: spin_lock_init(&adapter->stats64_lock);
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82576:
fp@2685: case e1000_i350:
fp@2685: if (max_vfs > 7) {
fp@2685: dev_warn(&pdev->dev,
fp@2685: "Maximum of 7 VFs per PF, using max\n");
fp@2685: max_vfs = adapter->vfs_allocated_count = 7;
fp@2685: } else
fp@2685: adapter->vfs_allocated_count = max_vfs;
fp@2685: if (adapter->vfs_allocated_count)
fp@2685: dev_warn(&pdev->dev,
fp@2685: "Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n");
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685: #endif /* CONFIG_PCI_IOV */
fp@2685:
fp@2685: igb_init_queue_configuration(adapter);
fp@2685:
fp@2685: /* Setup and initialize a copy of the hw vlan table array */
fp@2685: adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32),
fp@2685: GFP_ATOMIC);
fp@2685:
fp@2685: /* This call may decrease the number of queues */
fp@2685: if (igb_init_interrupt_scheme(adapter, true)) {
fp@2685: dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: igb_probe_vfs(adapter);
fp@2685:
fp@2685: /* Explicitly disable IRQ since the NIC can be in any state. */
fp@2685: igb_irq_disable(adapter);
fp@2685:
fp@2685: if (hw->mac.type >= e1000_i350)
fp@2685: adapter->flags &= ~IGB_FLAG_DMAC;
fp@2685:
fp@2685: set_bit(__IGB_DOWN, &adapter->state);
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_open - Called when a network interface is made active
fp@2685: * @netdev: network interface device structure
fp@2685: *
fp@2685: * Returns 0 on success, negative value on failure
fp@2685: *
fp@2685: * The open entry point is called when a network interface is made
fp@2685: * active by the system (IFF_UP). At this point all resources needed
fp@2685: * for transmit and receive operations are allocated, the interrupt
fp@2685: * handler is registered with the OS, the watchdog timer is started,
fp@2685: * and the stack is notified that the interface is ready.
fp@2685: **/
fp@2685: static int __igb_open(struct net_device *netdev, bool resuming)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int err;
fp@2685: int i;
fp@2685:
fp@2685: /* disallow open during test */
fp@2685: if (test_bit(__IGB_TESTING, &adapter->state)) {
fp@2685: WARN_ON(resuming);
fp@2685: return -EBUSY;
fp@2685: }
fp@2685:
fp@2685: if (!resuming)
fp@2685: pm_runtime_get_sync(&pdev->dev);
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: ecdev_set_link(adapter->ecdev, 0);
fp@2686: }
fp@2686: else {
fp@2686: netif_carrier_off(netdev);
fp@2686: }
fp@2685:
fp@2685: /* allocate transmit descriptors */
fp@2685: err = igb_setup_all_tx_resources(adapter);
fp@2685: if (err)
fp@2685: goto err_setup_tx;
fp@2685:
fp@2685: /* allocate receive descriptors */
fp@2685: err = igb_setup_all_rx_resources(adapter);
fp@2685: if (err)
fp@2685: goto err_setup_rx;
fp@2685:
fp@2685: igb_power_up_link(adapter);
fp@2685:
fp@2685: /* before we allocate an interrupt, we must be ready to handle it.
fp@2685: * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
fp@2685: * as soon as we call pci_request_irq, so we have to setup our
fp@2685: * clean_rx handler before we do so.
fp@2685: */
fp@2685: igb_configure(adapter);
fp@2685:
fp@2685: err = igb_request_irq(adapter);
fp@2685: if (err)
fp@2685: goto err_req_irq;
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: /* Notify the stack of the actual queue counts. */
fp@2686: err = netif_set_real_num_tx_queues(adapter->netdev,
fp@2686: adapter->num_tx_queues);
fp@2686: if (err)
fp@2686: goto err_set_queues;
fp@2686:
fp@2686: err = netif_set_real_num_rx_queues(adapter->netdev,
fp@2686: adapter->num_rx_queues);
fp@2686: if (err)
fp@2686: goto err_set_queues;
fp@2686: }
fp@2685:
fp@2685: /* From here on the code is the same as igb_up() */
fp@2685: clear_bit(__IGB_DOWN, &adapter->state);
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2686: napi_enable(&(adapter->q_vector[i]->napi));
fp@2686: }
fp@2685:
fp@2685: /* Clear any pending interrupts. */
fp@2685: rd32(E1000_ICR);
fp@2685:
fp@2685: igb_irq_enable(adapter);
fp@2685:
fp@2685: /* notify VFs that reset has been completed */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: u32 reg_data = rd32(E1000_CTRL_EXT);
fp@2685:
fp@2685: reg_data |= E1000_CTRL_EXT_PFRSTD;
fp@2685: wr32(E1000_CTRL_EXT, reg_data);
fp@2685: }
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_tx_start_all_queues(netdev);
fp@2686: }
fp@2685:
fp@2685: if (!resuming)
fp@2685: pm_runtime_put(&pdev->dev);
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: /* start the watchdog. */
fp@2686: hw->mac.get_link_status = 1;
fp@2686: schedule_work(&adapter->watchdog_task);
fp@2686: }
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err_set_queues:
fp@2685: igb_free_irq(adapter);
fp@2685: err_req_irq:
fp@2685: igb_release_hw_control(adapter);
fp@2685: igb_power_down_link(adapter);
fp@2685: igb_free_all_rx_resources(adapter);
fp@2685: err_setup_rx:
fp@2685: igb_free_all_tx_resources(adapter);
fp@2685: err_setup_tx:
fp@2685: igb_reset(adapter);
fp@2685: if (!resuming)
fp@2685: pm_runtime_put(&pdev->dev);
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static int igb_open(struct net_device *netdev)
fp@2685: {
fp@2685: return __igb_open(netdev, false);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_close - Disables a network interface
fp@2685: * @netdev: network interface device structure
fp@2685: *
fp@2685: * Returns 0, this is not allowed to fail
fp@2685: *
fp@2685: * The close entry point is called when an interface is de-activated
fp@2685: * by the OS. The hardware is still under the driver's control, but
fp@2685: * needs to be disabled. A global MAC reset is issued to stop the
fp@2685: * hardware, and all transmit and receive resources are freed.
fp@2685: **/
fp@2685: static int __igb_close(struct net_device *netdev, bool suspending)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685:
fp@2685: WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
fp@2685:
fp@2685: if (!suspending)
fp@2685: pm_runtime_get_sync(&pdev->dev);
fp@2685:
fp@2685: igb_down(adapter);
fp@2685: igb_free_irq(adapter);
fp@2685:
fp@2685: igb_free_all_tx_resources(adapter);
fp@2685: igb_free_all_rx_resources(adapter);
fp@2685:
fp@2685: if (!suspending)
fp@2685: pm_runtime_put_sync(&pdev->dev);
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_close(struct net_device *netdev)
fp@2685: {
fp@2685: return __igb_close(netdev, false);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_tx_resources - allocate Tx resources (Descriptors)
fp@2685: * @tx_ring: tx descriptor ring (for a specific queue) to setup
fp@2685: *
fp@2685: * Return 0 on success, negative on failure
fp@2685: **/
fp@2685: int igb_setup_tx_resources(struct igb_ring *tx_ring)
fp@2685: {
fp@2685: struct device *dev = tx_ring->dev;
fp@2685: int size;
fp@2685:
fp@2685: size = sizeof(struct igb_tx_buffer) * tx_ring->count;
fp@2685:
fp@2685: tx_ring->tx_buffer_info = vzalloc(size);
fp@2685: if (!tx_ring->tx_buffer_info)
fp@2685: goto err;
fp@2685:
fp@2685: /* round up to nearest 4K */
fp@2685: tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
fp@2685: tx_ring->size = ALIGN(tx_ring->size, 4096);
fp@2685:
fp@2685: tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
fp@2685: &tx_ring->dma, GFP_KERNEL);
fp@2685: if (!tx_ring->desc)
fp@2685: goto err;
fp@2685:
fp@2685: tx_ring->next_to_use = 0;
fp@2685: tx_ring->next_to_clean = 0;
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err:
fp@2685: vfree(tx_ring->tx_buffer_info);
fp@2685: tx_ring->tx_buffer_info = NULL;
fp@2685: dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_all_tx_resources - wrapper to allocate Tx resources
fp@2685: * (Descriptors) for all queues
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Return 0 on success, negative on failure
fp@2685: **/
fp@2685: static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int i, err = 0;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++) {
fp@2685: err = igb_setup_tx_resources(adapter->tx_ring[i]);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "Allocation for Tx Queue %u failed\n", i);
fp@2685: for (i--; i >= 0; i--)
fp@2685: igb_free_tx_resources(adapter->tx_ring[i]);
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_tctl - configure the transmit control registers
fp@2685: * @adapter: Board private structure
fp@2685: **/
fp@2685: void igb_setup_tctl(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 tctl;
fp@2685:
fp@2685: /* disable queue 0 which is enabled by default on 82575 and 82576 */
fp@2685: wr32(E1000_TXDCTL(0), 0);
fp@2685:
fp@2685: /* Program the Transmit Control Register */
fp@2685: tctl = rd32(E1000_TCTL);
fp@2685: tctl &= ~E1000_TCTL_CT;
fp@2685: tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
fp@2685: (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
fp@2685:
fp@2685: igb_config_collision_dist(hw);
fp@2685:
fp@2685: /* Enable transmits */
fp@2685: tctl |= E1000_TCTL_EN;
fp@2685:
fp@2685: wr32(E1000_TCTL, tctl);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure_tx_ring - Configure transmit ring after Reset
fp@2685: * @adapter: board private structure
fp@2685: * @ring: tx ring to configure
fp@2685: *
fp@2685: * Configure a transmit ring after a reset.
fp@2685: **/
fp@2685: void igb_configure_tx_ring(struct igb_adapter *adapter,
fp@2685: struct igb_ring *ring)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 txdctl = 0;
fp@2685: u64 tdba = ring->dma;
fp@2685: int reg_idx = ring->reg_idx;
fp@2685:
fp@2685: /* disable the queue */
fp@2685: wr32(E1000_TXDCTL(reg_idx), 0);
fp@2685: wrfl();
fp@2685: mdelay(10);
fp@2685:
fp@2685: wr32(E1000_TDLEN(reg_idx),
fp@2685: ring->count * sizeof(union e1000_adv_tx_desc));
fp@2685: wr32(E1000_TDBAL(reg_idx),
fp@2685: tdba & 0x00000000ffffffffULL);
fp@2685: wr32(E1000_TDBAH(reg_idx), tdba >> 32);
fp@2685:
fp@2685: ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
fp@2685: wr32(E1000_TDH(reg_idx), 0);
fp@2685: writel(0, ring->tail);
fp@2685:
fp@2685: txdctl |= IGB_TX_PTHRESH;
fp@2685: txdctl |= IGB_TX_HTHRESH << 8;
fp@2685: txdctl |= IGB_TX_WTHRESH << 16;
fp@2685:
fp@2685: txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
fp@2685: wr32(E1000_TXDCTL(reg_idx), txdctl);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure_tx - Configure transmit Unit after Reset
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Configure the Tx unit of the MAC after a reset.
fp@2685: **/
fp@2685: static void igb_configure_tx(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++)
fp@2685: igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_rx_resources - allocate Rx resources (Descriptors)
fp@2685: * @rx_ring: Rx descriptor ring (for a specific queue) to setup
fp@2685: *
fp@2685: * Returns 0 on success, negative on failure
fp@2685: **/
fp@2685: int igb_setup_rx_resources(struct igb_ring *rx_ring)
fp@2685: {
fp@2685: struct device *dev = rx_ring->dev;
fp@2685: int size;
fp@2685:
fp@2685: size = sizeof(struct igb_rx_buffer) * rx_ring->count;
fp@2685:
fp@2685: rx_ring->rx_buffer_info = vzalloc(size);
fp@2685: if (!rx_ring->rx_buffer_info)
fp@2685: goto err;
fp@2685:
fp@2685: /* Round up to nearest 4K */
fp@2685: rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
fp@2685: rx_ring->size = ALIGN(rx_ring->size, 4096);
fp@2685:
fp@2685: rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
fp@2685: &rx_ring->dma, GFP_KERNEL);
fp@2685: if (!rx_ring->desc)
fp@2685: goto err;
fp@2685:
fp@2685: rx_ring->next_to_alloc = 0;
fp@2685: rx_ring->next_to_clean = 0;
fp@2685: rx_ring->next_to_use = 0;
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err:
fp@2685: vfree(rx_ring->rx_buffer_info);
fp@2685: rx_ring->rx_buffer_info = NULL;
fp@2685: dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_all_rx_resources - wrapper to allocate Rx resources
fp@2685: * (Descriptors) for all queues
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Return 0 on success, negative on failure
fp@2685: **/
fp@2685: static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int i, err = 0;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++) {
fp@2685: err = igb_setup_rx_resources(adapter->rx_ring[i]);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "Allocation for Rx Queue %u failed\n", i);
fp@2685: for (i--; i >= 0; i--)
fp@2685: igb_free_rx_resources(adapter->rx_ring[i]);
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_mrqc - configure the multiple receive queue control registers
fp@2685: * @adapter: Board private structure
fp@2685: **/
fp@2685: static void igb_setup_mrqc(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 mrqc, rxcsum;
fp@2685: u32 j, num_rx_queues;
fp@2685: static const u32 rsskey[10] = { 0xDA565A6D, 0xC20E5B25, 0x3D256741,
fp@2685: 0xB08FA343, 0xCB2BCAD0, 0xB4307BAE,
fp@2685: 0xA32DCB77, 0x0CF23080, 0x3BB7426A,
fp@2685: 0xFA01ACBE };
fp@2685:
fp@2685: /* Fill out hash function seeds */
fp@2685: for (j = 0; j < 10; j++)
fp@2685: wr32(E1000_RSSRK(j), rsskey[j]);
fp@2685:
fp@2685: num_rx_queues = adapter->rss_queues;
fp@2685:
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82576:
fp@2685: /* 82576 supports 2 RSS queues for SR-IOV */
fp@2685: if (adapter->vfs_allocated_count)
fp@2685: num_rx_queues = 2;
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if (adapter->rss_indir_tbl_init != num_rx_queues) {
fp@2685: for (j = 0; j < IGB_RETA_SIZE; j++)
fp@2685: adapter->rss_indir_tbl[j] =
fp@2685: (j * num_rx_queues) / IGB_RETA_SIZE;
fp@2685: adapter->rss_indir_tbl_init = num_rx_queues;
fp@2685: }
fp@2685: igb_write_rss_indir_tbl(adapter);
fp@2685:
fp@2685: /* Disable raw packet checksumming so that RSS hash is placed in
fp@2685: * descriptor on writeback. No need to enable TCP/UDP/IP checksum
fp@2685: * offloads as they are enabled by default
fp@2685: */
fp@2685: rxcsum = rd32(E1000_RXCSUM);
fp@2685: rxcsum |= E1000_RXCSUM_PCSD;
fp@2685:
fp@2685: if (adapter->hw.mac.type >= e1000_82576)
fp@2685: /* Enable Receive Checksum Offload for SCTP */
fp@2685: rxcsum |= E1000_RXCSUM_CRCOFL;
fp@2685:
fp@2685: /* Don't need to set TUOFL or IPOFL, they default to 1 */
fp@2685: wr32(E1000_RXCSUM, rxcsum);
fp@2685:
fp@2685: /* Generate RSS hash based on packet types, TCP/UDP
fp@2685: * port numbers and/or IPv4/v6 src and dst addresses
fp@2685: */
fp@2685: mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
fp@2685: E1000_MRQC_RSS_FIELD_IPV4_TCP |
fp@2685: E1000_MRQC_RSS_FIELD_IPV6 |
fp@2685: E1000_MRQC_RSS_FIELD_IPV6_TCP |
fp@2685: E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
fp@2685: mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
fp@2685: if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
fp@2685: mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
fp@2685:
fp@2685: /* If VMDq is enabled then we set the appropriate mode for that, else
fp@2685: * we default to RSS so that an RSS hash is calculated per packet even
fp@2685: * if we are only using one queue
fp@2685: */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: if (hw->mac.type > e1000_82575) {
fp@2685: /* Set the default pool for the PF's first queue */
fp@2685: u32 vtctl = rd32(E1000_VT_CTL);
fp@2685:
fp@2685: vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
fp@2685: E1000_VT_CTL_DISABLE_DEF_POOL);
fp@2685: vtctl |= adapter->vfs_allocated_count <<
fp@2685: E1000_VT_CTL_DEFAULT_POOL_SHIFT;
fp@2685: wr32(E1000_VT_CTL, vtctl);
fp@2685: }
fp@2685: if (adapter->rss_queues > 1)
fp@2685: mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
fp@2685: else
fp@2685: mrqc |= E1000_MRQC_ENABLE_VMDQ;
fp@2685: } else {
fp@2685: if (hw->mac.type != e1000_i211)
fp@2685: mrqc |= E1000_MRQC_ENABLE_RSS_4Q;
fp@2685: }
fp@2685: igb_vmm_control(adapter);
fp@2685:
fp@2685: wr32(E1000_MRQC, mrqc);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_setup_rctl - configure the receive control registers
fp@2685: * @adapter: Board private structure
fp@2685: **/
fp@2685: void igb_setup_rctl(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 rctl;
fp@2685:
fp@2685: rctl = rd32(E1000_RCTL);
fp@2685:
fp@2685: rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
fp@2685: rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
fp@2685:
fp@2685: rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
fp@2685: (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
fp@2685:
fp@2685: /* enable stripping of CRC. It's unlikely this will break BMC
fp@2685: * redirection as it did with e1000. Newer features require
fp@2685: * that the HW strips the CRC.
fp@2685: */
fp@2685: rctl |= E1000_RCTL_SECRC;
fp@2685:
fp@2685: /* disable store bad packets and clear size bits. */
fp@2685: rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
fp@2685:
fp@2685: /* enable LPE to prevent packets larger than max_frame_size */
fp@2685: rctl |= E1000_RCTL_LPE;
fp@2685:
fp@2685: /* disable queue 0 to prevent tail write w/o re-config */
fp@2685: wr32(E1000_RXDCTL(0), 0);
fp@2685:
fp@2685: /* Attention!!! For SR-IOV PF driver operations you must enable
fp@2685: * queue drop for all VF and PF queues to prevent head of line blocking
fp@2685: * if an un-trusted VF does not provide descriptors to hardware.
fp@2685: */
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: /* set all queue drop enable bits */
fp@2685: wr32(E1000_QDE, ALL_QUEUES);
fp@2685: }
fp@2685:
fp@2685: /* This is useful for sniffing bad packets. */
fp@2685: if (adapter->netdev->features & NETIF_F_RXALL) {
fp@2685: /* UPE and MPE will be handled by normal PROMISC logic
fp@2685: * in e1000e_set_rx_mode
fp@2685: */
fp@2685: rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
fp@2685: E1000_RCTL_BAM | /* RX All Bcast Pkts */
fp@2685: E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
fp@2685:
fp@2685: rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
fp@2685: E1000_RCTL_DPF | /* Allow filtered pause */
fp@2685: E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
fp@2685: /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
fp@2685: * and that breaks VLANs.
fp@2685: */
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_RCTL, rctl);
fp@2685: }
fp@2685:
fp@2685: static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
fp@2685: int vfn)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 vmolr;
fp@2685:
fp@2685: /* if it isn't the PF check to see if VFs are enabled and
fp@2685: * increase the size to support vlan tags
fp@2685: */
fp@2685: if (vfn < adapter->vfs_allocated_count &&
fp@2685: adapter->vf_data[vfn].vlans_enabled)
fp@2685: size += VLAN_TAG_SIZE;
fp@2685:
fp@2685: vmolr = rd32(E1000_VMOLR(vfn));
fp@2685: vmolr &= ~E1000_VMOLR_RLPML_MASK;
fp@2685: vmolr |= size | E1000_VMOLR_LPE;
fp@2685: wr32(E1000_VMOLR(vfn), vmolr);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_rlpml_set - set maximum receive packet size
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Configure maximum receivable packet size.
fp@2685: **/
fp@2685: static void igb_rlpml_set(struct igb_adapter *adapter)
fp@2685: {
fp@2685: u32 max_frame_size = adapter->max_frame_size;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u16 pf_id = adapter->vfs_allocated_count;
fp@2685:
fp@2685: if (pf_id) {
fp@2685: igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
fp@2685: /* If we're in VMDQ or SR-IOV mode, then set global RLPML
fp@2685: * to our max jumbo frame size, in case we need to enable
fp@2685: * jumbo frames on one of the rings later.
fp@2685: * This will not pass over-length frames into the default
fp@2685: * queue because it's gated by the VMOLR.RLPML.
fp@2685: */
fp@2685: max_frame_size = MAX_JUMBO_FRAME_SIZE;
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_RLPML, max_frame_size);
fp@2685: }
fp@2685:
fp@2685: static inline void igb_set_vmolr(struct igb_adapter *adapter,
fp@2685: int vfn, bool aupe)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 vmolr;
fp@2685:
fp@2685: /* This register exists only on 82576 and newer so if we are older then
fp@2685: * we should exit and do nothing
fp@2685: */
fp@2685: if (hw->mac.type < e1000_82576)
fp@2685: return;
fp@2685:
fp@2685: vmolr = rd32(E1000_VMOLR(vfn));
fp@2685: vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
fp@2685: if (hw->mac.type == e1000_i350) {
fp@2685: u32 dvmolr;
fp@2685:
fp@2685: dvmolr = rd32(E1000_DVMOLR(vfn));
fp@2685: dvmolr |= E1000_DVMOLR_STRVLAN;
fp@2685: wr32(E1000_DVMOLR(vfn), dvmolr);
fp@2685: }
fp@2685: if (aupe)
fp@2685: vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
fp@2685: else
fp@2685: vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
fp@2685:
fp@2685: /* clear all bits that might not be set */
fp@2685: vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
fp@2685:
fp@2685: if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
fp@2685: vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
fp@2685: /* for VMDq only allow the VFs and pool 0 to accept broadcast and
fp@2685: * multicast packets
fp@2685: */
fp@2685: if (vfn <= adapter->vfs_allocated_count)
fp@2685: vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
fp@2685:
fp@2685: wr32(E1000_VMOLR(vfn), vmolr);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure_rx_ring - Configure a receive ring after Reset
fp@2685: * @adapter: board private structure
fp@2685: * @ring: receive ring to be configured
fp@2685: *
fp@2685: * Configure the Rx unit of the MAC after a reset.
fp@2685: **/
fp@2685: void igb_configure_rx_ring(struct igb_adapter *adapter,
fp@2685: struct igb_ring *ring)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u64 rdba = ring->dma;
fp@2685: int reg_idx = ring->reg_idx;
fp@2685: u32 srrctl = 0, rxdctl = 0;
fp@2685:
fp@2685: /* disable the queue */
fp@2685: wr32(E1000_RXDCTL(reg_idx), 0);
fp@2685:
fp@2685: /* Set DMA base address registers */
fp@2685: wr32(E1000_RDBAL(reg_idx),
fp@2685: rdba & 0x00000000ffffffffULL);
fp@2685: wr32(E1000_RDBAH(reg_idx), rdba >> 32);
fp@2685: wr32(E1000_RDLEN(reg_idx),
fp@2685: ring->count * sizeof(union e1000_adv_rx_desc));
fp@2685:
fp@2685: /* initialize head and tail */
fp@2685: ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
fp@2685: wr32(E1000_RDH(reg_idx), 0);
fp@2685: writel(0, ring->tail);
fp@2685:
fp@2685: /* set descriptor configuration */
fp@2685: srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
fp@2685: srrctl |= IGB_RX_BUFSZ >> E1000_SRRCTL_BSIZEPKT_SHIFT;
fp@2685: srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
fp@2685: if (hw->mac.type >= e1000_82580)
fp@2685: srrctl |= E1000_SRRCTL_TIMESTAMP;
fp@2685: /* Only set Drop Enable if we are supporting multiple queues */
fp@2685: if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
fp@2685: srrctl |= E1000_SRRCTL_DROP_EN;
fp@2685:
fp@2685: wr32(E1000_SRRCTL(reg_idx), srrctl);
fp@2685:
fp@2685: /* set filtering for VMDQ pools */
fp@2685: igb_set_vmolr(adapter, reg_idx & 0x7, true);
fp@2685:
fp@2685: rxdctl |= IGB_RX_PTHRESH;
fp@2685: rxdctl |= IGB_RX_HTHRESH << 8;
fp@2685: rxdctl |= IGB_RX_WTHRESH << 16;
fp@2685:
fp@2685: /* enable receive descriptor fetching */
fp@2685: rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
fp@2685: wr32(E1000_RXDCTL(reg_idx), rxdctl);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_configure_rx - Configure receive Unit after Reset
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Configure the Rx unit of the MAC after a reset.
fp@2685: **/
fp@2685: static void igb_configure_rx(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: /* set UTA to appropriate mode */
fp@2685: igb_set_uta(adapter);
fp@2685:
fp@2685: /* set the correct pool for the PF default MAC address in entry 0 */
fp@2685: igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
fp@2685: adapter->vfs_allocated_count);
fp@2685:
fp@2685: /* Setup the HW Rx Head and Tail Descriptor Pointers and
fp@2685: * the Base and Length of the Rx Descriptor Ring
fp@2685: */
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++)
fp@2685: igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_tx_resources - Free Tx Resources per Queue
fp@2685: * @tx_ring: Tx descriptor ring for a specific queue
fp@2685: *
fp@2685: * Free all transmit software resources
fp@2685: **/
fp@2685: void igb_free_tx_resources(struct igb_ring *tx_ring)
fp@2685: {
fp@2685: igb_clean_tx_ring(tx_ring);
fp@2685:
fp@2685: vfree(tx_ring->tx_buffer_info);
fp@2685: tx_ring->tx_buffer_info = NULL;
fp@2685:
fp@2685: /* if not set, then don't free */
fp@2685: if (!tx_ring->desc)
fp@2685: return;
fp@2685:
fp@2685: dma_free_coherent(tx_ring->dev, tx_ring->size,
fp@2685: tx_ring->desc, tx_ring->dma);
fp@2685:
fp@2685: tx_ring->desc = NULL;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_all_tx_resources - Free Tx Resources for All Queues
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Free all transmit software resources
fp@2685: **/
fp@2685: static void igb_free_all_tx_resources(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++)
fp@2685: if (adapter->tx_ring[i])
fp@2685: igb_free_tx_resources(adapter->tx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
fp@2685: struct igb_tx_buffer *tx_buffer)
fp@2685: {
fp@2685: if (tx_buffer->skb) {
fp@2686: struct igb_adapter *adapter = netdev_priv(ring->netdev);
fp@2686: if (!adapter->ecdev) {
fp@2686: /* skb is reused in EtherCAT TX operation */
fp@2686: dev_kfree_skb_any(tx_buffer->skb);
fp@2686: }
fp@2685: if (dma_unmap_len(tx_buffer, len))
fp@2685: dma_unmap_single(ring->dev,
fp@2685: dma_unmap_addr(tx_buffer, dma),
fp@2685: dma_unmap_len(tx_buffer, len),
fp@2685: DMA_TO_DEVICE);
fp@2685: } else if (dma_unmap_len(tx_buffer, len)) {
fp@2685: dma_unmap_page(ring->dev,
fp@2685: dma_unmap_addr(tx_buffer, dma),
fp@2685: dma_unmap_len(tx_buffer, len),
fp@2685: DMA_TO_DEVICE);
fp@2685: }
fp@2685: tx_buffer->next_to_watch = NULL;
fp@2685: tx_buffer->skb = NULL;
fp@2685: dma_unmap_len_set(tx_buffer, len, 0);
fp@2685: /* buffer_info must be completely set up in the transmit path */
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clean_tx_ring - Free Tx Buffers
fp@2685: * @tx_ring: ring to be cleaned
fp@2685: **/
fp@2685: static void igb_clean_tx_ring(struct igb_ring *tx_ring)
fp@2685: {
fp@2685: struct igb_tx_buffer *buffer_info;
fp@2685: unsigned long size;
fp@2685: u16 i;
fp@2685:
fp@2685: if (!tx_ring->tx_buffer_info)
fp@2685: return;
fp@2685: /* Free all the Tx ring sk_buffs */
fp@2685:
fp@2685: for (i = 0; i < tx_ring->count; i++) {
fp@2685: buffer_info = &tx_ring->tx_buffer_info[i];
fp@2685: igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
fp@2685: }
fp@2685:
fp@2685: netdev_tx_reset_queue(txring_txq(tx_ring));
fp@2685:
fp@2685: size = sizeof(struct igb_tx_buffer) * tx_ring->count;
fp@2685: memset(tx_ring->tx_buffer_info, 0, size);
fp@2685:
fp@2685: /* Zero out the descriptor ring */
fp@2685: memset(tx_ring->desc, 0, tx_ring->size);
fp@2685:
fp@2685: tx_ring->next_to_use = 0;
fp@2685: tx_ring->next_to_clean = 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clean_all_tx_rings - Free Tx Buffers for all queues
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++)
fp@2685: if (adapter->tx_ring[i])
fp@2685: igb_clean_tx_ring(adapter->tx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_rx_resources - Free Rx Resources
fp@2685: * @rx_ring: ring to clean the resources from
fp@2685: *
fp@2685: * Free all receive software resources
fp@2685: **/
fp@2685: void igb_free_rx_resources(struct igb_ring *rx_ring)
fp@2685: {
fp@2685: igb_clean_rx_ring(rx_ring);
fp@2685:
fp@2685: vfree(rx_ring->rx_buffer_info);
fp@2685: rx_ring->rx_buffer_info = NULL;
fp@2685:
fp@2685: /* if not set, then don't free */
fp@2685: if (!rx_ring->desc)
fp@2685: return;
fp@2685:
fp@2685: dma_free_coherent(rx_ring->dev, rx_ring->size,
fp@2685: rx_ring->desc, rx_ring->dma);
fp@2685:
fp@2685: rx_ring->desc = NULL;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_free_all_rx_resources - Free Rx Resources for All Queues
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * Free all receive software resources
fp@2685: **/
fp@2685: static void igb_free_all_rx_resources(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++)
fp@2685: if (adapter->rx_ring[i])
fp@2685: igb_free_rx_resources(adapter->rx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clean_rx_ring - Free Rx Buffers per Queue
fp@2685: * @rx_ring: ring to free buffers from
fp@2685: **/
fp@2685: static void igb_clean_rx_ring(struct igb_ring *rx_ring)
fp@2685: {
fp@2685: unsigned long size;
fp@2685: u16 i;
fp@2685:
fp@2685: if (rx_ring->skb)
fp@2685: dev_kfree_skb(rx_ring->skb);
fp@2685: rx_ring->skb = NULL;
fp@2685:
fp@2685: if (!rx_ring->rx_buffer_info)
fp@2685: return;
fp@2685:
fp@2685: /* Free all the Rx ring sk_buffs */
fp@2685: for (i = 0; i < rx_ring->count; i++) {
fp@2685: struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
fp@2685:
fp@2685: if (!buffer_info->page)
fp@2685: continue;
fp@2685:
fp@2685: dma_unmap_page(rx_ring->dev,
fp@2685: buffer_info->dma,
fp@2685: PAGE_SIZE,
fp@2685: DMA_FROM_DEVICE);
fp@2685: __free_page(buffer_info->page);
fp@2685:
fp@2685: buffer_info->page = NULL;
fp@2685: }
fp@2685:
fp@2685: size = sizeof(struct igb_rx_buffer) * rx_ring->count;
fp@2685: memset(rx_ring->rx_buffer_info, 0, size);
fp@2685:
fp@2685: /* Zero out the descriptor ring */
fp@2685: memset(rx_ring->desc, 0, rx_ring->size);
fp@2685:
fp@2685: rx_ring->next_to_alloc = 0;
fp@2685: rx_ring->next_to_clean = 0;
fp@2685: rx_ring->next_to_use = 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clean_all_rx_rings - Free Rx Buffers for all queues
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++)
fp@2685: if (adapter->rx_ring[i])
fp@2685: igb_clean_rx_ring(adapter->rx_ring[i]);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_mac - Change the Ethernet Address of the NIC
fp@2685: * @netdev: network interface device structure
fp@2685: * @p: pointer to an address structure
fp@2685: *
fp@2685: * Returns 0 on success, negative on failure
fp@2685: **/
fp@2685: static int igb_set_mac(struct net_device *netdev, void *p)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct sockaddr *addr = p;
fp@2685:
fp@2685: if (!is_valid_ether_addr(addr->sa_data))
fp@2685: return -EADDRNOTAVAIL;
fp@2685:
fp@2685: memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
fp@2685: memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
fp@2685:
fp@2685: /* set the correct pool for the new PF MAC address in entry 0 */
fp@2685: igb_rar_set_qsel(adapter, hw->mac.addr, 0,
fp@2685: adapter->vfs_allocated_count);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_write_mc_addr_list - write multicast addresses to MTA
fp@2685: * @netdev: network interface device structure
fp@2685: *
fp@2685: * Writes multicast address list to the MTA hash table.
fp@2685: * Returns: -ENOMEM on failure
fp@2685: * 0 on no addresses written
fp@2685: * X on writing X addresses to MTA
fp@2685: **/
fp@2685: static int igb_write_mc_addr_list(struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct netdev_hw_addr *ha;
fp@2685: u8 *mta_list;
fp@2685: int i;
fp@2685:
fp@2685: if (netdev_mc_empty(netdev)) {
fp@2685: /* nothing to program, so clear mc list */
fp@2685: igb_update_mc_addr_list(hw, NULL, 0);
fp@2685: igb_restore_vf_multicasts(adapter);
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
fp@2685: if (!mta_list)
fp@2685: return -ENOMEM;
fp@2685:
fp@2685: /* The shared function expects a packed array of only addresses. */
fp@2685: i = 0;
fp@2685: netdev_for_each_mc_addr(ha, netdev)
fp@2685: memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
fp@2685:
fp@2685: igb_update_mc_addr_list(hw, mta_list, i);
fp@2685: kfree(mta_list);
fp@2685:
fp@2685: return netdev_mc_count(netdev);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_write_uc_addr_list - write unicast addresses to RAR table
fp@2685: * @netdev: network interface device structure
fp@2685: *
fp@2685: * Writes unicast address list to the RAR table.
fp@2685: * Returns: -ENOMEM on failure/insufficient address space
fp@2685: * 0 on no addresses written
fp@2685: * X on writing X addresses to the RAR table
fp@2685: **/
fp@2685: static int igb_write_uc_addr_list(struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: unsigned int vfn = adapter->vfs_allocated_count;
fp@2685: unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
fp@2685: int count = 0;
fp@2685:
fp@2685: /* return ENOMEM indicating insufficient memory for addresses */
fp@2685: if (netdev_uc_count(netdev) > rar_entries)
fp@2685: return -ENOMEM;
fp@2685:
fp@2685: if (!netdev_uc_empty(netdev) && rar_entries) {
fp@2685: struct netdev_hw_addr *ha;
fp@2685:
fp@2685: netdev_for_each_uc_addr(ha, netdev) {
fp@2685: if (!rar_entries)
fp@2685: break;
fp@2685: igb_rar_set_qsel(adapter, ha->addr,
fp@2685: rar_entries--,
fp@2685: vfn);
fp@2685: count++;
fp@2685: }
fp@2685: }
fp@2685: /* write the addresses in reverse order to avoid write combining */
fp@2685: for (; rar_entries > 0 ; rar_entries--) {
fp@2685: wr32(E1000_RAH(rar_entries), 0);
fp@2685: wr32(E1000_RAL(rar_entries), 0);
fp@2685: }
fp@2685: wrfl();
fp@2685:
fp@2685: return count;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
fp@2685: * @netdev: network interface device structure
fp@2685: *
fp@2685: * The set_rx_mode entry point is called whenever the unicast or multicast
fp@2685: * address lists or the network interface flags are updated. This routine is
fp@2685: * responsible for configuring the hardware for proper unicast, multicast,
fp@2685: * promiscuous mode, and all-multi behavior.
fp@2685: **/
fp@2685: static void igb_set_rx_mode(struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: unsigned int vfn = adapter->vfs_allocated_count;
fp@2685: u32 rctl, vmolr = 0;
fp@2685: int count;
fp@2685:
fp@2685: /* Check for Promiscuous and All Multicast modes */
fp@2685: rctl = rd32(E1000_RCTL);
fp@2685:
fp@2685: /* clear the effected bits */
fp@2685: rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
fp@2685:
fp@2685: if (netdev->flags & IFF_PROMISC) {
fp@2685: /* retain VLAN HW filtering if in VT mode */
fp@2685: if (adapter->vfs_allocated_count)
fp@2685: rctl |= E1000_RCTL_VFE;
fp@2685: rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
fp@2685: vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
fp@2685: } else {
fp@2685: if (netdev->flags & IFF_ALLMULTI) {
fp@2685: rctl |= E1000_RCTL_MPE;
fp@2685: vmolr |= E1000_VMOLR_MPME;
fp@2685: } else {
fp@2685: /* Write addresses to the MTA, if the attempt fails
fp@2685: * then we should just turn on promiscuous mode so
fp@2685: * that we can at least receive multicast traffic
fp@2685: */
fp@2685: count = igb_write_mc_addr_list(netdev);
fp@2685: if (count < 0) {
fp@2685: rctl |= E1000_RCTL_MPE;
fp@2685: vmolr |= E1000_VMOLR_MPME;
fp@2685: } else if (count) {
fp@2685: vmolr |= E1000_VMOLR_ROMPE;
fp@2685: }
fp@2685: }
fp@2685: /* Write addresses to available RAR registers, if there is not
fp@2685: * sufficient space to store all the addresses then enable
fp@2685: * unicast promiscuous mode
fp@2685: */
fp@2685: count = igb_write_uc_addr_list(netdev);
fp@2685: if (count < 0) {
fp@2685: rctl |= E1000_RCTL_UPE;
fp@2685: vmolr |= E1000_VMOLR_ROPE;
fp@2685: }
fp@2685: rctl |= E1000_RCTL_VFE;
fp@2685: }
fp@2685: wr32(E1000_RCTL, rctl);
fp@2685:
fp@2685: /* In order to support SR-IOV and eventually VMDq it is necessary to set
fp@2685: * the VMOLR to enable the appropriate modes. Without this workaround
fp@2685: * we will have issues with VLAN tag stripping not being done for frames
fp@2685: * that are only arriving because we are the default pool
fp@2685: */
fp@2685: if ((hw->mac.type < e1000_82576) || (hw->mac.type > e1000_i350))
fp@2685: return;
fp@2685:
fp@2685: vmolr |= rd32(E1000_VMOLR(vfn)) &
fp@2685: ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
fp@2685: wr32(E1000_VMOLR(vfn), vmolr);
fp@2685: igb_restore_vf_multicasts(adapter);
fp@2685: }
fp@2685:
fp@2685: static void igb_check_wvbr(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 wvbr = 0;
fp@2685:
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82576:
fp@2685: case e1000_i350:
fp@2685: wvbr = rd32(E1000_WVBR);
fp@2685: if (!wvbr)
fp@2685: return;
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: adapter->wvbr |= wvbr;
fp@2685: }
fp@2685:
fp@2685: #define IGB_STAGGERED_QUEUE_OFFSET 8
fp@2685:
fp@2685: static void igb_spoof_check(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int j;
fp@2685:
fp@2685: if (!adapter->wvbr)
fp@2685: return;
fp@2685:
fp@2685: for (j = 0; j < adapter->vfs_allocated_count; j++) {
fp@2685: if (adapter->wvbr & (1 << j) ||
fp@2685: adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
fp@2685: dev_warn(&adapter->pdev->dev,
fp@2685: "Spoof event(s) detected on VF %d\n", j);
fp@2685: adapter->wvbr &=
fp@2685: ~((1 << j) |
fp@2685: (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /* Need to wait a few seconds after link up to get diagnostic information from
fp@2685: * the phy
fp@2685: */
fp@2685: static void igb_update_phy_info(unsigned long data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *) data;
fp@2685: igb_get_phy_info(&adapter->hw);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_has_link - check shared code for link and determine up/down
fp@2685: * @adapter: pointer to driver private info
fp@2685: **/
fp@2685: bool igb_has_link(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: bool link_active = false;
fp@2685:
fp@2685: /* get_link_status is set on LSC (link status) interrupt or
fp@2685: * rx sequence error interrupt. get_link_status will stay
fp@2685: * false until the e1000_check_for_link establishes link
fp@2685: * for copper adapters ONLY
fp@2685: */
fp@2685: switch (hw->phy.media_type) {
fp@2685: case e1000_media_type_copper:
fp@2685: if (!hw->mac.get_link_status)
fp@2685: return true;
fp@2685: case e1000_media_type_internal_serdes:
fp@2685: hw->mac.ops.check_for_link(hw);
fp@2685: link_active = !hw->mac.get_link_status;
fp@2685: break;
fp@2685: default:
fp@2685: case e1000_media_type_unknown:
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if (((hw->mac.type == e1000_i210) ||
fp@2685: (hw->mac.type == e1000_i211)) &&
fp@2685: (hw->phy.id == I210_I_PHY_ID)) {
fp@2685: if (!netif_carrier_ok(adapter->netdev)) {
fp@2685: adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
fp@2685: } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
fp@2685: adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
fp@2685: adapter->link_check_timeout = jiffies;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: return link_active;
fp@2685: }
fp@2685:
fp@2685: static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
fp@2685: {
fp@2685: bool ret = false;
fp@2685: u32 ctrl_ext, thstat;
fp@2685:
fp@2685: /* check for thermal sensor event on i350 copper only */
fp@2685: if (hw->mac.type == e1000_i350) {
fp@2685: thstat = rd32(E1000_THSTAT);
fp@2685: ctrl_ext = rd32(E1000_CTRL_EXT);
fp@2685:
fp@2685: if ((hw->phy.media_type == e1000_media_type_copper) &&
fp@2685: !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII))
fp@2685: ret = !!(thstat & event);
fp@2685: }
fp@2685:
fp@2685: return ret;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_check_lvmmc - check for malformed packets received
fp@2685: * and indicated in LVMMC register
fp@2685: * @adapter: pointer to adapter
fp@2685: **/
fp@2685: static void igb_check_lvmmc(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 lvmmc;
fp@2685:
fp@2685: lvmmc = rd32(E1000_LVMMC);
fp@2685: if (lvmmc) {
fp@2685: if (unlikely(net_ratelimit())) {
fp@2685: netdev_warn(adapter->netdev,
fp@2685: "malformed Tx packet detected and dropped, LVMMC:0x%08x\n",
fp@2685: lvmmc);
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_watchdog - Timer Call-back
fp@2685: * @data: pointer to adapter cast into an unsigned long
fp@2685: **/
fp@2685: static void igb_watchdog(unsigned long data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = (struct igb_adapter *)data;
fp@2685: /* Do the rest outside of interrupt context */
fp@2685: schedule_work(&adapter->watchdog_task);
fp@2685: }
fp@2685:
fp@2685: static void igb_watchdog_task(struct work_struct *work)
fp@2685: {
fp@2685: struct igb_adapter *adapter = container_of(work,
fp@2685: struct igb_adapter,
fp@2685: watchdog_task);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct e1000_phy_info *phy = &hw->phy;
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: u32 link;
fp@2685: int i;
fp@2685: u32 connsw;
fp@2685:
fp@2685: link = igb_has_link(adapter);
fp@2685:
fp@2685: if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
fp@2685: if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
fp@2685: adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
fp@2685: else
fp@2685: link = false;
fp@2685: }
fp@2685:
fp@2685: /* Force link down if we have fiber to swap to */
fp@2685: if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
fp@2685: if (hw->phy.media_type == e1000_media_type_copper) {
fp@2685: connsw = rd32(E1000_CONNSW);
fp@2685: if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
fp@2685: link = 0;
fp@2685: }
fp@2685: }
fp@2685: if (link) {
fp@2685: /* Perform a reset if the media type changed. */
fp@2685: if (hw->dev_spec._82575.media_changed) {
fp@2685: hw->dev_spec._82575.media_changed = false;
fp@2685: adapter->flags |= IGB_FLAG_MEDIA_RESET;
fp@2685: igb_reset(adapter);
fp@2685: }
fp@2685: /* Cancel scheduled suspend requests. */
fp@2685: pm_runtime_resume(netdev->dev.parent);
fp@2685:
fp@2685: if (!netif_carrier_ok(netdev)) {
fp@2685: u32 ctrl;
fp@2685:
fp@2685: hw->mac.ops.get_speed_and_duplex(hw,
fp@2685: &adapter->link_speed,
fp@2685: &adapter->link_duplex);
fp@2685:
fp@2685: ctrl = rd32(E1000_CTRL);
fp@2685: /* Links status message must follow this format */
fp@2685: netdev_info(netdev,
fp@2685: "igb: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
fp@2685: netdev->name,
fp@2685: adapter->link_speed,
fp@2685: adapter->link_duplex == FULL_DUPLEX ?
fp@2685: "Full" : "Half",
fp@2685: (ctrl & E1000_CTRL_TFCE) &&
fp@2685: (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
fp@2685: (ctrl & E1000_CTRL_RFCE) ? "RX" :
fp@2685: (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
fp@2685:
fp@2685: /* disable EEE if enabled */
fp@2685: if ((adapter->flags & IGB_FLAG_EEE) &&
fp@2685: (adapter->link_duplex == HALF_DUPLEX)) {
fp@2685: dev_info(&adapter->pdev->dev,
fp@2685: "EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex.\n");
fp@2685: adapter->hw.dev_spec._82575.eee_disable = true;
fp@2685: adapter->flags &= ~IGB_FLAG_EEE;
fp@2685: }
fp@2685:
fp@2685: /* check if SmartSpeed worked */
fp@2685: igb_check_downshift(hw);
fp@2685: if (phy->speed_downgraded)
fp@2685: netdev_warn(netdev, "Link Speed was downgraded by SmartSpeed\n");
fp@2685:
fp@2685: /* check for thermal sensor event */
fp@2685: if (igb_thermal_sensor_event(hw,
fp@2685: E1000_THSTAT_LINK_THROTTLE))
fp@2685: netdev_info(netdev, "The network adapter link speed was downshifted because it overheated\n");
fp@2685:
fp@2685: /* adjust timeout factor according to speed/duplex */
fp@2685: adapter->tx_timeout_factor = 1;
fp@2685: switch (adapter->link_speed) {
fp@2685: case SPEED_10:
fp@2685: adapter->tx_timeout_factor = 14;
fp@2685: break;
fp@2685: case SPEED_100:
fp@2685: /* maybe add some timeout factor ? */
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: netif_carrier_on(netdev);
fp@2685:
fp@2685: igb_ping_all_vfs(adapter);
fp@2685: igb_check_vf_rate_limit(adapter);
fp@2685:
fp@2685: /* link state has changed, schedule phy info update */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state))
fp@2685: mod_timer(&adapter->phy_info_timer,
fp@2685: round_jiffies(jiffies + 2 * HZ));
fp@2685: }
fp@2685: } else {
fp@2685: if (netif_carrier_ok(netdev)) {
fp@2685: adapter->link_speed = 0;
fp@2685: adapter->link_duplex = 0;
fp@2685:
fp@2685: /* check for thermal sensor event */
fp@2685: if (igb_thermal_sensor_event(hw,
fp@2685: E1000_THSTAT_PWR_DOWN)) {
fp@2685: netdev_err(netdev, "The network adapter was stopped because it overheated\n");
fp@2685: }
fp@2685:
fp@2685: /* Links status message must follow this format */
fp@2685: netdev_info(netdev, "igb: %s NIC Link is Down\n",
fp@2685: netdev->name);
fp@2685: netif_carrier_off(netdev);
fp@2685:
fp@2685: igb_ping_all_vfs(adapter);
fp@2685:
fp@2685: /* link state has changed, schedule phy info update */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state))
fp@2685: mod_timer(&adapter->phy_info_timer,
fp@2685: round_jiffies(jiffies + 2 * HZ));
fp@2685:
fp@2685: /* link is down, time to check for alternate media */
fp@2685: if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
fp@2685: igb_check_swap_media(adapter);
fp@2685: if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
fp@2685: schedule_work(&adapter->reset_task);
fp@2685: /* return immediately */
fp@2685: return;
fp@2685: }
fp@2685: }
fp@2685: pm_schedule_suspend(netdev->dev.parent,
fp@2685: MSEC_PER_SEC * 5);
fp@2685:
fp@2685: /* also check for alternate media here */
fp@2685: } else if (!netif_carrier_ok(netdev) &&
fp@2685: (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
fp@2685: igb_check_swap_media(adapter);
fp@2685: if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
fp@2685: schedule_work(&adapter->reset_task);
fp@2685: /* return immediately */
fp@2685: return;
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: spin_lock(&adapter->stats64_lock);
fp@2685: igb_update_stats(adapter, &adapter->stats64);
fp@2685: spin_unlock(&adapter->stats64_lock);
fp@2685:
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++) {
fp@2685: struct igb_ring *tx_ring = adapter->tx_ring[i];
fp@2685: if (!netif_carrier_ok(netdev)) {
fp@2685: /* We've lost link, so the controller stops DMA,
fp@2685: * but we've got queued Tx work that's never going
fp@2685: * to get done, so reset controller to flush Tx.
fp@2685: * (Do the reset outside of interrupt context).
fp@2685: */
fp@2685: if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
fp@2685: adapter->tx_timeout_count++;
fp@2685: schedule_work(&adapter->reset_task);
fp@2685: /* return immediately since reset is imminent */
fp@2685: return;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /* Force detection of hung controller every watchdog period */
fp@2685: set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
fp@2685: }
fp@2685:
fp@2685: /* Cause software interrupt to ensure Rx ring is cleaned */
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX) {
fp@2685: u32 eics = 0;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++)
fp@2685: eics |= adapter->q_vector[i]->eims_value;
fp@2685: wr32(E1000_EICS, eics);
fp@2685: } else {
fp@2685: wr32(E1000_ICS, E1000_ICS_RXDMT0);
fp@2685: }
fp@2685:
fp@2685: igb_spoof_check(adapter);
fp@2685: igb_ptp_rx_hang(adapter);
fp@2685:
fp@2685: /* Check LVMMC register on i350/i354 only */
fp@2685: if ((adapter->hw.mac.type == e1000_i350) ||
fp@2685: (adapter->hw.mac.type == e1000_i354))
fp@2685: igb_check_lvmmc(adapter);
fp@2685:
fp@2685: /* Reset the timer */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state)) {
fp@2685: if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
fp@2685: mod_timer(&adapter->watchdog_timer,
fp@2685: round_jiffies(jiffies + HZ));
fp@2685: else
fp@2685: mod_timer(&adapter->watchdog_timer,
fp@2685: round_jiffies(jiffies + 2 * HZ));
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: enum latency_range {
fp@2685: lowest_latency = 0,
fp@2685: low_latency = 1,
fp@2685: bulk_latency = 2,
fp@2685: latency_invalid = 255
fp@2685: };
fp@2685:
fp@2685: /**
fp@2685: * igb_update_ring_itr - update the dynamic ITR value based on packet size
fp@2685: * @q_vector: pointer to q_vector
fp@2685: *
fp@2685: * Stores a new ITR value based on strictly on packet size. This
fp@2685: * algorithm is less sophisticated than that used in igb_update_itr,
fp@2685: * due to the difficulty of synchronizing statistics across multiple
fp@2685: * receive rings. The divisors and thresholds used by this function
fp@2685: * were determined based on theoretical maximum wire speed and testing
fp@2685: * data, in order to minimize response time while increasing bulk
fp@2685: * throughput.
fp@2685: * This functionality is controlled by ethtool's coalescing settings.
fp@2685: * NOTE: This function is called only when operating in a multiqueue
fp@2685: * receive environment.
fp@2685: **/
fp@2685: static void igb_update_ring_itr(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: int new_val = q_vector->itr_val;
fp@2685: int avg_wire_size = 0;
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: unsigned int packets;
fp@2685:
fp@2685: /* For non-gigabit speeds, just fix the interrupt rate at 4000
fp@2685: * ints/sec - ITR timer value of 120 ticks.
fp@2685: */
fp@2685: if (adapter->link_speed != SPEED_1000) {
fp@2685: new_val = IGB_4K_ITR;
fp@2685: goto set_itr_val;
fp@2685: }
fp@2685:
fp@2685: packets = q_vector->rx.total_packets;
fp@2685: if (packets)
fp@2685: avg_wire_size = q_vector->rx.total_bytes / packets;
fp@2685:
fp@2685: packets = q_vector->tx.total_packets;
fp@2685: if (packets)
fp@2685: avg_wire_size = max_t(u32, avg_wire_size,
fp@2685: q_vector->tx.total_bytes / packets);
fp@2685:
fp@2685: /* if avg_wire_size isn't set no work was done */
fp@2685: if (!avg_wire_size)
fp@2685: goto clear_counts;
fp@2685:
fp@2685: /* Add 24 bytes to size to account for CRC, preamble, and gap */
fp@2685: avg_wire_size += 24;
fp@2685:
fp@2685: /* Don't starve jumbo frames */
fp@2685: avg_wire_size = min(avg_wire_size, 3000);
fp@2685:
fp@2685: /* Give a little boost to mid-size frames */
fp@2685: if ((avg_wire_size > 300) && (avg_wire_size < 1200))
fp@2685: new_val = avg_wire_size / 3;
fp@2685: else
fp@2685: new_val = avg_wire_size / 2;
fp@2685:
fp@2685: /* conservative mode (itr 3) eliminates the lowest_latency setting */
fp@2685: if (new_val < IGB_20K_ITR &&
fp@2685: ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
fp@2685: (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
fp@2685: new_val = IGB_20K_ITR;
fp@2685:
fp@2685: set_itr_val:
fp@2685: if (new_val != q_vector->itr_val) {
fp@2685: q_vector->itr_val = new_val;
fp@2685: q_vector->set_itr = 1;
fp@2685: }
fp@2685: clear_counts:
fp@2685: q_vector->rx.total_bytes = 0;
fp@2685: q_vector->rx.total_packets = 0;
fp@2685: q_vector->tx.total_bytes = 0;
fp@2685: q_vector->tx.total_packets = 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_update_itr - update the dynamic ITR value based on statistics
fp@2685: * @q_vector: pointer to q_vector
fp@2685: * @ring_container: ring info to update the itr for
fp@2685: *
fp@2685: * Stores a new ITR value based on packets and byte
fp@2685: * counts during the last interrupt. The advantage of per interrupt
fp@2685: * computation is faster updates and more accurate ITR for the current
fp@2685: * traffic pattern. Constants in this function were computed
fp@2685: * based on theoretical maximum wire speed and thresholds were set based
fp@2685: * on testing data as well as attempting to minimize response time
fp@2685: * while increasing bulk throughput.
fp@2685: * This functionality is controlled by ethtool's coalescing settings.
fp@2685: * NOTE: These calculations are only valid when operating in a single-
fp@2685: * queue environment.
fp@2685: **/
fp@2685: static void igb_update_itr(struct igb_q_vector *q_vector,
fp@2685: struct igb_ring_container *ring_container)
fp@2685: {
fp@2685: unsigned int packets = ring_container->total_packets;
fp@2685: unsigned int bytes = ring_container->total_bytes;
fp@2685: u8 itrval = ring_container->itr;
fp@2685:
fp@2685: /* no packets, exit with status unchanged */
fp@2685: if (packets == 0)
fp@2685: return;
fp@2685:
fp@2685: switch (itrval) {
fp@2685: case lowest_latency:
fp@2685: /* handle TSO and jumbo frames */
fp@2685: if (bytes/packets > 8000)
fp@2685: itrval = bulk_latency;
fp@2685: else if ((packets < 5) && (bytes > 512))
fp@2685: itrval = low_latency;
fp@2685: break;
fp@2685: case low_latency: /* 50 usec aka 20000 ints/s */
fp@2685: if (bytes > 10000) {
fp@2685: /* this if handles the TSO accounting */
fp@2685: if (bytes/packets > 8000)
fp@2685: itrval = bulk_latency;
fp@2685: else if ((packets < 10) || ((bytes/packets) > 1200))
fp@2685: itrval = bulk_latency;
fp@2685: else if ((packets > 35))
fp@2685: itrval = lowest_latency;
fp@2685: } else if (bytes/packets > 2000) {
fp@2685: itrval = bulk_latency;
fp@2685: } else if (packets <= 2 && bytes < 512) {
fp@2685: itrval = lowest_latency;
fp@2685: }
fp@2685: break;
fp@2685: case bulk_latency: /* 250 usec aka 4000 ints/s */
fp@2685: if (bytes > 25000) {
fp@2685: if (packets > 35)
fp@2685: itrval = low_latency;
fp@2685: } else if (bytes < 1500) {
fp@2685: itrval = low_latency;
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: /* clear work counters since we have the values we need */
fp@2685: ring_container->total_bytes = 0;
fp@2685: ring_container->total_packets = 0;
fp@2685:
fp@2685: /* write updated itr to ring container */
fp@2685: ring_container->itr = itrval;
fp@2685: }
fp@2685:
fp@2685: static void igb_set_itr(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: u32 new_itr = q_vector->itr_val;
fp@2685: u8 current_itr = 0;
fp@2685:
fp@2685: /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
fp@2685: if (adapter->link_speed != SPEED_1000) {
fp@2685: current_itr = 0;
fp@2685: new_itr = IGB_4K_ITR;
fp@2685: goto set_itr_now;
fp@2685: }
fp@2685:
fp@2685: igb_update_itr(q_vector, &q_vector->tx);
fp@2685: igb_update_itr(q_vector, &q_vector->rx);
fp@2685:
fp@2685: current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
fp@2685:
fp@2685: /* conservative mode (itr 3) eliminates the lowest_latency setting */
fp@2685: if (current_itr == lowest_latency &&
fp@2685: ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
fp@2685: (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
fp@2685: current_itr = low_latency;
fp@2685:
fp@2685: switch (current_itr) {
fp@2685: /* counts and packets in update_itr are dependent on these numbers */
fp@2685: case lowest_latency:
fp@2685: new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
fp@2685: break;
fp@2685: case low_latency:
fp@2685: new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
fp@2685: break;
fp@2685: case bulk_latency:
fp@2685: new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
fp@2685: break;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: set_itr_now:
fp@2685: if (new_itr != q_vector->itr_val) {
fp@2685: /* this attempts to bias the interrupt rate towards Bulk
fp@2685: * by adding intermediate steps when interrupt rate is
fp@2685: * increasing
fp@2685: */
fp@2685: new_itr = new_itr > q_vector->itr_val ?
fp@2685: max((new_itr * q_vector->itr_val) /
fp@2685: (new_itr + (q_vector->itr_val >> 2)),
fp@2685: new_itr) : new_itr;
fp@2685: /* Don't write the value here; it resets the adapter's
fp@2685: * internal timer, and causes us to delay far longer than
fp@2685: * we should between interrupts. Instead, we write the ITR
fp@2685: * value at the beginning of the next interrupt so the timing
fp@2685: * ends up being correct.
fp@2685: */
fp@2685: q_vector->itr_val = new_itr;
fp@2685: q_vector->set_itr = 1;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
fp@2685: u32 type_tucmd, u32 mss_l4len_idx)
fp@2685: {
fp@2685: struct e1000_adv_tx_context_desc *context_desc;
fp@2685: u16 i = tx_ring->next_to_use;
fp@2685:
fp@2685: context_desc = IGB_TX_CTXTDESC(tx_ring, i);
fp@2685:
fp@2685: i++;
fp@2685: tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
fp@2685:
fp@2685: /* set bits to identify this as an advanced context descriptor */
fp@2685: type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
fp@2685:
fp@2685: /* For 82575, context index must be unique per ring. */
fp@2685: if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
fp@2685: mss_l4len_idx |= tx_ring->reg_idx << 4;
fp@2685:
fp@2685: context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
fp@2685: context_desc->seqnum_seed = 0;
fp@2685: context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
fp@2685: context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
fp@2685: }
fp@2685:
fp@2685: static int igb_tso(struct igb_ring *tx_ring,
fp@2685: struct igb_tx_buffer *first,
fp@2685: u8 *hdr_len)
fp@2685: {
fp@2685: struct sk_buff *skb = first->skb;
fp@2685: u32 vlan_macip_lens, type_tucmd;
fp@2685: u32 mss_l4len_idx, l4len;
fp@2685: int err;
fp@2685:
fp@2685: if (skb->ip_summed != CHECKSUM_PARTIAL)
fp@2685: return 0;
fp@2685:
fp@2685: if (!skb_is_gso(skb))
fp@2685: return 0;
fp@2685:
fp@2685: err = skb_cow_head(skb, 0);
fp@2685: if (err < 0)
fp@2685: return err;
fp@2685:
fp@2685: /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
fp@2685: type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
fp@2685:
fp@2685: if (first->protocol == htons(ETH_P_IP)) {
fp@2685: struct iphdr *iph = ip_hdr(skb);
fp@2685: iph->tot_len = 0;
fp@2685: iph->check = 0;
fp@2685: tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
fp@2685: iph->daddr, 0,
fp@2685: IPPROTO_TCP,
fp@2685: 0);
fp@2685: type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
fp@2685: first->tx_flags |= IGB_TX_FLAGS_TSO |
fp@2685: IGB_TX_FLAGS_CSUM |
fp@2685: IGB_TX_FLAGS_IPV4;
fp@2685: } else if (skb_is_gso_v6(skb)) {
fp@2685: ipv6_hdr(skb)->payload_len = 0;
fp@2685: tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
fp@2685: &ipv6_hdr(skb)->daddr,
fp@2685: 0, IPPROTO_TCP, 0);
fp@2685: first->tx_flags |= IGB_TX_FLAGS_TSO |
fp@2685: IGB_TX_FLAGS_CSUM;
fp@2685: }
fp@2685:
fp@2685: /* compute header lengths */
fp@2685: l4len = tcp_hdrlen(skb);
fp@2685: *hdr_len = skb_transport_offset(skb) + l4len;
fp@2685:
fp@2685: /* update gso size and bytecount with header size */
fp@2685: first->gso_segs = skb_shinfo(skb)->gso_segs;
fp@2685: first->bytecount += (first->gso_segs - 1) * *hdr_len;
fp@2685:
fp@2685: /* MSS L4LEN IDX */
fp@2685: mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
fp@2685: mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
fp@2685:
fp@2685: /* VLAN MACLEN IPLEN */
fp@2685: vlan_macip_lens = skb_network_header_len(skb);
fp@2685: vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
fp@2685: vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
fp@2685:
fp@2685: igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
fp@2685:
fp@2685: return 1;
fp@2685: }
fp@2685:
fp@2685: static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
fp@2685: {
fp@2685: struct sk_buff *skb = first->skb;
fp@2685: u32 vlan_macip_lens = 0;
fp@2685: u32 mss_l4len_idx = 0;
fp@2685: u32 type_tucmd = 0;
fp@2685:
fp@2685: if (skb->ip_summed != CHECKSUM_PARTIAL) {
fp@2685: if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
fp@2685: return;
fp@2685: } else {
fp@2685: u8 l4_hdr = 0;
fp@2685:
fp@2685: switch (first->protocol) {
fp@2685: case htons(ETH_P_IP):
fp@2685: vlan_macip_lens |= skb_network_header_len(skb);
fp@2685: type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
fp@2685: l4_hdr = ip_hdr(skb)->protocol;
fp@2685: break;
fp@2685: case htons(ETH_P_IPV6):
fp@2685: vlan_macip_lens |= skb_network_header_len(skb);
fp@2685: l4_hdr = ipv6_hdr(skb)->nexthdr;
fp@2685: break;
fp@2685: default:
fp@2685: if (unlikely(net_ratelimit())) {
fp@2685: dev_warn(tx_ring->dev,
fp@2685: "partial checksum but proto=%x!\n",
fp@2685: first->protocol);
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: switch (l4_hdr) {
fp@2685: case IPPROTO_TCP:
fp@2685: type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
fp@2685: mss_l4len_idx = tcp_hdrlen(skb) <<
fp@2685: E1000_ADVTXD_L4LEN_SHIFT;
fp@2685: break;
fp@2685: case IPPROTO_SCTP:
fp@2685: type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
fp@2685: mss_l4len_idx = sizeof(struct sctphdr) <<
fp@2685: E1000_ADVTXD_L4LEN_SHIFT;
fp@2685: break;
fp@2685: case IPPROTO_UDP:
fp@2685: mss_l4len_idx = sizeof(struct udphdr) <<
fp@2685: E1000_ADVTXD_L4LEN_SHIFT;
fp@2685: break;
fp@2685: default:
fp@2685: if (unlikely(net_ratelimit())) {
fp@2685: dev_warn(tx_ring->dev,
fp@2685: "partial checksum but l4 proto=%x!\n",
fp@2685: l4_hdr);
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: /* update TX checksum flag */
fp@2685: first->tx_flags |= IGB_TX_FLAGS_CSUM;
fp@2685: }
fp@2685:
fp@2685: vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
fp@2685: vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
fp@2685:
fp@2685: igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
fp@2685: }
fp@2685:
fp@2685: #define IGB_SET_FLAG(_input, _flag, _result) \
fp@2685: ((_flag <= _result) ? \
fp@2685: ((u32)(_input & _flag) * (_result / _flag)) : \
fp@2685: ((u32)(_input & _flag) / (_flag / _result)))
fp@2685:
fp@2685: static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
fp@2685: {
fp@2685: /* set type for advanced descriptor with frame checksum insertion */
fp@2685: u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
fp@2685: E1000_ADVTXD_DCMD_DEXT |
fp@2685: E1000_ADVTXD_DCMD_IFCS;
fp@2685:
fp@2685: /* set HW vlan bit if vlan is present */
fp@2685: cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
fp@2685: (E1000_ADVTXD_DCMD_VLE));
fp@2685:
fp@2685: /* set segmentation bits for TSO */
fp@2685: cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
fp@2685: (E1000_ADVTXD_DCMD_TSE));
fp@2685:
fp@2685: /* set timestamp bit if present */
fp@2685: cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
fp@2685: (E1000_ADVTXD_MAC_TSTAMP));
fp@2685:
fp@2685: /* insert frame checksum */
fp@2685: cmd_type ^= IGB_SET_FLAG(skb->no_fcs, 1, E1000_ADVTXD_DCMD_IFCS);
fp@2685:
fp@2685: return cmd_type;
fp@2685: }
fp@2685:
fp@2685: static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
fp@2685: union e1000_adv_tx_desc *tx_desc,
fp@2685: u32 tx_flags, unsigned int paylen)
fp@2685: {
fp@2685: u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
fp@2685:
fp@2685: /* 82575 requires a unique index per ring */
fp@2685: if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
fp@2685: olinfo_status |= tx_ring->reg_idx << 4;
fp@2685:
fp@2685: /* insert L4 checksum */
fp@2685: olinfo_status |= IGB_SET_FLAG(tx_flags,
fp@2685: IGB_TX_FLAGS_CSUM,
fp@2685: (E1000_TXD_POPTS_TXSM << 8));
fp@2685:
fp@2685: /* insert IPv4 checksum */
fp@2685: olinfo_status |= IGB_SET_FLAG(tx_flags,
fp@2685: IGB_TX_FLAGS_IPV4,
fp@2685: (E1000_TXD_POPTS_IXSM << 8));
fp@2685:
fp@2685: tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
fp@2685: }
fp@2685:
fp@2685: static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
fp@2685: {
fp@2685: struct net_device *netdev = tx_ring->netdev;
fp@2686: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2686:
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_stop_subqueue(netdev, tx_ring->queue_index);
fp@2686: }
fp@2685:
fp@2685: /* Herbert's original patch had:
fp@2685: * smp_mb__after_netif_stop_queue();
fp@2685: * but since that doesn't exist yet, just open code it.
fp@2685: */
fp@2685: smp_mb();
fp@2685:
fp@2685: /* We need to check again in a case another CPU has just
fp@2685: * made room available.
fp@2685: */
fp@2685: if (igb_desc_unused(tx_ring) < size)
fp@2685: return -EBUSY;
fp@2685:
fp@2685: /* A reprieve! */
fp@2686: if (!adapter->ecdev) {
fp@2686: netif_wake_subqueue(netdev, tx_ring->queue_index);
fp@2686: }
fp@2685:
fp@2685: u64_stats_update_begin(&tx_ring->tx_syncp2);
fp@2685: tx_ring->tx_stats.restart_queue2++;
fp@2685: u64_stats_update_end(&tx_ring->tx_syncp2);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
fp@2685: {
fp@2685: if (igb_desc_unused(tx_ring) >= size)
fp@2685: return 0;
fp@2685: return __igb_maybe_stop_tx(tx_ring, size);
fp@2685: }
fp@2685:
fp@2685: static void igb_tx_map(struct igb_ring *tx_ring,
fp@2685: struct igb_tx_buffer *first,
fp@2685: const u8 hdr_len)
fp@2685: {
fp@2685: struct sk_buff *skb = first->skb;
fp@2685: struct igb_tx_buffer *tx_buffer;
fp@2685: union e1000_adv_tx_desc *tx_desc;
fp@2685: struct skb_frag_struct *frag;
fp@2685: dma_addr_t dma;
fp@2685: unsigned int data_len, size;
fp@2685: u32 tx_flags = first->tx_flags;
fp@2685: u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
fp@2685: u16 i = tx_ring->next_to_use;
fp@2685:
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, i);
fp@2685:
fp@2685: igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
fp@2685:
fp@2685: size = skb_headlen(skb);
fp@2685: data_len = skb->data_len;
fp@2685:
fp@2685: dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
fp@2685:
fp@2685: tx_buffer = first;
fp@2685:
fp@2685: for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
fp@2685: if (dma_mapping_error(tx_ring->dev, dma))
fp@2685: goto dma_error;
fp@2685:
fp@2685: /* record length, and DMA address */
fp@2685: dma_unmap_len_set(tx_buffer, len, size);
fp@2685: dma_unmap_addr_set(tx_buffer, dma, dma);
fp@2685:
fp@2685: tx_desc->read.buffer_addr = cpu_to_le64(dma);
fp@2685:
fp@2685: while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
fp@2685: tx_desc->read.cmd_type_len =
fp@2685: cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
fp@2685:
fp@2685: i++;
fp@2685: tx_desc++;
fp@2685: if (i == tx_ring->count) {
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, 0);
fp@2685: i = 0;
fp@2685: }
fp@2685: tx_desc->read.olinfo_status = 0;
fp@2685:
fp@2685: dma += IGB_MAX_DATA_PER_TXD;
fp@2685: size -= IGB_MAX_DATA_PER_TXD;
fp@2685:
fp@2685: tx_desc->read.buffer_addr = cpu_to_le64(dma);
fp@2685: }
fp@2685:
fp@2685: if (likely(!data_len))
fp@2685: break;
fp@2685:
fp@2685: tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
fp@2685:
fp@2685: i++;
fp@2685: tx_desc++;
fp@2685: if (i == tx_ring->count) {
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, 0);
fp@2685: i = 0;
fp@2685: }
fp@2685: tx_desc->read.olinfo_status = 0;
fp@2685:
fp@2685: size = skb_frag_size(frag);
fp@2685: data_len -= size;
fp@2685:
fp@2685: dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
fp@2685: size, DMA_TO_DEVICE);
fp@2685:
fp@2685: tx_buffer = &tx_ring->tx_buffer_info[i];
fp@2685: }
fp@2685:
fp@2685: /* write last descriptor with RS and EOP bits */
fp@2685: cmd_type |= size | IGB_TXD_DCMD;
fp@2685: tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
fp@2685:
fp@2685: netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
fp@2685:
fp@2685: /* set the timestamp */
fp@2685: first->time_stamp = jiffies;
fp@2685:
fp@2685: /* Force memory writes to complete before letting h/w know there
fp@2685: * are new descriptors to fetch. (Only applicable for weak-ordered
fp@2685: * memory model archs, such as IA-64).
fp@2685: *
fp@2685: * We also need this memory barrier to make certain all of the
fp@2685: * status bits have been updated before next_to_watch is written.
fp@2685: */
fp@2685: wmb();
fp@2685:
fp@2685: /* set next_to_watch value indicating a packet is present */
fp@2685: first->next_to_watch = tx_desc;
fp@2685:
fp@2685: i++;
fp@2685: if (i == tx_ring->count)
fp@2685: i = 0;
fp@2685:
fp@2685: tx_ring->next_to_use = i;
fp@2685:
fp@2685: /* Make sure there is space in the ring for the next send. */
fp@2685: igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
fp@2685:
fp@2685: if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
fp@2685: writel(i, tx_ring->tail);
fp@2685:
fp@2685: /* we need this if more than one processor can write to our tail
fp@2685: * at a time, it synchronizes IO on IA64/Altix systems
fp@2685: */
fp@2685: mmiowb();
fp@2685: }
fp@2685: return;
fp@2685:
fp@2685: dma_error:
fp@2685: dev_err(tx_ring->dev, "TX DMA map failed\n");
fp@2685:
fp@2685: /* clear dma mappings for failed tx_buffer_info map */
fp@2685: for (;;) {
fp@2685: tx_buffer = &tx_ring->tx_buffer_info[i];
fp@2685: igb_unmap_and_free_tx_resource(tx_ring, tx_buffer);
fp@2685: if (tx_buffer == first)
fp@2685: break;
fp@2685: if (i == 0)
fp@2685: i = tx_ring->count;
fp@2685: i--;
fp@2685: }
fp@2685:
fp@2685: tx_ring->next_to_use = i;
fp@2685: }
fp@2685:
fp@2685: netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
fp@2685: struct igb_ring *tx_ring)
fp@2685: {
fp@2685: struct igb_tx_buffer *first;
fp@2685: int tso;
fp@2685: u32 tx_flags = 0;
fp@2685: u16 count = TXD_USE_COUNT(skb_headlen(skb));
fp@2685: __be16 protocol = vlan_get_protocol(skb);
fp@2685: u8 hdr_len = 0;
fp@2686: struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
fp@2685:
fp@2685: /* need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
fp@2685: * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
fp@2685: * + 2 desc gap to keep tail from touching head,
fp@2685: * + 1 desc for context descriptor,
fp@2685: * otherwise try next time
fp@2685: */
fp@2685: if (NETDEV_FRAG_PAGE_MAX_SIZE > IGB_MAX_DATA_PER_TXD) {
fp@2685: unsigned short f;
fp@2685:
fp@2685: for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
fp@2685: count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
fp@2685: } else {
fp@2685: count += skb_shinfo(skb)->nr_frags;
fp@2685: }
fp@2685:
fp@2685: if (igb_maybe_stop_tx(tx_ring, count + 3)) {
fp@2685: /* this is a hard error */
fp@2685: return NETDEV_TX_BUSY;
fp@2685: }
fp@2685:
fp@2685: /* record the location of the first descriptor for this packet */
fp@2685: first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
fp@2685: first->skb = skb;
fp@2685: first->bytecount = skb->len;
fp@2685: first->gso_segs = 1;
fp@2685:
fp@2686: if (unlikely(!adapter->ecdev &&
fp@2686: (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))) {
fp@2685:
fp@2685: if (!test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
fp@2685: &adapter->state)) {
fp@2685: skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
fp@2685: tx_flags |= IGB_TX_FLAGS_TSTAMP;
fp@2685:
fp@2685: adapter->ptp_tx_skb = skb_get(skb);
fp@2685: adapter->ptp_tx_start = jiffies;
fp@2685: if (adapter->hw.mac.type == e1000_82576)
fp@2685: schedule_work(&adapter->ptp_tx_work);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: skb_tx_timestamp(skb);
fp@2685:
fp@2685: if (vlan_tx_tag_present(skb)) {
fp@2685: tx_flags |= IGB_TX_FLAGS_VLAN;
fp@2685: tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
fp@2685: }
fp@2685:
fp@2685: /* record initial flags and protocol */
fp@2685: first->tx_flags = tx_flags;
fp@2685: first->protocol = protocol;
fp@2685:
fp@2685: tso = igb_tso(tx_ring, first, &hdr_len);
fp@2685: if (tso < 0)
fp@2685: goto out_drop;
fp@2685: else if (!tso)
fp@2685: igb_tx_csum(tx_ring, first);
fp@2685:
fp@2685: igb_tx_map(tx_ring, first, hdr_len);
fp@2685:
fp@2685: return NETDEV_TX_OK;
fp@2685:
fp@2685: out_drop:
fp@2685: igb_unmap_and_free_tx_resource(tx_ring, first);
fp@2685:
fp@2685: return NETDEV_TX_OK;
fp@2685: }
fp@2685:
fp@2685: static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: unsigned int r_idx = skb->queue_mapping;
fp@2685:
fp@2685: if (r_idx >= adapter->num_tx_queues)
fp@2685: r_idx = r_idx % adapter->num_tx_queues;
fp@2685:
fp@2685: return adapter->tx_ring[r_idx];
fp@2685: }
fp@2685:
fp@2685: static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
fp@2685: struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: if (test_bit(__IGB_DOWN, &adapter->state)) {
fp@2686: if (!adapter->ecdev) {
fp@2686: dev_kfree_skb_any(skb);
fp@2686: }
fp@2685: return NETDEV_TX_OK;
fp@2685: }
fp@2685:
fp@2685: if (skb->len <= 0) {
fp@2686: if (!adapter->ecdev) {
fp@2686: dev_kfree_skb_any(skb);
fp@2686: }
fp@2685: return NETDEV_TX_OK;
fp@2685: }
fp@2685:
fp@2685: /* The minimum packet size with TCTL.PSP set is 17 so pad the skb
fp@2685: * in order to meet this minimum size requirement.
fp@2685: */
fp@2685: if (unlikely(skb->len < 17)) {
fp@2685: if (skb_pad(skb, 17 - skb->len))
fp@2685: return NETDEV_TX_OK;
fp@2685: skb->len = 17;
fp@2685: skb_set_tail_pointer(skb, 17);
fp@2685: }
fp@2685:
fp@2685: return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_tx_timeout - Respond to a Tx Hang
fp@2685: * @netdev: network interface device structure
fp@2685: **/
fp@2685: static void igb_tx_timeout(struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* Do the reset outside of interrupt context */
fp@2685: adapter->tx_timeout_count++;
fp@2685:
fp@2685: if (hw->mac.type >= e1000_82580)
fp@2685: hw->dev_spec._82575.global_device_reset = true;
fp@2685:
fp@2685: schedule_work(&adapter->reset_task);
fp@2685: wr32(E1000_EICS,
fp@2685: (adapter->eims_enable_mask & ~adapter->eims_other));
fp@2685: }
fp@2685:
fp@2685: static void igb_reset_task(struct work_struct *work)
fp@2685: {
fp@2685: struct igb_adapter *adapter;
fp@2685: adapter = container_of(work, struct igb_adapter, reset_task);
fp@2685:
fp@2685: igb_dump(adapter);
fp@2685: netdev_err(adapter->netdev, "Reset adapter\n");
fp@2685: igb_reinit_locked(adapter);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_get_stats64 - Get System Network Statistics
fp@2685: * @netdev: network interface device structure
fp@2685: * @stats: rtnl_link_stats64 pointer
fp@2685: **/
fp@2685: static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
fp@2685: struct rtnl_link_stats64 *stats)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: spin_lock(&adapter->stats64_lock);
fp@2685: igb_update_stats(adapter, &adapter->stats64);
fp@2685: memcpy(stats, &adapter->stats64, sizeof(*stats));
fp@2685: spin_unlock(&adapter->stats64_lock);
fp@2685:
fp@2685: return stats;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_change_mtu - Change the Maximum Transfer Unit
fp@2685: * @netdev: network interface device structure
fp@2685: * @new_mtu: new value for maximum frame size
fp@2685: *
fp@2685: * Returns 0 on success, negative on failure
fp@2685: **/
fp@2685: static int igb_change_mtu(struct net_device *netdev, int new_mtu)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
fp@2685:
fp@2685: if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
fp@2685: dev_err(&pdev->dev, "Invalid MTU setting\n");
fp@2685: return -EINVAL;
fp@2685: }
fp@2685:
fp@2685: #define MAX_STD_JUMBO_FRAME_SIZE 9238
fp@2685: if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
fp@2685: dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
fp@2685: return -EINVAL;
fp@2685: }
fp@2685:
fp@2685: /* adjust max frame to be at least the size of a standard frame */
fp@2685: if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
fp@2685: max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
fp@2685:
fp@2685: while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
fp@2685: usleep_range(1000, 2000);
fp@2685:
fp@2685: /* igb_down has a dependency on max_frame_size */
fp@2685: adapter->max_frame_size = max_frame;
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_down(adapter);
fp@2685:
fp@2685: dev_info(&pdev->dev, "changing MTU from %d to %d\n",
fp@2685: netdev->mtu, new_mtu);
fp@2685: netdev->mtu = new_mtu;
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_up(adapter);
fp@2685: else
fp@2685: igb_reset(adapter);
fp@2685:
fp@2685: clear_bit(__IGB_RESETTING, &adapter->state);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_update_stats - Update the board statistics counters
fp@2685: * @adapter: board private structure
fp@2685: **/
fp@2685: void igb_update_stats(struct igb_adapter *adapter,
fp@2685: struct rtnl_link_stats64 *net_stats)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: u32 reg, mpc;
fp@2685: int i;
fp@2685: u64 bytes, packets;
fp@2685: unsigned int start;
fp@2685: u64 _bytes, _packets;
fp@2685:
fp@2685: /* Prevent stats update while adapter is being reset, or if the pci
fp@2685: * connection is down.
fp@2685: */
fp@2685: if (adapter->link_speed == 0)
fp@2685: return;
fp@2685: if (pci_channel_offline(pdev))
fp@2685: return;
fp@2685:
fp@2685: bytes = 0;
fp@2685: packets = 0;
fp@2685:
fp@2685: rcu_read_lock();
fp@2685: for (i = 0; i < adapter->num_rx_queues; i++) {
fp@2685: struct igb_ring *ring = adapter->rx_ring[i];
fp@2685: u32 rqdpc = rd32(E1000_RQDPC(i));
fp@2685: if (hw->mac.type >= e1000_i210)
fp@2685: wr32(E1000_RQDPC(i), 0);
fp@2685:
fp@2685: if (rqdpc) {
fp@2685: ring->rx_stats.drops += rqdpc;
fp@2685: net_stats->rx_fifo_errors += rqdpc;
fp@2685: }
fp@2685:
fp@2685: do {
fp@2685: start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
fp@2685: _bytes = ring->rx_stats.bytes;
fp@2685: _packets = ring->rx_stats.packets;
fp@2685: } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
fp@2685: bytes += _bytes;
fp@2685: packets += _packets;
fp@2685: }
fp@2685:
fp@2685: net_stats->rx_bytes = bytes;
fp@2685: net_stats->rx_packets = packets;
fp@2685:
fp@2685: bytes = 0;
fp@2685: packets = 0;
fp@2685: for (i = 0; i < adapter->num_tx_queues; i++) {
fp@2685: struct igb_ring *ring = adapter->tx_ring[i];
fp@2685: do {
fp@2685: start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
fp@2685: _bytes = ring->tx_stats.bytes;
fp@2685: _packets = ring->tx_stats.packets;
fp@2685: } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
fp@2685: bytes += _bytes;
fp@2685: packets += _packets;
fp@2685: }
fp@2685: net_stats->tx_bytes = bytes;
fp@2685: net_stats->tx_packets = packets;
fp@2685: rcu_read_unlock();
fp@2685:
fp@2685: /* read stats registers */
fp@2685: adapter->stats.crcerrs += rd32(E1000_CRCERRS);
fp@2685: adapter->stats.gprc += rd32(E1000_GPRC);
fp@2685: adapter->stats.gorc += rd32(E1000_GORCL);
fp@2685: rd32(E1000_GORCH); /* clear GORCL */
fp@2685: adapter->stats.bprc += rd32(E1000_BPRC);
fp@2685: adapter->stats.mprc += rd32(E1000_MPRC);
fp@2685: adapter->stats.roc += rd32(E1000_ROC);
fp@2685:
fp@2685: adapter->stats.prc64 += rd32(E1000_PRC64);
fp@2685: adapter->stats.prc127 += rd32(E1000_PRC127);
fp@2685: adapter->stats.prc255 += rd32(E1000_PRC255);
fp@2685: adapter->stats.prc511 += rd32(E1000_PRC511);
fp@2685: adapter->stats.prc1023 += rd32(E1000_PRC1023);
fp@2685: adapter->stats.prc1522 += rd32(E1000_PRC1522);
fp@2685: adapter->stats.symerrs += rd32(E1000_SYMERRS);
fp@2685: adapter->stats.sec += rd32(E1000_SEC);
fp@2685:
fp@2685: mpc = rd32(E1000_MPC);
fp@2685: adapter->stats.mpc += mpc;
fp@2685: net_stats->rx_fifo_errors += mpc;
fp@2685: adapter->stats.scc += rd32(E1000_SCC);
fp@2685: adapter->stats.ecol += rd32(E1000_ECOL);
fp@2685: adapter->stats.mcc += rd32(E1000_MCC);
fp@2685: adapter->stats.latecol += rd32(E1000_LATECOL);
fp@2685: adapter->stats.dc += rd32(E1000_DC);
fp@2685: adapter->stats.rlec += rd32(E1000_RLEC);
fp@2685: adapter->stats.xonrxc += rd32(E1000_XONRXC);
fp@2685: adapter->stats.xontxc += rd32(E1000_XONTXC);
fp@2685: adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
fp@2685: adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
fp@2685: adapter->stats.fcruc += rd32(E1000_FCRUC);
fp@2685: adapter->stats.gptc += rd32(E1000_GPTC);
fp@2685: adapter->stats.gotc += rd32(E1000_GOTCL);
fp@2685: rd32(E1000_GOTCH); /* clear GOTCL */
fp@2685: adapter->stats.rnbc += rd32(E1000_RNBC);
fp@2685: adapter->stats.ruc += rd32(E1000_RUC);
fp@2685: adapter->stats.rfc += rd32(E1000_RFC);
fp@2685: adapter->stats.rjc += rd32(E1000_RJC);
fp@2685: adapter->stats.tor += rd32(E1000_TORH);
fp@2685: adapter->stats.tot += rd32(E1000_TOTH);
fp@2685: adapter->stats.tpr += rd32(E1000_TPR);
fp@2685:
fp@2685: adapter->stats.ptc64 += rd32(E1000_PTC64);
fp@2685: adapter->stats.ptc127 += rd32(E1000_PTC127);
fp@2685: adapter->stats.ptc255 += rd32(E1000_PTC255);
fp@2685: adapter->stats.ptc511 += rd32(E1000_PTC511);
fp@2685: adapter->stats.ptc1023 += rd32(E1000_PTC1023);
fp@2685: adapter->stats.ptc1522 += rd32(E1000_PTC1522);
fp@2685:
fp@2685: adapter->stats.mptc += rd32(E1000_MPTC);
fp@2685: adapter->stats.bptc += rd32(E1000_BPTC);
fp@2685:
fp@2685: adapter->stats.tpt += rd32(E1000_TPT);
fp@2685: adapter->stats.colc += rd32(E1000_COLC);
fp@2685:
fp@2685: adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
fp@2685: /* read internal phy specific stats */
fp@2685: reg = rd32(E1000_CTRL_EXT);
fp@2685: if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
fp@2685: adapter->stats.rxerrc += rd32(E1000_RXERRC);
fp@2685:
fp@2685: /* this stat has invalid values on i210/i211 */
fp@2685: if ((hw->mac.type != e1000_i210) &&
fp@2685: (hw->mac.type != e1000_i211))
fp@2685: adapter->stats.tncrs += rd32(E1000_TNCRS);
fp@2685: }
fp@2685:
fp@2685: adapter->stats.tsctc += rd32(E1000_TSCTC);
fp@2685: adapter->stats.tsctfc += rd32(E1000_TSCTFC);
fp@2685:
fp@2685: adapter->stats.iac += rd32(E1000_IAC);
fp@2685: adapter->stats.icrxoc += rd32(E1000_ICRXOC);
fp@2685: adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
fp@2685: adapter->stats.icrxatc += rd32(E1000_ICRXATC);
fp@2685: adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
fp@2685: adapter->stats.ictxatc += rd32(E1000_ICTXATC);
fp@2685: adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
fp@2685: adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
fp@2685: adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
fp@2685:
fp@2685: /* Fill out the OS statistics structure */
fp@2685: net_stats->multicast = adapter->stats.mprc;
fp@2685: net_stats->collisions = adapter->stats.colc;
fp@2685:
fp@2685: /* Rx Errors */
fp@2685:
fp@2685: /* RLEC on some newer hardware can be incorrect so build
fp@2685: * our own version based on RUC and ROC
fp@2685: */
fp@2685: net_stats->rx_errors = adapter->stats.rxerrc +
fp@2685: adapter->stats.crcerrs + adapter->stats.algnerrc +
fp@2685: adapter->stats.ruc + adapter->stats.roc +
fp@2685: adapter->stats.cexterr;
fp@2685: net_stats->rx_length_errors = adapter->stats.ruc +
fp@2685: adapter->stats.roc;
fp@2685: net_stats->rx_crc_errors = adapter->stats.crcerrs;
fp@2685: net_stats->rx_frame_errors = adapter->stats.algnerrc;
fp@2685: net_stats->rx_missed_errors = adapter->stats.mpc;
fp@2685:
fp@2685: /* Tx Errors */
fp@2685: net_stats->tx_errors = adapter->stats.ecol +
fp@2685: adapter->stats.latecol;
fp@2685: net_stats->tx_aborted_errors = adapter->stats.ecol;
fp@2685: net_stats->tx_window_errors = adapter->stats.latecol;
fp@2685: net_stats->tx_carrier_errors = adapter->stats.tncrs;
fp@2685:
fp@2685: /* Tx Dropped needs to be maintained elsewhere */
fp@2685:
fp@2685: /* Management Stats */
fp@2685: adapter->stats.mgptc += rd32(E1000_MGTPTC);
fp@2685: adapter->stats.mgprc += rd32(E1000_MGTPRC);
fp@2685: adapter->stats.mgpdc += rd32(E1000_MGTPDC);
fp@2685:
fp@2685: /* OS2BMC Stats */
fp@2685: reg = rd32(E1000_MANC);
fp@2685: if (reg & E1000_MANC_EN_BMC2OS) {
fp@2685: adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
fp@2685: adapter->stats.o2bspc += rd32(E1000_O2BSPC);
fp@2685: adapter->stats.b2ospc += rd32(E1000_B2OSPC);
fp@2685: adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static irqreturn_t igb_msix_other(int irq, void *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = data;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 icr = rd32(E1000_ICR);
fp@2685: /* reading ICR causes bit 31 of EICR to be cleared */
fp@2685:
fp@2685: if (icr & E1000_ICR_DRSTA)
fp@2685: schedule_work(&adapter->reset_task);
fp@2685:
fp@2685: if (icr & E1000_ICR_DOUTSYNC) {
fp@2685: /* HW is reporting DMA is out of sync */
fp@2685: adapter->stats.doosync++;
fp@2685: /* The DMA Out of Sync is also indication of a spoof event
fp@2685: * in IOV mode. Check the Wrong VM Behavior register to
fp@2685: * see if it is really a spoof event.
fp@2685: */
fp@2685: igb_check_wvbr(adapter);
fp@2685: }
fp@2685:
fp@2685: /* Check for a mailbox event */
fp@2685: if (icr & E1000_ICR_VMMB)
fp@2685: igb_msg_task(adapter);
fp@2685:
fp@2685: if (icr & E1000_ICR_LSC) {
fp@2685: hw->mac.get_link_status = 1;
fp@2685: /* guard against interrupt when we're going down */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state))
fp@2685: mod_timer(&adapter->watchdog_timer, jiffies + 1);
fp@2685: }
fp@2685:
fp@2685: if (icr & E1000_ICR_TS) {
fp@2685: u32 tsicr = rd32(E1000_TSICR);
fp@2685:
fp@2685: if (tsicr & E1000_TSICR_TXTS) {
fp@2685: /* acknowledge the interrupt */
fp@2685: wr32(E1000_TSICR, E1000_TSICR_TXTS);
fp@2685: /* retrieve hardware timestamp */
fp@2685: schedule_work(&adapter->ptp_tx_work);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_EIMS, adapter->eims_other);
fp@2685:
fp@2685: return IRQ_HANDLED;
fp@2685: }
fp@2685:
fp@2685: static void igb_write_itr(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: u32 itr_val = q_vector->itr_val & 0x7FFC;
fp@2685:
fp@2685: if (!q_vector->set_itr)
fp@2685: return;
fp@2685:
fp@2685: if (!itr_val)
fp@2685: itr_val = 0x4;
fp@2685:
fp@2685: if (adapter->hw.mac.type == e1000_82575)
fp@2685: itr_val |= itr_val << 16;
fp@2685: else
fp@2685: itr_val |= E1000_EITR_CNT_IGNR;
fp@2685:
fp@2685: writel(itr_val, q_vector->itr_register);
fp@2685: q_vector->set_itr = 0;
fp@2685: }
fp@2685:
fp@2685: static irqreturn_t igb_msix_ring(int irq, void *data)
fp@2685: {
fp@2685: struct igb_q_vector *q_vector = data;
fp@2685:
fp@2685: /* Write the ITR value calculated from the previous interrupt. */
fp@2685: igb_write_itr(q_vector);
fp@2685:
fp@2685: napi_schedule(&q_vector->napi);
fp@2685:
fp@2685: return IRQ_HANDLED;
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: static void igb_update_tx_dca(struct igb_adapter *adapter,
fp@2685: struct igb_ring *tx_ring,
fp@2685: int cpu)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
fp@2685:
fp@2685: if (hw->mac.type != e1000_82575)
fp@2685: txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT;
fp@2685:
fp@2685: /* We can enable relaxed ordering for reads, but not writes when
fp@2685: * DCA is enabled. This is due to a known issue in some chipsets
fp@2685: * which will cause the DCA tag to be cleared.
fp@2685: */
fp@2685: txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
fp@2685: E1000_DCA_TXCTRL_DATA_RRO_EN |
fp@2685: E1000_DCA_TXCTRL_DESC_DCA_EN;
fp@2685:
fp@2685: wr32(E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
fp@2685: }
fp@2685:
fp@2685: static void igb_update_rx_dca(struct igb_adapter *adapter,
fp@2685: struct igb_ring *rx_ring,
fp@2685: int cpu)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
fp@2685:
fp@2685: if (hw->mac.type != e1000_82575)
fp@2685: rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT;
fp@2685:
fp@2685: /* We can enable relaxed ordering for reads, but not writes when
fp@2685: * DCA is enabled. This is due to a known issue in some chipsets
fp@2685: * which will cause the DCA tag to be cleared.
fp@2685: */
fp@2685: rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
fp@2685: E1000_DCA_RXCTRL_DESC_DCA_EN;
fp@2685:
fp@2685: wr32(E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
fp@2685: }
fp@2685:
fp@2685: static void igb_update_dca(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: int cpu = get_cpu();
fp@2685:
fp@2685: if (q_vector->cpu == cpu)
fp@2685: goto out_no_update;
fp@2685:
fp@2685: if (q_vector->tx.ring)
fp@2685: igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
fp@2685:
fp@2685: if (q_vector->rx.ring)
fp@2685: igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
fp@2685:
fp@2685: q_vector->cpu = cpu;
fp@2685: out_no_update:
fp@2685: put_cpu();
fp@2685: }
fp@2685:
fp@2685: static void igb_setup_dca(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int i;
fp@2685:
fp@2685: if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
fp@2685: return;
fp@2685:
fp@2685: /* Always use CB2 mode, difference is masked in the CB driver. */
fp@2685: wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++) {
fp@2685: adapter->q_vector[i]->cpu = -1;
fp@2685: igb_update_dca(adapter->q_vector[i]);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static int __igb_notify_dca(struct device *dev, void *data)
fp@2685: {
fp@2685: struct net_device *netdev = dev_get_drvdata(dev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: unsigned long event = *(unsigned long *)data;
fp@2685:
fp@2685: switch (event) {
fp@2685: case DCA_PROVIDER_ADD:
fp@2685: /* if already enabled, don't do it again */
fp@2685: if (adapter->flags & IGB_FLAG_DCA_ENABLED)
fp@2685: break;
fp@2685: if (dca_add_requester(dev) == 0) {
fp@2685: adapter->flags |= IGB_FLAG_DCA_ENABLED;
fp@2685: dev_info(&pdev->dev, "DCA enabled\n");
fp@2685: igb_setup_dca(adapter);
fp@2685: break;
fp@2685: }
fp@2685: /* Fall Through since DCA is disabled. */
fp@2685: case DCA_PROVIDER_REMOVE:
fp@2685: if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
fp@2685: /* without this a class_device is left
fp@2685: * hanging around in the sysfs model
fp@2685: */
fp@2685: dca_remove_requester(dev);
fp@2685: dev_info(&pdev->dev, "DCA disabled\n");
fp@2685: adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
fp@2685: wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
fp@2685: }
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
fp@2685: void *p)
fp@2685: {
fp@2685: int ret_val;
fp@2685:
fp@2685: ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
fp@2685: __igb_notify_dca);
fp@2685:
fp@2685: return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
fp@2685: }
fp@2685: #endif /* CONFIG_IGB_DCA */
fp@2685:
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: static int igb_vf_configure(struct igb_adapter *adapter, int vf)
fp@2685: {
fp@2685: unsigned char mac_addr[ETH_ALEN];
fp@2685:
fp@2685: eth_zero_addr(mac_addr);
fp@2685: igb_set_vf_mac(adapter, vf, mac_addr);
fp@2685:
fp@2685: /* By default spoof check is enabled for all VFs */
fp@2685: adapter->vf_data[vf].spoofchk_enabled = true;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: #endif
fp@2685: static void igb_ping_all_vfs(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ping;
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
fp@2685: ping = E1000_PF_CONTROL_MSG;
fp@2685: if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
fp@2685: ping |= E1000_VT_MSGTYPE_CTS;
fp@2685: igb_write_mbx(hw, &ping, 1, i);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 vmolr = rd32(E1000_VMOLR(vf));
fp@2685: struct vf_data_storage *vf_data = &adapter->vf_data[vf];
fp@2685:
fp@2685: vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
fp@2685: IGB_VF_FLAG_MULTI_PROMISC);
fp@2685: vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
fp@2685:
fp@2685: if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
fp@2685: vmolr |= E1000_VMOLR_MPME;
fp@2685: vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
fp@2685: *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
fp@2685: } else {
fp@2685: /* if we have hashes and we are clearing a multicast promisc
fp@2685: * flag we need to write the hashes to the MTA as this step
fp@2685: * was previously skipped
fp@2685: */
fp@2685: if (vf_data->num_vf_mc_hashes > 30) {
fp@2685: vmolr |= E1000_VMOLR_MPME;
fp@2685: } else if (vf_data->num_vf_mc_hashes) {
fp@2685: int j;
fp@2685:
fp@2685: vmolr |= E1000_VMOLR_ROMPE;
fp@2685: for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
fp@2685: igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_VMOLR(vf), vmolr);
fp@2685:
fp@2685: /* there are flags left unprocessed, likely not supported */
fp@2685: if (*msgbuf & E1000_VT_MSGINFO_MASK)
fp@2685: return -EINVAL;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_set_vf_multicasts(struct igb_adapter *adapter,
fp@2685: u32 *msgbuf, u32 vf)
fp@2685: {
fp@2685: int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
fp@2685: u16 *hash_list = (u16 *)&msgbuf[1];
fp@2685: struct vf_data_storage *vf_data = &adapter->vf_data[vf];
fp@2685: int i;
fp@2685:
fp@2685: /* salt away the number of multicast addresses assigned
fp@2685: * to this VF for later use to restore when the PF multi cast
fp@2685: * list changes
fp@2685: */
fp@2685: vf_data->num_vf_mc_hashes = n;
fp@2685:
fp@2685: /* only up to 30 hash values supported */
fp@2685: if (n > 30)
fp@2685: n = 30;
fp@2685:
fp@2685: /* store the hashes for later use */
fp@2685: for (i = 0; i < n; i++)
fp@2685: vf_data->vf_mc_hashes[i] = hash_list[i];
fp@2685:
fp@2685: /* Flush and reset the mta with the new values */
fp@2685: igb_set_rx_mode(adapter->netdev);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct vf_data_storage *vf_data;
fp@2685: int i, j;
fp@2685:
fp@2685: for (i = 0; i < adapter->vfs_allocated_count; i++) {
fp@2685: u32 vmolr = rd32(E1000_VMOLR(i));
fp@2685:
fp@2685: vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
fp@2685:
fp@2685: vf_data = &adapter->vf_data[i];
fp@2685:
fp@2685: if ((vf_data->num_vf_mc_hashes > 30) ||
fp@2685: (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
fp@2685: vmolr |= E1000_VMOLR_MPME;
fp@2685: } else if (vf_data->num_vf_mc_hashes) {
fp@2685: vmolr |= E1000_VMOLR_ROMPE;
fp@2685: for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
fp@2685: igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
fp@2685: }
fp@2685: wr32(E1000_VMOLR(i), vmolr);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 pool_mask, reg, vid;
fp@2685: int i;
fp@2685:
fp@2685: pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
fp@2685:
fp@2685: /* Find the vlan filter for this id */
fp@2685: for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
fp@2685: reg = rd32(E1000_VLVF(i));
fp@2685:
fp@2685: /* remove the vf from the pool */
fp@2685: reg &= ~pool_mask;
fp@2685:
fp@2685: /* if pool is empty then remove entry from vfta */
fp@2685: if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
fp@2685: (reg & E1000_VLVF_VLANID_ENABLE)) {
fp@2685: reg = 0;
fp@2685: vid = reg & E1000_VLVF_VLANID_MASK;
fp@2685: igb_vfta_set(hw, vid, false);
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_VLVF(i), reg);
fp@2685: }
fp@2685:
fp@2685: adapter->vf_data[vf].vlans_enabled = 0;
fp@2685: }
fp@2685:
fp@2685: static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 reg, i;
fp@2685:
fp@2685: /* The vlvf table only exists on 82576 hardware and newer */
fp@2685: if (hw->mac.type < e1000_82576)
fp@2685: return -1;
fp@2685:
fp@2685: /* we only need to do this if VMDq is enabled */
fp@2685: if (!adapter->vfs_allocated_count)
fp@2685: return -1;
fp@2685:
fp@2685: /* Find the vlan filter for this id */
fp@2685: for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
fp@2685: reg = rd32(E1000_VLVF(i));
fp@2685: if ((reg & E1000_VLVF_VLANID_ENABLE) &&
fp@2685: vid == (reg & E1000_VLVF_VLANID_MASK))
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if (add) {
fp@2685: if (i == E1000_VLVF_ARRAY_SIZE) {
fp@2685: /* Did not find a matching VLAN ID entry that was
fp@2685: * enabled. Search for a free filter entry, i.e.
fp@2685: * one without the enable bit set
fp@2685: */
fp@2685: for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
fp@2685: reg = rd32(E1000_VLVF(i));
fp@2685: if (!(reg & E1000_VLVF_VLANID_ENABLE))
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685: if (i < E1000_VLVF_ARRAY_SIZE) {
fp@2685: /* Found an enabled/available entry */
fp@2685: reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
fp@2685:
fp@2685: /* if !enabled we need to set this up in vfta */
fp@2685: if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
fp@2685: /* add VID to filter table */
fp@2685: igb_vfta_set(hw, vid, true);
fp@2685: reg |= E1000_VLVF_VLANID_ENABLE;
fp@2685: }
fp@2685: reg &= ~E1000_VLVF_VLANID_MASK;
fp@2685: reg |= vid;
fp@2685: wr32(E1000_VLVF(i), reg);
fp@2685:
fp@2685: /* do not modify RLPML for PF devices */
fp@2685: if (vf >= adapter->vfs_allocated_count)
fp@2685: return 0;
fp@2685:
fp@2685: if (!adapter->vf_data[vf].vlans_enabled) {
fp@2685: u32 size;
fp@2685:
fp@2685: reg = rd32(E1000_VMOLR(vf));
fp@2685: size = reg & E1000_VMOLR_RLPML_MASK;
fp@2685: size += 4;
fp@2685: reg &= ~E1000_VMOLR_RLPML_MASK;
fp@2685: reg |= size;
fp@2685: wr32(E1000_VMOLR(vf), reg);
fp@2685: }
fp@2685:
fp@2685: adapter->vf_data[vf].vlans_enabled++;
fp@2685: }
fp@2685: } else {
fp@2685: if (i < E1000_VLVF_ARRAY_SIZE) {
fp@2685: /* remove vf from the pool */
fp@2685: reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
fp@2685: /* if pool is empty then remove entry from vfta */
fp@2685: if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
fp@2685: reg = 0;
fp@2685: igb_vfta_set(hw, vid, false);
fp@2685: }
fp@2685: wr32(E1000_VLVF(i), reg);
fp@2685:
fp@2685: /* do not modify RLPML for PF devices */
fp@2685: if (vf >= adapter->vfs_allocated_count)
fp@2685: return 0;
fp@2685:
fp@2685: adapter->vf_data[vf].vlans_enabled--;
fp@2685: if (!adapter->vf_data[vf].vlans_enabled) {
fp@2685: u32 size;
fp@2685:
fp@2685: reg = rd32(E1000_VMOLR(vf));
fp@2685: size = reg & E1000_VMOLR_RLPML_MASK;
fp@2685: size -= 4;
fp@2685: reg &= ~E1000_VMOLR_RLPML_MASK;
fp@2685: reg |= size;
fp@2685: wr32(E1000_VMOLR(vf), reg);
fp@2685: }
fp@2685: }
fp@2685: }
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: if (vid)
fp@2685: wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
fp@2685: else
fp@2685: wr32(E1000_VMVIR(vf), 0);
fp@2685: }
fp@2685:
fp@2685: static int igb_ndo_set_vf_vlan(struct net_device *netdev,
fp@2685: int vf, u16 vlan, u8 qos)
fp@2685: {
fp@2685: int err = 0;
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
fp@2685: return -EINVAL;
fp@2685: if (vlan || qos) {
fp@2685: err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
fp@2685: if (err)
fp@2685: goto out;
fp@2685: igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
fp@2685: igb_set_vmolr(adapter, vf, !vlan);
fp@2685: adapter->vf_data[vf].pf_vlan = vlan;
fp@2685: adapter->vf_data[vf].pf_qos = qos;
fp@2685: dev_info(&adapter->pdev->dev,
fp@2685: "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
fp@2685: if (test_bit(__IGB_DOWN, &adapter->state)) {
fp@2685: dev_warn(&adapter->pdev->dev,
fp@2685: "The VF VLAN has been set, but the PF device is not up.\n");
fp@2685: dev_warn(&adapter->pdev->dev,
fp@2685: "Bring the PF device up before attempting to use the VF device.\n");
fp@2685: }
fp@2685: } else {
fp@2685: igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
fp@2685: false, vf);
fp@2685: igb_set_vmvir(adapter, vlan, vf);
fp@2685: igb_set_vmolr(adapter, vf, true);
fp@2685: adapter->vf_data[vf].pf_vlan = 0;
fp@2685: adapter->vf_data[vf].pf_qos = 0;
fp@2685: }
fp@2685: out:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static int igb_find_vlvf_entry(struct igb_adapter *adapter, int vid)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int i;
fp@2685: u32 reg;
fp@2685:
fp@2685: /* Find the vlan filter for this id */
fp@2685: for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
fp@2685: reg = rd32(E1000_VLVF(i));
fp@2685: if ((reg & E1000_VLVF_VLANID_ENABLE) &&
fp@2685: vid == (reg & E1000_VLVF_VLANID_MASK))
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if (i >= E1000_VLVF_ARRAY_SIZE)
fp@2685: i = -1;
fp@2685:
fp@2685: return i;
fp@2685: }
fp@2685:
fp@2685: static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
fp@2685: int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
fp@2685: int err = 0;
fp@2685:
fp@2685: /* If in promiscuous mode we need to make sure the PF also has
fp@2685: * the VLAN filter set.
fp@2685: */
fp@2685: if (add && (adapter->netdev->flags & IFF_PROMISC))
fp@2685: err = igb_vlvf_set(adapter, vid, add,
fp@2685: adapter->vfs_allocated_count);
fp@2685: if (err)
fp@2685: goto out;
fp@2685:
fp@2685: err = igb_vlvf_set(adapter, vid, add, vf);
fp@2685:
fp@2685: if (err)
fp@2685: goto out;
fp@2685:
fp@2685: /* Go through all the checks to see if the VLAN filter should
fp@2685: * be wiped completely.
fp@2685: */
fp@2685: if (!add && (adapter->netdev->flags & IFF_PROMISC)) {
fp@2685: u32 vlvf, bits;
fp@2685: int regndx = igb_find_vlvf_entry(adapter, vid);
fp@2685:
fp@2685: if (regndx < 0)
fp@2685: goto out;
fp@2685: /* See if any other pools are set for this VLAN filter
fp@2685: * entry other than the PF.
fp@2685: */
fp@2685: vlvf = bits = rd32(E1000_VLVF(regndx));
fp@2685: bits &= 1 << (E1000_VLVF_POOLSEL_SHIFT +
fp@2685: adapter->vfs_allocated_count);
fp@2685: /* If the filter was removed then ensure PF pool bit
fp@2685: * is cleared if the PF only added itself to the pool
fp@2685: * because the PF is in promiscuous mode.
fp@2685: */
fp@2685: if ((vlvf & VLAN_VID_MASK) == vid &&
fp@2685: !test_bit(vid, adapter->active_vlans) &&
fp@2685: !bits)
fp@2685: igb_vlvf_set(adapter, vid, add,
fp@2685: adapter->vfs_allocated_count);
fp@2685: }
fp@2685:
fp@2685: out:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: /* clear flags - except flag that indicates PF has set the MAC */
fp@2685: adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
fp@2685: adapter->vf_data[vf].last_nack = jiffies;
fp@2685:
fp@2685: /* reset offloads to defaults */
fp@2685: igb_set_vmolr(adapter, vf, true);
fp@2685:
fp@2685: /* reset vlans for device */
fp@2685: igb_clear_vf_vfta(adapter, vf);
fp@2685: if (adapter->vf_data[vf].pf_vlan)
fp@2685: igb_ndo_set_vf_vlan(adapter->netdev, vf,
fp@2685: adapter->vf_data[vf].pf_vlan,
fp@2685: adapter->vf_data[vf].pf_qos);
fp@2685: else
fp@2685: igb_clear_vf_vfta(adapter, vf);
fp@2685:
fp@2685: /* reset multicast table array for vf */
fp@2685: adapter->vf_data[vf].num_vf_mc_hashes = 0;
fp@2685:
fp@2685: /* Flush and reset the mta with the new values */
fp@2685: igb_set_rx_mode(adapter->netdev);
fp@2685: }
fp@2685:
fp@2685: static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
fp@2685:
fp@2685: /* clear mac address as we were hotplug removed/added */
fp@2685: if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
fp@2685: eth_zero_addr(vf_mac);
fp@2685:
fp@2685: /* process remaining reset events */
fp@2685: igb_vf_reset(adapter, vf);
fp@2685: }
fp@2685:
fp@2685: static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
fp@2685: int rar_entry = hw->mac.rar_entry_count - (vf + 1);
fp@2685: u32 reg, msgbuf[3];
fp@2685: u8 *addr = (u8 *)(&msgbuf[1]);
fp@2685:
fp@2685: /* process all the same items cleared in a function level reset */
fp@2685: igb_vf_reset(adapter, vf);
fp@2685:
fp@2685: /* set vf mac address */
fp@2685: igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
fp@2685:
fp@2685: /* enable transmit and receive for vf */
fp@2685: reg = rd32(E1000_VFTE);
fp@2685: wr32(E1000_VFTE, reg | (1 << vf));
fp@2685: reg = rd32(E1000_VFRE);
fp@2685: wr32(E1000_VFRE, reg | (1 << vf));
fp@2685:
fp@2685: adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
fp@2685:
fp@2685: /* reply to reset with ack and vf mac address */
fp@2685: msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
fp@2685: memcpy(addr, vf_mac, ETH_ALEN);
fp@2685: igb_write_mbx(hw, msgbuf, 3, vf);
fp@2685: }
fp@2685:
fp@2685: static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
fp@2685: {
fp@2685: /* The VF MAC Address is stored in a packed array of bytes
fp@2685: * starting at the second 32 bit word of the msg array
fp@2685: */
fp@2685: unsigned char *addr = (char *)&msg[1];
fp@2685: int err = -1;
fp@2685:
fp@2685: if (is_valid_ether_addr(addr))
fp@2685: err = igb_set_vf_mac(adapter, vf, addr);
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct vf_data_storage *vf_data = &adapter->vf_data[vf];
fp@2685: u32 msg = E1000_VT_MSGTYPE_NACK;
fp@2685:
fp@2685: /* if device isn't clear to send it shouldn't be reading either */
fp@2685: if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
fp@2685: time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
fp@2685: igb_write_mbx(hw, &msg, 1, vf);
fp@2685: vf_data->last_nack = jiffies;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: u32 msgbuf[E1000_VFMAILBOX_SIZE];
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct vf_data_storage *vf_data = &adapter->vf_data[vf];
fp@2685: s32 retval;
fp@2685:
fp@2685: retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
fp@2685:
fp@2685: if (retval) {
fp@2685: /* if receive failed revoke VF CTS stats and restart init */
fp@2685: dev_err(&pdev->dev, "Error receiving message from VF\n");
fp@2685: vf_data->flags &= ~IGB_VF_FLAG_CTS;
fp@2685: if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
fp@2685: return;
fp@2685: goto out;
fp@2685: }
fp@2685:
fp@2685: /* this is a message we already processed, do nothing */
fp@2685: if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
fp@2685: return;
fp@2685:
fp@2685: /* until the vf completes a reset it should not be
fp@2685: * allowed to start any configuration.
fp@2685: */
fp@2685: if (msgbuf[0] == E1000_VF_RESET) {
fp@2685: igb_vf_reset_msg(adapter, vf);
fp@2685: return;
fp@2685: }
fp@2685:
fp@2685: if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
fp@2685: if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
fp@2685: return;
fp@2685: retval = -1;
fp@2685: goto out;
fp@2685: }
fp@2685:
fp@2685: switch ((msgbuf[0] & 0xFFFF)) {
fp@2685: case E1000_VF_SET_MAC_ADDR:
fp@2685: retval = -EINVAL;
fp@2685: if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
fp@2685: retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
fp@2685: else
fp@2685: dev_warn(&pdev->dev,
fp@2685: "VF %d attempted to override administratively set MAC address\nReload the VF driver to resume operations\n",
fp@2685: vf);
fp@2685: break;
fp@2685: case E1000_VF_SET_PROMISC:
fp@2685: retval = igb_set_vf_promisc(adapter, msgbuf, vf);
fp@2685: break;
fp@2685: case E1000_VF_SET_MULTICAST:
fp@2685: retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
fp@2685: break;
fp@2685: case E1000_VF_SET_LPE:
fp@2685: retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
fp@2685: break;
fp@2685: case E1000_VF_SET_VLAN:
fp@2685: retval = -1;
fp@2685: if (vf_data->pf_vlan)
fp@2685: dev_warn(&pdev->dev,
fp@2685: "VF %d attempted to override administratively set VLAN tag\nReload the VF driver to resume operations\n",
fp@2685: vf);
fp@2685: else
fp@2685: retval = igb_set_vf_vlan(adapter, msgbuf, vf);
fp@2685: break;
fp@2685: default:
fp@2685: dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
fp@2685: retval = -1;
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
fp@2685: out:
fp@2685: /* notify the VF of the results of what it sent us */
fp@2685: if (retval)
fp@2685: msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
fp@2685: else
fp@2685: msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
fp@2685:
fp@2685: igb_write_mbx(hw, msgbuf, 1, vf);
fp@2685: }
fp@2685:
fp@2685: static void igb_msg_task(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 vf;
fp@2685:
fp@2685: for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
fp@2685: /* process any reset requests */
fp@2685: if (!igb_check_for_rst(hw, vf))
fp@2685: igb_vf_reset_event(adapter, vf);
fp@2685:
fp@2685: /* process any messages pending */
fp@2685: if (!igb_check_for_msg(hw, vf))
fp@2685: igb_rcv_msg_from_vf(adapter, vf);
fp@2685:
fp@2685: /* process any acks */
fp@2685: if (!igb_check_for_ack(hw, vf))
fp@2685: igb_rcv_ack_from_vf(adapter, vf);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_set_uta - Set unicast filter table address
fp@2685: * @adapter: board private structure
fp@2685: *
fp@2685: * The unicast table address is a register array of 32-bit registers.
fp@2685: * The table is meant to be used in a way similar to how the MTA is used
fp@2685: * however due to certain limitations in the hardware it is necessary to
fp@2685: * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
fp@2685: * enable bit to allow vlan tag stripping when promiscuous mode is enabled
fp@2685: **/
fp@2685: static void igb_set_uta(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int i;
fp@2685:
fp@2685: /* The UTA table only exists on 82576 hardware and newer */
fp@2685: if (hw->mac.type < e1000_82576)
fp@2685: return;
fp@2685:
fp@2685: /* we only need to do this if VMDq is enabled */
fp@2685: if (!adapter->vfs_allocated_count)
fp@2685: return;
fp@2685:
fp@2685: for (i = 0; i < hw->mac.uta_reg_count; i++)
fp@2685: array_wr32(E1000_UTA, i, ~0);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_intr_msi - Interrupt Handler
fp@2685: * @irq: interrupt number
fp@2685: * @data: pointer to a network interface device structure
fp@2685: **/
fp@2685: static irqreturn_t igb_intr_msi(int irq, void *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = data;
fp@2685: struct igb_q_vector *q_vector = adapter->q_vector[0];
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: /* read ICR disables interrupts using IAM */
fp@2685: u32 icr = rd32(E1000_ICR);
fp@2685:
fp@2685: igb_write_itr(q_vector);
fp@2685:
fp@2685: if (icr & E1000_ICR_DRSTA)
fp@2685: schedule_work(&adapter->reset_task);
fp@2685:
fp@2685: if (icr & E1000_ICR_DOUTSYNC) {
fp@2685: /* HW is reporting DMA is out of sync */
fp@2685: adapter->stats.doosync++;
fp@2685: }
fp@2685:
fp@2685: if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
fp@2685: hw->mac.get_link_status = 1;
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state))
fp@2685: mod_timer(&adapter->watchdog_timer, jiffies + 1);
fp@2685: }
fp@2685:
fp@2685: if (icr & E1000_ICR_TS) {
fp@2685: u32 tsicr = rd32(E1000_TSICR);
fp@2685:
fp@2685: if (tsicr & E1000_TSICR_TXTS) {
fp@2685: /* acknowledge the interrupt */
fp@2685: wr32(E1000_TSICR, E1000_TSICR_TXTS);
fp@2685: /* retrieve hardware timestamp */
fp@2685: schedule_work(&adapter->ptp_tx_work);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: napi_schedule(&q_vector->napi);
fp@2685:
fp@2685: return IRQ_HANDLED;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_intr - Legacy Interrupt Handler
fp@2685: * @irq: interrupt number
fp@2685: * @data: pointer to a network interface device structure
fp@2685: **/
fp@2685: static irqreturn_t igb_intr(int irq, void *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = data;
fp@2685: struct igb_q_vector *q_vector = adapter->q_vector[0];
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
fp@2685: * need for the IMC write
fp@2685: */
fp@2685: u32 icr = rd32(E1000_ICR);
fp@2685:
fp@2685: /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
fp@2685: * not set, then the adapter didn't send an interrupt
fp@2685: */
fp@2685: if (!(icr & E1000_ICR_INT_ASSERTED))
fp@2685: return IRQ_NONE;
fp@2685:
fp@2685: igb_write_itr(q_vector);
fp@2685:
fp@2685: if (icr & E1000_ICR_DRSTA)
fp@2685: schedule_work(&adapter->reset_task);
fp@2685:
fp@2685: if (icr & E1000_ICR_DOUTSYNC) {
fp@2685: /* HW is reporting DMA is out of sync */
fp@2685: adapter->stats.doosync++;
fp@2685: }
fp@2685:
fp@2685: if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
fp@2685: hw->mac.get_link_status = 1;
fp@2685: /* guard against interrupt when we're going down */
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state))
fp@2685: mod_timer(&adapter->watchdog_timer, jiffies + 1);
fp@2685: }
fp@2685:
fp@2685: if (icr & E1000_ICR_TS) {
fp@2685: u32 tsicr = rd32(E1000_TSICR);
fp@2685:
fp@2685: if (tsicr & E1000_TSICR_TXTS) {
fp@2685: /* acknowledge the interrupt */
fp@2685: wr32(E1000_TSICR, E1000_TSICR_TXTS);
fp@2685: /* retrieve hardware timestamp */
fp@2685: schedule_work(&adapter->ptp_tx_work);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: napi_schedule(&q_vector->napi);
fp@2685:
fp@2685: return IRQ_HANDLED;
fp@2685: }
fp@2685:
fp@2685: static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
fp@2685: (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
fp@2685: if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
fp@2685: igb_set_itr(q_vector);
fp@2685: else
fp@2685: igb_update_ring_itr(q_vector);
fp@2685: }
fp@2685:
fp@2685: if (!test_bit(__IGB_DOWN, &adapter->state)) {
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX)
fp@2685: wr32(E1000_EIMS, q_vector->eims_value);
fp@2685: else
fp@2685: igb_irq_enable(adapter);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_poll - NAPI Rx polling callback
fp@2685: * @napi: napi polling structure
fp@2685: * @budget: count of how many packets we should handle
fp@2685: **/
fp@2685: static int igb_poll(struct napi_struct *napi, int budget)
fp@2685: {
fp@2685: struct igb_q_vector *q_vector = container_of(napi,
fp@2685: struct igb_q_vector,
fp@2685: napi);
fp@2685: bool clean_complete = true;
fp@2685:
fp@2685: #ifdef CONFIG_IGB_DCA
fp@2685: if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
fp@2685: igb_update_dca(q_vector);
fp@2685: #endif
fp@2685: if (q_vector->tx.ring)
fp@2685: clean_complete = igb_clean_tx_irq(q_vector);
fp@2685:
fp@2685: if (q_vector->rx.ring)
fp@2685: clean_complete &= igb_clean_rx_irq(q_vector, budget);
fp@2685:
fp@2685: /* If all work not completed, return budget and keep polling */
fp@2685: if (!clean_complete)
fp@2685: return budget;
fp@2685:
fp@2685: /* If not enough Rx work done, exit the polling mode */
fp@2685: napi_complete(napi);
fp@2685: igb_ring_irq_enable(q_vector);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_clean_tx_irq - Reclaim resources after transmit completes
fp@2685: * @q_vector: pointer to q_vector containing needed info
fp@2685: *
fp@2685: * returns true if ring is completely cleaned
fp@2685: **/
fp@2685: static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
fp@2685: {
fp@2685: struct igb_adapter *adapter = q_vector->adapter;
fp@2685: struct igb_ring *tx_ring = q_vector->tx.ring;
fp@2685: struct igb_tx_buffer *tx_buffer;
fp@2685: union e1000_adv_tx_desc *tx_desc;
fp@2685: unsigned int total_bytes = 0, total_packets = 0;
fp@2685: unsigned int budget = q_vector->tx.work_limit;
fp@2685: unsigned int i = tx_ring->next_to_clean;
fp@2685:
fp@2685: if (test_bit(__IGB_DOWN, &adapter->state))
fp@2685: return true;
fp@2685:
fp@2685: tx_buffer = &tx_ring->tx_buffer_info[i];
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, i);
fp@2685: i -= tx_ring->count;
fp@2685:
fp@2685: do {
fp@2685: union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
fp@2685:
fp@2685: /* if next_to_watch is not set then there is no work pending */
fp@2685: if (!eop_desc)
fp@2685: break;
fp@2685:
fp@2685: /* prevent any other reads prior to eop_desc */
fp@2685: read_barrier_depends();
fp@2685:
fp@2685: /* if DD is not set pending work has not been completed */
fp@2685: if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
fp@2685: break;
fp@2685:
fp@2685: /* clear next_to_watch to prevent false hangs */
fp@2685: tx_buffer->next_to_watch = NULL;
fp@2685:
fp@2685: /* update the statistics for this packet */
fp@2685: total_bytes += tx_buffer->bytecount;
fp@2685: total_packets += tx_buffer->gso_segs;
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: /* free the skb */
fp@2686: dev_consume_skb_any(tx_buffer->skb);
fp@2686: }
fp@2685:
fp@2685: /* unmap skb header data */
fp@2685: dma_unmap_single(tx_ring->dev,
fp@2685: dma_unmap_addr(tx_buffer, dma),
fp@2685: dma_unmap_len(tx_buffer, len),
fp@2685: DMA_TO_DEVICE);
fp@2685:
fp@2685: /* clear tx_buffer data */
fp@2685: tx_buffer->skb = NULL;
fp@2685: dma_unmap_len_set(tx_buffer, len, 0);
fp@2685:
fp@2685: /* clear last DMA location and unmap remaining buffers */
fp@2685: while (tx_desc != eop_desc) {
fp@2685: tx_buffer++;
fp@2685: tx_desc++;
fp@2685: i++;
fp@2685: if (unlikely(!i)) {
fp@2685: i -= tx_ring->count;
fp@2685: tx_buffer = tx_ring->tx_buffer_info;
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, 0);
fp@2685: }
fp@2685:
fp@2685: /* unmap any remaining paged data */
fp@2685: if (dma_unmap_len(tx_buffer, len)) {
fp@2685: dma_unmap_page(tx_ring->dev,
fp@2685: dma_unmap_addr(tx_buffer, dma),
fp@2685: dma_unmap_len(tx_buffer, len),
fp@2685: DMA_TO_DEVICE);
fp@2685: dma_unmap_len_set(tx_buffer, len, 0);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /* move us one more past the eop_desc for start of next pkt */
fp@2685: tx_buffer++;
fp@2685: tx_desc++;
fp@2685: i++;
fp@2685: if (unlikely(!i)) {
fp@2685: i -= tx_ring->count;
fp@2685: tx_buffer = tx_ring->tx_buffer_info;
fp@2685: tx_desc = IGB_TX_DESC(tx_ring, 0);
fp@2685: }
fp@2685:
fp@2685: /* issue prefetch for next Tx descriptor */
fp@2685: prefetch(tx_desc);
fp@2685:
fp@2685: /* update budget accounting */
fp@2685: budget--;
fp@2685: } while (likely(budget));
fp@2685:
fp@2686: if (!adapter->ecdev) {
fp@2686: netdev_tx_completed_queue(txring_txq(tx_ring),
fp@2686: total_packets, total_bytes);
fp@2686: }
fp@2685: i += tx_ring->count;
fp@2685: tx_ring->next_to_clean = i;
fp@2685: u64_stats_update_begin(&tx_ring->tx_syncp);
fp@2685: tx_ring->tx_stats.bytes += total_bytes;
fp@2685: tx_ring->tx_stats.packets += total_packets;
fp@2685: u64_stats_update_end(&tx_ring->tx_syncp);
fp@2685: q_vector->tx.total_bytes += total_bytes;
fp@2685: q_vector->tx.total_packets += total_packets;
fp@2685:
fp@2686: if (!adapter->ecdev &&
fp@2686: test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* Detect a transmit hang in hardware, this serializes the
fp@2685: * check with the clearing of time_stamp and movement of i
fp@2685: */
fp@2685: clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
fp@2685: if (tx_buffer->next_to_watch &&
fp@2685: time_after(jiffies, tx_buffer->time_stamp +
fp@2685: (adapter->tx_timeout_factor * HZ)) &&
fp@2685: !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
fp@2685:
fp@2685: /* detected Tx unit hang */
fp@2685: dev_err(tx_ring->dev,
fp@2685: "Detected Tx Unit Hang\n"
fp@2685: " Tx Queue <%d>\n"
fp@2685: " TDH <%x>\n"
fp@2685: " TDT <%x>\n"
fp@2685: " next_to_use <%x>\n"
fp@2685: " next_to_clean <%x>\n"
fp@2685: "buffer_info[next_to_clean]\n"
fp@2685: " time_stamp <%lx>\n"
fp@2685: " next_to_watch <%p>\n"
fp@2685: " jiffies <%lx>\n"
fp@2685: " desc.status <%x>\n",
fp@2685: tx_ring->queue_index,
fp@2685: rd32(E1000_TDH(tx_ring->reg_idx)),
fp@2685: readl(tx_ring->tail),
fp@2685: tx_ring->next_to_use,
fp@2685: tx_ring->next_to_clean,
fp@2685: tx_buffer->time_stamp,
fp@2685: tx_buffer->next_to_watch,
fp@2685: jiffies,
fp@2685: tx_buffer->next_to_watch->wb.status);
fp@2685: netif_stop_subqueue(tx_ring->netdev,
fp@2685: tx_ring->queue_index);
fp@2685:
fp@2685: /* we are about to reset, no point in enabling stuff */
fp@2685: return true;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
fp@2686: if (unlikely(!adapter->ecdev && total_packets &&
fp@2685: netif_carrier_ok(tx_ring->netdev) &&
fp@2685: igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
fp@2685: /* Make sure that anybody stopping the queue after this
fp@2685: * sees the new next_to_clean.
fp@2685: */
fp@2685: smp_mb();
fp@2685: if (__netif_subqueue_stopped(tx_ring->netdev,
fp@2685: tx_ring->queue_index) &&
fp@2685: !(test_bit(__IGB_DOWN, &adapter->state))) {
fp@2685: netif_wake_subqueue(tx_ring->netdev,
fp@2685: tx_ring->queue_index);
fp@2685:
fp@2685: u64_stats_update_begin(&tx_ring->tx_syncp);
fp@2685: tx_ring->tx_stats.restart_queue++;
fp@2685: u64_stats_update_end(&tx_ring->tx_syncp);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: return !!budget;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_reuse_rx_page - page flip buffer and store it back on the ring
fp@2685: * @rx_ring: rx descriptor ring to store buffers on
fp@2685: * @old_buff: donor buffer to have page reused
fp@2685: *
fp@2685: * Synchronizes page for reuse by the adapter
fp@2685: **/
fp@2685: static void igb_reuse_rx_page(struct igb_ring *rx_ring,
fp@2685: struct igb_rx_buffer *old_buff)
fp@2685: {
fp@2685: struct igb_rx_buffer *new_buff;
fp@2685: u16 nta = rx_ring->next_to_alloc;
fp@2685:
fp@2685: new_buff = &rx_ring->rx_buffer_info[nta];
fp@2685:
fp@2685: /* update, and store next to alloc */
fp@2685: nta++;
fp@2685: rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
fp@2685:
fp@2685: /* transfer page from old buffer to new buffer */
fp@2685: *new_buff = *old_buff;
fp@2685:
fp@2685: /* sync the buffer for use by the device */
fp@2685: dma_sync_single_range_for_device(rx_ring->dev, old_buff->dma,
fp@2685: old_buff->page_offset,
fp@2685: IGB_RX_BUFSZ,
fp@2685: DMA_FROM_DEVICE);
fp@2685: }
fp@2685:
fp@2685: static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
fp@2685: struct page *page,
fp@2685: unsigned int truesize)
fp@2685: {
fp@2685: /* avoid re-using remote pages */
fp@2685: if (unlikely(page_to_nid(page) != numa_node_id()))
fp@2685: return false;
fp@2685:
fp@2685: if (unlikely(page->pfmemalloc))
fp@2685: return false;
fp@2685:
fp@2685: #if (PAGE_SIZE < 8192)
fp@2685: /* if we are only owner of page we can reuse it */
fp@2685: if (unlikely(page_count(page) != 1))
fp@2685: return false;
fp@2685:
fp@2685: /* flip page offset to other buffer */
fp@2685: rx_buffer->page_offset ^= IGB_RX_BUFSZ;
fp@2685:
fp@2685: /* Even if we own the page, we are not allowed to use atomic_set()
fp@2685: * This would break get_page_unless_zero() users.
fp@2685: */
fp@2685: atomic_inc(&page->_count);
fp@2685: #else
fp@2685: /* move offset up to the next cache line */
fp@2685: rx_buffer->page_offset += truesize;
fp@2685:
fp@2685: if (rx_buffer->page_offset > (PAGE_SIZE - IGB_RX_BUFSZ))
fp@2685: return false;
fp@2685:
fp@2685: /* bump ref count on page before it is given to the stack */
fp@2685: get_page(page);
fp@2685: #endif
fp@2685:
fp@2685: return true;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
fp@2685: * @rx_ring: rx descriptor ring to transact packets on
fp@2685: * @rx_buffer: buffer containing page to add
fp@2685: * @rx_desc: descriptor containing length of buffer written by hardware
fp@2685: * @skb: sk_buff to place the data into
fp@2685: *
fp@2685: * This function will add the data contained in rx_buffer->page to the skb.
fp@2685: * This is done either through a direct copy if the data in the buffer is
fp@2685: * less than the skb header size, otherwise it will just attach the page as
fp@2685: * a frag to the skb.
fp@2685: *
fp@2685: * The function will then update the page offset if necessary and return
fp@2685: * true if the buffer can be reused by the adapter.
fp@2685: **/
fp@2685: static bool igb_add_rx_frag(struct igb_ring *rx_ring,
fp@2685: struct igb_rx_buffer *rx_buffer,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: struct page *page = rx_buffer->page;
fp@2685: unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
fp@2685: #if (PAGE_SIZE < 8192)
fp@2685: unsigned int truesize = IGB_RX_BUFSZ;
fp@2685: #else
fp@2685: unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
fp@2685: #endif
fp@2685:
fp@2685: if ((size <= IGB_RX_HDR_LEN) && !skb_is_nonlinear(skb)) {
fp@2685: unsigned char *va = page_address(page) + rx_buffer->page_offset;
fp@2685:
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
fp@2685: igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
fp@2685: va += IGB_TS_HDR_LEN;
fp@2685: size -= IGB_TS_HDR_LEN;
fp@2685: }
fp@2685:
fp@2685: memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
fp@2685:
fp@2685: /* we can reuse buffer as-is, just make sure it is local */
fp@2685: if (likely((page_to_nid(page) == numa_node_id()) &&
fp@2685: !page->pfmemalloc))
fp@2685: return true;
fp@2685:
fp@2685: /* this page cannot be reused so discard it */
fp@2685: put_page(page);
fp@2685: return false;
fp@2685: }
fp@2685:
fp@2685: skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
fp@2685: rx_buffer->page_offset, size, truesize);
fp@2685:
fp@2685: return igb_can_reuse_rx_page(rx_buffer, page, truesize);
fp@2685: }
fp@2685:
fp@2685: static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: struct igb_rx_buffer *rx_buffer;
fp@2685: struct page *page;
fp@2686: struct igb_adapter *adapter = netdev_priv(rx_ring->netdev);
fp@2685:
fp@2685: rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
fp@2685:
fp@2685: page = rx_buffer->page;
fp@2685: prefetchw(page);
fp@2685:
fp@2686: if (!adapter->ecdev && likely(!skb)) {
fp@2685: void *page_addr = page_address(page) +
fp@2685: rx_buffer->page_offset;
fp@2685:
fp@2685: /* prefetch first cache line of first page */
fp@2685: prefetch(page_addr);
fp@2685: #if L1_CACHE_BYTES < 128
fp@2685: prefetch(page_addr + L1_CACHE_BYTES);
fp@2685: #endif
fp@2685:
fp@2685: /* allocate a skb to store the frags */
fp@2685: skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
fp@2685: IGB_RX_HDR_LEN);
fp@2685: if (unlikely(!skb)) {
fp@2685: rx_ring->rx_stats.alloc_failed++;
fp@2685: return NULL;
fp@2685: }
fp@2685:
fp@2685: /* we will be copying header into skb->data in
fp@2685: * pskb_may_pull so it is in our interest to prefetch
fp@2685: * it now to avoid a possible cache miss
fp@2685: */
fp@2685: prefetchw(skb->data);
fp@2685: }
fp@2685:
fp@2685: /* we are reusing so sync this buffer for CPU use */
fp@2685: dma_sync_single_range_for_cpu(rx_ring->dev,
fp@2685: rx_buffer->dma,
fp@2685: rx_buffer->page_offset,
fp@2685: IGB_RX_BUFSZ,
fp@2685: DMA_FROM_DEVICE);
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: unsigned char *va =
fp@2686: page_address(rx_buffer->page) + rx_buffer->page_offset;
fp@2686: unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
fp@2686: ecdev_receive(adapter->ecdev, va, size);
fp@2723: adapter->ec_watchdog_jiffies = jiffies;
fp@2685: igb_reuse_rx_page(rx_ring, rx_buffer);
fp@2686: }
fp@2686: else {
fp@2686: /* pull page into skb */
fp@2686: if (igb_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
fp@2686: /* hand second half of page back to the ring */
fp@2686: igb_reuse_rx_page(rx_ring, rx_buffer);
fp@2686: } else {
fp@2686: /* we are not reusing the buffer so unmap it */
fp@2686: dma_unmap_page(rx_ring->dev, rx_buffer->dma,
fp@2686: PAGE_SIZE, DMA_FROM_DEVICE);
fp@2686: }
fp@2686:
fp@2686: /* clear contents of rx_buffer */
fp@2686: rx_buffer->page = NULL;
fp@2686: }
fp@2685:
fp@2685: return skb;
fp@2685: }
fp@2685:
fp@2685: static inline void igb_rx_checksum(struct igb_ring *ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: skb_checksum_none_assert(skb);
fp@2685:
fp@2685: /* Ignore Checksum bit is set */
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
fp@2685: return;
fp@2685:
fp@2685: /* Rx checksum disabled via ethtool */
fp@2685: if (!(ring->netdev->features & NETIF_F_RXCSUM))
fp@2685: return;
fp@2685:
fp@2685: /* TCP/UDP checksum error bit is set */
fp@2685: if (igb_test_staterr(rx_desc,
fp@2685: E1000_RXDEXT_STATERR_TCPE |
fp@2685: E1000_RXDEXT_STATERR_IPE)) {
fp@2685: /* work around errata with sctp packets where the TCPE aka
fp@2685: * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
fp@2685: * packets, (aka let the stack check the crc32c)
fp@2685: */
fp@2685: if (!((skb->len == 60) &&
fp@2685: test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
fp@2685: u64_stats_update_begin(&ring->rx_syncp);
fp@2685: ring->rx_stats.csum_err++;
fp@2685: u64_stats_update_end(&ring->rx_syncp);
fp@2685: }
fp@2685: /* let the stack verify checksum errors */
fp@2685: return;
fp@2685: }
fp@2685: /* It must be a TCP or UDP packet with a valid checksum */
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
fp@2685: E1000_RXD_STAT_UDPCS))
fp@2685: skb->ip_summed = CHECKSUM_UNNECESSARY;
fp@2685:
fp@2685: dev_dbg(ring->dev, "cksum success: bits %08X\n",
fp@2685: le32_to_cpu(rx_desc->wb.upper.status_error));
fp@2685: }
fp@2685:
fp@2685: static inline void igb_rx_hash(struct igb_ring *ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: if (ring->netdev->features & NETIF_F_RXHASH)
fp@2685: skb_set_hash(skb,
fp@2685: le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
fp@2685: PKT_HASH_TYPE_L3);
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_is_non_eop - process handling of non-EOP buffers
fp@2685: * @rx_ring: Rx ring being processed
fp@2685: * @rx_desc: Rx descriptor for current buffer
fp@2685: * @skb: current socket buffer containing buffer in progress
fp@2685: *
fp@2685: * This function updates next to clean. If the buffer is an EOP buffer
fp@2685: * this function exits returning false, otherwise it will place the
fp@2685: * sk_buff in the next buffer to be chained and return true indicating
fp@2685: * that this is in fact a non-EOP buffer.
fp@2685: **/
fp@2685: static bool igb_is_non_eop(struct igb_ring *rx_ring,
fp@2685: union e1000_adv_rx_desc *rx_desc)
fp@2685: {
fp@2685: u32 ntc = rx_ring->next_to_clean + 1;
fp@2685:
fp@2685: /* fetch, update, and store next to clean */
fp@2685: ntc = (ntc < rx_ring->count) ? ntc : 0;
fp@2685: rx_ring->next_to_clean = ntc;
fp@2685:
fp@2685: prefetch(IGB_RX_DESC(rx_ring, ntc));
fp@2685:
fp@2685: if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
fp@2685: return false;
fp@2685:
fp@2685: return true;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_pull_tail - igb specific version of skb_pull_tail
fp@2685: * @rx_ring: rx descriptor ring packet is being transacted on
fp@2685: * @rx_desc: pointer to the EOP Rx descriptor
fp@2685: * @skb: pointer to current skb being adjusted
fp@2685: *
fp@2685: * This function is an igb specific version of __pskb_pull_tail. The
fp@2685: * main difference between this version and the original function is that
fp@2685: * this function can make several assumptions about the state of things
fp@2685: * that allow for significant optimizations versus the standard function.
fp@2685: * As a result we can do things like drop a frag and maintain an accurate
fp@2685: * truesize for the skb.
fp@2685: */
fp@2685: static void igb_pull_tail(struct igb_ring *rx_ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
fp@2685: unsigned char *va;
fp@2685: unsigned int pull_len;
fp@2685:
fp@2685: /* it is valid to use page_address instead of kmap since we are
fp@2685: * working with pages allocated out of the lomem pool per
fp@2685: * alloc_page(GFP_ATOMIC)
fp@2685: */
fp@2685: va = skb_frag_address(frag);
fp@2685:
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
fp@2685: /* retrieve timestamp from buffer */
fp@2685: igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
fp@2685:
fp@2685: /* update pointers to remove timestamp header */
fp@2685: skb_frag_size_sub(frag, IGB_TS_HDR_LEN);
fp@2685: frag->page_offset += IGB_TS_HDR_LEN;
fp@2685: skb->data_len -= IGB_TS_HDR_LEN;
fp@2685: skb->len -= IGB_TS_HDR_LEN;
fp@2685:
fp@2685: /* move va to start of packet data */
fp@2685: va += IGB_TS_HDR_LEN;
fp@2685: }
fp@2685:
fp@2685: /* we need the header to contain the greater of either ETH_HLEN or
fp@2685: * 60 bytes if the skb->len is less than 60 for skb_pad.
fp@2685: */
fp@2685: pull_len = eth_get_headlen(va, IGB_RX_HDR_LEN);
fp@2685:
fp@2685: /* align pull length to size of long to optimize memcpy performance */
fp@2685: skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
fp@2685:
fp@2685: /* update all of the pointers */
fp@2685: skb_frag_size_sub(frag, pull_len);
fp@2685: frag->page_offset += pull_len;
fp@2685: skb->data_len -= pull_len;
fp@2685: skb->tail += pull_len;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_cleanup_headers - Correct corrupted or empty headers
fp@2685: * @rx_ring: rx descriptor ring packet is being transacted on
fp@2685: * @rx_desc: pointer to the EOP Rx descriptor
fp@2685: * @skb: pointer to current skb being fixed
fp@2685: *
fp@2685: * Address the case where we are pulling data in on pages only
fp@2685: * and as such no data is present in the skb header.
fp@2685: *
fp@2685: * In addition if skb is not at least 60 bytes we need to pad it so that
fp@2685: * it is large enough to qualify as a valid Ethernet frame.
fp@2685: *
fp@2685: * Returns true if an error was encountered and skb was freed.
fp@2685: **/
fp@2685: static bool igb_cleanup_headers(struct igb_ring *rx_ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: if (unlikely((igb_test_staterr(rx_desc,
fp@2685: E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
fp@2685: struct net_device *netdev = rx_ring->netdev;
fp@2685: if (!(netdev->features & NETIF_F_RXALL)) {
fp@2685: dev_kfree_skb_any(skb);
fp@2685: return true;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /* place header in linear portion of buffer */
fp@2685: if (skb_is_nonlinear(skb))
fp@2685: igb_pull_tail(rx_ring, rx_desc, skb);
fp@2685:
fp@2685: /* if skb_pad returns an error the skb was freed */
fp@2685: if (unlikely(skb->len < 60)) {
fp@2685: int pad_len = 60 - skb->len;
fp@2685:
fp@2685: if (skb_pad(skb, pad_len))
fp@2685: return true;
fp@2685: __skb_put(skb, pad_len);
fp@2685: }
fp@2685:
fp@2685: return false;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_process_skb_fields - Populate skb header fields from Rx descriptor
fp@2685: * @rx_ring: rx descriptor ring packet is being transacted on
fp@2685: * @rx_desc: pointer to the EOP Rx descriptor
fp@2685: * @skb: pointer to current skb being populated
fp@2685: *
fp@2685: * This function checks the ring, descriptor, and packet information in
fp@2685: * order to populate the hash, checksum, VLAN, timestamp, protocol, and
fp@2685: * other fields within the skb.
fp@2685: **/
fp@2685: static void igb_process_skb_fields(struct igb_ring *rx_ring,
fp@2685: union e1000_adv_rx_desc *rx_desc,
fp@2685: struct sk_buff *skb)
fp@2685: {
fp@2685: struct net_device *dev = rx_ring->netdev;
fp@2685:
fp@2685: igb_rx_hash(rx_ring, rx_desc, skb);
fp@2685:
fp@2685: igb_rx_checksum(rx_ring, rx_desc, skb);
fp@2685:
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS) &&
fp@2685: !igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
fp@2685: igb_ptp_rx_rgtstamp(rx_ring->q_vector, skb);
fp@2685:
fp@2685: if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
fp@2685: igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
fp@2685: u16 vid;
fp@2685:
fp@2685: if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
fp@2685: test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
fp@2685: vid = be16_to_cpu(rx_desc->wb.upper.vlan);
fp@2685: else
fp@2685: vid = le16_to_cpu(rx_desc->wb.upper.vlan);
fp@2685:
fp@2685: __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
fp@2685: }
fp@2685:
fp@2685: skb_record_rx_queue(skb, rx_ring->queue_index);
fp@2685:
fp@2685: skb->protocol = eth_type_trans(skb, rx_ring->netdev);
fp@2685: }
fp@2685:
fp@2685: static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
fp@2685: {
fp@2685: struct igb_ring *rx_ring = q_vector->rx.ring;
fp@2686: struct igb_adapter *adapter = netdev_priv(rx_ring->netdev);
fp@2685: struct sk_buff *skb = rx_ring->skb;
fp@2685: unsigned int total_bytes = 0, total_packets = 0;
fp@2685: u16 cleaned_count = igb_desc_unused(rx_ring);
fp@2685:
fp@2685: while (likely(total_packets < budget)) {
fp@2685: union e1000_adv_rx_desc *rx_desc;
fp@2685:
fp@2685: /* return some buffers to hardware, one at a time is too slow */
fp@2685: if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
fp@2685: igb_alloc_rx_buffers(rx_ring, cleaned_count);
fp@2685: cleaned_count = 0;
fp@2685: }
fp@2685:
fp@2685: rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
fp@2685:
fp@2685: if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
fp@2685: break;
fp@2685:
fp@2685: /* This memory barrier is needed to keep us from reading
fp@2685: * any other fields out of the rx_desc until we know the
fp@2685: * RXD_STAT_DD bit is set
fp@2685: */
fp@2685: rmb();
fp@2685:
fp@2685: /* retrieve a buffer from the ring */
fp@2685: skb = igb_fetch_rx_buffer(rx_ring, rx_desc, skb);
fp@2685:
fp@2685: /* exit if we failed to retrieve a buffer */
fp@2686: if (!adapter->ecdev && !skb) {
fp@2685: break;
fp@2686: }
fp@2685:
fp@2685: cleaned_count++;
fp@2685:
fp@2685: /* fetch next buffer in frame if non-eop */
fp@2685: if (igb_is_non_eop(rx_ring, rx_desc))
fp@2685: continue;
fp@2685:
fp@2686: if (adapter->ecdev) {
fp@2686: total_packets++;
fp@2686: continue;
fp@2686: }
fp@2686:
fp@2685: /* verify the packet layout is correct */
fp@2685: if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
fp@2685: skb = NULL;
fp@2685: continue;
fp@2685: }
fp@2685:
fp@2685: /* probably a little skewed due to removing CRC */
fp@2685: total_bytes += skb->len;
fp@2685:
fp@2685: /* populate checksum, timestamp, VLAN, and protocol */
fp@2685: igb_process_skb_fields(rx_ring, rx_desc, skb);
fp@2685:
fp@2685: napi_gro_receive(&q_vector->napi, skb);
fp@2685:
fp@2685: /* reset skb pointer */
fp@2685: skb = NULL;
fp@2685:
fp@2685: /* update budget accounting */
fp@2685: total_packets++;
fp@2685: }
fp@2685:
fp@2685: /* place incomplete frames back on ring for completion */
fp@2685: rx_ring->skb = skb;
fp@2685:
fp@2685: u64_stats_update_begin(&rx_ring->rx_syncp);
fp@2685: rx_ring->rx_stats.packets += total_packets;
fp@2685: rx_ring->rx_stats.bytes += total_bytes;
fp@2685: u64_stats_update_end(&rx_ring->rx_syncp);
fp@2685: q_vector->rx.total_packets += total_packets;
fp@2685: q_vector->rx.total_bytes += total_bytes;
fp@2685:
fp@2685: if (cleaned_count)
fp@2685: igb_alloc_rx_buffers(rx_ring, cleaned_count);
fp@2685:
fp@2685: return total_packets < budget;
fp@2685: }
fp@2685:
fp@2685: static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
fp@2685: struct igb_rx_buffer *bi)
fp@2685: {
fp@2685: struct page *page = bi->page;
fp@2685: dma_addr_t dma;
fp@2685:
fp@2685: /* since we are recycling buffers we should seldom need to alloc */
fp@2685: if (likely(page))
fp@2685: return true;
fp@2685:
fp@2685: /* alloc new page for storage */
fp@2685: page = __skb_alloc_page(GFP_ATOMIC | __GFP_COLD, NULL);
fp@2685: if (unlikely(!page)) {
fp@2685: rx_ring->rx_stats.alloc_failed++;
fp@2685: return false;
fp@2685: }
fp@2685:
fp@2685: /* map page for use */
fp@2685: dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
fp@2685:
fp@2685: /* if mapping failed free memory back to system since
fp@2685: * there isn't much point in holding memory we can't use
fp@2685: */
fp@2685: if (dma_mapping_error(rx_ring->dev, dma)) {
fp@2685: __free_page(page);
fp@2685:
fp@2685: rx_ring->rx_stats.alloc_failed++;
fp@2685: return false;
fp@2685: }
fp@2685:
fp@2685: bi->dma = dma;
fp@2685: bi->page = page;
fp@2685: bi->page_offset = 0;
fp@2685:
fp@2685: return true;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_alloc_rx_buffers - Replace used receive buffers; packet split
fp@2685: * @adapter: address of board private structure
fp@2685: **/
fp@2685: void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
fp@2685: {
fp@2685: union e1000_adv_rx_desc *rx_desc;
fp@2685: struct igb_rx_buffer *bi;
fp@2685: u16 i = rx_ring->next_to_use;
fp@2685:
fp@2685: /* nothing to do */
fp@2685: if (!cleaned_count)
fp@2685: return;
fp@2685:
fp@2685: rx_desc = IGB_RX_DESC(rx_ring, i);
fp@2685: bi = &rx_ring->rx_buffer_info[i];
fp@2685: i -= rx_ring->count;
fp@2685:
fp@2685: do {
fp@2685: if (!igb_alloc_mapped_page(rx_ring, bi))
fp@2685: break;
fp@2685:
fp@2685: /* Refresh the desc even if buffer_addrs didn't change
fp@2685: * because each write-back erases this info.
fp@2685: */
fp@2685: rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
fp@2685:
fp@2685: rx_desc++;
fp@2685: bi++;
fp@2685: i++;
fp@2685: if (unlikely(!i)) {
fp@2685: rx_desc = IGB_RX_DESC(rx_ring, 0);
fp@2685: bi = rx_ring->rx_buffer_info;
fp@2685: i -= rx_ring->count;
fp@2685: }
fp@2685:
fp@2685: /* clear the hdr_addr for the next_to_use descriptor */
fp@2685: rx_desc->read.hdr_addr = 0;
fp@2685:
fp@2685: cleaned_count--;
fp@2685: } while (cleaned_count);
fp@2685:
fp@2685: i += rx_ring->count;
fp@2685:
fp@2685: if (rx_ring->next_to_use != i) {
fp@2685: /* record the next descriptor to use */
fp@2685: rx_ring->next_to_use = i;
fp@2685:
fp@2685: /* update next to alloc since we have filled the ring */
fp@2685: rx_ring->next_to_alloc = i;
fp@2685:
fp@2685: /* Force memory writes to complete before letting h/w
fp@2685: * know there are new descriptors to fetch. (Only
fp@2685: * applicable for weak-ordered memory model archs,
fp@2685: * such as IA-64).
fp@2685: */
fp@2685: wmb();
fp@2685: writel(i, rx_ring->tail);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_mii_ioctl -
fp@2685: * @netdev:
fp@2685: * @ifreq:
fp@2685: * @cmd:
fp@2685: **/
fp@2685: static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct mii_ioctl_data *data = if_mii(ifr);
fp@2685:
fp@2685: if (adapter->hw.phy.media_type != e1000_media_type_copper)
fp@2685: return -EOPNOTSUPP;
fp@2685:
fp@2685: switch (cmd) {
fp@2685: case SIOCGMIIPHY:
fp@2685: data->phy_id = adapter->hw.phy.addr;
fp@2685: break;
fp@2685: case SIOCGMIIREG:
fp@2685: if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
fp@2685: &data->val_out))
fp@2685: return -EIO;
fp@2685: break;
fp@2685: case SIOCSMIIREG:
fp@2685: default:
fp@2685: return -EOPNOTSUPP;
fp@2685: }
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_ioctl -
fp@2685: * @netdev:
fp@2685: * @ifreq:
fp@2685: * @cmd:
fp@2685: **/
fp@2685: static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
fp@2685: {
fp@2685: switch (cmd) {
fp@2685: case SIOCGMIIPHY:
fp@2685: case SIOCGMIIREG:
fp@2685: case SIOCSMIIREG:
fp@2685: return igb_mii_ioctl(netdev, ifr, cmd);
fp@2685: case SIOCGHWTSTAMP:
fp@2685: return igb_ptp_get_ts_config(netdev, ifr);
fp@2685: case SIOCSHWTSTAMP:
fp@2685: return igb_ptp_set_ts_config(netdev, ifr);
fp@2685: default:
fp@2685: return -EOPNOTSUPP;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
fp@2685: {
fp@2685: struct igb_adapter *adapter = hw->back;
fp@2685:
fp@2685: pci_read_config_word(adapter->pdev, reg, value);
fp@2685: }
fp@2685:
fp@2685: void igb_write_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
fp@2685: {
fp@2685: struct igb_adapter *adapter = hw->back;
fp@2685:
fp@2685: pci_write_config_word(adapter->pdev, reg, *value);
fp@2685: }
fp@2685:
fp@2685: s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
fp@2685: {
fp@2685: struct igb_adapter *adapter = hw->back;
fp@2685:
fp@2685: if (pcie_capability_read_word(adapter->pdev, reg, value))
fp@2685: return -E1000_ERR_CONFIG;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
fp@2685: {
fp@2685: struct igb_adapter *adapter = hw->back;
fp@2685:
fp@2685: if (pcie_capability_write_word(adapter->pdev, reg, *value))
fp@2685: return -E1000_ERR_CONFIG;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ctrl, rctl;
fp@2685: bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
fp@2685:
fp@2685: if (enable) {
fp@2685: /* enable VLAN tag insert/strip */
fp@2685: ctrl = rd32(E1000_CTRL);
fp@2685: ctrl |= E1000_CTRL_VME;
fp@2685: wr32(E1000_CTRL, ctrl);
fp@2685:
fp@2685: /* Disable CFI check */
fp@2685: rctl = rd32(E1000_RCTL);
fp@2685: rctl &= ~E1000_RCTL_CFIEN;
fp@2685: wr32(E1000_RCTL, rctl);
fp@2685: } else {
fp@2685: /* disable VLAN tag insert/strip */
fp@2685: ctrl = rd32(E1000_CTRL);
fp@2685: ctrl &= ~E1000_CTRL_VME;
fp@2685: wr32(E1000_CTRL, ctrl);
fp@2685: }
fp@2685:
fp@2685: igb_rlpml_set(adapter);
fp@2685: }
fp@2685:
fp@2685: static int igb_vlan_rx_add_vid(struct net_device *netdev,
fp@2685: __be16 proto, u16 vid)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int pf_id = adapter->vfs_allocated_count;
fp@2685:
fp@2685: /* attempt to add filter to vlvf array */
fp@2685: igb_vlvf_set(adapter, vid, true, pf_id);
fp@2685:
fp@2685: /* add the filter since PF can receive vlans w/o entry in vlvf */
fp@2685: igb_vfta_set(hw, vid, true);
fp@2685:
fp@2685: set_bit(vid, adapter->active_vlans);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_vlan_rx_kill_vid(struct net_device *netdev,
fp@2685: __be16 proto, u16 vid)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int pf_id = adapter->vfs_allocated_count;
fp@2685: s32 err;
fp@2685:
fp@2685: /* remove vlan from VLVF table array */
fp@2685: err = igb_vlvf_set(adapter, vid, false, pf_id);
fp@2685:
fp@2685: /* if vid was not present in VLVF just remove it from table */
fp@2685: if (err)
fp@2685: igb_vfta_set(hw, vid, false);
fp@2685:
fp@2685: clear_bit(vid, adapter->active_vlans);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_restore_vlan(struct igb_adapter *adapter)
fp@2685: {
fp@2685: u16 vid;
fp@2685:
fp@2685: igb_vlan_mode(adapter->netdev, adapter->netdev->features);
fp@2685:
fp@2685: for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
fp@2685: igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
fp@2685: }
fp@2685:
fp@2685: int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
fp@2685: {
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: struct e1000_mac_info *mac = &adapter->hw.mac;
fp@2685:
fp@2685: mac->autoneg = 0;
fp@2685:
fp@2685: /* Make sure dplx is at most 1 bit and lsb of speed is not set
fp@2685: * for the switch() below to work
fp@2685: */
fp@2685: if ((spd & 1) || (dplx & ~1))
fp@2685: goto err_inval;
fp@2685:
fp@2685: /* Fiber NIC's only allow 1000 gbps Full duplex
fp@2685: * and 100Mbps Full duplex for 100baseFx sfp
fp@2685: */
fp@2685: if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
fp@2685: switch (spd + dplx) {
fp@2685: case SPEED_10 + DUPLEX_HALF:
fp@2685: case SPEED_10 + DUPLEX_FULL:
fp@2685: case SPEED_100 + DUPLEX_HALF:
fp@2685: goto err_inval;
fp@2685: default:
fp@2685: break;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: switch (spd + dplx) {
fp@2685: case SPEED_10 + DUPLEX_HALF:
fp@2685: mac->forced_speed_duplex = ADVERTISE_10_HALF;
fp@2685: break;
fp@2685: case SPEED_10 + DUPLEX_FULL:
fp@2685: mac->forced_speed_duplex = ADVERTISE_10_FULL;
fp@2685: break;
fp@2685: case SPEED_100 + DUPLEX_HALF:
fp@2685: mac->forced_speed_duplex = ADVERTISE_100_HALF;
fp@2685: break;
fp@2685: case SPEED_100 + DUPLEX_FULL:
fp@2685: mac->forced_speed_duplex = ADVERTISE_100_FULL;
fp@2685: break;
fp@2685: case SPEED_1000 + DUPLEX_FULL:
fp@2685: mac->autoneg = 1;
fp@2685: adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
fp@2685: break;
fp@2685: case SPEED_1000 + DUPLEX_HALF: /* not supported */
fp@2685: default:
fp@2685: goto err_inval;
fp@2685: }
fp@2685:
fp@2685: /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
fp@2685: adapter->hw.phy.mdix = AUTO_ALL_MODES;
fp@2685:
fp@2685: return 0;
fp@2685:
fp@2685: err_inval:
fp@2685: dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
fp@2685: return -EINVAL;
fp@2685: }
fp@2685:
fp@2685: static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
fp@2685: bool runtime)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 ctrl, rctl, status;
fp@2685: u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
fp@2685: #ifdef CONFIG_PM
fp@2685: int retval = 0;
fp@2685: #endif
fp@2685:
fp@2685: netif_device_detach(netdev);
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: __igb_close(netdev, true);
fp@2685:
fp@2685: igb_clear_interrupt_scheme(adapter);
fp@2685:
fp@2685: #ifdef CONFIG_PM
fp@2685: retval = pci_save_state(pdev);
fp@2685: if (retval)
fp@2685: return retval;
fp@2685: #endif
fp@2685:
fp@2685: status = rd32(E1000_STATUS);
fp@2685: if (status & E1000_STATUS_LU)
fp@2685: wufc &= ~E1000_WUFC_LNKC;
fp@2685:
fp@2685: if (wufc) {
fp@2685: igb_setup_rctl(adapter);
fp@2685: igb_set_rx_mode(netdev);
fp@2685:
fp@2685: /* turn on all-multi mode if wake on multicast is enabled */
fp@2685: if (wufc & E1000_WUFC_MC) {
fp@2685: rctl = rd32(E1000_RCTL);
fp@2685: rctl |= E1000_RCTL_MPE;
fp@2685: wr32(E1000_RCTL, rctl);
fp@2685: }
fp@2685:
fp@2685: ctrl = rd32(E1000_CTRL);
fp@2685: /* advertise wake from D3Cold */
fp@2685: #define E1000_CTRL_ADVD3WUC 0x00100000
fp@2685: /* phy power management enable */
fp@2685: #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
fp@2685: ctrl |= E1000_CTRL_ADVD3WUC;
fp@2685: wr32(E1000_CTRL, ctrl);
fp@2685:
fp@2685: /* Allow time for pending master requests to run */
fp@2685: igb_disable_pcie_master(hw);
fp@2685:
fp@2685: wr32(E1000_WUC, E1000_WUC_PME_EN);
fp@2685: wr32(E1000_WUFC, wufc);
fp@2685: } else {
fp@2685: wr32(E1000_WUC, 0);
fp@2685: wr32(E1000_WUFC, 0);
fp@2685: }
fp@2685:
fp@2685: *enable_wake = wufc || adapter->en_mng_pt;
fp@2685: if (!*enable_wake)
fp@2685: igb_power_down_link(adapter);
fp@2685: else
fp@2685: igb_power_up_link(adapter);
fp@2685:
fp@2685: /* Release control of h/w to f/w. If f/w is AMT enabled, this
fp@2685: * would have already happened in close and is redundant.
fp@2685: */
fp@2685: igb_release_hw_control(adapter);
fp@2685:
fp@2685: pci_disable_device(pdev);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_PM
fp@2685: #ifdef CONFIG_PM_SLEEP
fp@2685: static int igb_suspend(struct device *dev)
fp@2685: {
fp@2685: int retval;
fp@2685: bool wake;
fp@2685: struct pci_dev *pdev = to_pci_dev(dev);
fp@2685:
fp@2685: retval = __igb_shutdown(pdev, &wake, 0);
fp@2685: if (retval)
fp@2685: return retval;
fp@2685:
fp@2685: if (wake) {
fp@2685: pci_prepare_to_sleep(pdev);
fp@2685: } else {
fp@2685: pci_wake_from_d3(pdev, false);
fp@2685: pci_set_power_state(pdev, PCI_D3hot);
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685: #endif /* CONFIG_PM_SLEEP */
fp@2685:
fp@2685: static int igb_resume(struct device *dev)
fp@2685: {
fp@2685: struct pci_dev *pdev = to_pci_dev(dev);
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 err;
fp@2685:
fp@2685: pci_set_power_state(pdev, PCI_D0);
fp@2685: pci_restore_state(pdev);
fp@2685: pci_save_state(pdev);
fp@2685:
fp@2685: if (!pci_device_is_present(pdev))
fp@2685: return -ENODEV;
fp@2685: err = pci_enable_device_mem(pdev);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "igb: Cannot enable PCI device from suspend\n");
fp@2685: return err;
fp@2685: }
fp@2685: pci_set_master(pdev);
fp@2685:
fp@2685: pci_enable_wake(pdev, PCI_D3hot, 0);
fp@2685: pci_enable_wake(pdev, PCI_D3cold, 0);
fp@2685:
fp@2685: if (igb_init_interrupt_scheme(adapter, true)) {
fp@2685: dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: igb_reset(adapter);
fp@2685:
fp@2685: /* let the f/w know that the h/w is now under the control of the
fp@2685: * driver.
fp@2685: */
fp@2685: igb_get_hw_control(adapter);
fp@2685:
fp@2685: wr32(E1000_WUS, ~0);
fp@2685:
fp@2685: if (netdev->flags & IFF_UP) {
fp@2685: rtnl_lock();
fp@2685: err = __igb_open(netdev, true);
fp@2685: rtnl_unlock();
fp@2685: if (err)
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: netif_device_attach(netdev);
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_PM_RUNTIME
fp@2685: static int igb_runtime_idle(struct device *dev)
fp@2685: {
fp@2685: struct pci_dev *pdev = to_pci_dev(dev);
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: if (!igb_has_link(adapter))
fp@2685: pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
fp@2685:
fp@2685: return -EBUSY;
fp@2685: }
fp@2685:
fp@2685: static int igb_runtime_suspend(struct device *dev)
fp@2685: {
fp@2685: struct pci_dev *pdev = to_pci_dev(dev);
fp@2685: int retval;
fp@2685: bool wake;
fp@2685:
fp@2685: retval = __igb_shutdown(pdev, &wake, 1);
fp@2685: if (retval)
fp@2685: return retval;
fp@2685:
fp@2685: if (wake) {
fp@2685: pci_prepare_to_sleep(pdev);
fp@2685: } else {
fp@2685: pci_wake_from_d3(pdev, false);
fp@2685: pci_set_power_state(pdev, PCI_D3hot);
fp@2685: }
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_runtime_resume(struct device *dev)
fp@2685: {
fp@2685: return igb_resume(dev);
fp@2685: }
fp@2685: #endif /* CONFIG_PM_RUNTIME */
fp@2685: #endif
fp@2685:
fp@2685: static void igb_shutdown(struct pci_dev *pdev)
fp@2685: {
fp@2685: bool wake;
fp@2685:
fp@2685: __igb_shutdown(pdev, &wake, 0);
fp@2685:
fp@2685: if (system_state == SYSTEM_POWER_OFF) {
fp@2685: pci_wake_from_d3(pdev, wake);
fp@2685: pci_set_power_state(pdev, PCI_D3hot);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: static int igb_sriov_reinit(struct pci_dev *dev)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(dev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685:
fp@2685: rtnl_lock();
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_close(netdev);
fp@2685: else
fp@2685: igb_reset(adapter);
fp@2685:
fp@2685: igb_clear_interrupt_scheme(adapter);
fp@2685:
fp@2685: igb_init_queue_configuration(adapter);
fp@2685:
fp@2685: if (igb_init_interrupt_scheme(adapter, true)) {
fp@2685: dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_open(netdev);
fp@2685:
fp@2685: rtnl_unlock();
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_pci_disable_sriov(struct pci_dev *dev)
fp@2685: {
fp@2685: int err = igb_disable_sriov(dev);
fp@2685:
fp@2685: if (!err)
fp@2685: err = igb_sriov_reinit(dev);
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs)
fp@2685: {
fp@2685: int err = igb_enable_sriov(dev, num_vfs);
fp@2685:
fp@2685: if (err)
fp@2685: goto out;
fp@2685:
fp@2685: err = igb_sriov_reinit(dev);
fp@2685: if (!err)
fp@2685: return num_vfs;
fp@2685:
fp@2685: out:
fp@2685: return err;
fp@2685: }
fp@2685:
fp@2685: #endif
fp@2685: static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
fp@2685: {
fp@2685: #ifdef CONFIG_PCI_IOV
fp@2685: if (num_vfs == 0)
fp@2685: return igb_pci_disable_sriov(dev);
fp@2685: else
fp@2685: return igb_pci_enable_sriov(dev, num_vfs);
fp@2685: #endif
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: #ifdef CONFIG_NET_POLL_CONTROLLER
fp@2685: /* Polling 'interrupt' - used by things like netconsole to send skbs
fp@2685: * without having to re-enable interrupts. It's not called while
fp@2685: * the interrupt routine is executing.
fp@2685: */
fp@2685: static void igb_netpoll(struct net_device *netdev)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: struct igb_q_vector *q_vector;
fp@2685: int i;
fp@2685:
fp@2685: for (i = 0; i < adapter->num_q_vectors; i++) {
fp@2685: q_vector = adapter->q_vector[i];
fp@2685: if (adapter->flags & IGB_FLAG_HAS_MSIX)
fp@2685: wr32(E1000_EIMC, q_vector->eims_value);
fp@2685: else
fp@2685: igb_irq_disable(adapter);
fp@2685: napi_schedule(&q_vector->napi);
fp@2685: }
fp@2685: }
fp@2685: #endif /* CONFIG_NET_POLL_CONTROLLER */
fp@2685:
fp@2685: /**
fp@2685: * igb_io_error_detected - called when PCI error is detected
fp@2685: * @pdev: Pointer to PCI device
fp@2685: * @state: The current pci connection state
fp@2685: *
fp@2685: * This function is called after a PCI bus error affecting
fp@2685: * this device has been detected.
fp@2685: **/
fp@2685: static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
fp@2685: pci_channel_state_t state)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: netif_device_detach(netdev);
fp@2685:
fp@2685: if (state == pci_channel_io_perm_failure)
fp@2685: return PCI_ERS_RESULT_DISCONNECT;
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_down(adapter);
fp@2685: pci_disable_device(pdev);
fp@2685:
fp@2685: /* Request a slot slot reset. */
fp@2685: return PCI_ERS_RESULT_NEED_RESET;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_io_slot_reset - called after the pci bus has been reset.
fp@2685: * @pdev: Pointer to PCI device
fp@2685: *
fp@2685: * Restart the card from scratch, as if from a cold-boot. Implementation
fp@2685: * resembles the first-half of the igb_resume routine.
fp@2685: **/
fp@2685: static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: pci_ers_result_t result;
fp@2685: int err;
fp@2685:
fp@2685: if (pci_enable_device_mem(pdev)) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "Cannot re-enable PCI device after reset.\n");
fp@2685: result = PCI_ERS_RESULT_DISCONNECT;
fp@2685: } else {
fp@2685: pci_set_master(pdev);
fp@2685: pci_restore_state(pdev);
fp@2685: pci_save_state(pdev);
fp@2685:
fp@2685: pci_enable_wake(pdev, PCI_D3hot, 0);
fp@2685: pci_enable_wake(pdev, PCI_D3cold, 0);
fp@2685:
fp@2685: igb_reset(adapter);
fp@2685: wr32(E1000_WUS, ~0);
fp@2685: result = PCI_ERS_RESULT_RECOVERED;
fp@2685: }
fp@2685:
fp@2685: err = pci_cleanup_aer_uncorrect_error_status(pdev);
fp@2685: if (err) {
fp@2685: dev_err(&pdev->dev,
fp@2685: "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
fp@2685: err);
fp@2685: /* non-fatal, continue */
fp@2685: }
fp@2685:
fp@2685: return result;
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_io_resume - called when traffic can start flowing again.
fp@2685: * @pdev: Pointer to PCI device
fp@2685: *
fp@2685: * This callback is called when the error recovery driver tells us that
fp@2685: * its OK to resume normal operation. Implementation resembles the
fp@2685: * second-half of the igb_resume routine.
fp@2685: */
fp@2685: static void igb_io_resume(struct pci_dev *pdev)
fp@2685: {
fp@2685: struct net_device *netdev = pci_get_drvdata(pdev);
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685:
fp@2685: if (netif_running(netdev)) {
fp@2685: if (igb_up(adapter)) {
fp@2685: dev_err(&pdev->dev, "igb_up failed after reset\n");
fp@2685: return;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: netif_device_attach(netdev);
fp@2685:
fp@2685: /* let the f/w know that the h/w is now under the control of the
fp@2685: * driver.
fp@2685: */
fp@2685: igb_get_hw_control(adapter);
fp@2685: }
fp@2685:
fp@2685: static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
fp@2685: u8 qsel)
fp@2685: {
fp@2685: u32 rar_low, rar_high;
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685:
fp@2685: /* HW expects these in little endian so we reverse the byte order
fp@2685: * from network order (big endian) to little endian
fp@2685: */
fp@2685: rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
fp@2685: ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
fp@2685: rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
fp@2685:
fp@2685: /* Indicate to hardware the Address is Valid. */
fp@2685: rar_high |= E1000_RAH_AV;
fp@2685:
fp@2685: if (hw->mac.type == e1000_82575)
fp@2685: rar_high |= E1000_RAH_POOL_1 * qsel;
fp@2685: else
fp@2685: rar_high |= E1000_RAH_POOL_1 << qsel;
fp@2685:
fp@2685: wr32(E1000_RAL(index), rar_low);
fp@2685: wrfl();
fp@2685: wr32(E1000_RAH(index), rar_high);
fp@2685: wrfl();
fp@2685: }
fp@2685:
fp@2685: static int igb_set_vf_mac(struct igb_adapter *adapter,
fp@2685: int vf, unsigned char *mac_addr)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: /* VF MAC addresses start at end of receive addresses and moves
fp@2685: * towards the first, as a result a collision should not be possible
fp@2685: */
fp@2685: int rar_entry = hw->mac.rar_entry_count - (vf + 1);
fp@2685:
fp@2685: memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
fp@2685:
fp@2685: igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
fp@2685: return -EINVAL;
fp@2685: adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
fp@2685: dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
fp@2685: dev_info(&adapter->pdev->dev,
fp@2685: "Reload the VF driver to make this change effective.");
fp@2685: if (test_bit(__IGB_DOWN, &adapter->state)) {
fp@2685: dev_warn(&adapter->pdev->dev,
fp@2685: "The VF MAC address has been set, but the PF device is not up.\n");
fp@2685: dev_warn(&adapter->pdev->dev,
fp@2685: "Bring the PF device up before attempting to use the VF device.\n");
fp@2685: }
fp@2685: return igb_set_vf_mac(adapter, vf, mac);
fp@2685: }
fp@2685:
fp@2685: static int igb_link_mbps(int internal_link_speed)
fp@2685: {
fp@2685: switch (internal_link_speed) {
fp@2685: case SPEED_100:
fp@2685: return 100;
fp@2685: case SPEED_1000:
fp@2685: return 1000;
fp@2685: default:
fp@2685: return 0;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
fp@2685: int link_speed)
fp@2685: {
fp@2685: int rf_dec, rf_int;
fp@2685: u32 bcnrc_val;
fp@2685:
fp@2685: if (tx_rate != 0) {
fp@2685: /* Calculate the rate factor values to set */
fp@2685: rf_int = link_speed / tx_rate;
fp@2685: rf_dec = (link_speed - (rf_int * tx_rate));
fp@2685: rf_dec = (rf_dec * (1 << E1000_RTTBCNRC_RF_INT_SHIFT)) /
fp@2685: tx_rate;
fp@2685:
fp@2685: bcnrc_val = E1000_RTTBCNRC_RS_ENA;
fp@2685: bcnrc_val |= ((rf_int << E1000_RTTBCNRC_RF_INT_SHIFT) &
fp@2685: E1000_RTTBCNRC_RF_INT_MASK);
fp@2685: bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
fp@2685: } else {
fp@2685: bcnrc_val = 0;
fp@2685: }
fp@2685:
fp@2685: wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
fp@2685: /* Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
fp@2685: * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
fp@2685: */
fp@2685: wr32(E1000_RTTBCNRM, 0x14);
fp@2685: wr32(E1000_RTTBCNRC, bcnrc_val);
fp@2685: }
fp@2685:
fp@2685: static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
fp@2685: {
fp@2685: int actual_link_speed, i;
fp@2685: bool reset_rate = false;
fp@2685:
fp@2685: /* VF TX rate limit was not set or not supported */
fp@2685: if ((adapter->vf_rate_link_speed == 0) ||
fp@2685: (adapter->hw.mac.type != e1000_82576))
fp@2685: return;
fp@2685:
fp@2685: actual_link_speed = igb_link_mbps(adapter->link_speed);
fp@2685: if (actual_link_speed != adapter->vf_rate_link_speed) {
fp@2685: reset_rate = true;
fp@2685: adapter->vf_rate_link_speed = 0;
fp@2685: dev_info(&adapter->pdev->dev,
fp@2685: "Link speed has been changed. VF Transmit rate is disabled\n");
fp@2685: }
fp@2685:
fp@2685: for (i = 0; i < adapter->vfs_allocated_count; i++) {
fp@2685: if (reset_rate)
fp@2685: adapter->vf_data[i].tx_rate = 0;
fp@2685:
fp@2685: igb_set_vf_rate_limit(&adapter->hw, i,
fp@2685: adapter->vf_data[i].tx_rate,
fp@2685: actual_link_speed);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf,
fp@2685: int min_tx_rate, int max_tx_rate)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: int actual_link_speed;
fp@2685:
fp@2685: if (hw->mac.type != e1000_82576)
fp@2685: return -EOPNOTSUPP;
fp@2685:
fp@2685: if (min_tx_rate)
fp@2685: return -EINVAL;
fp@2685:
fp@2685: actual_link_speed = igb_link_mbps(adapter->link_speed);
fp@2685: if ((vf >= adapter->vfs_allocated_count) ||
fp@2685: (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
fp@2685: (max_tx_rate < 0) ||
fp@2685: (max_tx_rate > actual_link_speed))
fp@2685: return -EINVAL;
fp@2685:
fp@2685: adapter->vf_rate_link_speed = actual_link_speed;
fp@2685: adapter->vf_data[vf].tx_rate = (u16)max_tx_rate;
fp@2685: igb_set_vf_rate_limit(hw, vf, max_tx_rate, actual_link_speed);
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
fp@2685: bool setting)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 reg_val, reg_offset;
fp@2685:
fp@2685: if (!adapter->vfs_allocated_count)
fp@2685: return -EOPNOTSUPP;
fp@2685:
fp@2685: if (vf >= adapter->vfs_allocated_count)
fp@2685: return -EINVAL;
fp@2685:
fp@2685: reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
fp@2685: reg_val = rd32(reg_offset);
fp@2685: if (setting)
fp@2685: reg_val |= ((1 << vf) |
fp@2685: (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
fp@2685: else
fp@2685: reg_val &= ~((1 << vf) |
fp@2685: (1 << (vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT)));
fp@2685: wr32(reg_offset, reg_val);
fp@2685:
fp@2685: adapter->vf_data[vf].spoofchk_enabled = setting;
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static int igb_ndo_get_vf_config(struct net_device *netdev,
fp@2685: int vf, struct ifla_vf_info *ivi)
fp@2685: {
fp@2685: struct igb_adapter *adapter = netdev_priv(netdev);
fp@2685: if (vf >= adapter->vfs_allocated_count)
fp@2685: return -EINVAL;
fp@2685: ivi->vf = vf;
fp@2685: memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
fp@2685: ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
fp@2685: ivi->min_tx_rate = 0;
fp@2685: ivi->vlan = adapter->vf_data[vf].pf_vlan;
fp@2685: ivi->qos = adapter->vf_data[vf].pf_qos;
fp@2685: ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_vmm_control(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 reg;
fp@2685:
fp@2685: switch (hw->mac.type) {
fp@2685: case e1000_82575:
fp@2685: case e1000_i210:
fp@2685: case e1000_i211:
fp@2685: case e1000_i354:
fp@2685: default:
fp@2685: /* replication is not supported for 82575 */
fp@2685: return;
fp@2685: case e1000_82576:
fp@2685: /* notify HW that the MAC is adding vlan tags */
fp@2685: reg = rd32(E1000_DTXCTL);
fp@2685: reg |= E1000_DTXCTL_VLAN_ADDED;
fp@2685: wr32(E1000_DTXCTL, reg);
fp@2685: /* Fall through */
fp@2685: case e1000_82580:
fp@2685: /* enable replication vlan tag stripping */
fp@2685: reg = rd32(E1000_RPLOLR);
fp@2685: reg |= E1000_RPLOLR_STRVLAN;
fp@2685: wr32(E1000_RPLOLR, reg);
fp@2685: /* Fall through */
fp@2685: case e1000_i350:
fp@2685: /* none of the above registers are supported by i350 */
fp@2685: break;
fp@2685: }
fp@2685:
fp@2685: if (adapter->vfs_allocated_count) {
fp@2685: igb_vmdq_set_loopback_pf(hw, true);
fp@2685: igb_vmdq_set_replication_pf(hw, true);
fp@2685: igb_vmdq_set_anti_spoofing_pf(hw, true,
fp@2685: adapter->vfs_allocated_count);
fp@2685: } else {
fp@2685: igb_vmdq_set_loopback_pf(hw, false);
fp@2685: igb_vmdq_set_replication_pf(hw, false);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
fp@2685: {
fp@2685: struct e1000_hw *hw = &adapter->hw;
fp@2685: u32 dmac_thr;
fp@2685: u16 hwm;
fp@2685:
fp@2685: if (hw->mac.type > e1000_82580) {
fp@2685: if (adapter->flags & IGB_FLAG_DMAC) {
fp@2685: u32 reg;
fp@2685:
fp@2685: /* force threshold to 0. */
fp@2685: wr32(E1000_DMCTXTH, 0);
fp@2685:
fp@2685: /* DMA Coalescing high water mark needs to be greater
fp@2685: * than the Rx threshold. Set hwm to PBA - max frame
fp@2685: * size in 16B units, capping it at PBA - 6KB.
fp@2685: */
fp@2685: hwm = 64 * pba - adapter->max_frame_size / 16;
fp@2685: if (hwm < 64 * (pba - 6))
fp@2685: hwm = 64 * (pba - 6);
fp@2685: reg = rd32(E1000_FCRTC);
fp@2685: reg &= ~E1000_FCRTC_RTH_COAL_MASK;
fp@2685: reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
fp@2685: & E1000_FCRTC_RTH_COAL_MASK);
fp@2685: wr32(E1000_FCRTC, reg);
fp@2685:
fp@2685: /* Set the DMA Coalescing Rx threshold to PBA - 2 * max
fp@2685: * frame size, capping it at PBA - 10KB.
fp@2685: */
fp@2685: dmac_thr = pba - adapter->max_frame_size / 512;
fp@2685: if (dmac_thr < pba - 10)
fp@2685: dmac_thr = pba - 10;
fp@2685: reg = rd32(E1000_DMACR);
fp@2685: reg &= ~E1000_DMACR_DMACTHR_MASK;
fp@2685: reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
fp@2685: & E1000_DMACR_DMACTHR_MASK);
fp@2685:
fp@2685: /* transition to L0x or L1 if available..*/
fp@2685: reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
fp@2685:
fp@2685: /* watchdog timer= +-1000 usec in 32usec intervals */
fp@2685: reg |= (1000 >> 5);
fp@2685:
fp@2685: /* Disable BMC-to-OS Watchdog Enable */
fp@2685: if (hw->mac.type != e1000_i354)
fp@2685: reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
fp@2685:
fp@2685: wr32(E1000_DMACR, reg);
fp@2685:
fp@2685: /* no lower threshold to disable
fp@2685: * coalescing(smart fifb)-UTRESH=0
fp@2685: */
fp@2685: wr32(E1000_DMCRTRH, 0);
fp@2685:
fp@2685: reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
fp@2685:
fp@2685: wr32(E1000_DMCTLX, reg);
fp@2685:
fp@2685: /* free space in tx packet buffer to wake from
fp@2685: * DMA coal
fp@2685: */
fp@2685: wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
fp@2685: (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
fp@2685:
fp@2685: /* make low power state decision controlled
fp@2685: * by DMA coal
fp@2685: */
fp@2685: reg = rd32(E1000_PCIEMISC);
fp@2685: reg &= ~E1000_PCIEMISC_LX_DECISION;
fp@2685: wr32(E1000_PCIEMISC, reg);
fp@2685: } /* endif adapter->dmac is not disabled */
fp@2685: } else if (hw->mac.type == e1000_82580) {
fp@2685: u32 reg = rd32(E1000_PCIEMISC);
fp@2685:
fp@2685: wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
fp@2685: wr32(E1000_DMACR, 0);
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_read_i2c_byte - Reads 8 bit word over I2C
fp@2685: * @hw: pointer to hardware structure
fp@2685: * @byte_offset: byte offset to read
fp@2685: * @dev_addr: device address
fp@2685: * @data: value read
fp@2685: *
fp@2685: * Performs byte read operation over I2C interface at
fp@2685: * a specified device address.
fp@2685: **/
fp@2685: s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
fp@2685: u8 dev_addr, u8 *data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
fp@2685: struct i2c_client *this_client = adapter->i2c_client;
fp@2685: s32 status;
fp@2685: u16 swfw_mask = 0;
fp@2685:
fp@2685: if (!this_client)
fp@2685: return E1000_ERR_I2C;
fp@2685:
fp@2685: swfw_mask = E1000_SWFW_PHY0_SM;
fp@2685:
fp@2685: if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
fp@2685: return E1000_ERR_SWFW_SYNC;
fp@2685:
fp@2685: status = i2c_smbus_read_byte_data(this_client, byte_offset);
fp@2685: hw->mac.ops.release_swfw_sync(hw, swfw_mask);
fp@2685:
fp@2685: if (status < 0)
fp@2685: return E1000_ERR_I2C;
fp@2685: else {
fp@2685: *data = status;
fp@2685: return 0;
fp@2685: }
fp@2685: }
fp@2685:
fp@2685: /**
fp@2685: * igb_write_i2c_byte - Writes 8 bit word over I2C
fp@2685: * @hw: pointer to hardware structure
fp@2685: * @byte_offset: byte offset to write
fp@2685: * @dev_addr: device address
fp@2685: * @data: value to write
fp@2685: *
fp@2685: * Performs byte write operation over I2C interface at
fp@2685: * a specified device address.
fp@2685: **/
fp@2685: s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
fp@2685: u8 dev_addr, u8 data)
fp@2685: {
fp@2685: struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
fp@2685: struct i2c_client *this_client = adapter->i2c_client;
fp@2685: s32 status;
fp@2685: u16 swfw_mask = E1000_SWFW_PHY0_SM;
fp@2685:
fp@2685: if (!this_client)
fp@2685: return E1000_ERR_I2C;
fp@2685:
fp@2685: if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
fp@2685: return E1000_ERR_SWFW_SYNC;
fp@2685: status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
fp@2685: hw->mac.ops.release_swfw_sync(hw, swfw_mask);
fp@2685:
fp@2685: if (status)
fp@2685: return E1000_ERR_I2C;
fp@2685: else
fp@2685: return 0;
fp@2685:
fp@2685: }
fp@2685:
fp@2685: int igb_reinit_queues(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct net_device *netdev = adapter->netdev;
fp@2685: struct pci_dev *pdev = adapter->pdev;
fp@2685: int err = 0;
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: igb_close(netdev);
fp@2685:
fp@2685: igb_reset_interrupt_capability(adapter);
fp@2685:
fp@2685: if (igb_init_interrupt_scheme(adapter, true)) {
fp@2685: dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
fp@2685: return -ENOMEM;
fp@2685: }
fp@2685:
fp@2685: if (netif_running(netdev))
fp@2685: err = igb_open(netdev);
fp@2685:
fp@2685: return err;
fp@2685: }
fp@2685: /* igb_main.c */