remove unnecessary null checks
[dpdk.git] / drivers / net / ixgbe / ixgbe_ethdev.c
index a87c607..3d799d2 100644 (file)
@@ -1027,7 +1027,7 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 {
        struct ixgbe_adapter *ad = eth_dev->data->dev_private;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
        struct ixgbe_vfta *shadow_vfta =
@@ -1223,13 +1223,8 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
 
        /* initialize PF if max_vfs not zero */
        ret = ixgbe_pf_host_init(eth_dev);
-       if (ret) {
-               rte_free(eth_dev->data->mac_addrs);
-               eth_dev->data->mac_addrs = NULL;
-               rte_free(eth_dev->data->hash_mac_addrs);
-               eth_dev->data->hash_mac_addrs = NULL;
-               return ret;
-       }
+       if (ret)
+               goto err_pf_host_init;
 
        ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
        /* let hardware know driver is loaded */
@@ -1268,10 +1263,14 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
        TAILQ_INIT(&filter_info->fivetuple_list);
 
        /* initialize flow director filter list & hash */
-       ixgbe_fdir_filter_init(eth_dev);
+       ret = ixgbe_fdir_filter_init(eth_dev);
+       if (ret)
+               goto err_fdir_filter_init;
 
        /* initialize l2 tunnel filter list & hash */
-       ixgbe_l2_tn_filter_init(eth_dev);
+       ret = ixgbe_l2_tn_filter_init(eth_dev);
+       if (ret)
+               goto err_l2_tn_filter_init;
 
        /* initialize flow filter lists */
        ixgbe_filterlist_init();
@@ -1283,6 +1282,21 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
        ixgbe_tm_conf_init(eth_dev);
 
        return 0;
+
+err_l2_tn_filter_init:
+       ixgbe_fdir_filter_uninit(eth_dev);
+err_fdir_filter_init:
+       ixgbe_disable_intr(hw);
+       rte_intr_disable(intr_handle);
+       rte_intr_callback_unregister(intr_handle,
+               ixgbe_dev_interrupt_handler, eth_dev);
+       ixgbe_pf_host_uninit(eth_dev);
+err_pf_host_init:
+       rte_free(eth_dev->data->mac_addrs);
+       eth_dev->data->mac_addrs = NULL;
+       rte_free(eth_dev->data->hash_mac_addrs);
+       eth_dev->data->hash_mac_addrs = NULL;
+       return ret;
 }
 
 static int
@@ -1322,10 +1336,8 @@ static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev)
                IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
        struct ixgbe_fdir_filter *fdir_filter;
 
-               if (fdir_info->hash_map)
-               rte_free(fdir_info->hash_map);
-       if (fdir_info->hash_handle)
-               rte_hash_free(fdir_info->hash_handle);
+       rte_free(fdir_info->hash_map);
+       rte_hash_free(fdir_info->hash_handle);
 
        while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
                TAILQ_REMOVE(&fdir_info->fdir_list,
@@ -1343,10 +1355,8 @@ static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev)
                IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
        struct ixgbe_l2_tn_filter *l2_tn_filter;
 
-       if (l2_tn_info->hash_map)
-               rte_free(l2_tn_info->hash_map);
-       if (l2_tn_info->hash_handle)
-               rte_hash_free(l2_tn_info->hash_handle);
+       rte_free(l2_tn_info->hash_map);
+       rte_hash_free(l2_tn_info->hash_handle);
 
        while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
                TAILQ_REMOVE(&l2_tn_info->l2_tn_list,
@@ -1525,7 +1535,7 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
        uint32_t tc, tcs;
        struct ixgbe_adapter *ad = eth_dev->data->dev_private;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
        struct ixgbe_vfta *shadow_vfta =
@@ -2375,7 +2385,7 @@ ixgbe_dev_configure(struct rte_eth_dev *dev)
        if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
                dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
 
-       /* multipe queue mode checking */
+       /* multiple queue mode checking */
        ret  = ixgbe_check_mq_mode(dev);
        if (ret != 0) {
                PMD_DRV_LOG(ERR, "ixgbe_check_mq_mode fails with %d.",
@@ -2539,7 +2549,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
        struct ixgbe_vf_info *vfinfo =
                *IXGBE_DEV_PRIVATE_TO_P_VFDATA(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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        uint32_t intr_vector = 0;
        int err;
        bool link_up = false, negotiate = 0;
@@ -2594,18 +2604,16 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
                        return -1;
        }
 
-       if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
-               intr_handle->intr_vec =
-                       rte_zmalloc("intr_vec",
-                                   dev->data->nb_rx_queues * sizeof(int), 0);
-               if (intr_handle->intr_vec == NULL) {
+       if (rte_intr_dp_is_en(intr_handle)) {
+               if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
+                                                  dev->data->nb_rx_queues)) {
                        PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
                                     " intr_vec", dev->data->nb_rx_queues);
                        return -ENOMEM;
                }
        }
 
-       /* confiugre msix for sleep until rx interrupt */
+       /* configure MSI-X for sleep until Rx interrupt */
        ixgbe_configure_msix(dev);
 
        /* initialize transmission unit */
@@ -2834,7 +2842,7 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
        struct ixgbe_vf_info *vfinfo =
                *IXGBE_DEV_PRIVATE_TO_P_VFDATA(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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        int vf;
        struct ixgbe_tm_conf *tm_conf =
                IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
@@ -2885,10 +2893,7 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 
        /* Clean datapath event and queue/vec mapping */
        rte_intr_efd_disable(intr_handle);
-       if (intr_handle->intr_vec != NULL) {
-               rte_free(intr_handle->intr_vec);
-               intr_handle->intr_vec = NULL;
-       }
+       rte_intr_vec_list_free(intr_handle);
 
        /* reset hierarchy commit */
        tm_conf->committed = false;
@@ -2912,7 +2917,7 @@ ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
        if (hw->mac.type == ixgbe_mac_82599EB) {
 #ifdef RTE_LIBRTE_IXGBE_BYPASS
                if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
-                       /* Not suported in bypass mode */
+                       /* Not supported in bypass mode */
                        PMD_INIT_LOG(ERR, "Set link up is not supported "
                                     "by device id 0x%x", hw->device_id);
                        return -ENOTSUP;
@@ -2943,7 +2948,7 @@ ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
        if (hw->mac.type == ixgbe_mac_82599EB) {
 #ifdef RTE_LIBRTE_IXGBE_BYPASS
                if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
-                       /* Not suported in bypass mode */
+                       /* Not supported in bypass mode */
                        PMD_INIT_LOG(ERR, "Set link down is not supported "
                                     "by device id 0x%x", hw->device_id);
                        return -ENOTSUP;
@@ -2972,7 +2977,7 @@ ixgbe_dev_close(struct rte_eth_dev *dev)
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        int retries = 0;
        int ret;
 
@@ -4608,7 +4613,7 @@ ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
  * @param handle
  *  Pointer to interrupt handle.
  * @param param
- *  The address of parameter (struct rte_eth_dev *) regsitered before.
+ *  The address of parameter (struct rte_eth_dev *) registered before.
  *
  * @return
  *  void
@@ -4618,7 +4623,7 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_interrupt *intr =
                IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
        struct ixgbe_hw *hw =
@@ -4664,7 +4669,7 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
  * @param handle
  *  Pointer to interrupt handle.
  * @param param
- *  The address of parameter (struct rte_eth_dev *) regsitered before.
+ *  The address of parameter (struct rte_eth_dev *) registered before.
  *
  * @return
  *  void
@@ -5178,7 +5183,7 @@ ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
         * scattered packets when this feature has not been enabled before.
         */
        if (dev->data->dev_started && !dev->data->scattered_rx &&
-           frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
+           frame_size + 2 * RTE_VLAN_HLEN >
                        dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
                PMD_INIT_LOG(ERR, "Stop port first.");
                return -EINVAL;
@@ -5290,7 +5295,7 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
                IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        uint32_t intr_vector = 0;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
 
        int err, mask = 0;
 
@@ -5353,11 +5358,9 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
                }
        }
 
-       if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
-               intr_handle->intr_vec =
-                       rte_zmalloc("intr_vec",
-                                   dev->data->nb_rx_queues * sizeof(int), 0);
-               if (intr_handle->intr_vec == NULL) {
+       if (rte_intr_dp_is_en(intr_handle)) {
+               if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
+                                                  dev->data->nb_rx_queues)) {
                        PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
                                     " intr_vec", dev->data->nb_rx_queues);
                        ixgbe_dev_clear_queues(dev);
@@ -5397,7 +5400,7 @@ ixgbevf_dev_stop(struct rte_eth_dev *dev)
        struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct ixgbe_adapter *adapter = 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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
 
        if (hw->adapter_stopped)
                return 0;
@@ -5425,10 +5428,7 @@ ixgbevf_dev_stop(struct rte_eth_dev *dev)
 
        /* Clean datapath event and queue/vec mapping */
        rte_intr_efd_disable(intr_handle);
-       if (intr_handle->intr_vec != NULL) {
-               rte_free(intr_handle->intr_vec);
-               intr_handle->intr_vec = NULL;
-       }
+       rte_intr_vec_list_free(intr_handle);
 
        adapter->rss_reta_updated = 0;
 
@@ -5440,7 +5440,7 @@ ixgbevf_dev_close(struct rte_eth_dev *dev)
 {
        struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        int ret;
 
        PMD_INIT_FUNC_TRACE();
@@ -5738,7 +5738,7 @@ static int
 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_interrupt *intr =
                IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
        struct ixgbe_hw *hw =
@@ -5764,7 +5764,7 @@ ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(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;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        uint32_t vec = IXGBE_MISC_VEC_ID;
 
        if (rte_intr_allow_others(intr_handle))
@@ -5780,7 +5780,7 @@ static int
 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        uint32_t mask;
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5907,7 +5907,7 @@ static void
 ixgbevf_configure_msix(struct rte_eth_dev *dev)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        uint32_t q_idx;
@@ -5931,11 +5931,13 @@ ixgbevf_configure_msix(struct rte_eth_dev *dev)
        /* Configure all RX queues of VF */
        for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
                /* Force all queue use vector 0,
-                * as IXGBE_VF_MAXMSIVECOTR = 1
+                * as IXGBE_VF_MAXMSIVECTOR = 1
                 */
                ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
-               intr_handle->intr_vec[q_idx] = vector_idx;
-               if (vector_idx < base + intr_handle->nb_efd - 1)
+               rte_intr_vec_list_index_set(intr_handle, q_idx,
+                                                  vector_idx);
+               if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
+                   - 1)
                        vector_idx++;
        }
 
@@ -5956,7 +5958,7 @@ static void
 ixgbe_configure_msix(struct rte_eth_dev *dev)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
        struct ixgbe_hw *hw =
                IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
@@ -6000,8 +6002,10 @@ ixgbe_configure_msix(struct rte_eth_dev *dev)
                        queue_id++) {
                        /* by default, 1:1 mapping */
                        ixgbe_set_ivar_map(hw, 0, queue_id, vec);
-                       intr_handle->intr_vec[queue_id] = vec;
-                       if (vec < base + intr_handle->nb_efd - 1)
+                       rte_intr_vec_list_index_set(intr_handle,
+                                                          queue_id, vec);
+                       if (vec < base + rte_intr_nb_efd_get(intr_handle)
+                           - 1)
                                vec++;
                }
 
@@ -6262,7 +6266,7 @@ ixgbe_inject_5tuple_filter(struct rte_eth_dev *dev,
  * @param
  * dev: Pointer to struct rte_eth_dev.
  * index: the index the filter allocates.
- * filter: ponter to the filter that will be added.
+ * filter: pointer to the filter that will be added.
  * rx_queue: the queue id the filter assigned to.
  *
  * @return
@@ -6347,7 +6351,7 @@ ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
         * scattered packets when this feature has not been enabled before.
         */
        if (dev_data->dev_started && !dev_data->scattered_rx &&
-           (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
+           (max_frame + 2 * RTE_VLAN_HLEN >
                        dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
                PMD_INIT_LOG(ERR, "Stop port first.");
                return -EINVAL;
@@ -6878,7 +6882,7 @@ ixgbe_timesync_disable(struct rte_eth_dev *dev)
        /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
        IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
 
-       /* Stop incrementating the System Time registers. */
+       /* Stop incrementing the System Time registers. */
        IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
 
        return 0;