6e14b37a6824df6a64609aa77a5307e928c08156
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev_sec.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2020 Marvell International Ltd.
3  */
4
5 #include <rte_cryptodev.h>
6 #include <rte_malloc.h>
7 #include <rte_security.h>
8 #include <rte_security_driver.h>
9
10 #include "otx2_cryptodev.h"
11 #include "otx2_cryptodev_capabilities.h"
12 #include "otx2_cryptodev_sec.h"
13 #include "otx2_security.h"
14
15 static unsigned int
16 otx2_crypto_sec_session_get_size(void *device __rte_unused)
17 {
18         return sizeof(struct otx2_sec_session);
19 }
20
21 static int
22 otx2_crypto_sec_set_pkt_mdata(void *device __rte_unused,
23                               struct rte_security_session *session,
24                               struct rte_mbuf *m, void *params __rte_unused)
25 {
26         /* Set security session as the pkt metadata */
27         m->udata64 = (uint64_t)session;
28
29         return 0;
30 }
31
32 static int
33 otx2_crypto_sec_get_userdata(void *device __rte_unused, uint64_t md,
34                              void **userdata)
35 {
36         /* Retrieve userdata  */
37         *userdata = (void *)md;
38
39         return 0;
40 }
41
42 static struct rte_security_ops otx2_crypto_sec_ops = {
43         .session_create         = NULL,
44         .session_destroy        = NULL,
45         .session_get_size       = otx2_crypto_sec_session_get_size,
46         .set_pkt_metadata       = otx2_crypto_sec_set_pkt_mdata,
47         .get_userdata           = otx2_crypto_sec_get_userdata,
48         .capabilities_get       = otx2_crypto_sec_capabilities_get
49 };
50
51 int
52 otx2_crypto_sec_ctx_create(struct rte_cryptodev *cdev)
53 {
54         struct rte_security_ctx *ctx;
55
56         ctx = rte_malloc("otx2_cpt_dev_sec_ctx",
57                          sizeof(struct rte_security_ctx), 0);
58
59         if (ctx == NULL)
60                 return -ENOMEM;
61
62         /* Populate ctx */
63         ctx->device = cdev;
64         ctx->ops = &otx2_crypto_sec_ops;
65         ctx->sess_cnt = 0;
66
67         cdev->security_ctx = ctx;
68
69         return 0;
70 }
71
72 void
73 otx2_crypto_sec_ctx_destroy(struct rte_cryptodev *cdev)
74 {
75         rte_free(cdev->security_ctx);
76 }