From: Anoob Joseph <ano...@marvell.com>

If a CSR read is issued after a write, the read would block till the
write operation is complete. This would help in determining when the
FLUSH+INVALIDATE operation is complete.

Signed-off-by: Anoob Joseph <ano...@marvell.com>
---
 drivers/common/cnxk/hw/cpt.h             | 11 +++++++++++
 drivers/common/cnxk/roc_cpt.c            | 16 ++++++++++++++++
 drivers/crypto/cnxk/cnxk_cryptodev_ops.c |  4 ----
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/hw/cpt.h b/drivers/common/cnxk/hw/cpt.h
index d378a4eadd..44ff8b08b2 100644
--- a/drivers/common/cnxk/hw/cpt.h
+++ b/drivers/common/cnxk/hw/cpt.h
@@ -100,6 +100,17 @@ union cpt_lf_ctx_flush {
        } s;
 };
 
+union cpt_lf_ctx_err {
+       uint64_t u;
+       struct {
+               uint64_t flush_st_flt : 1;
+               uint64_t busy_flr : 1;
+               uint64_t busy_sw_flush : 1;
+               uint64_t reload_faulted : 1;
+               uint64_t reserved_4_63 : 1;
+       } s;
+};
+
 union cpt_lf_ctx_reload {
        uint64_t u;
        struct {
diff --git a/drivers/common/cnxk/roc_cpt.c b/drivers/common/cnxk/roc_cpt.c
index cf514be69f..dff2fbf2a4 100644
--- a/drivers/common/cnxk/roc_cpt.c
+++ b/drivers/common/cnxk/roc_cpt.c
@@ -783,6 +783,7 @@ int
 roc_cpt_lf_ctx_flush(struct roc_cpt_lf *lf, void *cptr, bool inval)
 {
        union cpt_lf_ctx_flush reg;
+       union cpt_lf_ctx_err err;
 
        if (lf == NULL) {
                plt_err("Could not trigger CTX flush");
@@ -795,6 +796,21 @@ roc_cpt_lf_ctx_flush(struct roc_cpt_lf *lf, void *cptr, 
bool inval)
 
        plt_write64(reg.u, lf->rbase + CPT_LF_CTX_FLUSH);
 
+       plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
+
+       /* Read a CSR to ensure that the FLUSH operation is complete */
+       err.u = plt_read64(lf->rbase + CPT_LF_CTX_ERR);
+
+       if (err.s.busy_sw_flush && inval) {
+               plt_err("CTX entry could not be invalidated due to active 
usage.");
+               return -EAGAIN;
+       }
+
+       if (err.s.flush_st_flt) {
+               plt_err("CTX flush could not complete due to store fault");
+               abort();
+       }
+
        return 0;
 }
 
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c 
b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index f03646fe1a..67bd7e3243 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -737,8 +737,6 @@ sym_session_clear(struct rte_cryptodev_sym_session *sess, 
bool is_session_less)
        /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
        roc_cpt_lf_ctx_flush(sess_priv->lf, &sess_priv->roc_se_ctx.se_ctx, 
true);
 
-       plt_delay_ms(1);
-
        if (sess_priv->roc_se_ctx.auth_key != NULL)
                plt_free(sess_priv->roc_se_ctx.auth_key);
 
@@ -767,8 +765,6 @@ cnxk_ae_session_clear(struct rte_cryptodev *dev, struct 
rte_cryptodev_asym_sessi
        /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
        roc_cpt_lf_ctx_flush(priv->lf, &priv->hw_ctx, true);
 
-       plt_delay_ms(1);
-
        /* Free resources allocated in session_cfg */
        cnxk_ae_free_session_parameters(priv);
 
-- 
2.25.1

Reply via email to