net/bnxt: support count action in flow query
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_fc_mgr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2019 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _ULP_FC_MGR_H_
7 #define _ULP_FC_MGR_H_
8
9 #include "bnxt_ulp.h"
10 #include "tf_core.h"
11
12 #define ULP_FLAG_FC_THREAD                      BIT(0)
13 #define ULP_FC_TIMER    1/* Timer freq in Sec Flow Counters */
14
15 /* Macros to extract packet/byte counters from a 64-bit flow counter. */
16 #define FLOW_CNTR_BYTE_WIDTH 36
17 #define FLOW_CNTR_BYTE_MASK  (((uint64_t)1 << FLOW_CNTR_BYTE_WIDTH) - 1)
18
19 #define FLOW_CNTR_PKTS(v) ((v) >> FLOW_CNTR_BYTE_WIDTH)
20 #define FLOW_CNTR_BYTES(v) ((v) & FLOW_CNTR_BYTE_MASK)
21
22 struct sw_acc_counter {
23         uint64_t pkt_count;
24         uint64_t byte_count;
25         bool    valid;
26         uint32_t hw_cntr_id;
27 };
28
29 struct hw_fc_mem_info {
30         /*
31          * [out] mem_va, pointer to the allocated memory.
32          */
33         void *mem_va;
34         /*
35          * [out] mem_pa, physical address of the allocated memory.
36          */
37         void *mem_pa;
38         uint32_t start_idx;
39 };
40
41 struct bnxt_ulp_fc_info {
42         struct sw_acc_counter   *sw_acc_tbl[TF_DIR_MAX];
43         struct hw_fc_mem_info   shadow_hw_tbl[TF_DIR_MAX];
44         uint32_t                flags;
45         uint32_t                num_entries;
46         pthread_mutex_t         fc_lock;
47 };
48
49 int32_t
50 ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt);
51
52 /*
53  * Release all resources in the flow counter manager for this ulp context
54  *
55  * ctxt [in] The ulp context for the flow counter manager
56  */
57 int32_t
58 ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt);
59
60 /*
61  * Setup the Flow counter timer thread that will fetch/accumulate raw counter
62  * data from the chip's internal flow counters
63  *
64  * ctxt [in] The ulp context for the flow counter manager
65  */
66 int32_t
67 ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt);
68
69 /*
70  * Alarm handler that will issue the TF-Core API to fetch
71  * data from the chip's internal flow counters
72  *
73  * ctxt [in] The ulp context for the flow counter manager
74  */
75 void
76 ulp_fc_mgr_alarm_cb(void *arg);
77
78 /*
79  * Cancel the alarm handler
80  *
81  * ctxt [in] The ulp context for the flow counter manager
82  *
83  */
84 void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt);
85
86 /*
87  * Set the starting index that indicates the first HW flow
88  * counter ID
89  *
90  * ctxt [in] The ulp context for the flow counter manager
91  *
92  * dir [in] The direction of the flow
93  *
94  * start_idx [in] The HW flow counter ID
95  *
96  */
97 int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
98                              uint32_t start_idx);
99
100 /*
101  * Set the corresponding SW accumulator table entry based on
102  * the difference between this counter ID and the starting
103  * counter ID. Also, keep track of num of active counter enabled
104  * flows.
105  *
106  * ctxt [in] The ulp context for the flow counter manager
107  *
108  * dir [in] The direction of the flow
109  *
110  * hw_cntr_id [in] The HW flow counter ID
111  *
112  */
113 int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
114                         uint32_t hw_cntr_id);
115 /*
116  * Reset the corresponding SW accumulator table entry based on
117  * the difference between this counter ID and the starting
118  * counter ID.
119  *
120  * ctxt [in] The ulp context for the flow counter manager
121  *
122  * dir [in] The direction of the flow
123  *
124  * hw_cntr_id [in] The HW flow counter ID
125  *
126  */
127 int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
128                           uint32_t hw_cntr_id);
129 /*
130  * Check if the starting HW counter ID value is set in the
131  * flow counter manager.
132  *
133  * ctxt [in] The ulp context for the flow counter manager
134  *
135  * dir [in] The direction of the flow
136  *
137  */
138 bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, enum tf_dir dir);
139
140 /*
141  * Check if the alarm thread that walks through the flows is started
142  *
143  * ctxt [in] The ulp context for the flow counter manager
144  *
145  */
146 bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt);
147
148 /*
149  * Fill the rte_flow_query_count 'data' argument passed
150  * in the rte_flow_query() with the values obtained and
151  * accumulated locally.
152  *
153  * ctxt [in] The ulp context for the flow counter manager
154  *
155  * flow_id [in] The HW flow ID
156  *
157  * count [out] The rte_flow_query_count 'data' that is set
158  *
159  */
160 int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx,
161                                uint32_t flow_id,
162                                struct rte_flow_query_count *count);
163 #endif /* _ULP_FC_MGR_H_ */