src/dpdk/drivers/net/bnxt/tf_ulp/ulp_mapper.c
int32_t
ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
		       struct bnxt_ulp_mapper_create_parms *cparms)
{
	struct bnxt_ulp_mapper_parms parms;
	struct ulp_regfile regfile;
	int32_t	 rc, trc;

	if (!ulp_ctx || !cparms)
		return -EINVAL;

	/* Initialize the parms structure */
	memset(&parms, 0, sizeof(parms));
	parms.act_prop = cparms->act_prop;
	parms.act_bitmap = cparms->act;
	parms.hdr_bitmap = cparms->hdr_bitmap;
	parms.regfile = &regfile;
	parms.hdr_field = cparms->hdr_field;
	parms.comp_fld = cparms->comp_fld;
	parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
	parms.ulp_ctx = ulp_ctx;
	parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
	parms.act_tid = cparms->act_tid;
	parms.class_tid = cparms->class_tid;
	parms.flow_type = cparms->flow_type;
	parms.parent_flow = cparms->parent_flow;
	parms.parent_fid = cparms->parent_fid;
	parms.fid = cparms->flow_id;
	parms.tun_idx = cparms->tun_idx;

	/* Get the device id from the ulp context */
	if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
		BNXT_TF_DBG(ERR, "Invalid ulp context\n");
		return -EINVAL;
	}

	/* Get the device params, it will be used in later processing */
	parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
	if (!parms.device_params) {
		BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
			    parms.dev_id);
		return -EINVAL;
	}

	/*
	 * Get the mapper data for dynamic mapper data such as default
	 * ids.
	 */
	parms.mapper_data = (struct bnxt_ulp_mapper_data *)
		bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
	if (!parms.mapper_data) {
		BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
		return -EINVAL;
	}

	/* initialize the registry file for further processing */
	if (!ulp_regfile_init(parms.regfile)) {
		BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
		return -EINVAL;
	}

	rc = ulp_regfile_write(parms.regfile,
			       BNXT_ULP_REGFILE_INDEX_CLASS_TID,
			       tfp_cpu_to_be_64((uint64_t)parms.class_tid));
	if (!rc) {
		BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
		return -EINVAL;
	}

	/* Process the action template list from the selected action table*/
	if (parms.act_tid) {
		parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
		/* Process the action template tables */
		rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
		if (rc)
			goto flow_error;
	}

	if (parms.class_tid) {
		parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;

		/* Process the class template tables.*/
		rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
		if (rc)
			goto flow_error;
	}

	/* setup the parent-child details */
	if (parms.parent_flow) {
		/* create a parent flow details */
		rc = ulp_flow_db_parent_flow_create(&parms);
		if (rc)
			goto flow_error;
	} else if (parms.parent_fid) {
		/* create a child flow details */
		rc = ulp_flow_db_child_flow_create(&parms);
		if (rc)
			goto flow_error;
	}

	return rc;

flow_error:
	/* Free all resources that were allocated during flow creation */
	trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
				      parms.fid);
	if (trc)
		BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);

	return rc;
}
/* Function to handle the mapping of the Flow to be compatible
 * with the underlying hardware.
 */
Function to handle the mapping of the Flow to be compatible
with the underlying hardware.
Function to handle the mapping of the Flow to be compatible with the underlying hardware .
int32_t
ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
		       struct bnxt_ulp_mapper_create_parms *cparms)
{
	struct bnxt_ulp_mapper_parms parms;
	struct ulp_regfile regfile;
	int32_t	 rc, trc;
	if (!ulp_ctx || !cparms)
		return -EINVAL;
	memset(&parms, 0, sizeof(parms));
	parms.act_prop = cparms->act_prop;
	parms.act_bitmap = cparms->act;
	parms.hdr_bitmap = cparms->hdr_bitmap;
	parms.regfile = &regfile;
	parms.hdr_field = cparms->hdr_field;
	parms.comp_fld = cparms->comp_fld;
	parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
	parms.ulp_ctx = ulp_ctx;
	parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
	parms.act_tid = cparms->act_tid;
	parms.class_tid = cparms->class_tid;
	parms.flow_type = cparms->flow_type;
	parms.parent_flow = cparms->parent_flow;
	parms.parent_fid = cparms->parent_fid;
	parms.fid = cparms->flow_id;
	parms.tun_idx = cparms->tun_idx;
	if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
		BNXT_TF_DBG(ERR, "Invalid ulp context\n");
		return -EINVAL;
	}
	parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
	if (!parms.device_params) {
		BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
			    parms.dev_id);
		return -EINVAL;
	}
	parms.mapper_data = (struct bnxt_ulp_mapper_data *)
		bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
	if (!parms.mapper_data) {
		BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
		return -EINVAL;
	}
	if (!ulp_regfile_init(parms.regfile)) {
		BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
		return -EINVAL;
	}
	rc = ulp_regfile_write(parms.regfile,
			       BNXT_ULP_REGFILE_INDEX_CLASS_TID,
			       tfp_cpu_to_be_64((uint64_t)parms.class_tid));
	if (!rc) {
		BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
		return -EINVAL;
	}
	if (parms.act_tid) {
		parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
		rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
		if (rc)
			goto flow_error;
	}
	if (parms.class_tid) {
		parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
		rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
		if (rc)
			goto flow_error;
	}
	if (parms.parent_flow) {
		rc = ulp_flow_db_parent_flow_create(&parms);
		if (rc)
			goto flow_error;
	} else if (parms.parent_fid) {
		rc = ulp_flow_db_child_flow_create(&parms);
		if (rc)
			goto flow_error;
	}
	return rc;
flow_error:
	trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
				      parms.fid);
	if (trc)
		BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
	return rc;
}
int32_t ulp_mapper_flow_create ( struct bnxt_ulp_context * ulp_ctx , struct bnxt_ulp_mapper_create_parms * cparms ) { struct bnxt_ulp_mapper_parms parms ; struct ulp_regfile regfile ; int32_t rc , trc ; if ( ! ulp_ctx || ! cparms ) return - EINVAL ; memset ( & parms , 0 , sizeof ( parms ) ) ; parms . act_prop = cparms -> act_prop ; parms . act_bitmap = cparms -> act ; parms . hdr_bitmap = cparms -> hdr_bitmap ; parms . regfile = & regfile ; parms . hdr_field = cparms -> hdr_field ; parms . comp_fld = cparms -> comp_fld ; parms . tfp = bnxt_ulp_cntxt_tfp_get ( ulp_ctx ) ; parms . ulp_ctx = ulp_ctx ; parms . tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL ; parms . act_tid = cparms -> act_tid ; parms . class_tid = cparms -> class_tid ; parms . flow_type = cparms -> flow_type ; parms . parent_flow = cparms -> parent_flow ; parms . parent_fid = cparms -> parent_fid ; parms . fid = cparms -> flow_id ; parms . tun_idx = cparms -> tun_idx ; if ( bnxt_ulp_cntxt_dev_id_get ( ulp_ctx , & parms . dev_id ) ) { BNXT_TF_DBG ( ERR , " \n " ) ; return - EINVAL ; } parms . device_params = bnxt_ulp_device_params_get ( parms . dev_id ) ; if ( ! parms . device_params ) { BNXT_TF_DBG ( ERR , " \n " , parms . dev_id ) ; return - EINVAL ; } parms . mapper_data = ( struct bnxt_ulp_mapper_data * ) bnxt_ulp_cntxt_ptr2_mapper_data_get ( ulp_ctx ) ; if ( ! parms . mapper_data ) { BNXT_TF_DBG ( ERR , " \n " ) ; return - EINVAL ; } if ( ! ulp_regfile_init ( parms . regfile ) ) { BNXT_TF_DBG ( ERR , " \n " ) ; return - EINVAL ; } rc = ulp_regfile_write ( parms . regfile , BNXT_ULP_REGFILE_INDEX_CLASS_TID , tfp_cpu_to_be_64 ( ( uint64_t ) parms . class_tid ) ) ; if ( ! rc ) { BNXT_TF_DBG ( ERR , " \n " ) ; return - EINVAL ; } if ( parms . act_tid ) { parms . tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION ; rc = ulp_mapper_tbls_process ( & parms , parms . act_tid ) ; if ( rc ) goto flow_error ; } if ( parms . class_tid ) { parms . tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS ; rc = ulp_mapper_tbls_process ( & parms , parms . class_tid ) ; if ( rc ) goto flow_error ; } if ( parms . parent_flow ) { rc = ulp_flow_db_parent_flow_create ( & parms ) ; if ( rc ) goto flow_error ; } else if ( parms . parent_fid ) { rc = ulp_flow_db_child_flow_create ( & parms ) ; if ( rc ) goto flow_error ; } return rc ; flow_error : trc = ulp_mapper_flow_destroy ( ulp_ctx , BNXT_ULP_FDB_TYPE_REGULAR , parms . fid ) ; if ( trc ) BNXT_TF_DBG ( ERR , " \n " , trc ) ; return rc ; }
Function to handle the mapping of the Flow to be compatible
 with the underlying hardware.
Function to handle the mapping of the Flow to be compatible with the underlying hardware .
/* Initialize the parms structure */ /* Get the device id from the ulp context */ /* Get the device params, it will be used in later processing */ /*
	 * Get the mapper data for dynamic mapper data such as default
	 * ids.
	 */ /* initialize the registry file for further processing */ /* Process the action template list from the selected action table*/ /* Process the action template tables */ /* Process the class template tables.*/ /* setup the parent-child details */ /* create a parent flow details */ /* create a child flow details */ /* Free all resources that were allocated during flow creation */