+
+/*
+ * Fill the rte_flow_query_count 'data' argument passed
+ * in the rte_flow_query() with the values obtained and
+ * accumulated locally.
+ *
+ * ctxt [in] The ulp context for the flow counter manager
+ *
+ * flow_id [in] The HW flow ID
+ *
+ * count [out] The rte_flow_query_count 'data' that is set
+ *
+ */
+int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ctxt,
+ uint32_t flow_id,
+ struct rte_flow_query_count *count)
+{
+ int rc = 0;
+ uint32_t nxt_resource_index = 0;
+ struct bnxt_ulp_fc_info *ulp_fc_info;
+ struct ulp_flow_db_res_params params;
+ enum tf_dir dir;
+ uint32_t hw_cntr_id = 0, sw_cntr_idx = 0;
+ struct sw_acc_counter sw_acc_tbl_entry;
+ bool found_cntr_resource = false;
+
+ ulp_fc_info = bnxt_ulp_cntxt_ptr2_fc_info_get(ctxt);
+ if (!ulp_fc_info)
+ return -ENODEV;
+
+ do {
+ rc = ulp_flow_db_resource_get(ctxt,
+ BNXT_ULP_REGULAR_FLOW_TABLE,
+ flow_id,
+ &nxt_resource_index,
+ ¶ms);
+ if (params.resource_func ==
+ BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
+ (params.resource_sub_type ==
+ BNXT_ULP_RESOURCE_SUB_TYPE_INDEX_TYPE_INT_COUNT ||
+ params.resource_sub_type ==
+ BNXT_ULP_RESOURCE_SUB_TYPE_INDEX_TYPE_EXT_COUNT)) {
+ found_cntr_resource = true;
+ break;
+ }
+
+ } while (!rc);
+
+ if (rc)
+ return rc;
+
+ if (found_cntr_resource) {
+ dir = params.direction;
+ hw_cntr_id = params.resource_hndl;
+ sw_cntr_idx = hw_cntr_id -
+ ulp_fc_info->shadow_hw_tbl[dir].start_idx;
+ sw_acc_tbl_entry = ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx];
+ if (params.resource_sub_type ==
+ BNXT_ULP_RESOURCE_SUB_TYPE_INDEX_TYPE_INT_COUNT) {
+ count->hits_set = 1;
+ count->bytes_set = 1;
+ count->hits = sw_acc_tbl_entry.pkt_count;
+ count->bytes = sw_acc_tbl_entry.byte_count;
+ } else {
+ /* TBD: Handle External counters */
+ rc = -EINVAL;
+ }
+ }
+
+ return rc;
+}