net/i40e/base: fix resource leakage
[dpdk.git] / drivers / net / i40e / base / i40e_adminq.c
index b2fc6f5..235667d 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2001-2018
+ * Copyright(c) 2001-2020 Intel Corporation
  */
 
 #include "i40e_status.h"
@@ -468,7 +468,7 @@ enum i40e_status_code i40e_init_arq(struct i40e_hw *hw)
        /* initialize base registers */
        ret_code = i40e_config_arq_regs(hw);
        if (ret_code != I40E_SUCCESS)
-               goto init_adminq_free_rings;
+               goto init_config_regs;
 
        /* success! */
        hw->aq.arq.count = hw->aq.num_arq_entries;
@@ -476,6 +476,10 @@ enum i40e_status_code i40e_init_arq(struct i40e_hw *hw)
 
 init_adminq_free_rings:
        i40e_free_adminq_arq(hw);
+       return ret_code;
+
+init_config_regs:
+       i40e_free_arq_bufs(hw);
 
 init_adminq_exit:
        return ret_code;
@@ -569,6 +573,70 @@ STATIC void i40e_resume_aq(struct i40e_hw *hw)
 }
 #endif /* PF_DRIVER */
 
+/**
+ *  i40e_set_hw_flags - set HW flags
+ *  @hw: pointer to the hardware structure
+ **/
+STATIC void i40e_set_hw_flags(struct i40e_hw *hw)
+{
+       struct i40e_adminq_info *aq = &hw->aq;
+
+       hw->flags = 0;
+
+       switch (hw->mac.type) {
+       case I40E_MAC_XL710:
+               if (aq->api_maj_ver > 1 ||
+                   (aq->api_maj_ver == 1 &&
+                    aq->api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710)) {
+                       hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE;
+                       hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
+                       /* The ability to RX (not drop) 802.1ad frames */
+                       hw->flags |= I40E_HW_FLAG_802_1AD_CAPABLE;
+               }
+               break;
+       case I40E_MAC_X722:
+               hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
+                            I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
+
+               if (aq->api_maj_ver > 1 ||
+                   (aq->api_maj_ver == 1 &&
+                    aq->api_min_ver >= I40E_MINOR_VER_FW_LLDP_STOPPABLE_X722))
+                       hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
+
+               if (aq->api_maj_ver > 1 ||
+                   (aq->api_maj_ver == 1 &&
+                    aq->api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_X722))
+                       hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE;
+
+               if (aq->api_maj_ver > 1 ||
+                   (aq->api_maj_ver == 1 &&
+                    aq->api_min_ver >= I40E_MINOR_VER_FW_REQUEST_FEC_X722))
+                       hw->flags |= I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE;
+
+               /* fall through */
+       default:
+               break;
+       }
+
+       /* Newer versions of firmware require lock when reading the NVM */
+       if (aq->api_maj_ver > 1 ||
+           (aq->api_maj_ver == 1 &&
+            aq->api_min_ver >= 5))
+               hw->flags |= I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
+
+       if (aq->api_maj_ver > 1 ||
+           (aq->api_maj_ver == 1 &&
+            aq->api_min_ver >= 8)) {
+               hw->flags |= I40E_HW_FLAG_FW_LLDP_PERSISTENT;
+               hw->flags |= I40E_HW_FLAG_DROP_MODE;
+       }
+
+       if (aq->api_maj_ver > 1 ||
+           (aq->api_maj_ver == 1 &&
+            aq->api_min_ver >= 9))
+               hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_EXTENDED;
+}
+
 /**
  *  i40e_init_adminq - main initialization routine for Admin Queue
  *  @hw: pointer to the hardware structure
@@ -582,25 +650,22 @@ STATIC void i40e_resume_aq(struct i40e_hw *hw)
  **/
 enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
 {
-#ifdef PF_DRIVER
+       struct i40e_adminq_info *aq = &hw->aq;
+       enum i40e_status_code ret_code;
        u16 cfg_ptr, oem_hi, oem_lo;
        u16 eetrack_lo, eetrack_hi;
-#endif
-       enum i40e_status_code ret_code;
-#ifdef PF_DRIVER
        int retry = 0;
-#endif
 
        /* verify input for valid configuration */
-       if ((hw->aq.num_arq_entries == 0) ||
-           (hw->aq.num_asq_entries == 0) ||
-           (hw->aq.arq_buf_size == 0) ||
-           (hw->aq.asq_buf_size == 0)) {
+       if (aq->num_arq_entries == 0 ||
+           aq->num_asq_entries == 0 ||
+           aq->arq_buf_size == 0 ||
+           aq->asq_buf_size == 0) {
                ret_code = I40E_ERR_CONFIG;
                goto init_adminq_exit;
        }
-       i40e_init_spinlock(&hw->aq.asq_spinlock);
-       i40e_init_spinlock(&hw->aq.arq_spinlock);
+       i40e_init_spinlock(&aq->asq_spinlock);
+       i40e_init_spinlock(&aq->arq_spinlock);
 
        /* Set up register offsets */
        i40e_adminq_init_regs(hw);
@@ -618,23 +683,21 @@ enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
        if (ret_code != I40E_SUCCESS)
                goto init_adminq_free_asq;
 
-#ifdef PF_DRIVER
-#ifdef INTEGRATED_VF
        /* VF has no need of firmware */
        if (i40e_is_vf(hw))
                goto init_adminq_exit;
-#endif
+
        /* There are some cases where the firmware may not be quite ready
         * for AdminQ operations, so we retry the AdminQ setup a few times
         * if we see timeouts in this first AQ call.
         */
        do {
                ret_code = i40e_aq_get_firmware_version(hw,
-                                                       &hw->aq.fw_maj_ver,
-                                                       &hw->aq.fw_min_ver,
-                                                       &hw->aq.fw_build,
-                                                       &hw->aq.api_maj_ver,
-                                                       &hw->aq.api_min_ver,
+                                                       &aq->fw_maj_ver,
+                                                       &aq->fw_min_ver,
+                                                       &aq->fw_build,
+                                                       &aq->api_maj_ver,
+                                                       &aq->api_min_ver,
                                                        NULL);
                if (ret_code != I40E_ERR_ADMIN_QUEUE_TIMEOUT)
                        break;
@@ -645,6 +708,12 @@ enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
        if (ret_code != I40E_SUCCESS)
                goto init_adminq_free_arq;
 
+       /*
+        * Some features were introduced in different FW API version
+        * for different MAC type.
+        */
+       i40e_set_hw_flags(hw);
+
        /* get the NVM version info */
        i40e_read_nvm_word(hw, I40E_SR_NVM_DEV_STARTER_VERSION,
                           &hw->nvm.version);
@@ -658,31 +727,7 @@ enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
                           &oem_lo);
        hw->nvm.oem_ver = ((u32)oem_hi << 16) | oem_lo;
 
-       /* The ability to RX (not drop) 802.1ad frames was added in API 1.7 */
-       if ((hw->aq.api_maj_ver > 1) ||
-           ((hw->aq.api_maj_ver == 1) &&
-            (hw->aq.api_min_ver >= 7)))
-               hw->flags |= I40E_HW_FLAG_802_1AD_CAPABLE;
-
-       if (hw->mac.type == I40E_MAC_XL710 &&
-           hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
-           hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
-               hw->flags |= I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE;
-               hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
-       }
-       if (hw->mac.type == I40E_MAC_X722 &&
-           hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
-           hw->aq.api_min_ver >= I40E_MINOR_VER_FW_LLDP_STOPPABLE_X722) {
-               hw->flags |= I40E_HW_FLAG_FW_LLDP_STOPPABLE;
-       }
-
-       /* Newer versions of firmware require lock when reading the NVM */
-       if ((hw->aq.api_maj_ver > 1) ||
-           ((hw->aq.api_maj_ver == 1) &&
-            (hw->aq.api_min_ver >= 5)))
-               hw->flags |= I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
-
-       if (hw->aq.api_maj_ver > I40E_FW_API_VERSION_MAJOR) {
+       if (aq->api_maj_ver > I40E_FW_API_VERSION_MAJOR) {
                ret_code = I40E_ERR_FIRMWARE_API_VERSION;
                goto init_adminq_free_arq;
        }
@@ -692,21 +737,18 @@ enum i40e_status_code i40e_init_adminq(struct i40e_hw *hw)
        hw->nvm_release_on_done = false;
        hw->nvmupd_state = I40E_NVMUPD_STATE_INIT;
 
-#endif /* PF_DRIVER */
        ret_code = I40E_SUCCESS;
 
        /* success! */
        goto init_adminq_exit;
 
-#ifdef PF_DRIVER
 init_adminq_free_arq:
        i40e_shutdown_arq(hw);
-#endif
 init_adminq_free_asq:
        i40e_shutdown_asq(hw);
 init_adminq_destroy_spinlocks:
-       i40e_destroy_spinlock(&hw->aq.asq_spinlock);
-       i40e_destroy_spinlock(&hw->aq.arq_spinlock);
+       i40e_destroy_spinlock(&aq->asq_spinlock);
+       i40e_destroy_spinlock(&aq->arq_spinlock);
 
 init_adminq_exit:
        return ret_code;
@@ -751,7 +793,7 @@ u16 i40e_clean_asq(struct i40e_hw *hw)
        desc = I40E_ADMINQ_DESC(*asq, ntc);
        details = I40E_ADMINQ_DETAILS(*asq, ntc);
        while (rd32(hw, hw->aq.asq.head) != ntc) {
-               i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
+               i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
                           "ntc %d head %d.\n", ntc, rd32(hw, hw->aq.asq.head));
 
                if (details->callback) {
@@ -923,7 +965,7 @@ enum i40e_status_code i40e_asq_send_command(struct i40e_hw *hw,
        }
 
        /* bump the tail */
-       i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: desc and buffer:\n");
+       i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQTX: desc and buffer:\n");
        i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring,
                      buff, buff_size);
        (hw->aq.asq.next_to_use)++;
@@ -976,7 +1018,7 @@ enum i40e_status_code i40e_asq_send_command(struct i40e_hw *hw,
                hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval;
        }
 
-       i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
+       i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
                   "AQTX: desc and buffer writeback:\n");
        i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, buff, buff_size);
 
@@ -1105,7 +1147,7 @@ enum i40e_status_code i40e_clean_arq_element(struct i40e_hw *hw,
                            hw->aq.arq.r.arq_bi[desc_idx].va,
                            e->msg_len, I40E_DMA_TO_NONDMA);
 
-       i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: desc and buffer:\n");
+       i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQRX: desc and buffer:\n");
        i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
                      hw->aq.arq_buf_size);