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 /* Accecptable 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;
257 rte_bbdev_log_debug("got device info from %u\n", dev->data->dev_id);
262 q_release(struct rte_bbdev *dev, uint16_t q_id)
264 struct turbo_sw_queue *q = dev->data->queues[q_id].queue_private;
267 rte_ring_free(q->processed_pkts);
268 rte_free(q->enc_out);
271 rte_free(q->code_block);
272 rte_free(q->deint_input);
273 rte_free(q->deint_output);
274 rte_free(q->adapter_output);
276 dev->data->queues[q_id].queue_private = NULL;
279 rte_bbdev_log_debug("released device queue %u:%u",
280 dev->data->dev_id, q_id);
286 q_setup(struct rte_bbdev *dev, uint16_t q_id,
287 const struct rte_bbdev_queue_conf *queue_conf)
290 struct turbo_sw_queue *q;
291 char name[RTE_RING_NAMESIZE];
293 /* Allocate the queue data structure. */
294 q = rte_zmalloc_socket(RTE_STR(DRIVER_NAME), sizeof(*q),
295 RTE_CACHE_LINE_SIZE, queue_conf->socket);
297 rte_bbdev_log(ERR, "Failed to allocate queue memory");
301 /* Allocate memory for encoder output. */
302 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_enc_o%u:%u",
303 dev->data->dev_id, q_id);
304 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
306 "Creating queue name for device %u queue %u failed",
307 dev->data->dev_id, q_id);
311 q->enc_out = rte_zmalloc_socket(name,
312 ((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) *
313 sizeof(*q->enc_out) * 3,
314 RTE_CACHE_LINE_SIZE, queue_conf->socket);
315 if (q->enc_out == NULL) {
317 "Failed to allocate queue memory for %s", name);
322 /* Allocate memory for rate matching output. */
323 ret = snprintf(name, RTE_RING_NAMESIZE,
324 RTE_STR(DRIVER_NAME)"_enc_i%u:%u", dev->data->dev_id,
326 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
328 "Creating queue name for device %u queue %u failed",
329 dev->data->dev_id, q_id);
333 q->enc_in = rte_zmalloc_socket(name,
334 (RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q->enc_in),
335 RTE_CACHE_LINE_SIZE, queue_conf->socket);
336 if (q->enc_in == NULL) {
338 "Failed to allocate queue memory for %s", name);
343 /* Allocate memory for Alpha Gamma temp buffer. */
344 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_ag%u:%u",
345 dev->data->dev_id, q_id);
346 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
348 "Creating queue name for device %u queue %u failed",
349 dev->data->dev_id, q_id);
353 q->ag = rte_zmalloc_socket(name,
354 RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q->ag),
355 RTE_CACHE_LINE_SIZE, queue_conf->socket);
358 "Failed to allocate queue memory for %s", name);
363 /* Allocate memory for code block temp buffer. */
364 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_cb%u:%u",
365 dev->data->dev_id, q_id);
366 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
368 "Creating queue name for device %u queue %u failed",
369 dev->data->dev_id, q_id);
373 q->code_block = rte_zmalloc_socket(name,
374 RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q->code_block),
375 RTE_CACHE_LINE_SIZE, queue_conf->socket);
376 if (q->code_block == NULL) {
378 "Failed to allocate queue memory for %s", name);
383 /* Allocate memory for Deinterleaver input. */
384 ret = snprintf(name, RTE_RING_NAMESIZE,
385 RTE_STR(DRIVER_NAME)"_de_i%u:%u",
386 dev->data->dev_id, q_id);
387 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
389 "Creating queue name for device %u queue %u failed",
390 dev->data->dev_id, q_id);
394 q->deint_input = rte_zmalloc_socket(name,
395 DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input),
396 RTE_CACHE_LINE_SIZE, queue_conf->socket);
397 if (q->deint_input == NULL) {
399 "Failed to allocate queue memory for %s", name);
404 /* Allocate memory for Deinterleaver output. */
405 ret = snprintf(name, RTE_RING_NAMESIZE,
406 RTE_STR(DRIVER_NAME)"_de_o%u:%u",
407 dev->data->dev_id, q_id);
408 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
410 "Creating queue name for device %u queue %u failed",
411 dev->data->dev_id, q_id);
415 q->deint_output = rte_zmalloc_socket(NULL,
416 DEINT_OUTPUT_BUF_SIZE * sizeof(*q->deint_output),
417 RTE_CACHE_LINE_SIZE, queue_conf->socket);
418 if (q->deint_output == NULL) {
420 "Failed to allocate queue memory for %s", name);
425 /* Allocate memory for Adapter output. */
426 ret = snprintf(name, RTE_RING_NAMESIZE,
427 RTE_STR(DRIVER_NAME)"_ada_o%u:%u",
428 dev->data->dev_id, q_id);
429 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
431 "Creating queue name for device %u queue %u failed",
432 dev->data->dev_id, q_id);
436 q->adapter_output = rte_zmalloc_socket(NULL,
437 ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q->adapter_output),
438 RTE_CACHE_LINE_SIZE, queue_conf->socket);
439 if (q->adapter_output == NULL) {
441 "Failed to allocate queue memory for %s", name);
446 /* Create ring for packets awaiting to be dequeued. */
447 ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"%u:%u",
448 dev->data->dev_id, q_id);
449 if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
451 "Creating queue name for device %u queue %u failed",
452 dev->data->dev_id, q_id);
456 q->processed_pkts = rte_ring_create(name, queue_conf->queue_size,
457 queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
458 if (q->processed_pkts == NULL) {
459 rte_bbdev_log(ERR, "Failed to create ring for %s", name);
464 q->type = queue_conf->op_type;
466 dev->data->queues[q_id].queue_private = q;
467 rte_bbdev_log_debug("setup device queue %s", name);
471 rte_ring_free(q->processed_pkts);
472 rte_free(q->enc_out);
475 rte_free(q->code_block);
476 rte_free(q->deint_input);
477 rte_free(q->deint_output);
478 rte_free(q->adapter_output);
483 static const struct rte_bbdev_ops pmd_ops = {
484 .info_get = info_get,
485 .queue_setup = q_setup,
486 .queue_release = q_release
489 #ifdef RTE_BBDEV_SDK_AVX2
490 #ifdef RTE_LIBRTE_BBDEV_DEBUG
491 /* Checks if the encoder input buffer is correct.
492 * Returns 0 if it's valid, -1 otherwise.
495 is_enc_input_valid(const uint16_t k, const int32_t k_idx,
496 const uint16_t in_length)
499 rte_bbdev_log(ERR, "K Index is invalid");
503 if (in_length - (k >> 3) < 0) {
505 "Mismatch between input length (%u bytes) and K (%u bits)",
510 if (k > RTE_BBDEV_TURBO_MAX_CB_SIZE) {
511 rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
512 k, RTE_BBDEV_TURBO_MAX_CB_SIZE);
519 /* Checks if the decoder input buffer is correct.
520 * Returns 0 if it's valid, -1 otherwise.
523 is_dec_input_valid(int32_t k_idx, int16_t kw, int16_t in_length)
526 rte_bbdev_log(ERR, "K index is invalid");
530 if (in_length < kw) {
532 "Mismatch between input length (%u) and kw (%u)",
537 if (kw > RTE_BBDEV_TURBO_MAX_KW) {
538 rte_bbdev_log(ERR, "Input length (%u) is too big, max: %d",
539 kw, RTE_BBDEV_TURBO_MAX_KW);
549 process_enc_cb(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
550 uint8_t r, uint8_t c, uint16_t k, uint16_t ncb,
551 uint32_t e, struct rte_mbuf *m_in, struct rte_mbuf *m_out_head,
552 struct rte_mbuf *m_out, uint16_t in_offset, uint16_t out_offset,
553 uint16_t in_length, struct rte_bbdev_stats *q_stats)
555 #ifdef RTE_BBDEV_SDK_AVX2
556 #ifdef RTE_LIBRTE_BBDEV_DEBUG
559 RTE_SET_USED(in_length);
563 uint8_t *in, *out0, *out1, *out2, *tmp_out, *rm_out;
564 uint64_t first_3_bytes = 0;
565 struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
566 struct bblib_crc_request crc_req;
567 struct bblib_crc_response crc_resp;
568 struct bblib_turbo_encoder_request turbo_req;
569 struct bblib_turbo_encoder_response turbo_resp;
570 struct bblib_rate_match_dl_request rm_req;
571 struct bblib_rate_match_dl_response rm_resp;
572 #ifdef RTE_BBDEV_OFFLOAD_COST
575 RTE_SET_USED(q_stats);
578 k_idx = compute_idx(k);
579 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
581 /* CRC24A (for TB) */
582 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH) &&
583 (enc->code_block_mode == RTE_BBDEV_CODE_BLOCK)) {
584 #ifdef RTE_LIBRTE_BBDEV_DEBUG
585 ret = is_enc_input_valid(k - 24, k_idx, in_length);
587 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
593 crc_req.len = k - 24;
594 /* Check if there is a room for CRC bits if not use
595 * the temporary buffer.
597 if (mbuf_append(m_in, m_in, 3) == NULL) {
598 rte_memcpy(q->enc_in, in, (k - 24) >> 3);
601 /* Store 3 first bytes of next CB as they will be
602 * overwritten by CRC bytes. If it is the last CB then
603 * there is no point to store 3 next bytes and this
604 * if..else branch will be omitted.
606 first_3_bytes = *((uint64_t *)&in[(k - 32) >> 3]);
610 #ifdef RTE_BBDEV_OFFLOAD_COST
611 start_time = rte_rdtsc_precise();
613 /* CRC24A generation */
614 bblib_lte_crc24a_gen(&crc_req, &crc_resp);
615 #ifdef RTE_BBDEV_OFFLOAD_COST
616 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
618 } else if (enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) {
620 #ifdef RTE_LIBRTE_BBDEV_DEBUG
621 ret = is_enc_input_valid(k - 24, k_idx, in_length);
623 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
629 crc_req.len = k - 24;
630 /* Check if there is a room for CRC bits if this is the last
631 * CB in TB. If not use temporary buffer.
633 if ((c - r == 1) && (mbuf_append(m_in, m_in, 3) == NULL)) {
634 rte_memcpy(q->enc_in, in, (k - 24) >> 3);
636 } else if (c - r > 1) {
637 /* Store 3 first bytes of next CB as they will be
638 * overwritten by CRC bytes. If it is the last CB then
639 * there is no point to store 3 next bytes and this
640 * if..else branch will be omitted.
642 first_3_bytes = *((uint64_t *)&in[(k - 32) >> 3]);
646 #ifdef RTE_BBDEV_OFFLOAD_COST
647 start_time = rte_rdtsc_precise();
649 /* CRC24B generation */
650 bblib_lte_crc24b_gen(&crc_req, &crc_resp);
651 #ifdef RTE_BBDEV_OFFLOAD_COST
652 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
655 #ifdef RTE_LIBRTE_BBDEV_DEBUG
657 ret = is_enc_input_valid(k, k_idx, in_length);
659 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
667 /* Each bit layer output from turbo encoder is (k+4) bits long, i.e.
668 * input length + 4 tail bits. That's (k/8) + 1 bytes after rounding up.
669 * So dst_data's length should be 3*(k/8) + 3 bytes.
670 * In Rate-matching bypass case outputs pointers passed to encoder
671 * (out0, out1 and out2) can directly point to addresses of output from
674 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH) {
676 out1 = RTE_PTR_ADD(out0, (k >> 3) + 1);
677 out2 = RTE_PTR_ADD(out1, (k >> 3) + 1);
679 out0 = (uint8_t *)mbuf_append(m_out_head, m_out,
682 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
684 "Too little space in output mbuf");
687 enc->output.length += (k >> 3) * 3 + 2;
688 /* rte_bbdev_op_data.offset can be different than the
689 * offset of the appended bytes
691 out0 = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
692 out1 = rte_pktmbuf_mtod_offset(m_out, uint8_t *,
693 out_offset + (k >> 3) + 1);
694 out2 = rte_pktmbuf_mtod_offset(m_out, uint8_t *,
695 out_offset + 2 * ((k >> 3) + 1));
698 turbo_req.case_id = k_idx;
699 turbo_req.input_win = in;
700 turbo_req.length = k >> 3;
701 turbo_resp.output_win_0 = out0;
702 turbo_resp.output_win_1 = out1;
703 turbo_resp.output_win_2 = out2;
705 #ifdef RTE_BBDEV_OFFLOAD_COST
706 start_time = rte_rdtsc_precise();
709 if (bblib_turbo_encoder(&turbo_req, &turbo_resp) != 0) {
710 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
711 rte_bbdev_log(ERR, "Turbo Encoder failed");
714 #ifdef RTE_BBDEV_OFFLOAD_COST
715 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
718 /* Restore 3 first bytes of next CB if they were overwritten by CRC*/
719 if (first_3_bytes != 0)
720 *((uint64_t *)&in[(k - 32) >> 3]) = first_3_bytes;
723 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH) {
725 /* Integer round up division by 8 */
726 uint16_t out_len = (e + 7) >> 3;
727 /* The mask array is indexed using E%8. E is an even number so
728 * there are only 4 possible values.
730 const uint8_t mask_out[] = {0xFF, 0xC0, 0xF0, 0xFC};
732 /* get output data starting address */
733 rm_out = (uint8_t *)mbuf_append(m_out_head, m_out, out_len);
734 if (rm_out == NULL) {
735 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
737 "Too little space in output mbuf");
740 /* rte_bbdev_op_data.offset can be different than the offset
741 * of the appended bytes
743 rm_out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
745 /* index of current code block */
747 /* total number of code block */
749 /* For DL - 1, UL - 0 */
750 rm_req.direction = 1;
751 /* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nsoft, KMIMO
752 * and MDL_HARQ are used for Ncb calculation. As Ncb is already
753 * known we can adjust those parameters
755 rm_req.Nsoft = ncb * rm_req.C;
758 /* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nl, Qm and G
759 * are used for E calculation. As E is already known we can
760 * adjust those parameters
764 rm_req.G = rm_req.NL * rm_req.Qm * rm_req.C;
766 rm_req.rvidx = enc->rv_index;
767 rm_req.Kidx = k_idx - 1;
772 rm_resp.output = rm_out;
773 rm_resp.OutputLen = out_len;
774 if (enc->op_flags & RTE_BBDEV_TURBO_RV_INDEX_BYPASS)
775 rm_req.bypass_rvidx = 1;
777 rm_req.bypass_rvidx = 0;
779 #ifdef RTE_BBDEV_OFFLOAD_COST
780 start_time = rte_rdtsc_precise();
783 if (bblib_rate_match_dl(&rm_req, &rm_resp) != 0) {
784 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
785 rte_bbdev_log(ERR, "Rate matching failed");
788 #ifdef RTE_BBDEV_OFFLOAD_COST
789 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
792 /* SW fills an entire last byte even if E%8 != 0. Clear the
793 * superfluous data bits for consistency with HW device.
795 mask_id = (e & 7) >> 1;
796 rm_out[out_len - 1] &= mask_out[mask_id];
797 enc->output.length += rm_resp.OutputLen;
799 /* Rate matching is bypassed */
801 /* Completing last byte of out0 (where 4 tail bits are stored)
802 * by moving first 4 bits from out1
804 tmp_out = (uint8_t *) --out1;
805 *tmp_out = *tmp_out | ((*(tmp_out + 1) & 0xF0) >> 4);
807 /* Shifting out1 data by 4 bits to the left */
808 for (m = 0; m < k >> 3; ++m) {
809 uint8_t *first = tmp_out;
810 uint8_t second = *(tmp_out + 1);
811 *first = (*first << 4) | ((second & 0xF0) >> 4);
814 /* Shifting out2 data by 8 bits to the left */
815 for (m = 0; m < (k >> 3) + 1; ++m) {
816 *tmp_out = *(tmp_out + 1);
830 RTE_SET_USED(m_out_head);
832 RTE_SET_USED(in_offset);
833 RTE_SET_USED(out_offset);
834 RTE_SET_USED(in_length);
835 RTE_SET_USED(q_stats);
841 process_ldpc_enc_cb(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
842 uint32_t e, struct rte_mbuf *m_in, struct rte_mbuf *m_out_head,
843 struct rte_mbuf *m_out, uint16_t in_offset, uint16_t out_offset,
844 uint16_t seg_total_left, struct rte_bbdev_stats *q_stats)
846 #ifdef RTE_BBDEV_SDK_AVX512
847 RTE_SET_USED(seg_total_left);
848 uint8_t *in, *rm_out;
849 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
850 struct bblib_ldpc_encoder_5gnr_request ldpc_req;
851 struct bblib_ldpc_encoder_5gnr_response ldpc_resp;
852 struct bblib_LDPC_ratematch_5gnr_request rm_req;
853 struct bblib_LDPC_ratematch_5gnr_response rm_resp;
854 struct bblib_crc_request crc_req;
855 struct bblib_crc_response crc_resp;
856 uint16_t msgLen, puntBits, parity_offset, out_len;
857 uint16_t K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
858 uint16_t in_length_in_bits = K - enc->n_filler;
859 uint16_t in_length_in_bytes = (in_length_in_bits + 7) >> 3;
861 #ifdef RTE_BBDEV_OFFLOAD_COST
862 uint64_t start_time = rte_rdtsc_precise();
864 RTE_SET_USED(q_stats);
867 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
869 /* Masking the Filler bits explicitly */
870 memset(q->enc_in + (in_length_in_bytes - 3), 0,
871 ((K + 7) >> 3) - (in_length_in_bytes - 3));
873 if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24A_ATTACH) {
874 rte_memcpy(q->enc_in, in, in_length_in_bytes - 3);
876 crc_req.len = in_length_in_bits - 24;
877 crc_resp.data = q->enc_in;
878 bblib_lte_crc24a_gen(&crc_req, &crc_resp);
879 } else if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH) {
880 rte_memcpy(q->enc_in, in, in_length_in_bytes - 3);
882 crc_req.len = in_length_in_bits - 24;
883 crc_resp.data = q->enc_in;
884 bblib_lte_crc24b_gen(&crc_req, &crc_resp);
885 } else if (enc->op_flags & RTE_BBDEV_LDPC_CRC_16_ATTACH) {
886 rte_memcpy(q->enc_in, in, in_length_in_bytes - 2);
888 crc_req.len = in_length_in_bits - 16;
889 crc_resp.data = q->enc_in;
890 bblib_lte_crc16_gen(&crc_req, &crc_resp);
892 rte_memcpy(q->enc_in, in, in_length_in_bytes);
895 ldpc_req.Zc = enc->z_c;
896 ldpc_req.baseGraph = enc->basegraph;
897 /* Number of rows set to maximum */
898 ldpc_req.nRows = ldpc_req.baseGraph == 1 ? 46 : 42;
899 ldpc_req.numberCodeblocks = 1;
900 ldpc_req.input[0] = (int8_t *) q->enc_in;
901 ldpc_resp.output[0] = (int8_t *) q->enc_out;
903 bblib_bit_reverse(ldpc_req.input[0], in_length_in_bytes << 3);
905 if (bblib_ldpc_encoder_5gnr(&ldpc_req, &ldpc_resp) != 0) {
906 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
907 rte_bbdev_log(ERR, "LDPC Encoder failed");
912 * Systematic + Parity : Recreating stream with filler bits, ideally
913 * the bit select could handle this in the RM SDK
915 msgLen = (ldpc_req.baseGraph == 1 ? 22 : 10) * ldpc_req.Zc;
916 puntBits = 2 * ldpc_req.Zc;
917 parity_offset = msgLen - puntBits;
918 ippsCopyBE_1u(((uint8_t *) ldpc_req.input[0]) + (puntBits / 8),
919 puntBits%8, q->adapter_output, 0, parity_offset);
920 ippsCopyBE_1u(q->enc_out, 0, q->adapter_output + (parity_offset / 8),
921 parity_offset % 8, ldpc_req.nRows * ldpc_req.Zc);
923 out_len = (e + 7) >> 3;
924 /* get output data starting address */
925 rm_out = (uint8_t *)mbuf_append(m_out_head, m_out, out_len);
926 if (rm_out == NULL) {
927 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
929 "Too little space in output mbuf");
933 * rte_bbdev_op_data.offset can be different than the offset
934 * of the appended bytes
936 rm_out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
940 rm_req.Ncb = enc->n_cb;
941 rm_req.Qm = enc->q_m;
942 rm_req.Zc = enc->z_c;
943 rm_req.baseGraph = enc->basegraph;
944 rm_req.input = q->adapter_output;
945 rm_req.nLen = enc->n_filler;
946 rm_req.nullIndex = parity_offset - enc->n_filler;
947 rm_req.rvidx = enc->rv_index;
948 rm_resp.output = q->deint_output;
950 if (bblib_LDPC_ratematch_5gnr(&rm_req, &rm_resp) != 0) {
951 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
952 rte_bbdev_log(ERR, "Rate matching failed");
956 /* RM SDK may provide non zero bits on last byte */
958 q->deint_output[out_len-1] &= (1 << (e % 8)) - 1;
960 bblib_bit_reverse((int8_t *) q->deint_output, out_len << 3);
962 rte_memcpy(rm_out, q->deint_output, out_len);
963 enc->output.length += out_len;
965 #ifdef RTE_BBDEV_OFFLOAD_COST
966 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
973 RTE_SET_USED(m_out_head);
975 RTE_SET_USED(in_offset);
976 RTE_SET_USED(out_offset);
977 RTE_SET_USED(seg_total_left);
978 RTE_SET_USED(q_stats);
983 enqueue_enc_one_op(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
984 struct rte_bbdev_stats *queue_stats)
986 uint8_t c, r, crc24_bits = 0;
989 struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
990 uint16_t in_offset = enc->input.offset;
991 uint16_t out_offset = enc->output.offset;
992 struct rte_mbuf *m_in = enc->input.data;
993 struct rte_mbuf *m_out = enc->output.data;
994 struct rte_mbuf *m_out_head = enc->output.data;
995 uint32_t in_length, mbuf_total_left = enc->input.length;
996 uint16_t seg_total_left;
998 /* Clear op status */
1001 if (mbuf_total_left > RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) {
1002 rte_bbdev_log(ERR, "TB size (%u) is too big, max: %d",
1003 mbuf_total_left, RTE_BBDEV_TURBO_MAX_TB_SIZE);
1004 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1008 if (m_in == NULL || m_out == NULL) {
1009 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1010 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1014 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) ||
1015 (enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH))
1018 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1019 c = enc->tb_params.c;
1020 r = enc->tb_params.r;
1021 } else {/* For Code Block mode */
1026 while (mbuf_total_left > 0 && r < c) {
1028 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1030 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1031 k = (r < enc->tb_params.c_neg) ?
1032 enc->tb_params.k_neg : enc->tb_params.k_pos;
1033 ncb = (r < enc->tb_params.c_neg) ?
1034 enc->tb_params.ncb_neg : enc->tb_params.ncb_pos;
1035 e = (r < enc->tb_params.cab) ?
1036 enc->tb_params.ea : enc->tb_params.eb;
1038 k = enc->cb_params.k;
1039 ncb = enc->cb_params.ncb;
1040 e = enc->cb_params.e;
1043 process_enc_cb(q, op, r, c, k, ncb, e, m_in, m_out_head,
1044 m_out, in_offset, out_offset, seg_total_left,
1046 /* Update total_left */
1047 in_length = ((k - crc24_bits) >> 3);
1048 mbuf_total_left -= in_length;
1049 /* Update offsets for next CBs (if exist) */
1050 in_offset += (k - crc24_bits) >> 3;
1051 if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH)
1052 out_offset += e >> 3;
1054 out_offset += (k >> 3) * 3 + 2;
1056 /* Update offsets */
1057 if (seg_total_left == in_length) {
1058 /* Go to the next mbuf */
1060 m_out = m_out->next;
1067 /* check if all input data was processed */
1068 if (mbuf_total_left != 0) {
1069 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1071 "Mismatch between mbuf length and included CBs sizes");
1077 enqueue_ldpc_enc_one_op(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
1078 struct rte_bbdev_stats *queue_stats)
1080 uint8_t c, r, crc24_bits = 0;
1082 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
1083 uint16_t in_offset = enc->input.offset;
1084 uint16_t out_offset = enc->output.offset;
1085 struct rte_mbuf *m_in = enc->input.data;
1086 struct rte_mbuf *m_out = enc->output.data;
1087 struct rte_mbuf *m_out_head = enc->output.data;
1088 uint32_t in_length, mbuf_total_left = enc->input.length;
1090 uint16_t seg_total_left;
1092 /* Clear op status */
1095 if (mbuf_total_left > RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) {
1096 rte_bbdev_log(ERR, "TB size (%u) is too big, max: %d",
1097 mbuf_total_left, RTE_BBDEV_TURBO_MAX_TB_SIZE);
1098 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1102 if (m_in == NULL || m_out == NULL) {
1103 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1104 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1108 if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) ||
1109 (enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH))
1112 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1113 c = enc->tb_params.c;
1114 r = enc->tb_params.r;
1115 } else { /* For Code Block mode */
1120 while (mbuf_total_left > 0 && r < c) {
1122 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1124 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1125 e = (r < enc->tb_params.cab) ?
1126 enc->tb_params.ea : enc->tb_params.eb;
1128 e = enc->cb_params.e;
1131 process_ldpc_enc_cb(q, op, e, m_in, m_out_head,
1132 m_out, in_offset, out_offset, seg_total_left,
1134 /* Update total_left */
1135 in_length = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
1136 in_length = ((in_length - crc24_bits - enc->n_filler) >> 3);
1137 mbuf_total_left -= in_length;
1138 /* Update offsets for next CBs (if exist) */
1139 in_offset += in_length;
1140 out_offset += (e + 7) >> 3;
1142 /* Update offsets */
1143 if (seg_total_left == in_length) {
1144 /* Go to the next mbuf */
1146 m_out = m_out->next;
1153 /* check if all input data was processed */
1154 if (mbuf_total_left != 0) {
1155 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1157 "Mismatch between mbuf length and included CBs sizes %d",
1162 static inline uint16_t
1163 enqueue_enc_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_enc_op **ops,
1164 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1167 #ifdef RTE_BBDEV_OFFLOAD_COST
1168 queue_stats->acc_offload_cycles = 0;
1171 for (i = 0; i < nb_ops; ++i)
1172 enqueue_enc_one_op(q, ops[i], queue_stats);
1174 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1178 static inline uint16_t
1179 enqueue_ldpc_enc_all_ops(struct turbo_sw_queue *q,
1180 struct rte_bbdev_enc_op **ops,
1181 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1184 #ifdef RTE_BBDEV_OFFLOAD_COST
1185 queue_stats->acc_offload_cycles = 0;
1188 for (i = 0; i < nb_ops; ++i)
1189 enqueue_ldpc_enc_one_op(q, ops[i], queue_stats);
1191 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1195 #ifdef RTE_BBDEV_SDK_AVX2
1197 move_padding_bytes(const uint8_t *in, uint8_t *out, uint16_t k,
1201 uint16_t kpi = ncb / 3;
1202 uint16_t nd = kpi - d;
1204 rte_memcpy(&out[nd], in, d);
1205 rte_memcpy(&out[nd + kpi + 64], &in[kpi], d);
1206 rte_memcpy(&out[(nd - 1) + 2 * (kpi + 64)], &in[2 * kpi], d);
1211 process_dec_cb(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1212 uint8_t c, uint16_t k, uint16_t kw, struct rte_mbuf *m_in,
1213 struct rte_mbuf *m_out_head, struct rte_mbuf *m_out,
1214 uint16_t in_offset, uint16_t out_offset, bool check_crc_24b,
1215 uint16_t crc24_overlap, uint16_t in_length,
1216 struct rte_bbdev_stats *q_stats)
1218 #ifdef RTE_BBDEV_SDK_AVX2
1219 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1222 RTE_SET_USED(in_length);
1226 uint8_t *in, *out, *adapter_input;
1227 int32_t ncb, ncb_without_null;
1228 struct bblib_turbo_adapter_ul_response adapter_resp;
1229 struct bblib_turbo_adapter_ul_request adapter_req;
1230 struct bblib_turbo_decoder_request turbo_req;
1231 struct bblib_turbo_decoder_response turbo_resp;
1232 struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
1233 #ifdef RTE_BBDEV_OFFLOAD_COST
1234 uint64_t start_time;
1236 RTE_SET_USED(q_stats);
1239 k_idx = compute_idx(k);
1241 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1242 ret = is_dec_input_valid(k_idx, kw, in_length);
1244 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1249 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
1251 ncb_without_null = (k + 4) * 3;
1253 if (check_bit(dec->op_flags, RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE)) {
1254 struct bblib_deinterleave_ul_request deint_req;
1255 struct bblib_deinterleave_ul_response deint_resp;
1257 deint_req.circ_buffer = BBLIB_FULL_CIRCULAR_BUFFER;
1258 deint_req.pharqbuffer = in;
1259 deint_req.ncb = ncb;
1260 deint_resp.pinteleavebuffer = q->deint_output;
1262 #ifdef RTE_BBDEV_OFFLOAD_COST
1263 start_time = rte_rdtsc_precise();
1265 /* Sub-block De-Interleaving */
1266 bblib_deinterleave_ul(&deint_req, &deint_resp);
1267 #ifdef RTE_BBDEV_OFFLOAD_COST
1268 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1271 move_padding_bytes(in, q->deint_output, k, ncb);
1273 adapter_input = q->deint_output;
1275 if (dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN)
1276 adapter_req.isinverted = 1;
1277 else if (dec->op_flags & RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)
1278 adapter_req.isinverted = 0;
1280 op->status |= 1 << RTE_BBDEV_DRV_ERROR;
1281 rte_bbdev_log(ERR, "LLR format wasn't specified");
1285 adapter_req.ncb = ncb_without_null;
1286 adapter_req.pinteleavebuffer = adapter_input;
1287 adapter_resp.pharqout = q->adapter_output;
1289 #ifdef RTE_BBDEV_OFFLOAD_COST
1290 start_time = rte_rdtsc_precise();
1292 /* Turbo decode adaptation */
1293 bblib_turbo_adapter_ul(&adapter_req, &adapter_resp);
1294 #ifdef RTE_BBDEV_OFFLOAD_COST
1295 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1298 out = (uint8_t *)mbuf_append(m_out_head, m_out,
1299 ((k - crc24_overlap) >> 3));
1301 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1302 rte_bbdev_log(ERR, "Too little space in output mbuf");
1305 /* rte_bbdev_op_data.offset can be different than the offset of the
1308 out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
1310 turbo_req.c = c + 1;
1313 turbo_req.input = (int8_t *)q->adapter_output;
1315 turbo_req.k_idx = k_idx;
1316 turbo_req.max_iter_num = dec->iter_max;
1317 turbo_req.early_term_disable = !check_bit(dec->op_flags,
1318 RTE_BBDEV_TURBO_EARLY_TERMINATION);
1319 turbo_resp.ag_buf = q->ag;
1320 turbo_resp.cb_buf = q->code_block;
1321 turbo_resp.output = out;
1323 #ifdef RTE_BBDEV_OFFLOAD_COST
1324 start_time = rte_rdtsc_precise();
1327 iter_cnt = bblib_turbo_decoder(&turbo_req, &turbo_resp);
1328 #ifdef RTE_BBDEV_OFFLOAD_COST
1329 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1331 dec->hard_output.length += (k >> 3);
1334 /* Temporary solution for returned iter_count from SDK */
1335 iter_cnt = (iter_cnt - 1) >> 1;
1336 dec->iter_count = RTE_MAX(iter_cnt, dec->iter_count);
1338 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1339 rte_bbdev_log(ERR, "Turbo Decoder failed");
1349 RTE_SET_USED(m_out_head);
1350 RTE_SET_USED(m_out);
1351 RTE_SET_USED(in_offset);
1352 RTE_SET_USED(out_offset);
1353 RTE_SET_USED(check_crc_24b);
1354 RTE_SET_USED(crc24_overlap);
1355 RTE_SET_USED(in_length);
1356 RTE_SET_USED(q_stats);
1361 process_ldpc_dec_cb(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1362 uint8_t c, uint16_t out_length, uint32_t e,
1363 struct rte_mbuf *m_in,
1364 struct rte_mbuf *m_out_head, struct rte_mbuf *m_out,
1365 struct rte_mbuf *m_harq_in,
1366 struct rte_mbuf *m_harq_out_head, struct rte_mbuf *m_harq_out,
1367 uint16_t in_offset, uint16_t out_offset,
1368 uint16_t harq_in_offset, uint16_t harq_out_offset,
1370 uint16_t crc24_overlap, uint16_t in_length,
1371 struct rte_bbdev_stats *q_stats)
1373 #ifdef RTE_BBDEV_SDK_AVX512
1374 RTE_SET_USED(in_length);
1376 uint8_t *in, *out, *harq_in, *harq_out, *adapter_input;
1377 struct bblib_rate_dematching_5gnr_request derm_req;
1378 struct bblib_rate_dematching_5gnr_response derm_resp;
1379 struct bblib_ldpc_decoder_5gnr_request dec_req;
1380 struct bblib_ldpc_decoder_5gnr_response dec_resp;
1381 struct bblib_crc_request crc_req;
1382 struct bblib_crc_response crc_resp;
1383 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1384 uint16_t K, parity_offset, sys_cols, outLenWithCrc;
1385 int16_t deRmOutSize, numRows;
1387 /* Compute some LDPC BG lengths */
1388 outLenWithCrc = out_length + (crc24_overlap >> 3);
1389 sys_cols = (dec->basegraph == 1) ? 22 : 10;
1390 K = sys_cols * dec->z_c;
1391 parity_offset = K - 2 * dec->z_c;
1393 #ifdef RTE_BBDEV_OFFLOAD_COST
1394 uint64_t start_time = rte_rdtsc_precise();
1396 RTE_SET_USED(q_stats);
1399 in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
1401 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1403 * Single contiguous block from the first LLR of the
1407 if (m_harq_in != NULL)
1408 harq_in = rte_pktmbuf_mtod_offset(m_harq_in,
1409 uint8_t *, harq_in_offset);
1410 if (harq_in == NULL) {
1411 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1412 rte_bbdev_log(ERR, "No space in harq input mbuf");
1415 uint16_t harq_in_length = RTE_MIN(
1416 dec->harq_combined_input.length,
1417 (uint32_t) dec->n_cb);
1418 memset(q->ag + harq_in_length, 0,
1419 dec->n_cb - harq_in_length);
1420 rte_memcpy(q->ag, harq_in, harq_in_length);
1423 derm_req.p_in = (int8_t *) in;
1424 derm_req.p_harq = q->ag; /* This doesn't include the filler bits */
1425 derm_req.base_graph = dec->basegraph;
1426 derm_req.zc = dec->z_c;
1427 derm_req.ncb = dec->n_cb;
1429 derm_req.k0 = 0; /* Actual output from SDK */
1430 derm_req.isretx = check_bit(dec->op_flags,
1431 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
1432 derm_req.rvid = dec->rv_index;
1433 derm_req.modulation_order = dec->q_m;
1434 derm_req.start_null_index = parity_offset - dec->n_filler;
1435 derm_req.num_of_null = dec->n_filler;
1437 bblib_rate_dematching_5gnr(&derm_req, &derm_resp);
1439 /* Compute RM out size and number of rows */
1440 deRmOutSize = RTE_MIN(
1441 derm_req.k0 + derm_req.e -
1442 ((derm_req.k0 < derm_req.start_null_index) ?
1444 dec->n_cb - dec->n_filler);
1445 if (m_harq_in != NULL)
1446 deRmOutSize = RTE_MAX(deRmOutSize,
1447 RTE_MIN(dec->n_cb - dec->n_filler,
1448 m_harq_in->data_len));
1449 numRows = ((deRmOutSize + dec->n_filler + dec->z_c - 1) / dec->z_c)
1451 numRows = RTE_MAX(4, numRows);
1453 /* get output data starting address */
1454 out = (uint8_t *)mbuf_append(m_out_head, m_out, out_length);
1456 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1458 "Too little space in LDPC decoder output mbuf");
1462 /* rte_bbdev_op_data.offset can be different than the offset
1463 * of the appended bytes
1465 out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
1466 adapter_input = q->enc_out;
1468 dec_req.Zc = dec->z_c;
1469 dec_req.baseGraph = dec->basegraph;
1470 dec_req.nRows = numRows;
1471 dec_req.numChannelLlrs = deRmOutSize;
1472 dec_req.varNodes = derm_req.p_harq;
1473 dec_req.numFillerBits = dec->n_filler;
1474 dec_req.maxIterations = dec->iter_max;
1475 dec_req.enableEarlyTermination = check_bit(dec->op_flags,
1476 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
1477 dec_resp.varNodes = (int16_t *) q->adapter_output;
1478 dec_resp.compactedMessageBytes = q->enc_out;
1480 bblib_ldpc_decoder_5gnr(&dec_req, &dec_resp);
1482 dec->iter_count = RTE_MAX(dec_resp.iterationAtTermination,
1484 if (!dec_resp.parityPassedAtTermination)
1485 op->status |= 1 << RTE_BBDEV_SYNDROME_ERROR;
1487 bblib_bit_reverse((int8_t *) q->enc_out, outLenWithCrc << 3);
1489 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK) ||
1490 check_bit(dec->op_flags,
1491 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK)) {
1492 crc_req.data = adapter_input;
1493 crc_req.len = K - dec->n_filler - 24;
1494 crc_resp.check_passed = false;
1495 crc_resp.data = adapter_input;
1497 bblib_lte_crc24b_check(&crc_req, &crc_resp);
1499 bblib_lte_crc24a_check(&crc_req, &crc_resp);
1500 if (!crc_resp.check_passed)
1501 op->status |= 1 << RTE_BBDEV_CRC_ERROR;
1502 } else if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK)) {
1503 crc_req.data = adapter_input;
1504 crc_req.len = K - dec->n_filler - 16;
1505 crc_resp.check_passed = false;
1506 crc_resp.data = adapter_input;
1507 bblib_lte_crc16_check(&crc_req, &crc_resp);
1508 if (!crc_resp.check_passed)
1509 op->status |= 1 << RTE_BBDEV_CRC_ERROR;
1512 #ifdef RTE_BBDEV_OFFLOAD_COST
1513 q_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
1515 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
1517 if (m_harq_out != NULL) {
1518 /* Initialize HARQ data length since we overwrite */
1519 m_harq_out->data_len = 0;
1520 /* Check there is enough space
1521 * in the HARQ outbound buffer
1523 harq_out = (uint8_t *)mbuf_append(m_harq_out_head,
1524 m_harq_out, deRmOutSize);
1526 if (harq_out == NULL) {
1527 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1528 rte_bbdev_log(ERR, "No space in HARQ output mbuf");
1531 /* get output data starting address and overwrite the data */
1532 harq_out = rte_pktmbuf_mtod_offset(m_harq_out, uint8_t *,
1534 rte_memcpy(harq_out, derm_req.p_harq, deRmOutSize);
1535 dec->harq_combined_output.length += deRmOutSize;
1538 rte_memcpy(out, adapter_input, out_length);
1539 dec->hard_output.length += out_length;
1544 RTE_SET_USED(out_length);
1547 RTE_SET_USED(m_out_head);
1548 RTE_SET_USED(m_out);
1549 RTE_SET_USED(m_harq_in);
1550 RTE_SET_USED(m_harq_out_head);
1551 RTE_SET_USED(m_harq_out);
1552 RTE_SET_USED(harq_in_offset);
1553 RTE_SET_USED(harq_out_offset);
1554 RTE_SET_USED(in_offset);
1555 RTE_SET_USED(out_offset);
1556 RTE_SET_USED(check_crc_24b);
1557 RTE_SET_USED(crc24_overlap);
1558 RTE_SET_USED(in_length);
1559 RTE_SET_USED(q_stats);
1565 enqueue_dec_one_op(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1566 struct rte_bbdev_stats *queue_stats)
1570 uint16_t crc24_overlap = 0;
1571 struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
1572 struct rte_mbuf *m_in = dec->input.data;
1573 struct rte_mbuf *m_out = dec->hard_output.data;
1574 struct rte_mbuf *m_out_head = dec->hard_output.data;
1575 uint16_t in_offset = dec->input.offset;
1576 uint16_t out_offset = dec->hard_output.offset;
1577 uint32_t mbuf_total_left = dec->input.length;
1578 uint16_t seg_total_left;
1580 /* Clear op status */
1583 if (m_in == NULL || m_out == NULL) {
1584 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1585 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1589 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1590 c = dec->tb_params.c;
1591 } else { /* For Code Block mode */
1592 k = dec->cb_params.k;
1596 if ((c > 1) && !check_bit(dec->op_flags,
1597 RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP))
1600 while (mbuf_total_left > 0) {
1601 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1602 k = (r < dec->tb_params.c_neg) ?
1603 dec->tb_params.k_neg : dec->tb_params.k_pos;
1605 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1607 /* Calculates circular buffer size (Kw).
1608 * According to 3gpp 36.212 section 5.1.4.2
1612 * where nCol is 32 and nRow can be calculated from:
1614 * where D is the size of each output from turbo encoder block
1617 kw = RTE_ALIGN_CEIL(k + 4, RTE_BBDEV_TURBO_C_SUBBLOCK) * 3;
1619 process_dec_cb(q, op, c, k, kw, m_in, m_out_head, m_out,
1620 in_offset, out_offset, check_bit(dec->op_flags,
1621 RTE_BBDEV_TURBO_CRC_TYPE_24B), crc24_overlap,
1622 seg_total_left, queue_stats);
1624 /* To keep CRC24 attached to end of Code block, use
1625 * RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP flag as it
1626 * removed by default once verified.
1629 mbuf_total_left -= kw;
1631 /* Update offsets */
1632 if (seg_total_left == kw) {
1633 /* Go to the next mbuf */
1635 m_out = m_out->next;
1639 /* Update offsets for next CBs (if exist) */
1641 out_offset += ((k - crc24_overlap) >> 3);
1648 enqueue_ldpc_dec_one_op(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
1649 struct rte_bbdev_stats *queue_stats)
1653 uint16_t out_length, crc24_overlap = 0;
1654 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1655 struct rte_mbuf *m_in = dec->input.data;
1656 struct rte_mbuf *m_harq_in = dec->harq_combined_input.data;
1657 struct rte_mbuf *m_harq_out = dec->harq_combined_output.data;
1658 struct rte_mbuf *m_harq_out_head = dec->harq_combined_output.data;
1659 struct rte_mbuf *m_out = dec->hard_output.data;
1660 struct rte_mbuf *m_out_head = dec->hard_output.data;
1661 uint16_t in_offset = dec->input.offset;
1662 uint16_t harq_in_offset = dec->harq_combined_input.offset;
1663 uint16_t harq_out_offset = dec->harq_combined_output.offset;
1664 uint16_t out_offset = dec->hard_output.offset;
1665 uint32_t mbuf_total_left = dec->input.length;
1666 uint16_t seg_total_left;
1668 /* Clear op status */
1671 if (m_in == NULL || m_out == NULL) {
1672 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1673 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1677 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1678 c = dec->tb_params.c;
1679 e = dec->tb_params.ea;
1680 } else { /* For Code Block mode */
1682 e = dec->cb_params.e;
1685 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1688 out_length = (dec->basegraph == 1 ? 22 : 10) * dec->z_c; /* K */
1689 out_length = ((out_length - crc24_overlap - dec->n_filler) >> 3);
1691 while (mbuf_total_left > 0) {
1692 if (dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1693 e = (r < dec->tb_params.cab) ?
1694 dec->tb_params.ea : dec->tb_params.eb;
1695 /* Special case handling when overusing mbuf */
1696 if (e < RTE_BBDEV_LDPC_E_MAX_MBUF)
1697 seg_total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1701 process_ldpc_dec_cb(q, op, c, out_length, e,
1702 m_in, m_out_head, m_out,
1703 m_harq_in, m_harq_out_head, m_harq_out,
1704 in_offset, out_offset, harq_in_offset,
1706 check_bit(dec->op_flags,
1707 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK),
1709 seg_total_left, queue_stats);
1711 /* To keep CRC24 attached to end of Code block, use
1712 * RTE_BBDEV_LDPC_DEC_TB_CRC_24B_KEEP flag as it
1713 * removed by default once verified.
1716 mbuf_total_left -= e;
1718 /* Update offsets */
1719 if (seg_total_left == e) {
1720 /* Go to the next mbuf */
1722 m_out = m_out->next;
1723 if (m_harq_in != NULL)
1724 m_harq_in = m_harq_in->next;
1725 if (m_harq_out != NULL)
1726 m_harq_out = m_harq_out->next;
1730 harq_out_offset = 0;
1732 /* Update offsets for next CBs (if exist) */
1734 out_offset += out_length;
1740 static inline uint16_t
1741 enqueue_dec_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_dec_op **ops,
1742 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1745 #ifdef RTE_BBDEV_OFFLOAD_COST
1746 queue_stats->acc_offload_cycles = 0;
1749 for (i = 0; i < nb_ops; ++i)
1750 enqueue_dec_one_op(q, ops[i], queue_stats);
1752 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1756 static inline uint16_t
1757 enqueue_ldpc_dec_all_ops(struct turbo_sw_queue *q,
1758 struct rte_bbdev_dec_op **ops,
1759 uint16_t nb_ops, struct rte_bbdev_stats *queue_stats)
1762 #ifdef RTE_BBDEV_OFFLOAD_COST
1763 queue_stats->acc_offload_cycles = 0;
1766 for (i = 0; i < nb_ops; ++i)
1767 enqueue_ldpc_dec_one_op(q, ops[i], queue_stats);
1769 return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
1775 enqueue_enc_ops(struct rte_bbdev_queue_data *q_data,
1776 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1778 void *queue = q_data->queue_private;
1779 struct turbo_sw_queue *q = queue;
1780 uint16_t nb_enqueued = 0;
1782 nb_enqueued = enqueue_enc_all_ops(q, ops, nb_ops, &q_data->queue_stats);
1784 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1785 q_data->queue_stats.enqueued_count += nb_enqueued;
1792 enqueue_ldpc_enc_ops(struct rte_bbdev_queue_data *q_data,
1793 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1795 void *queue = q_data->queue_private;
1796 struct turbo_sw_queue *q = queue;
1797 uint16_t nb_enqueued = 0;
1799 nb_enqueued = enqueue_ldpc_enc_all_ops(
1800 q, ops, nb_ops, &q_data->queue_stats);
1802 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1803 q_data->queue_stats.enqueued_count += nb_enqueued;
1810 enqueue_dec_ops(struct rte_bbdev_queue_data *q_data,
1811 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1813 void *queue = q_data->queue_private;
1814 struct turbo_sw_queue *q = queue;
1815 uint16_t nb_enqueued = 0;
1817 nb_enqueued = enqueue_dec_all_ops(q, ops, nb_ops, &q_data->queue_stats);
1819 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1820 q_data->queue_stats.enqueued_count += nb_enqueued;
1827 enqueue_ldpc_dec_ops(struct rte_bbdev_queue_data *q_data,
1828 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1830 void *queue = q_data->queue_private;
1831 struct turbo_sw_queue *q = queue;
1832 uint16_t nb_enqueued = 0;
1834 nb_enqueued = enqueue_ldpc_dec_all_ops(q, ops, nb_ops,
1835 &q_data->queue_stats);
1837 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1838 q_data->queue_stats.enqueued_count += nb_enqueued;
1843 /* Dequeue decode burst */
1845 dequeue_dec_ops(struct rte_bbdev_queue_data *q_data,
1846 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1848 struct turbo_sw_queue *q = q_data->queue_private;
1849 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1850 (void **)ops, nb_ops, NULL);
1851 q_data->queue_stats.dequeued_count += nb_dequeued;
1856 /* Dequeue encode burst */
1858 dequeue_enc_ops(struct rte_bbdev_queue_data *q_data,
1859 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1861 struct turbo_sw_queue *q = q_data->queue_private;
1862 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1863 (void **)ops, nb_ops, NULL);
1864 q_data->queue_stats.dequeued_count += nb_dequeued;
1869 /* Parse 16bit integer from string argument */
1871 parse_u16_arg(const char *key, const char *value, void *extra_args)
1873 uint16_t *u16 = extra_args;
1874 unsigned int long result;
1876 if ((value == NULL) || (extra_args == NULL))
1879 result = strtoul(value, NULL, 0);
1880 if ((result >= (1 << 16)) || (errno != 0)) {
1881 rte_bbdev_log(ERR, "Invalid value %lu for %s", result, key);
1884 *u16 = (uint16_t)result;
1888 /* Parse parameters used to create device */
1890 parse_turbo_sw_params(struct turbo_sw_params *params, const char *input_args)
1892 struct rte_kvargs *kvlist = NULL;
1898 kvlist = rte_kvargs_parse(input_args, turbo_sw_valid_params);
1902 ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[0],
1903 &parse_u16_arg, ¶ms->queues_num);
1907 ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[1],
1908 &parse_u16_arg, ¶ms->socket_id);
1912 if (params->socket_id >= RTE_MAX_NUMA_NODES) {
1913 rte_bbdev_log(ERR, "Invalid socket, must be < %u",
1914 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);