24ad961fbbc9df3bcb3a43645e7a5fc63cb09419
[dpdk.git] / drivers / crypto / ccp / ccp_pmd_ops.c
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
3  */
4
5 #include <string.h>
6
7 #include <rte_common.h>
8 #include <rte_cryptodev_pmd.h>
9 #include <rte_malloc.h>
10
11 #include "ccp_pmd_private.h"
12 #include "ccp_dev.h"
13 #include "ccp_crypto.h"
14
15 static const struct rte_cryptodev_capabilities ccp_pmd_capabilities[] = {
16         {       /* SHA1 */
17                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
18                 {.sym = {
19                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
20                         {.auth = {
21                                  .algo = RTE_CRYPTO_AUTH_SHA1,
22                                  .block_size = 64,
23                                  .key_size = {
24                                          .min = 0,
25                                          .max = 0,
26                                          .increment = 0
27                                  },
28                                  .digest_size = {
29                                          .min = 20,
30                                          .max = 20,
31                                          .increment = 0
32                                  },
33                                  .aad_size = { 0 }
34                          }, }
35                 }, }
36         },
37         {       /* SHA1 HMAC */
38                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
39                 {.sym = {
40                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
41                         {.auth = {
42                                  .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
43                                  .block_size = 64,
44                                  .key_size = {
45                                          .min = 1,
46                                          .max = 64,
47                                          .increment = 1
48                                  },
49                                  .digest_size = {
50                                          .min = 20,
51                                          .max = 20,
52                                          .increment = 0
53                                  },
54                                  .aad_size = { 0 }
55                          }, }
56                 }, }
57         },
58         {       /* SHA224 */
59                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
60                 {.sym = {
61                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
62                         {.auth = {
63                                  .algo = RTE_CRYPTO_AUTH_SHA224,
64                                  .block_size = 64,
65                                  .key_size = {
66                                          .min = 0,
67                                          .max = 0,
68                                          .increment = 0
69                                  },
70                                  .digest_size = {
71                                          .min = 28,
72                                          .max = 28,
73                                          .increment = 0
74                                  },
75                                  .aad_size = { 0 }
76                          }, }
77                 }, }
78         },
79         {       /* SHA224 HMAC */
80                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
81                 {.sym = {
82                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
83                         {.auth = {
84                                  .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
85                                  .block_size = 64,
86                                  .key_size = {
87                                          .min = 1,
88                                          .max = 64,
89                                          .increment = 1
90                                  },
91                                  .digest_size = {
92                                          .min = 28,
93                                          .max = 28,
94                                          .increment = 0
95                                  },
96                                  .aad_size = { 0 }
97                          }, }
98                 }, }
99         },
100         {       /* SHA3-224 */
101                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
102                 {.sym = {
103                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
104                         {.auth = {
105                                  .algo = RTE_CRYPTO_AUTH_SHA3_224,
106                                  .block_size = 144,
107                                  .key_size = {
108                                          .min = 0,
109                                          .max = 0,
110                                          .increment = 0
111                                  },
112                                  .digest_size = {
113                                          .min = 28,
114                                          .max = 28,
115                                          .increment = 0
116                                  },
117                                  .aad_size = { 0 }
118                          }, }
119                 }, }
120         },
121         {       /* SHA3-224  HMAC*/
122                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
123                 {.sym = {
124                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
125                         {.auth = {
126                                  .algo = RTE_CRYPTO_AUTH_SHA3_224_HMAC,
127                                  .block_size = 144,
128                                  .key_size = {
129                                          .min = 1,
130                                          .max = 144,
131                                          .increment = 1
132                                  },
133                                  .digest_size = {
134                                          .min = 28,
135                                          .max = 28,
136                                          .increment = 0
137                                  },
138                                  .aad_size = { 0 }
139                          }, }
140                 }, }
141         },
142         {       /* SHA256 */
143                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
144                 {.sym = {
145                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
146                         {.auth = {
147                                  .algo = RTE_CRYPTO_AUTH_SHA256,
148                                  .block_size = 64,
149                                  .key_size = {
150                                          .min = 0,
151                                          .max = 0,
152                                          .increment = 0
153                                  },
154                                  .digest_size = {
155                                          .min = 32,
156                                          .max = 32,
157                                          .increment = 0
158                                  },
159                                  .aad_size = { 0 }
160                          }, }
161                 }, }
162         },
163         {       /* SHA256 HMAC */
164                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
165                 {.sym = {
166                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
167                         {.auth = {
168                                  .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
169                                  .block_size = 64,
170                                  .key_size = {
171                                          .min = 1,
172                                          .max = 64,
173                                          .increment = 1
174                                  },
175                                  .digest_size = {
176                                          .min = 32,
177                                          .max = 32,
178                                          .increment = 0
179                                  },
180                                  .aad_size = { 0 }
181                          }, }
182                 }, }
183         },
184         {       /* SHA3-256 */
185                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
186                 {.sym = {
187                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
188                         {.auth = {
189                                  .algo = RTE_CRYPTO_AUTH_SHA3_256,
190                                  .block_size = 136,
191                                  .key_size = {
192                                          .min = 0,
193                                          .max = 0,
194                                          .increment = 0
195                                  },
196                                  .digest_size = {
197                                          .min = 32,
198                                          .max = 32,
199                                          .increment = 0
200                                  },
201                                  .aad_size = { 0 }
202                          }, }
203                 }, }
204         },
205         {       /* SHA3-256-HMAC */
206                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
207                 {.sym = {
208                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
209                         {.auth = {
210                                  .algo = RTE_CRYPTO_AUTH_SHA3_256_HMAC,
211                                  .block_size = 136,
212                                  .key_size = {
213                                          .min = 1,
214                                          .max = 136,
215                                          .increment = 1
216                                  },
217                                  .digest_size = {
218                                          .min = 32,
219                                          .max = 32,
220                                          .increment = 0
221                                  },
222                                  .aad_size = { 0 }
223                          }, }
224                 }, }
225         },
226         {       /* SHA384 */
227                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
228                 {.sym = {
229                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
230                         {.auth = {
231                                  .algo = RTE_CRYPTO_AUTH_SHA384,
232                                  .block_size = 128,
233                                  .key_size = {
234                                          .min = 0,
235                                          .max = 0,
236                                          .increment = 0
237                                  },
238                                  .digest_size = {
239                                          .min = 48,
240                                          .max = 48,
241                                          .increment = 0
242                                  },
243                                  .aad_size = { 0 }
244                          }, }
245                 }, }
246         },
247         {       /* SHA384 HMAC */
248                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
249                 {.sym = {
250                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
251                         {.auth = {
252                                  .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
253                                  .block_size = 128,
254                                  .key_size = {
255                                          .min = 1,
256                                          .max = 128,
257                                          .increment = 1
258                                  },
259                                  .digest_size = {
260                                          .min = 48,
261                                          .max = 48,
262                                          .increment = 0
263                                  },
264                                  .aad_size = { 0 }
265                          }, }
266                 }, }
267         },
268         {       /* SHA3-384 */
269                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
270                 {.sym = {
271                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
272                         {.auth = {
273                                  .algo = RTE_CRYPTO_AUTH_SHA3_384,
274                                  .block_size = 104,
275                                  .key_size = {
276                                          .min = 0,
277                                          .max = 0,
278                                          .increment = 0
279                                  },
280                                  .digest_size = {
281                                          .min = 48,
282                                          .max = 48,
283                                          .increment = 0
284                                  },
285                                  .aad_size = { 0 }
286                          }, }
287                 }, }
288         },
289         {       /* SHA3-384-HMAC */
290                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
291                 {.sym = {
292                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
293                         {.auth = {
294                                  .algo = RTE_CRYPTO_AUTH_SHA3_384_HMAC,
295                                  .block_size = 104,
296                                  .key_size = {
297                                          .min = 1,
298                                          .max = 104,
299                                          .increment = 1
300                                  },
301                                  .digest_size = {
302                                          .min = 48,
303                                          .max = 48,
304                                          .increment = 0
305                                  },
306                                  .aad_size = { 0 }
307                          }, }
308                 }, }
309         },
310         {       /* SHA512  */
311                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
312                 {.sym = {
313                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
314                         {.auth = {
315                                  .algo = RTE_CRYPTO_AUTH_SHA512,
316                                  .block_size = 128,
317                                  .key_size = {
318                                          .min = 0,
319                                          .max = 0,
320                                          .increment = 0
321                                  },
322                                  .digest_size = {
323                                          .min = 64,
324                                          .max = 64,
325                                          .increment = 0
326                                  },
327                                  .aad_size = { 0 }
328                          }, }
329                 }, }
330         },
331         {       /* SHA512 HMAC */
332                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
333                 {.sym = {
334                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
335                         {.auth = {
336                                  .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
337                                  .block_size = 128,
338                                  .key_size = {
339                                          .min = 1,
340                                          .max = 128,
341                                          .increment = 1
342                                  },
343                                  .digest_size = {
344                                          .min = 64,
345                                          .max = 64,
346                                          .increment = 0
347                                  },
348                                  .aad_size = { 0 }
349                          }, }
350                 }, }
351         },
352         {       /* SHA3-512  */
353                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
354                 {.sym = {
355                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
356                         {.auth = {
357                                  .algo = RTE_CRYPTO_AUTH_SHA3_512,
358                                  .block_size = 72,
359                                  .key_size = {
360                                          .min = 0,
361                                          .max = 0,
362                                          .increment = 0
363                                  },
364                                  .digest_size = {
365                                          .min = 64,
366                                          .max = 64,
367                                          .increment = 0
368                                  },
369                                  .aad_size = { 0 }
370                          }, }
371                 }, }
372         },
373         {       /* SHA3-512-HMAC  */
374                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
375                 {.sym = {
376                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
377                         {.auth = {
378                                  .algo = RTE_CRYPTO_AUTH_SHA3_512_HMAC,
379                                  .block_size = 72,
380                                  .key_size = {
381                                          .min = 1,
382                                          .max = 72,
383                                          .increment = 1
384                                  },
385                                  .digest_size = {
386                                          .min = 64,
387                                          .max = 64,
388                                          .increment = 0
389                                  },
390                                  .aad_size = { 0 }
391                         }, }
392                 }, }
393         },
394         {       /*AES-CMAC */
395                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
396                 {.sym = {
397                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
398                         {.auth = {
399                                  .algo = RTE_CRYPTO_AUTH_AES_CMAC,
400                                  .block_size = 16,
401                                  .key_size = {
402                                          .min = 16,
403                                          .max = 32,
404                                          .increment = 8
405                                  },
406                                  .digest_size = {
407                                          .min = 16,
408                                          .max = 16,
409                                          .increment = 0
410                                  },
411                         }, }
412                 }, }
413         },
414         {       /* AES ECB */
415                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
416                 {.sym = {
417                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
418                         {.cipher = {
419                                 .algo = RTE_CRYPTO_CIPHER_AES_ECB,
420                                 .block_size = 16,
421                                 .key_size = {
422                                    .min = 16,
423                                    .max = 32,
424                                    .increment = 8
425                                 },
426                                 .iv_size = {
427                                    .min = 0,
428                                    .max = 0,
429                                    .increment = 0
430                                 }
431                         }, }
432                 }, }
433         },
434         {       /* AES CBC */
435                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
436                 {.sym = {
437                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
438                         {.cipher = {
439                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
440                                 .block_size = 16,
441                                 .key_size = {
442                                         .min = 16,
443                                         .max = 32,
444                                         .increment = 8
445                                 },
446                                 .iv_size = {
447                                         .min = 16,
448                                         .max = 16,
449                                         .increment = 0
450                                 }
451                         }, }
452                 }, }
453         },
454         {       /* AES CTR */
455                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
456                 {.sym = {
457                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
458                         {.cipher = {
459                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
460                                 .block_size = 16,
461                                 .key_size = {
462                                         .min = 16,
463                                         .max = 32,
464                                         .increment = 8
465                                 },
466                                 .iv_size = {
467                                         .min = 16,
468                                         .max = 16,
469                                         .increment = 0
470                                 }
471                         }, }
472                 }, }
473         },
474         {       /* 3DES CBC */
475                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
476                 {.sym = {
477                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
478                         {.cipher = {
479                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
480                                 .block_size = 8,
481                                 .key_size = {
482                                         .min = 16,
483                                         .max = 24,
484                                         .increment = 8
485                                 },
486                                 .iv_size = {
487                                         .min = 8,
488                                         .max = 8,
489                                         .increment = 0
490                                 }
491                         }, }
492                 }, }
493         },
494         {       /* AES GCM */
495                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
496                 {.sym = {
497                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
498                         {.aead = {
499                                  .algo = RTE_CRYPTO_AEAD_AES_GCM,
500                                  .block_size = 16,
501                                  .key_size = {
502                                          .min = 16,
503                                          .max = 32,
504                                          .increment = 8
505                                  },
506                                  .digest_size = {
507                                          .min = 16,
508                                          .max = 16,
509                                          .increment = 0
510                                  },
511                                  .aad_size = {
512                                          .min = 0,
513                                          .max = 65535,
514                                          .increment = 1
515                                  },
516                                  .iv_size = {
517                                          .min = 12,
518                                          .max = 16,
519                                          .increment = 4
520                                  },
521                         }, }
522                 }, }
523         },
524         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
525 };
526
527 static int
528 ccp_pmd_config(struct rte_cryptodev *dev __rte_unused,
529                struct rte_cryptodev_config *config __rte_unused)
530 {
531         return 0;
532 }
533
534 static int
535 ccp_pmd_start(struct rte_cryptodev *dev)
536 {
537         return ccp_dev_start(dev);
538 }
539
540 static void
541 ccp_pmd_stop(struct rte_cryptodev *dev __rte_unused)
542 {
543
544 }
545
546 static int
547 ccp_pmd_close(struct rte_cryptodev *dev __rte_unused)
548 {
549         return 0;
550 }
551
552 static void
553 ccp_pmd_stats_get(struct rte_cryptodev *dev,
554                   struct rte_cryptodev_stats *stats)
555 {
556         int qp_id;
557
558         for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
559                 struct ccp_qp *qp = dev->data->queue_pairs[qp_id];
560
561                 stats->enqueued_count += qp->qp_stats.enqueued_count;
562                 stats->dequeued_count += qp->qp_stats.dequeued_count;
563
564                 stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
565                 stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
566         }
567
568 }
569
570 static void
571 ccp_pmd_stats_reset(struct rte_cryptodev *dev)
572 {
573         int qp_id;
574
575         for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
576                 struct ccp_qp *qp = dev->data->queue_pairs[qp_id];
577
578                 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
579         }
580 }
581
582 static void
583 ccp_pmd_info_get(struct rte_cryptodev *dev,
584                  struct rte_cryptodev_info *dev_info)
585 {
586         struct ccp_private *internals = dev->data->dev_private;
587
588         if (dev_info != NULL) {
589                 dev_info->driver_id = dev->driver_id;
590                 dev_info->feature_flags = dev->feature_flags;
591                 dev_info->capabilities = ccp_pmd_capabilities;
592                 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
593                 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
594         }
595 }
596
597 static int
598 ccp_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
599 {
600         struct ccp_qp *qp;
601
602         if (dev->data->queue_pairs[qp_id] != NULL) {
603                 qp = (struct ccp_qp *)dev->data->queue_pairs[qp_id];
604                 rte_ring_free(qp->processed_pkts);
605                 rte_mempool_free(qp->batch_mp);
606                 rte_free(qp);
607                 dev->data->queue_pairs[qp_id] = NULL;
608         }
609         return 0;
610 }
611
612 static int
613 ccp_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
614                 struct ccp_qp *qp)
615 {
616         unsigned int n = snprintf(qp->name, sizeof(qp->name),
617                         "ccp_pmd_%u_qp_%u",
618                         dev->data->dev_id, qp->id);
619
620         if (n > sizeof(qp->name))
621                 return -1;
622
623         return 0;
624 }
625
626 static struct rte_ring *
627 ccp_pmd_qp_create_batch_info_ring(struct ccp_qp *qp,
628                                   unsigned int ring_size, int socket_id)
629 {
630         struct rte_ring *r;
631
632         r = rte_ring_lookup(qp->name);
633         if (r) {
634                 if (r->size >= ring_size) {
635                         CCP_LOG_INFO(
636                                 "Reusing ring %s for processed packets",
637                                 qp->name);
638                         return r;
639                 }
640                 CCP_LOG_INFO(
641                         "Unable to reuse ring %s for processed packets",
642                          qp->name);
643                 return NULL;
644         }
645
646         return rte_ring_create(qp->name, ring_size, socket_id,
647                         RING_F_SP_ENQ | RING_F_SC_DEQ);
648 }
649
650 static int
651 ccp_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
652                  const struct rte_cryptodev_qp_conf *qp_conf,
653                  int socket_id, struct rte_mempool *session_pool)
654 {
655         struct ccp_private *internals = dev->data->dev_private;
656         struct ccp_qp *qp;
657         int retval = 0;
658
659         if (qp_id >= internals->max_nb_qpairs) {
660                 CCP_LOG_ERR("Invalid qp_id %u, should be less than %u",
661                             qp_id, internals->max_nb_qpairs);
662                 return (-EINVAL);
663         }
664
665         /* Free memory prior to re-allocation if needed. */
666         if (dev->data->queue_pairs[qp_id] != NULL)
667                 ccp_pmd_qp_release(dev, qp_id);
668
669         /* Allocate the queue pair data structure. */
670         qp = rte_zmalloc_socket("CCP Crypto PMD Queue Pair", sizeof(*qp),
671                                         RTE_CACHE_LINE_SIZE, socket_id);
672         if (qp == NULL) {
673                 CCP_LOG_ERR("Failed to allocate queue pair memory");
674                 return (-ENOMEM);
675         }
676
677         qp->dev = dev;
678         qp->id = qp_id;
679         dev->data->queue_pairs[qp_id] = qp;
680
681         retval = ccp_pmd_qp_set_unique_name(dev, qp);
682         if (retval) {
683                 CCP_LOG_ERR("Failed to create unique name for ccp qp");
684                 goto qp_setup_cleanup;
685         }
686
687         qp->processed_pkts = ccp_pmd_qp_create_batch_info_ring(qp,
688                         qp_conf->nb_descriptors, socket_id);
689         if (qp->processed_pkts == NULL) {
690                 CCP_LOG_ERR("Failed to create batch info ring");
691                 goto qp_setup_cleanup;
692         }
693
694         qp->sess_mp = session_pool;
695
696         /* mempool for batch info */
697         qp->batch_mp = rte_mempool_create(
698                                 qp->name,
699                                 qp_conf->nb_descriptors,
700                                 sizeof(struct ccp_batch_info),
701                                 RTE_CACHE_LINE_SIZE,
702                                 0, NULL, NULL, NULL, NULL,
703                                 SOCKET_ID_ANY, 0);
704         if (qp->batch_mp == NULL)
705                 goto qp_setup_cleanup;
706         memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
707         return 0;
708
709 qp_setup_cleanup:
710         dev->data->queue_pairs[qp_id] = NULL;
711         if (qp)
712                 rte_free(qp);
713         return -1;
714 }
715
716 static int
717 ccp_pmd_qp_start(struct rte_cryptodev *dev __rte_unused,
718                  uint16_t queue_pair_id __rte_unused)
719 {
720         return -ENOTSUP;
721 }
722
723 static int
724 ccp_pmd_qp_stop(struct rte_cryptodev *dev __rte_unused,
725                 uint16_t queue_pair_id __rte_unused)
726 {
727         return -ENOTSUP;
728 }
729
730 static uint32_t
731 ccp_pmd_qp_count(struct rte_cryptodev *dev)
732 {
733         return dev->data->nb_queue_pairs;
734 }
735
736 static unsigned
737 ccp_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
738 {
739         return sizeof(struct ccp_session);
740 }
741
742 static int
743 ccp_pmd_session_configure(struct rte_cryptodev *dev,
744                           struct rte_crypto_sym_xform *xform,
745                           struct rte_cryptodev_sym_session *sess,
746                           struct rte_mempool *mempool)
747 {
748         int ret;
749         void *sess_private_data;
750
751         if (unlikely(sess == NULL || xform == NULL)) {
752                 CCP_LOG_ERR("Invalid session struct or xform");
753                 return -ENOMEM;
754         }
755
756         if (rte_mempool_get(mempool, &sess_private_data)) {
757                 CCP_LOG_ERR("Couldn't get object from session mempool");
758                 return -ENOMEM;
759         }
760         ret = ccp_set_session_parameters(sess_private_data, xform);
761         if (ret != 0) {
762                 CCP_LOG_ERR("failed configure session parameters");
763
764                 /* Return session to mempool */
765                 rte_mempool_put(mempool, sess_private_data);
766                 return ret;
767         }
768         set_session_private_data(sess, dev->driver_id,
769                                  sess_private_data);
770
771         return 0;
772 }
773
774 static void
775 ccp_pmd_session_clear(struct rte_cryptodev *dev,
776                       struct rte_cryptodev_sym_session *sess)
777 {
778         uint8_t index = dev->driver_id;
779         void *sess_priv = get_session_private_data(sess, index);
780
781         if (sess_priv) {
782                 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
783
784                 rte_mempool_put(sess_mp, sess_priv);
785                 memset(sess_priv, 0, sizeof(struct ccp_session));
786                 set_session_private_data(sess, index, NULL);
787         }
788 }
789
790 struct rte_cryptodev_ops ccp_ops = {
791                 .dev_configure          = ccp_pmd_config,
792                 .dev_start              = ccp_pmd_start,
793                 .dev_stop               = ccp_pmd_stop,
794                 .dev_close              = ccp_pmd_close,
795
796                 .stats_get              = ccp_pmd_stats_get,
797                 .stats_reset            = ccp_pmd_stats_reset,
798
799                 .dev_infos_get          = ccp_pmd_info_get,
800
801                 .queue_pair_setup       = ccp_pmd_qp_setup,
802                 .queue_pair_release     = ccp_pmd_qp_release,
803                 .queue_pair_start       = ccp_pmd_qp_start,
804                 .queue_pair_stop        = ccp_pmd_qp_stop,
805                 .queue_pair_count       = ccp_pmd_qp_count,
806
807                 .session_get_size       = ccp_pmd_session_get_size,
808                 .session_configure      = ccp_pmd_session_configure,
809                 .session_clear          = ccp_pmd_session_clear,
810 };
811
812 struct rte_cryptodev_ops *ccp_pmd_ops = &ccp_ops;