1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_bus_vdev.h>
9 #include <rte_malloc.h>
11 #include <rte_kvargs.h>
12 #include <rte_cycles.h>
13 #include <rte_errno.h>
15 #include <rte_bbdev.h>
16 #include <rte_bbdev_pmd.h>
18 #include <rte_hexdump.h>
21 #ifdef RTE_BBDEV_SDK_AVX2
24 #include <phy_turbo.h>
26 #include <phy_rate_match.h>
28 #ifdef RTE_BBDEV_SDK_AVX512
29 #include <bit_reverse.h>
30 #include <phy_ldpc_encoder_5gnr.h>
31 #include <phy_ldpc_decoder_5gnr.h>
32 #include <phy_LDPC_ratematch_5gnr.h>
33 #include <phy_rate_dematching_5gnr.h>
36 #define DRIVER_NAME baseband_turbo_sw
38 RTE_LOG_REGISTER_DEFAULT(bbdev_turbo_sw_logtype, NOTICE);
40 /* Helper macro for logging */
41 #define rte_bbdev_log(level, fmt, ...) \
42 rte_log(RTE_LOG_ ## level, bbdev_turbo_sw_logtype, fmt "\n", \
45 #define rte_bbdev_log_debug(fmt, ...) \
46 rte_bbdev_log(DEBUG, RTE_STR(__LINE__) ":%s() " fmt, __func__, \
49 #define DEINT_INPUT_BUF_SIZE (((RTE_BBDEV_TURBO_MAX_CB_SIZE >> 3) + 1) * 48)
50 #define DEINT_OUTPUT_BUF_SIZE (DEINT_INPUT_BUF_SIZE * 6)
51 #define ADAPTER_OUTPUT_BUF_SIZE ((RTE_BBDEV_TURBO_MAX_CB_SIZE + 4) * 48)
53 /* private data structure */
54 struct bbdev_private {
55 unsigned int max_nb_queues; /**< Max number of queues */
58 /* Initialisation params structure that can be used by Turbo SW driver */
59 struct turbo_sw_params {
60 int socket_id; /*< Turbo SW device socket */
61 uint16_t queues_num; /*< Turbo SW device queues number */
64 /* Acceptable params for Turbo SW devices */
65 #define TURBO_SW_MAX_NB_QUEUES_ARG "max_nb_queues"
66 #define TURBO_SW_SOCKET_ID_ARG "socket_id"
68 static const char * const turbo_sw_valid_params[] = {
69 TURBO_SW_MAX_NB_QUEUES_ARG,
70 TURBO_SW_SOCKET_ID_ARG
74 struct turbo_sw_queue {
75 /* Ring for processed (encoded/decoded) operations which are ready to
78 struct rte_ring *processed_pkts;
79 /* Stores input for turbo encoder (used when CRC attachment is
83 /* Stores output from turbo encoder */
85 /* Alpha gamma buf for bblib_turbo_decoder() function */
87 /* Temp buf for bblib_turbo_decoder() function */
89 /* Input buf for bblib_rate_dematching_lte() function */
91 /* Output buf for bblib_rate_dematching_lte() function */
92 uint8_t *deint_output;
93 /* Output buf for bblib_turbodec_adapter_lte() function */
94 uint8_t *adapter_output;
95 /* Operation type of this queue */
96 enum rte_bbdev_op_type type;
97 } __rte_cache_aligned;
100 #ifdef RTE_BBDEV_SDK_AVX2
102 mbuf_append(struct rte_mbuf *m_head, struct rte_mbuf *m, uint16_t len)
104 if (unlikely(len > rte_pktmbuf_tailroom(m)))
107 char *tail = (char *)m->buf_addr + m->data_off + m->data_len;
108 m->data_len = (uint16_t)(m->data_len + len);
109 m_head->pkt_len = (m_head->pkt_len + len);
113 /* Calculate index based on Table 5.1.3-3 from TS34.212 */
114 static inline int32_t
115 compute_idx(uint16_t k)
119 if (k < RTE_BBDEV_TURBO_MIN_CB_SIZE || k > RTE_BBDEV_TURBO_MAX_CB_SIZE)
123 if ((k - 2048) % 64 != 0)
126 result = 124 + (k - 2048) / 64;
127 } else if (k <= 512) {
128 if ((k - 40) % 8 != 0)
131 result = (k - 40) / 8 + 1;
132 } else if (k <= 1024) {
133 if ((k - 512) % 16 != 0)
136 result = 60 + (k - 512) / 16;
137 } else { /* 1024 < k <= 2048 */
138 if ((k - 1024) % 32 != 0)
141 result = 92 + (k - 1024) / 32;
148 /* Read flag value 0/1 from bitmap */
150 check_bit(uint32_t bitmap, uint32_t bitmask)
152 return bitmap & bitmask;
155 /* Get device info */
157 info_get(struct rte_bbdev *dev, struct rte_bbdev_driver_info *dev_info)
159 struct bbdev_private *internals = dev->data->dev_private;
161 static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
162 #ifdef RTE_BBDEV_SDK_AVX2
164 .type = RTE_BBDEV_OP_TURBO_DEC,
167 RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE |
168 RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN |
169 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN |
170 RTE_BBDEV_TURBO_CRC_TYPE_24B |
171 RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP |
172 RTE_BBDEV_TURBO_EARLY_TERMINATION,
173 .max_llr_modulus = 16,
175 RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
176 .num_buffers_hard_out =
177 RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
178 .num_buffers_soft_out = 0,
182 .type = RTE_BBDEV_OP_TURBO_ENC,
185 RTE_BBDEV_TURBO_CRC_24B_ATTACH |
186 RTE_BBDEV_TURBO_CRC_24A_ATTACH |
187 RTE_BBDEV_TURBO_RATE_MATCH |
188 RTE_BBDEV_TURBO_RV_INDEX_BYPASS,
190 RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
192 RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
196 #ifdef RTE_BBDEV_SDK_AVX512
198 .type = RTE_BBDEV_OP_LDPC_ENC,
201 RTE_BBDEV_LDPC_RATE_MATCH |
202 RTE_BBDEV_LDPC_CRC_16_ATTACH |
203 RTE_BBDEV_LDPC_CRC_24A_ATTACH |
204 RTE_BBDEV_LDPC_CRC_24B_ATTACH,
206 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
208 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
212 .type = RTE_BBDEV_OP_LDPC_DEC,
215 RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK |
216 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
217 RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK |
218 RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
219 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
220 RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
221 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE,
225 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
226 .num_buffers_hard_out =
227 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
228 .num_buffers_soft_out = 0,
232 RTE_BBDEV_END_OF_CAPABILITIES_LIST()
235 static struct rte_bbdev_queue_conf default_queue_conf = {
236 .queue_size = RTE_BBDEV_QUEUE_SIZE_LIMIT,
238 #ifdef RTE_BBDEV_SDK_AVX2
239 static const enum rte_cpu_flag_t cpu_flag = RTE_CPUFLAG_SSE4_2;
240 dev_info->cpu_flag_reqs = &cpu_flag;
242 dev_info->cpu_flag_reqs = NULL;
244 default_queue_conf.socket = dev->data->socket_id;
246 dev_info->driver_name = RTE_STR(DRIVER_NAME);
247 dev_info->max_num_queues = internals->max_nb_queues;
248 dev_info->queue_size_lim = RTE_BBDEV_QUEUE_SIZE_LIMIT;
249 dev_info->hardware_accelerated = false;
250 dev_info->max_dl_queue_priority = 0;
251 dev_info->max_ul_queue_priority = 0;
252 dev_info->default_queue_conf = default_queue_conf;
253 dev_info->capabilities = bbdev_capabilities;
254 dev_info->min_alignment = 64;
255 dev_info->harq_buffer_size = 0;
256 dev_info->data_endianness = RTE_LITTLE_ENDIAN;
258 rte_bbdev_log_debug("got device info from %u\n", dev->data->dev_id);
263 q_release(struct rte_bbdev *dev, uint16_t q_id)
265 struct turbo_sw_queue *q = dev->data->queues[q_id].queue_private;
268 rte_ring_free(q->processed_pkts);
269 rte_free(q->enc_out);
272 rte_free(q->code_block);
273 rte_free(q->deint_input);
274 rte_free(q->deint_output);
275 rte_free(q->adapter_output);
277 dev->data->queues[q_id].queue_private = NULL;
280 rte_bbdev_log_debug("released device queue %u:%u",
281 dev->data->dev_id, q_id);
287 q_setup(struct rte_bbdev *dev, uint16_t q_id,
288 const struct rte_bbdev_queue_conf *queue_conf)
291 struct turbo_sw_queue *q;
292 char name[RTE_RING_NAMESIZE];
294 /* Allocate the queue data structure. */
295 q = rte_zmalloc_socket(RTE_STR(DRIVER_NAME), sizeof(*q),
296 RTE_CACHE_LINE_SIZE, queue_conf->socket);
298 rte_bbdev_log(ERR, "Failed to allocate queue memory");
302 /* Allocate memory for encoder output. */
303 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_enc_o%u:%u",
304 dev->data->dev_id, q_id);
305 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
307 "Creating queue name for device %u queue %u failed",
308 dev->data->dev_id, q_id);
312 q->enc_out = rte_zmalloc_socket(name,
313 ((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) *
314 sizeof(*q->enc_out) * 3,
315 RTE_CACHE_LINE_SIZE, queue_conf->socket);
316 if (q->enc_out == NULL) {
318 "Failed to allocate queue memory for %s", name);
323 /* Allocate memory for rate matching output. */
324 ret = snprintf(name, RTE_RING_NAMESIZE,
325 RTE_STR(DRIVER_NAME)"_enc_i%u:%u", dev->data->dev_id,
327 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
329 "Creating queue name for device %u queue %u failed",
330 dev->data->dev_id, q_id);
334 q->enc_in = rte_zmalloc_socket(name,
335 (RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q->enc_in),
336 RTE_CACHE_LINE_SIZE, queue_conf->socket);
337 if (q->enc_in == NULL) {
339 "Failed to allocate queue memory for %s", name);
344 /* Allocate memory for Alpha Gamma temp buffer. */
345 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_ag%u:%u",
346 dev->data->dev_id, q_id);
347 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
349 "Creating queue name for device %u queue %u failed",
350 dev->data->dev_id, q_id);
354 q->ag = rte_zmalloc_socket(name,
355 RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q->ag),
356 RTE_CACHE_LINE_SIZE, queue_conf->socket);
359 "Failed to allocate queue memory for %s", name);
364 /* Allocate memory for code block temp buffer. */
365 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_cb%u:%u",
366 dev->data->dev_id, q_id);
367 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
369 "Creating queue name for device %u queue %u failed",
370 dev->data->dev_id, q_id);
374 q->code_block = rte_zmalloc_socket(name,
375 RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q->code_block),
376 RTE_CACHE_LINE_SIZE, queue_conf->socket);
377 if (q->code_block == NULL) {
379 "Failed to allocate queue memory for %s", name);
384 /* Allocate memory for Deinterleaver input. */
385 ret = snprintf(name, RTE_RING_NAMESIZE,
386 RTE_STR(DRIVER_NAME)"_de_i%u:%u",
387 dev->data->dev_id, q_id);
388 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
390 "Creating queue name for device %u queue %u failed",
391 dev->data->dev_id, q_id);
395 q->deint_input = rte_zmalloc_socket(name,
396 DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
397 RTE_CACHE_LINE_SIZE, queue_conf->socket);
398 if (q->deint_input == NULL) {
400 "Failed to allocate queue memory for %s", name);
405 /* Allocate memory for Deinterleaver output. */
406 ret = snprintf(name, RTE_RING_NAMESIZE,
407 RTE_STR(DRIVER_NAME)"_de_o%u:%u",
408 dev->data->dev_id, q_id);
409 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
411 "Creating queue name for device %u queue %u failed",
412 dev->data->dev_id, q_id);
416 q->deint_output = rte_zmalloc_socket(NULL,
417 DEINT_OUTPUT_BUF_SIZE * sizeof(*q->deint_output),
418 RTE_CACHE_LINE_SIZE, queue_conf->socket);
419 if (q->deint_output == NULL) {
421 "Failed to allocate queue memory for %s", name);
426 /* Allocate memory for Adapter output. */
427 ret = snprintf(name, RTE_RING_NAMESIZE,
428 RTE_STR(DRIVER_NAME)"_ada_o%u:%u",
429 dev->data->dev_id, q_id);
430 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
432 "Creating queue name for device %u queue %u failed",
433 dev->data->dev_id, q_id);
437 q->adapter_output = rte_zmalloc_socket(NULL,
438 ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q->adapter_output),
439 RTE_CACHE_LINE_SIZE, queue_conf->socket);
440 if (q->adapter_output == NULL) {
442 "Failed to allocate queue memory for %s", name);
447 /* Create ring for packets awaiting to be dequeued. */
448 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"%u:%u",
449 dev->data->dev_id, q_id);
450 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
452 "Creating queue name for device %u queue %u failed",
453 dev->data->dev_id, q_id);
457 q->processed_pkts = rte_ring_create(name, queue_conf->queue_size,
458 queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
459 if (q->processed_pkts == NULL) {
460 rte_bbdev_log(ERR, "Failed to create ring for %s", name);
465 q->type = queue_conf->op_type;
467 dev->data->queues[q_id].queue_private = q;
468 rte_bbdev_log_debug("setup device queue %s", name);
472 rte_ring_free(q->processed_pkts);
473 rte_free(q->enc_out);
476 rte_free(q->code_block);
477 rte_free(q->deint_input);
478 rte_free(q->deint_output);
479 rte_free(q->adapter_output);
484 static const struct rte_bbdev_ops pmd_ops = {
485 .info_get = info_get,
486 .queue_setup = q_setup,
487 .queue_release = q_release
490 #ifdef RTE_BBDEV_SDK_AVX2
491 #ifdef RTE_LIBRTE_BBDEV_DEBUG
492 /* Checks if the encoder input buffer is correct.
493 * Returns 0 if it's valid, -1 otherwise.
496 is_enc_input_valid(const uint16_t k, const int32_t k_idx,
497 const uint16_t in_length)
500 rte_bbdev_log(ERR, "K Index is invalid");
504 if (in_length - (k >> 3) < 0) {
506 "Mismatch between input length (%u bytes) and K (%u bits)",
511 if (k > RTE_BBDEV_TURBO_MAX_CB_SIZE) {
512 rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
513 k, RTE_BBDEV_TURBO_MAX_CB_SIZE);
520 /* Checks if the decoder input buffer is correct.
521 * Returns 0 if it's valid, -1 otherwise.
524 is_dec_input_valid(int32_t k_idx, int16_t kw, int16_t in_length)
527 rte_bbdev_log(ERR, "K index is invalid");
531 if (in_length < kw) {
533 "Mismatch between input length (%u) and kw (%u)",
538 if (kw > RTE_BBDEV_TURBO_MAX_KW) {
539 rte_bbdev_log(ERR, "Input length (%u) is too big, max: %d",
540 kw, RTE_BBDEV_TURBO_MAX_KW);
550 process_enc_cb(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
551 uint8_t r, uint8_t c, uint16_t k, uint16_t ncb,
552 uint32_t e, struct rte_mbuf *m_in, struct rte_mbuf *m_out_head,
553 struct rte_mbuf *m_out, uint16_t in_offset, uint16_t out_offset,
554 uint16_t in_length, struct rte_bbdev_stats *q_stats)
556 #ifdef RTE_BBDEV_SDK_AVX2
557 #ifdef RTE_LIBRTE_BBDEV_DEBUG
560 RTE_SET_USED(in_length);
564 uint8_t *in, *out0, *out1, *out2, *tmp_out, *rm_out;
565 uint64_t first_3_bytes = 0;
566 struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
567 struct bblib_crc_request crc_req;
568 struct bblib_crc_response crc_resp;
569 struct bblib_turbo_encoder_request turbo_req;
570 struct bblib_turbo_encoder_response turbo_resp;
571 struct bblib_rate_match_dl_request rm_req;
572 struct bblib_rate_match_dl_response rm_resp;
573 #ifdef RTE_BBDEV_OFFLOAD_COST
576 RTE_SET_USED(q_stats);
579 k_idx = compute_idx(k);
580 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
582 /* CRC24A (for TB) */
583 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH) &&
584 (enc->code_block_mode == RTE_BBDEV_CODE_BLOCK)) {
585 #ifdef RTE_LIBRTE_BBDEV_DEBUG
586 ret = is_enc_input_valid(k - 24, k_idx, in_length);
588 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
594 crc_req.len = k - 24;
595 /* Check if there is a room for CRC bits if not use
596 * the temporary buffer.
598 if (mbuf_append(m_in, m_in, 3) == NULL) {
599 rte_memcpy(q->enc_in, in, (k - 24) >> 3);
602 /* Store 3 first bytes of next CB as they will be
603 * overwritten by CRC bytes. If it is the last CB then
604 * there is no point to store 3 next bytes and this
605 * if..else branch will be omitted.
607 first_3_bytes = *((uint64_t *)&in[(k - 32) >> 3]);
611 #ifdef RTE_BBDEV_OFFLOAD_COST
612 start_time = rte_rdtsc_precise();
614 /* CRC24A generation */
615 bblib_lte_crc24a_gen(&crc_req, &crc_resp);
616 #ifdef RTE_BBDEV_OFFLOAD_COST
617 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
619 } else if (enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) {
621 #ifdef RTE_LIBRTE_BBDEV_DEBUG
622 ret = is_enc_input_valid(k - 24, k_idx, in_length);
624 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
630 crc_req.len = k - 24;
631 /* Check if there is a room for CRC bits if this is the last
632 * CB in TB. If not use temporary buffer.
634 if ((c - r == 1) && (mbuf_append(m_in, m_in, 3) == NULL)) {
635 rte_memcpy(q->enc_in, in, (k - 24) >> 3);
637 } else if (c - r > 1) {
638 /* Store 3 first bytes of next CB as they will be
639 * overwritten by CRC bytes. If it is the last CB then
640 * there is no point to store 3 next bytes and this
641 * if..else branch will be omitted.
643 first_3_bytes = *((uint64_t *)&in[(k - 32) >> 3]);
647 #ifdef RTE_BBDEV_OFFLOAD_COST
648 start_time = rte_rdtsc_precise();
650 /* CRC24B generation */
651 bblib_lte_crc24b_gen(&crc_req, &crc_resp);
652 #ifdef RTE_BBDEV_OFFLOAD_COST
653 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
656 #ifdef RTE_LIBRTE_BBDEV_DEBUG
658 ret = is_enc_input_valid(k, k_idx, in_length);
660 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
668 /* Each bit layer output from turbo encoder is (k+4) bits long, i.e.
669 * input length + 4 tail bits. That's (k/8) + 1 bytes after rounding up.
670 * So dst_data's length should be 3*(k/8) + 3 bytes.
671 * In Rate-matching bypass case outputs pointers passed to encoder
672 * (out0, out1 and out2) can directly point to addresses of output from
675 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH) {
677 out1 = RTE_PTR_ADD(out0, (k >> 3) + 1);
678 out2 = RTE_PTR_ADD(out1, (k >> 3) + 1);
680 out0 = (uint8_t *)mbuf_append(m_out_head, m_out,
683 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
685 "Too little space in output mbuf");
688 enc->output.length += (k >> 3) * 3 + 2;
689 /* rte_bbdev_op_data.offset can be different than the
690 * offset of the appended bytes
692 out0 = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
693 out1 = rte_pktmbuf_mtod_offset(m_out, uint8_t *,
694 out_offset + (k >> 3) + 1);
695 out2 = rte_pktmbuf_mtod_offset(m_out, uint8_t *,
696 out_offset + 2 * ((k >> 3) + 1));
699 turbo_req.case_id = k_idx;
700 turbo_req.input_win = in;
701 turbo_req.length = k >> 3;
702 turbo_resp.output_win_0 = out0;
703 turbo_resp.output_win_1 = out1;
704 turbo_resp.output_win_2 = out2;
706 #ifdef RTE_BBDEV_OFFLOAD_COST
707 start_time = rte_rdtsc_precise();
710 if (bblib_turbo_encoder(&turbo_req, &turbo_resp) != 0) {
711 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
712 rte_bbdev_log(ERR, "Turbo Encoder failed");
715 #ifdef RTE_BBDEV_OFFLOAD_COST
716 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
719 /* Restore 3 first bytes of next CB if they were overwritten by CRC*/
720 if (first_3_bytes != 0)
721 *((uint64_t *)&in[(k - 32) >> 3]) = first_3_bytes;
724 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH) {
726 /* Integer round up division by 8 */
727 uint16_t out_len = (e + 7) >> 3;
728 /* The mask array is indexed using E%8. E is an even number so
729 * there are only 4 possible values.
731 const uint8_t mask_out[] = {0xFF, 0xC0, 0xF0, 0xFC};
733 /* get output data starting address */
734 rm_out = (uint8_t *)mbuf_append(m_out_head, m_out, out_len);
735 if (rm_out == NULL) {
736 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
738 "Too little space in output mbuf");
741 /* rte_bbdev_op_data.offset can be different than the offset
742 * of the appended bytes
744 rm_out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
746 /* index of current code block */
748 /* total number of code block */
750 /* For DL - 1, UL - 0 */
751 rm_req.direction = 1;
752 /* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nsoft, KMIMO
753 * and MDL_HARQ are used for Ncb calculation. As Ncb is already
754 * known we can adjust those parameters
756 rm_req.Nsoft = ncb * rm_req.C;
759 /* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nl, Qm and G
760 * are used for E calculation. As E is already known we can
761 * adjust those parameters
765 rm_req.G = rm_req.NL * rm_req.Qm * rm_req.C;
767 rm_req.rvidx = enc->rv_index;
768 rm_req.Kidx = k_idx - 1;
773 rm_resp.output = rm_out;
774 rm_resp.OutputLen = out_len;
775 if (enc->op_flags & RTE_BBDEV_TURBO_RV_INDEX_BYPASS)
776 rm_req.bypass_rvidx = 1;
778 rm_req.bypass_rvidx = 0;
780 #ifdef RTE_BBDEV_OFFLOAD_COST
781 start_time = rte_rdtsc_precise();
784 if (bblib_rate_match_dl(&rm_req, &rm_resp) != 0) {
785 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
786 rte_bbdev_log(ERR, "Rate matching failed");
789 #ifdef RTE_BBDEV_OFFLOAD_COST
790 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
793 /* SW fills an entire last byte even if E%8 != 0. Clear the
794 * superfluous data bits for consistency with HW device.
796 mask_id = (e & 7) >> 1;
797 rm_out[out_len - 1] &= mask_out[mask_id];
798 enc->output.length += rm_resp.OutputLen;
800 /* Rate matching is bypassed */
802 /* Completing last byte of out0 (where 4 tail bits are stored)
803 * by moving first 4 bits from out1
805 tmp_out = (uint8_t *) --out1;
806 *tmp_out = *tmp_out | ((*(tmp_out + 1) & 0xF0) >> 4);
808 /* Shifting out1 data by 4 bits to the left */
809 for (m = 0; m < k >> 3; ++m) {
810 uint8_t *first = tmp_out;
811 uint8_t second = *(tmp_out + 1);
812 *first = (*first << 4) | ((second & 0xF0) >> 4);
815 /* Shifting out2 data by 8 bits to the left */
816 for (m = 0; m < (k >> 3) + 1; ++m) {
817 *tmp_out = *(tmp_out + 1);
831 RTE_SET_USED(m_out_head);
833 RTE_SET_USED(in_offset);
834 RTE_SET_USED(out_offset);
835 RTE_SET_USED(in_length);
836 RTE_SET_USED(q_stats);
842 process_ldpc_enc_cb(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
843 uint32_t e, struct rte_mbuf *m_in, struct rte_mbuf *m_out_head,
844 struct rte_mbuf *m_out, uint16_t in_offset, uint16_t out_offset,
845 uint16_t seg_total_left, struct rte_bbdev_stats *q_stats)
847 #ifdef RTE_BBDEV_SDK_AVX512
848 RTE_SET_USED(seg_total_left);
849 uint8_t *in, *rm_out;
850 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
851 struct bblib_ldpc_encoder_5gnr_request ldpc_req;
852 struct bblib_ldpc_encoder_5gnr_response ldpc_resp;
853 struct bblib_LDPC_ratematch_5gnr_request rm_req;
854 struct bblib_LDPC_ratematch_5gnr_response rm_resp;
855 struct bblib_crc_request crc_req;
856 struct bblib_crc_response crc_resp;
857 uint16_t msgLen, puntBits, parity_offset, out_len;
858 uint16_t K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
859 uint16_t in_length_in_bits = K - enc->n_filler;
860 uint16_t in_length_in_bytes = (in_length_in_bits + 7) >> 3;
862 #ifdef RTE_BBDEV_OFFLOAD_COST
863 uint64_t start_time = rte_rdtsc_precise();
865 RTE_SET_USED(q_stats);
868 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
870 /* Masking the Filler bits explicitly */
871 memset(q->enc_in + (in_length_in_bytes - 3), 0,
872 ((K + 7) >> 3) - (in_length_in_bytes - 3));
874 if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24A_ATTACH) {
875 rte_memcpy(q->enc_in, in, in_length_in_bytes - 3);
877 crc_req.len = in_length_in_bits - 24;
878 crc_resp.data = q->enc_in;
879 bblib_lte_crc24a_gen(&crc_req, &crc_resp);
880 } else if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH) {
881 rte_memcpy(q->enc_in, in, in_length_in_bytes - 3);
883 crc_req.len = in_length_in_bits - 24;
884 crc_resp.data = q->enc_in;
885 bblib_lte_crc24b_gen(&crc_req, &crc_resp);
886 } else if (enc->op_flags & RTE_BBDEV_LDPC_CRC_16_ATTACH) {
887 rte_memcpy(q->enc_in, in, in_length_in_bytes - 2);
889 crc_req.len = in_length_in_bits - 16;
890 crc_resp.data = q->enc_in;
891 bblib_lte_crc16_gen(&crc_req, &crc_resp);
893 rte_memcpy(q->enc_in, in, in_length_in_bytes);
896 ldpc_req.Zc = enc->z_c;
897 ldpc_req.baseGraph = enc->basegraph;
898 /* Number of rows set to maximum */
899 ldpc_req.nRows = ldpc_req.baseGraph == 1 ? 46 : 42;
900 ldpc_req.numberCodeblocks = 1;
901 ldpc_req.input[0] = (int8_t *) q->enc_in;
902 ldpc_resp.output[0] = (int8_t *) q->enc_out;
904 bblib_bit_reverse(ldpc_req.input[0], in_length_in_bytes << 3);
906 if (bblib_ldpc_encoder_5gnr(&ldpc_req, &ldpc_resp) != 0) {
907 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
908 rte_bbdev_log(ERR, "LDPC Encoder failed");
913 * Systematic + Parity : Recreating stream with filler bits, ideally
914 * the bit select could handle this in the RM SDK
916 msgLen = (ldpc_req.baseGraph == 1 ? 22 : 10) * ldpc_req.Zc;
917 puntBits = 2 * ldpc_req.Zc;
918 parity_offset = msgLen - puntBits;
919 ippsCopyBE_1u(((uint8_t *) ldpc_req.input[0]) + (puntBits / 8),
920 puntBits%8, q->adapter_output, 0, parity_offset);
921 ippsCopyBE_1u(q->enc_out, 0, q->adapter_output + (parity_offset / 8),
922 parity_offset % 8, ldpc_req.nRows * ldpc_req.Zc);
924 out_len = (e + 7) >> 3;
925 /* get output data starting address */
926 rm_out = (uint8_t *)mbuf_append(m_out_head, m_out, out_len);
927 if (rm_out == NULL) {
928 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
930 "Too little space in output mbuf");
934 * rte_bbdev_op_data.offset can be different than the offset
935 * of the appended bytes
937 rm_out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
941 rm_req.Ncb = enc->n_cb;
942 rm_req.Qm = enc->q_m;
943 rm_req.Zc = enc->z_c;
944 rm_req.baseGraph = enc->basegraph;
945 rm_req.input = q->adapter_output;
946 rm_req.nLen = enc->n_filler;
947 rm_req.nullIndex = parity_offset - enc->n_filler;
948 rm_req.rvidx = enc->rv_index;
949 rm_resp.output = q->deint_output;
951 if (bblib_LDPC_ratematch_5gnr(&rm_req, &rm_resp) != 0) {
952 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
953 rte_bbdev_log(ERR, "Rate matching failed");
957 /* RM SDK may provide non zero bits on last byte */
959 q->deint_output[out_len-1] &= (1 << (e % 8)) - 1;
961 bblib_bit_reverse((int8_t *) q->deint_output, out_len << 3);
963 rte_memcpy(rm_out, q->deint_output, out_len);
964 enc->output.length += out_len;
966 #ifdef RTE_BBDEV_OFFLOAD_COST
967 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
974 RTE_SET_USED(m_out_head);
976 RTE_SET_USED(in_offset);
977 RTE_SET_USED(out_offset);
978 RTE_SET_USED(seg_total_left);
979 RTE_SET_USED(q_stats);
984 enqueue_enc_one_op(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
985 struct rte_bbdev_stats *queue_stats)
987 uint8_t c, r, crc24_bits = 0;
990 struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
991 uint16_t in_offset = enc->input.offset;
992 uint16_t out_offset = enc->output.offset;
993 struct rte_mbuf *m_in = enc->input.data;
994 struct rte_mbuf *m_out = enc->output.data;
995 struct rte_mbuf *m_out_head = enc->output.data;
996 uint32_t in_length, mbuf_total_left = enc->input.length;
997 uint16_t seg_total_left;
999 /* Clear op status */
1002 if (mbuf_total_left > RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) {
1003 rte_bbdev_log(ERR, "TB size (%u) is too big, max: %d",
1004 mbuf_total_left, RTE_BBDEV_TURBO_MAX_TB_SIZE);
1005 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1009 if (m_in == NULL || m_out == NULL) {
1010 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1011 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1015 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) ||
1016 (enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH))
1019 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1020 c = enc->tb_params.c;
1021 r = enc->tb_params.r;
1022 } else {/* For Code Block mode */
1027 while (mbuf_total_left > 0 && r < c) {
1029 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1031 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1032 k = (r < enc->tb_params.c_neg) ?
1033 enc->tb_params.k_neg : enc->tb_params.k_pos;
1034 ncb = (r < enc->tb_params.c_neg) ?
1035 enc->tb_params.ncb_neg : enc->tb_params.ncb_pos;
1036 e = (r < enc->tb_params.cab) ?
1037 enc->tb_params.ea : enc->tb_params.eb;
1039 k = enc->cb_params.k;
1040 ncb = enc->cb_params.ncb;
1041 e = enc->cb_params.e;
1044 process_enc_cb(q, op, r, c, k, ncb, e, m_in, m_out_head,
1045 m_out, in_offset, out_offset, seg_total_left,
1047 /* Update total_left */
1048 in_length = ((k - crc24_bits) >> 3);
1049 mbuf_total_left -= in_length;
1050 /* Update offsets for next CBs (if exist) */
1051 in_offset += (k - crc24_bits) >> 3;
1052 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH)
1053 out_offset += e >> 3;
1055 out_offset += (k >> 3) * 3 + 2;
1057 /* Update offsets */
1058 if (seg_total_left == in_length) {
1059 /* Go to the next mbuf */
1061 m_out = m_out->next;
1068 /* check if all input data was processed */
1069 if (mbuf_total_left != 0) {
1070 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1072 "Mismatch between mbuf length and included CBs sizes");
1078 enqueue_ldpc_enc_one_op(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
1079 struct rte_bbdev_stats *queue_stats)
1081 uint8_t c, r, crc24_bits = 0;
1083 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
1084 uint16_t in_offset = enc->input.offset;
1085 uint16_t out_offset = enc->output.offset;
1086 struct rte_mbuf *m_in = enc->input.data;
1087 struct rte_mbuf *m_out = enc->output.data;
1088 struct rte_mbuf *m_out_head = enc->output.data;
1089 uint32_t in_length, mbuf_total_left = enc->input.length;
1091 uint16_t seg_total_left;
1093 /* Clear op status */
1096 if (mbuf_total_left > RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) {
1097 rte_bbdev_log(ERR, "TB size (%u) is too big, max: %d",
1098 mbuf_total_left, RTE_BBDEV_TURBO_MAX_TB_SIZE);
1099 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1103 if (m_in == NULL || m_out == NULL) {
1104 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1105 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1109 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) ||
1110 (enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH))
1113 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1114 c = enc->tb_params.c;
1115 r = enc->tb_params.r;
1116 } else { /* For Code Block mode */
1121 while (mbuf_total_left > 0 && r < c) {
1123 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1125 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1126 e = (r < enc->tb_params.cab) ?
1127 enc->tb_params.ea : enc->tb_params.eb;
1129 e = enc->cb_params.e;
1132 process_ldpc_enc_cb(q, op, e, m_in, m_out_head,
1133 m_out, in_offset, out_offset, seg_total_left,
1135 /* Update total_left */
1136 in_length = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
1137 in_length = ((in_length - crc24_bits - enc->n_filler) >> 3);
1138 mbuf_total_left -= in_length;
1139 /* Update offsets for next CBs (if exist) */
1140 in_offset += in_length;
1141 out_offset += (e + 7) >> 3;
1143 /* Update offsets */
1144 if (seg_total_left == in_length) {
1145 /* Go to the next mbuf */
1147 m_out = m_out->next;
1154 /* check if all input data was processed */
1155 if (mbuf_total_left != 0) {
1156 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1158 "Mismatch between mbuf length and included CBs sizes %d",
1163 static inline uint16_t
1164 enqueue_enc_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_enc_op **ops,
1165 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1168 #ifdef RTE_BBDEV_OFFLOAD_COST
1169 queue_stats->acc_offload_cycles = 0;
1172 for (i = 0; i < nb_ops; ++i)
1173 enqueue_enc_one_op(q, ops[i], queue_stats);
1175 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1179 static inline uint16_t
1180 enqueue_ldpc_enc_all_ops(struct turbo_sw_queue *q,
1181 struct rte_bbdev_enc_op **ops,
1182 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1185 #ifdef RTE_BBDEV_OFFLOAD_COST
1186 queue_stats->acc_offload_cycles = 0;
1189 for (i = 0; i < nb_ops; ++i)
1190 enqueue_ldpc_enc_one_op(q, ops[i], queue_stats);
1192 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1196 #ifdef RTE_BBDEV_SDK_AVX2
1198 move_padding_bytes(const uint8_t *in, uint8_t *out, uint16_t k,
1202 uint16_t kpi = ncb / 3;
1203 uint16_t nd = kpi - d;
1205 rte_memcpy(&out[nd], in, d);
1206 rte_memcpy(&out[nd + kpi + 64], &in[kpi], d);
1207 rte_memcpy(&out[(nd - 1) + 2 * (kpi + 64)], &in[2 * kpi], d);
1212 process_dec_cb(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1213 uint8_t c, uint16_t k, uint16_t kw, struct rte_mbuf *m_in,
1214 struct rte_mbuf *m_out_head, struct rte_mbuf *m_out,
1215 uint16_t in_offset, uint16_t out_offset, bool check_crc_24b,
1216 uint16_t crc24_overlap, uint16_t in_length,
1217 struct rte_bbdev_stats *q_stats)
1219 #ifdef RTE_BBDEV_SDK_AVX2
1220 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1223 RTE_SET_USED(in_length);
1227 uint8_t *in, *out, *adapter_input;
1228 int32_t ncb, ncb_without_null;
1229 struct bblib_turbo_adapter_ul_response adapter_resp;
1230 struct bblib_turbo_adapter_ul_request adapter_req;
1231 struct bblib_turbo_decoder_request turbo_req;
1232 struct bblib_turbo_decoder_response turbo_resp;
1233 struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
1234 #ifdef RTE_BBDEV_OFFLOAD_COST
1235 uint64_t start_time;
1237 RTE_SET_USED(q_stats);
1240 k_idx = compute_idx(k);
1242 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1243 ret = is_dec_input_valid(k_idx, kw, in_length);
1245 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1250 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
1252 ncb_without_null = (k + 4) * 3;
1254 if (check_bit(dec->op_flags, RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE)) {
1255 struct bblib_deinterleave_ul_request deint_req;
1256 struct bblib_deinterleave_ul_response deint_resp;
1258 deint_req.circ_buffer = BBLIB_FULL_CIRCULAR_BUFFER;
1259 deint_req.pharqbuffer = in;
1260 deint_req.ncb = ncb;
1261 deint_resp.pinteleavebuffer = q->deint_output;
1263 #ifdef RTE_BBDEV_OFFLOAD_COST
1264 start_time = rte_rdtsc_precise();
1266 /* Sub-block De-Interleaving */
1267 bblib_deinterleave_ul(&deint_req, &deint_resp);
1268 #ifdef RTE_BBDEV_OFFLOAD_COST
1269 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1272 move_padding_bytes(in, q->deint_output, k, ncb);
1274 adapter_input = q->deint_output;
1276 if (dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN)
1277 adapter_req.isinverted = 1;
1278 else if (dec->op_flags & RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)
1279 adapter_req.isinverted = 0;
1281 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
1282 rte_bbdev_log(ERR, "LLR format wasn't specified");
1286 adapter_req.ncb = ncb_without_null;
1287 adapter_req.pinteleavebuffer = adapter_input;
1288 adapter_resp.pharqout = q->adapter_output;
1290 #ifdef RTE_BBDEV_OFFLOAD_COST
1291 start_time = rte_rdtsc_precise();
1293 /* Turbo decode adaptation */
1294 bblib_turbo_adapter_ul(&adapter_req, &adapter_resp);
1295 #ifdef RTE_BBDEV_OFFLOAD_COST
1296 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1299 out = (uint8_t *)mbuf_append(m_out_head, m_out,
1300 ((k - crc24_overlap) >> 3));
1302 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1303 rte_bbdev_log(ERR, "Too little space in output mbuf");
1306 /* rte_bbdev_op_data.offset can be different than the offset of the
1309 out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
1311 turbo_req.c = c + 1;
1314 turbo_req.input = (int8_t *)q->adapter_output;
1316 turbo_req.k_idx = k_idx;
1317 turbo_req.max_iter_num = dec->iter_max;
1318 turbo_req.early_term_disable = !check_bit(dec->op_flags,
1319 RTE_BBDEV_TURBO_EARLY_TERMINATION);
1320 turbo_resp.ag_buf = q->ag;
1321 turbo_resp.cb_buf = q->code_block;
1322 turbo_resp.output = out;
1324 #ifdef RTE_BBDEV_OFFLOAD_COST
1325 start_time = rte_rdtsc_precise();
1328 iter_cnt = bblib_turbo_decoder(&turbo_req, &turbo_resp);
1329 #ifdef RTE_BBDEV_OFFLOAD_COST
1330 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1332 dec->hard_output.length += (k >> 3);
1335 /* Temporary solution for returned iter_count from SDK */
1336 iter_cnt = (iter_cnt - 1) >> 1;
1337 dec->iter_count = RTE_MAX(iter_cnt, dec->iter_count);
1339 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1340 rte_bbdev_log(ERR, "Turbo Decoder failed");
1350 RTE_SET_USED(m_out_head);
1351 RTE_SET_USED(m_out);
1352 RTE_SET_USED(in_offset);
1353 RTE_SET_USED(out_offset);
1354 RTE_SET_USED(check_crc_24b);
1355 RTE_SET_USED(crc24_overlap);
1356 RTE_SET_USED(in_length);
1357 RTE_SET_USED(q_stats);
1362 process_ldpc_dec_cb(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1363 uint8_t c, uint16_t out_length, uint32_t e,
1364 struct rte_mbuf *m_in,
1365 struct rte_mbuf *m_out_head, struct rte_mbuf *m_out,
1366 struct rte_mbuf *m_harq_in,
1367 struct rte_mbuf *m_harq_out_head, struct rte_mbuf *m_harq_out,
1368 uint16_t in_offset, uint16_t out_offset,
1369 uint16_t harq_in_offset, uint16_t harq_out_offset,
1371 uint16_t crc24_overlap, uint16_t in_length,
1372 struct rte_bbdev_stats *q_stats)
1374 #ifdef RTE_BBDEV_SDK_AVX512
1375 RTE_SET_USED(in_length);
1377 uint8_t *in, *out, *harq_in, *harq_out, *adapter_input;
1378 struct bblib_rate_dematching_5gnr_request derm_req;
1379 struct bblib_rate_dematching_5gnr_response derm_resp;
1380 struct bblib_ldpc_decoder_5gnr_request dec_req;
1381 struct bblib_ldpc_decoder_5gnr_response dec_resp;
1382 struct bblib_crc_request crc_req;
1383 struct bblib_crc_response crc_resp;
1384 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1385 uint16_t K, parity_offset, sys_cols, outLenWithCrc;
1386 int16_t deRmOutSize, numRows;
1388 /* Compute some LDPC BG lengths */
1389 outLenWithCrc = out_length + (crc24_overlap >> 3);
1390 sys_cols = (dec->basegraph == 1) ? 22 : 10;
1391 K = sys_cols * dec->z_c;
1392 parity_offset = K - 2 * dec->z_c;
1394 #ifdef RTE_BBDEV_OFFLOAD_COST
1395 uint64_t start_time = rte_rdtsc_precise();
1397 RTE_SET_USED(q_stats);
1400 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
1402 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1404 * Single contiguous block from the first LLR of the
1408 if (m_harq_in != NULL)
1409 harq_in = rte_pktmbuf_mtod_offset(m_harq_in,
1410 uint8_t *, harq_in_offset);
1411 if (harq_in == NULL) {
1412 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1413 rte_bbdev_log(ERR, "No space in harq input mbuf");
1416 uint16_t harq_in_length = RTE_MIN(
1417 dec->harq_combined_input.length,
1418 (uint32_t) dec->n_cb);
1419 memset(q->ag + harq_in_length, 0,
1420 dec->n_cb - harq_in_length);
1421 rte_memcpy(q->ag, harq_in, harq_in_length);
1424 derm_req.p_in = (int8_t *) in;
1425 derm_req.p_harq = q->ag; /* This doesn't include the filler bits */
1426 derm_req.base_graph = dec->basegraph;
1427 derm_req.zc = dec->z_c;
1428 derm_req.ncb = dec->n_cb;
1430 derm_req.k0 = 0; /* Actual output from SDK */
1431 derm_req.isretx = check_bit(dec->op_flags,
1432 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
1433 derm_req.rvid = dec->rv_index;
1434 derm_req.modulation_order = dec->q_m;
1435 derm_req.start_null_index = parity_offset - dec->n_filler;
1436 derm_req.num_of_null = dec->n_filler;
1438 bblib_rate_dematching_5gnr(&derm_req, &derm_resp);
1440 /* Compute RM out size and number of rows */
1441 deRmOutSize = RTE_MIN(
1442 derm_req.k0 + derm_req.e -
1443 ((derm_req.k0 < derm_req.start_null_index) ?
1445 dec->n_cb - dec->n_filler);
1446 if (m_harq_in != NULL)
1447 deRmOutSize = RTE_MAX(deRmOutSize,
1448 RTE_MIN(dec->n_cb - dec->n_filler,
1449 m_harq_in->data_len));
1450 numRows = ((deRmOutSize + dec->n_filler + dec->z_c - 1) / dec->z_c)
1452 numRows = RTE_MAX(4, numRows);
1454 /* get output data starting address */
1455 out = (uint8_t *)mbuf_append(m_out_head, m_out, out_length);
1457 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1459 "Too little space in LDPC decoder output mbuf");
1463 /* rte_bbdev_op_data.offset can be different than the offset
1464 * of the appended bytes
1466 out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
1467 adapter_input = q->enc_out;
1469 dec_req.Zc = dec->z_c;
1470 dec_req.baseGraph = dec->basegraph;
1471 dec_req.nRows = numRows;
1472 dec_req.numChannelLlrs = deRmOutSize;
1473 dec_req.varNodes = derm_req.p_harq;
1474 dec_req.numFillerBits = dec->n_filler;
1475 dec_req.maxIterations = dec->iter_max;
1476 dec_req.enableEarlyTermination = check_bit(dec->op_flags,
1477 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
1478 dec_resp.varNodes = (int16_t *) q->adapter_output;
1479 dec_resp.compactedMessageBytes = q->enc_out;
1481 bblib_ldpc_decoder_5gnr(&dec_req, &dec_resp);
1483 dec->iter_count = RTE_MAX(dec_resp.iterationAtTermination,
1485 if (!dec_resp.parityPassedAtTermination)
1486 op->status |= 1 << RTE_BBDEV_SYNDROME_ERROR;
1488 bblib_bit_reverse((int8_t *) q->enc_out, outLenWithCrc << 3);
1490 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK) ||
1491 check_bit(dec->op_flags,
1492 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK)) {
1493 crc_req.data = adapter_input;
1494 crc_req.len = K - dec->n_filler - 24;
1495 crc_resp.check_passed = false;
1496 crc_resp.data = adapter_input;
1498 bblib_lte_crc24b_check(&crc_req, &crc_resp);
1500 bblib_lte_crc24a_check(&crc_req, &crc_resp);
1501 if (!crc_resp.check_passed)
1502 op->status |= 1 << RTE_BBDEV_CRC_ERROR;
1503 } else if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK)) {
1504 crc_req.data = adapter_input;
1505 crc_req.len = K - dec->n_filler - 16;
1506 crc_resp.check_passed = false;
1507 crc_resp.data = adapter_input;
1508 bblib_lte_crc16_check(&crc_req, &crc_resp);
1509 if (!crc_resp.check_passed)
1510 op->status |= 1 << RTE_BBDEV_CRC_ERROR;
1513 #ifdef RTE_BBDEV_OFFLOAD_COST
1514 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1516 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
1518 if (m_harq_out != NULL) {
1519 /* Initialize HARQ data length since we overwrite */
1520 m_harq_out->data_len = 0;
1521 /* Check there is enough space
1522 * in the HARQ outbound buffer
1524 harq_out = (uint8_t *)mbuf_append(m_harq_out_head,
1525 m_harq_out, deRmOutSize);
1527 if (harq_out == NULL) {
1528 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1529 rte_bbdev_log(ERR, "No space in HARQ output mbuf");
1532 /* get output data starting address and overwrite the data */
1533 harq_out = rte_pktmbuf_mtod_offset(m_harq_out, uint8_t *,
1535 rte_memcpy(harq_out, derm_req.p_harq, deRmOutSize);
1536 dec->harq_combined_output.length += deRmOutSize;
1539 rte_memcpy(out, adapter_input, out_length);
1540 dec->hard_output.length += out_length;
1545 RTE_SET_USED(out_length);
1548 RTE_SET_USED(m_out_head);
1549 RTE_SET_USED(m_out);
1550 RTE_SET_USED(m_harq_in);
1551 RTE_SET_USED(m_harq_out_head);
1552 RTE_SET_USED(m_harq_out);
1553 RTE_SET_USED(harq_in_offset);
1554 RTE_SET_USED(harq_out_offset);
1555 RTE_SET_USED(in_offset);
1556 RTE_SET_USED(out_offset);
1557 RTE_SET_USED(check_crc_24b);
1558 RTE_SET_USED(crc24_overlap);
1559 RTE_SET_USED(in_length);
1560 RTE_SET_USED(q_stats);
1566 enqueue_dec_one_op(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1567 struct rte_bbdev_stats *queue_stats)
1571 uint16_t crc24_overlap = 0;
1572 struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
1573 struct rte_mbuf *m_in = dec->input.data;
1574 struct rte_mbuf *m_out = dec->hard_output.data;
1575 struct rte_mbuf *m_out_head = dec->hard_output.data;
1576 uint16_t in_offset = dec->input.offset;
1577 uint16_t out_offset = dec->hard_output.offset;
1578 uint32_t mbuf_total_left = dec->input.length;
1579 uint16_t seg_total_left;
1581 /* Clear op status */
1584 if (m_in == NULL || m_out == NULL) {
1585 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1586 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1590 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1591 c = dec->tb_params.c;
1592 } else { /* For Code Block mode */
1593 k = dec->cb_params.k;
1597 if ((c > 1) && !check_bit(dec->op_flags,
1598 RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP))
1601 while (mbuf_total_left > 0) {
1602 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1603 k = (r < dec->tb_params.c_neg) ?
1604 dec->tb_params.k_neg : dec->tb_params.k_pos;
1606 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1608 /* Calculates circular buffer size (Kw).
1609 * According to 3gpp 36.212 section 5.1.4.2
1613 * where nCol is 32 and nRow can be calculated from:
1615 * where D is the size of each output from turbo encoder block
1618 kw = RTE_ALIGN_CEIL(k + 4, RTE_BBDEV_TURBO_C_SUBBLOCK) * 3;
1620 process_dec_cb(q, op, c, k, kw, m_in, m_out_head, m_out,
1621 in_offset, out_offset, check_bit(dec->op_flags,
1622 RTE_BBDEV_TURBO_CRC_TYPE_24B), crc24_overlap,
1623 seg_total_left, queue_stats);
1625 /* To keep CRC24 attached to end of Code block, use
1626 * RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP flag as it
1627 * removed by default once verified.
1630 mbuf_total_left -= kw;
1632 /* Update offsets */
1633 if (seg_total_left == kw) {
1634 /* Go to the next mbuf */
1636 m_out = m_out->next;
1640 /* Update offsets for next CBs (if exist) */
1642 out_offset += ((k - crc24_overlap) >> 3);
1649 enqueue_ldpc_dec_one_op(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1650 struct rte_bbdev_stats *queue_stats)
1654 uint16_t out_length, crc24_overlap = 0;
1655 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1656 struct rte_mbuf *m_in = dec->input.data;
1657 struct rte_mbuf *m_harq_in = dec->harq_combined_input.data;
1658 struct rte_mbuf *m_harq_out = dec->harq_combined_output.data;
1659 struct rte_mbuf *m_harq_out_head = dec->harq_combined_output.data;
1660 struct rte_mbuf *m_out = dec->hard_output.data;
1661 struct rte_mbuf *m_out_head = dec->hard_output.data;
1662 uint16_t in_offset = dec->input.offset;
1663 uint16_t harq_in_offset = dec->harq_combined_input.offset;
1664 uint16_t harq_out_offset = dec->harq_combined_output.offset;
1665 uint16_t out_offset = dec->hard_output.offset;
1666 uint32_t mbuf_total_left = dec->input.length;
1667 uint16_t seg_total_left;
1669 /* Clear op status */
1672 if (m_in == NULL || m_out == NULL) {
1673 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1674 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1678 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1679 c = dec->tb_params.c;
1680 e = dec->tb_params.ea;
1681 } else { /* For Code Block mode */
1683 e = dec->cb_params.e;
1686 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1689 out_length = (dec->basegraph == 1 ? 22 : 10) * dec->z_c; /* K */
1690 out_length = ((out_length - crc24_overlap - dec->n_filler) >> 3);
1692 while (mbuf_total_left > 0) {
1693 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1694 e = (r < dec->tb_params.cab) ?
1695 dec->tb_params.ea : dec->tb_params.eb;
1696 /* Special case handling when overusing mbuf */
1697 if (e < RTE_BBDEV_LDPC_E_MAX_MBUF)
1698 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1702 process_ldpc_dec_cb(q, op, c, out_length, e,
1703 m_in, m_out_head, m_out,
1704 m_harq_in, m_harq_out_head, m_harq_out,
1705 in_offset, out_offset, harq_in_offset,
1707 check_bit(dec->op_flags,
1708 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK),
1710 seg_total_left, queue_stats);
1712 /* To keep CRC24 attached to end of Code block, use
1713 * RTE_BBDEV_LDPC_DEC_TB_CRC_24B_KEEP flag as it
1714 * removed by default once verified.
1717 mbuf_total_left -= e;
1719 /* Update offsets */
1720 if (seg_total_left == e) {
1721 /* Go to the next mbuf */
1723 m_out = m_out->next;
1724 if (m_harq_in != NULL)
1725 m_harq_in = m_harq_in->next;
1726 if (m_harq_out != NULL)
1727 m_harq_out = m_harq_out->next;
1731 harq_out_offset = 0;
1733 /* Update offsets for next CBs (if exist) */
1735 out_offset += out_length;
1741 static inline uint16_t
1742 enqueue_dec_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_dec_op **ops,
1743 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1746 #ifdef RTE_BBDEV_OFFLOAD_COST
1747 queue_stats->acc_offload_cycles = 0;
1750 for (i = 0; i < nb_ops; ++i)
1751 enqueue_dec_one_op(q, ops[i], queue_stats);
1753 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1757 static inline uint16_t
1758 enqueue_ldpc_dec_all_ops(struct turbo_sw_queue *q,
1759 struct rte_bbdev_dec_op **ops,
1760 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1763 #ifdef RTE_BBDEV_OFFLOAD_COST
1764 queue_stats->acc_offload_cycles = 0;
1767 for (i = 0; i < nb_ops; ++i)
1768 enqueue_ldpc_dec_one_op(q, ops[i], queue_stats);
1770 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1776 enqueue_enc_ops(struct rte_bbdev_queue_data *q_data,
1777 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1779 void *queue = q_data->queue_private;
1780 struct turbo_sw_queue *q = queue;
1781 uint16_t nb_enqueued = 0;
1783 nb_enqueued = enqueue_enc_all_ops(q, ops, nb_ops, &q_data->queue_stats);
1785 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1786 q_data->queue_stats.enqueued_count += nb_enqueued;
1793 enqueue_ldpc_enc_ops(struct rte_bbdev_queue_data *q_data,
1794 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1796 void *queue = q_data->queue_private;
1797 struct turbo_sw_queue *q = queue;
1798 uint16_t nb_enqueued = 0;
1800 nb_enqueued = enqueue_ldpc_enc_all_ops(
1801 q, ops, nb_ops, &q_data->queue_stats);
1803 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1804 q_data->queue_stats.enqueued_count += nb_enqueued;
1811 enqueue_dec_ops(struct rte_bbdev_queue_data *q_data,
1812 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1814 void *queue = q_data->queue_private;
1815 struct turbo_sw_queue *q = queue;
1816 uint16_t nb_enqueued = 0;
1818 nb_enqueued = enqueue_dec_all_ops(q, ops, nb_ops, &q_data->queue_stats);
1820 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1821 q_data->queue_stats.enqueued_count += nb_enqueued;
1828 enqueue_ldpc_dec_ops(struct rte_bbdev_queue_data *q_data,
1829 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1831 void *queue = q_data->queue_private;
1832 struct turbo_sw_queue *q = queue;
1833 uint16_t nb_enqueued = 0;
1835 nb_enqueued = enqueue_ldpc_dec_all_ops(q, ops, nb_ops,
1836 &q_data->queue_stats);
1838 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1839 q_data->queue_stats.enqueued_count += nb_enqueued;
1844 /* Dequeue decode burst */
1846 dequeue_dec_ops(struct rte_bbdev_queue_data *q_data,
1847 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1849 struct turbo_sw_queue *q = q_data->queue_private;
1850 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1851 (void **)ops, nb_ops, NULL);
1852 q_data->queue_stats.dequeued_count += nb_dequeued;
1857 /* Dequeue encode burst */
1859 dequeue_enc_ops(struct rte_bbdev_queue_data *q_data,
1860 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1862 struct turbo_sw_queue *q = q_data->queue_private;
1863 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1864 (void **)ops, nb_ops, NULL);
1865 q_data->queue_stats.dequeued_count += nb_dequeued;
1870 /* Parse 16bit integer from string argument */
1872 parse_u16_arg(const char *key, const char *value, void *extra_args)
1874 uint16_t *u16 = extra_args;
1875 unsigned int long result;
1877 if ((value == NULL) || (extra_args == NULL))
1880 result = strtoul(value, NULL, 0);
1881 if ((result >= (1 << 16)) || (errno != 0)) {
1882 rte_bbdev_log(ERR, "Invalid value %lu for %s", result, key);
1885 *u16 = (uint16_t)result;
1889 /* Parse parameters used to create device */
1891 parse_turbo_sw_params(struct turbo_sw_params *params, const char *input_args)
1893 struct rte_kvargs *kvlist = NULL;
1899 kvlist = rte_kvargs_parse(input_args, turbo_sw_valid_params);
1903 ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[0],
1904 &parse_u16_arg, ¶ms->queues_num);
1908 ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[1],
1909 &parse_u16_arg, ¶ms->socket_id);
1913 if (params->socket_id >= RTE_MAX_NUMA_NODES) {
1914 rte_bbdev_log(ERR, "Invalid socket, must be < %u",
1915 RTE_MAX_NUMA_NODES);
1921 rte_kvargs_free(kvlist);
1927 turbo_sw_bbdev_create(struct rte_vdev_device *vdev,
1928 struct turbo_sw_params *init_params)
1930 struct rte_bbdev *bbdev;
1931 const char *name = rte_vdev_device_name(vdev);
1933 bbdev = rte_bbdev_allocate(name);
1937 bbdev->data->dev_private = rte_zmalloc_socket(name,
1938 sizeof(struct bbdev_private), RTE_CACHE_LINE_SIZE,
1939 init_params->socket_id);
1940 if (bbdev->data->dev_private == NULL) {
1941 rte_bbdev_release(bbdev);
1945 bbdev->dev_ops = &pmd_ops;
1946 bbdev->device = &vdev->device;
1947 bbdev->data->socket_id = init_params->socket_id;
1948 bbdev->intr_handle = NULL;
1950 /* register rx/tx burst functions for data path */
1951 bbdev->dequeue_enc_ops = dequeue_enc_ops;
1952 bbdev->dequeue_dec_ops = dequeue_dec_ops;
1953 bbdev->enqueue_enc_ops = enqueue_enc_ops;
1954 bbdev->enqueue_dec_ops = enqueue_dec_ops;
1955 bbdev->dequeue_ldpc_enc_ops = dequeue_enc_ops;
1956 bbdev->dequeue_ldpc_dec_ops = dequeue_dec_ops;
1957 bbdev->enqueue_ldpc_enc_ops = enqueue_ldpc_enc_ops;
1958 bbdev->enqueue_ldpc_dec_ops = enqueue_ldpc_dec_ops;
1959 ((struct bbdev_private *) bbdev->data->dev_private)->max_nb_queues =
1960 init_params->queues_num;
1965 /* Initialise device */
1967 turbo_sw_bbdev_probe(struct rte_vdev_device *vdev)
1969 struct turbo_sw_params init_params = {
1971 RTE_BBDEV_DEFAULT_MAX_NB_QUEUES
1974 const char *input_args;
1979 name = rte_vdev_device_name(vdev);
1982 input_args = rte_vdev_device_args(vdev);
1983 parse_turbo_sw_params(&init_params, input_args);
1985 rte_bbdev_log_debug(
1986 "Initialising %s on NUMA node %d with max queues: %d\n",
1987 name, init_params.socket_id, init_params.queues_num);
1989 return turbo_sw_bbdev_create(vdev, &init_params);
1992 /* Uninitialise device */
1994 turbo_sw_bbdev_remove(struct rte_vdev_device *vdev)
1996 struct rte_bbdev *bbdev;
2002 name = rte_vdev_device_name(vdev);
2006 bbdev = rte_bbdev_get_named_dev(name);
2010 rte_free(bbdev->data->dev_private);
2012 return rte_bbdev_release(bbdev);
2015 static struct rte_vdev_driver bbdev_turbo_sw_pmd_drv = {
2016 .probe = turbo_sw_bbdev_probe,
2017 .remove = turbo_sw_bbdev_remove
2020 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_turbo_sw_pmd_drv);
2021 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
2022 TURBO_SW_MAX_NB_QUEUES_ARG"=<int> "
2023 TURBO_SW_SOCKET_ID_ARG"=<int>");
2024 RTE_PMD_REGISTER_ALIAS(DRIVER_NAME, turbo_sw);