net/bnxt: support periodic FW health monitoring
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.c
index 655bcf1..3893179 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <rte_malloc.h>
+#include <rte_alarm.h>
 
 #include "bnxt.h"
 #include "bnxt_cpr.h"
@@ -20,6 +21,8 @@ void bnxt_handle_async_event(struct bnxt *bp,
        struct hwrm_async_event_cmpl *async_cmp =
                                (struct hwrm_async_event_cmpl *)cmp;
        uint16_t event_id = rte_le_to_cpu_16(async_cmp->event_id);
+       struct bnxt_error_recovery_info *info;
+       uint32_t event_data;
 
        /* TODO: HWRM async events are not defined yet */
        /* Needs to handle: link events, error events, etc. */
@@ -40,6 +43,64 @@ void bnxt_handle_async_event(struct bnxt *bp,
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED:
                PMD_DRV_LOG(INFO, "Port conn async event\n");
                break;
+       case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY:
+               event_data = rte_le_to_cpu_32(async_cmp->event_data1);
+               /* timestamp_lo/hi values are in units of 100ms */
+               bp->fw_reset_max_msecs = async_cmp->timestamp_hi ?
+                       rte_le_to_cpu_16(async_cmp->timestamp_hi) * 100 :
+                       BNXT_MAX_FW_RESET_TIMEOUT;
+               bp->fw_reset_min_msecs = async_cmp->timestamp_lo ?
+                       async_cmp->timestamp_lo * 100 :
+                       BNXT_MIN_FW_READY_TIMEOUT;
+               if ((event_data & EVENT_DATA1_REASON_CODE_MASK) ==
+                   EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL) {
+                       PMD_DRV_LOG(INFO,
+                                   "Firmware fatal reset event received\n");
+                       bp->flags |= BNXT_FLAG_FATAL_ERROR;
+               } else {
+                       PMD_DRV_LOG(INFO,
+                                   "Firmware non-fatal reset event received\n");
+               }
+
+               bp->flags |= BNXT_FLAG_FW_RESET;
+               rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
+                                 (void *)bp);
+               break;
+       case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY:
+               info = bp->recovery_info;
+
+               if (!info)
+                       return;
+
+               PMD_DRV_LOG(INFO, "Error recovery async event received\n");
+
+               event_data = rte_le_to_cpu_32(async_cmp->event_data1) &
+                               EVENT_DATA1_FLAGS_MASK;
+
+               if (event_data & EVENT_DATA1_FLAGS_MASTER_FUNC)
+                       info->flags |= BNXT_FLAG_MASTER_FUNC;
+               else
+                       info->flags &= ~BNXT_FLAG_MASTER_FUNC;
+
+               if (event_data & EVENT_DATA1_FLAGS_RECOVERY_ENABLED)
+                       info->flags |= BNXT_FLAG_RECOVERY_ENABLED;
+               else
+                       info->flags &= ~BNXT_FLAG_RECOVERY_ENABLED;
+
+               PMD_DRV_LOG(INFO, "recovery enabled(%d), master function(%d)\n",
+                           bnxt_is_recovery_enabled(bp),
+                           bnxt_is_master_func(bp));
+
+               if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
+                       return;
+
+               info->last_heart_beat =
+                       bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
+               info->last_reset_counter =
+                       bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
+
+               bnxt_schedule_fw_health_check(bp);
+               break;
        default:
                PMD_DRV_LOG(INFO, "handle_async_event id = 0x%x\n", event_id);
                break;
@@ -142,6 +203,9 @@ int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
                return evt;
        }
 
+       if (unlikely(is_bnxt_in_error(bp)))
+               return 0;
+
        switch (CMP_TYPE(cmp)) {
        case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
                /* Handle any async event */
@@ -161,3 +225,22 @@ int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
 
        return evt;
 }
+
+bool bnxt_is_master_func(struct bnxt *bp)
+{
+       if (bp->recovery_info->flags & BNXT_FLAG_MASTER_FUNC)
+               return true;
+
+       return false;
+}
+
+bool bnxt_is_recovery_enabled(struct bnxt *bp)
+{
+       struct bnxt_error_recovery_info *info;
+
+       info = bp->recovery_info;
+       if (info && (info->flags & BNXT_FLAG_RECOVERY_ENABLED))
+               return true;
+
+       return false;
+}