event/octeontx2: support crypto adapter forward mode
[dpdk.git] / drivers / event / octeontx2 / otx2_evdev_crypto_adptr.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_eventdev.h>
7
8 #include "otx2_cryptodev_hw_access.h"
9 #include "otx2_cryptodev_qp.h"
10 #include "otx2_cryptodev_mbox.h"
11 #include "otx2_evdev.h"
12
13 int
14 otx2_ca_caps_get(const struct rte_eventdev *dev,
15                 const struct rte_cryptodev *cdev, uint32_t *caps)
16 {
17         RTE_SET_USED(dev);
18         RTE_SET_USED(cdev);
19
20         *caps = RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_QP_EV_BIND |
21                 RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_NEW |
22                 RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD;
23
24         return 0;
25 }
26
27 int
28 otx2_ca_qp_add(const struct rte_eventdev *dev, const struct rte_cryptodev *cdev,
29                 int32_t queue_pair_id, const struct rte_event *event)
30 {
31         struct otx2_sso_evdev *sso_evdev = sso_pmd_priv(dev);
32         union otx2_cpt_af_lf_ctl2 af_lf_ctl2;
33         struct otx2_cpt_qp *qp;
34         int ret;
35
36         qp = cdev->data->queue_pairs[queue_pair_id];
37
38         qp->ca_enable = 1;
39         rte_memcpy(&qp->ev, event, sizeof(struct rte_event));
40
41         ret = otx2_cpt_af_reg_read(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
42                         qp->blkaddr, &af_lf_ctl2.u);
43         if (ret)
44                 return ret;
45
46         af_lf_ctl2.s.sso_pf_func = otx2_sso_pf_func_get();
47         ret = otx2_cpt_af_reg_write(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
48                         qp->blkaddr, af_lf_ctl2.u);
49         if (ret)
50                 return ret;
51
52         sso_evdev->rx_offloads |= NIX_RX_OFFLOAD_SECURITY_F;
53         sso_fastpath_fns_set((struct rte_eventdev *)(uintptr_t)dev);
54
55         return 0;
56 }
57
58 int
59 otx2_ca_qp_del(const struct rte_eventdev *dev, const struct rte_cryptodev *cdev,
60                 int32_t queue_pair_id)
61 {
62         union otx2_cpt_af_lf_ctl2 af_lf_ctl2;
63         struct otx2_cpt_qp *qp;
64         int ret;
65
66         RTE_SET_USED(dev);
67
68         qp = cdev->data->queue_pairs[queue_pair_id];
69         qp->ca_enable = 0;
70         memset(&qp->ev, 0, sizeof(struct rte_event));
71
72         ret = otx2_cpt_af_reg_read(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
73                         qp->blkaddr, &af_lf_ctl2.u);
74         if (ret)
75                 return ret;
76
77         af_lf_ctl2.s.sso_pf_func = 0;
78         ret = otx2_cpt_af_reg_write(cdev, OTX2_CPT_AF_LF_CTL2(qp->id),
79                         qp->blkaddr, af_lf_ctl2.u);
80
81         return ret;
82 }