d9a002625c94cb3732385ea50039454f7d603338
[dpdk.git] / drivers / event / octeontx2 / otx2_evdev_crypto_adptr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2020-2021 Marvell.
3  */
4
5 #include <rte_cryptodev.h>
6 #include <rte_eventdev.h>
7
8 #include "otx2_cryptodev.h"
9 #include "otx2_cryptodev_hw_access.h"
10 #include "otx2_cryptodev_qp.h"
11 #include "otx2_cryptodev_mbox.h"
12 #include "otx2_evdev.h"
13
14 int
15 otx2_ca_caps_get(const struct rte_eventdev *dev,
16                 const struct rte_cryptodev *cdev, uint32_t *caps)
17 {
18         RTE_SET_USED(dev);
19         RTE_SET_USED(cdev);
20
21         *caps = RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND |
22                 RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW |
23                 RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD;
24
25         return 0;
26 }
27
28 static int
29 otx2_ca_qp_sso_link(const struct rte_cryptodev *cdev, struct otx2_cpt_qp *qp,
30                     uint16_t sso_pf_func)
31 {
32         union otx2_cpt_af_lf_ctl2 af_lf_ctl2;
33         int ret;
34
35         ret = otx2_cpt_af_reg_read(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
36                                    qp->blkaddr, &af_lf_ctl2.u);
37         if (ret)
38                 return ret;
39
40         af_lf_ctl2.s.sso_pf_func = sso_pf_func;
41         ret = otx2_cpt_af_reg_write(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
42                                     qp->blkaddr, af_lf_ctl2.u);
43         return ret;
44 }
45
46 static void
47 otx2_ca_qp_init(struct otx2_cpt_qp *qp, const struct rte_event *event)
48 {
49         if (event) {
50                 qp->qp_ev_bind = 1;
51                 rte_memcpy(&qp->ev, event, sizeof(struct rte_event));
52         } else {
53                 qp->qp_ev_bind = 0;
54         }
55         qp->ca_enable = 1;
56 }
57
58 int
59 otx2_ca_qp_add(const struct rte_eventdev *dev, const struct rte_cryptodev *cdev,
60                 int32_t queue_pair_id, const struct rte_event *event)
61 {
62         struct otx2_sso_evdev *sso_evdev = sso_pmd_priv(dev);
63         struct otx2_cpt_vf *vf = cdev->data->dev_private;
64         uint16_t sso_pf_func = otx2_sso_pf_func_get();
65         struct otx2_cpt_qp *qp;
66         uint8_t qp_id;
67         int ret;
68
69         if (queue_pair_id == -1) {
70                 for (qp_id = 0; qp_id < vf->nb_queues; qp_id++) {
71                         qp = cdev->data->queue_pairs[qp_id];
72                         ret = otx2_ca_qp_sso_link(cdev, qp, sso_pf_func);
73                         if (ret) {
74                                 uint8_t qp_tmp;
75                                 for (qp_tmp = 0; qp_tmp < qp_id; qp_tmp++)
76                                         otx2_ca_qp_del(dev, cdev, qp_tmp);
77                                 return ret;
78                         }
79                         otx2_ca_qp_init(qp, event);
80                 }
81         } else {
82                 qp = cdev->data->queue_pairs[queue_pair_id];
83                 ret = otx2_ca_qp_sso_link(cdev, qp, sso_pf_func);
84                 if (ret)
85                         return ret;
86                 otx2_ca_qp_init(qp, event);
87         }
88
89         sso_evdev->rx_offloads |= NIX_RX_OFFLOAD_SECURITY_F;
90         sso_fastpath_fns_set((struct rte_eventdev *)(uintptr_t)dev);
91
92         /* Update crypto adapter xae count */
93         if (queue_pair_id == -1)
94                 sso_evdev->adptr_xae_cnt +=
95                         vf->nb_queues * OTX2_CPT_DEFAULT_CMD_QLEN;
96         else
97                 sso_evdev->adptr_xae_cnt += OTX2_CPT_DEFAULT_CMD_QLEN;
98         sso_xae_reconfigure((struct rte_eventdev *)(uintptr_t)dev);
99
100         return 0;
101 }
102
103 int
104 otx2_ca_qp_del(const struct rte_eventdev *dev, const struct rte_cryptodev *cdev,
105                 int32_t queue_pair_id)
106 {
107         struct otx2_cpt_vf *vf = cdev->data->dev_private;
108         struct otx2_cpt_qp *qp;
109         uint8_t qp_id;
110         int ret;
111
112         RTE_SET_USED(dev);
113
114         ret = 0;
115         if (queue_pair_id == -1) {
116                 for (qp_id = 0; qp_id < vf->nb_queues; qp_id++) {
117                         qp = cdev->data->queue_pairs[qp_id];
118                         ret = otx2_ca_qp_sso_link(cdev, qp, 0);
119                         if (ret)
120                                 return ret;
121                         qp->ca_enable = 0;
122                 }
123         } else {
124                 qp = cdev->data->queue_pairs[queue_pair_id];
125                 ret = otx2_ca_qp_sso_link(cdev, qp, 0);
126                 if (ret)
127                         return ret;
128                 qp->ca_enable = 0;
129         }
130
131         return 0;
132 }