net/octeontx2: support CN98xx
[dpdk.git] / drivers / net / ice / base / ice_controlq.c
index e7752fc..f278ef6 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2001-2019
+ * Copyright(c) 2001-2020 Intel Corporation
  */
 
 #include "ice_common.h"
@@ -13,6 +13,7 @@ do {                                                          \
        (qinfo)->sq.bal = prefix##_ATQBAL;                      \
        (qinfo)->sq.len_mask = prefix##_ATQLEN_ATQLEN_M;        \
        (qinfo)->sq.len_ena_mask = prefix##_ATQLEN_ATQENABLE_M; \
+       (qinfo)->sq.len_crit_mask = prefix##_ATQLEN_ATQCRIT_M;  \
        (qinfo)->sq.head_mask = prefix##_ATQH_ATQH_M;           \
        (qinfo)->rq.head = prefix##_ARQH;                       \
        (qinfo)->rq.tail = prefix##_ARQT;                       \
@@ -21,6 +22,7 @@ do {                                                          \
        (qinfo)->rq.bal = prefix##_ARQBAL;                      \
        (qinfo)->rq.len_mask = prefix##_ARQLEN_ARQLEN_M;        \
        (qinfo)->rq.len_ena_mask = prefix##_ARQLEN_ARQENABLE_M; \
+       (qinfo)->rq.len_crit_mask = prefix##_ARQLEN_ARQCRIT_M;  \
        (qinfo)->rq.head_mask = prefix##_ARQH_ARQH_M;           \
 } while (0)
 
@@ -180,7 +182,9 @@ unwind_alloc_rq_bufs:
        i--;
        for (; i >= 0; i--)
                ice_free_dma_mem(hw, &cq->rq.r.rq_bi[i]);
+       cq->rq.r.rq_bi = NULL;
        ice_free(hw, cq->rq.dma_head);
+       cq->rq.dma_head = NULL;
 
        return ICE_ERR_NO_MEMORY;
 }
@@ -218,7 +222,9 @@ unwind_alloc_sq_bufs:
        i--;
        for (; i >= 0; i--)
                ice_free_dma_mem(hw, &cq->sq.r.sq_bi[i]);
+       cq->sq.r.sq_bi = NULL;
        ice_free(hw, cq->sq.dma_head);
+       cq->sq.dma_head = NULL;
 
        return ICE_ERR_NO_MEMORY;
 }
@@ -277,6 +283,24 @@ ice_cfg_rq_regs(struct ice_hw *hw, struct ice_ctl_q_info *cq)
        return ICE_SUCCESS;
 }
 
+#define ICE_FREE_CQ_BUFS(hw, qi, ring)                                 \
+do {                                                                   \
+       /* free descriptors */                                          \
+       if ((qi)->ring.r.ring##_bi) {                                   \
+               int i;                                                  \
+                                                                       \
+               for (i = 0; i < (qi)->num_##ring##_entries; i++)        \
+                       if ((qi)->ring.r.ring##_bi[i].pa)               \
+                               ice_free_dma_mem((hw),                  \
+                                       &(qi)->ring.r.ring##_bi[i]);    \
+       }                                                               \
+       /* free the buffer info list */                                 \
+       if ((qi)->ring.cmd_buf)                                         \
+               ice_free(hw, (qi)->ring.cmd_buf);                       \
+       /* free DMA head */                                             \
+       ice_free(hw, (qi)->ring.dma_head);                              \
+} while (0)
+
 /**
  * ice_init_sq - main initialization routine for Control ATQ
  * @hw: pointer to the hardware structure
@@ -332,6 +356,7 @@ static enum ice_status ice_init_sq(struct ice_hw *hw, struct ice_ctl_q_info *cq)
        goto init_ctrlq_exit;
 
 init_ctrlq_free_rings:
+       ICE_FREE_CQ_BUFS(hw, cq, sq);
        ice_free_cq_ring(hw, &cq->sq);
 
 init_ctrlq_exit:
@@ -393,27 +418,13 @@ static enum ice_status ice_init_rq(struct ice_hw *hw, struct ice_ctl_q_info *cq)
        goto init_ctrlq_exit;
 
 init_ctrlq_free_rings:
+       ICE_FREE_CQ_BUFS(hw, cq, rq);
        ice_free_cq_ring(hw, &cq->rq);
 
 init_ctrlq_exit:
        return ret_code;
 }
 
-#define ICE_FREE_CQ_BUFS(hw, qi, ring)                                 \
-do {                                                                   \
-       int i;                                                          \
-       /* free descriptors */                                          \
-       for (i = 0; i < (qi)->num_##ring##_entries; i++)                \
-               if ((qi)->ring.r.ring##_bi[i].pa)                       \
-                       ice_free_dma_mem((hw),                          \
-                                        &(qi)->ring.r.ring##_bi[i]);   \
-       /* free the buffer info list */                                 \
-       if ((qi)->ring.cmd_buf)                                         \
-               ice_free(hw, (qi)->ring.cmd_buf);                       \
-       /* free DMA head */                                             \
-       ice_free(hw, (qi)->ring.dma_head);                              \
-} while (0)
-
 /**
  * ice_shutdown_sq - shutdown the Control ATQ
  * @hw: pointer to the hardware structure
@@ -609,6 +620,53 @@ init_ctrlq_free_sq:
        return ret_code;
 }
 
+/**
+ * ice_shutdown_ctrlq - shutdown routine for any control queue
+ * @hw: pointer to the hardware structure
+ * @q_type: specific Control queue type
+ *
+ * NOTE: this function does not destroy the control queue locks.
+ */
+static void ice_shutdown_ctrlq(struct ice_hw *hw, enum ice_ctl_q q_type)
+{
+       struct ice_ctl_q_info *cq;
+
+       ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
+
+       switch (q_type) {
+       case ICE_CTL_Q_ADMIN:
+               cq = &hw->adminq;
+               if (ice_check_sq_alive(hw, cq))
+                       ice_aq_q_shutdown(hw, true);
+               break;
+       case ICE_CTL_Q_MAILBOX:
+               cq = &hw->mailboxq;
+               break;
+       default:
+               return;
+       }
+
+       ice_shutdown_sq(hw, cq);
+       ice_shutdown_rq(hw, cq);
+}
+
+/**
+ * ice_shutdown_all_ctrlq - shutdown routine for all control queues
+ * @hw: pointer to the hardware structure
+ *
+ * NOTE: this function does not destroy the control queue locks. The driver
+ * may call this at runtime to shutdown and later restart control queues, such
+ * as in response to a reset event.
+ */
+void ice_shutdown_all_ctrlq(struct ice_hw *hw)
+{
+       ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
+       /* Shutdown FW admin queue */
+       ice_shutdown_ctrlq(hw, ICE_CTL_Q_ADMIN);
+       /* Shutdown PF-VF Mailbox */
+       ice_shutdown_ctrlq(hw, ICE_CTL_Q_MAILBOX);
+}
+
 /**
  * ice_init_all_ctrlq - main initialization routine for all control queues
  * @hw: pointer to the hardware structure
@@ -625,15 +683,26 @@ init_ctrlq_free_sq:
 enum ice_status ice_init_all_ctrlq(struct ice_hw *hw)
 {
        enum ice_status status;
+       u32 retry = 0;
 
        ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
 
        /* Init FW admin queue */
-       status = ice_init_ctrlq(hw, ICE_CTL_Q_ADMIN);
-       if (status)
-               return status;
+       do {
+               status = ice_init_ctrlq(hw, ICE_CTL_Q_ADMIN);
+               if (status)
+                       return status;
+
+               status = ice_init_check_adminq(hw);
+               if (status != ICE_ERR_AQ_FW_CRITICAL)
+                       break;
+
+               ice_debug(hw, ICE_DBG_AQ_MSG,
+                         "Retry Admin Queue init due to FW critical error\n");
+               ice_shutdown_ctrlq(hw, ICE_CTL_Q_ADMIN);
+               ice_msec_delay(ICE_CTL_Q_ADMIN_INIT_MSEC, true);
+       } while (retry++ < ICE_CTL_Q_ADMIN_INIT_TIMEOUT);
 
-       status = ice_init_check_adminq(hw);
        if (status)
                return status;
        /* Init Mailbox queue */
@@ -676,61 +745,13 @@ enum ice_status ice_create_all_ctrlq(struct ice_hw *hw)
        return ice_init_all_ctrlq(hw);
 }
 
-/**
- * ice_shutdown_ctrlq - shutdown routine for any control queue
- * @hw: pointer to the hardware structure
- * @q_type: specific Control queue type
- *
- * NOTE: this function does not destroy the control queue locks.
- */
-static void ice_shutdown_ctrlq(struct ice_hw *hw, enum ice_ctl_q q_type)
-{
-       struct ice_ctl_q_info *cq;
-
-       ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
-
-       switch (q_type) {
-       case ICE_CTL_Q_ADMIN:
-               cq = &hw->adminq;
-               if (ice_check_sq_alive(hw, cq))
-                       ice_aq_q_shutdown(hw, true);
-               break;
-       case ICE_CTL_Q_MAILBOX:
-               cq = &hw->mailboxq;
-               break;
-       default:
-               return;
-       }
-
-       ice_shutdown_sq(hw, cq);
-       ice_shutdown_rq(hw, cq);
-}
-
-/**
- * ice_shutdown_all_ctrlq - shutdown routine for all control queues
- * @hw: pointer to the hardware structure
- *
- * NOTE: this function does not destroy the control queue locks. The driver
- * may call this at runtime to shutdown and later restart control queues, such
- * as in response to a reset event.
- */
-void ice_shutdown_all_ctrlq(struct ice_hw *hw)
-{
-       ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
-       /* Shutdown FW admin queue */
-       ice_shutdown_ctrlq(hw, ICE_CTL_Q_ADMIN);
-       /* Shutdown PF-VF Mailbox */
-       ice_shutdown_ctrlq(hw, ICE_CTL_Q_MAILBOX);
-}
-
 /**
  * ice_destroy_ctrlq_locks - Destroy locks for a control queue
  * @cq: pointer to the control queue
  *
  * Destroys the send and receive queue locks for a given control queue.
  */
-static void
-ice_destroy_ctrlq_locks(struct ice_ctl_q_info *cq)
+static void ice_destroy_ctrlq_locks(struct ice_ctl_q_info *cq)
 {
        ice_destroy_lock(&cq->sq_lock);
        ice_destroy_lock(&cq->rq_lock);
@@ -1025,9 +1046,15 @@ ice_sq_send_cmd_nolock(struct ice_hw *hw, struct ice_ctl_q_info *cq,
 
        /* update the error if time out occurred */
        if (!cmd_completed) {
-               ice_debug(hw, ICE_DBG_AQ_MSG,
-                         "Control Send Queue Writeback timeout.\n");
-               status = ICE_ERR_AQ_TIMEOUT;
+               if (rd32(hw, cq->rq.len) & cq->rq.len_crit_mask ||
+                   rd32(hw, cq->sq.len) & cq->sq.len_crit_mask) {
+                       ice_debug(hw, ICE_DBG_AQ_MSG, "Critical FW error.\n");
+                       status = ICE_ERR_AQ_FW_CRITICAL;
+               } else {
+                       ice_debug(hw, ICE_DBG_AQ_MSG,
+                                 "Control Send Queue Writeback timeout.\n");
+                       status = ICE_ERR_AQ_TIMEOUT;
+               }
        }
 
 sq_send_command_error:
@@ -1147,8 +1174,7 @@ ice_clean_rq_elem(struct ice_hw *hw, struct ice_ctl_q_info *cq,
 
        ice_debug(hw, ICE_DBG_AQ_DESC, "ARQ: desc and buffer:\n");
 
-       ice_debug_cq(hw, (void *)desc, e->msg_buf,
-                    cq->rq_buf_size);
+       ice_debug_cq(hw, (void *)desc, e->msg_buf, cq->rq_buf_size);
 
        /* Restore the original datalen and buffer address in the desc,
         * FW updates datalen to indicate the event message size