From: Vidya Sagar Velumuri <vvelum...@marvell.com> Add support for rte_security session destroy for cn20k
Signed-off-by: Vidya Sagar Velumuri <vvelum...@marvell.com> --- drivers/crypto/cnxk/cn20k_cryptodev_sec.c | 17 +++++++- drivers/crypto/cnxk/cn20k_ipsec.c | 51 ++++++++++++++++++++++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/cnxk/cn20k_cryptodev_sec.c b/drivers/crypto/cnxk/cn20k_cryptodev_sec.c index cf82c33e89..2a39338556 100644 --- a/drivers/crypto/cnxk/cn20k_cryptodev_sec.c +++ b/drivers/crypto/cnxk/cn20k_cryptodev_sec.c @@ -38,8 +38,21 @@ cn20k_sec_session_create(void *dev, struct rte_security_session_conf *conf, static int cn20k_sec_session_destroy(void *dev, struct rte_security_session *sec_sess) { - RTE_SET_USED(dev); - RTE_SET_USED(sec_sess); + struct cn20k_sec_session *cn20k_sec_sess; + struct rte_cryptodev *crypto_dev = dev; + struct cnxk_cpt_qp *qp; + + if (unlikely(sec_sess == NULL)) + return -EINVAL; + + qp = crypto_dev->data->queue_pairs[0]; + if (unlikely(qp == NULL)) + return -ENOTSUP; + + cn20k_sec_sess = (struct cn20k_sec_session *)sec_sess; + + if (cn20k_sec_sess->proto == RTE_SECURITY_PROTOCOL_IPSEC) + return cn20k_sec_ipsec_session_destroy(qp, cn20k_sec_sess); return -EINVAL; } diff --git a/drivers/crypto/cnxk/cn20k_ipsec.c b/drivers/crypto/cnxk/cn20k_ipsec.c index 4fa3872ef9..e19e080600 100644 --- a/drivers/crypto/cnxk/cn20k_ipsec.c +++ b/drivers/crypto/cnxk/cn20k_ipsec.c @@ -276,8 +276,55 @@ cn20k_ipsec_session_create(struct cnxk_cpt_vf *vf, struct cnxk_cpt_qp *qp, int cn20k_sec_ipsec_session_destroy(struct cnxk_cpt_qp *qp, struct cn20k_sec_session *sess) { - RTE_SET_USED(qp); - RTE_SET_USED(sess); + union roc_ow_ipsec_sa_word2 *w2; + struct cn20k_ipsec_sa *sa; + struct roc_cpt_lf *lf; + void *sa_dptr = NULL; + int ret; + + lf = &qp->lf; + + sa = &sess->sa; + + /* Trigger CTX flush to write dirty data back to DRAM */ + roc_cpt_lf_ctx_flush(lf, &sa->in_sa, false); + + ret = -1; + + if (sess->ipsec.is_outbound) { + sa_dptr = plt_zmalloc(sizeof(struct roc_ow_ipsec_outb_sa), 8); + if (sa_dptr != NULL) { + roc_ow_ipsec_outb_sa_init(sa_dptr); + + ret = roc_cpt_ctx_write(lf, sa_dptr, &sa->out_sa, + sizeof(struct roc_ow_ipsec_outb_sa)); + } + } else { + sa_dptr = plt_zmalloc(sizeof(struct roc_ow_ipsec_inb_sa), 8); + if (sa_dptr != NULL) { + roc_ow_ipsec_inb_sa_init(sa_dptr); + + ret = roc_cpt_ctx_write(lf, sa_dptr, &sa->in_sa, + sizeof(struct roc_ow_ipsec_inb_sa)); + } + } + + plt_free(sa_dptr); + + if (ret) { + /* MC write_ctx failed. Attempt reload of CTX */ + + /* Wait for 1 ms so that flush is complete */ + rte_delay_ms(1); + + w2 = (union roc_ow_ipsec_sa_word2 *)&sa->in_sa.w2; + w2->s.valid = 0; + + rte_atomic_thread_fence(rte_memory_order_seq_cst); + + /* Trigger CTX reload to fetch new data from DRAM */ + roc_cpt_lf_ctx_reload(lf, &sa->in_sa); + } return 0; } -- 2.25.1