net/bnxt: support periodic FW health monitoring
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.c
index d13e6cc..3893179 100644 (file)
@@ -1,37 +1,10 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) Broadcom Limited.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Broadcom Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2014-2018 Broadcom
+ * All rights reserved.
  */
 
 #include <rte_malloc.h>
+#include <rte_alarm.h>
 
 #include "bnxt.h"
 #include "bnxt_cpr.h"
@@ -48,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. */
@@ -55,10 +30,79 @@ void bnxt_handle_async_event(struct bnxt *bp,
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
        case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE:
-               bnxt_link_update_op(bp->eth_dev, 0);
+               /* FALLTHROUGH */
+               bnxt_link_update_op(bp->eth_dev, 1);
+               break;
+       case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
+               PMD_DRV_LOG(INFO, "Async event: PF driver unloaded\n");
+               break;
+       case HWRM_ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
+               PMD_DRV_LOG(INFO, "Async event: VF config changed\n");
+               bnxt_hwrm_func_qcfg(bp, NULL);
+               break;
+       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:
-               RTE_LOG(ERR, PMD, "handle_async_event id = 0x%x\n", event_id);
+               PMD_DRV_LOG(INFO, "handle_async_event id = 0x%x\n", event_id);
                break;
        }
 }
@@ -74,7 +118,7 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
        int rc;
 
        if (bp->pf.active_vfs <= 0) {
-               RTE_LOG(ERR, PMD, "Forwarded VF with no active VFs\n");
+               PMD_DRV_LOG(ERR, "Forwarded VF with no active VFs\n");
                return;
        }
 
@@ -93,7 +137,7 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
 
        if (fw_vf_id < bp->pf.first_vf_id ||
            fw_vf_id >= (bp->pf.first_vf_id) + bp->pf.active_vfs) {
-               RTE_LOG(ERR, PMD,
+               PMD_DRV_LOG(ERR,
                "FWD req's source_id 0x%x out of range 0x%x - 0x%x (%d %d)\n",
                        fw_vf_id, bp->pf.first_vf_id,
                        (bp->pf.first_vf_id) + bp->pf.active_vfs - 1,
@@ -130,7 +174,7 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
                /* Forward */
                rc = bnxt_hwrm_exec_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
                if (rc) {
-                       RTE_LOG(ERR, PMD,
+                       PMD_DRV_LOG(ERR,
                                "Failed to send FWD req VF 0x%x, type 0x%x.\n",
                                fw_vf_id - bp->pf.first_vf_id,
                                rte_le_to_cpu_16(fwd_cmd->req_type));
@@ -141,7 +185,7 @@ void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmpl)
 reject:
        rc = bnxt_hwrm_reject_fwd_resp(bp, fw_vf_id, fwd_cmd, req_len);
        if (rc) {
-               RTE_LOG(ERR, PMD,
+               PMD_DRV_LOG(ERR,
                        "Failed to send REJECT req VF 0x%x, type 0x%x.\n",
                        fw_vf_id - bp->pf.first_vf_id,
                        rte_le_to_cpu_16(fwd_cmd->req_type));
@@ -150,67 +194,53 @@ reject:
        return;
 }
 
-/* For the default completion ring only */
-int bnxt_alloc_def_cp_ring(struct bnxt *bp)
+int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp)
 {
-       struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
-       struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
-       int rc;
+       bool evt = 0;
+
+       if (bp == NULL || cmp == NULL) {
+               PMD_DRV_LOG(ERR, "invalid NULL argument\n");
+               return evt;
+       }
 
-       rc = bnxt_hwrm_ring_alloc(bp, cp_ring,
-                                 HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL,
-                                 0, HWRM_NA_SIGNATURE);
-       if (rc)
-               goto err_out;
-       cpr->cp_doorbell = bp->pdev->mem_resource[2].addr;
-       B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
-       bp->grp_info[0].cp_fw_ring_id = cp_ring->fw_ring_id;
-       if (BNXT_PF(bp))
-               rc = bnxt_hwrm_func_cfg_def_cp(bp);
-       else
-               rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
-
-err_out:
-       return rc;
+       if (unlikely(is_bnxt_in_error(bp)))
+               return 0;
+
+       switch (CMP_TYPE(cmp)) {
+       case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
+               /* Handle any async event */
+               bnxt_handle_async_event(bp, cmp);
+               evt = 1;
+               break;
+       case CMPL_BASE_TYPE_HWRM_FWD_RESP:
+               /* Handle HWRM forwarded responses */
+               bnxt_handle_fwd_req(bp, cmp);
+               evt = 1;
+               break;
+       default:
+               /* Ignore any other events */
+               PMD_DRV_LOG(INFO, "Ignoring %02x completion\n", CMP_TYPE(cmp));
+               break;
+       }
+
+       return evt;
 }
 
-void bnxt_free_def_cp_ring(struct bnxt *bp)
+bool bnxt_is_master_func(struct bnxt *bp)
 {
-       struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
+       if (bp->recovery_info->flags & BNXT_FLAG_MASTER_FUNC)
+               return true;
 
-       if (cpr == NULL)
-               return;
-
-       bnxt_free_ring(cpr->cp_ring_struct);
-       rte_free(cpr->cp_ring_struct);
-       rte_free(cpr);
+       return false;
 }
 
-/* For the default completion ring only */
-int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id)
+bool bnxt_is_recovery_enabled(struct bnxt *bp)
 {
-       struct bnxt_cp_ring_info *cpr;
-       struct bnxt_ring *ring;
-
-       cpr = rte_zmalloc_socket("cpr",
-                                sizeof(struct bnxt_cp_ring_info),
-                                RTE_CACHE_LINE_SIZE, socket_id);
-       if (cpr == NULL)
-               return -ENOMEM;
-       bp->def_cp_ring = cpr;
-
-       ring = rte_zmalloc_socket("bnxt_cp_ring_struct",
-                                 sizeof(struct bnxt_ring),
-                                 RTE_CACHE_LINE_SIZE, socket_id);
-       if (ring == NULL)
-               return -ENOMEM;
-       cpr->cp_ring_struct = ring;
-       ring->bd = (void *)cpr->cp_desc_ring;
-       ring->bd_dma = cpr->cp_desc_mapping;
-       ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE);
-       ring->ring_mask = ring->ring_size - 1;
-       ring->vmem_size = 0;
-       ring->vmem = NULL;
-
-       return 0;
+       struct bnxt_error_recovery_info *info;
+
+       info = bp->recovery_info;
+       if (info && (info->flags & BNXT_FLAG_RECOVERY_ENABLED))
+               return true;
+
+       return false;
 }