xref: /dpdk/drivers/net/bnxt/tf_ulp/ulp_fc_mgr.h (revision f6e1201540603ced7cbaf8c883b03d859df62923)
19cf9c838SSomnath Kotur /* SPDX-License-Identifier: BSD-3-Clause
2d9e70b1dSRandy Schacher  * Copyright(c) 2014-2023 Broadcom
39cf9c838SSomnath Kotur  * All rights reserved.
49cf9c838SSomnath Kotur  */
59cf9c838SSomnath Kotur 
69cf9c838SSomnath Kotur #ifndef _ULP_FC_MGR_H_
79cf9c838SSomnath Kotur #define _ULP_FC_MGR_H_
89cf9c838SSomnath Kotur 
99cf9c838SSomnath Kotur #include "bnxt_ulp.h"
10*f6e12015SKishore Padmanabha #include "ulp_flow_db.h"
119cf9c838SSomnath Kotur 
129cf9c838SSomnath Kotur #define ULP_FLAG_FC_THREAD			BIT(0)
1349cdf043SKishore Padmanabha #define ULP_FLAG_FC_SW_AGG_EN			BIT(1)
1449cdf043SKishore Padmanabha #define ULP_FLAG_FC_PARENT_AGG_EN		BIT(2)
159cf9c838SSomnath Kotur #define ULP_FC_TIMER	1/* Timer freq in Sec Flow Counters */
169cf9c838SSomnath Kotur 
179cf9c838SSomnath Kotur /* Macros to extract packet/byte counters from a 64-bit flow counter. */
189cf9c838SSomnath Kotur #define FLOW_CNTR_BYTE_WIDTH 36
199cf9c838SSomnath Kotur #define FLOW_CNTR_BYTE_MASK  (((uint64_t)1 << FLOW_CNTR_BYTE_WIDTH) - 1)
209cf9c838SSomnath Kotur 
2149b8d40bSSomnath Kotur #define FLOW_CNTR_PKTS(v, d) (((v) & (d)->packet_count_mask) >> \
2249b8d40bSSomnath Kotur 		(d)->packet_count_shift)
2349b8d40bSSomnath Kotur #define FLOW_CNTR_BYTES(v, d) (((v) & (d)->byte_count_mask) >> \
2449b8d40bSSomnath Kotur 		(d)->byte_count_shift)
259cf9c838SSomnath Kotur 
26bdf4a3c6SKishore Padmanabha #define FLOW_CNTR_PC_FLOW_VALID	0x1000000
27bdf4a3c6SKishore Padmanabha 
28dd0191d5SShuanglin Wang struct bnxt_ulp_fc_core_ops {
29dd0191d5SShuanglin Wang 	int32_t
30dd0191d5SShuanglin Wang 	(*ulp_flow_stat_get)(struct bnxt_ulp_context *ctxt,
31dd0191d5SShuanglin Wang 			     uint8_t direction,
32*f6e12015SKishore Padmanabha 			     uint32_t session_type,
33dd0191d5SShuanglin Wang 			     uint64_t handle,
34dd0191d5SShuanglin Wang 			     struct rte_flow_query_count *count);
35dd0191d5SShuanglin Wang 	int32_t
36dd0191d5SShuanglin Wang 	(*ulp_flow_stats_accum_update)(struct bnxt_ulp_context *ctxt,
37dd0191d5SShuanglin Wang 				       struct bnxt_ulp_fc_info *ulp_fc_info,
38dd0191d5SShuanglin Wang 				       struct bnxt_ulp_device_params *dparms);
39dd0191d5SShuanglin Wang };
40dd0191d5SShuanglin Wang 
419cf9c838SSomnath Kotur struct sw_acc_counter {
429cf9c838SSomnath Kotur 	uint64_t pkt_count;
439cf9c838SSomnath Kotur 	uint64_t byte_count;
449cf9c838SSomnath Kotur 	bool	valid;
45306c2d28SSomnath Kotur 	uint32_t hw_cntr_id;
46bdf4a3c6SKishore Padmanabha 	uint32_t pc_flow_idx;
47d9e70b1dSRandy Schacher 	enum bnxt_ulp_session_type session_type;
489cf9c838SSomnath Kotur };
499cf9c838SSomnath Kotur 
509cf9c838SSomnath Kotur struct hw_fc_mem_info {
519cf9c838SSomnath Kotur 	/*
529cf9c838SSomnath Kotur 	 * [out] mem_va, pointer to the allocated memory.
539cf9c838SSomnath Kotur 	 */
549cf9c838SSomnath Kotur 	void *mem_va;
559cf9c838SSomnath Kotur 	/*
569cf9c838SSomnath Kotur 	 * [out] mem_pa, physical address of the allocated memory.
579cf9c838SSomnath Kotur 	 */
589cf9c838SSomnath Kotur 	void *mem_pa;
599cf9c838SSomnath Kotur 	uint32_t start_idx;
60811229d4SSomnath Kotur 	bool start_idx_is_set;
619cf9c838SSomnath Kotur };
629cf9c838SSomnath Kotur 
639cf9c838SSomnath Kotur struct bnxt_ulp_fc_info {
649cf9c838SSomnath Kotur 	struct sw_acc_counter	*sw_acc_tbl[TF_DIR_MAX];
659cf9c838SSomnath Kotur 	struct hw_fc_mem_info	shadow_hw_tbl[TF_DIR_MAX];
669cf9c838SSomnath Kotur 	uint32_t		flags;
679cf9c838SSomnath Kotur 	uint32_t		num_entries;
689cf9c838SSomnath Kotur 	pthread_mutex_t		fc_lock;
691993b267SShahaji Bhosle 	uint32_t		num_counters;
70dd0191d5SShuanglin Wang 	const struct bnxt_ulp_fc_core_ops *fc_ops;
719cf9c838SSomnath Kotur };
729cf9c838SSomnath Kotur 
739cf9c838SSomnath Kotur int32_t
749cf9c838SSomnath Kotur ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt);
759cf9c838SSomnath Kotur 
769cf9c838SSomnath Kotur /*
779cf9c838SSomnath Kotur  * Release all resources in the flow counter manager for this ulp context
789cf9c838SSomnath Kotur  *
799cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
809cf9c838SSomnath Kotur  */
819cf9c838SSomnath Kotur int32_t
829cf9c838SSomnath Kotur ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt);
839cf9c838SSomnath Kotur 
849cf9c838SSomnath Kotur /*
859cf9c838SSomnath Kotur  * Setup the Flow counter timer thread that will fetch/accumulate raw counter
869cf9c838SSomnath Kotur  * data from the chip's internal flow counters
879cf9c838SSomnath Kotur  *
889cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
899cf9c838SSomnath Kotur  */
909cf9c838SSomnath Kotur int32_t
919cf9c838SSomnath Kotur ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt);
929cf9c838SSomnath Kotur 
939cf9c838SSomnath Kotur /*
949cf9c838SSomnath Kotur  * Alarm handler that will issue the TF-Core API to fetch
959cf9c838SSomnath Kotur  * data from the chip's internal flow counters
969cf9c838SSomnath Kotur  *
979cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
989cf9c838SSomnath Kotur  */
999cf9c838SSomnath Kotur void
1009cf9c838SSomnath Kotur ulp_fc_mgr_alarm_cb(void *arg);
1019cf9c838SSomnath Kotur 
1029cf9c838SSomnath Kotur /*
1039cf9c838SSomnath Kotur  * Cancel the alarm handler
1049cf9c838SSomnath Kotur  *
1059cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1069cf9c838SSomnath Kotur  *
1079cf9c838SSomnath Kotur  */
1089cf9c838SSomnath Kotur void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt);
1099cf9c838SSomnath Kotur 
1109cf9c838SSomnath Kotur /*
1119cf9c838SSomnath Kotur  * Set the starting index that indicates the first HW flow
1129cf9c838SSomnath Kotur  * counter ID
1139cf9c838SSomnath Kotur  *
1149cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1159cf9c838SSomnath Kotur  *
1169cf9c838SSomnath Kotur  * dir [in] The direction of the flow
1179cf9c838SSomnath Kotur  *
1189cf9c838SSomnath Kotur  * start_idx [in] The HW flow counter ID
1199cf9c838SSomnath Kotur  *
1209cf9c838SSomnath Kotur  */
121dd0191d5SShuanglin Wang int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, uint8_t dir,
1229cf9c838SSomnath Kotur 			     uint32_t start_idx);
1239cf9c838SSomnath Kotur 
1249cf9c838SSomnath Kotur /*
1259cf9c838SSomnath Kotur  * Set the corresponding SW accumulator table entry based on
1269cf9c838SSomnath Kotur  * the difference between this counter ID and the starting
1279cf9c838SSomnath Kotur  * counter ID. Also, keep track of num of active counter enabled
1289cf9c838SSomnath Kotur  * flows.
1299cf9c838SSomnath Kotur  *
1309cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1319cf9c838SSomnath Kotur  *
1329cf9c838SSomnath Kotur  * dir [in] The direction of the flow
1339cf9c838SSomnath Kotur  *
1349cf9c838SSomnath Kotur  * hw_cntr_id [in] The HW flow counter ID
1359cf9c838SSomnath Kotur  *
1369cf9c838SSomnath Kotur  */
1379cf9c838SSomnath Kotur int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
138d9e70b1dSRandy Schacher 			uint32_t hw_cntr_id,
139d9e70b1dSRandy Schacher 			enum bnxt_ulp_session_type session_type);
140d9e70b1dSRandy Schacher 
1419cf9c838SSomnath Kotur /*
1429cf9c838SSomnath Kotur  * Reset the corresponding SW accumulator table entry based on
1439cf9c838SSomnath Kotur  * the difference between this counter ID and the starting
1449cf9c838SSomnath Kotur  * counter ID.
1459cf9c838SSomnath Kotur  *
1469cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1479cf9c838SSomnath Kotur  *
1489cf9c838SSomnath Kotur  * dir [in] The direction of the flow
1499cf9c838SSomnath Kotur  *
1509cf9c838SSomnath Kotur  * hw_cntr_id [in] The HW flow counter ID
1519cf9c838SSomnath Kotur  *
1529cf9c838SSomnath Kotur  */
153dd0191d5SShuanglin Wang int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, uint8_t dir,
1549cf9c838SSomnath Kotur 			  uint32_t hw_cntr_id);
1559cf9c838SSomnath Kotur /*
1569cf9c838SSomnath Kotur  * Check if the starting HW counter ID value is set in the
1579cf9c838SSomnath Kotur  * flow counter manager.
1589cf9c838SSomnath Kotur  *
1599cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1609cf9c838SSomnath Kotur  *
1619cf9c838SSomnath Kotur  * dir [in] The direction of the flow
1629cf9c838SSomnath Kotur  *
1639cf9c838SSomnath Kotur  */
164dd0191d5SShuanglin Wang bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, uint8_t dir);
1659cf9c838SSomnath Kotur 
1669cf9c838SSomnath Kotur /*
1679cf9c838SSomnath Kotur  * Check if the alarm thread that walks through the flows is started
1689cf9c838SSomnath Kotur  *
1699cf9c838SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
1709cf9c838SSomnath Kotur  *
1719cf9c838SSomnath Kotur  */
1729cf9c838SSomnath Kotur bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt);
1739cf9c838SSomnath Kotur 
174306c2d28SSomnath Kotur /*
175306c2d28SSomnath Kotur  * Fill the rte_flow_query_count 'data' argument passed
176306c2d28SSomnath Kotur  * in the rte_flow_query() with the values obtained and
177306c2d28SSomnath Kotur  * accumulated locally.
178306c2d28SSomnath Kotur  *
179306c2d28SSomnath Kotur  * ctxt [in] The ulp context for the flow counter manager
180306c2d28SSomnath Kotur  *
181306c2d28SSomnath Kotur  * flow_id [in] The HW flow ID
182306c2d28SSomnath Kotur  *
183306c2d28SSomnath Kotur  * count [out] The rte_flow_query_count 'data' that is set
184306c2d28SSomnath Kotur  *
185306c2d28SSomnath Kotur  */
186306c2d28SSomnath Kotur int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx,
187306c2d28SSomnath Kotur 			       uint32_t flow_id,
188306c2d28SSomnath Kotur 			       struct rte_flow_query_count *count);
189640bfd23SKishore Padmanabha 
190640bfd23SKishore Padmanabha /*
191640bfd23SKishore Padmanabha  * Set the parent flow if in the SW accumulator table entry
192640bfd23SKishore Padmanabha  *
193640bfd23SKishore Padmanabha  * ctxt [in] The ulp context for the flow counter manager
194640bfd23SKishore Padmanabha  *
195640bfd23SKishore Padmanabha  * dir [in] The direction of the flow
196640bfd23SKishore Padmanabha  *
197640bfd23SKishore Padmanabha  * hw_cntr_id [in] The HW flow counter ID
198640bfd23SKishore Padmanabha  *
199bdf4a3c6SKishore Padmanabha  * pc_idx [in] parent child db index
200640bfd23SKishore Padmanabha  *
201640bfd23SKishore Padmanabha  */
202640bfd23SKishore Padmanabha int32_t ulp_fc_mgr_cntr_parent_flow_set(struct bnxt_ulp_context *ctxt,
203dd0191d5SShuanglin Wang 					uint8_t dir,
204640bfd23SKishore Padmanabha 					uint32_t hw_cntr_id,
205bdf4a3c6SKishore Padmanabha 					uint32_t pc_idx);
206dd0191d5SShuanglin Wang 
207dd0191d5SShuanglin Wang extern const struct bnxt_ulp_fc_core_ops ulp_fc_tf_core_ops;
208dd0191d5SShuanglin Wang extern const struct bnxt_ulp_fc_core_ops ulp_fc_tfc_core_ops;
209dd0191d5SShuanglin Wang 
2109cf9c838SSomnath Kotur #endif /* _ULP_FC_MGR_H_ */
211