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