event/octeontx2: support crypto adapter forward mode
[dpdk.git] / drivers / event / octeontx2 / otx2_evdev_crypto_adptr_tx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2021 Marvell International Ltd.
3  */
4
5 #ifndef _OTX2_EVDEV_CRYPTO_ADPTR_TX_H_
6 #define _OTX2_EVDEV_CRYPTO_ADPTR_TX_H_
7
8 #include <rte_cryptodev.h>
9 #include <rte_cryptodev_pmd.h>
10 #include <rte_event_crypto_adapter.h>
11 #include <rte_eventdev.h>
12
13 #include <otx2_cryptodev_qp.h>
14 #include <otx2_worker.h>
15
16 static inline uint16_t
17 otx2_ca_enq(uintptr_t tag_op, const struct rte_event *ev)
18 {
19         union rte_event_crypto_metadata *m_data;
20         struct rte_crypto_op *crypto_op;
21         struct rte_cryptodev *cdev;
22         struct otx2_cpt_qp *qp;
23         uint8_t cdev_id;
24         uint16_t qp_id;
25
26         crypto_op = ev->event_ptr;
27         if (crypto_op == NULL)
28                 return 0;
29
30         if (crypto_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
31                 m_data = rte_cryptodev_sym_session_get_user_data(
32                                                 crypto_op->sym->session);
33                 if (m_data == NULL)
34                         goto free_op;
35
36                 cdev_id = m_data->request_info.cdev_id;
37                 qp_id = m_data->request_info.queue_pair_id;
38         } else if (crypto_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS &&
39                    crypto_op->private_data_offset) {
40                 m_data = (union rte_event_crypto_metadata *)
41                          ((uint8_t *)crypto_op +
42                           crypto_op->private_data_offset);
43                 cdev_id = m_data->request_info.cdev_id;
44                 qp_id = m_data->request_info.queue_pair_id;
45         } else {
46                 goto free_op;
47         }
48
49         cdev = &rte_cryptodevs[cdev_id];
50         qp = cdev->data->queue_pairs[qp_id];
51
52         if (!ev->sched_type)
53                 otx2_ssogws_head_wait(tag_op);
54         if (qp->ca_enable)
55                 return cdev->enqueue_burst(qp, &crypto_op, 1);
56
57 free_op:
58         rte_pktmbuf_free(crypto_op->sym->m_src);
59         rte_crypto_op_free(crypto_op);
60         rte_errno = EINVAL;
61         return 0;
62 }
63
64 static uint16_t __rte_hot
65 otx2_ssogws_ca_enq(void *port, struct rte_event ev[], uint16_t nb_events)
66 {
67         struct otx2_ssogws *ws = port;
68
69         RTE_SET_USED(nb_events);
70
71         return otx2_ca_enq(ws->tag_op, ev);
72 }
73
74 static uint16_t __rte_hot
75 otx2_ssogws_dual_ca_enq(void *port, struct rte_event ev[], uint16_t nb_events)
76 {
77         struct otx2_ssogws_dual *ws = port;
78
79         RTE_SET_USED(nb_events);
80
81         return otx2_ca_enq(ws->ws_state[!ws->vws].tag_op, ev);
82 }
83 #endif /* _OTX2_EVDEV_CRYPTO_ADPTR_TX_H_ */