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