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