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