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_BITSET_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)
54 * Making the blob statically sized to 128 bytes for now.
55 * The blob must be initialized with ulp_blob_init prior to using.
57 #define BNXT_ULP_FLMP_BLOB_SIZE (128)
58 #define BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS ULP_BYTE_2_BITS(BNXT_ULP_FLMP_BLOB_SIZE)
60 enum bnxt_ulp_byte_order byte_order;
63 uint8_t data[BNXT_ULP_FLMP_BLOB_SIZE];
64 uint16_t encap_swap_idx;
68 * The data can likely be only 32 bits for now. Just size check
69 * the data when being written.
71 #define ULP_REGFILE_ENTRY_SIZE (sizeof(uint32_t))
72 struct ulp_regfile_entry {
78 struct ulp_regfile_entry entry[BNXT_ULP_REGFILE_INDEX_LAST];
82 * Initialize the regfile structure for writing
84 * regfile [in] Ptr to a regfile instance
86 * returns 0 on error or 1 on success
89 ulp_regfile_init(struct ulp_regfile *regfile);
92 * Read a value from the regfile
94 * regfile [in] The regfile instance. Must be initialized prior to being used
96 * field [in] The field to be read within the regfile.
98 * returns the byte array
101 ulp_regfile_read(struct ulp_regfile *regfile,
102 enum bnxt_ulp_regfile_index field,
106 * Write a value to the regfile
108 * regfile [in] The regfile instance. Must be initialized prior to being used
110 * field [in] The field to be written within the regfile.
112 * data [in] The value is written into this variable. It is going to be in the
113 * same byte order as it was written.
115 * returns zero on error
118 ulp_regfile_write(struct ulp_regfile *regfile,
119 enum bnxt_ulp_regfile_index field,
123 * Initializes the blob structure for creating binary blob
125 * blob [in] The blob to be initialized
127 * bitlen [in] The bit length of the blob
129 * order [in] The byte order for the blob. Currently only supporting
130 * big endian. All fields are packed with this order.
132 * returns 0 on error or 1 on success
135 ulp_blob_init(struct ulp_blob *blob,
137 enum bnxt_ulp_byte_order order);
140 * Add data to the binary blob at the current offset.
142 * blob [in] The blob that data is added to. The blob must
143 * be initialized prior to pushing data.
145 * data [in] A pointer to bytes to be added to the blob.
147 * datalen [in] The number of bits to be added to the blob.
149 * The offset of the data is updated after each push of data.
150 * NULL returned on error.
153 ulp_blob_push(struct ulp_blob *blob,
158 * Add data to the binary blob at the current offset.
160 * blob [in] The blob that data is added to. The blob must
161 * be initialized prior to pushing data.
163 * data [in] 64-bit value to be added to the blob.
165 * datalen [in] The number of bits to be added to the blob.
167 * The offset of the data is updated after each push of data.
168 * NULL returned on error, ptr to pushed data otherwise
171 ulp_blob_push_64(struct ulp_blob *blob,
176 * Add encap data to the binary blob at the current offset.
178 * blob [in] The blob that data is added to. The blob must
179 * be initialized prior to pushing data.
181 * data [in] value to be added to the blob.
183 * datalen [in] The number of bits to be added to the blob.
185 * The offset of the data is updated after each push of data.
186 * NULL returned on error, pointer pushed value otherwise.
189 ulp_blob_push_encap(struct ulp_blob *blob,
194 * Get the data portion of the binary blob.
196 * blob [in] The blob's data to be retrieved. The blob must be
197 * initialized prior to pushing data.
199 * datalen [out] The number of bits to that are filled.
201 * returns a byte array of the blob data. Returns NULL on error.
204 ulp_blob_data_get(struct ulp_blob *blob,
208 * Adds pad to an initialized blob at the current offset
210 * blob [in] The blob that data is added to. The blob must
211 * be initialized prior to pushing data.
213 * datalen [in] The number of bits of pad to add
215 * returns the number of pad bits added, zero on failure
218 ulp_blob_pad_push(struct ulp_blob *blob,
222 * Set the 64 bit swap start index of the binary blob.
224 * blob [in] The blob's data to be retrieved. The blob must be
225 * initialized prior to pushing data.
230 ulp_blob_encap_swap_idx_set(struct ulp_blob *blob);
233 * Perform the encap buffer swap to 64 bit reversal.
235 * blob [in] The blob's data to be used for swap.
240 ulp_blob_perform_encap_swap(struct ulp_blob *blob);
243 * Read data from the operand
245 * operand [in] A pointer to a 16 Byte operand
247 * val [in/out] The variable to copy the operand to
249 * bitlen [in] The number of bits to read into val
251 * returns number of bits read, zero on error
254 ulp_operand_read(uint8_t *operand,
259 * copy the buffer in the encap format which is 2 bytes.
260 * The MSB of the src is placed at the LSB of dst.
262 * dst [out] The destination buffer
263 * src [in] The source buffer dst
264 * size[in] size of the buffer.
267 ulp_encap_buffer_copy(uint8_t *dst,
272 * Check the buffer is empty
274 * buf [in] The buffer
275 * size [in] The size of the buffer
277 int32_t ulp_buffer_is_empty(const uint8_t *buf, uint32_t size);
279 #endif /* _ULP_UTILS_H_ */