- aparms.dir = tbl->direction;
- aparms.type = tbl->resource_type;
- aparms.search_enable = tbl->srch_b4_alloc;
- aparms.result = ulp_blob_data_get(&data, &tmplen);
- aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
- aparms.tbl_scope_id = tbl_scope_id;
-
- /* All failures after the alloc succeeds require a free */
- rc = tf_alloc_tbl_entry(tfp, &aparms);
- if (rc) {
- BNXT_TF_DBG(ERR, "Alloc table[%d][%s] failed rc=%d\n",
- aparms.type,
- (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
- rc);
- return rc;
- }
+ if (tbl->srch_b4_alloc) {
+ memset(&srchparms, 0, sizeof(srchparms));
+ srchparms.dir = tbl->direction;
+ srchparms.type = tbl->resource_type;
+ srchparms.alloc = 1;
+ srchparms.result = ulp_blob_data_get(&data, &tmplen);
+ srchparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
+ srchparms.tbl_scope_id = tbl_scope_id;
+ rc = tf_search_tbl_entry(tfp, &srchparms);
+ if (rc) {
+ BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
+ tf_tbl_type_2_str(tbl->resource_type),
+ tf_dir_2_str(tbl->direction), rc);
+ return rc;
+ }
+ if (srchparms.search_status == REJECT) {
+ BNXT_TF_DBG(ERR, "Alloc table[%s][%s] rejected.\n",
+ tf_tbl_type_2_str(tbl->resource_type),
+ tf_dir_2_str(tbl->direction));
+ return -ENOMEM;
+ }
+ index = srchparms.idx;
+ hit = srchparms.hit;
+ } else {
+ aparms.dir = tbl->direction;
+ aparms.type = tbl->resource_type;
+ aparms.search_enable = tbl->srch_b4_alloc;
+ aparms.result = ulp_blob_data_get(&data, &tmplen);
+ aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
+ aparms.tbl_scope_id = tbl_scope_id;