net/ice: fix crash on device detach
[dpdk.git] / drivers / net / ice / ice_ethdev.c
index 0a81e04..6b0113b 100644 (file)
@@ -38,6 +38,10 @@ static int ice_rss_hash_update(struct rte_eth_dev *dev,
                               struct rte_eth_rss_conf *rss_conf);
 static int ice_rss_hash_conf_get(struct rte_eth_dev *dev,
                                 struct rte_eth_rss_conf *rss_conf);
+static void ice_promisc_enable(struct rte_eth_dev *dev);
+static void ice_promisc_disable(struct rte_eth_dev *dev);
+static void ice_allmulti_enable(struct rte_eth_dev *dev);
+static void ice_allmulti_disable(struct rte_eth_dev *dev);
 static int ice_vlan_filter_set(struct rte_eth_dev *dev,
                               uint16_t vlan_id,
                               int on);
@@ -103,6 +107,10 @@ static const struct eth_dev_ops ice_eth_dev_ops = {
        .reta_query                   = ice_rss_reta_query,
        .rss_hash_update              = ice_rss_hash_update,
        .rss_hash_conf_get            = ice_rss_hash_conf_get,
+       .promiscuous_enable           = ice_promisc_enable,
+       .promiscuous_disable          = ice_promisc_disable,
+       .allmulticast_enable          = ice_allmulti_enable,
+       .allmulticast_disable         = ice_allmulti_disable,
        .rx_queue_intr_enable         = ice_rx_queue_intr_enable,
        .rx_queue_intr_disable        = ice_rx_queue_intr_disable,
        .fw_version_get               = ice_fw_version_get,
@@ -1450,15 +1458,14 @@ ice_dev_close(struct rte_eth_dev *dev)
 
        ice_res_pool_destroy(&pf->msix_pool);
        ice_release_vsi(pf->main_vsi);
-
+       ice_sched_cleanup_all(hw);
+       rte_free(hw->port_info);
        ice_shutdown_all_ctrlq(hw);
 }
 
 static int
 ice_dev_uninit(struct rte_eth_dev *dev)
 {
-       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
@@ -1478,11 +1485,6 @@ ice_dev_uninit(struct rte_eth_dev *dev)
        rte_intr_callback_unregister(intr_handle,
                                     ice_interrupt_handler, dev);
 
-       ice_release_vsi(pf->main_vsi);
-       ice_sched_cleanup_all(hw);
-       rte_free(hw->port_info);
-       ice_shutdown_all_ctrlq(hw);
-
        return 0;
 }
 
@@ -1709,6 +1711,7 @@ ice_dev_start(struct rte_eth_dev *dev)
        struct rte_eth_dev_data *data = dev->data;
        struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       struct ice_vsi *vsi = pf->main_vsi;
        uint16_t nb_rxq = 0;
        uint16_t nb_txq, i;
        int ret;
@@ -1743,6 +1746,14 @@ ice_dev_start(struct rte_eth_dev *dev)
        if (ice_rxq_intr_setup(dev))
                return -EIO;
 
+       /* Enable receiving broadcast packets and transmitting packets */
+       ret = ice_set_vsi_promisc(hw, vsi->idx,
+                                 ICE_PROMISC_BCAST_RX | ICE_PROMISC_BCAST_TX |
+                                 ICE_PROMISC_UCAST_TX | ICE_PROMISC_MCAST_TX,
+                                 0);
+       if (ret != ICE_SUCCESS)
+               PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
+
        ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
                                    ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
                                     ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
@@ -1882,7 +1893,9 @@ ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                               ETH_LINK_SPEED_10G |
                               ETH_LINK_SPEED_20G |
                               ETH_LINK_SPEED_25G |
-                              ETH_LINK_SPEED_40G;
+                              ETH_LINK_SPEED_40G |
+                              ETH_LINK_SPEED_50G |
+                              ETH_LINK_SPEED_100G;
 
        dev_info->nb_rx_queues = dev->data->nb_rx_queues;
        dev_info->nb_tx_queues = dev->data->nb_tx_queues;
@@ -1993,6 +2006,12 @@ ice_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
        case ICE_AQ_LINK_SPEED_40GB:
                link.link_speed = ETH_SPEED_NUM_40G;
                break;
+       case ICE_AQ_LINK_SPEED_50GB:
+               link.link_speed = ETH_SPEED_NUM_50G;
+               break;
+       case ICE_AQ_LINK_SPEED_100GB:
+               link.link_speed = ETH_SPEED_NUM_100G;
+               break;
        case ICE_AQ_LINK_SPEED_UNKNOWN:
        default:
                PMD_DRV_LOG(ERR, "Unknown link speed");
@@ -2183,14 +2202,20 @@ ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
        if (ret) {
                PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
                            on ? "enable" : "disable");
-               ret = -EINVAL;
+               return -EINVAL;
        } else {
                vsi->info.valid_sections |=
                        rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
                                         ICE_AQ_VSI_PROP_SECURITY_VALID);
        }
 
-       return ret;
+       /* consist with other drivers, allow untagged packet when vlan filter on */
+       if (on)
+               ret = ice_add_vlan_filter(vsi, 0);
+       else
+               ret = ice_remove_vlan_filter(vsi, 0);
+
+       return 0;
 }
 
 static int
@@ -2550,6 +2575,75 @@ ice_rss_hash_conf_get(struct rte_eth_dev *dev,
        return 0;
 }
 
+static void
+ice_promisc_enable(struct rte_eth_dev *dev)
+{
+       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct ice_vsi *vsi = pf->main_vsi;
+       uint8_t pmask;
+       uint16_t status;
+
+       pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
+               ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
+
+       status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
+       if (status != ICE_SUCCESS)
+               PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
+}
+
+static void
+ice_promisc_disable(struct rte_eth_dev *dev)
+{
+       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct ice_vsi *vsi = pf->main_vsi;
+       uint16_t status;
+       uint8_t pmask;
+
+       pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
+               ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
+
+       status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
+       if (status != ICE_SUCCESS)
+               PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
+}
+
+static void
+ice_allmulti_enable(struct rte_eth_dev *dev)
+{
+       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct ice_vsi *vsi = pf->main_vsi;
+       uint8_t pmask;
+       uint16_t status;
+
+       pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
+
+       status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
+       if (status != ICE_SUCCESS)
+               PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
+}
+
+static void
+ice_allmulti_disable(struct rte_eth_dev *dev)
+{
+       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+       struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct ice_vsi *vsi = pf->main_vsi;
+       uint16_t status;
+       uint8_t pmask;
+
+       if (dev->data->promiscuous == 1)
+               return; /* must remain in all_multicast mode */
+
+       pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
+
+       status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
+       if (status != ICE_SUCCESS)
+               PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
+}
+
 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
                                    uint16_t queue_id)
 {
@@ -2590,11 +2684,22 @@ static int
 ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
 {
        struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       u32 full_ver;
+       u8 ver, patch;
+       u16 build;
        int ret;
 
-       ret = snprintf(fw_version, fw_size, "%d.%d.%05d %d.%d",
-                      hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
-                      hw->api_maj_ver, hw->api_min_ver);
+       full_ver = hw->nvm.oem_ver;
+       ver = (u8)(full_ver >> 24);
+       build = (u16)((full_ver >> 8) & 0xffff);
+       patch = (u8)(full_ver & 0xff);
+
+       ret = snprintf(fw_version, fw_size,
+                       "%d.%d%d 0x%08x %d.%d.%d",
+                       ((hw->nvm.ver >> 12) & 0xf),
+                       ((hw->nvm.ver >> 4) & 0xff),
+                       (hw->nvm.ver & 0xf), hw->nvm.eetrack,
+                       ver, build, patch);
 
        /* add the size of '\0' */
        ret += 1;