From: Vidya Sagar Velumuri <vvelum...@marvell.com> Add support for IPsec session update and IPsec stats get for cn20k
Signed-off-by: Vidya Sagar Velumuri <vvelum...@marvell.com> --- drivers/crypto/cnxk/cn20k_cryptodev_sec.c | 41 +++++++++++++++++++---- drivers/crypto/cnxk/cn20k_ipsec.c | 39 +++++++++++++++++---- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/cnxk/cn20k_cryptodev_sec.c b/drivers/crypto/cnxk/cn20k_cryptodev_sec.c index 1b18398250..ba7f1baf86 100644 --- a/drivers/crypto/cnxk/cn20k_cryptodev_sec.c +++ b/drivers/crypto/cnxk/cn20k_cryptodev_sec.c @@ -60,16 +60,28 @@ cn20k_sec_session_destroy(void *dev, struct rte_security_session *sec_sess) static unsigned int cn20k_sec_session_get_size(void *dev __rte_unused) { - return 0; + return sizeof(struct cn20k_sec_session) - sizeof(struct rte_security_session); } static int cn20k_sec_session_stats_get(void *dev, struct rte_security_session *sec_sess, struct rte_security_stats *stats) { - RTE_SET_USED(dev); - RTE_SET_USED(sec_sess); - RTE_SET_USED(stats); + 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_ipsec_stats_get(qp, cn20k_sec_sess, stats); return -ENOTSUP; } @@ -78,9 +90,24 @@ static int cn20k_sec_session_update(void *dev, struct rte_security_session *sec_sess, struct rte_security_session_conf *conf) { - RTE_SET_USED(dev); - RTE_SET_USED(sec_sess); - RTE_SET_USED(conf); + struct cn20k_sec_session *cn20k_sec_sess; + struct rte_cryptodev *crypto_dev = dev; + struct cnxk_cpt_qp *qp; + struct cnxk_cpt_vf *vf; + + if (sec_sess == NULL) + return -EINVAL; + + qp = crypto_dev->data->queue_pairs[0]; + if (qp == NULL) + return -EINVAL; + + vf = crypto_dev->data->dev_private; + + cn20k_sec_sess = (struct cn20k_sec_session *)sec_sess; + + if (cn20k_sec_sess->proto == RTE_SECURITY_PROTOCOL_IPSEC) + return cn20k_ipsec_session_update(vf, qp, cn20k_sec_sess, conf); return -ENOTSUP; } diff --git a/drivers/crypto/cnxk/cn20k_ipsec.c b/drivers/crypto/cnxk/cn20k_ipsec.c index edb3462630..1a65438646 100644 --- a/drivers/crypto/cnxk/cn20k_ipsec.c +++ b/drivers/crypto/cnxk/cn20k_ipsec.c @@ -333,9 +333,24 @@ int cn20k_ipsec_stats_get(struct cnxk_cpt_qp *qp, struct cn20k_sec_session *sess, struct rte_security_stats *stats) { - RTE_SET_USED(qp); - RTE_SET_USED(sess); - RTE_SET_USED(stats); + struct roc_ow_ipsec_outb_sa *out_sa; + struct roc_ow_ipsec_inb_sa *in_sa; + struct cn20k_ipsec_sa *sa; + + stats->protocol = RTE_SECURITY_PROTOCOL_IPSEC; + sa = &sess->sa; + + if (sess->ipsec.is_outbound) { + out_sa = &sa->out_sa; + roc_cpt_lf_ctx_flush(&qp->lf, out_sa, false); + stats->ipsec.opackets = out_sa->ctx.mib_pkts; + stats->ipsec.obytes = out_sa->ctx.mib_octs; + } else { + in_sa = &sa->in_sa; + roc_cpt_lf_ctx_flush(&qp->lf, in_sa, false); + stats->ipsec.ipackets = in_sa->ctx.mib_pkts; + stats->ipsec.ibytes = in_sa->ctx.mib_octs; + } return 0; } @@ -344,10 +359,20 @@ int cn20k_ipsec_session_update(struct cnxk_cpt_vf *vf, struct cnxk_cpt_qp *qp, struct cn20k_sec_session *sess, struct rte_security_session_conf *conf) { - RTE_SET_USED(vf); - RTE_SET_USED(qp); - RTE_SET_USED(sess); - RTE_SET_USED(conf); + struct roc_cpt *roc_cpt; + int ret; + + if (conf->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) + return -ENOTSUP; + + ret = cnxk_ipsec_xform_verify(&conf->ipsec, conf->crypto_xform); + if (ret) + return ret; + + roc_cpt = &vf->cpt; + + return cn20k_ipsec_outb_sa_create(roc_cpt, &qp->lf, &conf->ipsec, conf->crypto_xform, + (struct cn20k_sec_session *)sess); return 0; } -- 2.25.1