1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _ULP_SC_MGR_H_ 7 #define _ULP_SC_MGR_H_ 8 9 #include "pthread.h" 10 #include "bnxt_ulp.h" 11 #include "ulp_flow_db.h" 12 13 #define ULP_FLAG_SC_THREAD BIT(0) 14 15 #define ULP_SC_ENTRY_FLAG_VALID BIT(0) 16 #define ULP_SC_ENTRY_FLAG_PARENT BIT(1) 17 #define ULP_SC_PC_IDX_MASK 0xFFFFF 18 19 #define ULP_SC_BATCH_SIZE 64 20 #define ULP_SC_PAGE_SIZE 4096 21 22 struct ulp_sc_tfc_stats_cache_entry { 23 struct bnxt_ulp_context *ctxt; 24 uint32_t flags : 8; 25 uint32_t pc_idx : 24; 26 uint64_t timestamp; 27 uint64_t handle; 28 uint8_t dir; 29 uint64_t packet_count; 30 uint64_t byte_count; 31 uint64_t count_fields1; 32 uint64_t count_fields2; 33 bool reset; 34 }; 35 36 struct bnxt_ulp_sc_info { 37 struct ulp_sc_tfc_stats_cache_entry *stats_cache_tbl; 38 uint8_t *read_data; 39 uint64_t read_data_iova[ULP_SC_BATCH_SIZE]; 40 uint32_t flags; 41 uint32_t num_entries; 42 uint32_t num_counters; 43 uint32_t cache_tbl_size; 44 rte_thread_t tid; 45 const struct bnxt_ulp_sc_core_ops *sc_ops; 46 }; 47 48 struct bnxt_ulp_sc_core_ops { 49 int32_t 50 (*ulp_stats_cache_update)(struct tfc *tfcp, 51 int dir, 52 uint64_t *host_address, 53 uint64_t handle, 54 uint16_t *words, 55 struct tfc_mpc_batch_info_t *batch_info, 56 bool reset); 57 }; 58 59 /* 60 * Allocate all resources in the stats cache manager for this ulp context 61 * 62 * ctxt [in] The ulp context for the stats cache manager 63 */ 64 int32_t 65 ulp_sc_mgr_init(struct bnxt_ulp_context *ctxt); 66 67 /* 68 * Release all resources in the stats cache manager for this ulp context 69 * 70 * ctxt [in] The ulp context for the stats cache manager 71 */ 72 int32_t 73 ulp_sc_mgr_deinit(struct bnxt_ulp_context *ctxt); 74 75 /* 76 * Setup the stats cache timer thread that will fetch/accumulate raw counter 77 * data from the chip's internal stats caches 78 * 79 * ctxt [in] The ulp context for the stats cache manager 80 */ 81 int32_t 82 ulp_sc_mgr_thread_start(struct bnxt_ulp_context *ctxt); 83 84 /* 85 * Alarm handler that will issue the TF-Core API to fetch 86 * data from the chip's internal stats caches 87 * 88 * ctxt [in] The ulp context for the stats cache manager 89 */ 90 void 91 ulp_sc_mgr_alarm_cb(void *arg); 92 93 /* 94 * Cancel the alarm handler 95 * 96 * ctxt [in] The ulp context for the stats cache manager 97 * 98 */ 99 void ulp_sc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt); 100 101 /* 102 * Check if the thread that walks through the flows is started 103 * 104 * ctxt [in] The ulp context for the stats cache manager 105 * 106 */ 107 bool ulp_sc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt); 108 109 /* 110 * Get the current counts for the given flow id 111 * 112 * ctxt [in] The ulp context for the stats cache manager 113 * flow_id [in] The flow identifier 114 * count [out] structure in which the updated counts are passed 115 * back to the caller. 116 * 117 */ 118 int ulp_sc_mgr_query_count_get(struct bnxt_ulp_context *ctxt, 119 uint32_t flow_id, 120 struct rte_flow_query_count *count); 121 122 /* 123 * Allocate a cache entry for flow 124 * 125 * parms [in] Various fields used to identify the flow 126 * counter_handle [in] This is the action table entry identifier. 127 * tbl [in] Various fields used to identify the flow 128 * 129 */ 130 int ulp_sc_mgr_entry_alloc(struct bnxt_ulp_mapper_parms *parms, 131 uint64_t counter_handle, 132 struct bnxt_ulp_mapper_tbl_info *tbl); 133 134 /* 135 * Free cache entry 136 * 137 * ulp [in] The ulp context for the stats cache manager 138 * fid [in] The flow identifier 139 * 140 */ 141 void ulp_sc_mgr_entry_free(struct bnxt_ulp_context *ulp, 142 uint32_t fid); 143 144 145 /* 146 * Set pc_idx for the flow if stat cache info is valid 147 * 148 * ctxt [in] The ulp context for the flow counter manager 149 * flow_id [in] The HW flow ID 150 * pc_idx [in] The parent flow entry idx 151 * 152 */ 153 void ulp_sc_mgr_set_pc_idx(struct bnxt_ulp_context *ctxt, 154 uint32_t flow_id, 155 uint32_t pc_idx); 156 157 extern const struct bnxt_ulp_sc_core_ops ulp_sc_tfc_core_ops; 158 159 #endif /* _ULP_SC_MGR_H_ */ 160