]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/bnxt/tf_ulp/ulp_utils.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / bnxt / tf_ulp / ulp_utils.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2019 Broadcom
3 * All rights reserved.
4 */
5
6 #ifndef _ULP_UTILS_H_
7 #define _ULP_UTILS_H_
8
9 #include "bnxt.h"
10 #include "ulp_template_db.h"
11
12 /*
13 * Macros for bitmap sets and gets
14 * These macros can be used if the val are power of 2.
15 */
16 #define ULP_BITMAP_SET(bitmap, val) ((bitmap) |= (val))
17 #define ULP_BITMAP_RESET(bitmap, val) ((bitmap) &= ~(val))
18 #define ULP_BITMAP_ISSET(bitmap, val) ((bitmap) & (val))
19 #define ULP_BITMAP_CMP(b1, b2) memcmp(&(b1)->bits, \
20 &(b2)->bits, sizeof((b1)->bits))
21 /*
22 * Macros for bitmap sets and gets
23 * These macros can be used if the val are not power of 2 and
24 * are simple index values.
25 */
26 #define ULP_INDEX_BITMAP_SIZE (sizeof(uint64_t) * 8)
27 #define ULP_INDEX_BITMAP_CSET(i) (1UL << \
28 ((ULP_INDEX_BITMAP_SIZE - 1) - \
29 ((i) % ULP_INDEX_BITMAP_SIZE)))
30
31 #define ULP_INDEX_BITMAP_SET(b, i) ((b) |= \
32 (1UL << ((ULP_INDEX_BITMAP_SIZE - 1) - \
33 ((i) % ULP_INDEX_BITMAP_SIZE))))
34
35 #define ULP_INDEX_BITMAP_RESET(b, i) ((b) &= \
36 (~(1UL << ((ULP_INDEX_BITMAP_SIZE - 1) - \
37 ((i) % ULP_INDEX_BITMAP_SIZE)))))
38
39 #define ULP_INDEX_BITMAP_GET(b, i) (((b) >> \
40 ((ULP_INDEX_BITMAP_SIZE - 1) - \
41 ((i) % ULP_INDEX_BITMAP_SIZE))) & 1)
42
43 #define ULP_DEVICE_PARAMS_INDEX(tid, dev_id) \
44 (((tid) << BNXT_ULP_LOG2_MAX_NUM_DEV) | (dev_id))
45
46 /* Macro to convert bytes to bits */
47 #define ULP_BYTE_2_BITS(byte_x) ((byte_x) * 8)
48 /* Macro to convert bits to bytes */
49 #define ULP_BITS_2_BYTE(bits_x) (((bits_x) + 7) / 8)
50 /* Macro to convert bits to bytes with no round off*/
51 #define ULP_BITS_2_BYTE_NR(bits_x) ((bits_x) / 8)
52
53 /* Macros to read the computed fields */
54 #define ULP_UTIL_CHF_IDX_RD(params, idx) \
55 rte_be_to_cpu_32((params)->comp_fld[(idx)])
56
57 #define ULP_UTIL_CHF_IDX_WR(params, idx, val) \
58 ((params)->comp_fld[(idx)] = rte_cpu_to_be_32((val)))
59 /*
60 * Making the blob statically sized to 128 bytes for now.
61 * The blob must be initialized with ulp_blob_init prior to using.
62 */
63 #define BNXT_ULP_FLMP_BLOB_SIZE (128)
64 #define BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS ULP_BYTE_2_BITS(BNXT_ULP_FLMP_BLOB_SIZE)
65 struct ulp_blob {
66 enum bnxt_ulp_byte_order byte_order;
67 uint16_t write_idx;
68 uint16_t bitlen;
69 uint8_t data[BNXT_ULP_FLMP_BLOB_SIZE];
70 uint16_t encap_swap_idx;
71 };
72
73 /*
74 * The data can likely be only 32 bits for now. Just size check
75 * the data when being written.
76 */
77 #define ULP_REGFILE_ENTRY_SIZE (sizeof(uint32_t))
78 struct ulp_regfile_entry {
79 uint64_t data;
80 uint32_t size;
81 };
82
83 struct ulp_regfile {
84 struct ulp_regfile_entry entry[BNXT_ULP_REGFILE_INDEX_LAST];
85 };
86
87 /*
88 * Initialize the regfile structure for writing
89 *
90 * regfile [in] Ptr to a regfile instance
91 *
92 * returns 0 on error or 1 on success
93 */
94 uint32_t
95 ulp_regfile_init(struct ulp_regfile *regfile);
96
97 /*
98 * Read a value from the regfile
99 *
100 * regfile [in] The regfile instance. Must be initialized prior to being used
101 *
102 * field [in] The field to be read within the regfile.
103 *
104 * returns the byte array
105 */
106 uint32_t
107 ulp_regfile_read(struct ulp_regfile *regfile,
108 enum bnxt_ulp_regfile_index field,
109 uint64_t *data);
110
111 /*
112 * Write a value to the regfile
113 *
114 * regfile [in] The regfile instance. Must be initialized prior to being used
115 *
116 * field [in] The field to be written within the regfile.
117 *
118 * data [in] The value is written into this variable. It is going to be in the
119 * same byte order as it was written.
120 *
121 * returns zero on error
122 */
123 uint32_t
124 ulp_regfile_write(struct ulp_regfile *regfile,
125 enum bnxt_ulp_regfile_index field,
126 uint64_t data);
127
128 /*
129 * Initializes the blob structure for creating binary blob
130 *
131 * blob [in] The blob to be initialized
132 *
133 * bitlen [in] The bit length of the blob
134 *
135 * order [in] The byte order for the blob. Currently only supporting
136 * big endian. All fields are packed with this order.
137 *
138 * returns 0 on error or 1 on success
139 */
140 uint32_t
141 ulp_blob_init(struct ulp_blob *blob,
142 uint16_t bitlen,
143 enum bnxt_ulp_byte_order order);
144
145 /*
146 * Add data to the binary blob at the current offset.
147 *
148 * blob [in] The blob that data is added to. The blob must
149 * be initialized prior to pushing data.
150 *
151 * data [in] A pointer to bytes to be added to the blob.
152 *
153 * datalen [in] The number of bits to be added to the blob.
154 *
155 * The offset of the data is updated after each push of data.
156 * NULL returned on error.
157 */
158 uint32_t
159 ulp_blob_push(struct ulp_blob *blob,
160 uint8_t *data,
161 uint32_t datalen);
162
163 /*
164 * Add data to the binary blob at the current offset.
165 *
166 * blob [in] The blob that data is added to. The blob must
167 * be initialized prior to pushing data.
168 *
169 * data [in] 64-bit value to be added to the blob.
170 *
171 * datalen [in] The number of bits to be added to the blob.
172 *
173 * The offset of the data is updated after each push of data.
174 * NULL returned on error, ptr to pushed data otherwise
175 */
176 uint8_t *
177 ulp_blob_push_64(struct ulp_blob *blob,
178 uint64_t *data,
179 uint32_t datalen);
180
181 /*
182 * Add encap data to the binary blob at the current offset.
183 *
184 * blob [in] The blob that data is added to. The blob must
185 * be initialized prior to pushing data.
186 *
187 * data [in] value to be added to the blob.
188 *
189 * datalen [in] The number of bits to be added to the blob.
190 *
191 * The offset of the data is updated after each push of data.
192 * NULL returned on error, pointer pushed value otherwise.
193 */
194 uint32_t
195 ulp_blob_push_encap(struct ulp_blob *blob,
196 uint8_t *data,
197 uint32_t datalen);
198
199 /*
200 * Get the data portion of the binary blob.
201 *
202 * blob [in] The blob's data to be retrieved. The blob must be
203 * initialized prior to pushing data.
204 *
205 * datalen [out] The number of bits to that are filled.
206 *
207 * returns a byte array of the blob data. Returns NULL on error.
208 */
209 uint8_t *
210 ulp_blob_data_get(struct ulp_blob *blob,
211 uint16_t *datalen);
212
213 /*
214 * Adds pad to an initialized blob at the current offset
215 *
216 * blob [in] The blob that data is added to. The blob must
217 * be initialized prior to pushing data.
218 *
219 * datalen [in] The number of bits of pad to add
220 *
221 * returns the number of pad bits added, zero on failure
222 */
223 uint32_t
224 ulp_blob_pad_push(struct ulp_blob *blob,
225 uint32_t datalen);
226
227 /*
228 * Set the 64 bit swap start index of the binary blob.
229 *
230 * blob [in] The blob's data to be retrieved. The blob must be
231 * initialized prior to pushing data.
232 *
233 * returns void.
234 */
235 void
236 ulp_blob_encap_swap_idx_set(struct ulp_blob *blob);
237
238 /*
239 * Perform the encap buffer swap to 64 bit reversal.
240 *
241 * blob [in] The blob's data to be used for swap.
242 *
243 * returns void.
244 */
245 void
246 ulp_blob_perform_encap_swap(struct ulp_blob *blob);
247
248 /*
249 * Read data from the operand
250 *
251 * operand [in] A pointer to a 16 Byte operand
252 *
253 * val [in/out] The variable to copy the operand to
254 *
255 * bitlen [in] The number of bits to read into val
256 *
257 * returns number of bits read, zero on error
258 */
259 uint16_t
260 ulp_operand_read(uint8_t *operand,
261 uint8_t *val,
262 uint16_t bitlen);
263
264 /*
265 * copy the buffer in the encap format which is 2 bytes.
266 * The MSB of the src is placed at the LSB of dst.
267 *
268 * dst [out] The destination buffer
269 * src [in] The source buffer dst
270 * size[in] size of the buffer.
271 */
272 void
273 ulp_encap_buffer_copy(uint8_t *dst,
274 const uint8_t *src,
275 uint16_t size);
276
277 /*
278 * Check the buffer is empty
279 *
280 * buf [in] The buffer
281 * size [in] The size of the buffer
282 */
283 int32_t ulp_buffer_is_empty(const uint8_t *buf, uint32_t size);
284
285 /* Function to check if bitmap is zero.Return 1 on success */
286 uint32_t ulp_bitmap_is_zero(uint8_t *bitmap, int32_t size);
287
288 /* Function to check if bitmap is ones. Return 1 on success */
289 uint32_t ulp_bitmap_is_ones(uint8_t *bitmap, int32_t size);
290
291 /* Function to check if bitmap is not zero. Return 1 on success */
292 uint32_t ulp_bitmap_notzero(uint8_t *bitmap, int32_t size);
293
294 #endif /* _ULP_UTILS_H_ */