net/ice/base: introduce and use bitmap set API
authorQi Zhang <qi.z.zhang@intel.com>
Wed, 26 Aug 2020 07:04:26 +0000 (15:04 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 18 Sep 2020 16:55:09 +0000 (18:55 +0200)
Introduce ice_bitmap_set() and use it instead of open-coding that
functionality.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Qiming Yang <qiming.yang@intel.com>
drivers/net/ice/base/ice_acl_ctrl.c
drivers/net/ice/base/ice_bitops.h
drivers/net/ice/base/ice_flex_pipe.c
drivers/net/ice/base/ice_switch.c

index 5310b9d..a732397 100644 (file)
@@ -354,7 +354,6 @@ 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)
@@ -415,8 +414,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:
index 3022116..8352b5d 100644 (file)
@@ -375,6 +375,25 @@ static inline void ice_cp_bitmap(ice_bitmap_t *dst, ice_bitmap_t *src, u16 size)
                   ICE_NONDMA_TO_NONDMA);
 }
 
+/**
+ * ice_bitmap_set - set a number of bits in bitmap from a starting position
+ * @dst: bitmap destination
+ * @pos: first bit position to set
+ * @num_bits: number of bits to set
+ *
+ * This function sets bits in a bitmap from pos to (pos + num_bits) - 1.
+ * Note that this function assumes it is operating on a bitmap declared using
+ * ice_declare_bitmap.
+ */
+static inline void
+ice_bitmap_set(ice_bitmap_t *dst, u16 pos, u16 num_bits)
+{
+       u16 i;
+
+       for (i = pos; i < num_bits; i++)
+               ice_set_bit(i, dst);
+}
+
 /**
  * ice_cmp_bitmaps - compares two bitmaps.
  * @bmp1: the bitmap to compare
index 25d79b5..a083909 100644 (file)
@@ -1580,18 +1580,13 @@ ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
        struct ice_seg *ice_seg;
        struct ice_fv *fv;
 
-       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
-
        if (req_profs == ICE_PROF_ALL) {
-               u16 i;
-
-               for (i = 0; i < ICE_MAX_NUM_PROFILES; i++)
-                       ice_set_bit(i, bm);
+               ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES);
                return;
        }
 
+       ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
        ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
-
        ice_seg = hw->seg;
        do {
                enum ice_prof_type prof_type;
index 858a732..41ebfed 100644 (file)
@@ -5940,8 +5940,7 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const ice_bitmap_t *profiles,
        ice_zero_bitmap(used_idx, ICE_MAX_FV_WORDS);
        ice_zero_bitmap(free_idx, ICE_MAX_FV_WORDS);
 
-       for (count = 0; count < ICE_MAX_FV_WORDS; count++)
-               ice_set_bit(count, possible_idx);
+       ice_bitmap_set(possible_idx, 0, ICE_MAX_FV_WORDS);
 
        /* For each profile we are going to associate the recipe with, add the
         * recipes that are associated with that profile. This will give us