crypto/mvsam: support crypto/auth NULL algorithms
[dpdk.git] / drivers / crypto / mvsam / rte_mrvl_pmd_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Marvell International Ltd.
3  * Copyright(c) 2017 Semihalf.
4  * All rights reserved.
5  */
6
7 #include <string.h>
8
9 #include <rte_common.h>
10 #include <rte_malloc.h>
11 #include <rte_cryptodev_pmd.h>
12
13 #include "rte_mrvl_pmd_private.h"
14
15 /**
16  * Capabilities list to be used in reporting to DPDK.
17  */
18 static const struct rte_cryptodev_capabilities
19         mrvl_crypto_pmd_capabilities[] = {
20         {       /* MD5 HMAC */
21                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
22                 {.sym = {
23                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
24                         {.auth = {
25                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
26                                 .block_size = 64,
27                                 .key_size = {
28                                         .min = 1,
29                                         .max = 64,
30                                         .increment = 1
31                                 },
32                                 .digest_size = {
33                                         .min = 12,
34                                         .max = 16,
35                                         .increment = 4
36                                 },
37                         }, }
38                 }, }
39         },
40         {       /* MD5 */
41                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
42                         {.sym = {
43                                 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
44                                 {.auth = {
45                                         .algo = RTE_CRYPTO_AUTH_MD5,
46                                         .block_size = 64,
47                                         .key_size = {
48                                                 .min = 0,
49                                                 .max = 0,
50                                                 .increment = 0
51                                         },
52                                         .digest_size = {
53                                                 .min = 12,
54                                                 .max = 16,
55                                                 .increment = 4
56                                         },
57                                 }, }
58                         }, }
59         },
60         {       /* SHA1 HMAC */
61                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
62                         {.sym = {
63                                 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
64                                 {.auth = {
65                                         .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
66                                         .block_size = 64,
67                                         .key_size = {
68                                                 .min = 1,
69                                                 .max = 64,
70                                                 .increment = 1
71                                         },
72                                         .digest_size = {
73                                                 .min = 12,
74                                                 .max = 20,
75                                                 .increment = 4
76                                         },
77                                 }, }
78                         }, }
79         },
80         {       /* SHA1 */
81                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
82                 {.sym = {
83                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
84                         {.auth = {
85                                 .algo = RTE_CRYPTO_AUTH_SHA1,
86                                 .block_size = 64,
87                                 .key_size = {
88                                         .min = 0,
89                                         .max = 0,
90                                         .increment = 0
91                                 },
92                                 .digest_size = {
93                                         .min = 12,
94                                         .max = 20,
95                                         .increment = 4
96                                 },
97                         }, }
98                 }, }
99         },
100         {
101                 /* SHA224 HMAC */
102                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
103                 {.sym = {
104                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
105                         {.auth = {
106                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
107                                 .block_size = 64,
108                                 .key_size = {
109                                         .min = 1,
110                                         .max = 64,
111                                         .increment = 1
112                                 },
113                                 .digest_size = {
114                                         .min = 28,
115                                         .max = 28,
116                                         .increment = 0
117                                 },
118                         }, }
119                 }, }
120         },
121         {       /* SHA224 */
122                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
123                 {.sym = {
124                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
125                         {.auth = {
126                                 .algo = RTE_CRYPTO_AUTH_SHA224,
127                                 .block_size = 64,
128                                 .key_size = {
129                                         .min = 0,
130                                         .max = 0,
131                                         .increment = 0
132                                 },
133                                 .digest_size = {
134                                         .min = 12,
135                                         .max = 28,
136                                         .increment = 4
137                                 },
138                         }, }
139                 }, }
140         },
141         {       /* SHA256 HMAC */
142                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
143                         {.sym = {
144                                 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
145                                 {.auth = {
146                                         .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
147                                         .block_size = 64,
148                                         .key_size = {
149                                                 .min = 1,
150                                                 .max = 64,
151                                                 .increment = 1
152                                         },
153                                         .digest_size = {
154                                                 .min = 12,
155                                                 .max = 32,
156                                                 .increment = 4
157                                         },
158                                 }, }
159                         }, }
160         },
161         {       /* SHA256 */
162                         .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
163                         {.sym = {
164                                 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
165                                 {.auth = {
166                                         .algo = RTE_CRYPTO_AUTH_SHA256,
167                                         .block_size = 64,
168                                         .key_size = {
169                                                 .min = 0,
170                                                 .max = 0,
171                                                 .increment = 0
172                                         },
173                                         .digest_size = {
174                                                 .min = 12,
175                                                 .max = 32,
176                                                 .increment = 4
177                                         },
178                                 }, }
179                         }, }
180                 },
181         {       /* SHA384 HMAC */
182                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
183                 {.sym = {
184                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
185                         {.auth = {
186                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
187                                 .block_size = 128,
188                                 .key_size = {
189                                         .min = 1,
190                                         .max = 128,
191                                         .increment = 1
192                                 },
193                                 .digest_size = {
194                                         .min = 12,
195                                         .max = 48,
196                                         .increment = 4
197                                 },
198                         }, }
199                 }, }
200         },
201         {       /* SHA384 */
202                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
203                 {.sym = {
204                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
205                         {.auth = {
206                                 .algo = RTE_CRYPTO_AUTH_SHA384,
207                                 .block_size = 128,
208                                 .key_size = {
209                                         .min = 0,
210                                         .max = 0,
211                                         .increment = 0
212                                 },
213                                 .digest_size = {
214                                         .min = 12,
215                                         .max = 48,
216                                         .increment = 4
217                                 },
218                         }, }
219                 }, }
220         },
221         {       /* SHA512 HMAC */
222                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
223                 {.sym = {
224                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
225                         {.auth = {
226                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
227                                 .block_size = 128,
228                                 .key_size = {
229                                         .min = 1,
230                                         .max = 128,
231                                         .increment = 1
232                                 },
233                                 .digest_size = {
234                                         .min = 12,
235                                         .max = 48,
236                                         .increment = 4
237                                 },
238                         }, }
239                 }, }
240         },
241         {       /* SHA512  */
242                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
243                 {.sym = {
244                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
245                         {.auth = {
246                                 .algo = RTE_CRYPTO_AUTH_SHA512,
247                                 .block_size = 128,
248                                 .key_size = {
249                                         .min = 0,
250                                         .max = 0,
251                                         .increment = 0
252                                 },
253                                 .digest_size = {
254                                         .min = 12,
255                                         .max = 48,
256                                         .increment = 0
257                                 },
258                         }, }
259                 }, }
260         },
261         {       /* AES CBC */
262                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
263                         {.sym = {
264                                 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
265                                 {.cipher = {
266                                         .algo = RTE_CRYPTO_CIPHER_AES_CBC,
267                                         .block_size = 16,
268                                         .key_size = {
269                                                 .min = 16,
270                                                 .max = 32,
271                                                 .increment = 8
272                                         },
273                                         .iv_size = {
274                                                 .min = 16,
275                                                 .max = 16,
276                                                 .increment = 0
277                                         }
278                                 }, }
279                         }, }
280         },
281         {       /* AES CTR */
282                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
283                 {.sym = {
284                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
285                         {.cipher = {
286                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
287                                 .block_size = 16,
288                                 .key_size = {
289                                         .min = 16,
290                                         .max = 32,
291                                         .increment = 8
292                                 },
293                                 .iv_size = {
294                                         .min = 16,
295                                         .max = 16,
296                                         .increment = 0
297                                 }
298                         }, }
299                 }, }
300         },
301         {       /* AES ECB */
302                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
303                 {.sym = {
304                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
305                         {.cipher = {
306                                 .algo = RTE_CRYPTO_CIPHER_AES_ECB,
307                                 .block_size = 16,
308                                 .key_size = {
309                                         .min = 16,
310                                         .max = 32,
311                                         .increment = 8
312                                 },
313                                 .iv_size = {
314                                         .min = 0,
315                                         .max = 0,
316                                         .increment = 0
317                                 }
318                         }, }
319                 }, }
320         },
321         {       /* AES GCM */
322                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
323                 {.sym = {
324                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
325                         {.aead = {
326                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
327                                 .block_size = 16,
328                                 .key_size = {
329                                         .min = 16,
330                                         .max = 32,
331                                         .increment = 8
332                                 },
333                                 .digest_size = {
334                                         .min = 16,
335                                         .max = 16,
336                                         .increment = 0
337                                 },
338                                 .aad_size = {
339                                         .min = 8,
340                                         .max = 12,
341                                         .increment = 4
342                                 },
343                                 .iv_size = {
344                                         .min = 12,
345                                         .max = 16,
346                                         .increment = 4
347                                 }
348                         }, }
349                 }, }
350         },
351         {       /* AES GMAC (AUTH) */
352                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
353                 {.sym = {
354                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
355                         {.auth = {
356                                 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
357                                 .block_size = 16,
358                                 .key_size = {
359                                         .min = 16,
360                                         .max = 32,
361                                         .increment = 8
362                                 },
363                                 .digest_size = {
364                                         .min = 16,
365                                         .max = 16,
366                                         .increment = 0
367                                 },
368                                 .iv_size = {
369                                         .min = 8,
370                                         .max = 65532,
371                                         .increment = 4
372                                 }
373                         }, }
374                 }, }
375         },
376         {       /* 3DES CBC */
377                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
378                 {.sym = {
379                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
380                         {.cipher = {
381                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
382                                 .block_size = 8,
383                                 .key_size = {
384                                         .min = 24,
385                                         .max = 24,
386                                         .increment = 0
387                                 },
388                                 .iv_size = {
389                                         .min = 8,
390                                         .max = 8,
391                                         .increment = 0
392                                 }
393                         }, }
394                 }, }
395         },
396         {       /* 3DES CTR */
397                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
398                 {.sym = {
399                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
400                         {.cipher = {
401                                 .algo = RTE_CRYPTO_CIPHER_3DES_CTR,
402                                 .block_size = 8,
403                                 .key_size = {
404                                         .min = 24,
405                                         .max = 24,
406                                         .increment = 0
407                                 },
408                                 .iv_size = {
409                                         .min = 8,
410                                         .max = 8,
411                                         .increment = 0
412                                 }
413                         }, }
414                 }, }
415         },
416         {       /* NULL (AUTH) */
417                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
418                 {.sym = {
419                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
420                         {.auth = {
421                                 .algo = RTE_CRYPTO_AUTH_NULL,
422                                 .block_size = 1,
423                                 .key_size = {
424                                         .min = 0,
425                                         .max = 0,
426                                         .increment = 0
427                                 },
428                                 .digest_size = {
429                                         .min = 0,
430                                         .max = 0,
431                                         .increment = 0
432                                 },
433                                 .iv_size = {
434                                         .min = 0,
435                                         .max = 0,
436                                         .increment = 0
437                                 }
438                         }, },
439                 }, },
440         },
441         {       /* NULL (CIPHER) */
442                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
443                 {.sym = {
444                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
445                         {.cipher = {
446                                 .algo = RTE_CRYPTO_CIPHER_NULL,
447                                 .block_size = 1,
448                                 .key_size = {
449                                         .min = 0,
450                                         .max = 0,
451                                         .increment = 0
452                                 },
453                                 .iv_size = {
454                                         .min = 0,
455                                         .max = 0,
456                                         .increment = 0
457                                 }
458                         }, },
459                 }, }
460         },
461
462         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
463 };
464
465
466 /**
467  * Configure device (PMD ops callback).
468  *
469  * @param dev Pointer to the device structure.
470  * @param config Pointer to configuration structure.
471  * @returns 0. Always.
472  */
473 static int
474 mrvl_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev,
475                 __rte_unused struct rte_cryptodev_config *config)
476 {
477         return 0;
478 }
479
480 /**
481  * Start device (PMD ops callback).
482  *
483  * @param dev Pointer to the device structure.
484  * @returns 0. Always.
485  */
486 static int
487 mrvl_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
488 {
489         return 0;
490 }
491
492 /**
493  * Stop device (PMD ops callback).
494  *
495  * @param dev Pointer to the device structure.
496  * @returns 0. Always.
497  */
498 static void
499 mrvl_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
500 {
501 }
502
503 /**
504  * Get device statistics (PMD ops callback).
505  *
506  * @param dev Pointer to the device structure.
507  * @param stats Pointer to statistics structure [out].
508  */
509 static void
510 mrvl_crypto_pmd_stats_get(struct rte_cryptodev *dev,
511                 struct rte_cryptodev_stats *stats)
512 {
513         int qp_id;
514
515         for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
516                 struct mrvl_crypto_qp *qp = dev->data->queue_pairs[qp_id];
517
518                 stats->enqueued_count += qp->stats.enqueued_count;
519                 stats->dequeued_count += qp->stats.dequeued_count;
520
521                 stats->enqueue_err_count += qp->stats.enqueue_err_count;
522                 stats->dequeue_err_count += qp->stats.dequeue_err_count;
523         }
524 }
525
526 /**
527  * Reset device statistics (PMD ops callback).
528  *
529  * @param dev Pointer to the device structure.
530  */
531 static void
532 mrvl_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
533 {
534         int qp_id;
535
536         for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
537                 struct mrvl_crypto_qp *qp = dev->data->queue_pairs[qp_id];
538
539                 memset(&qp->stats, 0, sizeof(qp->stats));
540         }
541 }
542
543 /**
544  * Get device info (PMD ops callback).
545  *
546  * @param dev Pointer to the device structure.
547  * @param dev_info Pointer to the device info structure [out].
548  */
549 static void
550 mrvl_crypto_pmd_info_get(struct rte_cryptodev *dev,
551                 struct rte_cryptodev_info *dev_info)
552 {
553         struct mrvl_crypto_private *internals = dev->data->dev_private;
554
555         if (dev_info != NULL) {
556                 dev_info->driver_id = dev->driver_id;
557                 dev_info->feature_flags = dev->feature_flags;
558                 dev_info->capabilities = mrvl_crypto_pmd_capabilities;
559                 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
560                 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
561         }
562 }
563
564 /**
565  * Release queue pair (PMD ops callback).
566  *
567  * @param dev Pointer to the device structure.
568  * @param qp_id ID of Queue Pair to release.
569  * @returns 0. Always.
570  */
571 static int
572 mrvl_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
573 {
574         struct mrvl_crypto_qp *qp =
575                         (struct mrvl_crypto_qp *)dev->data->queue_pairs[qp_id];
576
577         if (dev->data->queue_pairs[qp_id] != NULL) {
578                 sam_cio_flush(qp->cio);
579                 sam_cio_deinit(qp->cio);
580                 rte_free(dev->data->queue_pairs[qp_id]);
581                 dev->data->queue_pairs[qp_id] = NULL;
582         }
583
584         return 0;
585 }
586
587 /**
588  * Close device (PMD ops callback).
589  *
590  * @param dev Pointer to the device structure.
591  * @returns 0. Always.
592  */
593 static int
594 mrvl_crypto_pmd_close(struct rte_cryptodev *dev)
595 {
596         int qp_id;
597
598         for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++)
599                 mrvl_crypto_pmd_qp_release(dev, qp_id);
600
601         return 0;
602 }
603
604 /**
605  * Setup a queue pair (PMD ops callback).
606  *
607  * @param dev Pointer to the device structure.
608  * @param qp_id ID of the Queue Pair.
609  * @param qp_conf Queue pair configuration (nb of descriptors).
610  * @param socket_id NUMA socket to allocate memory on.
611  * @returns 0 upon success, negative value otherwise.
612  */
613 static int
614 mrvl_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
615                 const struct rte_cryptodev_qp_conf *qp_conf,
616                 int socket_id, struct rte_mempool *session_pool)
617 {
618         struct mrvl_crypto_qp *qp = NULL;
619         char match[RTE_CRYPTODEV_NAME_MAX_LEN];
620         unsigned int n;
621
622         /* Allocate the queue pair data structure. */
623         qp = rte_zmalloc_socket("MRVL Crypto PMD Queue Pair", sizeof(*qp),
624                                         RTE_CACHE_LINE_SIZE, socket_id);
625         if (qp == NULL)
626                 return -ENOMEM;
627
628         /* Free old qp prior setup if needed. */
629         if (dev->data->queue_pairs[qp_id] != NULL)
630                 mrvl_crypto_pmd_qp_release(dev, qp_id);
631
632         do { /* Error handling block */
633
634                 /*
635                  * This extra check is necessary due to a bug in
636                  * crypto library.
637                  */
638                 int num = sam_get_num_inst();
639                 if (num == 0) {
640                         MRVL_CRYPTO_LOG_ERR("No crypto engines detected.\n");
641                         return -1;
642                 }
643
644                 /*
645                  * In case two crypto engines are enabled qps will
646                  * be evenly spread among them. Even and odd qps will
647                  * be handled by cio-0 and cio-1 respectively. qp-cio mapping
648                  * will look as follows:
649                  *
650                  * qp:      0        1        2        3
651                  * cio-x:y: cio-0:0, cio-1:0, cio-0:1, cio-1:1
652                  *
653                  * qp:      4        5        6        7
654                  * cio-x:y: cio-0:2, cio-1:2, cio-0:3, cio-1:3
655                  *
656                  * In case just one engine is enabled mapping will look as
657                  * follows:
658                  * qp:      0        1        2        3
659                  * cio-x:y: cio-0:0, cio-0:1, cio-0:2, cio-0:3
660                  */
661                 n = snprintf(match, sizeof(match), "cio-%u:%u",
662                                 qp_id % num, qp_id / num);
663
664                 if (n >= sizeof(match))
665                         break;
666
667                 qp->cio_params.match = match;
668                 qp->cio_params.size = qp_conf->nb_descriptors;
669
670                 if (sam_cio_init(&qp->cio_params, &qp->cio) < 0)
671                         break;
672
673                 qp->sess_mp = session_pool;
674
675                 memset(&qp->stats, 0, sizeof(qp->stats));
676                 dev->data->queue_pairs[qp_id] = qp;
677                 return 0;
678         } while (0);
679
680         rte_free(qp);
681         return -1;
682 }
683
684 /** Return the number of allocated queue pairs (PMD ops callback).
685  *
686  * @param dev Pointer to the device structure.
687  * @returns Number of allocated queue pairs.
688  */
689 static uint32_t
690 mrvl_crypto_pmd_qp_count(struct rte_cryptodev *dev)
691 {
692         return dev->data->nb_queue_pairs;
693 }
694
695 /** Returns the size of the session structure (PMD ops callback).
696  *
697  * @param dev Pointer to the device structure [Unused].
698  * @returns Size of Marvell crypto session.
699  */
700 static unsigned
701 mrvl_crypto_pmd_sym_session_get_size(__rte_unused struct rte_cryptodev *dev)
702 {
703         return sizeof(struct mrvl_crypto_session);
704 }
705
706 /** Configure the session from a crypto xform chain (PMD ops callback).
707  *
708  * @param dev Pointer to the device structure.
709  * @param xform Pointer to the crytpo configuration structure.
710  * @param sess Pointer to the empty session structure.
711  * @returns 0 upon success, negative value otherwise.
712  */
713 static int
714 mrvl_crypto_pmd_sym_session_configure(__rte_unused struct rte_cryptodev *dev,
715                 struct rte_crypto_sym_xform *xform,
716                 struct rte_cryptodev_sym_session *sess,
717                 struct rte_mempool *mp)
718 {
719         struct mrvl_crypto_session *mrvl_sess;
720         void *sess_private_data;
721         int ret;
722
723         if (sess == NULL) {
724                 MRVL_CRYPTO_LOG_ERR("Invalid session struct.");
725                 return -EINVAL;
726         }
727
728         if (rte_mempool_get(mp, &sess_private_data)) {
729                 CDEV_LOG_ERR("Couldn't get object from session mempool.");
730                 return -ENOMEM;
731         }
732
733         ret = mrvl_crypto_set_session_parameters(sess_private_data, xform);
734         if (ret != 0) {
735                 MRVL_CRYPTO_LOG_ERR("Failed to configure session parameters.");
736
737                 /* Return session to mempool */
738                 rte_mempool_put(mp, sess_private_data);
739                 return ret;
740         }
741
742         set_sym_session_private_data(sess, dev->driver_id, sess_private_data);
743
744         mrvl_sess = (struct mrvl_crypto_session *)sess_private_data;
745         if (sam_session_create(&mrvl_sess->sam_sess_params,
746                                 &mrvl_sess->sam_sess) < 0) {
747                 MRVL_CRYPTO_LOG_DBG("Failed to create session!");
748                 return -EIO;
749         }
750
751         return 0;
752 }
753
754 /**
755  * Clear the memory of session so it doesn't leave key material behind.
756  *
757  * @param dev Pointer to the device structure.
758  * @returns 0. Always.
759  */
760 static void
761 mrvl_crypto_pmd_sym_session_clear(struct rte_cryptodev *dev,
762                 struct rte_cryptodev_sym_session *sess)
763 {
764
765         uint8_t index = dev->driver_id;
766         void *sess_priv = get_sym_session_private_data(sess, index);
767
768         /* Zero out the whole structure */
769         if (sess_priv) {
770                 struct mrvl_crypto_session *mrvl_sess =
771                         (struct mrvl_crypto_session *)sess_priv;
772
773                 if (mrvl_sess->sam_sess &&
774                     sam_session_destroy(mrvl_sess->sam_sess) < 0) {
775                         MRVL_CRYPTO_LOG_INFO("Error while destroying session!");
776                 }
777
778                 memset(sess, 0, sizeof(struct mrvl_crypto_session));
779                 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
780                 set_sym_session_private_data(sess, index, NULL);
781                 rte_mempool_put(sess_mp, sess_priv);
782         }
783 }
784
785 /**
786  * PMD handlers for crypto ops.
787  */
788 static struct rte_cryptodev_ops mrvl_crypto_pmd_ops = {
789                 .dev_configure          = mrvl_crypto_pmd_config,
790                 .dev_start              = mrvl_crypto_pmd_start,
791                 .dev_stop               = mrvl_crypto_pmd_stop,
792                 .dev_close              = mrvl_crypto_pmd_close,
793
794                 .dev_infos_get          = mrvl_crypto_pmd_info_get,
795
796                 .stats_get              = mrvl_crypto_pmd_stats_get,
797                 .stats_reset            = mrvl_crypto_pmd_stats_reset,
798
799                 .queue_pair_setup       = mrvl_crypto_pmd_qp_setup,
800                 .queue_pair_release     = mrvl_crypto_pmd_qp_release,
801                 .queue_pair_count       = mrvl_crypto_pmd_qp_count,
802
803                 .sym_session_get_size   = mrvl_crypto_pmd_sym_session_get_size,
804                 .sym_session_configure  = mrvl_crypto_pmd_sym_session_configure,
805                 .sym_session_clear      = mrvl_crypto_pmd_sym_session_clear
806 };
807
808 struct rte_cryptodev_ops *rte_mrvl_crypto_pmd_ops = &mrvl_crypto_pmd_ops;