net/ice/base: adjust rate limit profile ids runtime database
[dpdk.git] / drivers / net / ice / base / ice_acl_ctrl.c
index 5310b9d..bd09e9d 100644 (file)
@@ -149,10 +149,8 @@ static enum ice_status ice_acl_init_tbl(struct ice_hw *hw)
        u16 idx;
 
        tbl = hw->acl_tbl;
-       if (!tbl) {
-               status = ICE_ERR_CFG;
-               return status;
-       }
+       if (!tbl)
+               return ICE_ERR_CFG;
 
        ice_memset(&buf, 0, sizeof(buf), ICE_NONDMA_MEM);
        ice_memset(&act_buf, 0, sizeof(act_buf), ICE_NONDMA_MEM);
@@ -354,16 +352,13 @@ ice_acl_create_tbl(struct ice_hw *hw, struct ice_acl_tbl_params *params)
 
        /* call the AQ command to create the ACL table with these values */
        status = ice_aq_alloc_acl_tbl(hw, &tbl_alloc, NULL);
-
        if (status) {
                if (LE16_TO_CPU(tbl_alloc.buf.resp_buf.alloc_id) <
                    ICE_AQC_ALLOC_ID_LESS_THAN_4K)
-                       ice_debug(hw, ICE_DBG_ACL,
-                                 "Alloc ACL table failed. Unavailable resource.\n");
+                       ice_debug(hw, ICE_DBG_ACL, "Alloc ACL table failed. Unavailable resource.\n");
                else
-                       ice_debug(hw, ICE_DBG_ACL,
-                                 "AQ allocation of ACL failed with error. status: %d\n",
-                                  status);
+                       ice_debug(hw, ICE_DBG_ACL, "AQ allocation of ACL failed with error. status: %d\n",
+                                 status);
                return status;
        }
 
@@ -403,8 +398,7 @@ ice_acl_create_tbl(struct ice_hw *hw, struct ice_acl_tbl_params *params)
        if (status) {
                ice_free(hw, tbl);
                hw->acl_tbl = NULL;
-               ice_debug(hw, ICE_DBG_ACL,
-                         "Initialization of TCAM entries failed. status: %d\n",
+               ice_debug(hw, ICE_DBG_ACL, "Initialization of TCAM entries failed. status: %d\n",
                          status);
                goto out;
        }
@@ -415,8 +409,7 @@ ice_acl_create_tbl(struct ice_hw *hw, struct ice_acl_tbl_params *params)
                (tbl->last_entry / ICE_ACL_ENTRY_ALLOC_UNIT);
 
        /* Indicate available entries in the table */
-       for (i = first_e; i <= last_e; i++)
-               ice_set_bit(i, tbl->avail);
+       ice_bitmap_set(tbl->avail, first_e, last_e - first_e + 1);
 
        INIT_LIST_HEAD(&tbl->scens);
 out:
@@ -531,7 +524,7 @@ ice_acl_alloc_partition(struct ice_hw *hw, struct ice_acl_scen *req)
                        break;
                }
 
-               row = (dir > 0) ? (row + width) : (row - width);
+               row = dir > 0 ? row + width : row - width;
                if (row > hw->acl_tbl->last_tcam ||
                    row < hw->acl_tbl->first_tcam) {
                        /* All rows have been checked. Increment 'off' that
@@ -673,8 +666,7 @@ static void
 ice_acl_assign_act_mem_for_scen(struct ice_acl_tbl *tbl,
                                struct ice_acl_scen *scen,
                                struct ice_aqc_acl_scen *scen_buf,
-                               u8 current_tcam_idx,
-                               u8 target_tcam_idx)
+                               u8 current_tcam_idx, u8 target_tcam_idx)
 {
        u8 i;
 
@@ -766,10 +758,8 @@ ice_acl_create_scen(struct ice_hw *hw, u16 match_width, u16 num_entries,
        scen->num_entry = num_entries;
 
        status = ice_acl_alloc_partition(hw, scen);
-       if (status) {
-               ice_free(hw, scen);
-               return status;
-       }
+       if (status)
+               goto out;
 
        ice_memset(&scen_buf, 0, sizeof(scen_buf), ICE_NONDMA_MEM);
 
@@ -832,11 +822,9 @@ ice_acl_create_scen(struct ice_hw *hw, u16 match_width, u16 num_entries,
 
        status = ice_aq_alloc_acl_scen(hw, scen_id, &scen_buf, NULL);
        if (status) {
-               ice_debug(hw, ICE_DBG_ACL,
-                         "AQ allocation of ACL scenario failed. status: %d\n",
+               ice_debug(hw, ICE_DBG_ACL, "AQ allocation of ACL scenario failed. status: %d\n",
                          status);
-               ice_free(hw, scen);
-               return status;
+               goto out;
        }
 
        scen->id = *scen_id;
@@ -844,9 +832,58 @@ ice_acl_create_scen(struct ice_hw *hw, u16 match_width, u16 num_entries,
        ice_acl_init_entry(scen);
        LIST_ADD(&scen->list_entry, &hw->acl_tbl->scens);
 
+out:
+       if (status)
+               ice_free(hw, scen);
+
        return status;
 }
 
+/**
+ * ice_acl_destroy_scen - Destroy an ACL scenario
+ * @hw: pointer to the HW struct
+ * @scen_id: ID of the remove scenario
+ */
+static enum ice_status ice_acl_destroy_scen(struct ice_hw *hw, u16 scen_id)
+{
+       struct ice_acl_scen *scen, *tmp_scen;
+       struct ice_flow_prof *p, *tmp;
+       enum ice_status status;
+
+       if (!hw->acl_tbl)
+               return ICE_ERR_DOES_NOT_EXIST;
+
+       /* Remove profiles that use "scen_id" scenario */
+       LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[ICE_BLK_ACL],
+                                ice_flow_prof, l_entry)
+               if (p->cfg.scen && p->cfg.scen->id == scen_id) {
+                       status = ice_flow_rem_prof(hw, ICE_BLK_ACL, p->id);
+                       if (status) {
+                               ice_debug(hw, ICE_DBG_ACL, "ice_flow_rem_prof failed. status: %d\n",
+                                         status);
+                               return status;
+                       }
+               }
+
+       /* Call the AQ command to destroy the targeted scenario */
+       status = ice_aq_dealloc_acl_scen(hw, scen_id, NULL);
+       if (status) {
+               ice_debug(hw, ICE_DBG_ACL, "AQ de-allocation of scenario failed. status: %d\n",
+                         status);
+               return status;
+       }
+
+       /* Remove scenario from hw->acl_tbl->scens */
+       LIST_FOR_EACH_ENTRY_SAFE(scen, tmp_scen, &hw->acl_tbl->scens,
+                                ice_acl_scen, list_entry)
+               if (scen->id == scen_id) {
+                       LIST_DEL(&scen->list_entry);
+                       ice_free(hw, scen);
+               }
+
+       return ICE_SUCCESS;
+}
+
 /**
  * ice_acl_destroy_tbl - Destroy a previously created LEM table for ACL
  * @hw: pointer to the HW struct
@@ -900,10 +937,8 @@ enum ice_status ice_acl_destroy_tbl(struct ice_hw *hw)
 
        /* call the AQ command to destroy the ACL table */
        status = ice_aq_dealloc_acl_tbl(hw, hw->acl_tbl->id, &resp_buf, NULL);
-
        if (status) {
-               ice_debug(hw, ICE_DBG_ACL,
-                         "AQ de-allocation of ACL failed. status: %d\n",
+               ice_debug(hw, ICE_DBG_ACL, "AQ de-allocation of ACL failed. status: %d\n",
                          status);
                return status;
        }
@@ -979,8 +1014,7 @@ ice_acl_add_entry(struct ice_hw *hw, struct ice_acl_scen *scen,
                status = ice_aq_program_acl_entry(hw, entry_tcam + offset, idx,
                                                  &buf, NULL);
                if (status) {
-                       ice_debug(hw, ICE_DBG_ACL,
-                                 "aq program acl entry failed status: %d\n",
+                       ice_debug(hw, ICE_DBG_ACL, "aq program acl entry failed status: %d\n",
                                  status);
                        goto out;
                }
@@ -1030,9 +1064,8 @@ ice_acl_prog_act(struct ice_hw *hw, struct ice_acl_scen *scen,
        entry_tcam = ICE_ACL_TBL_TCAM_IDX(scen->start);
        idx = ICE_ACL_TBL_TCAM_ENTRY_IDX(scen->start + entry_idx);
 
-       i = ice_find_first_bit(scen->act_mem_bitmap,
-                              ICE_AQC_MAX_ACTION_MEMORIES);
-       while (i < ICE_AQC_MAX_ACTION_MEMORIES) {
+       ice_for_each_set_bit(i, scen->act_mem_bitmap,
+                            ICE_AQC_MAX_ACTION_MEMORIES) {
                struct ice_acl_act_mem *mem = &hw->acl_tbl->act_mems[i];
 
                if (actx_idx >= acts_cnt)
@@ -1052,16 +1085,12 @@ ice_acl_prog_act(struct ice_hw *hw, struct ice_acl_scen *scen,
                        status = ice_aq_program_actpair(hw, i, idx, &act_buf,
                                                        NULL);
                        if (status) {
-                               ice_debug(hw, ICE_DBG_ACL,
-                                         "program actpair failed status: %d\n",
+                               ice_debug(hw, ICE_DBG_ACL, "program actpair failed status: %d\n",
                                          status);
                                break;
                        }
                        actx_idx++;
                }
-
-               i = ice_find_next_bit(scen->act_mem_bitmap,
-                                     ICE_AQC_MAX_ACTION_MEMORIES, i + 1);
        }
 
        if (!status && actx_idx < acts_cnt)
@@ -1107,15 +1136,14 @@ ice_acl_rem_entry(struct ice_hw *hw, struct ice_acl_scen *scen, u16 entry_idx)
                status = ice_aq_program_acl_entry(hw, entry_tcam + i, idx, &buf,
                                                  NULL);
                if (status)
-                       ice_debug(hw, ICE_DBG_ACL,
-                                 "AQ program ACL entry failed status: %d\n",
+                       ice_debug(hw, ICE_DBG_ACL, "AQ program ACL entry failed status: %d\n",
                                  status);
        }
 
        ice_memset(&act_buf, 0, sizeof(act_buf), ICE_NONDMA_MEM);
-       i = ice_find_first_bit(scen->act_mem_bitmap,
-                              ICE_AQC_MAX_ACTION_MEMORIES);
-       while (i < ICE_AQC_MAX_ACTION_MEMORIES) {
+
+       ice_for_each_set_bit(i, scen->act_mem_bitmap,
+                            ICE_AQC_MAX_ACTION_MEMORIES) {
                struct ice_acl_act_mem *mem = &hw->acl_tbl->act_mems[i];
 
                if (mem->member_of_tcam >= entry_tcam &&
@@ -1124,64 +1152,12 @@ ice_acl_rem_entry(struct ice_hw *hw, struct ice_acl_scen *scen, u16 entry_idx)
                        status = ice_aq_program_actpair(hw, i, idx, &act_buf,
                                                        NULL);
                        if (status)
-                               ice_debug(hw, ICE_DBG_ACL,
-                                         "program actpair failed.status: %d\n",
+                               ice_debug(hw, ICE_DBG_ACL, "program actpair failed status: %d\n",
                                          status);
                }
-
-               i = ice_find_next_bit(scen->act_mem_bitmap,
-                                     ICE_AQC_MAX_ACTION_MEMORIES, i + 1);
        }
 
        ice_acl_scen_free_entry_idx(scen, entry_idx);
 
        return status;
 }
-
-/**
- * ice_acl_destroy_scen - Destroy an ACL scenario
- * @hw: pointer to the HW struct
- * @scen_id: ID of the remove scenario
- */
-enum ice_status ice_acl_destroy_scen(struct ice_hw *hw, u16 scen_id)
-{
-       struct ice_acl_scen *scen, *tmp_scen;
-       struct ice_flow_prof *p, *tmp;
-       enum ice_status status;
-
-       if (!hw->acl_tbl)
-               return ICE_ERR_DOES_NOT_EXIST;
-
-       /* Remove profiles that use "scen_id" scenario */
-       LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[ICE_BLK_ACL],
-                                ice_flow_prof, l_entry)
-               if (p->cfg.scen && p->cfg.scen->id == scen_id) {
-                       status = ice_flow_rem_prof(hw, ICE_BLK_ACL, p->id);
-                       if (status) {
-                               ice_debug(hw, ICE_DBG_ACL,
-                                         "ice_flow_rem_prof failed. status: %d\n",
-                                         status);
-                               goto exit;
-                       }
-               }
-
-       /* Call the AQ command to destroy the targeted scenario */
-       status = ice_aq_dealloc_acl_scen(hw, scen_id, NULL);
-
-       if (status) {
-               ice_debug(hw, ICE_DBG_ACL,
-                         "AQ de-allocation of scenario failed. status: %d\n",
-                         status);
-               goto exit;
-       }
-
-       /* Remove scenario from hw->acl_tbl->scens */
-       LIST_FOR_EACH_ENTRY_SAFE(scen, tmp_scen, &hw->acl_tbl->scens,
-                                ice_acl_scen, list_entry)
-               if (scen->id == scen_id) {
-                       LIST_DEL(&scen->list_entry);
-                       ice_free(hw, scen);
-               }
-exit:
-       return status;
-}