New upstream version 18.02
[deb_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 #define RTE_BBDEV_MAX_CODE_BLOCKS 64
29
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 =
41          * max_iteration + 0.5
42          */
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
46          */
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
56          * bit '0'.
57          * This is mutually exclusive with RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN
58          * when used to formalize the input data format.
59          */
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
63          * bit '0'.
64          * This is mutually exclusive with RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN
65          * when used to formalize the input data format.
66          */
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
70          * bit '0'.
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.
74          */
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
78          * bit '0'.
79          * This is mutually exclusive with
80          * RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT when used to formalize the
81          * input data format.
82          */
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.
86          */
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)
90 };
91
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)
106 };
107
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.
111          *
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.
117          *
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
122          * one TB.
123          *
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.
135          *
136          * The output mbuf data though is always one segment, even if the input
137          * was a chained mbuf.
138          */
139         struct rte_mbuf *data;
140         /**< The starting point of the BBDEV (encode/decode) operation,
141          * in bytes.
142          *
143          * BBDEV starts to read data past this offset.
144          * In case of chained mbuf, this offset applies only to the first mbuf
145          * segment.
146          */
147         uint32_t offset;
148         /**< The total data length to be processed in one operation, in bytes.
149          *
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
155          * operation.
156          *
157          * In case of chained mbuf, this data length includes the lengths of the
158          * "scattered" data segments undergoing the operation.
159          */
160         uint32_t length;
161 };
162
163 struct rte_bbdev_op_dec_cb_params {
164         /**< The K size of the input CB, in bits [40:6144], as specified in
165          * 3GPP TS 36.212.
166          * This size is inclusive of CRC bits, regardless whether it was
167          * pre-calculated by the application or not.
168          */
169         uint16_t k;
170         /**< The E length of the CB rate matched LLR output, in bytes, as in
171          * 3GPP TS 36.212.
172          */
173         uint32_t e;
174 };
175
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.
179          */
180         uint16_t k_neg;
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.
183          */
184         uint16_t k_pos;
185         /**< The number of CBs that have K- size, [0:63] */
186         uint8_t c_neg;
187         /**< The total number of CBs in the TB, [1:RTE_BBDEV_MAX_CODE_BLOCKS] */
188         uint8_t c;
189         /**< The number of CBs that uses Ea before switching to Eb, [0:63] */
190         uint8_t cab;
191         /**< The E size of the CB rate matched output to use in the Turbo
192          * operation when r < cab
193          */
194         uint32_t ea;
195         /**< The E size of the CB rate matched output to use in the Turbo
196          * operation when r >= cab
197          */
198         uint32_t eb;
199 };
200
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
206  * decode operation.
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.
211  *
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.
217  *
218  * Each byte in the input circular buffer is the LLR value of each bit of the
219  * original CB.
220  *
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.
225  *
226  * The output mbuf data structure is expected to be allocated by the
227  * application with enough room for the output data.
228  */
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,
233          * size K for each CB
234          */
235         struct rte_bbdev_op_data hard_output;
236         /**< The soft LLR output buffer - optional */
237         struct rte_bbdev_op_data soft_output;
238
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
243          */
244         uint8_t iter_min:4;
245         /**< The maximum number of iterations to perform in decoding all CBs in
246          * this operation - input
247          */
248         uint8_t iter_max:4;
249         /**< The maximum number of iterations that were perform in decoding all
250          * CBs in this decode operation - output
251          */
252         uint8_t iter_count;
253         /**< 5 bit extrinsic scale (scale factor on extrinsic info) */
254         uint8_t ext_scale;
255         /**< Number of MAP engines to use in decode,
256          * must be power of 2 (or 0 to auto-select)
257          */
258         uint8_t num_maps;
259
260         uint8_t code_block_mode; /**< [0 - TB : 1 - CB] */
261         union {
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;
266         };
267 };
268
269 struct rte_bbdev_op_enc_cb_params {
270         /**< The K size of the input CB, in bits [40:6144], as specified in
271          * 3GPP TS 36.212.
272          * This size is inclusive of CRC24A, regardless whether it was
273          * pre-calculated by the application or not.
274          */
275         uint16_t k;
276         /**< The E length of the CB rate matched output, in bits, as in
277          * 3GPP TS 36.212.
278          */
279         uint32_t e;
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.
282          */
283         uint16_t ncb;
284 };
285
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.
291          */
292         uint16_t k_neg;
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.
297          */
298         uint16_t k_pos;
299         /**< The number of CBs that have K- size, [0:63] */
300         uint8_t c_neg;
301         /**< The total number of CBs in the TB, [1:RTE_BBDEV_MAX_CODE_BLOCKS] */
302         uint8_t c;
303         /**< The number of CBs that uses Ea before switching to Eb, [0:63] */
304         uint8_t cab;
305         /**< The E size of the CB rate matched output to use in the Turbo
306          * operation when r < cab
307          */
308         uint32_t ea;
309         /**< The E size of the CB rate matched output to use in the Turbo
310          * operation when r >= cab
311          */
312         uint32_t eb;
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]
315          */
316         uint16_t ncb_neg;
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]
319          */
320         uint16_t ncb_pos;
321         /**< The index of the first CB in the inbound mbuf data, default is 0 */
322         uint8_t r;
323 };
324
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".
329  *
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.
337  *
338  * In TB-mode, CRC24A is assumed to be pre-calculated and appended to the
339  * inbound TB mbuf data buffer.
340  *
341  * The output mbuf data structure is expected to be allocated by the
342  * application with enough room for the output data.
343  */
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;
349
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] */
352
353         uint8_t code_block_mode; /**< [0 - TB : 1 - CB] */
354         union {
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;
359         };
360 };
361
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;
371 };
372
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 */
379 };
380
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 */
387 };
388
389 /**< Bit indexes of possible errors reported through status field */
390 enum {
391         RTE_BBDEV_DRV_ERROR,
392         RTE_BBDEV_DATA_ERROR,
393         RTE_BBDEV_CRC_ERROR,
394 };
395
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;
403 };
404
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;
412 };
413
414 /**< Operation capabilities supported by a device */
415 struct rte_bbdev_op_cap {
416         enum rte_bbdev_op_type type;  /**< Type of operation */
417         union {
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 */
421 };
422
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 */
426 };
427
428 /**
429  * Converts queue operation type from enum to string
430  *
431  * @param op_type
432  *   Operation type as enum
433  *
434  * @returns
435  *   Operation type as string or NULL if op_type is invalid
436  *
437  */
438 const char*
439 rte_bbdev_op_type_str(enum rte_bbdev_op_type op_type);
440
441 /**
442  * Creates a bbdev operation mempool
443  *
444  * @param name
445  *   Pool name.
446  * @param type
447  *   Operation type, use RTE_BBDEV_OP_NONE for a pool which supports all
448  *   operation types.
449  * @param num_elements
450  *   Number of elements in the pool.
451  * @param cache_size
452  *   Number of elements to cache on an lcore, see rte_mempool_create() for
453  *   further details about cache size.
454  * @param socket_id
455  *   Socket to allocate memory on.
456  *
457  * @return
458  *   - Pointer to a mempool on success,
459  *   - NULL pointer on failure.
460  */
461 struct rte_mempool *
462 rte_bbdev_op_pool_create(const char *name, enum rte_bbdev_op_type type,
463                 unsigned int num_elements, unsigned int cache_size,
464                 int socket_id);
465
466 /**
467  * Bulk allocate encode operations from a mempool with parameter defaults reset.
468  *
469  * @param mempool
470  *   Operation mempool, created by rte_bbdev_op_pool_create().
471  * @param ops
472  *   Output array to place allocated operations
473  * @param num_ops
474  *   Number of operations to allocate
475  *
476  * @returns
477  *   - 0 on success
478  *   - EINVAL if invalid mempool is provided
479  */
480 static inline int
481 rte_bbdev_enc_op_alloc_bulk(struct rte_mempool *mempool,
482                 struct rte_bbdev_enc_op **ops, uint16_t num_ops)
483 {
484         struct rte_bbdev_op_pool_private *priv;
485         int ret;
486
487         /* Check type */
488         priv = (struct rte_bbdev_op_pool_private *)
489                         rte_mempool_get_priv(mempool);
490         if (unlikely(priv->type != RTE_BBDEV_OP_TURBO_ENC))
491                 return -EINVAL;
492
493         /* Get elements */
494         ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
495         if (unlikely(ret < 0))
496                 return ret;
497
498         return 0;
499 }
500
501 /**
502  * Bulk allocate decode operations from a mempool with parameter defaults reset.
503  *
504  * @param mempool
505  *   Operation mempool, created by rte_bbdev_op_pool_create().
506  * @param ops
507  *   Output array to place allocated operations
508  * @param num_ops
509  *   Number of operations to allocate
510  *
511  * @returns
512  *   - 0 on success
513  *   - EINVAL if invalid mempool is provided
514  */
515 static inline int
516 rte_bbdev_dec_op_alloc_bulk(struct rte_mempool *mempool,
517                 struct rte_bbdev_dec_op **ops, uint16_t num_ops)
518 {
519         struct rte_bbdev_op_pool_private *priv;
520         int ret;
521
522         /* Check type */
523         priv = (struct rte_bbdev_op_pool_private *)
524                         rte_mempool_get_priv(mempool);
525         if (unlikely(priv->type != RTE_BBDEV_OP_TURBO_DEC))
526                 return -EINVAL;
527
528         /* Get elements */
529         ret = rte_mempool_get_bulk(mempool, (void **)ops, num_ops);
530         if (unlikely(ret < 0))
531                 return ret;
532
533         return 0;
534 }
535
536 /**
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.
540  *
541  * @param ops
542  *   Operation structures
543  * @param num_ops
544  *   Number of structures
545  */
546 static inline void
547 rte_bbdev_dec_op_free_bulk(struct rte_bbdev_dec_op **ops, unsigned int num_ops)
548 {
549         if (num_ops > 0)
550                 rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
551 }
552
553 /**
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.
557  *
558  * @param ops
559  *   Operation structures
560  * @param num_ops
561  *   Number of structures
562  */
563 static inline void
564 rte_bbdev_enc_op_free_bulk(struct rte_bbdev_enc_op **ops, unsigned int num_ops)
565 {
566         if (num_ops > 0)
567                 rte_mempool_put_bulk(ops[0]->mempool, (void **)ops, num_ops);
568 }
569
570 #ifdef __cplusplus
571 }
572 #endif
573
574 #endif /* _RTE_BBDEV_OP_H_ */