net/ice: fix flow director counter resource release
[dpdk.git] / drivers / net / ice / ice_fdir_filter.c
index 6052bed..e3b633e 100644 (file)
@@ -127,6 +127,12 @@ static struct ice_flow_parser ice_fdir_parser_comms;
 static const struct rte_memzone *
 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
 {
+       const struct rte_memzone *mz;
+
+       mz = rte_memzone_lookup(name);
+       if (mz)
+               return mz;
+
        return rte_memzone_reserve_aligned(name, len, socket_id,
                                           RTE_MEMZONE_IOVA_CONTIG,
                                           ICE_RING_BASE_ALIGN);
@@ -146,7 +152,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
                if (!hw->fdir_prof)
                        return -ENOMEM;
        }
-       for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+       for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
             ptype < ICE_FLTR_PTYPE_MAX;
             ptype++) {
                if (!hw->fdir_prof[ptype]) {
@@ -159,7 +165,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
        return 0;
 
 fail_mem:
-       for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+       for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
             fltr_ptype < ptype;
             fltr_ptype++)
                rte_free(hw->fdir_prof[fltr_ptype]);
@@ -246,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
        for (i = 0; i < container->index_free; i++)
                rte_free(container->pools[i]);
 
+       TAILQ_INIT(&container->pool_list);
+       container->index_free = 0;
+
        return 0;
 }
 
@@ -481,19 +490,23 @@ ice_fdir_setup(struct ice_pf *pf)
        }
        pf->fdir.prg_pkt = mz->addr;
        pf->fdir.dma_addr = mz->iova;
+       pf->fdir.mz = mz;
 
        err = ice_fdir_prof_alloc(hw);
        if (err) {
                PMD_DRV_LOG(ERR, "Cannot allocate memory for "
                            "flow director profile.");
                err = -ENOMEM;
-               goto fail_mem;
+               goto fail_prof;
        }
 
        PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
                    vsi->base_queue);
        return ICE_SUCCESS;
 
+fail_prof:
+       rte_memzone_free(pf->fdir.mz);
+       pf->fdir.mz = NULL;
 fail_mem:
        ice_rx_queue_release(pf->fdir.rxq);
        pf->fdir.rxq = NULL;
@@ -511,7 +524,7 @@ ice_fdir_prof_free(struct ice_hw *hw)
 {
        enum ice_fltr_ptype ptype;
 
-       for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+       for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
             ptype < ICE_FLTR_PTYPE_MAX;
             ptype++)
                rte_free(hw->fdir_prof[ptype]);
@@ -561,7 +574,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
        enum ice_fltr_ptype ptype;
 
-       for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+       for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
             ptype < ICE_FLTR_PTYPE_MAX;
             ptype++) {
                ice_fdir_prof_rm(pf, ptype, false);
@@ -607,6 +620,13 @@ ice_fdir_teardown(struct ice_pf *pf)
        ice_fdir_prof_free(hw);
        ice_release_vsi(vsi);
        pf->fdir.fdir_vsi = NULL;
+
+       if (pf->fdir.mz) {
+               err = rte_memzone_free(pf->fdir.mz);
+               pf->fdir.mz = NULL;
+               if (err)
+                       PMD_DRV_LOG(ERR, "Failed to free FDIR memezone.");
+       }
 }
 
 static int
@@ -863,8 +883,10 @@ ice_fdir_init(struct ice_adapter *ad)
 
        if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
                parser = &ice_fdir_parser_comms;
-       else
+       else if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
                parser = &ice_fdir_parser_os;
+       else
+               return -EINVAL;
 
        return ice_register_parser(parser, ad);
 }