1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2019 Broadcom
10 #include "ulp_template_db.h"
13 * Macros for bitmap sets and gets
14 * These macros can be used if the val are power of 2.
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))
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.
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)))
31 #define ULP_INDEX_BITMAP_SET(b, i) ((b) |= \
32 (1UL << ((ULP_INDEX_BITMAP_SIZE - 1) - \
33 ((i) % ULP_INDEX_BITMAP_SIZE))))
35 #define ULP_INDEX_BITMAP_RESET(b, i) ((b) &= \
36 (~(1UL << ((ULP_INDEX_BITMAP_SIZE - 1) - \
37 ((i) % ULP_INDEX_BITMAP_SIZE)))))
39 #define ULP_INDEX_BITMAP_GET(b, i) (((b) >> \
40 ((ULP_INDEX_BITMAP_SIZE - 1) - \
41 ((i) % ULP_INDEX_BITMAP_SIZE))) & 1)
43 #define ULP_DEVICE_PARAMS_INDEX(tid, dev_id) \
44 (((tid) << BNXT_ULP_LOG2_MAX_NUM_DEV) | (dev_id))
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)
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)])
57 #define ULP_UTIL_CHF_IDX_WR(params, idx, val) \
58 ((params)->comp_fld[(idx)] = rte_cpu_to_be_32((val)))
60 * Making the blob statically sized to 128 bytes for now.
61 * The blob must be initialized with ulp_blob_init prior to using.
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)
66 enum bnxt_ulp_byte_order byte_order;
69 uint8_t data[BNXT_ULP_FLMP_BLOB_SIZE];
70 uint16_t encap_swap_idx;
74 * The data can likely be only 32 bits for now. Just size check
75 * the data when being written.
77 #define ULP_REGFILE_ENTRY_SIZE (sizeof(uint32_t))
78 struct ulp_regfile_entry {
84 struct ulp_regfile_entry entry[BNXT_ULP_REGFILE_INDEX_LAST];
88 * Initialize the regfile structure for writing
90 * regfile [in] Ptr to a regfile instance
92 * returns 0 on error or 1 on success
95 ulp_regfile_init(struct ulp_regfile *regfile);
98 * Read a value from the regfile
100 * regfile [in] The regfile instance. Must be initialized prior to being used
102 * field [in] The field to be read within the regfile.
104 * returns the byte array
107 ulp_regfile_read(struct ulp_regfile *regfile,
108 enum bnxt_ulp_regfile_index field,
112 * Write a value to the regfile
114 * regfile [in] The regfile instance. Must be initialized prior to being used
116 * field [in] The field to be written within the regfile.
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.
121 * returns zero on error
124 ulp_regfile_write(struct ulp_regfile *regfile,
125 enum bnxt_ulp_regfile_index field,
129 * Initializes the blob structure for creating binary blob
131 * blob [in] The blob to be initialized
133 * bitlen [in] The bit length of the blob
135 * order [in] The byte order for the blob. Currently only supporting
136 * big endian. All fields are packed with this order.
138 * returns 0 on error or 1 on success
141 ulp_blob_init(struct ulp_blob *blob,
143 enum bnxt_ulp_byte_order order);
146 * Add data to the binary blob at the current offset.
148 * blob [in] The blob that data is added to. The blob must
149 * be initialized prior to pushing data.
151 * data [in] A pointer to bytes to be added to the blob.
153 * datalen [in] The number of bits to be added to the blob.
155 * The offset of the data is updated after each push of data.
156 * NULL returned on error.
159 ulp_blob_push(struct ulp_blob *blob,
164 * Add data to the binary blob at the current offset.
166 * blob [in] The blob that data is added to. The blob must
167 * be initialized prior to pushing data.
169 * data [in] 64-bit value to be added to the blob.
171 * datalen [in] The number of bits to be added to the blob.
173 * The offset of the data is updated after each push of data.
174 * NULL returned on error, ptr to pushed data otherwise
177 ulp_blob_push_64(struct ulp_blob *blob,
182 * Add encap data to the binary blob at the current offset.
184 * blob [in] The blob that data is added to. The blob must
185 * be initialized prior to pushing data.
187 * data [in] value to be added to the blob.
189 * datalen [in] The number of bits to be added to the blob.
191 * The offset of the data is updated after each push of data.
192 * NULL returned on error, pointer pushed value otherwise.
195 ulp_blob_push_encap(struct ulp_blob *blob,
200 * Get the data portion of the binary blob.
202 * blob [in] The blob's data to be retrieved. The blob must be
203 * initialized prior to pushing data.
205 * datalen [out] The number of bits to that are filled.
207 * returns a byte array of the blob data. Returns NULL on error.
210 ulp_blob_data_get(struct ulp_blob *blob,
214 * Adds pad to an initialized blob at the current offset
216 * blob [in] The blob that data is added to. The blob must
217 * be initialized prior to pushing data.
219 * datalen [in] The number of bits of pad to add
221 * returns the number of pad bits added, zero on failure
224 ulp_blob_pad_push(struct ulp_blob *blob,
228 * Set the 64 bit swap start index of the binary blob.
230 * blob [in] The blob's data to be retrieved. The blob must be
231 * initialized prior to pushing data.
236 ulp_blob_encap_swap_idx_set(struct ulp_blob *blob);
239 * Perform the encap buffer swap to 64 bit reversal.
241 * blob [in] The blob's data to be used for swap.
246 ulp_blob_perform_encap_swap(struct ulp_blob *blob);
249 * Read data from the operand
251 * operand [in] A pointer to a 16 Byte operand
253 * val [in/out] The variable to copy the operand to
255 * bitlen [in] The number of bits to read into val
257 * returns number of bits read, zero on error
260 ulp_operand_read(uint8_t *operand,
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.
268 * dst [out] The destination buffer
269 * src [in] The source buffer dst
270 * size[in] size of the buffer.
273 ulp_encap_buffer_copy(uint8_t *dst,
278 * Check the buffer is empty
280 * buf [in] The buffer
281 * size [in] The size of the buffer
283 int32_t ulp_buffer_is_empty(const uint8_t *buf, uint32_t size);
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);
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);
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);
294 #endif /* _ULP_UTILS_H_ */