xref: /dpdk/lib/bbdev/rte_bbdev_op.h (revision 99f9d799ce21ab22e922ffec8aad51d56e24d04d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #ifndef _RTE_BBDEV_OP_H_
6 #define _RTE_BBDEV_OP_H_
7 
8 /**
9  * @file rte_bbdev_op.h
10  *
11  * Defines wireless base band layer 1 operations and capabilities
12  *
13  * @warning
14  * @b EXPERIMENTAL: this API may change without prior notice
15  */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <stdint.h>
22 
23 #include <rte_common.h>
24 #include <rte_mbuf.h>
25 #include <rte_memory.h>
26 #include <rte_mempool.h>
27 
28 /* Number of columns in sub-block interleaver (36.212, section 5.1.4.1.1) */
29 #define RTE_BBDEV_TURBO_C_SUBBLOCK (32)
30 /* Maximum size of Transport Block (36.213, Table, Table 7.1.7.2.5-1) */
31 #define RTE_BBDEV_TURBO_MAX_TB_SIZE (391656)
32 /* Maximum size of Code Block (36.212, Table 5.1.3-3) */
33 #define RTE_BBDEV_TURBO_MAX_CB_SIZE (6144)
34 /* Maximum size of Code Block */
35 #define RTE_BBDEV_LDPC_MAX_CB_SIZE (8448)
36 /* Minimum size of Code Block */
37 #define RTE_BBDEV_LDPC_MIN_CB_SIZE (40)
38 /* Maximum E size we can manage with default mbuf */
39 #define RTE_BBDEV_LDPC_E_MAX_MBUF (64000)
40 /* Minimum size of Code Block (36.212, Table 5.1.3-3) */
41 #define RTE_BBDEV_TURBO_MIN_CB_SIZE (40)
42 /* Maximum size of circular buffer */
43 #define RTE_BBDEV_TURBO_MAX_KW (18528)
44 /*
45  * Turbo: Maximum number of Code Blocks in Transport Block. It is calculated
46  * based on maximum size of one Code Block and one Transport Block
47  * (considering CRC24A and CRC24B):
48  * (391656 + 24) / (6144 - 24) = 64
49  */
50 #define RTE_BBDEV_TURBO_MAX_CODE_BLOCKS (64)
51 /* LDPC:  Maximum number of Code Blocks in Transport Block.*/
52 #define RTE_BBDEV_LDPC_MAX_CODE_BLOCKS (256)
53 
54 /** Flags for turbo decoder operation and capability structure */
55 enum rte_bbdev_op_td_flag_bitmasks {
56 	/** If sub block de-interleaving is to be performed. */
57 	RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE = (1ULL << 0),
58 	/** To use CRC Type 24B (otherwise use CRC Type 24A). */
59 	RTE_BBDEV_TURBO_CRC_TYPE_24B = (1ULL << 1),
60 	/** If turbo equalization is to be performed. */
61 	RTE_BBDEV_TURBO_EQUALIZER = (1ULL << 2),
62 	/** If set, saturate soft output to +/-127 */
63 	RTE_BBDEV_TURBO_SOFT_OUT_SATURATE = (1ULL << 3),
64 	/** Set to 1 to start iteration from even, else odd; one iteration =
65 	 * max_iteration + 0.5
66 	 */
67 	RTE_BBDEV_TURBO_HALF_ITERATION_EVEN = (1ULL << 4),
68 	/** If 0, TD stops after CRC matches; else if 1, runs to end of next
69 	 * odd iteration after CRC matches
70 	 */
71 	RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH = (1ULL << 5),
72 	/** Set if soft output is required to be output  */
73 	RTE_BBDEV_TURBO_SOFT_OUTPUT = (1ULL << 6),
74 	/** Set to enable early termination mode */
75 	RTE_BBDEV_TURBO_EARLY_TERMINATION = (1ULL << 7),
76 	/** Set if a device supports decoder dequeue interrupts */
77 	RTE_BBDEV_TURBO_DEC_INTERRUPTS = (1ULL << 9),
78 	/** Set if positive LLR encoded input is supported. Positive LLR value
79 	 * represents the level of confidence for bit '1', and vice versa for
80 	 * bit '0'.
81 	 * This is mutually exclusive with RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN
82 	 * when used to formalize the input data format.
83 	 */
84 	RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN = (1ULL << 10),
85 	/** Set if negative LLR encoded input is supported. Negative LLR value
86 	 * represents the level of confidence for bit '1', and vice versa for
87 	 * bit '0'.
88 	 * This is mutually exclusive with RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN
89 	 * when used to formalize the input data format.
90 	 */
91 	RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN = (1ULL << 11),
92 	/** Set if positive LLR soft output is supported. Positive LLR value
93 	 * represents the level of confidence for bit '1', and vice versa for
94 	 * bit '0'.
95 	 * This is mutually exclusive with
96 	 * RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT when used to formalize
97 	 * the input data format.
98 	 */
99 	RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT = (1ULL << 12),
100 	/** Set if negative LLR soft output is supported. Negative LLR value
101 	 * represents the level of confidence for bit '1', and vice versa for
102 	 * bit '0'.
103 	 * This is mutually exclusive with
104 	 * RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT when used to formalize the
105 	 * input data format.
106 	 */
107 	RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT = (1ULL << 13),
108 	/** Set if driver supports flexible parallel MAP engine decoding. If
109 	 * not supported, num_maps (number of MAP engines) argument is unusable.
110 	 */
111 	RTE_BBDEV_TURBO_MAP_DEC = (1ULL << 14),
112 	/** Set if a device supports scatter-gather functionality */
113 	RTE_BBDEV_TURBO_DEC_SCATTER_GATHER = (1ULL << 15),
114 	/** Set to keep CRC24B bits appended while decoding. Only usable when
115 	 * decoding Transport Block mode.
116 	 */
117 	RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP = (1ULL << 16)
118 };
119 
120 
121 /** Flags for turbo encoder operation and capability structure */
122 enum rte_bbdev_op_te_flag_bitmasks {
123 	/** Ignore rv_index and set K0 = 0 */
124 	RTE_BBDEV_TURBO_RV_INDEX_BYPASS = (1ULL << 0),
125 	/** If rate matching is to be performed */
126 	RTE_BBDEV_TURBO_RATE_MATCH = (1ULL << 1),
127 	/** This bit must be set to enable CRC-24B generation */
128 	RTE_BBDEV_TURBO_CRC_24B_ATTACH = (1ULL << 2),
129 	/** This bit must be set to enable CRC-24A generation */
130 	RTE_BBDEV_TURBO_CRC_24A_ATTACH = (1ULL << 3),
131 	/** Set if a device supports encoder dequeue interrupts */
132 	RTE_BBDEV_TURBO_ENC_INTERRUPTS = (1ULL << 4),
133 	/** Set if a device supports scatter-gather functionality */
134 	RTE_BBDEV_TURBO_ENC_SCATTER_GATHER = (1ULL << 5)
135 };
136 
137 /** Flags for LDPC decoder operation and capability structure */
138 enum rte_bbdev_op_ldpcdec_flag_bitmasks {
139 	/** Set for transport block CRC-24A checking */
140 	RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK = (1ULL << 0),
141 	/** Set for code block CRC-24B checking */
142 	RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK = (1ULL << 1),
143 	/** Set to drop the last CRC bits decoding output */
144 	RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP = (1ULL << 2),
145 	/** Set for bit-level de-interleaver bypass on Rx stream. */
146 	RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS = (1ULL << 3),
147 	/** Set for HARQ combined input stream enable. */
148 	RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE = (1ULL << 4),
149 	/** Set for HARQ combined output stream enable. */
150 	RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE = (1ULL << 5),
151 	/** Set for LDPC decoder bypass.
152 	 *  RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE must be set.
153 	 */
154 	RTE_BBDEV_LDPC_DECODE_BYPASS = (1ULL << 6),
155 	/** Set for soft-output stream enable */
156 	RTE_BBDEV_LDPC_SOFT_OUT_ENABLE = (1ULL << 7),
157 	/** Set for Rate-Matching bypass on soft-out stream. */
158 	RTE_BBDEV_LDPC_SOFT_OUT_RM_BYPASS = (1ULL << 8),
159 	/** Set for bit-level de-interleaver bypass on soft-output stream. */
160 	RTE_BBDEV_LDPC_SOFT_OUT_DEINTERLEAVER_BYPASS = (1ULL << 9),
161 	/** Set for iteration stopping on successful decode condition
162 	 *  i.e. a successful syndrome check.
163 	 */
164 	RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE = (1ULL << 10),
165 	/** Set if a device supports decoder dequeue interrupts. */
166 	RTE_BBDEV_LDPC_DEC_INTERRUPTS = (1ULL << 11),
167 	/** Set if a device supports scatter-gather functionality. */
168 	RTE_BBDEV_LDPC_DEC_SCATTER_GATHER = (1ULL << 12),
169 	/** Set if a device supports input/output HARQ compression. */
170 	RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION = (1ULL << 13),
171 	/** Set if a device supports input LLR compression. */
172 	RTE_BBDEV_LDPC_LLR_COMPRESSION = (1ULL << 14),
173 	/** Set if a device supports HARQ input from
174 	 *  device's internal memory.
175 	 */
176 	RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE = (1ULL << 15),
177 	/** Set if a device supports HARQ output to
178 	 *  device's internal memory.
179 	 */
180 	RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE = (1ULL << 16),
181 	/** Set if a device supports loop-back access to
182 	 *  HARQ internal memory. Intended for troubleshooting.
183 	 */
184 	RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK = (1ULL << 17),
185 	/** Set if a device includes LLR filler bits in the circular buffer
186 	 *  for HARQ memory. If not set, it is assumed the filler bits are not
187 	 *  in HARQ memory and handled directly by the LDPC decoder.
188 	 */
189 	RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_FILLERS = (1ULL << 18)
190 };
191 
192 /** Flags for LDPC encoder operation and capability structure */
193 enum rte_bbdev_op_ldpcenc_flag_bitmasks {
194 	/** Set for bit-level interleaver bypass on output stream. */
195 	RTE_BBDEV_LDPC_INTERLEAVER_BYPASS = (1ULL << 0),
196 	/** If rate matching is to be performed */
197 	RTE_BBDEV_LDPC_RATE_MATCH = (1ULL << 1),
198 	/** Set for transport block CRC-24A attach */
199 	RTE_BBDEV_LDPC_CRC_24A_ATTACH = (1ULL << 2),
200 	/** Set for code block CRC-24B attach */
201 	RTE_BBDEV_LDPC_CRC_24B_ATTACH = (1ULL << 3),
202 	/** Set for code block CRC-16 attach */
203 	RTE_BBDEV_LDPC_CRC_16_ATTACH = (1ULL << 4),
204 	/** Set if a device supports encoder dequeue interrupts. */
205 	RTE_BBDEV_LDPC_ENC_INTERRUPTS = (1ULL << 5),
206 	/** Set if a device supports scatter-gather functionality. */
207 	RTE_BBDEV_LDPC_ENC_SCATTER_GATHER = (1ULL << 6),
208 	/** Set if a device supports concatenation of non byte aligned output */
209 	RTE_BBDEV_LDPC_ENC_CONCATENATION = (1ULL << 7)
210 };
211 
212 /** Flags for the Code Block/Transport block mode  */
213 enum rte_bbdev_op_cb_mode {
214 	/** One operation is one or fraction of one transport block  */
215 	RTE_BBDEV_TRANSPORT_BLOCK = 0,
216 	/** One operation is one code block mode */
217 	RTE_BBDEV_CODE_BLOCK = 1,
218 };
219 
220 /** Data input and output buffer for BBDEV operations */
221 struct rte_bbdev_op_data {
222 	/** The mbuf data structure representing the data for BBDEV operation.
223 	 *
224 	 * This mbuf pointer can point to one Code Block (CB) data buffer or
225 	 * multiple CBs contiguously located next to each other.
226 	 * A Transport Block (TB) represents a whole piece of data that is
227 	 * divided into one or more CBs. Maximum number of CBs can be contained
228 	 * in one TB is defined by RTE_BBDEV_(TURBO/LDPC)_MAX_CODE_BLOCKS.
229 	 *
230 	 * An mbuf data structure cannot represent more than one TB. The
231 	 * smallest piece of data that can be contained in one mbuf is one CB.
232 	 * An mbuf can include one contiguous CB, subset of contiguous CBs that
233 	 * are belonging to one TB, or all contiguous CBs that are belonging to
234 	 * one TB.
235 	 *
236 	 * If a BBDEV PMD supports the extended capability "Scatter-Gather",
237 	 * then it is capable of collecting (gathering) non-contiguous
238 	 * (scattered) data from multiple locations in the memory.
239 	 * This capability is reported by the capability flags:
240 	 * - RTE_BBDEV_(TURBO/LDPC)_ENC_SCATTER_GATHER and
241 	 * - RTE_BBDEV_(TURBO/LDPC)_DEC_SCATTER_GATHER.
242 	 * Only if a BBDEV PMD supports this feature, chained mbuf data
243 	 * structures are accepted. A chained mbuf can represent one
244 	 * non-contiguous CB or multiple non-contiguous CBs.
245 	 * If BBDEV PMD does not support this feature, it will assume inbound
246 	 * mbuf data contains one segment.
247 	 *
248 	 * The output mbuf data though is always one segment, even if the input
249 	 * was a chained mbuf.
250 	 */
251 	struct rte_mbuf *data;
252 	/** The starting point of the BBDEV (encode/decode) operation,
253 	 * in bytes.
254 	 *
255 	 * BBDEV starts to read data past this offset.
256 	 * In case of chained mbuf, this offset applies only to the first mbuf
257 	 * segment.
258 	 */
259 	uint32_t offset;
260 	/** The total data length to be processed in one operation, in bytes.
261 	 *
262 	 * In case the mbuf data is representing one CB, this is the length of
263 	 * the CB undergoing the operation.
264 	 * If it's for multiple CBs, this is the total length of those CBs
265 	 * undergoing the operation.
266 	 * If it is for one TB, this is the total length of the TB under
267 	 * operation.
268 	 *
269 	 * In case of chained mbuf, this data length includes the lengths of the
270 	 * "scattered" data segments undergoing the operation.
271 	 */
272 	uint32_t length;
273 };
274 
275 /** Turbo decode code block parameters */
276 struct rte_bbdev_op_dec_turbo_cb_params {
277 	/** The K size of the input CB, in bits [40:6144], as specified in
278 	 * 3GPP TS 36.212.
279 	 * This size is inclusive of CRC bits, regardless whether it was
280 	 * pre-calculated by the application or not.
281 	 */
282 	uint16_t k;
283 	/** The E length of the CB rate matched LLR output, in bytes, as in
284 	 * 3GPP TS 36.212.
285 	 */
286 	uint32_t e;
287 };
288 
289 /** LDPC decode code block parameters */
290 struct rte_bbdev_op_dec_ldpc_cb_params {
291 	/** Rate matching output sequence length in bits or LLRs.
292 	 *  [3GPP TS38.212, section 5.4.2.1]
293 	 */
294 	uint32_t e;
295 };
296 
297 /** Turbo decode transport block parameters */
298 struct rte_bbdev_op_dec_turbo_tb_params {
299 	/** The K- size of the input CB, in bits [40:6144], that is in the
300 	 * Turbo operation when r < C-, as in 3GPP TS 36.212.
301 	 */
302 	uint16_t k_neg;
303 	/** The K+ size of the input CB, in bits [40:6144], that is in the
304 	 * Turbo operation when r >= C-, as in 3GPP TS 36.212.
305 	 */
306 	uint16_t k_pos;
307 	/** The number of CBs that have K- size, [0:63] */
308 	uint8_t c_neg;
309 	/** The total number of CBs in the TB,
310 	 * [1:RTE_BBDEV_TURBO_MAX_CODE_BLOCKS]
311 	 */
312 	uint8_t c;
313 	/** The number of CBs that uses Ea before switching to Eb, [0:63] */
314 	uint8_t cab;
315 	/** The E size of the CB rate matched output to use in the Turbo
316 	 * operation when r < cab
317 	 */
318 	uint32_t ea;
319 	/** The E size of the CB rate matched output to use in the Turbo
320 	 * operation when r >= cab
321 	 */
322 	uint32_t eb;
323 	/** The index of the first CB in the inbound mbuf data, default is 0 */
324 	uint8_t r;
325 };
326 
327 /** LDPC decode transport block parameters */
328 struct rte_bbdev_op_dec_ldpc_tb_params {
329 	/** Ea, length after rate matching in bits, r < cab.
330 	 *  [3GPP TS38.212, section 5.4.2.1]
331 	 */
332 	uint32_t ea;
333 	/** Eb, length after rate matching in bits, r >= cab.
334 	 *  [3GPP TS38.212, section 5.4.2.1]
335 	 */
336 	uint32_t eb;
337 	/** The total number of CBs in the TB or partial TB
338 	 * [1:RTE_BBDEV_LDPC_MAX_CODE_BLOCKS]
339 	 */
340 	uint8_t c;
341 	/** The index of the first CB in the inbound mbuf data, default is 0 */
342 	uint8_t r;
343 	/** The number of CBs that use Ea before switching to Eb, [0:63] */
344 	uint8_t cab;
345 };
346 
347 /** Operation structure for Turbo decode.
348  * An operation can be performed on one CB at a time "CB-mode".
349  * An operation can be performed on one or multiple CBs that logically
350  * belong to one TB "TB-mode".
351  * The provided K size parameter of the CB is its size coming from the
352  * decode operation.
353  * CRC24A/B check is requested by the application by setting the flag
354  * RTE_BBDEV_TURBO_CRC_TYPE_24B for CRC24B check or CRC24A otherwise.
355  * In TB-mode, BBDEV concatenates the decoded CBs one next to the other with
356  * relevant CRC24B in between.
357  *
358  * The input encoded CB data is the Virtual Circular Buffer data stream, wk,
359  * with the null padding included as described in 3GPP TS 36.212
360  * section 5.1.4.1.2 and shown in 3GPP TS 36.212 section 5.1.4.1 Figure 5.1.4-1.
361  * The size of the virtual circular buffer is 3*Kpi, where Kpi is the 32 byte
362  * aligned value of K, as specified in 3GPP TS 36.212 section 5.1.4.1.1.
363  *
364  * Each byte in the input circular buffer is the LLR value of each bit of the
365  * original CB.
366  *
367  * Hard output is a mandatory capability that all BBDEV PMDs support. This is
368  * the decoded CBs of K sizes (CRC24A/B is the last 24-bit in each decoded CB).
369  * Soft output is an optional capability for BBDEV PMDs. If supported, an LLR
370  * rate matched output is computed in the soft_output buffer structure.
371  *
372  * The output mbuf data structure is expected to be allocated by the
373  * application with enough room for the output data.
374  */
375 struct rte_bbdev_op_turbo_dec {
376 	/** The Virtual Circular Buffer, wk, size 3*Kpi for each CB */
377 	struct rte_bbdev_op_data input;
378 	/** The hard decisions buffer for the decoded output,
379 	 * size K for each CB
380 	 */
381 	struct rte_bbdev_op_data hard_output;
382 	/** The soft LLR output buffer - optional */
383 	struct rte_bbdev_op_data soft_output;
384 
385 	/** Flags from rte_bbdev_op_td_flag_bitmasks */
386 	uint32_t op_flags;
387 
388 	/** Rv index for rate matching [0:3] */
389 	uint8_t rv_index;
390 	/** The minimum number of iterations to perform in decoding all CBs in
391 	 * this operation - input
392 	 */
393 	uint8_t iter_min:4;
394 	/** The maximum number of iterations to perform in decoding all CBs in
395 	 * this operation - input
396 	 */
397 	uint8_t iter_max:4;
398 	/** The maximum number of iterations that were performed in decoding
399 	 * all CBs in this decode operation - output
400 	 */
401 	uint8_t iter_count;
402 	/** 5 bit extrinsic scale (scale factor on extrinsic info) */
403 	uint8_t ext_scale;
404 	/** Number of MAP engines to use in decode,
405 	 *  must be power of 2 (or 0 to auto-select)
406 	 */
407 	uint8_t num_maps;
408 
409 	/** [0 - TB : 1 - CB] */
410 	uint8_t code_block_mode;
411 	union {
412 		/** Struct which stores Code Block specific parameters */
413 		struct rte_bbdev_op_dec_turbo_cb_params cb_params;
414 		/** Struct which stores Transport Block specific parameters */
415 		struct rte_bbdev_op_dec_turbo_tb_params tb_params;
416 	};
417 };
418 
419 /** Operation structure for LDPC decode.
420  *
421  * An operation can be performed on one CB at a time "CB-mode".
422  * An operation can also be performed on one or multiple CBs that logically
423  * belong to a TB "TB-mode" (Currently not supported).
424  *
425  * The input encoded CB data is the Virtual Circular Buffer data stream.
426  *
427  * Each byte in the input circular buffer is the LLR value of each bit of the
428  * original CB.
429  *
430  * Hard output is a mandatory capability that all BBDEV PMDs support. This is
431  * the decoded CBs (CRC24A/B is the last 24-bit in each decoded CB).
432  *
433  * Soft output is an optional capability for BBDEV PMDs. If supported, an LLR
434  * rate matched output is computed in the soft_output buffer structure.
435  * These are A Posteriori Probabilities (APP) LLR samples for coded bits.
436  *
437  * HARQ combined output is an optional capability for BBDEV PMDs.
438  * If supported, a LLR output is streamed to the harq_combined_output
439  * buffer.
440  *
441  * HARQ combined input is an optional capability for BBDEV PMDs.
442  * If supported, a LLR input is streamed from the harq_combined_input
443  * buffer.
444  *
445  * The output mbuf data structure is expected to be allocated by the
446  * application with enough room for the output data.
447  */
448 struct rte_bbdev_op_ldpc_dec {
449 	/** The Virtual Circular Buffer for this code block, one LLR
450 	 * per bit of the original CB.
451 	 */
452 	struct rte_bbdev_op_data input;
453 	/** The hard decisions buffer for the decoded output,
454 	 * size K for each CB
455 	 */
456 	struct rte_bbdev_op_data hard_output;
457 	/** The soft LLR output LLR stream buffer - optional */
458 	struct rte_bbdev_op_data soft_output;
459 	/** The HARQ combined LLR stream input buffer - optional */
460 	struct rte_bbdev_op_data harq_combined_input;
461 	/** The HARQ combined LLR stream output buffer - optional */
462 	struct rte_bbdev_op_data harq_combined_output;
463 
464 	/** Flags from rte_bbdev_op_ldpcdec_flag_bitmasks */
465 	uint32_t op_flags;
466 
467 	/** Rate matching redundancy version
468 	 *  [3GPP TS38.212, section 5.4.2.1]
469 	 */
470 	uint8_t rv_index;
471 	/** The maximum number of iterations to perform in decoding CB in
472 	 *  this operation - input
473 	 */
474 	uint8_t iter_max;
475 	/** The number of iterations that were performed in decoding
476 	 * CB in this decode operation - output
477 	 */
478 	uint8_t iter_count;
479 	/** 1: LDPC Base graph 1, 2: LDPC Base graph 2.
480 	 * [3GPP TS38.212, section 5.2.2]
481 	 */
482 	uint8_t basegraph;
483 	/** Zc, LDPC lifting size.
484 	 *  [3GPP TS38.212, section 5.2.2]
485 	 */
486 	uint16_t z_c;
487 	/** Ncb, length of the circular buffer in bits.
488 	 *  [3GPP TS38.212, section 5.4.2.1]
489 	 */
490 	uint16_t n_cb;
491 	/** Qm, modulation order {1,2,4,6,8}.
492 	 *  [3GPP TS38.212, section 5.4.2.2]
493 	 */
494 	uint8_t q_m;
495 	/** Number of Filler bits, n_filler = K – K’
496 	 *  [3GPP TS38.212 section 5.2.2]
497 	 */
498 	uint16_t n_filler;
499 	/** [0 - TB : 1 - CB] */
500 	uint8_t code_block_mode;
501 	union {
502 		/** Struct which stores Code Block specific parameters */
503 		struct rte_bbdev_op_dec_ldpc_cb_params cb_params;
504 		/** Struct which stores Transport Block specific parameters */
505 		struct rte_bbdev_op_dec_ldpc_tb_params tb_params;
506 	};
507 };
508 
509 /** Turbo encode code block parameters */
510 struct rte_bbdev_op_enc_turbo_cb_params {
511 	/** The K size of the input CB, in bits [40:6144], as specified in
512 	 * 3GPP TS 36.212.
513 	 * This size is inclusive of CRC24A, regardless whether it was
514 	 * pre-calculated by the application or not.
515 	 */
516 	uint16_t k;
517 	/** The E length of the CB rate matched output, in bits, as in
518 	 * 3GPP TS 36.212.
519 	 */
520 	uint32_t e;
521 	/** The Ncb soft buffer size of the CB rate matched output [K:3*Kpi],
522 	 * in bits, as specified in 3GPP TS 36.212.
523 	 */
524 	uint16_t ncb;
525 };
526 
527 /** Turbo encode transport block parameters */
528 struct rte_bbdev_op_enc_turbo_tb_params {
529 	/** The K- size of the input CB, in bits [40:6144], that is in the
530 	 * Turbo operation when r < C-, as in 3GPP TS 36.212.
531 	 * This size is inclusive of CRC24B, regardless whether it was
532 	 * pre-calculated and appended by the application or not.
533 	 */
534 	uint16_t k_neg;
535 	/** The K+ size of the input CB, in bits [40:6144], that is in the
536 	 * Turbo operation when r >= C-, as in 3GPP TS 36.212.
537 	 * This size is inclusive of CRC24B, regardless whether it was
538 	 * pre-calculated and appended by the application or not.
539 	 */
540 	uint16_t k_pos;
541 	/** The number of CBs that have K- size, [0:63] */
542 	uint8_t c_neg;
543 	/** The total number of CBs in the TB,
544 	 * [1:RTE_BBDEV_TURBO_MAX_CODE_BLOCKS]
545 	 */
546 	uint8_t c;
547 	/** The number of CBs that uses Ea before switching to Eb, [0:63] */
548 	uint8_t cab;
549 	/** The E size of the CB rate matched output to use in the Turbo
550 	 * operation when r < cab
551 	 */
552 	uint32_t ea;
553 	/** The E size of the CB rate matched output to use in the Turbo
554 	 * operation when r >= cab
555 	 */
556 	uint32_t eb;
557 	/** The Ncb soft buffer size for the rate matched CB that is used in
558 	 * the Turbo operation when r < C-, [K:3*Kpi]
559 	 */
560 	uint16_t ncb_neg;
561 	/** The Ncb soft buffer size for the rate matched CB that is used in
562 	 * the Turbo operation when r >= C-, [K:3*Kpi]
563 	 */
564 	uint16_t ncb_pos;
565 	/** The index of the first CB in the inbound mbuf data, default is 0 */
566 	uint8_t r;
567 };
568 
569 /** LDPC encode code block parameters */
570 struct rte_bbdev_op_enc_ldpc_cb_params {
571 	/** E, length after rate matching in bits.
572 	 *  [3GPP TS38.212, section 5.4.2.1]
573 	 */
574 	uint32_t e;
575 };
576 
577 /** LDPC encode transport block parameters */
578 struct rte_bbdev_op_enc_ldpc_tb_params {
579 	/** Ea, length after rate matching in bits, r < cab.
580 	 *  [3GPP TS38.212, section 5.4.2.1]
581 	 */
582 	uint32_t ea;
583 	/** Eb, length after rate matching in bits, r >= cab.
584 	 *  [3GPP TS38.212, section 5.4.2.1]
585 	 */
586 	uint32_t eb;
587 	/** The total number of CBs in the TB or partial TB
588 	 * [1:RTE_BBDEV_LDPC_MAX_CODE_BLOCKS]
589 	 */
590 	uint8_t c;
591 	/** The index of the first CB in the inbound mbuf data, default is 0 */
592 	uint8_t r;
593 	/** The number of CBs that use Ea before switching to Eb, [0:63] */
594 	uint8_t cab;
595 };
596 
597 /** Operation structure for Turbo encode.
598  * An operation can be performed on one CB at a time "CB-mode".
599  * An operation can pbe erformd on one or multiple CBs that logically
600  * belong to one TB "TB-mode".
601  *
602  * In CB-mode, CRC24A/B is an optional operation. K size parameter is not
603  * affected by CRC24A/B inclusion, this only affects the inbound mbuf data
604  * length. Not all BBDEV PMDs are capable of CRC24A/B calculation. Flags
605  * RTE_BBDEV_TURBO_CRC_24A_ATTACH and RTE_BBDEV_TURBO_CRC_24B_ATTACH informs
606  * the application with relevant capability. These flags can be set in the
607  * op_flags parameter to indicate BBDEV to calculate and append CRC24A to CB
608  * before going forward with Turbo encoding.
609  *
610  * In TB-mode, CRC24A is assumed to be pre-calculated and appended to the
611  * inbound TB mbuf data buffer.
612  *
613  * The output mbuf data structure is expected to be allocated by the
614  * application with enough room for the output data.
615  */
616 struct rte_bbdev_op_turbo_enc {
617 	/** The input CB or TB data */
618 	struct rte_bbdev_op_data input;
619 	/** The rate matched CB or TB output buffer */
620 	struct rte_bbdev_op_data output;
621 	/** Flags from rte_bbdev_op_te_flag_bitmasks */
622 	uint32_t op_flags;
623 
624 	/** Rv index for rate matching [0:3] */
625 	uint8_t rv_index;
626 	/** [0 - TB : 1 - CB] */
627 	uint8_t code_block_mode;
628 	union {
629 		/** Struct which stores Code Block specific parameters */
630 		struct rte_bbdev_op_enc_turbo_cb_params cb_params;
631 		/** Struct which stores Transport Block specific parameters */
632 		struct rte_bbdev_op_enc_turbo_tb_params tb_params;
633 	};
634 };
635 
636 /** Operation structure for LDPC encode.
637  * An operation can be performed on one CB at a time "CB-mode".
638  * An operation can be performed on one or multiple CBs that logically
639  * belong to a TB "TB-mode".
640  *
641  * The input data is the CB or TB input to the decoder.
642  *
643  * The output data is the ratematched CB or TB data, or the output after
644  * bit-selection if RTE_BBDEV_LDPC_INTERLEAVER_BYPASS is set.
645  *
646  * The output mbuf data structure is expected to be allocated by the
647  * application with enough room for the output data.
648  */
649 struct rte_bbdev_op_ldpc_enc {
650 	/** The input TB or CB data */
651 	struct rte_bbdev_op_data input;
652 	/** The rate matched TB or CB output buffer */
653 	struct rte_bbdev_op_data output;
654 
655 	/** Flags from rte_bbdev_op_ldpcenc_flag_bitmasks */
656 	uint32_t op_flags;
657 
658 	/** Rate matching redundancy version */
659 	uint8_t rv_index;
660 	/** 1: LDPC Base graph 1, 2: LDPC Base graph 2.
661 	 *  [3GPP TS38.212, section 5.2.2]
662 	 */
663 	uint8_t basegraph;
664 	/** Zc, LDPC lifting size.
665 	 *  [3GPP TS38.212, section 5.2.2]
666 	 */
667 	uint16_t z_c;
668 	/** Ncb, length of the circular buffer in bits.
669 	 *  [3GPP TS38.212, section 5.4.2.1]
670 	 */
671 	uint16_t n_cb;
672 	/** Qm, modulation order {2,4,6,8,10}.
673 	 *  [3GPP TS38.212, section 5.4.2.2]
674 	 */
675 	uint8_t q_m;
676 	/** Number of Filler bits, n_filler = K – K’
677 	 *  [3GPP TS38.212 section 5.2.2]
678 	 */
679 	uint16_t n_filler;
680 	/** [0 - TB : 1 - CB] */
681 	uint8_t code_block_mode;
682 	union {
683 		/** Struct which stores Code Block specific parameters */
684 		struct rte_bbdev_op_enc_ldpc_cb_params cb_params;
685 		/** Struct which stores Transport Block specific parameters */
686 		struct rte_bbdev_op_enc_ldpc_tb_params tb_params;
687 	};
688 };
689 
690 /** List of the capabilities for the Turbo Decoder */
691 struct rte_bbdev_op_cap_turbo_dec {
692 	/** Flags from rte_bbdev_op_td_flag_bitmasks */
693 	uint32_t capability_flags;
694 	/** Maximal LLR absolute value. Acceptable LLR values lie in range
695 	 * [-max_llr_modulus, max_llr_modulus].
696 	 */
697 	int8_t max_llr_modulus;
698 	/** Num input code block buffers */
699 	uint8_t num_buffers_src;  /**< Num input code block buffers */
700 	/** Num hard output code block buffers */
701 	uint8_t num_buffers_hard_out;
702 	/** Num soft output code block buffers if supported by the driver */
703 	uint8_t num_buffers_soft_out;
704 };
705 
706 /** List of the capabilities for the Turbo Encoder */
707 struct rte_bbdev_op_cap_turbo_enc {
708 	/** Flags from rte_bbdev_op_te_flag_bitmasks */
709 	uint32_t capability_flags;
710 	/** Num input code block buffers */
711 	uint8_t num_buffers_src;
712 	/** Num output code block buffers */
713 	uint8_t num_buffers_dst;
714 };
715 
716 /** List of the capabilities for the LDPC Decoder */
717 struct rte_bbdev_op_cap_ldpc_dec {
718 	/** Flags from rte_bbdev_op_ldpcdec_flag_bitmasks */
719 	uint32_t capability_flags;
720 	/** LLR size in bits. LLR is a two’s complement number. */
721 	int8_t llr_size;
722 	/** LLR numbers of decimals bit for arithmetic representation */
723 	int8_t llr_decimals;
724 	/** Num input code block buffers */
725 	uint16_t num_buffers_src;
726 	/** Num hard output code block buffers */
727 	uint16_t num_buffers_hard_out;
728 	/** Num soft output code block buffers if supported by the driver */
729 	uint16_t num_buffers_soft_out;
730 };
731 
732 /** List of the capabilities for the LDPC Encoder */
733 struct rte_bbdev_op_cap_ldpc_enc {
734 	/** Flags from rte_bbdev_op_ldpcenc_flag_bitmasks */
735 	uint32_t capability_flags;
736 	/** Num input code block buffers */
737 	uint16_t num_buffers_src;
738 	/** Num output code block buffers */
739 	uint16_t num_buffers_dst;
740 };
741 
742 /** Different operation types supported by the device */
743 enum rte_bbdev_op_type {
744 	RTE_BBDEV_OP_NONE,  /**< Dummy operation that does nothing */
745 	RTE_BBDEV_OP_TURBO_DEC,  /**< Turbo decode */
746 	RTE_BBDEV_OP_TURBO_ENC,  /**< Turbo encode */
747 	RTE_BBDEV_OP_LDPC_DEC,  /**< LDPC decode */
748 	RTE_BBDEV_OP_LDPC_ENC,  /**< LDPC encode */
749 	RTE_BBDEV_OP_TYPE_COUNT,  /**< Count of different op types */
750 };
751 
752 /** Bit indexes of possible errors reported through status field */
753 enum {
754 	RTE_BBDEV_DRV_ERROR,
755 	RTE_BBDEV_DATA_ERROR,
756 	RTE_BBDEV_CRC_ERROR,
757 	RTE_BBDEV_SYNDROME_ERROR
758 };
759 
760 /** Structure specifying a single encode operation */
761 struct rte_bbdev_enc_op {
762 	/** Status of operation that was performed */
763 	int status;
764 	/** Mempool which op instance is in */
765 	struct rte_mempool *mempool;
766 	/** Opaque pointer for user data */
767 	void *opaque_data;
768 	union {
769 		/** Contains turbo decoder specific parameters */
770 		struct rte_bbdev_op_turbo_enc turbo_enc;
771 		/** Contains LDPC decoder specific parameters */
772 		struct rte_bbdev_op_ldpc_enc ldpc_enc;
773 	};
774 };
775 
776 /** Structure specifying a single decode operation */
777 struct rte_bbdev_dec_op {
778 	/** Status of operation that was performed */
779 	int status;
780 	/** Mempool which op instance is in */
781 	struct rte_mempool *mempool;
782 	/** Opaque pointer for user data */
783 	void *opaque_data;
784 	union {
785 		/** Contains turbo decoder specific parameters */
786 		struct rte_bbdev_op_turbo_dec turbo_dec;
787 		/** Contains LDPC decoder specific parameters */
788 		struct rte_bbdev_op_ldpc_dec ldpc_dec;
789 	};
790 };
791 
792 /** Operation capabilities supported by a device */
793 struct rte_bbdev_op_cap {
794 	enum rte_bbdev_op_type type;  /**< Type of operation */
795 	union {
796 		struct rte_bbdev_op_cap_turbo_dec turbo_dec;
797 		struct rte_bbdev_op_cap_turbo_enc turbo_enc;
798 		struct rte_bbdev_op_cap_ldpc_dec ldpc_dec;
799 		struct rte_bbdev_op_cap_ldpc_enc ldpc_enc;
800 	} cap;  /**< Operation-type specific capabilities */
801 };
802 
803 /** @internal Private data structure stored with operation pool. */
804 struct rte_bbdev_op_pool_private {
805 	enum rte_bbdev_op_type type;  /**< Type of operations in a pool */
806 };
807 
808 /**
809  * Converts queue operation type from enum to string
810  *
811  * @param op_type
812  *   Operation type as enum
813  *
814  * @returns
815  *   Operation type as string or NULL if op_type is invalid
816  *
817  */
818 __rte_experimental
819 const char*
820 rte_bbdev_op_type_str(enum rte_bbdev_op_type op_type);
821 
822 /**
823  * Creates a bbdev operation mempool
824  *
825  * @param name
826  *   Pool name.
827  * @param type
828  *   Operation type, use RTE_BBDEV_OP_NONE for a pool which supports all
829  *   operation types.
830  * @param num_elements
831  *   Number of elements in the pool.
832  * @param cache_size
833  *   Number of elements to cache on an lcore, see rte_mempool_create() for
834  *   further details about cache size.
835  * @param socket_id
836  *   Socket to allocate memory on.
837  *
838  * @return
839  *   - Pointer to a mempool on success,
840  *   - NULL pointer on failure.
841  */
842 __rte_experimental
843 struct rte_mempool *
844 rte_bbdev_op_pool_create(const char *name, enum rte_bbdev_op_type type,
845 		unsigned int num_elements, unsigned int cache_size,
846 		int socket_id);
847 
848 /**
849  * Bulk allocate encode operations from a mempool with parameter defaults reset.
850  *
851  * @param mempool
852  *   Operation mempool, created by rte_bbdev_op_pool_create().
853  * @param ops
854  *   Output array to place allocated operations
855  * @param num_ops
856  *   Number of operations to allocate
857  *
858  * @returns
859  *   - 0 on success
860  *   - EINVAL if invalid mempool is provided
861  */
862 __rte_experimental
863 static inline int
864 rte_bbdev_enc_op_alloc_bulk(struct rte_mempool *mempool,
865 		struct rte_bbdev_enc_op **ops, uint16_t num_ops)
866 {
867 	struct rte_bbdev_op_pool_private *priv;
868 	int ret;
869 
870 	/* Check type */
871 	priv = (struct rte_bbdev_op_pool_private *)
872 			rte_mempool_get_priv(mempool);
873 	if (unlikely((priv->type != RTE_BBDEV_OP_TURBO_ENC) &&
874 					(priv->type != RTE_BBDEV_OP_LDPC_ENC)))
875 		return -EINVAL;
876 
877 	/* Get elements */
878 	ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
879 	if (unlikely(ret < 0))
880 		return ret;
881 
882 	return 0;
883 }
884 
885 /**
886  * Bulk allocate decode operations from a mempool with parameter defaults reset.
887  *
888  * @param mempool
889  *   Operation mempool, created by rte_bbdev_op_pool_create().
890  * @param ops
891  *   Output array to place allocated operations
892  * @param num_ops
893  *   Number of operations to allocate
894  *
895  * @returns
896  *   - 0 on success
897  *   - EINVAL if invalid mempool is provided
898  */
899 __rte_experimental
900 static inline int
901 rte_bbdev_dec_op_alloc_bulk(struct rte_mempool *mempool,
902 		struct rte_bbdev_dec_op **ops, uint16_t num_ops)
903 {
904 	struct rte_bbdev_op_pool_private *priv;
905 	int ret;
906 
907 	/* Check type */
908 	priv = (struct rte_bbdev_op_pool_private *)
909 			rte_mempool_get_priv(mempool);
910 	if (unlikely((priv->type != RTE_BBDEV_OP_TURBO_DEC) &&
911 					(priv->type != RTE_BBDEV_OP_LDPC_DEC)))
912 		return -EINVAL;
913 
914 	/* Get elements */
915 	ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
916 	if (unlikely(ret < 0))
917 		return ret;
918 
919 	return 0;
920 }
921 
922 /**
923  * Free decode operation structures that were allocated by
924  * rte_bbdev_dec_op_alloc_bulk().
925  * All structures must belong to the same mempool.
926  *
927  * @param ops
928  *   Operation structures
929  * @param num_ops
930  *   Number of structures
931  */
932 __rte_experimental
933 static inline void
934 rte_bbdev_dec_op_free_bulk(struct rte_bbdev_dec_op **ops, unsigned int num_ops)
935 {
936 	if (num_ops > 0)
937 		rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
938 }
939 
940 /**
941  * Free encode operation structures that were allocated by
942  * rte_bbdev_enc_op_alloc_bulk().
943  * All structures must belong to the same mempool.
944  *
945  * @param ops
946  *   Operation structures
947  * @param num_ops
948  *   Number of structures
949  */
950 __rte_experimental
951 static inline void
952 rte_bbdev_enc_op_free_bulk(struct rte_bbdev_enc_op **ops, unsigned int num_ops)
953 {
954 	if (num_ops > 0)
955 		rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
956 }
957 
958 #ifdef __cplusplus
959 }
960 #endif
961 
962 #endif /* _RTE_BBDEV_OP_H_ */
963