1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef _RTE_BBDEV_OP_H_
6 #define _RTE_BBDEV_OP_H_
11 * Defines wireless base band layer 1 operations and capabilities
14 * @b EXPERIMENTAL: this API may change without prior notice
23 #include <rte_common.h>
25 #include <rte_memory.h>
26 #include <rte_mempool.h>
28 #define RTE_BBDEV_MAX_CODE_BLOCKS 64
30 /** Flags for turbo decoder operation and capability structure */
31 enum rte_bbdev_op_td_flag_bitmasks {
32 /**< If sub block de-interleaving is to be performed. */
33 RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE = (1ULL << 0),
34 /**< To use CRC Type 24B (otherwise use CRC Type 24A). */
35 RTE_BBDEV_TURBO_CRC_TYPE_24B = (1ULL << 1),
36 /**< If turbo equalization is to be performed. */
37 RTE_BBDEV_TURBO_EQUALIZER = (1ULL << 2),
38 /**< If set, saturate soft output to +/-127 */
39 RTE_BBDEV_TURBO_SOFT_OUT_SATURATE = (1ULL << 3),
40 /**< Set to 1 to start iteration from even, else odd; one iteration =
43 RTE_BBDEV_TURBO_HALF_ITERATION_EVEN = (1ULL << 4),
44 /**< If 0, TD stops after CRC matches; else if 1, runs to end of next
45 * odd iteration after CRC matches
47 RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH = (1ULL << 5),
48 /**< Set if soft output is required to be output */
49 RTE_BBDEV_TURBO_SOFT_OUTPUT = (1ULL << 6),
50 /**< Set to enable early termination mode */
51 RTE_BBDEV_TURBO_EARLY_TERMINATION = (1ULL << 7),
52 /**< Set if a device supports decoder dequeue interrupts */
53 RTE_BBDEV_TURBO_DEC_INTERRUPTS = (1ULL << 9),
54 /**< Set if positive LLR encoded input is supported. Positive LLR value
55 * represents the level of confidence for bit '1', and vice versa for
57 * This is mutually exclusive with RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN
58 * when used to formalize the input data format.
60 RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN = (1ULL << 10),
61 /**< Set if negative LLR encoded input is supported. Negative LLR value
62 * represents the level of confidence for bit '1', and vice versa for
64 * This is mutually exclusive with RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN
65 * when used to formalize the input data format.
67 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN = (1ULL << 11),
68 /**< Set if positive LLR soft output is supported. Positive LLR value
69 * represents the level of confidence for bit '1', and vice versa for
71 * This is mutually exclusive with
72 * RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT when used to formalize
73 * the input data format.
75 RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT = (1ULL << 12),
76 /**< Set if negative LLR soft output is supported. Negative LLR value
77 * represents the level of confidence for bit '1', and vice versa for
79 * This is mutually exclusive with
80 * RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT when used to formalize the
83 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT = (1ULL << 13),
84 /**< Set if driver supports flexible parallel MAP engine decoding. If
85 * not supported, num_maps (number of MAP engines) argument is unusable.
87 RTE_BBDEV_TURBO_MAP_DEC = (1ULL << 14),
88 /**< Set if a device supports scatter-gather functionality */
89 RTE_BBDEV_TURBO_DEC_SCATTER_GATHER = (1ULL << 15)
92 /** Flags for turbo encoder operation and capability structure */
93 enum rte_bbdev_op_te_flag_bitmasks {
94 /**< Ignore rv_index and set K0 = 0 */
95 RTE_BBDEV_TURBO_RV_INDEX_BYPASS = (1ULL << 0),
96 /**< If rate matching is to be performed */
97 RTE_BBDEV_TURBO_RATE_MATCH = (1ULL << 1),
98 /**< This bit must be set to enable CRC-24B generation */
99 RTE_BBDEV_TURBO_CRC_24B_ATTACH = (1ULL << 2),
100 /**< This bit must be set to enable CRC-24A generation */
101 RTE_BBDEV_TURBO_CRC_24A_ATTACH = (1ULL << 3),
102 /**< Set if a device supports encoder dequeue interrupts */
103 RTE_BBDEV_TURBO_ENC_INTERRUPTS = (1ULL << 4),
104 /**< Set if a device supports scatter-gather functionality */
105 RTE_BBDEV_TURBO_ENC_SCATTER_GATHER = (1ULL << 5)
108 /**< Data input and output buffer for BBDEV operations */
109 struct rte_bbdev_op_data {
110 /**< The mbuf data structure representing the data for BBDEV operation.
112 * This mbuf pointer can point to one Code Block (CB) data buffer or
113 * multiple CBs contiguously located next to each other.
114 * A Transport Block (TB) represents a whole piece of data that is
115 * divided into one or more CBs. Maximum number of CBs can be contained
116 * in one TB is defined by RTE_BBDEV_MAX_CODE_BLOCKS.
118 * An mbuf data structure cannot represent more than one TB. The
119 * smallest piece of data that can be contained in one mbuf is one CB.
120 * An mbuf can include one contiguous CB, subset of contiguous CBs that
121 * are belonging to one TB, or all contiguous CBs that are belonging to
124 * If a BBDEV PMD supports the extended capability "Scatter-Gather",
125 * then it is capable of collecting (gathering) non-contiguous
126 * (scattered) data from multiple locations in the memory.
127 * This capability is reported by the capability flags:
128 * - RTE_BBDEV_TURBO_ENC_SCATTER_GATHER and
129 * - RTE_BBDEV_TURBO_DEC_SCATTER_GATHER.
130 * Only if a BBDEV PMD supports this feature, chained mbuf data
131 * structures are accepted. A chained mbuf can represent one
132 * non-contiguous CB or multiple non-contiguous CBs.
133 * If BBDEV PMD does not support this feature, it will assume inbound
134 * mbuf data contains one segment.
136 * The output mbuf data though is always one segment, even if the input
137 * was a chained mbuf.
139 struct rte_mbuf *data;
140 /**< The starting point of the BBDEV (encode/decode) operation,
143 * BBDEV starts to read data past this offset.
144 * In case of chained mbuf, this offset applies only to the first mbuf
148 /**< The total data length to be processed in one operation, in bytes.
150 * In case the mbuf data is representing one CB, this is the length of
151 * the CB undergoing the operation.
152 * If it's for multiple CBs, this is the total length of those CBs
153 * undergoing the operation.
154 * If it's for one TB, this is the total length of the TB under
157 * In case of chained mbuf, this data length includes the lengths of the
158 * "scattered" data segments undergoing the operation.
163 struct rte_bbdev_op_dec_cb_params {
164 /**< The K size of the input CB, in bits [40:6144], as specified in
166 * This size is inclusive of CRC bits, regardless whether it was
167 * pre-calculated by the application or not.
170 /**< The E length of the CB rate matched LLR output, in bytes, as in
176 struct rte_bbdev_op_dec_tb_params {
177 /**< The K- size of the input CB, in bits [40:6144], that is in the
178 * Turbo operation when r < C-, as in 3GPP TS 36.212.
181 /**< The K+ size of the input CB, in bits [40:6144], that is in the
182 * Turbo operation when r >= C-, as in 3GPP TS 36.212.
185 /**< The number of CBs that have K- size, [0:63] */
187 /**< The total number of CBs in the TB, [1:RTE_BBDEV_MAX_CODE_BLOCKS] */
189 /**< The number of CBs that uses Ea before switching to Eb, [0:63] */
191 /**< The E size of the CB rate matched output to use in the Turbo
192 * operation when r < cab
195 /**< The E size of the CB rate matched output to use in the Turbo
196 * operation when r >= cab
201 /**< Operation structure for Turbo decode.
202 * An operation can perform on one CB at a time "CB-mode".
203 * An operation can perform on one or multiple CBs that are logically belonging
204 * to one TB "TB-mode".
205 * The provided K size parameter of the CB is its size out coming from the
207 * CRC24A/B check is requested by the application by setting the flag
208 * RTE_BBDEV_TURBO_CRC_TYPE_24B for CRC24B check or CRC24A otherwise.
209 * In TB-mode, BBDEV concatenates the decoded CBs one next to the other with
210 * relevant CRC24B in between.
212 * The input encoded CB data is the Virtual Circular Buffer data stream, wk,
213 * with the null padding included as described in 3GPP TS 36.212
214 * section 5.1.4.1.2 and shown in 3GPP TS 36.212 section 5.1.4.1 Figure 5.1.4-1.
215 * The size of the virtual circular buffer is 3*Kpi, where Kpi is the 32 byte
216 * aligned value of K, as specified in 3GPP TS 36.212 section 5.1.4.1.1.
218 * Each byte in the input circular buffer is the LLR value of each bit of the
221 * Hard output is a mandatory capability that all BBDEV PMDs support. This is
222 * the decoded CBs of K sizes (CRC24A/B is the last 24-bit in each decoded CB).
223 * Soft output is an optional capability for BBDEV PMDs. If supported, an LLR
224 * rate matched output is computed in the soft_output buffer structure.
226 * The output mbuf data structure is expected to be allocated by the
227 * application with enough room for the output data.
229 struct rte_bbdev_op_turbo_dec {
230 /**< The Virtual Circular Buffer, wk, size 3*Kpi for each CB */
231 struct rte_bbdev_op_data input;
232 /**< The hard decisions buffer for the decoded output,
235 struct rte_bbdev_op_data hard_output;
236 /**< The soft LLR output buffer - optional */
237 struct rte_bbdev_op_data soft_output;
239 uint32_t op_flags; /**< Flags from rte_bbdev_op_td_flag_bitmasks */
240 uint8_t rv_index; /**< Rv index for rate matching [0:3] */
241 /**< The minimum number of iterations to perform in decoding all CBs in
242 * this operation - input
245 /**< The maximum number of iterations to perform in decoding all CBs in
246 * this operation - input
249 /**< The maximum number of iterations that were perform in decoding all
250 * CBs in this decode operation - output
253 /**< 5 bit extrinsic scale (scale factor on extrinsic info) */
255 /**< Number of MAP engines to use in decode,
256 * must be power of 2 (or 0 to auto-select)
260 uint8_t code_block_mode; /**< [0 - TB : 1 - CB] */
262 /**< Struct which stores Code Block specific parameters */
263 struct rte_bbdev_op_dec_cb_params cb_params;
264 /**< Struct which stores Transport Block specific parameters */
265 struct rte_bbdev_op_dec_tb_params tb_params;
269 struct rte_bbdev_op_enc_cb_params {
270 /**< The K size of the input CB, in bits [40:6144], as specified in
272 * This size is inclusive of CRC24A, regardless whether it was
273 * pre-calculated by the application or not.
276 /**< The E length of the CB rate matched output, in bits, as in
280 /**< The Ncb soft buffer size of the CB rate matched output [K:3*Kpi],
281 * in bits, as specified in 3GPP TS 36.212.
286 struct rte_bbdev_op_enc_tb_params {
287 /**< The K- size of the input CB, in bits [40:6144], that is in the
288 * Turbo operation when r < C-, as in 3GPP TS 36.212.
289 * This size is inclusive of CRC24B, regardless whether it was
290 * pre-calculated and appended by the application or not.
293 /**< The K+ size of the input CB, in bits [40:6144], that is in the
294 * Turbo operation when r >= C-, as in 3GPP TS 36.212.
295 * This size is inclusive of CRC24B, regardless whether it was
296 * pre-calculated and appended by the application or not.
299 /**< The number of CBs that have K- size, [0:63] */
301 /**< The total number of CBs in the TB, [1:RTE_BBDEV_MAX_CODE_BLOCKS] */
303 /**< The number of CBs that uses Ea before switching to Eb, [0:63] */
305 /**< The E size of the CB rate matched output to use in the Turbo
306 * operation when r < cab
309 /**< The E size of the CB rate matched output to use in the Turbo
310 * operation when r >= cab
313 /**< The Ncb soft buffer size for the rate matched CB that is used in
314 * the Turbo operation when r < C-, [K:3*Kpi]
317 /**< The Ncb soft buffer size for the rate matched CB that is used in
318 * the Turbo operation when r >= C-, [K:3*Kpi]
321 /**< The index of the first CB in the inbound mbuf data, default is 0 */
325 /**< Operation structure for Turbo encode.
326 * An operation can perform on one CB at a time "CB-mode".
327 * An operation can perform on one or multiple CBs that are logically
328 * belonging to one TB "TB-mode".
330 * In CB-mode, CRC24A/B is an optional operation. K size parameter is not
331 * affected by CRC24A/B inclusion, this only affects the inbound mbuf data
332 * length. Not all BBDEV PMDs are capable of CRC24A/B calculation. Flags
333 * RTE_BBDEV_TURBO_CRC_24A_ATTACH and RTE_BBDEV_TURBO_CRC_24B_ATTACH informs
334 * the application with relevant capability. These flags can be set in the
335 * op_flags parameter to indicate BBDEV to calculate and append CRC24A to CB
336 * before going forward with Turbo encoding.
338 * In TB-mode, CRC24A is assumed to be pre-calculated and appended to the
339 * inbound TB mbuf data buffer.
341 * The output mbuf data structure is expected to be allocated by the
342 * application with enough room for the output data.
344 struct rte_bbdev_op_turbo_enc {
345 /**< The input CB or TB data */
346 struct rte_bbdev_op_data input;
347 /**< The rate matched CB or TB output buffer */
348 struct rte_bbdev_op_data output;
350 uint32_t op_flags; /**< Flags from rte_bbdev_op_te_flag_bitmasks */
351 uint8_t rv_index; /**< Rv index for rate matching [0:3] */
353 uint8_t code_block_mode; /**< [0 - TB : 1 - CB] */
355 /**< Struct which stores Code Block specific parameters */
356 struct rte_bbdev_op_enc_cb_params cb_params;
357 /**< Struct which stores Transport Block specific parameters */
358 struct rte_bbdev_op_enc_tb_params tb_params;
362 /**< List of the capabilities for the Turbo Decoder */
363 struct rte_bbdev_op_cap_turbo_dec {
364 /**< Flags from rte_bbdev_op_td_flag_bitmasks */
365 uint32_t capability_flags;
366 uint8_t num_buffers_src; /**< Num input code block buffers */
367 /**< Num hard output code block buffers */
368 uint8_t num_buffers_hard_out;
369 /**< Num soft output code block buffers if supported by the driver */
370 uint8_t num_buffers_soft_out;
373 /**< List of the capabilities for the Turbo Encoder */
374 struct rte_bbdev_op_cap_turbo_enc {
375 /**< Flags from rte_bbdev_op_te_flag_bitmasks */
376 uint32_t capability_flags;
377 uint8_t num_buffers_src; /**< Num input code block buffers */
378 uint8_t num_buffers_dst; /**< Num output code block buffers */
381 /** Different operation types supported by the device */
382 enum rte_bbdev_op_type {
383 RTE_BBDEV_OP_NONE, /**< Dummy operation that does nothing */
384 RTE_BBDEV_OP_TURBO_DEC, /**< Turbo decode */
385 RTE_BBDEV_OP_TURBO_ENC, /**< Turbo encode */
386 RTE_BBDEV_OP_TYPE_COUNT, /**< Count of different op types */
389 /**< Bit indexes of possible errors reported through status field */
392 RTE_BBDEV_DATA_ERROR,
396 /**< Structure specifying a single encode operation */
397 struct rte_bbdev_enc_op {
398 int status; /**< Status of operation that was performed */
399 struct rte_mempool *mempool; /**< Mempool which op instance is in */
400 void *opaque_data; /**< Opaque pointer for user data */
401 /**< Contains encoder specific parameters */
402 struct rte_bbdev_op_turbo_enc turbo_enc;
405 /**< Structure specifying a single decode operation */
406 struct rte_bbdev_dec_op {
407 int status; /**< Status of operation that was performed */
408 struct rte_mempool *mempool; /**< Mempool which op instance is in */
409 void *opaque_data; /**< Opaque pointer for user data */
410 /**< Contains decoder specific parameters */
411 struct rte_bbdev_op_turbo_dec turbo_dec;
414 /**< Operation capabilities supported by a device */
415 struct rte_bbdev_op_cap {
416 enum rte_bbdev_op_type type; /**< Type of operation */
418 struct rte_bbdev_op_cap_turbo_dec turbo_dec;
419 struct rte_bbdev_op_cap_turbo_enc turbo_enc;
420 } cap; /**< Operation-type specific capabilities */
423 /**< @internal Private data structure stored with operation pool. */
424 struct rte_bbdev_op_pool_private {
425 enum rte_bbdev_op_type type; /**< Type of operations in a pool */
429 * Converts queue operation type from enum to string
432 * Operation type as enum
435 * Operation type as string or NULL if op_type is invalid
439 rte_bbdev_op_type_str(enum rte_bbdev_op_type op_type);
442 * Creates a bbdev operation mempool
447 * Operation type, use RTE_BBDEV_OP_NONE for a pool which supports all
449 * @param num_elements
450 * Number of elements in the pool.
452 * Number of elements to cache on an lcore, see rte_mempool_create() for
453 * further details about cache size.
455 * Socket to allocate memory on.
458 * - Pointer to a mempool on success,
459 * - NULL pointer on failure.
462 rte_bbdev_op_pool_create(const char *name, enum rte_bbdev_op_type type,
463 unsigned int num_elements, unsigned int cache_size,
467 * Bulk allocate encode operations from a mempool with parameter defaults reset.
470 * Operation mempool, created by rte_bbdev_op_pool_create().
472 * Output array to place allocated operations
474 * Number of operations to allocate
478 * - EINVAL if invalid mempool is provided
481 rte_bbdev_enc_op_alloc_bulk(struct rte_mempool *mempool,
482 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
484 struct rte_bbdev_op_pool_private *priv;
488 priv = (struct rte_bbdev_op_pool_private *)
489 rte_mempool_get_priv(mempool);
490 if (unlikely(priv->type != RTE_BBDEV_OP_TURBO_ENC))
494 ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
495 if (unlikely(ret < 0))
502 * Bulk allocate decode operations from a mempool with parameter defaults reset.
505 * Operation mempool, created by rte_bbdev_op_pool_create().
507 * Output array to place allocated operations
509 * Number of operations to allocate
513 * - EINVAL if invalid mempool is provided
516 rte_bbdev_dec_op_alloc_bulk(struct rte_mempool *mempool,
517 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
519 struct rte_bbdev_op_pool_private *priv;
523 priv = (struct rte_bbdev_op_pool_private *)
524 rte_mempool_get_priv(mempool);
525 if (unlikely(priv->type != RTE_BBDEV_OP_TURBO_DEC))
529 ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
530 if (unlikely(ret < 0))
537 * Free decode operation structures that were allocated by
538 * rte_bbdev_dec_op_alloc_bulk().
539 * All structures must belong to the same mempool.
542 * Operation structures
544 * Number of structures
547 rte_bbdev_dec_op_free_bulk(struct rte_bbdev_dec_op **ops, unsigned int num_ops)
550 rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
554 * Free encode operation structures that were allocated by
555 * rte_bbdev_enc_op_alloc_bulk().
556 * All structures must belong to the same mempool.
559 * Operation structures
561 * Number of structures
564 rte_bbdev_enc_op_free_bulk(struct rte_bbdev_enc_op **ops, unsigned int num_ops)
567 rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
574 #endif /* _RTE_BBDEV_OP_H_ */