net/qede/base: add DMAE sanity check
authorRasesh Mody <rasesh.mody@cavium.com>
Mon, 9 Apr 2018 04:47:59 +0000 (21:47 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Apr 2018 22:41:44 +0000 (00:41 +0200)
Add DMA engine sanity check during the engine initialization and before
PF initialization

Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
drivers/net/qede/base/ecore_dev.c
drivers/net/qede/base/ecore_hw.c
drivers/net/qede/base/ecore_hw.h
drivers/net/qede/base/ecore_init_ops.c
drivers/net/qede/base/ecore_rt_defs.h

index b15af03..38492e6 100644 (file)
@@ -2161,6 +2161,11 @@ ecore_hw_init_pf(struct ecore_hwfn *p_hwfn,
        /* perform debug configuration when chip is out of reset */
        OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
 
+       /* Sanity check before the PF init sequence that uses DMAE */
+       rc = ecore_dmae_sanity(p_hwfn, p_ptt, "pf_phase");
+       if (rc)
+               return rc;
+
        /* PF Init sequence */
        rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
        if (rc)
index 1e76509..bc47af4 100644 (file)
@@ -953,3 +953,74 @@ void ecore_hw_err_notify(struct ecore_hwfn *p_hwfn,
 
        OSAL_HW_ERROR_OCCURRED(p_hwfn, err_type);
 }
+
+enum _ecore_status_t ecore_dmae_sanity(struct ecore_hwfn *p_hwfn,
+                                      struct ecore_ptt *p_ptt,
+                                      const char *phase)
+{
+       u32 size = OSAL_PAGE_SIZE / 2, val;
+       struct ecore_dmae_params params;
+       enum _ecore_status_t rc = ECORE_SUCCESS;
+       dma_addr_t p_phys;
+       void *p_virt;
+       u32 *p_tmp;
+
+       p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev, &p_phys, 2 * size);
+       if (!p_virt) {
+               DP_NOTICE(p_hwfn, false,
+                         "DMAE sanity [%s]: failed to allocate memory\n",
+                         phase);
+               return ECORE_NOMEM;
+       }
+
+       /* Fill the bottom half of the allocated memory with a known pattern */
+       for (p_tmp = (u32 *)p_virt;
+            p_tmp < (u32 *)((u8 *)p_virt + size);
+            p_tmp++) {
+               /* Save the address itself as the value */
+               val = (u32)(osal_uintptr_t)p_tmp;
+               *p_tmp = val;
+       }
+
+       /* Zero the top half of the allocated memory */
+       OSAL_MEM_ZERO((u8 *)p_virt + size, size);
+
+       DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
+                  "DMAE sanity [%s]: src_addr={phys 0x%lx, virt %p}, dst_addr={phys 0x%lx, virt %p}, size 0x%x\n",
+                  phase, (unsigned long)p_phys, p_virt,
+                  (unsigned long)(p_phys + size),
+                  (u8 *)p_virt + size, size);
+
+       OSAL_MEMSET(&params, 0, sizeof(params));
+       rc = ecore_dmae_host2host(p_hwfn, p_ptt, p_phys, p_phys + size,
+                                 size / 4 /* size_in_dwords */, &params);
+       if (rc != ECORE_SUCCESS) {
+               DP_NOTICE(p_hwfn, false,
+                         "DMAE sanity [%s]: ecore_dmae_host2host() failed. rc = %d.\n",
+                         phase, rc);
+               goto out;
+       }
+
+       /* Verify that the top half of the allocated memory has the pattern */
+       for (p_tmp = (u32 *)((u8 *)p_virt + size);
+            p_tmp < (u32 *)((u8 *)p_virt + (2 * size));
+            p_tmp++) {
+               /* The corresponding address in the bottom half */
+               val = (u32)(osal_uintptr_t)p_tmp - size;
+
+               if (*p_tmp != val) {
+                       DP_NOTICE(p_hwfn, false,
+                                 "DMAE sanity [%s]: addr={phys 0x%lx, virt %p}, read_val 0x%08x, expected_val 0x%08x\n",
+                                 phase,
+                                 (unsigned long)p_phys +
+                                  ((u8 *)p_tmp - (u8 *)p_virt),
+                                 p_tmp, *p_tmp, val);
+                       rc = ECORE_UNKNOWN_ERROR;
+                       goto out;
+               }
+       }
+
+out:
+       OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_virt, p_phys, 2 * size);
+       return rc;
+}
index 0b9814f..b59a26a 100644 (file)
@@ -255,4 +255,8 @@ enum _ecore_status_t ecore_init_fw_data(struct ecore_dev *p_dev,
 void ecore_hw_err_notify(struct ecore_hwfn *p_hwfn,
                         enum ecore_hw_err_type err_type);
 
+enum _ecore_status_t ecore_dmae_sanity(struct ecore_hwfn *p_hwfn,
+                                      struct ecore_ptt *p_ptt,
+                                      const char *phase);
+
 #endif /* __ECORE_HW_H__ */
index 91633c1..722aa56 100644 (file)
@@ -389,23 +389,29 @@ static void ecore_init_cmd_rd(struct ecore_hwfn *p_hwfn,
        }
 
        if (i == ECORE_INIT_MAX_POLL_COUNT)
-               DP_ERR(p_hwfn,
-                      "Timeout when polling reg: 0x%08x [ Waiting-for: %08x"
-                      " Got: %08x (comparsion %08x)]\n",
+               DP_ERR(p_hwfn, "Timeout when polling reg: 0x%08x [ Waiting-for: %08x Got: %08x (comparison %08x)]\n",
                       addr, OSAL_LE32_TO_CPU(cmd->expected_val), val,
                       OSAL_LE32_TO_CPU(cmd->op_data));
 }
 
-/* init_ops callbacks entry point.
- * OSAL_UNUSED is temporary used to avoid unused-parameter compilation warnings.
- * Should be removed when the function is actually used.
- */
-static void ecore_init_cmd_cb(struct ecore_hwfn *p_hwfn,
-                             struct ecore_ptt OSAL_UNUSED * p_ptt,
-                             struct init_callback_op OSAL_UNUSED * p_cmd)
+/* init_ops callbacks entry point */
+static enum _ecore_status_t ecore_init_cmd_cb(struct ecore_hwfn *p_hwfn,
+                                             struct ecore_ptt *p_ptt,
+                                             struct init_callback_op *p_cmd)
 {
-       DP_NOTICE(p_hwfn, true,
-                 "Currently init values have no need of callbacks\n");
+       enum _ecore_status_t rc;
+
+       switch (p_cmd->callback_id) {
+       case DMAE_READY_CB:
+               rc = ecore_dmae_sanity(p_hwfn, p_ptt, "engine_phase");
+               break;
+       default:
+               DP_NOTICE(p_hwfn, false, "Unexpected init op callback ID %d\n",
+                         p_cmd->callback_id);
+               return ECORE_INVAL;
+       }
+
+       return rc;
 }
 
 static u8 ecore_init_cmd_mode_match(struct ecore_hwfn *p_hwfn,
@@ -513,7 +519,7 @@ enum _ecore_status_t ecore_init_run(struct ecore_hwfn *p_hwfn,
                        break;
 
                case INIT_OP_CALLBACK:
-                       ecore_init_cmd_cb(p_hwfn, p_ptt, &cmd->callback);
+                       rc = ecore_init_cmd_cb(p_hwfn, p_ptt, &cmd->callback);
                        break;
                }
 
index 1d08581..401e4b6 100644 (file)
 
 #define RUNTIME_ARRAY_SIZE 41743
 
+/* Init Callbacks */
+#define DMAE_READY_CB                                               0
+
 #endif /* __RT_DEFS_H__ */