net/ice/base: fix inner L4 offset for GTPU dummy packet
[dpdk.git] / drivers / net / ice / base / ice_common.c
index 16dc474..2424f3b 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2001-2020 Intel Corporation
+ * Copyright(c) 2001-2021 Intel Corporation
  */
 
 #include "ice_common.h"
@@ -48,6 +48,11 @@ static enum ice_status ice_set_mac_type(struct ice_hw *hw)
        case ICE_DEV_ID_E823L_BACKPLANE:
        case ICE_DEV_ID_E823L_QSFP:
        case ICE_DEV_ID_E823L_SFP:
+       case ICE_DEV_ID_E823C_10G_BASE_T:
+       case ICE_DEV_ID_E823C_BACKPLANE:
+       case ICE_DEV_ID_E823C_QSFP:
+       case ICE_DEV_ID_E823C_SFP:
+       case ICE_DEV_ID_E823C_SGMII:
                hw->mac_type = ICE_MAC_GENERIC;
                break;
        default:
@@ -161,6 +166,10 @@ ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
                return ICE_ERR_PARAM;
        hw = pi->hw;
 
+       if (report_mode == ICE_AQC_REPORT_DFLT_CFG &&
+           !ice_fw_supports_report_dflt_cfg(hw))
+               return ICE_ERR_PARAM;
+
        ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
 
        if (qual_mods)
@@ -194,7 +203,7 @@ ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
        ice_debug(hw, ICE_DBG_LINK, "   module_type[2] = 0x%x\n",
                  pcaps->module_type[2]);
 
-       if (status == ICE_SUCCESS && report_mode == ICE_AQC_REPORT_TOPO_CAP) {
+       if (status == ICE_SUCCESS && report_mode == ICE_AQC_REPORT_TOPO_CAP_MEDIA) {
                pi->phy.phy_type_low = LE64_TO_CPU(pcaps->phy_type_low);
                pi->phy.phy_type_high = LE64_TO_CPU(pcaps->phy_type_high);
                ice_memcpy(pi->phy.link_info.module_type, &pcaps->module_type,
@@ -425,6 +434,7 @@ ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
        li->phy_type_high = LE64_TO_CPU(link_data.phy_type_high);
        *hw_media_type = ice_get_media_type(pi);
        li->link_info = link_data.link_info;
+       li->link_cfg_err = link_data.link_cfg_err;
        li->an_info = link_data.an_info;
        li->ext_info = link_data.ext_info;
        li->max_frame_size = LE16_TO_CPU(link_data.max_frame_size);
@@ -455,6 +465,7 @@ ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
                  (unsigned long long)li->phy_type_high);
        ice_debug(hw, ICE_DBG_LINK, "   media_type = 0x%x\n", *hw_media_type);
        ice_debug(hw, ICE_DBG_LINK, "   link_info = 0x%x\n", li->link_info);
+       ice_debug(hw, ICE_DBG_LINK, "   link_cfg_err = 0x%x\n", li->link_cfg_err);
        ice_debug(hw, ICE_DBG_LINK, "   an_info = 0x%x\n", li->an_info);
        ice_debug(hw, ICE_DBG_LINK, "   ext_info = 0x%x\n", li->ext_info);
        ice_debug(hw, ICE_DBG_LINK, "   fec_info = 0x%x\n", li->fec_info);
@@ -633,7 +644,7 @@ ice_cleanup_fltr_mgmt_single(struct ice_hw *hw, struct ice_switch_info *sw)
 }
 
 /**
- * ice_cleanup_all_fltr_mgmt - cleanup filter management list and locks
+ * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
  * @hw: pointer to the HW struct
  */
 void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
@@ -779,10 +790,11 @@ enum ice_status ice_init_hw(struct ice_hw *hw)
 
        /* Initialize port_info struct with PHY capabilities */
        status = ice_aq_get_phy_caps(hw->port_info, false,
-                                    ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL);
+                                    ICE_AQC_REPORT_TOPO_CAP_MEDIA, pcaps, NULL);
        ice_free(hw, pcaps);
        if (status)
-               ice_debug(hw, ICE_DBG_PHY, "Get PHY capabilities failed, continuing anyway\n");
+               ice_warn(hw, "Get PHY capabilities failed status = %d, continuing anyway\n",
+                        status);
 
        /* Initialize port_info struct with link information */
        status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
@@ -831,8 +843,6 @@ enum ice_status ice_init_hw(struct ice_hw *hw)
                goto err_unroll_fltr_mgmt_struct;
        ice_init_lock(&hw->tnl_lock);
 
-       ice_init_vlan_mode_ops(hw);
-
        return ICE_SUCCESS;
 
 err_unroll_fltr_mgmt_struct:
@@ -1344,6 +1354,89 @@ ice_clear_tx_drbell_q_ctx(struct ice_hw *hw, u32 tx_drbell_q_index)
 
 /* FW Admin Queue command wrappers */
 
+/**
+ * ice_should_retry_sq_send_cmd
+ * @opcode: AQ opcode
+ *
+ * Decide if we should retry the send command routine for the ATQ, depending
+ * on the opcode.
+ */
+static bool ice_should_retry_sq_send_cmd(u16 opcode)
+{
+       switch (opcode) {
+       case ice_aqc_opc_get_link_topo:
+       case ice_aqc_opc_lldp_stop:
+       case ice_aqc_opc_lldp_start:
+       case ice_aqc_opc_lldp_filter_ctrl:
+               return true;
+       }
+
+       return false;
+}
+
+/**
+ * ice_sq_send_cmd_retry - send command to Control Queue (ATQ)
+ * @hw: pointer to the HW struct
+ * @cq: pointer to the specific Control queue
+ * @desc: prefilled descriptor describing the command
+ * @buf: buffer to use for indirect commands (or NULL for direct commands)
+ * @buf_size: size of buffer for indirect commands (or 0 for direct commands)
+ * @cd: pointer to command details structure
+ *
+ * Retry sending the FW Admin Queue command, multiple times, to the FW Admin
+ * Queue if the EBUSY AQ error is returned.
+ */
+static enum ice_status
+ice_sq_send_cmd_retry(struct ice_hw *hw, struct ice_ctl_q_info *cq,
+                     struct ice_aq_desc *desc, void *buf, u16 buf_size,
+                     struct ice_sq_cd *cd)
+{
+       struct ice_aq_desc desc_cpy;
+       enum ice_status status;
+       bool is_cmd_for_retry;
+       u8 *buf_cpy = NULL;
+       u8 idx = 0;
+       u16 opcode;
+
+       opcode = LE16_TO_CPU(desc->opcode);
+       is_cmd_for_retry = ice_should_retry_sq_send_cmd(opcode);
+       ice_memset(&desc_cpy, 0, sizeof(desc_cpy), ICE_NONDMA_MEM);
+
+       if (is_cmd_for_retry) {
+               if (buf) {
+                       buf_cpy = (u8 *)ice_malloc(hw, buf_size);
+                       if (!buf_cpy)
+                               return ICE_ERR_NO_MEMORY;
+               }
+
+               ice_memcpy(&desc_cpy, desc, sizeof(desc_cpy),
+                          ICE_NONDMA_TO_NONDMA);
+       }
+
+       do {
+               status = ice_sq_send_cmd(hw, cq, desc, buf, buf_size, cd);
+
+               if (!is_cmd_for_retry || status == ICE_SUCCESS ||
+                   hw->adminq.sq_last_status != ICE_AQ_RC_EBUSY)
+                       break;
+
+               if (buf_cpy)
+                       ice_memcpy(buf, buf_cpy, buf_size,
+                                  ICE_NONDMA_TO_NONDMA);
+
+               ice_memcpy(desc, &desc_cpy, sizeof(desc_cpy),
+                          ICE_NONDMA_TO_NONDMA);
+
+               ice_msec_delay(ICE_SQ_SEND_DELAY_TIME_MS, false);
+
+       } while (++idx < ICE_SQ_SEND_MAX_EXECUTE);
+
+       if (buf_cpy)
+               ice_free(hw, buf_cpy);
+
+       return status;
+}
+
 /**
  * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
  * @hw: pointer to the HW struct
@@ -1380,7 +1473,7 @@ ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
 
                return status;
        }
-       return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
+       return ice_sq_send_cmd_retry(hw, &hw->adminq, desc, buf, buf_size, cd);
 }
 
 /**
@@ -2356,7 +2449,7 @@ ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
        ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
 
        cmd->flags = flags;
-       ice_memcpy(cmd->mac_addr, mac_addr, ETH_ALEN, ICE_NONDMA_TO_DMA);
+       ice_memcpy(cmd->mac_addr, mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
 
        return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
 }
@@ -2689,7 +2782,7 @@ enum ice_status ice_update_link_info(struct ice_port_info *pi)
                if (!pcaps)
                        return ICE_ERR_NO_MEMORY;
 
-               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
+               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
                                             pcaps, NULL);
 
                if (status == ICE_SUCCESS)
@@ -2812,7 +2905,7 @@ ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
                /* Query the value of FC that both the NIC and attached media
                 * can do.
                 */
-               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
+               status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
                                             pcaps, NULL);
                if (status) {
                        ice_free(pi->hw, pcaps);
@@ -2881,8 +2974,9 @@ ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
                return ICE_ERR_NO_MEMORY;
 
        /* Get the current PHY config */
-       status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
-                                    NULL);
+       status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
+                                    pcaps, NULL);
+
        if (status) {
                *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
                goto out;
@@ -2999,17 +3093,6 @@ ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
        cfg->link_fec_opt = caps->link_fec_options;
        cfg->module_compliance_enforcement =
                caps->module_compliance_enforcement;
-
-       if (ice_fw_supports_link_override(pi->hw)) {
-               struct ice_link_default_override_tlv tlv;
-
-               if (ice_get_link_default_override(&tlv, pi))
-                       return;
-
-               if (tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE)
-                       cfg->module_compliance_enforcement |=
-                               ICE_LINK_OVERRIDE_STRICT_MODE;
-       }
 }
 
 /**
@@ -3036,8 +3119,11 @@ ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
        if (!pcaps)
                return ICE_ERR_NO_MEMORY;
 
-       status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP, pcaps,
-                                    NULL);
+       status = ice_aq_get_phy_caps(pi, false,
+                                    (ice_fw_supports_report_dflt_cfg(hw) ?
+                                     ICE_AQC_REPORT_DFLT_CFG :
+                                     ICE_AQC_REPORT_TOPO_CAP_MEDIA), pcaps, NULL);
+
        if (status)
                goto out;
 
@@ -3076,7 +3162,8 @@ ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
                break;
        }
 
-       if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw)) {
+       if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw) &&
+           !ice_fw_supports_report_dflt_cfg(pi->hw)) {
                struct ice_link_default_override_tlv tlv;
 
                if (ice_get_link_default_override(&tlv, pi))
@@ -4679,6 +4766,158 @@ enum ice_fw_modes ice_get_fw_mode(struct ice_hw *hw)
                return ICE_FW_MODE_NORMAL;
 }
 
+/**
+ * ice_aq_read_i2c
+ * @hw: pointer to the hw struct
+ * @topo_addr: topology address for a device to communicate with
+ * @bus_addr: 7-bit I2C bus address
+ * @addr: I2C memory address (I2C offset) with up to 16 bits
+ * @params: I2C parameters: bit [7] - Repeated start, bits [6:5] data offset size,
+ *                         bit [4] - I2C address type, bits [3:0] - data size to read (0-16 bytes)
+ * @data: pointer to data (0 to 16 bytes) to be read from the I2C device
+ * @cd: pointer to command details structure or NULL
+ *
+ * Read I2C (0x06E2)
+ */
+enum ice_status
+ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
+               u16 bus_addr, __le16 addr, u8 params, u8 *data,
+               struct ice_sq_cd *cd)
+{
+       struct ice_aq_desc desc = { 0 };
+       struct ice_aqc_i2c *cmd;
+       enum ice_status status;
+       u8 data_size;
+
+       ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_read_i2c);
+       cmd = &desc.params.read_write_i2c;
+
+       if (!data)
+               return ICE_ERR_PARAM;
+
+       data_size = (params & ICE_AQC_I2C_DATA_SIZE_M) >> ICE_AQC_I2C_DATA_SIZE_S;
+
+       cmd->i2c_bus_addr = CPU_TO_LE16(bus_addr);
+       cmd->topo_addr = topo_addr;
+       cmd->i2c_params = params;
+       cmd->i2c_addr = addr;
+
+       status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
+       if (!status) {
+               struct ice_aqc_read_i2c_resp *resp;
+               u8 i;
+
+               resp = &desc.params.read_i2c_resp;
+               for (i = 0; i < data_size; i++) {
+                       *data = resp->i2c_data[i];
+                       data++;
+               }
+       }
+
+       return status;
+}
+
+/**
+ * ice_aq_write_i2c
+ * @hw: pointer to the hw struct
+ * @topo_addr: topology address for a device to communicate with
+ * @bus_addr: 7-bit I2C bus address
+ * @addr: I2C memory address (I2C offset) with up to 16 bits
+ * @params: I2C parameters: bit [4] - I2C address type, bits [3:0] - data size to write (0-7 bytes)
+ * @data: pointer to data (0 to 4 bytes) to be written to the I2C device
+ * @cd: pointer to command details structure or NULL
+ *
+ * Write I2C (0x06E3)
+ */
+enum ice_status
+ice_aq_write_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
+                u16 bus_addr, __le16 addr, u8 params, u8 *data,
+                struct ice_sq_cd *cd)
+{
+       struct ice_aq_desc desc = { 0 };
+       struct ice_aqc_i2c *cmd;
+       u8 i, data_size;
+
+       ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_write_i2c);
+       cmd = &desc.params.read_write_i2c;
+
+       data_size = (params & ICE_AQC_I2C_DATA_SIZE_M) >> ICE_AQC_I2C_DATA_SIZE_S;
+
+       /* data_size limited to 4 */
+       if (data_size > 4)
+               return ICE_ERR_PARAM;
+
+       cmd->i2c_bus_addr = CPU_TO_LE16(bus_addr);
+       cmd->topo_addr = topo_addr;
+       cmd->i2c_params = params;
+       cmd->i2c_addr = addr;
+
+       for (i = 0; i < data_size; i++) {
+               cmd->i2c_data[i] = *data;
+               data++;
+       }
+
+       return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
+}
+
+/**
+ * ice_aq_set_gpio
+ * @hw: pointer to the hw struct
+ * @gpio_ctrl_handle: GPIO controller node handle
+ * @pin_idx: IO Number of the GPIO that needs to be set
+ * @value: SW provide IO value to set in the LSB
+ * @cd: pointer to command details structure or NULL
+ *
+ * Sends 0x06EC AQ command to set the GPIO pin state that's part of the topology
+ */
+enum ice_status
+ice_aq_set_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, bool value,
+               struct ice_sq_cd *cd)
+{
+       struct ice_aqc_gpio *cmd;
+       struct ice_aq_desc desc;
+
+       ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_gpio);
+       cmd = &desc.params.read_write_gpio;
+       cmd->gpio_ctrl_handle = gpio_ctrl_handle;
+       cmd->gpio_num = pin_idx;
+       cmd->gpio_val = value ? 1 : 0;
+
+       return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
+}
+
+/**
+ * ice_aq_get_gpio
+ * @hw: pointer to the hw struct
+ * @gpio_ctrl_handle: GPIO controller node handle
+ * @pin_idx: IO Number of the GPIO that needs to be set
+ * @value: IO value read
+ * @cd: pointer to command details structure or NULL
+ *
+ * Sends 0x06ED AQ command to get the value of a GPIO signal which is part of
+ * the topology
+ */
+enum ice_status
+ice_aq_get_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx,
+               bool *value, struct ice_sq_cd *cd)
+{
+       struct ice_aqc_gpio *cmd;
+       struct ice_aq_desc desc;
+       enum ice_status status;
+
+       ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_gpio);
+       cmd = &desc.params.read_write_gpio;
+       cmd->gpio_ctrl_handle = gpio_ctrl_handle;
+       cmd->gpio_num = pin_idx;
+
+       status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
+       if (status)
+               return status;
+
+       *value = !!cmd->gpio_val;
+       return ICE_SUCCESS;
+}
+
 /**
  * ice_fw_supports_link_override
  * @hw: pointer to the hardware structure
@@ -4822,7 +5061,7 @@ ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
 }
 
 /**
- * ice_fw_supports_lldp_fltr - check NVM version supports lldp_fltr_ctrl
+ * ice_fw_supports_lldp_fltr_ctrl - check NVM version supports lldp_fltr_ctrl
  * @hw: pointer to HW struct
  */
 bool ice_fw_supports_lldp_fltr_ctrl(struct ice_hw *hw)
@@ -4867,3 +5106,23 @@ ice_lldp_fltr_add_remove(struct ice_hw *hw, u16 vsi_num, bool add)
 
        return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
 }
+
+/**
+ * ice_fw_supports_report_dflt_cfg
+ * @hw: pointer to the hardware structure
+ *
+ * Checks if the firmware supports report default configuration
+ */
+bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
+{
+       if (hw->api_maj_ver == ICE_FW_API_REPORT_DFLT_CFG_MAJ) {
+               if (hw->api_min_ver > ICE_FW_API_REPORT_DFLT_CFG_MIN)
+                       return true;
+               if (hw->api_min_ver == ICE_FW_API_REPORT_DFLT_CFG_MIN &&
+                   hw->api_patch >= ICE_FW_API_REPORT_DFLT_CFG_PATCH)
+                       return true;
+       } else if (hw->api_maj_ver > ICE_FW_API_REPORT_DFLT_CFG_MAJ) {
+               return true;
+       }
+       return false;
+}