From: Anoob Joseph <anoob.jos...@caviumnetworks.com>

Adding hardware register accesses required for misc poll

Signed-off-by: Ankur Dwivedi <ankur.dwiv...@caviumnetworks.com>
Signed-off-by: Anoob Joseph <anoob.jos...@caviumnetworks.com>
Signed-off-by: Murthy NSSR <nidadavolu.mur...@caviumnetworks.com>
Signed-off-by: Nithin Dabilpuram <nithin.dabilpu...@caviumnetworks.com>
Signed-off-by: Ragothaman Jayaraman <rjayara...@caviumnetworks.com>
Signed-off-by: Srisivasubramanian S <ssriniva...@caviumnetworks.com>
Signed-off-by: Tejasree Kondoj <kondoj.tejas...@caviumnetworks.com>
---
 drivers/crypto/octeontx/otx_cryptodev_hw_access.c | 192 +++++++++++++++++++++-
 drivers/crypto/octeontx/otx_cryptodev_hw_access.h |  11 ++
 2 files changed, 202 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c 
b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
index 211b6ee..02ec3ce 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
@@ -3,11 +3,19 @@
  */
 #include <string.h>
 
+#include <rte_branch_prediction.h>
 #include <rte_common.h>
 
 #include "otx_cryptodev_hw_access.h"
 
 #include "cpt_pmd_logs.h"
+#include "cpt_hw_types.h"
+
+/*
+ * VF HAL functions
+ * Access its own BAR0/4 registers by passing VF number as 0.
+ * OS/PCI maps them accordingly.
+ */
 
 static int
 otx_cpt_vf_init(struct cpt_vf *cptvf)
@@ -22,10 +30,192 @@ otx_cpt_vf_init(struct cpt_vf *cptvf)
        return ret;
 }
 
+/*
+ * Read Interrupt status of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static uint64_t
+otx_cpt_read_vf_misc_intr_status(struct cpt_vf *cptvf)
+{
+       return CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf), CPTX_VQX_MISC_INT(0, 0));
+}
+
+/*
+ * Clear mailbox interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_mbox_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.mbox = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear instruction NCB read error interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_irde_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.irde = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear NCB result write response error interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_nwrp_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.nwrp = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear swerr interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_swerr_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.swerr = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear hwerr interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_hwerr_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.hwerr = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear translation fault interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_fault_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                               CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.fault = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+               CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
+/*
+ * Clear doorbell overflow interrupt of the VF
+ *
+ * @param   cptvf      cptvf structure
+ */
+static void
+otx_cpt_clear_dovf_intr(struct cpt_vf *cptvf)
+{
+       cptx_vqx_misc_int_t vqx_misc_int;
+
+       vqx_misc_int.u = CPT_READ_CSR(CPT_CSR_REG_BASE(cptvf),
+                                     CPTX_VQX_MISC_INT(0, 0));
+       /* W1C for the VF */
+       vqx_misc_int.s.dovf = 1;
+       CPT_WRITE_CSR(CPT_CSR_REG_BASE(cptvf),
+                     CPTX_VQX_MISC_INT(0, 0), vqx_misc_int.u);
+}
+
 void
 otx_cpt_poll_misc(struct cpt_vf *cptvf)
 {
-       RTE_SET_USED(cptvf);
+       uint64_t intr;
+
+       intr = otx_cpt_read_vf_misc_intr_status(cptvf);
+
+       if (!intr)
+               return;
+
+       /* Check for MISC interrupt types */
+       if (likely(intr & CPT_VF_INTR_MBOX_MASK)) {
+               CPT_LOG_DP_DEBUG("%s: Mailbox interrupt 0x%lx on CPT VF %d",
+                       cptvf->dev_name, (unsigned int long)intr, cptvf->vfid);
+               otx_cpt_clear_mbox_intr(cptvf);
+       } else if (unlikely(intr & CPT_VF_INTR_IRDE_MASK)) {
+               otx_cpt_clear_irde_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: Instruction NCB read error interrupt "
+                               "0x%lx on CPT VF %d", cptvf->dev_name,
+                               (unsigned int long)intr, cptvf->vfid);
+       } else if (unlikely(intr & CPT_VF_INTR_NWRP_MASK)) {
+               otx_cpt_clear_nwrp_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: NCB response write error interrupt 0x%lx"
+                               " on CPT VF %d", cptvf->dev_name,
+                               (unsigned int long)intr, cptvf->vfid);
+       } else if (unlikely(intr & CPT_VF_INTR_SWERR_MASK)) {
+               otx_cpt_clear_swerr_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: Software error interrupt 0x%lx on CPT VF "
+                               "%d", cptvf->dev_name, (unsigned int long)intr,
+                               cptvf->vfid);
+       } else if (unlikely(intr & CPT_VF_INTR_HWERR_MASK)) {
+               otx_cpt_clear_hwerr_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: Hardware error interrupt 0x%lx on CPT VF "
+                               "%d", cptvf->dev_name, (unsigned int long)intr,
+                               cptvf->vfid);
+       } else if (unlikely(intr & CPT_VF_INTR_FAULT_MASK)) {
+               otx_cpt_clear_fault_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: Translation fault interrupt 0x%lx on CPT 
VF "
+                               "%d", cptvf->dev_name, (unsigned int long)intr,
+                               cptvf->vfid);
+       } else if (unlikely(intr & CPT_VF_INTR_DOVF_MASK)) {
+               otx_cpt_clear_dovf_intr(cptvf);
+               CPT_LOG_DP_DEBUG("%s: Doorbell overflow interrupt 0x%lx on CPT 
VF "
+                               "%d", cptvf->dev_name, (unsigned int long)intr,
+                               cptvf->vfid);
+       } else
+               CPT_LOG_DP_ERR("%s: Unhandled interrupt 0x%lx in CPT VF %d",
+                               cptvf->dev_name, (unsigned int long)intr,
+                               cptvf->vfid);
 }
 
 int
diff --git a/drivers/crypto/octeontx/otx_cryptodev_hw_access.h 
b/drivers/crypto/octeontx/otx_cryptodev_hw_access.h
index 40db69c..f3c7a45 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_hw_access.h
+++ b/drivers/crypto/octeontx/otx_cryptodev_hw_access.h
@@ -7,6 +7,7 @@
 
 #include <stdbool.h>
 
+#include <rte_io.h>
 #include <rte_memory.h>
 
 #include "cpt_common.h"
@@ -19,6 +20,16 @@
 /* Default command queue length */
 #define DEFAULT_CMD_QCHUNKS    2
 
+#define CPT_CSR_REG_BASE(cpt)          ((cpt)->reg_base)
+
+/* Read hw register */
+#define CPT_READ_CSR(__hw_addr, __offset) \
+       rte_read64_relaxed((uint8_t *)__hw_addr + __offset)
+
+/* Write hw register */
+#define CPT_WRITE_CSR(__hw_addr, __offset, __val) \
+       rte_write64_relaxed((__val), ((uint8_t *)__hw_addr + __offset))
+
 struct command_chunk {
        uint8_t *head;
                /**< 128-byte aligned real_vaddr */
-- 
2.7.4

Reply via email to