net/sfc: add pattern parsing stub to MAE backend
[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, d) (((v) & (d)->packet_count_mask) >> \
20                 (d)->packet_count_shift)
21 #define FLOW_CNTR_BYTES(v, d) (((v) & (d)->byte_count_mask) >> \
22                 (d)->byte_count_shift)
23
24 struct sw_acc_counter {
25         uint64_t pkt_count;
26         uint64_t byte_count;
27         bool    valid;
28         uint32_t hw_cntr_id;
29 };
30
31 struct hw_fc_mem_info {
32         /*
33          * [out] mem_va, pointer to the allocated memory.
34          */
35         void *mem_va;
36         /*
37          * [out] mem_pa, physical address of the allocated memory.
38          */
39         void *mem_pa;
40         uint32_t start_idx;
41         bool start_idx_is_set;
42 };
43
44 struct bnxt_ulp_fc_info {
45         struct sw_acc_counter   *sw_acc_tbl[TF_DIR_MAX];
46         struct hw_fc_mem_info   shadow_hw_tbl[TF_DIR_MAX];
47         uint32_t                flags;
48         uint32_t                num_entries;
49         pthread_mutex_t         fc_lock;
50 };
51
52 int32_t
53 ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt);
54
55 /*
56  * Release all resources in the flow counter manager for this ulp context
57  *
58  * ctxt [in] The ulp context for the flow counter manager
59  */
60 int32_t
61 ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt);
62
63 /*
64  * Setup the Flow counter timer thread that will fetch/accumulate raw counter
65  * data from the chip's internal flow counters
66  *
67  * ctxt [in] The ulp context for the flow counter manager
68  */
69 int32_t
70 ulp_fc_mgr_thread_start(struct bnxt_ulp_context *ctxt);
71
72 /*
73  * Alarm handler that will issue the TF-Core API to fetch
74  * data from the chip's internal flow counters
75  *
76  * ctxt [in] The ulp context for the flow counter manager
77  */
78 void
79 ulp_fc_mgr_alarm_cb(void *arg);
80
81 /*
82  * Cancel the alarm handler
83  *
84  * ctxt [in] The ulp context for the flow counter manager
85  *
86  */
87 void ulp_fc_mgr_thread_cancel(struct bnxt_ulp_context *ctxt);
88
89 /*
90  * Set the starting index that indicates the first HW flow
91  * counter ID
92  *
93  * ctxt [in] The ulp context for the flow counter manager
94  *
95  * dir [in] The direction of the flow
96  *
97  * start_idx [in] The HW flow counter ID
98  *
99  */
100 int ulp_fc_mgr_start_idx_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
101                              uint32_t start_idx);
102
103 /*
104  * Set the corresponding SW accumulator table entry based on
105  * the difference between this counter ID and the starting
106  * counter ID. Also, keep track of num of active counter enabled
107  * flows.
108  *
109  * ctxt [in] The ulp context for the flow counter manager
110  *
111  * dir [in] The direction of the flow
112  *
113  * hw_cntr_id [in] The HW flow counter ID
114  *
115  */
116 int ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
117                         uint32_t hw_cntr_id);
118 /*
119  * Reset the corresponding SW accumulator table entry based on
120  * the difference between this counter ID and the starting
121  * counter ID.
122  *
123  * ctxt [in] The ulp context for the flow counter manager
124  *
125  * dir [in] The direction of the flow
126  *
127  * hw_cntr_id [in] The HW flow counter ID
128  *
129  */
130 int ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, enum tf_dir dir,
131                           uint32_t hw_cntr_id);
132 /*
133  * Check if the starting HW counter ID value is set in the
134  * flow counter manager.
135  *
136  * ctxt [in] The ulp context for the flow counter manager
137  *
138  * dir [in] The direction of the flow
139  *
140  */
141 bool ulp_fc_mgr_start_idx_isset(struct bnxt_ulp_context *ctxt, enum tf_dir dir);
142
143 /*
144  * Check if the alarm thread that walks through the flows is started
145  *
146  * ctxt [in] The ulp context for the flow counter manager
147  *
148  */
149 bool ulp_fc_mgr_thread_isstarted(struct bnxt_ulp_context *ctxt);
150
151 /*
152  * Fill the rte_flow_query_count 'data' argument passed
153  * in the rte_flow_query() with the values obtained and
154  * accumulated locally.
155  *
156  * ctxt [in] The ulp context for the flow counter manager
157  *
158  * flow_id [in] The HW flow ID
159  *
160  * count [out] The rte_flow_query_count 'data' that is set
161  *
162  */
163 int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ulp_ctx,
164                                uint32_t flow_id,
165                                struct rte_flow_query_count *count);
166 #endif /* _ULP_FC_MGR_H_ */