eal: remove sys/queue.h from public headers
[dpdk.git] / drivers / net / bnxt / tf_core / tf_sram_mgr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_SRAM_MGR_H_
7 #define _TF_SRAM_MGR_H_
8
9 #include <string.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <ctype.h>
15 #include <limits.h>
16 #include <errno.h>
17 #include "tf_core.h"
18 #include "tf_rm.h"
19
20 /* When special access registers are used to access the SRAM, stats can be
21  * automatically cleared on read by the hardware.  This requires additional
22  * support to be added in the firmware to use these registers for statistics.
23  * The support entails using the special access registers to read the stats.
24  * These are stored in bank 3 currently but may move depending upon the
25  * policy defined in tf_device_p58.h
26  */
27 #define STATS_CLEAR_ON_READ_SUPPORT 0
28
29 #define TF_SRAM_MGR_BLOCK_SZ_BYTES 64
30 #define TF_SRAM_MGR_MIN_SLICE_BYTES 8
31 /**
32  * Bank identifier
33  */
34 enum tf_sram_bank_id {
35         TF_SRAM_BANK_ID_0,              /**< SRAM Bank 0 id */
36         TF_SRAM_BANK_ID_1,              /**< SRAM Bank 1 id */
37         TF_SRAM_BANK_ID_2,              /**< SRAM Bank 2 id */
38         TF_SRAM_BANK_ID_3,              /**< SRAM Bank 3 id */
39         TF_SRAM_BANK_ID_MAX             /**< SRAM Bank index limit */
40 };
41
42 /**
43  * TF slice size.
44  *
45  * A slice is part of a 64B row
46  *
47  * Each slice is a multiple of 8B
48  */
49 enum tf_sram_slice_size {
50         TF_SRAM_SLICE_SIZE_8B,  /**< 8 byte SRAM slice */
51         TF_SRAM_SLICE_SIZE_16B, /**< 16 byte SRAM slice */
52         TF_SRAM_SLICE_SIZE_32B, /**< 32 byte SRAM slice */
53         TF_SRAM_SLICE_SIZE_64B, /**< 64 byte SRAM slice */
54         TF_SRAM_SLICE_SIZE_MAX  /**< slice limit */
55 };
56
57
58 /** Initialize the SRAM slice manager
59  *
60  *  The SRAM slice manager manages slices within 64B rows. Slices are of size
61  *  tf_sram_slice_size.  This function provides a handle to the SRAM manager
62  *  data.
63  *
64  *  SRAM manager data may dynamically allocate data upon initialization if
65  *  running on the host.
66  *
67  * [in/out] sram_handle
68  *   Pointer to SRAM handle
69  *
70  * Returns
71  *   - (0) if successful
72  *   - (-EINVAL) on failure
73  *
74  * Returns the handle for the SRAM slice manager
75  */
76 int tf_sram_mgr_bind(void **sram_handle);
77
78 /** Uninitialize the SRAM slice manager
79  *
80  * Frees any dynamically allocated data structures for SRAM slice management.
81  *
82  * [in] sram_handle
83  *   Pointer to SRAM handle
84  *
85  * Returns
86  *   - (0) if successful
87  *   - (-EINVAL) on failure
88  */
89 int tf_sram_mgr_unbind(void *sram_handle);
90
91 /**
92  * tf_sram_mgr_alloc_parms parameter definition
93  */
94 struct tf_sram_mgr_alloc_parms {
95         /**
96          * [in] dir
97          */
98         enum tf_dir dir;
99         /**
100          * [in] bank
101          *
102          *  the SRAM bank to allocate from
103          */
104         enum tf_sram_bank_id bank_id;
105         /**
106          * [in] slice_size
107          *
108          *  the slice size to allocate
109          */
110         enum tf_sram_slice_size slice_size;
111         /**
112          * [in/out] sram_slice
113          *
114          *  A pointer to be filled with an 8B sram slice offset
115          */
116         uint16_t *sram_offset;
117         /**
118          * [in] RM DB Handle required for RM allocation
119          */
120         void *rm_db;
121         /**
122          * [in] tf table type
123          */
124         enum tf_tbl_type tbl_type;
125 };
126
127 /**
128  * Allocate an SRAM Slice
129  *
130  * Allocate an SRAM slice from the indicated bank.  If successful an 8B SRAM
131  * offset will be returned.  Slices are variable sized.  This may result in
132  * a row being allocated from the RM SRAM bank pool if required.
133  *
134  * [in] sram_handle
135  *   Pointer to SRAM handle
136  *
137  * [in] parms
138  *   Pointer to the SRAM alloc parameters
139  *
140  * Returns
141  *   - (0) if successful
142  *   - (-EINVAL) on failure
143  *
144  */
145 int tf_sram_mgr_alloc(void *sram_handle,
146                       struct tf_sram_mgr_alloc_parms *parms);
147 /**
148  * tf_sram_mgr_free_parms parameter definition
149  */
150 struct tf_sram_mgr_free_parms {
151         /**
152          * [in] dir
153          */
154         enum tf_dir dir;
155         /**
156          * [in] bank
157          *
158          *  the SRAM bank to free to
159          */
160         enum tf_sram_bank_id bank_id;
161         /**
162          * [in] slice_size
163          *
164          *  the slice size to be returned
165          */
166         enum tf_sram_slice_size slice_size;
167         /**
168          * [in] sram_offset
169          *
170          *  the SRAM slice offset (8B) to be returned
171          */
172         uint16_t sram_offset;
173         /**
174          * [in] RM DB Handle required for RM free
175          */
176         void *rm_db;
177         /**
178          * [in] tf table type
179          */
180         enum tf_tbl_type tbl_type;
181 #if (STATS_CLEAR_ON_READ_SUPPORT == 0)
182         /**
183          * [in] tfp
184          *
185          * A pointer to the tf handle
186          */
187         void *tfp;
188 #endif
189 };
190
191 /**
192  * Free an SRAM Slice
193  *
194  * Free an SRAM slice to the indicated bank.  This may result in a 64B row
195  * being returned to the RM SRAM bank pool.
196  *
197  * [in] sram_handle
198  *   Pointer to SRAM handle
199  *
200  * [in] parms
201  *   Pointer to the SRAM free parameters
202  *
203  * Returns
204  *   - (0) if successful
205  *   - (-EINVAL) on failure
206  *
207  */
208 int tf_sram_mgr_free(void *sram_handle,
209                      struct tf_sram_mgr_free_parms *parms);
210
211 /**
212  * tf_sram_mgr_dump_parms parameter definition
213  */
214 struct tf_sram_mgr_dump_parms {
215         /**
216          * [in] dir
217          */
218         enum tf_dir dir;
219         /**
220          * [in] bank
221          *
222          *  the SRAM bank to dump
223          */
224         enum tf_sram_bank_id bank_id;
225         /**
226          * [in] slice_size
227          *
228          *  the slice size list to be dumped
229          */
230         enum tf_sram_slice_size slice_size;
231 };
232
233 /**
234  * Dump a slice list
235  *
236  * Dump the slice list given the SRAM bank and the slice size
237  *
238  * [in] sram_handle
239  *   Pointer to SRAM handle
240  *
241  * [in] parms
242  *   Pointer to the SRAM free parameters
243  *
244  * Returns
245  *   - (0) if successful
246  *   - (-EINVAL) on failure
247  *
248  */
249 int tf_sram_mgr_dump(void *sram_handle,
250                      struct tf_sram_mgr_dump_parms *parms);
251
252 /**
253  * tf_sram_mgr_is_allocated_parms parameter definition
254  */
255 struct tf_sram_mgr_is_allocated_parms {
256         /**
257          * [in] dir
258          */
259         enum tf_dir dir;
260         /**
261          * [in] bank
262          *
263          *  the SRAM bank to allocate from
264          */
265         enum tf_sram_bank_id bank_id;
266         /**
267          * [in] slice_size
268          *
269          *  the slice size which was allocated
270          */
271         enum tf_sram_slice_size slice_size;
272         /**
273          * [in] sram_offset
274          *
275          *  The sram slice offset to validate
276          */
277         uint16_t sram_offset;
278         /**
279          * [in/out] is_allocated
280          *
281          *  Pointer passed in to be filled with indication of allocation
282          */
283         bool *is_allocated;
284 };
285
286 /**
287  * Validate an SRAM Slice is allocated
288  *
289  * Validate whether the SRAM slice is allocated
290  *
291  * [in] sram_handle
292  *   Pointer to SRAM handle
293  *
294  * [in] parms
295  *   Pointer to the SRAM alloc parameters
296  *
297  * Returns
298  *   - (0) if successful
299  *   - (-EINVAL) on failure
300  *
301  */
302 int tf_sram_mgr_is_allocated(void *sram_handle,
303                              struct tf_sram_mgr_is_allocated_parms *parms);
304
305 /**
306  * Given the slice size, return a char string
307  */
308 const char
309 *tf_sram_slice_2_str(enum tf_sram_slice_size slice_size);
310
311 /**
312  * Given the bank_id, return a char string
313  */
314 const char
315 *tf_sram_bank_2_str(enum tf_sram_bank_id bank_id);
316
317 #endif /* _TF_SRAM_MGR_H_ */