DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(C) 2019 Marvell International Ltd.
 */

#include <stdbool.h>

#include <rte_cryptodev_pmd.h>
#include <rte_crypto.h>

#include "nitrox_sym.h"
#include "nitrox_device.h"
#include "nitrox_sym_capabilities.h"
#include "nitrox_qp.h"
#include "nitrox_sym_reqmgr.h"
#include "nitrox_sym_ctx.h"
#include "nitrox_logs.h"

#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
#define MC_MAC_MISMATCH_ERR_CODE 0x4c
#define NPS_PKT_IN_INSTR_SIZE 64
#define IV_FROM_DPTR 1
#define FLEXI_CRYPTO_ENCRYPT_HMAC 0x33
#define AES_KEYSIZE_128 16
#define AES_KEYSIZE_192 24
#define AES_KEYSIZE_256 32
#define MAX_IV_LEN 16

struct nitrox_sym_device {
	struct rte_cryptodev *cdev;
	struct nitrox_device *ndev;
};

/* Cipher opcodes */
enum flexi_cipher {
	CIPHER_NULL = 0,
	CIPHER_3DES_CBC,
	CIPHER_3DES_ECB,
	CIPHER_AES_CBC,
	CIPHER_AES_ECB,
	CIPHER_AES_CFB,
	CIPHER_AES_CTR,
	CIPHER_AES_GCM,
	CIPHER_AES_XTS,
	CIPHER_AES_CCM,
	CIPHER_AES_CBC_CTS,
	CIPHER_AES_ECB_CTS,
	CIPHER_INVALID
};

/* Auth opcodes */
enum flexi_auth {
	AUTH_NULL = 0,
	AUTH_MD5,
	AUTH_SHA1,
	AUTH_SHA2_SHA224,
	AUTH_SHA2_SHA256,
	AUTH_SHA2_SHA384,
	AUTH_SHA2_SHA512,
	AUTH_GMAC,
	AUTH_INVALID
};

uint8_t nitrox_sym_drv_id;
static const char nitrox_sym_drv_name[] = RTE_STR(CRYPTODEV_NAME_NITROX_PMD);
static const struct rte_driver nitrox_rte_sym_drv = {
	.name = nitrox_sym_drv_name,
	.alias = nitrox_sym_drv_name
};

static int nitrox_sym_dev_qp_release(struct rte_cryptodev *cdev,
				     uint16_t qp_id);

static int
nitrox_sym_dev_config(struct rte_cryptodev *cdev,
		      struct rte_cryptodev_config *config)
{
	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
	struct nitrox_device *ndev = sym_dev->ndev;

	if (config->nb_queue_pairs > ndev->nr_queues) {
		NITROX_LOG(ERR, "Invalid queue pairs, max supported %d\n",
			   ndev->nr_queues);
		return -EINVAL;
	}

	return 0;
}

static int
nitrox_sym_dev_start(struct rte_cryptodev *cdev)
{
	/* SE cores initialization is done in PF */
	RTE_SET_USED(cdev);
	return 0;
}

static void
nitrox_sym_dev_stop(struct rte_cryptodev *cdev)
{
	/* SE cores cleanup is done in PF */
	RTE_SET_USED(cdev);
}

static int
nitrox_sym_dev_close(struct rte_cryptodev *cdev)
{
	int i, ret;

	for (i = 0; i < cdev->data->nb_queue_pairs; i++) {
		ret = nitrox_sym_dev_qp_release(cdev, i);
		if (ret)
			return ret;
	}

	return 0;
}

static void
nitrox_sym_dev_info_get(struct rte_cryptodev *cdev,
			struct rte_cryptodev_info *info)
{
	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
	struct nitrox_device *ndev = sym_dev->ndev;

	if (!info)
		return;

	info->max_nb_queue_pairs = ndev->nr_queues;
	info->feature_flags = cdev->feature_flags;
	info->capabilities = nitrox_get_sym_capabilities();
	info->driver_id = nitrox_sym_drv_id;
	info->sym.max_nb_sessions = 0;
}

static void
nitrox_sym_dev_stats_get(struct rte_cryptodev *cdev,
			 struct rte_cryptodev_stats *stats)
{
	int qp_id;

	for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
		struct nitrox_qp *qp = cdev->data->queue_pairs[qp_id];

		if (!qp)
			continue;

		stats->enqueued_count += qp->stats.enqueued_count;
		stats->dequeued_count += qp->stats.dequeued_count;
		stats->enqueue_err_count += qp->stats.enqueue_err_count;
		stats->dequeue_err_count += qp->stats.dequeue_err_count;
	}
}

static void
nitrox_sym_dev_stats_reset(struct rte_cryptodev *cdev)
{
	int qp_id;

	for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
		struct nitrox_qp *qp = cdev->data->queue_pairs[qp_id];

		if (!qp)
			continue;

		memset(&qp->stats, 0, sizeof(qp->stats));
	}
}

static int
nitrox_sym_dev_qp_setup(struct rte_cryptodev *cdev, uint16_t qp_id,
			const struct rte_cryptodev_qp_conf *qp_conf,
			int socket_id)
{
	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
	struct nitrox_device *ndev = sym_dev->ndev;
	struct nitrox_qp *qp = NULL;
	int err;

	NITROX_LOG(DEBUG, "queue %d\n", qp_id);
	if (qp_id >= ndev->nr_queues) {
		NITROX_LOG(ERR, "queue %u invalid, max queues supported %d\n",
			   qp_id, ndev->nr_queues);
		return -EINVAL;
	}

	if (cdev->data->queue_pairs[qp_id]) {
		err = nitrox_sym_dev_qp_release(cdev, qp_id);
		if (err)
			return err;
	}

	qp = rte_zmalloc_socket("nitrox PMD qp", sizeof(*qp),
				RTE_CACHE_LINE_SIZE,
				socket_id);
	if (!qp) {
		NITROX_LOG(ERR, "Failed to allocate nitrox qp\n");
		return -ENOMEM;
	}

	qp->qno = qp_id;
	err = nitrox_qp_setup(qp, ndev->bar_addr, cdev->data->name,
			      qp_conf->nb_descriptors, NPS_PKT_IN_INSTR_SIZE,
			      socket_id);
	if (unlikely(err))
		goto qp_setup_err;

	qp->sr_mp = nitrox_sym_req_pool_create(cdev, qp->count, qp_id,
					       socket_id);
	if (unlikely(!qp->sr_mp))
		goto req_pool_err;

	cdev->data->queue_pairs[qp_id] = qp;
	NITROX_LOG(DEBUG, "queue %d setup done\n", qp_id);
	return 0;

req_pool_err:
	nitrox_qp_release(qp, ndev->bar_addr);
qp_setup_err:
	rte_free(qp);
	return err;
}

static int
nitrox_sym_dev_qp_release(struct rte_cryptodev *cdev, uint16_t qp_id)
{
	struct nitrox_sym_device *sym_dev = cdev->data->dev_private;
	struct nitrox_device *ndev = sym_dev->ndev;
	struct nitrox_qp *qp;
	int err;

	NITROX_LOG(DEBUG, "queue %d\n", qp_id);
	if (qp_id >= ndev->nr_queues) {
		NITROX_LOG(ERR, "queue %u invalid, max queues supported %d\n",
			   qp_id, ndev->nr_queues);
		return -EINVAL;
	}

	qp = cdev->data->queue_pairs[qp_id];
	if (!qp) {
		NITROX_LOG(DEBUG, "queue %u already freed\n", qp_id);
		return 0;
	}

	if (!nitrox_qp_is_empty(qp)) {
		NITROX_LOG(ERR, "queue %d not empty\n", qp_id);
		return -EAGAIN;
	}

	cdev->data->queue_pairs[qp_id] = NULL;
	err = nitrox_qp_release(qp, ndev->bar_addr);
	nitrox_sym_req_pool_free(qp->sr_mp);
	rte_free(qp);
	NITROX_LOG(DEBUG, "queue %d release done\n", qp_id);
	return err;
}

static unsigned int
nitrox_sym_dev_sess_get_size(__rte_unused struct rte_cryptodev *cdev)
{
	return sizeof(struct nitrox_crypto_ctx);
}

static enum nitrox_chain
get_crypto_chain_order(const struct rte_crypto_sym_xform *xform)
{
	enum nitrox_chain res = NITROX_CHAIN_NOT_SUPPORTED;

	if (unlikely(xform == NULL))
		return res;

	switch (xform->type) {
	case RTE_CRYPTO_SYM_XFORM_AUTH:
		if (xform->next == NULL) {
			res = NITROX_CHAIN_NOT_SUPPORTED;
		} else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
			if (xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY &&
			    xform->next->cipher.op ==
			    RTE_CRYPTO_CIPHER_OP_DECRYPT) {
				res = NITROX_CHAIN_AUTH_CIPHER;
			} else {
				NITROX_LOG(ERR, "auth op %d, cipher op %d\n",
				    xform->auth.op, xform->next->cipher.op);
			}
		}
		break;
	case RTE_CRYPTO_SYM_XFORM_CIPHER:
		if (xform->next == NULL) {
			res = NITROX_CHAIN_CIPHER_ONLY;
		} else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
			if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
			    xform->next->auth.op ==
			    RTE_CRYPTO_AUTH_OP_GENERATE) {
				res = NITROX_CHAIN_CIPHER_AUTH;
			} else {
				NITROX_LOG(ERR, "cipher op %d, auth op %d\n",
				    xform->cipher.op, xform->next->auth.op);
			}
		}
		break;
	default:
		break;
	}

	return res;
}

static enum flexi_cipher
get_flexi_cipher_type(enum rte_crypto_cipher_algorithm algo, bool *is_aes)
{
	enum flexi_cipher type;

	switch (algo) {
	case RTE_CRYPTO_CIPHER_AES_CBC:
		type = CIPHER_AES_CBC;
		*is_aes = true;
		break;
	case RTE_CRYPTO_CIPHER_3DES_CBC:
		type = CIPHER_3DES_CBC;
		*is_aes = false;
		break;
	default:
		type = CIPHER_INVALID;
		NITROX_LOG(ERR, "Algorithm not supported %d\n", algo);
		break;
	}

	return type;
}

static int
flexi_aes_keylen(size_t keylen, bool is_aes)
{
	int aes_keylen;

	if (!is_aes)
		return 0;

	switch (keylen) {
	case AES_KEYSIZE_128:
		aes_keylen = 1;
		break;
	case AES_KEYSIZE_192:
		aes_keylen = 2;
		break;
	case AES_KEYSIZE_256:
		aes_keylen = 3;
		break;
	default:
		NITROX_LOG(ERR, "Invalid keylen %zu\n", keylen);
		aes_keylen = -EINVAL;
		break;
	}

	return aes_keylen;
}

static bool
crypto_key_is_valid(struct rte_crypto_cipher_xform *xform,
		    struct flexi_crypto_context *fctx)
{
	if (unlikely(xform->key.length > sizeof(fctx->crypto.key))) {
		NITROX_LOG(ERR, "Invalid crypto key length %d\n",
			   xform->key.length);
		return false;
	}

	return true;
}

static int
configure_cipher_ctx(struct rte_crypto_cipher_xform *xform,
		     struct nitrox_crypto_ctx *ctx)
{
	enum flexi_cipher type;
	bool cipher_is_aes = false;
	int aes_keylen;
	struct flexi_crypto_context *fctx = &ctx->fctx;

	type = get_flexi_cipher_type(xform->algo, &cipher_is_aes);
	if (unlikely(type == CIPHER_INVALID))
		return -ENOTSUP;

	aes_keylen = flexi_aes_keylen(xform->key.length, cipher_is_aes);
	if (unlikely(aes_keylen < 0))
		return -EINVAL;

	if (unlikely(!cipher_is_aes && !crypto_key_is_valid(xform, fctx)))
		return -EINVAL;

	if (unlikely(xform->iv.length > MAX_IV_LEN))
		return -EINVAL;

	fctx->flags = rte_be_to_cpu_64(fctx->flags);
	fctx->w0.cipher_type = type;
	fctx->w0.aes_keylen = aes_keylen;
	fctx->w0.iv_source = IV_FROM_DPTR;
	fctx->flags = rte_cpu_to_be_64(fctx->flags);
	memset(fctx->crypto.key, 0, sizeof(fctx->crypto.key));
	memcpy(fctx->crypto.key, xform->key.data, xform->key.length);

	ctx->opcode = FLEXI_CRYPTO_ENCRYPT_HMAC;
	ctx->req_op = (xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
			NITROX_OP_ENCRYPT : NITROX_OP_DECRYPT;
	ctx->iv.offset = xform->iv.offset;
	ctx->iv.length = xform->iv.length;
	return 0;
}

static enum flexi_auth
get_flexi_auth_type(enum rte_crypto_auth_algorithm algo)
{
	enum flexi_auth type;

	switch (algo) {
	case RTE_CRYPTO_AUTH_SHA1_HMAC:
		type = AUTH_SHA1;
		break;
	case RTE_CRYPTO_AUTH_SHA224_HMAC:
		type = AUTH_SHA2_SHA224;
		break;
	case RTE_CRYPTO_AUTH_SHA256_HMAC:
		type = AUTH_SHA2_SHA256;
		break;
	default:
		NITROX_LOG(ERR, "Algorithm not supported %d\n", algo);
		type = AUTH_INVALID;
		break;
	}

	return type;
}

static bool
auth_key_digest_is_valid(struct rte_crypto_auth_xform *xform,
			 struct flexi_crypto_context *fctx)
{
	if (unlikely(!xform->key.data && xform->key.length)) {
		NITROX_LOG(ERR, "Invalid auth key\n");
		return false;
	}

	if (unlikely(xform->key.length > sizeof(fctx->auth.opad))) {
		NITROX_LOG(ERR, "Invalid auth key length %d\n",
			   xform->key.length);
		return false;
	}

	return true;
}

static int
configure_auth_ctx(struct rte_crypto_auth_xform *xform,
		   struct nitrox_crypto_ctx *ctx)
{
	enum flexi_auth type;
	struct flexi_crypto_context *fctx = &ctx->fctx;

	type = get_flexi_auth_type(xform->algo);
	if (unlikely(type == AUTH_INVALID))
		return -ENOTSUP;

	if (unlikely(!auth_key_digest_is_valid(xform, fctx)))
		return -EINVAL;

	ctx->auth_op = xform->op;
	ctx->auth_algo = xform->algo;
	ctx->digest_length = xform->digest_length;

	fctx->flags = rte_be_to_cpu_64(fctx->flags);
	fctx->w0.hash_type = type;
	fctx->w0.auth_input_type = 1;
	fctx->w0.mac_len = xform->digest_length;
	fctx->flags = rte_cpu_to_be_64(fctx->flags);
	memset(&fctx->auth, 0, sizeof(fctx->auth));
	memcpy(fctx->auth.opad, xform->key.data, xform->key.length);
	return 0;
}

static int
nitrox_sym_dev_sess_configure(struct rte_cryptodev *cdev,
			      struct rte_crypto_sym_xform *xform,
			      struct rte_cryptodev_sym_session *sess,
			      struct rte_mempool *mempool)
{
	void *mp_obj;
	struct nitrox_crypto_ctx *ctx;
	struct rte_crypto_cipher_xform *cipher_xform = NULL;
	struct rte_crypto_auth_xform *auth_xform = NULL;

	if (rte_mempool_get(mempool, &mp_obj)) {
		NITROX_LOG(ERR, "Couldn't allocate context\n");
		return -ENOMEM;
	}

	ctx = mp_obj;
	ctx->nitrox_chain = get_crypto_chain_order(xform);
	switch (ctx->nitrox_chain) {
	case NITROX_CHAIN_CIPHER_AUTH:
		cipher_xform = &xform->cipher;
		auth_xform = &xform->next->auth;
		break;
	case NITROX_CHAIN_AUTH_CIPHER:
		auth_xform = &xform->auth;
		cipher_xform = &xform->next->cipher;
		break;
	default:
		NITROX_LOG(ERR, "Crypto chain not supported\n");
		goto err;
	}

	if (cipher_xform && unlikely(configure_cipher_ctx(cipher_xform, ctx))) {
		NITROX_LOG(ERR, "Failed to configure cipher ctx\n");
		goto err;
	}

	if (auth_xform && unlikely(configure_auth_ctx(auth_xform, ctx))) {
		NITROX_LOG(ERR, "Failed to configure auth ctx\n");
		goto err;
	}

	ctx->iova = rte_mempool_virt2iova(ctx);
	set_sym_session_private_data(sess, cdev->driver_id, ctx);
	return 0;
err:
	rte_mempool_put(mempool, mp_obj);
	return -EINVAL;
}

static void
nitrox_sym_dev_sess_clear(struct rte_cryptodev *cdev,
			  struct rte_cryptodev_sym_session *sess)
{
	struct nitrox_crypto_ctx *ctx = get_sym_session_private_data(sess,
							cdev->driver_id);
	struct rte_mempool *sess_mp;

	if (!ctx)
		return;

	memset(ctx, 0, sizeof(*ctx));
	sess_mp = rte_mempool_from_obj(ctx);
	set_sym_session_private_data(sess, cdev->driver_id, NULL);
	rte_mempool_put(sess_mp, ctx);
}

static struct nitrox_crypto_ctx *
get_crypto_ctx(struct rte_crypto_op *op)
{
	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
		if (likely(op->sym->session))
			return get_sym_session_private_data(op->sym->session,
							   nitrox_sym_drv_id);
	}

	return NULL;
}

static int
nitrox_enq_single_op(struct nitrox_qp *qp, struct rte_crypto_op *op)
{
	struct nitrox_crypto_ctx *ctx;
	struct nitrox_softreq *sr;
	int err;

	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
	ctx = get_crypto_ctx(op);
	if (unlikely(!ctx)) {
		op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
		return -EINVAL;
	}

	if (unlikely(rte_mempool_get(qp->sr_mp, (void **)&sr)))
		return -ENOMEM;

	err = nitrox_process_se_req(qp->qno, op, ctx, sr);
	if (unlikely(err)) {
		rte_mempool_put(qp->sr_mp, sr);
		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
		return err;
	}

	nitrox_qp_enqueue(qp, nitrox_sym_instr_addr(sr), sr);
	return 0;
}

static uint16_t
nitrox_sym_dev_enq_burst(void *queue_pair, struct rte_crypto_op **ops,
			 uint16_t nb_ops)
{
	struct nitrox_qp *qp = queue_pair;
	uint16_t free_slots = 0;
	uint16_t cnt = 0;
	bool err = false;

	free_slots = nitrox_qp_free_count(qp);
	if (nb_ops > free_slots)
		nb_ops = free_slots;

	for (cnt = 0; cnt < nb_ops; cnt++) {
		if (unlikely(nitrox_enq_single_op(qp, ops[cnt]))) {
			err = true;
			break;
		}
	}

	nitrox_ring_dbell(qp, cnt);
	qp->stats.enqueued_count += cnt;
	if (unlikely(err))
		qp->stats.enqueue_err_count++;

	return cnt;
}

static int
nitrox_deq_single_op(struct nitrox_qp *qp, struct rte_crypto_op **op_ptr)
{
	struct nitrox_softreq *sr;
	int ret;
	struct rte_crypto_op *op;

	sr = nitrox_qp_get_softreq(qp);
	ret = nitrox_check_se_req(sr, op_ptr);
	if (ret < 0)
		return -EAGAIN;

	op = *op_ptr;
	nitrox_qp_dequeue(qp);
	rte_mempool_put(qp->sr_mp, sr);
	if (!ret) {
		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
		qp->stats.dequeued_count++;

		return 0;
	}

	if (ret == MC_MAC_MISMATCH_ERR_CODE)
		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
	else
		op->status = RTE_CRYPTO_OP_STATUS_ERROR;

	qp->stats.dequeue_err_count++;
	return 0;
}

static uint16_t
nitrox_sym_dev_deq_burst(void *queue_pair, struct rte_crypto_op **ops,
			 uint16_t nb_ops)
{
	struct nitrox_qp *qp = queue_pair;
	uint16_t filled_slots = nitrox_qp_used_count(qp);
	int cnt = 0;

	if (nb_ops > filled_slots)
		nb_ops = filled_slots;

	for (cnt = 0; cnt < nb_ops; cnt++)
		if (nitrox_deq_single_op(qp, &ops[cnt]))
			break;

	return cnt;
}

static struct rte_cryptodev_ops nitrox_cryptodev_ops = {
	.dev_configure		= nitrox_sym_dev_config,
	.dev_start		= nitrox_sym_dev_start,
	.dev_stop		= nitrox_sym_dev_stop,
	.dev_close		= nitrox_sym_dev_close,
	.dev_infos_get		= nitrox_sym_dev_info_get,
	.stats_get		= nitrox_sym_dev_stats_get,
	.stats_reset		= nitrox_sym_dev_stats_reset,
	.queue_pair_setup	= nitrox_sym_dev_qp_setup,
	.queue_pair_release     = nitrox_sym_dev_qp_release,
	.sym_session_get_size   = nitrox_sym_dev_sess_get_size,
	.sym_session_configure  = nitrox_sym_dev_sess_configure,
	.sym_session_clear      = nitrox_sym_dev_sess_clear
};

int
nitrox_sym_pmd_create(struct nitrox_device *ndev)
{
	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
	struct rte_cryptodev_pmd_init_params init_params = {
			.name = "",
			.socket_id = ndev->pdev->device.numa_node,
			.private_data_size = sizeof(struct nitrox_sym_device)
	};
	struct rte_cryptodev *cdev;

	rte_pci_device_name(&ndev->pdev->addr, name, sizeof(name));
	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN - strlen(name),
		 "_n5sym");
	ndev->rte_sym_dev.driver = &nitrox_rte_sym_drv;
	ndev->rte_sym_dev.numa_node = ndev->pdev->device.numa_node;
	ndev->rte_sym_dev.devargs = NULL;
	cdev = rte_cryptodev_pmd_create(name, &ndev->rte_sym_dev,
					&init_params);
	if (!cdev) {
		NITROX_LOG(ERR, "Cryptodev '%s' creation failed\n", name);
		return -ENODEV;
	}

	ndev->rte_sym_dev.name = cdev->data->name;
	cdev->driver_id = nitrox_sym_drv_id;
	cdev->dev_ops = &nitrox_cryptodev_ops;
	cdev->enqueue_burst = nitrox_sym_dev_enq_burst;
	cdev->dequeue_burst = nitrox_sym_dev_deq_burst;
	cdev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
		RTE_CRYPTODEV_FF_HW_ACCELERATED |
		RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
		RTE_CRYPTODEV_FF_IN_PLACE_SGL |
		RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
		RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
		RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
		RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;

	ndev->sym_dev = cdev->data->dev_private;
	ndev->sym_dev->cdev = cdev;
	ndev->sym_dev->ndev = ndev;
	NITROX_LOG(DEBUG, "Created cryptodev '%s', dev_id %d, drv_id %d\n",
		   cdev->data->name, cdev->data->dev_id, nitrox_sym_drv_id);
	return 0;
}

int
nitrox_sym_pmd_destroy(struct nitrox_device *ndev)
{
	return rte_cryptodev_pmd_destroy(ndev->sym_dev->cdev);
}

static struct cryptodev_driver nitrox_crypto_drv;
RTE_PMD_REGISTER_CRYPTO_DRIVER(nitrox_crypto_drv,
		nitrox_rte_sym_drv,
		nitrox_sym_drv_id);