1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
6 #include <rte_common.h>
8 #include "bnxt_tf_common.h"
11 * Initialize the regfile structure for writing
13 * regfile [in] Ptr to a regfile instance
15 * returns 0 on error or 1 on success
18 ulp_regfile_init(struct ulp_regfile *regfile)
20 /* validate the arguments */
22 BNXT_TF_DBG(ERR, "invalid argument\n");
23 return 0; /* failure */
25 memset(regfile, 0, sizeof(struct ulp_regfile));
26 return 1; /* Success */
30 * Read a value from the regfile
32 * regfile [in] The regfile instance. Must be initialized prior to being used
34 * field [in] The field to be read within the regfile.
38 * returns size, zero on failure
41 ulp_regfile_read(struct ulp_regfile *regfile,
42 enum bnxt_ulp_rf_idx field,
45 /* validate the arguments */
46 if (!regfile || field >= BNXT_ULP_RF_IDX_LAST) {
47 BNXT_TF_DBG(ERR, "invalid argument\n");
48 return 0; /* failure */
51 *data = regfile->entry[field].data;
56 * Write a value to the regfile
58 * regfile [in] The regfile instance. Must be initialized prior to being used
60 * field [in] The field to be written within the regfile.
62 * data [in] The value is written into this variable. It is going to be in the
63 * same byte order as it was written.
65 * size [in] The size in bytes of the value being written into this
68 * returns 0 on success
71 ulp_regfile_write(struct ulp_regfile *regfile,
72 enum bnxt_ulp_rf_idx field,
75 /* validate the arguments */
76 if (!regfile || field >= BNXT_ULP_RF_IDX_LAST) {
77 BNXT_TF_DBG(ERR, "invalid argument\n");
78 return -EINVAL; /* failure */
81 regfile->entry[field].data = data;
82 return 0; /* Success */
86 ulp_bs_put_msb(uint8_t *bs, uint16_t bitpos, uint8_t bitlen, uint8_t val)
88 uint8_t bitoffs = bitpos % 8;
89 uint16_t index = bitpos / 8;
95 mask = ((uint8_t)-1 >> (8 - bitlen));
96 shift = 8 - bitoffs - bitlen;
100 tmp &= ~(mask << shift);
104 tmp &= ~((uint8_t)-1 >> bitoffs);
105 tmp |= val >> -shift;
109 tmp &= ((uint8_t)-1 >> (bitlen - (8 - bitoffs)));
110 tmp |= val << (8 + shift);
116 ulp_bs_put_lsb(uint8_t *bs, uint16_t bitpos, uint8_t bitlen, uint8_t val)
118 uint8_t bitoffs = bitpos % 8;
119 uint16_t index = bitpos / 8;
128 if (bitoffs + bitlen <= 8) {
129 mask = ((1 << bitlen) - 1) << shift;
131 tmp |= ((val << shift) & mask);
134 partial = 8 - bitoffs;
135 mask = ((1 << partial) - 1) << shift;
137 tmp |= ((val << shift) & mask);
141 partial = bitlen - partial;
142 mask = ((1 << partial) - 1);
151 * Add data to the byte array in Little endian format.
153 * bs [in] The byte array where data is pushed
155 * pos [in] The offset where data is pushed
157 * len [in] The number of bits to be added to the data array.
159 * val [in] The data to be added to the data array.
161 * returns the number of bits pushed.
164 ulp_bs_push_lsb(uint8_t *bs, uint16_t pos, uint8_t len, uint8_t *val)
170 if (cnt > 0 && !(len % 8))
173 for (i = 0; i < cnt; i++) {
174 ulp_bs_put_lsb(bs, pos, 8, val[cnt - i]);
179 /* Handle the remainder bits */
181 ulp_bs_put_lsb(bs, pos, tlen, val[0]);
186 * Add data to the byte array in Big endian format.
188 * bs [in] The byte array where data is pushed
190 * pos [in] The offset where data is pushed
192 * len [in] The number of bits to be added to the data array.
194 * val [in] The data to be added to the data array.
196 * returns the number of bits pushed.
199 ulp_bs_push_msb(uint8_t *bs, uint16_t pos, uint8_t len, uint8_t *val)
202 int cnt = (len + 7) / 8;
204 /* Handle any remainder bits */
210 ulp_bs_put_msb(bs, pos, tmp, val[0]);
214 for (i = 1; i < cnt; i++) {
215 ulp_bs_put_msb(bs, pos, 8, val[i]);
223 * Initializes the blob structure for creating binary blob
225 * blob [in] The blob to be initialized
227 * bitlen [in] The bit length of the blob
229 * order [in] The byte order for the blob. Currently only supporting
230 * big endian. All fields are packed with this order.
232 * returns 0 on error or 1 on success
233 * Notes - If bitlen is zero then set it to max.
236 ulp_blob_init(struct ulp_blob *blob,
238 enum bnxt_ulp_byte_order order)
240 /* validate the arguments */
241 if (!blob || bitlen > (8 * sizeof(blob->data))) {
242 BNXT_TF_DBG(ERR, "invalid argument\n");
243 return 0; /* failure */
246 blob->bitlen = bitlen;
248 blob->bitlen = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
249 blob->byte_order = order;
251 memset(blob->data, 0, sizeof(blob->data));
252 return 1; /* Success */
256 * Add data to the binary blob at the current offset.
258 * blob [in] The blob that data is added to. The blob must
259 * be initialized prior to pushing data.
261 * data [in] A pointer to bytes to be added to the blob.
263 * datalen [in] The number of bits to be added to the blob.
265 * The offset of the data is updated after each push of data.
266 * NULL returned on error.
268 #define ULP_BLOB_BYTE 8
269 #define ULP_BLOB_BYTE_HEX 0xFF
270 #define BLOB_MASK_CAL(x) ((0xFF << (x)) & 0xFF)
272 ulp_blob_push(struct ulp_blob *blob,
278 /* validate the arguments */
279 if (!blob || datalen > (uint32_t)(blob->bitlen - blob->write_idx)) {
280 BNXT_TF_DBG(ERR, "invalid argument\n");
281 return 0; /* failure */
284 if (blob->byte_order == BNXT_ULP_BYTE_ORDER_BE)
285 rc = ulp_bs_push_msb(blob->data,
290 rc = ulp_bs_push_lsb(blob->data,
295 BNXT_TF_DBG(ERR, "Failed to write blob\n");
298 blob->write_idx += datalen;
303 * Insert data into the binary blob at the given offset.
305 * blob [in] The blob that data is added to. The blob must
306 * be initialized prior to pushing data.
308 * offset [in] The offset where the data needs to be inserted.
310 * data [in/out] A pointer to bytes to be added to the blob.
312 * datalen [in] The number of bits to be added to the blob.
314 * The offset of the data is updated after each push of data.
315 * NULL returned on error.
318 ulp_blob_insert(struct ulp_blob *blob, uint32_t offset,
319 uint8_t *data, uint32_t datalen)
322 uint8_t local_data[BNXT_ULP_FLMP_BLOB_SIZE];
325 /* validate the arguments */
326 if (!blob || datalen > (uint32_t)(blob->bitlen - blob->write_idx) ||
327 offset > blob->write_idx) {
328 BNXT_TF_DBG(ERR, "invalid argument\n");
329 return 0; /* failure */
332 mov_len = blob->write_idx - offset;
333 /* If offset and data len are not 8 bit aligned then return error */
334 if (ULP_BITS_IS_BYTE_NOT_ALIGNED(offset) ||
335 ULP_BITS_IS_BYTE_NOT_ALIGNED(datalen)) {
336 BNXT_TF_DBG(ERR, "invalid argument, not aligned\n");
337 return 0; /* failure */
340 /* copy the data so we can move the data */
341 memcpy(local_data, &blob->data[ULP_BITS_2_BYTE_NR(offset)],
342 ULP_BITS_2_BYTE(mov_len));
343 blob->write_idx = offset;
344 if (blob->byte_order == BNXT_ULP_BYTE_ORDER_BE)
345 rc = ulp_bs_push_msb(blob->data,
350 rc = ulp_bs_push_lsb(blob->data,
355 BNXT_TF_DBG(ERR, "Failed to write blob\n");
358 /* copy the previously stored data */
359 memcpy(&blob->data[ULP_BITS_2_BYTE_NR(offset + datalen)], local_data,
360 ULP_BITS_2_BYTE(mov_len));
361 blob->write_idx += (mov_len + datalen);
366 * Add data to the binary blob at the current offset.
368 * blob [in] The blob that data is added to. The blob must
369 * be initialized prior to pushing data.
371 * data [in] 64-bit value to be added to the blob.
373 * datalen [in] The number of bits to be added to the blob.
375 * The offset of the data is updated after each push of data.
376 * NULL returned on error, pointer pushed value otherwise.
379 ulp_blob_push_64(struct ulp_blob *blob,
383 uint8_t *val = (uint8_t *)data;
386 int size = (datalen + 7) / 8;
388 if (!blob || !data ||
389 datalen > (uint32_t)(blob->bitlen - blob->write_idx)) {
390 BNXT_TF_DBG(ERR, "invalid argument\n");
394 rc = ulp_blob_push(blob, &val[8 - size], datalen);
398 return &val[8 - size];
402 * Add data to the binary blob at the current offset.
404 * blob [in] The blob that data is added to. The blob must
405 * be initialized prior to pushing data.
407 * data [in] 32-bit value to be added to the blob.
409 * datalen [in] The number of bits to be added to the blob.
411 * The offset of the data is updated after each push of data.
412 * NULL returned on error, pointer pushed value otherwise.
415 ulp_blob_push_32(struct ulp_blob *blob,
419 uint8_t *val = (uint8_t *)data;
421 uint32_t size = ULP_BITS_2_BYTE(datalen);
423 if (!data || size > sizeof(uint32_t)) {
424 BNXT_TF_DBG(ERR, "invalid argument\n");
428 rc = ulp_blob_push(blob, &val[sizeof(uint32_t) - size], datalen);
432 return &val[sizeof(uint32_t) - size];
436 * Add encap data to the binary blob at the current offset.
438 * blob [in] The blob that data is added to. The blob must
439 * be initialized prior to pushing data.
441 * data [in] value to be added to the blob.
443 * datalen [in] The number of bits to be added to the blob.
445 * The offset of the data is updated after each push of data.
446 * NULL returned on error, pointer pushed value otherwise.
449 ulp_blob_push_encap(struct ulp_blob *blob,
453 uint8_t *val = (uint8_t *)data;
454 uint32_t initial_size, write_size = datalen;
457 if (!blob || !data ||
458 datalen > (uint32_t)(blob->bitlen - blob->write_idx)) {
459 BNXT_TF_DBG(ERR, "invalid argument\n");
463 initial_size = ULP_BYTE_2_BITS(sizeof(uint64_t)) -
464 (blob->write_idx % ULP_BYTE_2_BITS(sizeof(uint64_t)));
465 while (write_size > 0) {
466 if (initial_size && write_size > initial_size) {
469 } else if (initial_size && write_size <= initial_size) {
472 } else if (write_size > ULP_BYTE_2_BITS(sizeof(uint64_t))) {
473 size = ULP_BYTE_2_BITS(sizeof(uint64_t));
477 if (!ulp_blob_push(blob, val, size)) {
478 BNXT_TF_DBG(ERR, "push field failed\n");
481 val += ULP_BITS_2_BYTE(size);
488 * Adds pad to an initialized blob at the current offset
490 * blob [in] The blob that data is added to. The blob must
491 * be initialized prior to pushing data.
493 * datalen [in] The number of bits of pad to add
495 * returns the number of pad bits added, -1 on failure
498 ulp_blob_pad_push(struct ulp_blob *blob,
501 if (datalen > (uint32_t)(blob->bitlen - blob->write_idx)) {
502 BNXT_TF_DBG(ERR, "Pad too large for blob\n");
506 blob->write_idx += datalen;
511 * Adds pad to an initialized blob at the current offset based on
514 * blob [in] The blob that needs to be aligned
516 * align [in] Alignment in bits.
518 * returns the number of pad bits added, -1 on failure
521 ulp_blob_pad_align(struct ulp_blob *blob,
526 pad = RTE_ALIGN(blob->write_idx, align) - blob->write_idx;
527 if (pad > (int32_t)(blob->bitlen - blob->write_idx)) {
528 BNXT_TF_DBG(ERR, "Pad too large for blob\n");
531 blob->write_idx += pad;
535 /* Get data from src and put into dst using little-endian format */
537 ulp_bs_get_lsb(uint8_t *src, uint16_t bitpos, uint8_t bitlen, uint8_t *dst)
539 uint8_t bitoffs = bitpos % ULP_BLOB_BYTE;
540 uint16_t index = ULP_BITS_2_BYTE_NR(bitpos);
541 uint8_t mask, partial, shift;
544 partial = ULP_BLOB_BYTE - bitoffs;
545 if (bitoffs + bitlen <= ULP_BLOB_BYTE) {
546 mask = ((1 << bitlen) - 1) << shift;
547 *dst = (src[index] & mask) >> shift;
549 mask = ((1 << partial) - 1) << shift;
550 *dst = (src[index] & mask) >> shift;
552 partial = bitlen - partial;
553 mask = ((1 << partial) - 1);
554 *dst |= (src[index] & mask) << (ULP_BLOB_BYTE - bitoffs);
559 * Get data from the byte array in Little endian format.
561 * src [in] The byte array where data is extracted from
563 * dst [out] The byte array where data is pulled into
565 * size [in] The size of dst array in bytes
567 * offset [in] The offset where data is pulled
569 * len [in] The number of bits to be extracted from the data array
574 ulp_bs_pull_lsb(uint8_t *src, uint8_t *dst, uint32_t size,
575 uint32_t offset, uint32_t len)
578 uint32_t cnt = ULP_BITS_2_BYTE_NR(len);
580 /* iterate bytewise to get data */
581 for (idx = 0; idx < cnt; idx++) {
582 ulp_bs_get_lsb(src, offset, ULP_BLOB_BYTE,
583 &dst[size - 1 - idx]);
584 offset += ULP_BLOB_BYTE;
585 len -= ULP_BLOB_BYTE;
588 /* Extract the last reminder data that is not 8 byte boundary */
590 ulp_bs_get_lsb(src, offset, len, &dst[size - 1 - idx]);
593 /* Get data from src and put into dst using big-endian format */
595 ulp_bs_get_msb(uint8_t *src, uint16_t bitpos, uint8_t bitlen, uint8_t *dst)
597 uint8_t bitoffs = bitpos % ULP_BLOB_BYTE;
598 uint16_t index = ULP_BITS_2_BYTE_NR(bitpos);
602 shift = ULP_BLOB_BYTE - bitoffs - bitlen;
604 mask = 0xFF >> -bitlen;
605 *dst = (src[index] >> shift) & mask;
607 *dst = (src[index] & (0xFF >> bitoffs)) << -shift;
608 *dst |= src[index + 1] >> -shift;
613 * Get data from the byte array in Big endian format.
615 * src [in] The byte array where data is extracted from
617 * dst [out] The byte array where data is pulled into
619 * offset [in] The offset where data is pulled
621 * len [in] The number of bits to be extracted from the data array
626 ulp_bs_pull_msb(uint8_t *src, uint8_t *dst,
627 uint32_t offset, uint32_t len)
630 uint32_t cnt = ULP_BITS_2_BYTE_NR(len);
632 /* iterate bytewise to get data */
633 for (idx = 0; idx < cnt; idx++) {
634 ulp_bs_get_msb(src, offset, ULP_BLOB_BYTE, &dst[idx]);
635 offset += ULP_BLOB_BYTE;
636 len -= ULP_BLOB_BYTE;
639 /* Extract the last reminder data that is not 8 byte boundary */
641 ulp_bs_get_msb(src, offset, len, &dst[idx]);
645 * Extract data from the binary blob using given offset.
647 * blob [in] The blob that data is extracted from. The blob must
648 * be initialized prior to pulling data.
650 * data [in] A pointer to put the data.
651 * data_size [in] size of the data buffer in bytes.
652 *offset [in] - Offset in the blob to extract the data in bits format.
653 * len [in] The number of bits to be pulled from the blob.
655 * Output: zero on success, -1 on failure
658 ulp_blob_pull(struct ulp_blob *blob, uint8_t *data, uint32_t data_size,
659 uint16_t offset, uint16_t len)
661 /* validate the arguments */
662 if (!blob || (offset + len) > blob->bitlen ||
663 ULP_BYTE_2_BITS(data_size) < len) {
664 BNXT_TF_DBG(ERR, "invalid argument\n");
665 return -1; /* failure */
668 if (blob->byte_order == BNXT_ULP_BYTE_ORDER_BE)
669 ulp_bs_pull_msb(blob->data, data, offset, len);
671 ulp_bs_pull_lsb(blob->data, data, data_size, offset, len);
676 * Get the data portion of the binary blob.
678 * blob [in] The blob's data to be retrieved. The blob must be
679 * initialized prior to pushing data.
681 * datalen [out] The number of bits to that are filled.
683 * returns a byte array of the blob data. Returns NULL on error.
686 ulp_blob_data_get(struct ulp_blob *blob,
689 /* validate the arguments */
691 BNXT_TF_DBG(ERR, "invalid argument\n");
692 return NULL; /* failure */
694 *datalen = blob->write_idx;
699 * Get the data length of the binary blob.
701 * blob [in] The blob's data len to be retrieved.
703 * returns length of the binary blob
706 ulp_blob_data_len_get(struct ulp_blob *blob)
708 /* validate the arguments */
710 BNXT_TF_DBG(ERR, "invalid argument\n");
711 return 0; /* failure */
713 return blob->write_idx;
717 * Set the encap swap start index of the binary blob.
719 * blob [in] The blob's data to be retrieved. The blob must be
720 * initialized prior to pushing data.
725 ulp_blob_encap_swap_idx_set(struct ulp_blob *blob)
727 /* validate the arguments */
729 BNXT_TF_DBG(ERR, "invalid argument\n");
730 return; /* failure */
732 blob->encap_swap_idx = blob->write_idx;
736 * Perform the encap buffer swap to 64 bit reversal.
738 * blob [in] The blob's data to be used for swap.
743 ulp_blob_perform_encap_swap(struct ulp_blob *blob)
745 uint32_t i, idx = 0, end_idx = 0, roundoff;
746 uint8_t temp_val_1, temp_val_2;
748 /* validate the arguments */
750 BNXT_TF_DBG(ERR, "invalid argument\n");
751 return; /* failure */
753 idx = ULP_BITS_2_BYTE_NR(blob->encap_swap_idx);
754 end_idx = ULP_BITS_2_BYTE(blob->write_idx);
755 roundoff = ULP_BYTE_2_BITS(ULP_BITS_2_BYTE(end_idx));
756 if (roundoff > end_idx) {
757 blob->write_idx += ULP_BYTE_2_BITS(roundoff - end_idx);
760 while (idx <= end_idx) {
761 for (i = 0; i < 4; i = i + 2) {
762 temp_val_1 = blob->data[idx + i];
763 temp_val_2 = blob->data[idx + i + 1];
764 blob->data[idx + i] = blob->data[idx + 6 - i];
765 blob->data[idx + i + 1] = blob->data[idx + 7 - i];
766 blob->data[idx + 7 - i] = temp_val_2;
767 blob->data[idx + 6 - i] = temp_val_1;
774 * Perform the blob buffer reversal byte wise.
775 * This api makes the first byte the last and
778 * blob [in] The blob's data to be used for swap.
779 * chunk_size[in] the swap is done within the chunk in bytes
784 ulp_blob_perform_byte_reverse(struct ulp_blob *blob,
787 uint32_t idx = 0, jdx = 0, num = 0;
791 /* validate the arguments */
793 BNXT_TF_DBG(ERR, "invalid argument\n");
794 return; /* failure */
798 num = ULP_BITS_2_BYTE(blob->write_idx) / chunk_size;
799 for (idx = 0; idx < num; idx++) {
800 for (jdx = 0; jdx < chunk_size / 2; jdx++) {
802 buff[jdx] = buff[(chunk_size - 1) - jdx];
803 buff[(chunk_size - 1) - jdx] = xchar;
810 * Perform the blob buffer 64 bit word swap.
811 * This api makes the first 4 bytes the last in
812 * a given 64 bit value and vice-versa.
814 * blob [in] The blob's data to be used for swap.
819 ulp_blob_perform_64B_word_swap(struct ulp_blob *blob)
823 uint32_t word_size = ULP_64B_IN_BYTES / 2;
825 /* validate the arguments */
827 BNXT_TF_DBG(ERR, "invalid argument\n");
828 return; /* failure */
830 num = ULP_BITS_2_BYTE(blob->write_idx);
831 for (i = 0; i < num; i = i + ULP_64B_IN_BYTES) {
832 for (j = 0; j < word_size; j++) {
833 xchar = blob->data[i + j];
834 blob->data[i + j] = blob->data[i + j + word_size];
835 blob->data[i + j + word_size] = xchar;
841 * Perform the blob buffer 64 bit byte swap.
842 * This api makes the first byte the last in
843 * a given 64 bit value and vice-versa.
845 * blob [in] The blob's data to be used for swap.
850 ulp_blob_perform_64B_byte_swap(struct ulp_blob *blob)
854 uint32_t offset = ULP_64B_IN_BYTES - 1;
856 /* validate the arguments */
858 BNXT_TF_DBG(ERR, "invalid argument\n");
859 return; /* failure */
861 num = ULP_BITS_2_BYTE(blob->write_idx);
862 for (i = 0; i < num; i = i + ULP_64B_IN_BYTES) {
863 for (j = 0; j < (ULP_64B_IN_BYTES / 2); j++) {
864 xchar = blob->data[i + j];
865 blob->data[i + j] = blob->data[i + offset - j];
866 blob->data[i + offset - j] = xchar;
872 ulp_blob_msb_block_merge(struct ulp_blob *dst, struct ulp_blob *src,
873 uint32_t block_size, uint32_t pad)
875 uint32_t i, k, write_bytes, remaining;
877 uint8_t *src_buf = ulp_blob_data_get(src, &num);
880 for (i = 0; i < num;) {
881 if (((dst->write_idx % block_size) + (num - i)) > block_size)
882 write_bytes = block_size -
883 (dst->write_idx % block_size);
885 write_bytes = num - i;
886 for (k = 0; k < ULP_BITS_2_BYTE_NR(write_bytes); k++) {
887 ulp_bs_put_msb(dst->data, dst->write_idx, ULP_BLOB_BYTE,
889 dst->write_idx += ULP_BLOB_BYTE;
892 remaining = write_bytes % ULP_BLOB_BYTE;
894 bluff = (*src_buf) & ((uint8_t)-1 <<
895 (ULP_BLOB_BYTE - remaining));
896 ulp_bs_put_msb(dst->data, dst->write_idx,
897 ULP_BLOB_BYTE, bluff);
898 dst->write_idx += remaining;
900 if (write_bytes != (num - i)) {
901 /* add the padding */
902 ulp_blob_pad_push(dst, pad);
904 ulp_bs_put_msb(dst->data, dst->write_idx,
905 ULP_BLOB_BYTE - remaining,
907 dst->write_idx += ULP_BLOB_BYTE - remaining;
917 * Perform the blob buffer merge.
918 * This api makes the src blob merged to the dst blob.
919 * The block size and pad size help in padding the dst blob
921 * dst [in] The destination blob, the blob to be merged.
922 * src [in] The src blob.
923 * block_size [in] The size of the block after which padding gets applied.
924 * pad [in] The size of the pad to be applied.
926 * returns 0 on success.
929 ulp_blob_block_merge(struct ulp_blob *dst, struct ulp_blob *src,
930 uint32_t block_size, uint32_t pad)
932 if (dst->byte_order == BNXT_ULP_BYTE_ORDER_BE &&
933 src->byte_order == BNXT_ULP_BYTE_ORDER_BE)
934 return ulp_blob_msb_block_merge(dst, src, block_size, pad);
936 BNXT_TF_DBG(ERR, "block merge not implemented yet\n");
941 ulp_blob_append(struct ulp_blob *dst, struct ulp_blob *src,
942 uint16_t src_offset, uint16_t src_len)
944 uint32_t k, remaining;
947 uint8_t *src_buf = ulp_blob_data_get(src, &num);
949 if ((src_offset + src_len) > num)
952 /* Only supporting BE for now */
953 if (src->byte_order != BNXT_ULP_BYTE_ORDER_BE ||
954 dst->byte_order != BNXT_ULP_BYTE_ORDER_BE)
957 /* Handle if the source offset is not on a byte boundary */
958 remaining = src_offset % ULP_BLOB_BYTE;
960 bluff = src_buf[src_offset / ULP_BLOB_BYTE] & ((uint8_t)-1 >>
961 (ULP_BLOB_BYTE - remaining));
962 ulp_bs_put_msb(dst->data, dst->write_idx,
963 ULP_BLOB_BYTE, bluff);
964 dst->write_idx += remaining;
965 src_offset += remaining;
968 src_buf += ULP_BITS_2_BYTE_NR(src_offset);
970 /* Push the byte aligned pieces */
971 for (k = 0; k < ULP_BITS_2_BYTE_NR(src_len); k++) {
972 ulp_bs_put_msb(dst->data, dst->write_idx, ULP_BLOB_BYTE,
974 dst->write_idx += ULP_BLOB_BYTE;
978 /* Handle the remaining if length is not a byte boundary */
979 remaining = src_len % ULP_BLOB_BYTE;
981 bluff = (*src_buf) & ((uint8_t)-1 <<
982 (ULP_BLOB_BYTE - remaining));
983 ulp_bs_put_msb(dst->data, dst->write_idx,
984 ULP_BLOB_BYTE, bluff);
985 dst->write_idx += remaining;
992 * Perform the blob buffer copy.
993 * This api makes the src blob merged to the dst blob.
995 * dst [in] The destination blob, the blob to be merged.
996 * src [in] The src blob.
998 * returns 0 on success.
1001 ulp_blob_buffer_copy(struct ulp_blob *dst, struct ulp_blob *src)
1003 if ((dst->write_idx + src->write_idx) > dst->bitlen) {
1004 BNXT_TF_DBG(ERR, "source buffer too large\n");
1007 if (ULP_BITS_IS_BYTE_NOT_ALIGNED(dst->write_idx) ||
1008 ULP_BITS_IS_BYTE_NOT_ALIGNED(src->write_idx)) {
1009 BNXT_TF_DBG(ERR, "source buffer is not aligned\n");
1012 memcpy(&dst->data[ULP_BITS_2_BYTE_NR(dst->write_idx)],
1013 src->data, ULP_BITS_2_BYTE_NR(src->write_idx));
1014 dst->write_idx += src->write_idx;
1019 * Read data from the operand
1021 * operand [in] A pointer to a 16 Byte operand
1023 * val [in/out] The variable to copy the operand to
1025 * bytes [in] The number of bytes to read into val
1027 * returns number of bits read, zero on error
1030 ulp_operand_read(uint8_t *operand,
1034 /* validate the arguments */
1035 if (!operand || !val) {
1036 BNXT_TF_DBG(ERR, "invalid argument\n");
1037 return 0; /* failure */
1039 memcpy(val, operand, bytes);
1044 * Check the buffer is empty
1046 * buf [in] The buffer
1047 * size [in] The size of the buffer
1050 int32_t ulp_buffer_is_empty(const uint8_t *buf, uint32_t size)
1052 return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
1055 /* Function to check if bitmap is zero.Return 1 on success */
1056 uint32_t ulp_bitmap_is_zero(uint8_t *bitmap, int32_t size)
1058 while (size-- > 0) {
1066 /* Function to check if bitmap is ones. Return 1 on success */
1067 uint32_t ulp_bitmap_is_ones(uint8_t *bitmap, int32_t size)
1069 while (size-- > 0) {
1070 if (*bitmap != 0xFF)
1077 /* Function to check if bitmap is not zero. Return 1 on success */
1078 uint32_t ulp_bitmap_notzero(const uint8_t *bitmap, int32_t size)
1080 while (size-- > 0) {
1088 /* returns 0 if input is power of 2 */
1089 int32_t ulp_util_is_power_of_2(uint64_t x)