int type, int chan_id);
 static int nix_update_mce_rule(struct rvu *rvu, u16 pcifunc,
                               int type, bool add);
+static int nix_setup_ipolicers(struct rvu *rvu,
+                              struct nix_hw *nix_hw, int blkaddr);
+static void nix_ipolicer_freemem(struct nix_hw *nix_hw);
+static int nix_verify_bandprof(struct nix_cn10k_aq_enq_req *req,
+                              struct nix_hw *nix_hw, u16 pcifunc);
+static int nix_free_all_bandprof(struct rvu *rvu, u16 pcifunc);
+static void nix_clear_ratelimit_aggr(struct rvu *rvu, struct nix_hw *nix_hw,
+                                    u32 leaf_prof);
 
 enum mc_tbl_sz {
        MC_TBL_SZ_256,
        pfvf = rvu_get_pfvf(rvu, pcifunc);
        nixlf = rvu_get_lf(rvu, block, pcifunc, 0);
 
-       /* Skip NIXLF check for broadcast MCE entry init */
-       if (!(!rsp && req->ctype == NIX_AQ_CTYPE_MCE)) {
+       /* Skip NIXLF check for broadcast MCE entry and bandwidth profile
+        * operations done by AF itself.
+        */
+       if (!((!rsp && req->ctype == NIX_AQ_CTYPE_MCE) ||
+             (req->ctype == NIX_AQ_CTYPE_BANDPROF && !pcifunc))) {
                if (!pfvf->nixlf || nixlf < 0)
                        return NIX_AF_ERR_AF_LF_INVALID;
        }
                if (rsp)
                        rc = NIX_AF_ERR_AQ_ENQUEUE;
                break;
+       case NIX_AQ_CTYPE_BANDPROF:
+               if (nix_verify_bandprof((struct nix_cn10k_aq_enq_req *)req,
+                                       nix_hw, pcifunc))
+                       rc = NIX_AF_ERR_INVALID_BANDPROF;
+               break;
        default:
                rc = NIX_AF_ERR_AQ_ENQUEUE;
        }
                else if (req->ctype == NIX_AQ_CTYPE_MCE)
                        memcpy(mask, &req->mce_mask,
                               sizeof(struct nix_rx_mce_s));
+               else if (req->ctype == NIX_AQ_CTYPE_BANDPROF)
+                       memcpy(mask, &req->prof_mask,
+                              sizeof(struct nix_bandprof_s));
                fallthrough;
        case NIX_AQ_INSTOP_INIT:
                if (req->ctype == NIX_AQ_CTYPE_RQ)
                        memcpy(ctx, &req->rss, sizeof(struct nix_rsse_s));
                else if (req->ctype == NIX_AQ_CTYPE_MCE)
                        memcpy(ctx, &req->mce, sizeof(struct nix_rx_mce_s));
+               else if (req->ctype == NIX_AQ_CTYPE_BANDPROF)
+                       memcpy(ctx, &req->prof, sizeof(struct nix_bandprof_s));
                break;
        case NIX_AQ_INSTOP_NOP:
        case NIX_AQ_INSTOP_READ:
                        else if (req->ctype == NIX_AQ_CTYPE_MCE)
                                memcpy(&rsp->mce, ctx,
                                       sizeof(struct nix_rx_mce_s));
+                       else if (req->ctype == NIX_AQ_CTYPE_BANDPROF)
+                               memcpy(&rsp->prof, ctx,
+                                      sizeof(struct nix_bandprof_s));
                }
        }
 
                if (err)
                        return err;
 
+               err = nix_setup_ipolicers(rvu, nix_hw, blkaddr);
+               if (err)
+                       return err;
+
                err = nix_af_mark_format_setup(rvu, nix_hw, blkaddr);
                if (err)
                        return err;
                        kfree(txsch->schq.bmap);
                }
 
+               nix_ipolicer_freemem(nix_hw);
+
                vlan = &nix_hw->txvlan;
                kfree(vlan->rsrc.bmap);
                mutex_destroy(&vlan->rsrc_lock);
        }
 
        nix_ctx_free(rvu, pfvf);
+
+       nix_free_all_bandprof(rvu, pcifunc);
 }
 
 #define NIX_AF_LFX_TX_CFG_PTP_EN       BIT_ULL(32)
        if (from_vf)
                ether_addr_copy(pfvf->mac_addr, pfvf->default_mac);
 }
+
+/* NIX ingress policers or bandwidth profiles APIs */
+static void nix_config_rx_pkt_policer_precolor(struct rvu *rvu, int blkaddr)
+{
+       struct npc_lt_def_cfg defs, *ltdefs;
+
+       ltdefs = &defs;
+       memcpy(ltdefs, rvu->kpu.lt_def, sizeof(struct npc_lt_def_cfg));
+
+       /* Extract PCP and DEI fields from outer VLAN from byte offset
+        * 2 from the start of LB_PTR (ie TAG).
+        * VLAN0 is Outer VLAN and VLAN1 is Inner VLAN. Inner VLAN
+        * fields are considered when 'Tunnel enable' is set in profile.
+        */
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_VLAN0_PCP_DEI,
+                   (2UL << 12) | (ltdefs->ovlan.lid << 8) |
+                   (ltdefs->ovlan.ltype_match << 4) |
+                   ltdefs->ovlan.ltype_mask);
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_VLAN1_PCP_DEI,
+                   (2UL << 12) | (ltdefs->ivlan.lid << 8) |
+                   (ltdefs->ivlan.ltype_match << 4) |
+                   ltdefs->ivlan.ltype_mask);
+
+       /* DSCP field in outer and tunneled IPv4 packets */
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_OIP4_DSCP,
+                   (1UL << 12) | (ltdefs->rx_oip4.lid << 8) |
+                   (ltdefs->rx_oip4.ltype_match << 4) |
+                   ltdefs->rx_oip4.ltype_mask);
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_IIP4_DSCP,
+                   (1UL << 12) | (ltdefs->rx_iip4.lid << 8) |
+                   (ltdefs->rx_iip4.ltype_match << 4) |
+                   ltdefs->rx_iip4.ltype_mask);
+
+       /* DSCP field (traffic class) in outer and tunneled IPv6 packets */
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_OIP6_DSCP,
+                   (1UL << 11) | (ltdefs->rx_oip6.lid << 8) |
+                   (ltdefs->rx_oip6.ltype_match << 4) |
+                   ltdefs->rx_oip6.ltype_mask);
+       rvu_write64(rvu, blkaddr, NIX_AF_RX_DEF_IIP6_DSCP,
+                   (1UL << 11) | (ltdefs->rx_iip6.lid << 8) |
+                   (ltdefs->rx_iip6.ltype_match << 4) |
+                   ltdefs->rx_iip6.ltype_mask);
+}
+
+static int nix_init_policer_context(struct rvu *rvu, struct nix_hw *nix_hw,
+                                   int layer, int prof_idx)
+{
+       struct nix_cn10k_aq_enq_req aq_req;
+       int rc;
+
+       memset(&aq_req, 0, sizeof(struct nix_cn10k_aq_enq_req));
+
+       aq_req.qidx = (prof_idx & 0x3FFF) | (layer << 14);
+       aq_req.ctype = NIX_AQ_CTYPE_BANDPROF;
+       aq_req.op = NIX_AQ_INSTOP_INIT;
+
+       /* Context is all zeros, submit to AQ */
+       rc = rvu_nix_blk_aq_enq_inst(rvu, nix_hw,
+                                    (struct nix_aq_enq_req *)&aq_req, NULL);
+       if (rc)
+               dev_err(rvu->dev, "Failed to INIT bandwidth profile layer %d profile %d\n",
+                       layer, prof_idx);
+       return rc;
+}
+
+static int nix_setup_ipolicers(struct rvu *rvu,
+                              struct nix_hw *nix_hw, int blkaddr)
+{
+       struct rvu_hwinfo *hw = rvu->hw;
+       struct nix_ipolicer *ipolicer;
+       int err, layer, prof_idx;
+       u64 cfg;
+
+       cfg = rvu_read64(rvu, blkaddr, NIX_AF_CONST);
+       if (!(cfg & BIT_ULL(61))) {
+               hw->cap.ipolicer = false;
+               return 0;
+       }
+
+       hw->cap.ipolicer = true;
+       nix_hw->ipolicer = devm_kcalloc(rvu->dev, BAND_PROF_NUM_LAYERS,
+                                       sizeof(*ipolicer), GFP_KERNEL);
+       if (!nix_hw->ipolicer)
+               return -ENOMEM;
+
+       cfg = rvu_read64(rvu, blkaddr, NIX_AF_PL_CONST);
+
+       for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
+               ipolicer = &nix_hw->ipolicer[layer];
+               switch (layer) {
+               case BAND_PROF_LEAF_LAYER:
+                       ipolicer->band_prof.max = cfg & 0XFFFF;
+                       break;
+               case BAND_PROF_MID_LAYER:
+                       ipolicer->band_prof.max = (cfg >> 16) & 0XFFFF;
+                       break;
+               case BAND_PROF_TOP_LAYER:
+                       ipolicer->band_prof.max = (cfg >> 32) & 0XFFFF;
+                       break;
+               }
+
+               if (!ipolicer->band_prof.max)
+                       continue;
+
+               err = rvu_alloc_bitmap(&ipolicer->band_prof);
+               if (err)
+                       return err;
+
+               ipolicer->pfvf_map = devm_kcalloc(rvu->dev,
+                                                 ipolicer->band_prof.max,
+                                                 sizeof(u16), GFP_KERNEL);
+               if (!ipolicer->pfvf_map)
+                       return -ENOMEM;
+
+               ipolicer->match_id = devm_kcalloc(rvu->dev,
+                                                 ipolicer->band_prof.max,
+                                                 sizeof(u16), GFP_KERNEL);
+               if (!ipolicer->match_id)
+                       return -ENOMEM;
+
+               for (prof_idx = 0;
+                    prof_idx < ipolicer->band_prof.max; prof_idx++) {
+                       /* Set AF as current owner for INIT ops to succeed */
+                       ipolicer->pfvf_map[prof_idx] = 0x00;
+
+                       /* There is no enable bit in the profile context,
+                        * so no context disable. So let's INIT them here
+                        * so that PF/VF later on have to just do WRITE to
+                        * setup policer rates and config.
+                        */
+                       err = nix_init_policer_context(rvu, nix_hw,
+                                                      layer, prof_idx);
+                       if (err)
+                               return err;
+               }
+
+               /* Allocate memory for maintaining ref_counts for MID level
+                * profiles, this will be needed for leaf layer profiles'
+                * aggregation.
+                */
+               if (layer != BAND_PROF_MID_LAYER)
+                       continue;
+
+               ipolicer->ref_count = devm_kcalloc(rvu->dev,
+                                                  ipolicer->band_prof.max,
+                                                  sizeof(u16), GFP_KERNEL);
+       }
+
+       /* Set policer timeunit to 2us ie  (19 + 1) * 100 nsec = 2us */
+       rvu_write64(rvu, blkaddr, NIX_AF_PL_TS, 19);
+
+       nix_config_rx_pkt_policer_precolor(rvu, blkaddr);
+
+       return 0;
+}
+
+static void nix_ipolicer_freemem(struct nix_hw *nix_hw)
+{
+       struct nix_ipolicer *ipolicer;
+       int layer;
+
+       for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
+               ipolicer = &nix_hw->ipolicer[layer];
+
+               if (!ipolicer->band_prof.max)
+                       continue;
+
+               kfree(ipolicer->band_prof.bmap);
+       }
+}
+
+static int nix_verify_bandprof(struct nix_cn10k_aq_enq_req *req,
+                              struct nix_hw *nix_hw, u16 pcifunc)
+{
+       struct nix_ipolicer *ipolicer;
+       int layer, hi_layer, prof_idx;
+
+       /* Bits [15:14] in profile index represent layer */
+       layer = (req->qidx >> 14) & 0x03;
+       prof_idx = req->qidx & 0x3FFF;
+
+       ipolicer = &nix_hw->ipolicer[layer];
+       if (prof_idx >= ipolicer->band_prof.max)
+               return -EINVAL;
+
+       /* Check if the profile is allocated to the requesting PCIFUNC or not
+        * with the exception of AF. AF is allowed to read and update contexts.
+        */
+       if (pcifunc && ipolicer->pfvf_map[prof_idx] != pcifunc)
+               return -EINVAL;
+
+       /* If this profile is linked to higher layer profile then check
+        * if that profile is also allocated to the requesting PCIFUNC
+        * or not.
+        */
+       if (!req->prof.hl_en)
+               return 0;
+
+       /* Leaf layer profile can link only to mid layer and
+        * mid layer to top layer.
+        */
+       if (layer == BAND_PROF_LEAF_LAYER)
+               hi_layer = BAND_PROF_MID_LAYER;
+       else if (layer == BAND_PROF_MID_LAYER)
+               hi_layer = BAND_PROF_TOP_LAYER;
+       else
+               return -EINVAL;
+
+       ipolicer = &nix_hw->ipolicer[hi_layer];
+       prof_idx = req->prof.band_prof_id;
+       if (prof_idx >= ipolicer->band_prof.max ||
+           ipolicer->pfvf_map[prof_idx] != pcifunc)
+               return -EINVAL;
+
+       return 0;
+}
+
+int rvu_mbox_handler_nix_bandprof_alloc(struct rvu *rvu,
+                                       struct nix_bandprof_alloc_req *req,
+                                       struct nix_bandprof_alloc_rsp *rsp)
+{
+       int blkaddr, layer, prof, idx, err;
+       u16 pcifunc = req->hdr.pcifunc;
+       struct nix_ipolicer *ipolicer;
+       struct nix_hw *nix_hw;
+
+       if (!rvu->hw->cap.ipolicer)
+               return NIX_AF_ERR_IPOLICER_NOTSUPP;
+
+       err = nix_get_struct_ptrs(rvu, pcifunc, &nix_hw, &blkaddr);
+       if (err)
+               return err;
+
+       mutex_lock(&rvu->rsrc_lock);
+       for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
+               if (layer == BAND_PROF_INVAL_LAYER)
+                       continue;
+               if (!req->prof_count[layer])
+                       continue;
+
+               ipolicer = &nix_hw->ipolicer[layer];
+               for (idx = 0; idx < req->prof_count[layer]; idx++) {
+                       /* Allocate a max of 'MAX_BANDPROF_PER_PFFUNC' profiles */
+                       if (idx == MAX_BANDPROF_PER_PFFUNC)
+                               break;
+
+                       prof = rvu_alloc_rsrc(&ipolicer->band_prof);
+                       if (prof < 0)
+                               break;
+                       rsp->prof_count[layer]++;
+                       rsp->prof_idx[layer][idx] = prof;
+                       ipolicer->pfvf_map[prof] = pcifunc;
+               }
+       }
+       mutex_unlock(&rvu->rsrc_lock);
+       return 0;
+}
+
+static int nix_free_all_bandprof(struct rvu *rvu, u16 pcifunc)
+{
+       int blkaddr, layer, prof_idx, err;
+       struct nix_ipolicer *ipolicer;
+       struct nix_hw *nix_hw;
+
+       if (!rvu->hw->cap.ipolicer)
+               return NIX_AF_ERR_IPOLICER_NOTSUPP;
+
+       err = nix_get_struct_ptrs(rvu, pcifunc, &nix_hw, &blkaddr);
+       if (err)
+               return err;
+
+       mutex_lock(&rvu->rsrc_lock);
+       /* Free all the profiles allocated to the PCIFUNC */
+       for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
+               if (layer == BAND_PROF_INVAL_LAYER)
+                       continue;
+               ipolicer = &nix_hw->ipolicer[layer];
+
+               for (prof_idx = 0; prof_idx < ipolicer->band_prof.max; prof_idx++) {
+                       if (ipolicer->pfvf_map[prof_idx] != pcifunc)
+                               continue;
+
+                       /* Clear ratelimit aggregation, if any */
+                       if (layer == BAND_PROF_LEAF_LAYER &&
+                           ipolicer->match_id[prof_idx])
+                               nix_clear_ratelimit_aggr(rvu, nix_hw, prof_idx);
+
+                       ipolicer->pfvf_map[prof_idx] = 0x00;
+                       ipolicer->match_id[prof_idx] = 0;
+                       rvu_free_rsrc(&ipolicer->band_prof, prof_idx);
+               }
+       }
+       mutex_unlock(&rvu->rsrc_lock);
+       return 0;
+}
+
+int rvu_mbox_handler_nix_bandprof_free(struct rvu *rvu,
+                                      struct nix_bandprof_free_req *req,
+                                      struct msg_rsp *rsp)
+{
+       int blkaddr, layer, prof_idx, idx, err;
+       u16 pcifunc = req->hdr.pcifunc;
+       struct nix_ipolicer *ipolicer;
+       struct nix_hw *nix_hw;
+
+       if (req->free_all)
+               return nix_free_all_bandprof(rvu, pcifunc);
+
+       if (!rvu->hw->cap.ipolicer)
+               return NIX_AF_ERR_IPOLICER_NOTSUPP;
+
+       err = nix_get_struct_ptrs(rvu, pcifunc, &nix_hw, &blkaddr);
+       if (err)
+               return err;
+
+       mutex_lock(&rvu->rsrc_lock);
+       /* Free the requested profile indices */
+       for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
+               if (layer == BAND_PROF_INVAL_LAYER)
+                       continue;
+               if (!req->prof_count[layer])
+                       continue;
+
+               ipolicer = &nix_hw->ipolicer[layer];
+               for (idx = 0; idx < req->prof_count[layer]; idx++) {
+                       prof_idx = req->prof_idx[layer][idx];
+                       if (prof_idx >= ipolicer->band_prof.max ||
+                           ipolicer->pfvf_map[prof_idx] != pcifunc)
+                               continue;
+
+                       /* Clear ratelimit aggregation, if any */
+                       if (layer == BAND_PROF_LEAF_LAYER &&
+                           ipolicer->match_id[prof_idx])
+                               nix_clear_ratelimit_aggr(rvu, nix_hw, prof_idx);
+
+                       ipolicer->pfvf_map[prof_idx] = 0x00;
+                       ipolicer->match_id[prof_idx] = 0;
+                       rvu_free_rsrc(&ipolicer->band_prof, prof_idx);
+                       if (idx == MAX_BANDPROF_PER_PFFUNC)
+                               break;
+               }
+       }
+       mutex_unlock(&rvu->rsrc_lock);
+       return 0;
+}
+
+static int nix_aq_context_read(struct rvu *rvu, struct nix_hw *nix_hw,
+                              struct nix_cn10k_aq_enq_req *aq_req,
+                              struct nix_cn10k_aq_enq_rsp *aq_rsp,
+                              u16 pcifunc, u8 ctype, u32 qidx)
+{
+       memset(aq_req, 0, sizeof(struct nix_cn10k_aq_enq_req));
+       aq_req->hdr.pcifunc = pcifunc;
+       aq_req->ctype = ctype;
+       aq_req->op = NIX_AQ_INSTOP_READ;
+       aq_req->qidx = qidx;
+
+       return rvu_nix_blk_aq_enq_inst(rvu, nix_hw,
+                                      (struct nix_aq_enq_req *)aq_req,
+                                      (struct nix_aq_enq_rsp *)aq_rsp);
+}
+
+static int nix_ipolicer_map_leaf_midprofs(struct rvu *rvu,
+                                         struct nix_hw *nix_hw,
+                                         struct nix_cn10k_aq_enq_req *aq_req,
+                                         struct nix_cn10k_aq_enq_rsp *aq_rsp,
+                                         u32 leaf_prof, u16 mid_prof)
+{
+       memset(aq_req, 0, sizeof(struct nix_cn10k_aq_enq_req));
+       aq_req->hdr.pcifunc = 0x00;
+       aq_req->ctype = NIX_AQ_CTYPE_BANDPROF;
+       aq_req->op = NIX_AQ_INSTOP_WRITE;
+       aq_req->qidx = leaf_prof;
+
+       aq_req->prof.band_prof_id = mid_prof;
+       aq_req->prof_mask.band_prof_id = GENMASK(6, 0);
+       aq_req->prof.hl_en = 1;
+       aq_req->prof_mask.hl_en = 1;
+
+       return rvu_nix_blk_aq_enq_inst(rvu, nix_hw,
+                                      (struct nix_aq_enq_req *)aq_req,
+                                      (struct nix_aq_enq_rsp *)aq_rsp);
+}
+
+int rvu_nix_setup_ratelimit_aggr(struct rvu *rvu, u16 pcifunc,
+                                u16 rq_idx, u16 match_id)
+{
+       int leaf_prof, mid_prof, leaf_match;
+       struct nix_cn10k_aq_enq_req aq_req;
+       struct nix_cn10k_aq_enq_rsp aq_rsp;
+       struct nix_ipolicer *ipolicer;
+       struct nix_hw *nix_hw;
+       int blkaddr, idx, rc;
+
+       if (!rvu->hw->cap.ipolicer)
+               return 0;
+
+       rc = nix_get_struct_ptrs(rvu, pcifunc, &nix_hw, &blkaddr);
+       if (rc)
+               return rc;
+
+       /* Fetch the RQ's context to see if policing is enabled */
+       rc = nix_aq_context_read(rvu, nix_hw, &aq_req, &aq_rsp, pcifunc,
+                                NIX_AQ_CTYPE_RQ, rq_idx);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to fetch RQ%d context of PFFUNC 0x%x\n",
+                       __func__, rq_idx, pcifunc);
+               return rc;
+       }
+
+       if (!aq_rsp.rq.policer_ena)
+               return 0;
+
+       /* Get the bandwidth profile ID mapped to this RQ */
+       leaf_prof = aq_rsp.rq.band_prof_id;
+
+       ipolicer = &nix_hw->ipolicer[BAND_PROF_LEAF_LAYER];
+       ipolicer->match_id[leaf_prof] = match_id;
+
+       /* Check if any other leaf profile is marked with same match_id */
+       for (idx = 0; idx < ipolicer->band_prof.max; idx++) {
+               if (idx == leaf_prof)
+                       continue;
+               if (ipolicer->match_id[idx] != match_id)
+                       continue;
+
+               leaf_match = idx;
+               break;
+       }
+
+       if (idx == ipolicer->band_prof.max)
+               return 0;
+
+       /* Fetch the matching profile's context to check if it's already
+        * mapped to a mid level profile.
+        */
+       rc = nix_aq_context_read(rvu, nix_hw, &aq_req, &aq_rsp, 0x00,
+                                NIX_AQ_CTYPE_BANDPROF, leaf_match);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to fetch context of leaf profile %d\n",
+                       __func__, leaf_match);
+               return rc;
+       }
+
+       ipolicer = &nix_hw->ipolicer[BAND_PROF_MID_LAYER];
+       if (aq_rsp.prof.hl_en) {
+               /* Get Mid layer prof index and map leaf_prof index
+                * also such that flows that are being steered
+                * to different RQs and marked with same match_id
+                * are rate limited in a aggregate fashion
+                */
+               mid_prof = aq_rsp.prof.band_prof_id;
+               rc = nix_ipolicer_map_leaf_midprofs(rvu, nix_hw,
+                                                   &aq_req, &aq_rsp,
+                                                   leaf_prof, mid_prof);
+               if (rc) {
+                       dev_err(rvu->dev,
+                               "%s: Failed to map leaf(%d) and mid(%d) profiles\n",
+                               __func__, leaf_prof, mid_prof);
+                       goto exit;
+               }
+
+               mutex_lock(&rvu->rsrc_lock);
+               ipolicer->ref_count[mid_prof]++;
+               mutex_unlock(&rvu->rsrc_lock);
+               goto exit;
+       }
+
+       /* Allocate a mid layer profile and
+        * map both 'leaf_prof' and 'leaf_match' profiles to it.
+        */
+       mutex_lock(&rvu->rsrc_lock);
+       mid_prof = rvu_alloc_rsrc(&ipolicer->band_prof);
+       if (mid_prof < 0) {
+               dev_err(rvu->dev,
+                       "%s: Unable to allocate mid layer profile\n", __func__);
+               mutex_unlock(&rvu->rsrc_lock);
+               goto exit;
+       }
+       mutex_unlock(&rvu->rsrc_lock);
+       ipolicer->pfvf_map[mid_prof] = 0x00;
+       ipolicer->ref_count[mid_prof] = 0;
+
+       /* Initialize mid layer profile same as 'leaf_prof' */
+       rc = nix_aq_context_read(rvu, nix_hw, &aq_req, &aq_rsp, 0x00,
+                                NIX_AQ_CTYPE_BANDPROF, leaf_prof);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to fetch context of leaf profile %d\n",
+                       __func__, leaf_prof);
+               goto exit;
+       }
+
+       memset(&aq_req, 0, sizeof(struct nix_cn10k_aq_enq_req));
+       aq_req.hdr.pcifunc = 0x00;
+       aq_req.qidx = (mid_prof & 0x3FFF) | (BAND_PROF_MID_LAYER << 14);
+       aq_req.ctype = NIX_AQ_CTYPE_BANDPROF;
+       aq_req.op = NIX_AQ_INSTOP_WRITE;
+       memcpy(&aq_req.prof, &aq_rsp.prof, sizeof(struct nix_bandprof_s));
+       /* Clear higher layer enable bit in the mid profile, just in case */
+       aq_req.prof.hl_en = 0;
+       aq_req.prof_mask.hl_en = 1;
+
+       rc = rvu_nix_blk_aq_enq_inst(rvu, nix_hw,
+                                    (struct nix_aq_enq_req *)&aq_req, NULL);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to INIT context of mid layer profile %d\n",
+                       __func__, mid_prof);
+               goto exit;
+       }
+
+       /* Map both leaf profiles to this mid layer profile */
+       rc = nix_ipolicer_map_leaf_midprofs(rvu, nix_hw,
+                                           &aq_req, &aq_rsp,
+                                           leaf_prof, mid_prof);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to map leaf(%d) and mid(%d) profiles\n",
+                       __func__, leaf_prof, mid_prof);
+               goto exit;
+       }
+
+       mutex_lock(&rvu->rsrc_lock);
+       ipolicer->ref_count[mid_prof]++;
+       mutex_unlock(&rvu->rsrc_lock);
+
+       rc = nix_ipolicer_map_leaf_midprofs(rvu, nix_hw,
+                                           &aq_req, &aq_rsp,
+                                           leaf_match, mid_prof);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to map leaf(%d) and mid(%d) profiles\n",
+                       __func__, leaf_match, mid_prof);
+               ipolicer->ref_count[mid_prof]--;
+               goto exit;
+       }
+
+       mutex_lock(&rvu->rsrc_lock);
+       ipolicer->ref_count[mid_prof]++;
+       mutex_unlock(&rvu->rsrc_lock);
+
+exit:
+       return rc;
+}
+
+/* Called with mutex rsrc_lock */
+static void nix_clear_ratelimit_aggr(struct rvu *rvu, struct nix_hw *nix_hw,
+                                    u32 leaf_prof)
+{
+       struct nix_cn10k_aq_enq_req aq_req;
+       struct nix_cn10k_aq_enq_rsp aq_rsp;
+       struct nix_ipolicer *ipolicer;
+       u16 mid_prof;
+       int rc;
+
+       mutex_unlock(&rvu->rsrc_lock);
+
+       rc = nix_aq_context_read(rvu, nix_hw, &aq_req, &aq_rsp, 0x00,
+                                NIX_AQ_CTYPE_BANDPROF, leaf_prof);
+
+       mutex_lock(&rvu->rsrc_lock);
+       if (rc) {
+               dev_err(rvu->dev,
+                       "%s: Failed to fetch context of leaf profile %d\n",
+                       __func__, leaf_prof);
+               return;
+       }
+
+       if (!aq_rsp.prof.hl_en)
+               return;
+
+       mid_prof = aq_rsp.prof.band_prof_id;
+       ipolicer = &nix_hw->ipolicer[BAND_PROF_MID_LAYER];
+       ipolicer->ref_count[mid_prof]--;
+       /* If ref_count is zero, free mid layer profile */
+       if (!ipolicer->ref_count[mid_prof]) {
+               ipolicer->pfvf_map[mid_prof] = 0x00;
+               rvu_free_rsrc(&ipolicer->band_prof, mid_prof);
+       }
+}