xref: /dpdk/drivers/baseband/turbo_sw/bbdev_turbo_software.c (revision 1ef7e1819194dc58d72b5b6d03bfdff59dfecf5a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #include <string.h>
6 
7 #include <rte_common.h>
8 #include <rte_bus_vdev.h>
9 #include <rte_malloc.h>
10 #include <rte_ring.h>
11 #include <rte_kvargs.h>
12 
13 #include <rte_bbdev.h>
14 #include <rte_bbdev_pmd.h>
15 
16 #include <phy_turbo.h>
17 #include <phy_crc.h>
18 #include <phy_rate_match.h>
19 #include <divide.h>
20 
21 #define DRIVER_NAME turbo_sw
22 
23 /* Turbo SW PMD logging ID */
24 static int bbdev_turbo_sw_logtype;
25 
26 /* Helper macro for logging */
27 #define rte_bbdev_log(level, fmt, ...) \
28 	rte_log(RTE_LOG_ ## level, bbdev_turbo_sw_logtype, fmt "\n", \
29 		##__VA_ARGS__)
30 
31 #define rte_bbdev_log_debug(fmt, ...) \
32 	rte_bbdev_log(DEBUG, RTE_STR(__LINE__) ":%s() " fmt, __func__, \
33 		##__VA_ARGS__)
34 
35 /* Number of columns in sub-block interleaver (36.212, section 5.1.4.1.1) */
36 #define C_SUBBLOCK (32)
37 #define MAX_TB_SIZE (391656)
38 #define MAX_CB_SIZE (6144)
39 #define MAX_KW (18528)
40 
41 /* private data structure */
42 struct bbdev_private {
43 	unsigned int max_nb_queues;  /**< Max number of queues */
44 };
45 
46 /*  Initialisation params structure that can be used by Turbo SW driver */
47 struct turbo_sw_params {
48 	int socket_id;  /*< Turbo SW device socket */
49 	uint16_t queues_num;  /*< Turbo SW device queues number */
50 };
51 
52 /* Accecptable params for Turbo SW devices */
53 #define TURBO_SW_MAX_NB_QUEUES_ARG  "max_nb_queues"
54 #define TURBO_SW_SOCKET_ID_ARG      "socket_id"
55 
56 static const char * const turbo_sw_valid_params[] = {
57 	TURBO_SW_MAX_NB_QUEUES_ARG,
58 	TURBO_SW_SOCKET_ID_ARG
59 };
60 
61 /* queue */
62 struct turbo_sw_queue {
63 	/* Ring for processed (encoded/decoded) operations which are ready to
64 	 * be dequeued.
65 	 */
66 	struct rte_ring *processed_pkts;
67 	/* Stores input for turbo encoder (used when CRC attachment is
68 	 * performed
69 	 */
70 	uint8_t *enc_in;
71 	/* Stores output from turbo encoder */
72 	uint8_t *enc_out;
73 	/* Alpha gamma buf for bblib_turbo_decoder() function */
74 	int8_t *ag;
75 	/* Temp buf for bblib_turbo_decoder() function */
76 	uint16_t *code_block;
77 	/* Input buf for bblib_rate_dematching_lte() function */
78 	uint8_t *deint_input;
79 	/* Output buf for bblib_rate_dematching_lte() function */
80 	uint8_t *deint_output;
81 	/* Output buf for bblib_turbodec_adapter_lte() function */
82 	uint8_t *adapter_output;
83 	/* Operation type of this queue */
84 	enum rte_bbdev_op_type type;
85 } __rte_cache_aligned;
86 
87 /* Calculate index based on Table 5.1.3-3 from TS34.212 */
88 static inline int32_t
89 compute_idx(uint16_t k)
90 {
91 	int32_t result = 0;
92 
93 	if (k < 40 || k > MAX_CB_SIZE)
94 		return -1;
95 
96 	if (k > 2048) {
97 		if ((k - 2048) % 64 != 0)
98 			result = -1;
99 
100 		result = 124 + (k - 2048) / 64;
101 	} else if (k <= 512) {
102 		if ((k - 40) % 8 != 0)
103 			result = -1;
104 
105 		result = (k - 40) / 8 + 1;
106 	} else if (k <= 1024) {
107 		if ((k - 512) % 16 != 0)
108 			result = -1;
109 
110 		result = 60 + (k - 512) / 16;
111 	} else { /* 1024 < k <= 2048 */
112 		if ((k - 1024) % 32 != 0)
113 			result = -1;
114 
115 		result = 92 + (k - 1024) / 32;
116 	}
117 
118 	return result;
119 }
120 
121 /* Read flag value 0/1 from bitmap */
122 static inline bool
123 check_bit(uint32_t bitmap, uint32_t bitmask)
124 {
125 	return bitmap & bitmask;
126 }
127 
128 /* Get device info */
129 static void
130 info_get(struct rte_bbdev *dev, struct rte_bbdev_driver_info *dev_info)
131 {
132 	struct bbdev_private *internals = dev->data->dev_private;
133 
134 	static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
135 		{
136 			.type = RTE_BBDEV_OP_TURBO_DEC,
137 			.cap.turbo_dec = {
138 				.capability_flags =
139 					RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE |
140 					RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN |
141 					RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN |
142 					RTE_BBDEV_TURBO_CRC_TYPE_24B |
143 					RTE_BBDEV_TURBO_EARLY_TERMINATION,
144 				.num_buffers_src = RTE_BBDEV_MAX_CODE_BLOCKS,
145 				.num_buffers_hard_out =
146 						RTE_BBDEV_MAX_CODE_BLOCKS,
147 				.num_buffers_soft_out = 0,
148 			}
149 		},
150 		{
151 			.type   = RTE_BBDEV_OP_TURBO_ENC,
152 			.cap.turbo_enc = {
153 				.capability_flags =
154 						RTE_BBDEV_TURBO_CRC_24B_ATTACH |
155 						RTE_BBDEV_TURBO_CRC_24A_ATTACH |
156 						RTE_BBDEV_TURBO_RATE_MATCH |
157 						RTE_BBDEV_TURBO_RV_INDEX_BYPASS,
158 				.num_buffers_src = RTE_BBDEV_MAX_CODE_BLOCKS,
159 				.num_buffers_dst = RTE_BBDEV_MAX_CODE_BLOCKS,
160 			}
161 		},
162 		RTE_BBDEV_END_OF_CAPABILITIES_LIST()
163 	};
164 
165 	static struct rte_bbdev_queue_conf default_queue_conf = {
166 		.queue_size = RTE_BBDEV_QUEUE_SIZE_LIMIT,
167 	};
168 
169 	static const enum rte_cpu_flag_t cpu_flag = RTE_CPUFLAG_SSE4_2;
170 
171 	default_queue_conf.socket = dev->data->socket_id;
172 
173 	dev_info->driver_name = RTE_STR(DRIVER_NAME);
174 	dev_info->max_num_queues = internals->max_nb_queues;
175 	dev_info->queue_size_lim = RTE_BBDEV_QUEUE_SIZE_LIMIT;
176 	dev_info->hardware_accelerated = false;
177 	dev_info->max_queue_priority = 0;
178 	dev_info->default_queue_conf = default_queue_conf;
179 	dev_info->capabilities = bbdev_capabilities;
180 	dev_info->cpu_flag_reqs = &cpu_flag;
181 	dev_info->min_alignment = 64;
182 
183 	rte_bbdev_log_debug("got device info from %u\n", dev->data->dev_id);
184 }
185 
186 /* Release queue */
187 static int
188 q_release(struct rte_bbdev *dev, uint16_t q_id)
189 {
190 	struct turbo_sw_queue *q = dev->data->queues[q_id].queue_private;
191 
192 	if (q != NULL) {
193 		rte_ring_free(q->processed_pkts);
194 		rte_free(q->enc_out);
195 		rte_free(q->enc_in);
196 		rte_free(q->ag);
197 		rte_free(q->code_block);
198 		rte_free(q->deint_input);
199 		rte_free(q->deint_output);
200 		rte_free(q->adapter_output);
201 		rte_free(q);
202 		dev->data->queues[q_id].queue_private = NULL;
203 	}
204 
205 	rte_bbdev_log_debug("released device queue %u:%u",
206 			dev->data->dev_id, q_id);
207 	return 0;
208 }
209 
210 /* Setup a queue */
211 static int
212 q_setup(struct rte_bbdev *dev, uint16_t q_id,
213 		const struct rte_bbdev_queue_conf *queue_conf)
214 {
215 	int ret;
216 	struct turbo_sw_queue *q;
217 	char name[RTE_RING_NAMESIZE];
218 
219 	/* Allocate the queue data structure. */
220 	q = rte_zmalloc_socket(RTE_STR(DRIVER_NAME), sizeof(*q),
221 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
222 	if (q == NULL) {
223 		rte_bbdev_log(ERR, "Failed to allocate queue memory");
224 		return -ENOMEM;
225 	}
226 
227 	/* Allocate memory for encoder output. */
228 	ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_enc_out%u:%u",
229 			dev->data->dev_id, q_id);
230 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
231 		rte_bbdev_log(ERR,
232 				"Creating queue name for device %u queue %u failed",
233 				dev->data->dev_id, q_id);
234 		return -ENAMETOOLONG;
235 	}
236 	q->enc_out = rte_zmalloc_socket(name,
237 			((MAX_TB_SIZE >> 3) + 3) * sizeof(*q->enc_out) * 3,
238 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
239 	if (q->enc_out == NULL) {
240 		rte_bbdev_log(ERR,
241 			"Failed to allocate queue memory for %s", name);
242 		goto free_q;
243 	}
244 
245 	/* Allocate memory for rate matching output. */
246 	ret = snprintf(name, RTE_RING_NAMESIZE,
247 			RTE_STR(DRIVER_NAME)"_enc_in%u:%u", dev->data->dev_id,
248 			q_id);
249 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
250 		rte_bbdev_log(ERR,
251 				"Creating queue name for device %u queue %u failed",
252 				dev->data->dev_id, q_id);
253 		return -ENAMETOOLONG;
254 	}
255 	q->enc_in = rte_zmalloc_socket(name,
256 			(MAX_CB_SIZE >> 3) * sizeof(*q->enc_in),
257 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
258 	if (q->enc_in == NULL) {
259 		rte_bbdev_log(ERR,
260 			"Failed to allocate queue memory for %s", name);
261 		goto free_q;
262 	}
263 
264 	/* Allocate memory for Aplha Gamma temp buffer. */
265 	ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_ag%u:%u",
266 			dev->data->dev_id, q_id);
267 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
268 		rte_bbdev_log(ERR,
269 				"Creating queue name for device %u queue %u failed",
270 				dev->data->dev_id, q_id);
271 		return -ENAMETOOLONG;
272 	}
273 	q->ag = rte_zmalloc_socket(name,
274 			MAX_CB_SIZE * 10 * sizeof(*q->ag),
275 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
276 	if (q->ag == NULL) {
277 		rte_bbdev_log(ERR,
278 			"Failed to allocate queue memory for %s", name);
279 		goto free_q;
280 	}
281 
282 	/* Allocate memory for code block temp buffer. */
283 	ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"_cb%u:%u",
284 			dev->data->dev_id, q_id);
285 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
286 		rte_bbdev_log(ERR,
287 				"Creating queue name for device %u queue %u failed",
288 				dev->data->dev_id, q_id);
289 		return -ENAMETOOLONG;
290 	}
291 	q->code_block = rte_zmalloc_socket(name,
292 			(6144 >> 3) * sizeof(*q->code_block),
293 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
294 	if (q->code_block == NULL) {
295 		rte_bbdev_log(ERR,
296 			"Failed to allocate queue memory for %s", name);
297 		goto free_q;
298 	}
299 
300 	/* Allocate memory for Deinterleaver input. */
301 	ret = snprintf(name, RTE_RING_NAMESIZE,
302 			RTE_STR(DRIVER_NAME)"_deint_input%u:%u",
303 			dev->data->dev_id, q_id);
304 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
305 		rte_bbdev_log(ERR,
306 				"Creating queue name for device %u queue %u failed",
307 				dev->data->dev_id, q_id);
308 		return -ENAMETOOLONG;
309 	}
310 	q->deint_input = rte_zmalloc_socket(name,
311 			MAX_KW * sizeof(*q->deint_input),
312 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
313 	if (q->deint_input == NULL) {
314 		rte_bbdev_log(ERR,
315 			"Failed to allocate queue memory for %s", name);
316 		goto free_q;
317 	}
318 
319 	/* Allocate memory for Deinterleaver output. */
320 	ret = snprintf(name, RTE_RING_NAMESIZE,
321 			RTE_STR(DRIVER_NAME)"_deint_output%u:%u",
322 			dev->data->dev_id, q_id);
323 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
324 		rte_bbdev_log(ERR,
325 				"Creating queue name for device %u queue %u failed",
326 				dev->data->dev_id, q_id);
327 		return -ENAMETOOLONG;
328 	}
329 	q->deint_output = rte_zmalloc_socket(NULL,
330 			MAX_KW * sizeof(*q->deint_output),
331 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
332 	if (q->deint_output == NULL) {
333 		rte_bbdev_log(ERR,
334 			"Failed to allocate queue memory for %s", name);
335 		goto free_q;
336 	}
337 
338 	/* Allocate memory for Adapter output. */
339 	ret = snprintf(name, RTE_RING_NAMESIZE,
340 			RTE_STR(DRIVER_NAME)"_adapter_output%u:%u",
341 			dev->data->dev_id, q_id);
342 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
343 		rte_bbdev_log(ERR,
344 				"Creating queue name for device %u queue %u failed",
345 				dev->data->dev_id, q_id);
346 		return -ENAMETOOLONG;
347 	}
348 	q->adapter_output = rte_zmalloc_socket(NULL,
349 			MAX_CB_SIZE * 6 * sizeof(*q->adapter_output),
350 			RTE_CACHE_LINE_SIZE, queue_conf->socket);
351 	if (q->adapter_output == NULL) {
352 		rte_bbdev_log(ERR,
353 			"Failed to allocate queue memory for %s", name);
354 		goto free_q;
355 	}
356 
357 	/* Create ring for packets awaiting to be dequeued. */
358 	ret = snprintf(name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME)"%u:%u",
359 			dev->data->dev_id, q_id);
360 	if ((ret < 0) || (ret >= (int)RTE_RING_NAMESIZE)) {
361 		rte_bbdev_log(ERR,
362 				"Creating queue name for device %u queue %u failed",
363 				dev->data->dev_id, q_id);
364 		return -ENAMETOOLONG;
365 	}
366 	q->processed_pkts = rte_ring_create(name, queue_conf->queue_size,
367 			queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
368 	if (q->processed_pkts == NULL) {
369 		rte_bbdev_log(ERR, "Failed to create ring for %s", name);
370 		goto free_q;
371 	}
372 
373 	q->type = queue_conf->op_type;
374 
375 	dev->data->queues[q_id].queue_private = q;
376 	rte_bbdev_log_debug("setup device queue %s", name);
377 	return 0;
378 
379 free_q:
380 	rte_ring_free(q->processed_pkts);
381 	rte_free(q->enc_out);
382 	rte_free(q->enc_in);
383 	rte_free(q->ag);
384 	rte_free(q->code_block);
385 	rte_free(q->deint_input);
386 	rte_free(q->deint_output);
387 	rte_free(q->adapter_output);
388 	rte_free(q);
389 	return -EFAULT;
390 }
391 
392 static const struct rte_bbdev_ops pmd_ops = {
393 	.info_get = info_get,
394 	.queue_setup = q_setup,
395 	.queue_release = q_release
396 };
397 
398 /* Checks if the encoder input buffer is correct.
399  * Returns 0 if it's valid, -1 otherwise.
400  */
401 static inline int
402 is_enc_input_valid(const uint16_t k, const int32_t k_idx,
403 		const uint16_t in_length)
404 {
405 	if (k_idx < 0) {
406 		rte_bbdev_log(ERR, "K Index is invalid");
407 		return -1;
408 	}
409 
410 	if (in_length - (k >> 3) < 0) {
411 		rte_bbdev_log(ERR,
412 				"Mismatch between input length (%u bytes) and K (%u bits)",
413 				in_length, k);
414 		return -1;
415 	}
416 
417 	if (k > MAX_CB_SIZE) {
418 		rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
419 				k, MAX_CB_SIZE);
420 		return -1;
421 	}
422 
423 	return 0;
424 }
425 
426 /* Checks if the decoder input buffer is correct.
427  * Returns 0 if it's valid, -1 otherwise.
428  */
429 static inline int
430 is_dec_input_valid(int32_t k_idx, int16_t kw, int16_t in_length)
431 {
432 	if (k_idx < 0) {
433 		rte_bbdev_log(ERR, "K index is invalid");
434 		return -1;
435 	}
436 
437 	if (in_length - kw < 0) {
438 		rte_bbdev_log(ERR,
439 				"Mismatch between input length (%u) and kw (%u)",
440 				in_length, kw);
441 		return -1;
442 	}
443 
444 	if (kw > MAX_KW) {
445 		rte_bbdev_log(ERR, "Input length (%u) is too big, max: %d",
446 				kw, MAX_KW);
447 		return -1;
448 	}
449 
450 	return 0;
451 }
452 
453 static inline void
454 process_enc_cb(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op,
455 		uint8_t cb_idx, uint8_t c, uint16_t k, uint16_t ncb,
456 		uint32_t e, struct rte_mbuf *m_in, struct rte_mbuf *m_out,
457 		uint16_t in_offset, uint16_t out_offset, uint16_t total_left)
458 {
459 	int ret;
460 	int16_t k_idx;
461 	uint16_t m;
462 	uint8_t *in, *out0, *out1, *out2, *tmp_out, *rm_out;
463 	struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
464 	struct bblib_crc_request crc_req;
465 	struct bblib_turbo_encoder_request turbo_req;
466 	struct bblib_turbo_encoder_response turbo_resp;
467 	struct bblib_rate_match_dl_request rm_req;
468 	struct bblib_rate_match_dl_response rm_resp;
469 
470 	k_idx = compute_idx(k);
471 	in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
472 
473 	/* CRC24A (for TB) */
474 	if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH) &&
475 		(enc->code_block_mode == 1)) {
476 		ret = is_enc_input_valid(k - 24, k_idx, total_left);
477 		if (ret != 0) {
478 			op->status |= 1 << RTE_BBDEV_DATA_ERROR;
479 			return;
480 		}
481 		/* copy the input to the temporary buffer to be able to extend
482 		 * it by 3 CRC bytes
483 		 */
484 		rte_memcpy(q->enc_in, in, (k - 24) >> 3);
485 		crc_req.data = q->enc_in;
486 		crc_req.len = (k - 24) >> 3;
487 		if (bblib_lte_crc24a_gen(&crc_req) == -1) {
488 			op->status |= 1 << RTE_BBDEV_CRC_ERROR;
489 			rte_bbdev_log(ERR, "CRC24a generation failed");
490 			return;
491 		}
492 		in = q->enc_in;
493 	} else if (enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) {
494 		/* CRC24B */
495 		ret = is_enc_input_valid(k - 24, k_idx, total_left);
496 		if (ret != 0) {
497 			op->status |= 1 << RTE_BBDEV_DATA_ERROR;
498 			return;
499 		}
500 		/* copy the input to the temporary buffer to be able to extend
501 		 * it by 3 CRC bytes
502 		 */
503 		rte_memcpy(q->enc_in, in, (k - 24) >> 3);
504 		crc_req.data = q->enc_in;
505 		crc_req.len = (k - 24) >> 3;
506 		if (bblib_lte_crc24b_gen(&crc_req) == -1) {
507 			op->status |= 1 << RTE_BBDEV_CRC_ERROR;
508 			rte_bbdev_log(ERR, "CRC24b generation failed");
509 			return;
510 		}
511 		in = q->enc_in;
512 	} else {
513 		ret = is_enc_input_valid(k, k_idx, total_left);
514 		if (ret != 0) {
515 			op->status |= 1 << RTE_BBDEV_DATA_ERROR;
516 			return;
517 		}
518 	}
519 
520 	/* Turbo encoder */
521 
522 	/* Each bit layer output from turbo encoder is (k+4) bits long, i.e.
523 	 * input length + 4 tail bits. That's (k/8) + 1 bytes after rounding up.
524 	 * So dst_data's length should be 3*(k/8) + 3 bytes.
525 	 */
526 	out0 = q->enc_out;
527 	out1 = RTE_PTR_ADD(out0, (k >> 3) + 1);
528 	out2 = RTE_PTR_ADD(out1, (k >> 3) + 1);
529 
530 	turbo_req.case_id = k_idx;
531 	turbo_req.input_win = in;
532 	turbo_req.length = k >> 3;
533 	turbo_resp.output_win_0 = out0;
534 	turbo_resp.output_win_1 = out1;
535 	turbo_resp.output_win_2 = out2;
536 	if (bblib_turbo_encoder(&turbo_req, &turbo_resp) != 0) {
537 		op->status |= 1 << RTE_BBDEV_DRV_ERROR;
538 		rte_bbdev_log(ERR, "Turbo Encoder failed");
539 		return;
540 	}
541 
542 	/* Rate-matching */
543 	if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH) {
544 		/* get output data starting address */
545 		rm_out = (uint8_t *)rte_pktmbuf_append(m_out, (e >> 3));
546 		if (rm_out == NULL) {
547 			op->status |= 1 << RTE_BBDEV_DATA_ERROR;
548 			rte_bbdev_log(ERR,
549 					"Too little space in output mbuf");
550 			return;
551 		}
552 		/* rte_bbdev_op_data.offset can be different than the offset
553 		 * of the appended bytes
554 		 */
555 		rm_out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
556 
557 		/* index of current code block */
558 		rm_req.r = cb_idx;
559 		/* total number of code block */
560 		rm_req.C = c;
561 		/* For DL - 1, UL - 0 */
562 		rm_req.direction = 1;
563 		/* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nsoft, KMIMO
564 		 * and MDL_HARQ are used for Ncb calculation. As Ncb is already
565 		 * known we can adjust those parameters
566 		 */
567 		rm_req.Nsoft = ncb * rm_req.C;
568 		rm_req.KMIMO = 1;
569 		rm_req.MDL_HARQ = 1;
570 		/* According to 3ggp 36.212 Spec 5.1.4.1.2 section Nl, Qm and G
571 		 * are used for E calculation. As E is already known we can
572 		 * adjust those parameters
573 		 */
574 		rm_req.NL = e;
575 		rm_req.Qm = 1;
576 		rm_req.G = rm_req.NL * rm_req.Qm * rm_req.C;
577 
578 		rm_req.rvidx = enc->rv_index;
579 		rm_req.Kidx = k_idx - 1;
580 		rm_req.nLen = k + 4;
581 		rm_req.tin0 = out0;
582 		rm_req.tin1 = out1;
583 		rm_req.tin2 = out2;
584 		rm_resp.output = rm_out;
585 		rm_resp.OutputLen = (e >> 3);
586 		if (enc->op_flags & RTE_BBDEV_TURBO_RV_INDEX_BYPASS)
587 			rm_req.bypass_rvidx = 1;
588 		else
589 			rm_req.bypass_rvidx = 0;
590 
591 		if (bblib_rate_match_dl(&rm_req, &rm_resp) != 0) {
592 			op->status |= 1 << RTE_BBDEV_DRV_ERROR;
593 			rte_bbdev_log(ERR, "Rate matching failed");
594 			return;
595 		}
596 		enc->output.length += rm_resp.OutputLen;
597 	} else {
598 		/* Rate matching is bypassed */
599 
600 		/* Completing last byte of out0 (where 4 tail bits are stored)
601 		 * by moving first 4 bits from out1
602 		 */
603 		tmp_out = (uint8_t *) --out1;
604 		*tmp_out = *tmp_out | ((*(tmp_out + 1) & 0xF0) >> 4);
605 		tmp_out++;
606 		/* Shifting out1 data by 4 bits to the left */
607 		for (m = 0; m < k >> 3; ++m) {
608 			uint8_t *first = tmp_out;
609 			uint8_t second = *(tmp_out + 1);
610 			*first = (*first << 4) | ((second & 0xF0) >> 4);
611 			tmp_out++;
612 		}
613 		/* Shifting out2 data by 8 bits to the left */
614 		for (m = 0; m < (k >> 3) + 1; ++m) {
615 			*tmp_out = *(tmp_out + 1);
616 			tmp_out++;
617 		}
618 		*tmp_out = 0;
619 
620 		/* copy shifted output to turbo_enc entity */
621 		out0 = (uint8_t *)rte_pktmbuf_append(m_out,
622 				(k >> 3) * 3 + 2);
623 		if (out0 == NULL) {
624 			op->status |= 1 << RTE_BBDEV_DATA_ERROR;
625 			rte_bbdev_log(ERR,
626 					"Too little space in output mbuf");
627 			return;
628 		}
629 		enc->output.length += (k >> 3) * 3 + 2;
630 		/* rte_bbdev_op_data.offset can be different than the
631 		 * offset of the appended bytes
632 		 */
633 		out0 = rte_pktmbuf_mtod_offset(m_out, uint8_t *,
634 				out_offset);
635 		rte_memcpy(out0, q->enc_out, (k >> 3) * 3 + 2);
636 	}
637 }
638 
639 static inline void
640 enqueue_enc_one_op(struct turbo_sw_queue *q, struct rte_bbdev_enc_op *op)
641 {
642 	uint8_t c, r, crc24_bits = 0;
643 	uint16_t k, ncb;
644 	uint32_t e;
645 	struct rte_bbdev_op_turbo_enc *enc = &op->turbo_enc;
646 	uint16_t in_offset = enc->input.offset;
647 	uint16_t out_offset = enc->output.offset;
648 	struct rte_mbuf *m_in = enc->input.data;
649 	struct rte_mbuf *m_out = enc->output.data;
650 	uint16_t total_left = enc->input.length;
651 
652 	/* Clear op status */
653 	op->status = 0;
654 
655 	if (total_left > MAX_TB_SIZE >> 3) {
656 		rte_bbdev_log(ERR, "TB size (%u) is too big, max: %d",
657 				total_left, MAX_TB_SIZE);
658 		op->status = 1 << RTE_BBDEV_DATA_ERROR;
659 		return;
660 	}
661 
662 	if (m_in == NULL || m_out == NULL) {
663 		rte_bbdev_log(ERR, "Invalid mbuf pointer");
664 		op->status = 1 << RTE_BBDEV_DATA_ERROR;
665 		return;
666 	}
667 
668 	if ((enc->op_flags & RTE_BBDEV_TURBO_CRC_24B_ATTACH) ||
669 		(enc->op_flags & RTE_BBDEV_TURBO_CRC_24A_ATTACH))
670 		crc24_bits = 24;
671 
672 	if (enc->code_block_mode == 0) { /* For Transport Block mode */
673 		c = enc->tb_params.c;
674 		r = enc->tb_params.r;
675 	} else {/* For Code Block mode */
676 		c = 1;
677 		r = 0;
678 	}
679 
680 	while (total_left > 0 && r < c) {
681 		if (enc->code_block_mode == 0) {
682 			k = (r < enc->tb_params.c_neg) ?
683 				enc->tb_params.k_neg : enc->tb_params.k_pos;
684 			ncb = (r < enc->tb_params.c_neg) ?
685 				enc->tb_params.ncb_neg : enc->tb_params.ncb_pos;
686 			e = (r < enc->tb_params.cab) ?
687 				enc->tb_params.ea : enc->tb_params.eb;
688 		} else {
689 			k = enc->cb_params.k;
690 			ncb = enc->cb_params.ncb;
691 			e = enc->cb_params.e;
692 		}
693 
694 		process_enc_cb(q, op, r, c, k, ncb, e, m_in,
695 				m_out, in_offset, out_offset, total_left);
696 		/* Update total_left */
697 		total_left -= (k - crc24_bits) >> 3;
698 		/* Update offsets for next CBs (if exist) */
699 		in_offset += (k - crc24_bits) >> 3;
700 		if (enc->op_flags & RTE_BBDEV_TURBO_RATE_MATCH)
701 			out_offset += e >> 3;
702 		else
703 			out_offset += (k >> 3) * 3 + 2;
704 		r++;
705 	}
706 
707 	/* check if all input data was processed */
708 	if (total_left != 0) {
709 		op->status |= 1 << RTE_BBDEV_DATA_ERROR;
710 		rte_bbdev_log(ERR,
711 				"Mismatch between mbuf length and included CBs sizes");
712 	}
713 }
714 
715 static inline uint16_t
716 enqueue_enc_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_enc_op **ops,
717 		uint16_t nb_ops)
718 {
719 	uint16_t i;
720 
721 	for (i = 0; i < nb_ops; ++i)
722 		enqueue_enc_one_op(q, ops[i]);
723 
724 	return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
725 			NULL);
726 }
727 
728 /* Remove the padding bytes from a cyclic buffer.
729  * The input buffer is a data stream wk as described in 3GPP TS 36.212 section
730  * 5.1.4.1.2 starting from w0 and with length Ncb bytes.
731  * The output buffer is a data stream wk with pruned padding bytes. It's length
732  * is 3*D bytes and the order of non-padding bytes is preserved.
733  */
734 static inline void
735 remove_nulls_from_circular_buf(const uint8_t *in, uint8_t *out, uint16_t k,
736 		uint16_t ncb)
737 {
738 	uint32_t in_idx, out_idx, c_idx;
739 	const uint32_t d = k + 4;
740 	const uint32_t kw = (ncb / 3);
741 	const uint32_t nd = kw - d;
742 	const uint32_t r_subblock = kw / C_SUBBLOCK;
743 	/* Inter-column permutation pattern */
744 	const uint32_t P[C_SUBBLOCK] = {0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10,
745 			26, 6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19,
746 			11, 27, 7, 23, 15, 31};
747 	in_idx = 0;
748 	out_idx = 0;
749 
750 	/* The padding bytes are at the first Nd positions in the first row. */
751 	for (c_idx = 0; in_idx < kw; in_idx += r_subblock, ++c_idx) {
752 		if (P[c_idx] < nd) {
753 			rte_memcpy(&out[out_idx], &in[in_idx + 1],
754 					r_subblock - 1);
755 			out_idx += r_subblock - 1;
756 		} else {
757 			rte_memcpy(&out[out_idx], &in[in_idx], r_subblock);
758 			out_idx += r_subblock;
759 		}
760 	}
761 
762 	/* First and second parity bits sub-blocks are interlaced. */
763 	for (c_idx = 0; in_idx < ncb - 2 * r_subblock;
764 			in_idx += 2 * r_subblock, ++c_idx) {
765 		uint32_t second_block_c_idx = P[c_idx];
766 		uint32_t third_block_c_idx = P[c_idx] + 1;
767 
768 		if (second_block_c_idx < nd && third_block_c_idx < nd) {
769 			rte_memcpy(&out[out_idx], &in[in_idx + 2],
770 					2 * r_subblock - 2);
771 			out_idx += 2 * r_subblock - 2;
772 		} else if (second_block_c_idx >= nd &&
773 				third_block_c_idx >= nd) {
774 			rte_memcpy(&out[out_idx], &in[in_idx], 2 * r_subblock);
775 			out_idx += 2 * r_subblock;
776 		} else if (second_block_c_idx < nd) {
777 			out[out_idx++] = in[in_idx];
778 			rte_memcpy(&out[out_idx], &in[in_idx + 2],
779 					2 * r_subblock - 2);
780 			out_idx += 2 * r_subblock - 2;
781 		} else {
782 			rte_memcpy(&out[out_idx], &in[in_idx + 1],
783 					2 * r_subblock - 1);
784 			out_idx += 2 * r_subblock - 1;
785 		}
786 	}
787 
788 	/* Last interlaced row is different - its last byte is the only padding
789 	 * byte. We can have from 2 up to 26 padding bytes (Nd) per sub-block.
790 	 * After interlacing the 1st and 2nd parity sub-blocks we can have 0, 1
791 	 * or 2 padding bytes each time we make a step of 2 * R_SUBBLOCK bytes
792 	 * (moving to another column). 2nd parity sub-block uses the same
793 	 * inter-column permutation pattern as the systematic and 1st parity
794 	 * sub-blocks but it adds '1' to the resulting index and calculates the
795 	 * modulus of the result and Kw. Last column is mapped to itself (id 31)
796 	 * so the first byte taken from the 2nd parity sub-block will be the
797 	 * 32nd (31+1) byte, then 64th etc. (step is C_SUBBLOCK == 32) and the
798 	 * last byte will be the first byte from the sub-block:
799 	 * (32 + 32 * (R_SUBBLOCK-1)) % Kw == Kw % Kw == 0. Nd can't  be smaller
800 	 * than 2 so we know that bytes with ids 0 and 1 must be the padding
801 	 * bytes. The bytes from the 1st parity sub-block are the bytes from the
802 	 * 31st column - Nd can't be greater than 26 so we are sure that there
803 	 * are no padding bytes in 31st column.
804 	 */
805 	rte_memcpy(&out[out_idx], &in[in_idx], 2 * r_subblock - 1);
806 }
807 
808 static inline void
809 move_padding_bytes(const uint8_t *in, uint8_t *out, uint16_t k,
810 		uint16_t ncb)
811 {
812 	uint16_t d = k + 4;
813 	uint16_t kpi = ncb / 3;
814 	uint16_t nd = kpi - d;
815 
816 	rte_memcpy(&out[nd], in, d);
817 	rte_memcpy(&out[nd + kpi + 64], &in[kpi], d);
818 	rte_memcpy(&out[nd + 2 * (kpi + 64)], &in[2 * kpi], d);
819 }
820 
821 static inline void
822 process_dec_cb(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op,
823 		uint8_t c, uint16_t k, uint16_t kw, struct rte_mbuf *m_in,
824 		struct rte_mbuf *m_out, uint16_t in_offset, uint16_t out_offset,
825 		bool check_crc_24b, uint16_t total_left)
826 {
827 	int ret;
828 	int32_t k_idx;
829 	int32_t iter_cnt;
830 	uint8_t *in, *out, *adapter_input;
831 	int32_t ncb, ncb_without_null;
832 	struct bblib_turbo_adapter_ul_response adapter_resp;
833 	struct bblib_turbo_adapter_ul_request adapter_req;
834 	struct bblib_turbo_decoder_request turbo_req;
835 	struct bblib_turbo_decoder_response turbo_resp;
836 	struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
837 
838 	k_idx = compute_idx(k);
839 
840 	ret = is_dec_input_valid(k_idx, kw, total_left);
841 	if (ret != 0) {
842 		op->status |= 1 << RTE_BBDEV_DATA_ERROR;
843 		return;
844 	}
845 
846 	in = rte_pktmbuf_mtod_offset(m_in, uint8_t *, in_offset);
847 	ncb = kw;
848 	ncb_without_null = (k + 4) * 3;
849 
850 	if (check_bit(dec->op_flags, RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE)) {
851 		struct bblib_deinterleave_ul_request deint_req;
852 		struct bblib_deinterleave_ul_response deint_resp;
853 
854 		/* SW decoder accepts only a circular buffer without NULL bytes
855 		 * so the input needs to be converted.
856 		 */
857 		remove_nulls_from_circular_buf(in, q->deint_input, k, ncb);
858 
859 		deint_req.pharqbuffer = q->deint_input;
860 		deint_req.ncb = ncb_without_null;
861 		deint_resp.pinteleavebuffer = q->deint_output;
862 		bblib_deinterleave_ul(&deint_req, &deint_resp);
863 	} else
864 		move_padding_bytes(in, q->deint_output, k, ncb);
865 
866 	adapter_input = q->deint_output;
867 
868 	if (dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN)
869 		adapter_req.isinverted = 1;
870 	else if (dec->op_flags & RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)
871 		adapter_req.isinverted = 0;
872 	else {
873 		op->status |= 1 << RTE_BBDEV_DRV_ERROR;
874 		rte_bbdev_log(ERR, "LLR format wasn't specified");
875 		return;
876 	}
877 
878 	adapter_req.ncb = ncb_without_null;
879 	adapter_req.pinteleavebuffer = adapter_input;
880 	adapter_resp.pharqout = q->adapter_output;
881 	bblib_turbo_adapter_ul(&adapter_req, &adapter_resp);
882 
883 	out = (uint8_t *)rte_pktmbuf_append(m_out, (k >> 3));
884 	if (out == NULL) {
885 		op->status |= 1 << RTE_BBDEV_DATA_ERROR;
886 		rte_bbdev_log(ERR, "Too little space in output mbuf");
887 		return;
888 	}
889 	/* rte_bbdev_op_data.offset can be different than the offset of the
890 	 * appended bytes
891 	 */
892 	out = rte_pktmbuf_mtod_offset(m_out, uint8_t *, out_offset);
893 	if (check_crc_24b)
894 		turbo_req.c = c + 1;
895 	else
896 		turbo_req.c = c;
897 	turbo_req.input = (int8_t *)q->adapter_output;
898 	turbo_req.k = k;
899 	turbo_req.k_idx = k_idx;
900 	turbo_req.max_iter_num = dec->iter_max;
901 	turbo_resp.ag_buf = q->ag;
902 	turbo_resp.cb_buf = q->code_block;
903 	turbo_resp.output = out;
904 	iter_cnt = bblib_turbo_decoder(&turbo_req, &turbo_resp);
905 	dec->hard_output.length += (k >> 3);
906 
907 	if (iter_cnt > 0) {
908 		/* Temporary solution for returned iter_count from SDK */
909 		iter_cnt = (iter_cnt - 1) / 2;
910 		dec->iter_count = RTE_MAX(iter_cnt, dec->iter_count);
911 	} else {
912 		op->status |= 1 << RTE_BBDEV_DATA_ERROR;
913 		rte_bbdev_log(ERR, "Turbo Decoder failed");
914 		return;
915 	}
916 }
917 
918 static inline void
919 enqueue_dec_one_op(struct turbo_sw_queue *q, struct rte_bbdev_dec_op *op)
920 {
921 	uint8_t c, r = 0;
922 	uint16_t kw, k = 0;
923 	struct rte_bbdev_op_turbo_dec *dec = &op->turbo_dec;
924 	struct rte_mbuf *m_in = dec->input.data;
925 	struct rte_mbuf *m_out = dec->hard_output.data;
926 	uint16_t in_offset = dec->input.offset;
927 	uint16_t total_left = dec->input.length;
928 	uint16_t out_offset = dec->hard_output.offset;
929 
930 	/* Clear op status */
931 	op->status = 0;
932 
933 	if (m_in == NULL || m_out == NULL) {
934 		rte_bbdev_log(ERR, "Invalid mbuf pointer");
935 		op->status = 1 << RTE_BBDEV_DATA_ERROR;
936 		return;
937 	}
938 
939 	if (dec->code_block_mode == 0) { /* For Transport Block mode */
940 		c = dec->tb_params.c;
941 	} else { /* For Code Block mode */
942 		k = dec->cb_params.k;
943 		c = 1;
944 	}
945 
946 	while (total_left > 0) {
947 		if (dec->code_block_mode == 0)
948 			k = (r < dec->tb_params.c_neg) ?
949 				dec->tb_params.k_neg : dec->tb_params.k_pos;
950 
951 		/* Calculates circular buffer size (Kw).
952 		 * According to 3gpp 36.212 section 5.1.4.2
953 		 *   Kw = 3 * Kpi,
954 		 * where:
955 		 *   Kpi = nCol * nRow
956 		 * where nCol is 32 and nRow can be calculated from:
957 		 *   D =< nCol * nRow
958 		 * where D is the size of each output from turbo encoder block
959 		 * (k + 4).
960 		 */
961 		kw = RTE_ALIGN_CEIL(k + 4, C_SUBBLOCK) * 3;
962 
963 		process_dec_cb(q, op, c, k, kw, m_in, m_out, in_offset,
964 				out_offset, check_bit(dec->op_flags,
965 				RTE_BBDEV_TURBO_CRC_TYPE_24B), total_left);
966 		/* As a result of decoding we get Code Block with included
967 		 * decoded CRC24 at the end of Code Block. Type of CRC24 is
968 		 * specified by flag.
969 		 */
970 
971 		/* Update total_left */
972 		total_left -= kw;
973 		/* Update offsets for next CBs (if exist) */
974 		in_offset += kw;
975 		out_offset += (k >> 3);
976 		r++;
977 	}
978 	if (total_left != 0) {
979 		op->status |= 1 << RTE_BBDEV_DATA_ERROR;
980 		rte_bbdev_log(ERR,
981 				"Mismatch between mbuf length and included Circular buffer sizes");
982 	}
983 }
984 
985 static inline uint16_t
986 enqueue_dec_all_ops(struct turbo_sw_queue *q, struct rte_bbdev_dec_op **ops,
987 		uint16_t nb_ops)
988 {
989 	uint16_t i;
990 
991 	for (i = 0; i < nb_ops; ++i)
992 		enqueue_dec_one_op(q, ops[i]);
993 
994 	return rte_ring_enqueue_burst(q->processed_pkts, (void **)ops, nb_ops,
995 			NULL);
996 }
997 
998 /* Enqueue burst */
999 static uint16_t
1000 enqueue_enc_ops(struct rte_bbdev_queue_data *q_data,
1001 		struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1002 {
1003 	void *queue = q_data->queue_private;
1004 	struct turbo_sw_queue *q = queue;
1005 	uint16_t nb_enqueued = 0;
1006 
1007 	nb_enqueued = enqueue_enc_all_ops(q, ops, nb_ops);
1008 
1009 	q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1010 	q_data->queue_stats.enqueued_count += nb_enqueued;
1011 
1012 	return nb_enqueued;
1013 }
1014 
1015 /* Enqueue burst */
1016 static uint16_t
1017 enqueue_dec_ops(struct rte_bbdev_queue_data *q_data,
1018 		 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1019 {
1020 	void *queue = q_data->queue_private;
1021 	struct turbo_sw_queue *q = queue;
1022 	uint16_t nb_enqueued = 0;
1023 
1024 	nb_enqueued = enqueue_dec_all_ops(q, ops, nb_ops);
1025 
1026 	q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
1027 	q_data->queue_stats.enqueued_count += nb_enqueued;
1028 
1029 	return nb_enqueued;
1030 }
1031 
1032 /* Dequeue decode burst */
1033 static uint16_t
1034 dequeue_dec_ops(struct rte_bbdev_queue_data *q_data,
1035 		struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
1036 {
1037 	struct turbo_sw_queue *q = q_data->queue_private;
1038 	uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1039 			(void **)ops, nb_ops, NULL);
1040 	q_data->queue_stats.dequeued_count += nb_dequeued;
1041 
1042 	return nb_dequeued;
1043 }
1044 
1045 /* Dequeue encode burst */
1046 static uint16_t
1047 dequeue_enc_ops(struct rte_bbdev_queue_data *q_data,
1048 		struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
1049 {
1050 	struct turbo_sw_queue *q = q_data->queue_private;
1051 	uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
1052 			(void **)ops, nb_ops, NULL);
1053 	q_data->queue_stats.dequeued_count += nb_dequeued;
1054 
1055 	return nb_dequeued;
1056 }
1057 
1058 /* Parse 16bit integer from string argument */
1059 static inline int
1060 parse_u16_arg(const char *key, const char *value, void *extra_args)
1061 {
1062 	uint16_t *u16 = extra_args;
1063 	unsigned int long result;
1064 
1065 	if ((value == NULL) || (extra_args == NULL))
1066 		return -EINVAL;
1067 	errno = 0;
1068 	result = strtoul(value, NULL, 0);
1069 	if ((result >= (1 << 16)) || (errno != 0)) {
1070 		rte_bbdev_log(ERR, "Invalid value %lu for %s", result, key);
1071 		return -ERANGE;
1072 	}
1073 	*u16 = (uint16_t)result;
1074 	return 0;
1075 }
1076 
1077 /* Parse parameters used to create device */
1078 static int
1079 parse_turbo_sw_params(struct turbo_sw_params *params, const char *input_args)
1080 {
1081 	struct rte_kvargs *kvlist = NULL;
1082 	int ret = 0;
1083 
1084 	if (params == NULL)
1085 		return -EINVAL;
1086 	if (input_args) {
1087 		kvlist = rte_kvargs_parse(input_args, turbo_sw_valid_params);
1088 		if (kvlist == NULL)
1089 			return -EFAULT;
1090 
1091 		ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[0],
1092 					&parse_u16_arg, &params->queues_num);
1093 		if (ret < 0)
1094 			goto exit;
1095 
1096 		ret = rte_kvargs_process(kvlist, turbo_sw_valid_params[1],
1097 					&parse_u16_arg, &params->socket_id);
1098 		if (ret < 0)
1099 			goto exit;
1100 
1101 		if (params->socket_id >= RTE_MAX_NUMA_NODES) {
1102 			rte_bbdev_log(ERR, "Invalid socket, must be < %u",
1103 					RTE_MAX_NUMA_NODES);
1104 			goto exit;
1105 		}
1106 	}
1107 
1108 exit:
1109 	if (kvlist)
1110 		rte_kvargs_free(kvlist);
1111 	return ret;
1112 }
1113 
1114 /* Create device */
1115 static int
1116 turbo_sw_bbdev_create(struct rte_vdev_device *vdev,
1117 		struct turbo_sw_params *init_params)
1118 {
1119 	struct rte_bbdev *bbdev;
1120 	const char *name = rte_vdev_device_name(vdev);
1121 
1122 	bbdev = rte_bbdev_allocate(name);
1123 	if (bbdev == NULL)
1124 		return -ENODEV;
1125 
1126 	bbdev->data->dev_private = rte_zmalloc_socket(name,
1127 			sizeof(struct bbdev_private), RTE_CACHE_LINE_SIZE,
1128 			init_params->socket_id);
1129 	if (bbdev->data->dev_private == NULL) {
1130 		rte_bbdev_release(bbdev);
1131 		return -ENOMEM;
1132 	}
1133 
1134 	bbdev->dev_ops = &pmd_ops;
1135 	bbdev->device = &vdev->device;
1136 	bbdev->data->socket_id = init_params->socket_id;
1137 	bbdev->intr_handle = NULL;
1138 
1139 	/* register rx/tx burst functions for data path */
1140 	bbdev->dequeue_enc_ops = dequeue_enc_ops;
1141 	bbdev->dequeue_dec_ops = dequeue_dec_ops;
1142 	bbdev->enqueue_enc_ops = enqueue_enc_ops;
1143 	bbdev->enqueue_dec_ops = enqueue_dec_ops;
1144 	((struct bbdev_private *) bbdev->data->dev_private)->max_nb_queues =
1145 			init_params->queues_num;
1146 
1147 	return 0;
1148 }
1149 
1150 /* Initialise device */
1151 static int
1152 turbo_sw_bbdev_probe(struct rte_vdev_device *vdev)
1153 {
1154 	struct turbo_sw_params init_params = {
1155 		rte_socket_id(),
1156 		RTE_BBDEV_DEFAULT_MAX_NB_QUEUES
1157 	};
1158 	const char *name;
1159 	const char *input_args;
1160 
1161 	if (vdev == NULL)
1162 		return -EINVAL;
1163 
1164 	name = rte_vdev_device_name(vdev);
1165 	if (name == NULL)
1166 		return -EINVAL;
1167 	input_args = rte_vdev_device_args(vdev);
1168 	parse_turbo_sw_params(&init_params, input_args);
1169 
1170 	rte_bbdev_log_debug(
1171 			"Initialising %s on NUMA node %d with max queues: %d\n",
1172 			name, init_params.socket_id, init_params.queues_num);
1173 
1174 	return turbo_sw_bbdev_create(vdev, &init_params);
1175 }
1176 
1177 /* Uninitialise device */
1178 static int
1179 turbo_sw_bbdev_remove(struct rte_vdev_device *vdev)
1180 {
1181 	struct rte_bbdev *bbdev;
1182 	const char *name;
1183 
1184 	if (vdev == NULL)
1185 		return -EINVAL;
1186 
1187 	name = rte_vdev_device_name(vdev);
1188 	if (name == NULL)
1189 		return -EINVAL;
1190 
1191 	bbdev = rte_bbdev_get_named_dev(name);
1192 	if (bbdev == NULL)
1193 		return -EINVAL;
1194 
1195 	rte_free(bbdev->data->dev_private);
1196 
1197 	return rte_bbdev_release(bbdev);
1198 }
1199 
1200 static struct rte_vdev_driver bbdev_turbo_sw_pmd_drv = {
1201 	.probe = turbo_sw_bbdev_probe,
1202 	.remove = turbo_sw_bbdev_remove
1203 };
1204 
1205 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_turbo_sw_pmd_drv);
1206 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
1207 	TURBO_SW_MAX_NB_QUEUES_ARG"=<int> "
1208 	TURBO_SW_SOCKET_ID_ARG"=<int>");
1209 
1210 RTE_INIT(null_bbdev_init_log);
1211 static void
1212 null_bbdev_init_log(void)
1213 {
1214 	bbdev_turbo_sw_logtype = rte_log_register("pmd.bb.turbo_sw");
1215 	if (bbdev_turbo_sw_logtype >= 0)
1216 		rte_log_set_level(bbdev_turbo_sw_logtype, RTE_LOG_NOTICE);
1217 }
1218