src/dpdk/drivers/net/ice/base/ice_acl_ctrl.c
enum ice_status
ice_acl_create_tbl(struct ice_hw *hw, struct ice_acl_tbl_params *params)
{
	u16 width, depth, first_e, last_e, i;
	struct ice_aqc_acl_generic *resp_buf;
	struct ice_acl_alloc_tbl tbl_alloc;
	struct ice_acl_tbl *tbl;
	enum ice_status status;

	if (hw->acl_tbl)
		return ICE_ERR_ALREADY_EXISTS;

	if (!params)
		return ICE_ERR_PARAM;

	/* round up the width to the next TCAM width boundary. */
	width = ROUND_UP(params->width, (u16)ICE_AQC_ACL_KEY_WIDTH_BYTES);
	/* depth should be provided in chunk (64 entry) increments */
	depth = ICE_ALIGN(params->depth, ICE_ACL_ENTRY_ALLOC_UNIT);

	if (params->entry_act_pairs < width / ICE_AQC_ACL_KEY_WIDTH_BYTES) {
		params->entry_act_pairs = width / ICE_AQC_ACL_KEY_WIDTH_BYTES;

		if (params->entry_act_pairs > ICE_AQC_TBL_MAX_ACTION_PAIRS)
			params->entry_act_pairs = ICE_AQC_TBL_MAX_ACTION_PAIRS;
	}

	/* Validate that width*depth will not exceed the TCAM limit */
	if ((DIVIDE_AND_ROUND_UP(depth, ICE_AQC_ACL_TCAM_DEPTH) *
	     (width / ICE_AQC_ACL_KEY_WIDTH_BYTES)) > ICE_AQC_ACL_SLICES)
		return ICE_ERR_MAX_LIMIT;

	ice_memset(&tbl_alloc, 0, sizeof(tbl_alloc), ICE_NONDMA_MEM);
	tbl_alloc.width = width;
	tbl_alloc.depth = depth;
	tbl_alloc.act_pairs_per_entry = params->entry_act_pairs;
	tbl_alloc.concurr = params->concurr;
	/* Set dependent_alloc_id only for concurrent table type */
	if (params->concurr) {
		tbl_alloc.num_dependent_alloc_ids =
			ICE_AQC_MAX_CONCURRENT_ACL_TBL;

		for (i = 0; i < ICE_AQC_MAX_CONCURRENT_ACL_TBL; i++)
			tbl_alloc.buf.data_buf.alloc_ids[i] =
				CPU_TO_LE16(params->dep_tbls[i]);
	}

	/* 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");
		else
			ice_debug(hw, ICE_DBG_ACL, "AQ allocation of ACL failed with error. status: %d\n",
				  status);
		return status;
	}

	tbl = (struct ice_acl_tbl *)ice_malloc(hw, sizeof(*tbl));
	if (!tbl) {
		status = ICE_ERR_NO_MEMORY;

		goto out;
	}

	resp_buf = &tbl_alloc.buf.resp_buf;

	/* Retrieve information of the allocated table */
	tbl->id = LE16_TO_CPU(resp_buf->alloc_id);
	tbl->first_tcam = resp_buf->ops.table.first_tcam;
	tbl->last_tcam = resp_buf->ops.table.last_tcam;
	tbl->first_entry = LE16_TO_CPU(resp_buf->first_entry);
	tbl->last_entry = LE16_TO_CPU(resp_buf->last_entry);

	tbl->info = *params;
	tbl->info.width = width;
	tbl->info.depth = depth;
	hw->acl_tbl = tbl;

	for (i = 0; i < ICE_AQC_MAX_ACTION_MEMORIES; i++)
		tbl->act_mems[i].act_mem = resp_buf->act_mem[i];

	/* Figure out which TCAMs that these newly allocated action memories
	 * belong to.
	 */
	ice_acl_divide_act_mems_to_tcams(tbl);

	/* Initialize the resources allocated by invalidating all TCAM entries
	 * and all the action pairs
	 */
	status = ice_acl_init_tbl(hw);
	if (status) {
		ice_free(hw, tbl);
		hw->acl_tbl = NULL;
		ice_debug(hw, ICE_DBG_ACL, "Initialization of TCAM entries failed. status: %d\n",
			  status);
		goto out;
	}

	first_e = (tbl->first_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS) +
		(tbl->first_entry / ICE_ACL_ENTRY_ALLOC_UNIT);
	last_e = (tbl->last_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS) +
		(tbl->last_entry / ICE_ACL_ENTRY_ALLOC_UNIT);

	/* Indicate available entries in the table */
	ice_bitmap_set(tbl->avail, first_e, last_e - first_e + 1);

	INIT_LIST_HEAD(&tbl->scens);
out:

	return status;
}
/**
 * ice_acl_create_tbl
 * @hw: pointer to the HW struct
 * @params: parameters for the table to be created
 *
 * Create a LEM table for ACL usage. We are currently starting with some fixed
 * values for the size of the table, but this will need to grow as more flow
 * entries are added by the user level.
 */
ice_acl_create_tbl
@hw: pointer to the HW struct
@params: parameters for the table to be created

Create a LEM table for ACL usage. We are currently starting with some fixed
values for the size of the table, but this will need to grow as more flow
entries are added by the user level.
ice_acl_create_tbl @hw : pointer to the HW struct @params : parameters for the table to be created Create a LEM table for ACL usage . We are currently starting with some fixed values for the size of the table but this will need to grow as more flow entries are added by the user level .
enum ice_status
ice_acl_create_tbl(struct ice_hw *hw, struct ice_acl_tbl_params *params)
{
	u16 width, depth, first_e, last_e, i;
	struct ice_aqc_acl_generic *resp_buf;
	struct ice_acl_alloc_tbl tbl_alloc;
	struct ice_acl_tbl *tbl;
	enum ice_status status;
	if (hw->acl_tbl)
		return ICE_ERR_ALREADY_EXISTS;
	if (!params)
		return ICE_ERR_PARAM;
	width = ROUND_UP(params->width, (u16)ICE_AQC_ACL_KEY_WIDTH_BYTES);
	depth = ICE_ALIGN(params->depth, ICE_ACL_ENTRY_ALLOC_UNIT);
	if (params->entry_act_pairs < width / ICE_AQC_ACL_KEY_WIDTH_BYTES) {
		params->entry_act_pairs = width / ICE_AQC_ACL_KEY_WIDTH_BYTES;
		if (params->entry_act_pairs > ICE_AQC_TBL_MAX_ACTION_PAIRS)
			params->entry_act_pairs = ICE_AQC_TBL_MAX_ACTION_PAIRS;
	}
	if ((DIVIDE_AND_ROUND_UP(depth, ICE_AQC_ACL_TCAM_DEPTH) *
	     (width / ICE_AQC_ACL_KEY_WIDTH_BYTES)) > ICE_AQC_ACL_SLICES)
		return ICE_ERR_MAX_LIMIT;
	ice_memset(&tbl_alloc, 0, sizeof(tbl_alloc), ICE_NONDMA_MEM);
	tbl_alloc.width = width;
	tbl_alloc.depth = depth;
	tbl_alloc.act_pairs_per_entry = params->entry_act_pairs;
	tbl_alloc.concurr = params->concurr;
	if (params->concurr) {
		tbl_alloc.num_dependent_alloc_ids =
			ICE_AQC_MAX_CONCURRENT_ACL_TBL;
		for (i = 0; i < ICE_AQC_MAX_CONCURRENT_ACL_TBL; i++)
			tbl_alloc.buf.data_buf.alloc_ids[i] =
				CPU_TO_LE16(params->dep_tbls[i]);
	}
	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");
		else
			ice_debug(hw, ICE_DBG_ACL, "AQ allocation of ACL failed with error. status: %d\n",
				  status);
		return status;
	}
	tbl = (struct ice_acl_tbl *)ice_malloc(hw, sizeof(*tbl));
	if (!tbl) {
		status = ICE_ERR_NO_MEMORY;
		goto out;
	}
	resp_buf = &tbl_alloc.buf.resp_buf;
	tbl->id = LE16_TO_CPU(resp_buf->alloc_id);
	tbl->first_tcam = resp_buf->ops.table.first_tcam;
	tbl->last_tcam = resp_buf->ops.table.last_tcam;
	tbl->first_entry = LE16_TO_CPU(resp_buf->first_entry);
	tbl->last_entry = LE16_TO_CPU(resp_buf->last_entry);
	tbl->info = *params;
	tbl->info.width = width;
	tbl->info.depth = depth;
	hw->acl_tbl = tbl;
	for (i = 0; i < ICE_AQC_MAX_ACTION_MEMORIES; i++)
		tbl->act_mems[i].act_mem = resp_buf->act_mem[i];
	ice_acl_divide_act_mems_to_tcams(tbl);
	status = ice_acl_init_tbl(hw);
	if (status) {
		ice_free(hw, tbl);
		hw->acl_tbl = NULL;
		ice_debug(hw, ICE_DBG_ACL, "Initialization of TCAM entries failed. status: %d\n",
			  status);
		goto out;
	}
	first_e = (tbl->first_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS) +
		(tbl->first_entry / ICE_ACL_ENTRY_ALLOC_UNIT);
	last_e = (tbl->last_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS) +
		(tbl->last_entry / ICE_ACL_ENTRY_ALLOC_UNIT);
	ice_bitmap_set(tbl->avail, first_e, last_e - first_e + 1);
	INIT_LIST_HEAD(&tbl->scens);
out:
	return status;
}
enum ice_status ice_acl_create_tbl ( struct ice_hw * hw , struct ice_acl_tbl_params * params ) { u16 width , depth , first_e , last_e , i ; struct ice_aqc_acl_generic * resp_buf ; struct ice_acl_alloc_tbl tbl_alloc ; struct ice_acl_tbl * tbl ; enum ice_status status ; if ( hw -> acl_tbl ) return ICE_ERR_ALREADY_EXISTS ; if ( ! params ) return ICE_ERR_PARAM ; width = ROUND_UP ( params -> width , ( u16 ) ICE_AQC_ACL_KEY_WIDTH_BYTES ) ; depth = ICE_ALIGN ( params -> depth , ICE_ACL_ENTRY_ALLOC_UNIT ) ; if ( params -> entry_act_pairs < width / ICE_AQC_ACL_KEY_WIDTH_BYTES ) { params -> entry_act_pairs = width / ICE_AQC_ACL_KEY_WIDTH_BYTES ; if ( params -> entry_act_pairs > ICE_AQC_TBL_MAX_ACTION_PAIRS ) params -> entry_act_pairs = ICE_AQC_TBL_MAX_ACTION_PAIRS ; } if ( ( DIVIDE_AND_ROUND_UP ( depth , ICE_AQC_ACL_TCAM_DEPTH ) * ( width / ICE_AQC_ACL_KEY_WIDTH_BYTES ) ) > ICE_AQC_ACL_SLICES ) return ICE_ERR_MAX_LIMIT ; ice_memset ( & tbl_alloc , 0 , sizeof ( tbl_alloc ) , ICE_NONDMA_MEM ) ; tbl_alloc . width = width ; tbl_alloc . depth = depth ; tbl_alloc . act_pairs_per_entry = params -> entry_act_pairs ; tbl_alloc . concurr = params -> concurr ; if ( params -> concurr ) { tbl_alloc . num_dependent_alloc_ids = ICE_AQC_MAX_CONCURRENT_ACL_TBL ; for ( i = 0 ; i < ICE_AQC_MAX_CONCURRENT_ACL_TBL ; i ++ ) tbl_alloc . buf . data_buf . alloc_ids [ i ] = CPU_TO_LE16 ( params -> dep_tbls [ i ] ) ; } 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 , " \n " ) ; else ice_debug ( hw , ICE_DBG_ACL , " \n " , status ) ; return status ; } tbl = ( struct ice_acl_tbl * ) ice_malloc ( hw , sizeof ( * tbl ) ) ; if ( ! tbl ) { status = ICE_ERR_NO_MEMORY ; goto out ; } resp_buf = & tbl_alloc . buf . resp_buf ; tbl -> id = LE16_TO_CPU ( resp_buf -> alloc_id ) ; tbl -> first_tcam = resp_buf -> ops . table . first_tcam ; tbl -> last_tcam = resp_buf -> ops . table . last_tcam ; tbl -> first_entry = LE16_TO_CPU ( resp_buf -> first_entry ) ; tbl -> last_entry = LE16_TO_CPU ( resp_buf -> last_entry ) ; tbl -> info = * params ; tbl -> info . width = width ; tbl -> info . depth = depth ; hw -> acl_tbl = tbl ; for ( i = 0 ; i < ICE_AQC_MAX_ACTION_MEMORIES ; i ++ ) tbl -> act_mems [ i ] . act_mem = resp_buf -> act_mem [ i ] ; ice_acl_divide_act_mems_to_tcams ( tbl ) ; status = ice_acl_init_tbl ( hw ) ; if ( status ) { ice_free ( hw , tbl ) ; hw -> acl_tbl = NULL ; ice_debug ( hw , ICE_DBG_ACL , " \n " , status ) ; goto out ; } first_e = ( tbl -> first_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS ) + ( tbl -> first_entry / ICE_ACL_ENTRY_ALLOC_UNIT ) ; last_e = ( tbl -> last_tcam * ICE_AQC_MAX_TCAM_ALLOC_UNITS ) + ( tbl -> last_entry / ICE_ACL_ENTRY_ALLOC_UNIT ) ; ice_bitmap_set ( tbl -> avail , first_e , last_e - first_e + 1 ) ; INIT_LIST_HEAD ( & tbl -> scens ) ; out : return status ; }
ice_acl_create_tbl
 @hw: pointer to the HW struct
 @params: parameters for the table to be created
ice_acl_create_tbl @hw : pointer to the HW struct @params : parameters for the table to be created
/* round up the width to the next TCAM width boundary. */ /* depth should be provided in chunk (64 entry) increments */ /* Validate that width*depth will not exceed the TCAM limit */ /* Set dependent_alloc_id only for concurrent table type */ /* call the AQ command to create the ACL table with these values */ /* Retrieve information of the allocated table */ /* Figure out which TCAMs that these newly allocated action memories
	 * belong to.
	 */ /* Initialize the resources allocated by invalidating all TCAM entries
	 * and all the action pairs
	 */ /* Indicate available entries in the table */