-/*******************************************************************************
-
-Copyright (c) 2013 - 2015, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. 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.
-
- 3. Neither the name of the Intel 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) 2013 - 2015 Intel Corporation
+ */
#include "iavf_type.h"
#include "iavf_adminq.h"
* This function sets the mac type of the adapter based on the
* vendor ID and device ID stored in the hw structure.
**/
-enum iavf_status_code iavf_set_mac_type(struct iavf_hw *hw)
+enum iavf_status iavf_set_mac_type(struct iavf_hw *hw)
{
- enum iavf_status_code status = IAVF_SUCCESS;
+ enum iavf_status status = IAVF_SUCCESS;
DEBUGFUNC("iavf_set_mac_type\n");
if (hw->vendor_id == IAVF_INTEL_VENDOR_ID) {
switch (hw->device_id) {
- /* TODO: remove undefined device ID now, need to think how to
- * remove them in share code
- */
+ case IAVF_DEV_ID_X722_VF:
+ hw->mac.type = IAVF_MAC_X722_VF;
+ break;
+ case IAVF_DEV_ID_VF:
+ case IAVF_DEV_ID_VF_HV:
case IAVF_DEV_ID_ADAPTIVE_VF:
hw->mac.type = IAVF_MAC_VF;
break;
* @hw: pointer to the HW structure
* @stat_err: the status error code to convert
**/
-const char *iavf_stat_str(struct iavf_hw *hw, enum iavf_status_code stat_err)
+const char *iavf_stat_str(struct iavf_hw *hw, enum iavf_status stat_err)
{
switch (stat_err) {
case IAVF_SUCCESS:
bool iavf_check_asq_alive(struct iavf_hw *hw)
{
if (hw->aq.asq.len)
-#ifdef INTEGRATED_VF
- if (iavf_is_vf(hw))
- return !!(rd32(hw, hw->aq.asq.len) &
- IAVF_ATQLEN1_ATQENABLE_MASK);
-#else
return !!(rd32(hw, hw->aq.asq.len) &
- IAVF_ATQLEN1_ATQENABLE_MASK);
-#endif /* INTEGRATED_VF */
- return false;
+ IAVF_VF_ATQLEN1_ATQENABLE_MASK);
+ else
+ return false;
}
/**
* Tell the Firmware that we're shutting down the AdminQ and whether
* or not the driver is unloading as well.
**/
-enum iavf_status_code iavf_aq_queue_shutdown(struct iavf_hw *hw,
+enum iavf_status iavf_aq_queue_shutdown(struct iavf_hw *hw,
bool unloading)
{
struct iavf_aq_desc desc;
struct iavf_aqc_queue_shutdown *cmd =
(struct iavf_aqc_queue_shutdown *)&desc.params.raw;
- enum iavf_status_code status;
+ enum iavf_status status;
iavf_fill_default_direct_cmd_desc(&desc,
iavf_aqc_opc_queue_shutdown);
*
* Internal function to get or set RSS look up table
**/
-STATIC enum iavf_status_code iavf_aq_get_set_rss_lut(struct iavf_hw *hw,
+STATIC enum iavf_status iavf_aq_get_set_rss_lut(struct iavf_hw *hw,
u16 vsi_id, bool pf_lut,
u8 *lut, u16 lut_size,
bool set)
{
- enum iavf_status_code status;
+ enum iavf_status status;
struct iavf_aq_desc desc;
struct iavf_aqc_get_set_rss_lut *cmd_resp =
(struct iavf_aqc_get_set_rss_lut *)&desc.params.raw;
*
* get the RSS lookup table, PF or VSI type
**/
-enum iavf_status_code iavf_aq_get_rss_lut(struct iavf_hw *hw, u16 vsi_id,
+enum iavf_status iavf_aq_get_rss_lut(struct iavf_hw *hw, u16 vsi_id,
bool pf_lut, u8 *lut, u16 lut_size)
{
return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
*
* set the RSS lookup table, PF or VSI type
**/
-enum iavf_status_code iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 vsi_id,
+enum iavf_status iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 vsi_id,
bool pf_lut, u8 *lut, u16 lut_size)
{
return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
*
* get the RSS key per VSI
**/
-STATIC enum iavf_status_code iavf_aq_get_set_rss_key(struct iavf_hw *hw,
+STATIC enum iavf_status iavf_aq_get_set_rss_key(struct iavf_hw *hw,
u16 vsi_id,
struct iavf_aqc_get_set_rss_key_data *key,
bool set)
{
- enum iavf_status_code status;
+ enum iavf_status status;
struct iavf_aq_desc desc;
struct iavf_aqc_get_set_rss_key *cmd_resp =
(struct iavf_aqc_get_set_rss_key *)&desc.params.raw;
* @key: pointer to key info struct
*
**/
-enum iavf_status_code iavf_aq_get_rss_key(struct iavf_hw *hw,
+enum iavf_status iavf_aq_get_rss_key(struct iavf_hw *hw,
u16 vsi_id,
struct iavf_aqc_get_set_rss_key_data *key)
{
*
* set the RSS key per VSI
**/
-enum iavf_status_code iavf_aq_set_rss_key(struct iavf_hw *hw,
+enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw,
u16 vsi_id,
struct iavf_aqc_get_set_rss_key_data *key)
{
IAVF_PTT_UNUSED_ENTRY(255)
};
-
/**
* iavf_validate_mac_addr - Validate unicast MAC address
* @mac_addr: pointer to MAC address
*
* Tests a MAC address to ensure it is a valid Individual Address
**/
-enum iavf_status_code iavf_validate_mac_addr(u8 *mac_addr)
+enum iavf_status iavf_validate_mac_addr(u8 *mac_addr)
{
- enum iavf_status_code status = IAVF_SUCCESS;
+ enum iavf_status status = IAVF_SUCCESS;
DEBUGFUNC("iavf_validate_mac_addr");
return status;
}
-/**
- * iavf_aq_rx_ctl_read_register - use FW to read from an Rx control register
- * @hw: pointer to the hw struct
- * @reg_addr: register address
- * @reg_val: ptr to register value
- * @cmd_details: pointer to command details structure or NULL
- *
- * Use the firmware to read the Rx control register,
- * especially useful if the Rx unit is under heavy pressure
- **/
-enum iavf_status_code iavf_aq_rx_ctl_read_register(struct iavf_hw *hw,
- u32 reg_addr, u32 *reg_val,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_rx_ctl_reg_read_write *cmd_resp =
- (struct iavf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
- enum iavf_status_code status;
-
- if (reg_val == NULL)
- return IAVF_ERR_PARAM;
-
- iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_rx_ctl_reg_read);
-
- cmd_resp->address = CPU_TO_LE32(reg_addr);
-
- status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
-
- if (status == IAVF_SUCCESS)
- *reg_val = LE32_TO_CPU(cmd_resp->value);
-
- return status;
-}
-
-/**
- * iavf_read_rx_ctl - read from an Rx control register
- * @hw: pointer to the hw struct
- * @reg_addr: register address
- **/
-u32 iavf_read_rx_ctl(struct iavf_hw *hw, u32 reg_addr)
-{
- enum iavf_status_code status = IAVF_SUCCESS;
- bool use_register;
- int retry = 5;
- u32 val = 0;
-
- use_register = (((hw->aq.api_maj_ver == 1) &&
- (hw->aq.api_min_ver < 5)) ||
- (hw->mac.type == IAVF_MAC_X722));
- if (!use_register) {
-do_retry:
- status = iavf_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
- if (hw->aq.asq_last_status == IAVF_AQ_RC_EAGAIN && retry) {
- iavf_msec_delay(1);
- retry--;
- goto do_retry;
- }
- }
-
- /* if the AQ access failed, try the old-fashioned way */
- if (status || use_register)
- val = rd32(hw, reg_addr);
-
- return val;
-}
-
-/**
- * iavf_aq_rx_ctl_write_register
- * @hw: pointer to the hw struct
- * @reg_addr: register address
- * @reg_val: register value
- * @cmd_details: pointer to command details structure or NULL
- *
- * Use the firmware to write to an Rx control register,
- * especially useful if the Rx unit is under heavy pressure
- **/
-enum iavf_status_code iavf_aq_rx_ctl_write_register(struct iavf_hw *hw,
- u32 reg_addr, u32 reg_val,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_rx_ctl_reg_read_write *cmd =
- (struct iavf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_rx_ctl_reg_write);
-
- cmd->address = CPU_TO_LE32(reg_addr);
- cmd->value = CPU_TO_LE32(reg_val);
-
- status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
-
- return status;
-}
-
-/**
- * iavf_write_rx_ctl - write to an Rx control register
- * @hw: pointer to the hw struct
- * @reg_addr: register address
- * @reg_val: register value
- **/
-void iavf_write_rx_ctl(struct iavf_hw *hw, u32 reg_addr, u32 reg_val)
-{
- enum iavf_status_code status = IAVF_SUCCESS;
- bool use_register;
- int retry = 5;
-
- use_register = (((hw->aq.api_maj_ver == 1) &&
- (hw->aq.api_min_ver < 5)) ||
- (hw->mac.type == IAVF_MAC_X722));
- if (!use_register) {
-do_retry:
- status = iavf_aq_rx_ctl_write_register(hw, reg_addr,
- reg_val, NULL);
- if (hw->aq.asq_last_status == IAVF_AQ_RC_EAGAIN && retry) {
- iavf_msec_delay(1);
- retry--;
- goto do_retry;
- }
- }
-
- /* if the AQ access failed, try the old-fashioned way */
- if (status || use_register)
- wr32(hw, reg_addr, reg_val);
-}
-
-/**
- * iavf_aq_set_phy_register
- * @hw: pointer to the hw struct
- * @phy_select: select which phy should be accessed
- * @dev_addr: PHY device address
- * @reg_addr: PHY register address
- * @reg_val: new register value
- * @cmd_details: pointer to command details structure or NULL
- *
- * Write the external PHY register.
- **/
-enum iavf_status_code iavf_aq_set_phy_register(struct iavf_hw *hw,
- u8 phy_select, u8 dev_addr,
- u32 reg_addr, u32 reg_val,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_phy_register_access *cmd =
- (struct iavf_aqc_phy_register_access *)&desc.params.raw;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc,
- iavf_aqc_opc_set_phy_register);
-
- cmd->phy_interface = phy_select;
- cmd->dev_addres = dev_addr;
- cmd->reg_address = CPU_TO_LE32(reg_addr);
- cmd->reg_value = CPU_TO_LE32(reg_val);
-
- status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
-
- return status;
-}
-
-/**
- * iavf_aq_get_phy_register
- * @hw: pointer to the hw struct
- * @phy_select: select which phy should be accessed
- * @dev_addr: PHY device address
- * @reg_addr: PHY register address
- * @reg_val: read register value
- * @cmd_details: pointer to command details structure or NULL
- *
- * Read the external PHY register.
- **/
-enum iavf_status_code iavf_aq_get_phy_register(struct iavf_hw *hw,
- u8 phy_select, u8 dev_addr,
- u32 reg_addr, u32 *reg_val,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_phy_register_access *cmd =
- (struct iavf_aqc_phy_register_access *)&desc.params.raw;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc,
- iavf_aqc_opc_get_phy_register);
-
- cmd->phy_interface = phy_select;
- cmd->dev_addres = dev_addr;
- cmd->reg_address = CPU_TO_LE32(reg_addr);
-
- status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
- if (!status)
- *reg_val = LE32_TO_CPU(cmd->reg_value);
-
- return status;
-}
-
-
/**
* iavf_aq_send_msg_to_pf
* @hw: pointer to the hardware structure
* is sent asynchronously, i.e. iavf_asq_send_command() does not wait for
* completion before returning.
**/
-enum iavf_status_code iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
+enum iavf_status iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
enum virtchnl_ops v_opcode,
- enum iavf_status_code v_retval,
+ enum iavf_status v_retval,
u8 *msg, u16 msglen,
struct iavf_asq_cmd_details *cmd_details)
{
struct iavf_aq_desc desc;
struct iavf_asq_cmd_details details;
- enum iavf_status_code status;
+ enum iavf_status status;
iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_send_msg_to_pf);
desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_SI);
hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
hw->dev_caps.dcb = msg->vf_cap_flags &
VIRTCHNL_VF_OFFLOAD_L2;
- hw->dev_caps.iwarp = (msg->vf_cap_flags &
- VIRTCHNL_VF_OFFLOAD_IWARP) ? 1 : 0;
for (i = 0; i < msg->num_vsis; i++) {
if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
iavf_memcpy(hw->mac.perm_addr,
* as none will be forthcoming. Immediately after calling this function,
* the admin queue should be shut down and (optionally) reinitialized.
**/
-enum iavf_status_code iavf_reset(struct iavf_hw *hw)
+enum iavf_status iavf_reset(struct iavf_hw *hw)
{
return iavf_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
IAVF_SUCCESS, NULL, 0, NULL);
}
-/**
- * iavf_aq_set_arp_proxy_config
- * @hw: pointer to the HW structure
- * @proxy_config: pointer to proxy config command table struct
- * @cmd_details: pointer to command details
- *
- * Set ARP offload parameters from pre-populated
- * iavf_aqc_arp_proxy_data struct
- **/
-enum iavf_status_code iavf_aq_set_arp_proxy_config(struct iavf_hw *hw,
- struct iavf_aqc_arp_proxy_data *proxy_config,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- enum iavf_status_code status;
-
- if (!proxy_config)
- return IAVF_ERR_PARAM;
-
- iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_set_proxy_config);
-
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
- desc.params.external.addr_high =
- CPU_TO_LE32(IAVF_HI_DWORD((u64)proxy_config));
- desc.params.external.addr_low =
- CPU_TO_LE32(IAVF_LO_DWORD((u64)proxy_config));
- desc.datalen = CPU_TO_LE16(sizeof(struct iavf_aqc_arp_proxy_data));
-
- status = iavf_asq_send_command(hw, &desc, proxy_config,
- sizeof(struct iavf_aqc_arp_proxy_data),
- cmd_details);
-
- return status;
-}
-
-/**
- * iavf_aq_opc_set_ns_proxy_table_entry
- * @hw: pointer to the HW structure
- * @ns_proxy_table_entry: pointer to NS table entry command struct
- * @cmd_details: pointer to command details
- *
- * Set IPv6 Neighbor Solicitation (NS) protocol offload parameters
- * from pre-populated iavf_aqc_ns_proxy_data struct
- **/
-enum iavf_status_code iavf_aq_set_ns_proxy_table_entry(struct iavf_hw *hw,
- struct iavf_aqc_ns_proxy_data *ns_proxy_table_entry,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- enum iavf_status_code status;
-
- if (!ns_proxy_table_entry)
- return IAVF_ERR_PARAM;
-
- iavf_fill_default_direct_cmd_desc(&desc,
- iavf_aqc_opc_set_ns_proxy_table_entry);
-
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
- desc.params.external.addr_high =
- CPU_TO_LE32(IAVF_HI_DWORD((u64)ns_proxy_table_entry));
- desc.params.external.addr_low =
- CPU_TO_LE32(IAVF_LO_DWORD((u64)ns_proxy_table_entry));
- desc.datalen = CPU_TO_LE16(sizeof(struct iavf_aqc_ns_proxy_data));
-
- status = iavf_asq_send_command(hw, &desc, ns_proxy_table_entry,
- sizeof(struct iavf_aqc_ns_proxy_data),
- cmd_details);
-
- return status;
-}
-
-/**
- * iavf_aq_set_clear_wol_filter
- * @hw: pointer to the hw struct
- * @filter_index: index of filter to modify (0-7)
- * @filter: buffer containing filter to be set
- * @set_filter: true to set filter, false to clear filter
- * @no_wol_tco: if true, pass through packets cannot cause wake-up
- * if false, pass through packets may cause wake-up
- * @filter_valid: true if filter action is valid
- * @no_wol_tco_valid: true if no WoL in TCO traffic action valid
- * @cmd_details: pointer to command details structure or NULL
- *
- * Set or clear WoL filter for port attached to the PF
- **/
-enum iavf_status_code iavf_aq_set_clear_wol_filter(struct iavf_hw *hw,
- u8 filter_index,
- struct iavf_aqc_set_wol_filter_data *filter,
- bool set_filter, bool no_wol_tco,
- bool filter_valid, bool no_wol_tco_valid,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_set_wol_filter *cmd =
- (struct iavf_aqc_set_wol_filter *)&desc.params.raw;
- enum iavf_status_code status;
- u16 cmd_flags = 0;
- u16 valid_flags = 0;
- u16 buff_len = 0;
-
- iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_set_wol_filter);
-
- if (filter_index >= IAVF_AQC_MAX_NUM_WOL_FILTERS)
- return IAVF_ERR_PARAM;
- cmd->filter_index = CPU_TO_LE16(filter_index);
-
- if (set_filter) {
- if (!filter)
- return IAVF_ERR_PARAM;
-
- cmd_flags |= IAVF_AQC_SET_WOL_FILTER;
- cmd_flags |= IAVF_AQC_SET_WOL_FILTER_WOL_PRESERVE_ON_PFR;
- }
-
- if (no_wol_tco)
- cmd_flags |= IAVF_AQC_SET_WOL_FILTER_NO_TCO_WOL;
- cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
-
- if (filter_valid)
- valid_flags |= IAVF_AQC_SET_WOL_FILTER_ACTION_VALID;
- if (no_wol_tco_valid)
- valid_flags |= IAVF_AQC_SET_WOL_FILTER_NO_TCO_ACTION_VALID;
- cmd->valid_flags = CPU_TO_LE16(valid_flags);
-
- buff_len = sizeof(*filter);
- desc.datalen = CPU_TO_LE16(buff_len);
-
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
-
- cmd->address_high = CPU_TO_LE32(IAVF_HI_DWORD((u64)filter));
- cmd->address_low = CPU_TO_LE32(IAVF_LO_DWORD((u64)filter));
-
- status = iavf_asq_send_command(hw, &desc, filter,
- buff_len, cmd_details);
-
- return status;
-}
-
-/**
- * iavf_aq_get_wake_event_reason
- * @hw: pointer to the hw struct
- * @wake_reason: return value, index of matching filter
- * @cmd_details: pointer to command details structure or NULL
- *
- * Get information for the reason of a Wake Up event
- **/
-enum iavf_status_code iavf_aq_get_wake_event_reason(struct iavf_hw *hw,
- u16 *wake_reason,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_get_wake_reason_completion *resp =
- (struct iavf_aqc_get_wake_reason_completion *)&desc.params.raw;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_get_wake_reason);
-
- status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
-
- if (status == IAVF_SUCCESS)
- *wake_reason = LE16_TO_CPU(resp->wake_reason);
-
- return status;
-}
-
/**
* iavf_aq_clear_all_wol_filters
* @hw: pointer to the hw struct
*
* Get information for the reason of a Wake Up event
**/
-enum iavf_status_code iavf_aq_clear_all_wol_filters(struct iavf_hw *hw,
+enum iavf_status iavf_aq_clear_all_wol_filters(struct iavf_hw *hw,
struct iavf_asq_cmd_details *cmd_details)
{
struct iavf_aq_desc desc;
- enum iavf_status_code status;
+ enum iavf_status status;
iavf_fill_default_direct_cmd_desc(&desc,
iavf_aqc_opc_clear_all_wol_filters);
return status;
}
-
-/**
- * iavf_aq_write_ddp - Write dynamic device personalization (ddp)
- * @hw: pointer to the hw struct
- * @buff: command buffer (size in bytes = buff_size)
- * @buff_size: buffer size in bytes
- * @track_id: package tracking id
- * @error_offset: returns error offset
- * @error_info: returns error information
- * @cmd_details: pointer to command details structure or NULL
- **/
-enum
-iavf_status_code iavf_aq_write_ddp(struct iavf_hw *hw, void *buff,
- u16 buff_size, u32 track_id,
- u32 *error_offset, u32 *error_info,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_write_personalization_profile *cmd =
- (struct iavf_aqc_write_personalization_profile *)
- &desc.params.raw;
- struct iavf_aqc_write_ddp_resp *resp;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc,
- iavf_aqc_opc_write_personalization_profile);
-
- desc.flags |= CPU_TO_LE16(IAVF_AQ_FLAG_BUF | IAVF_AQ_FLAG_RD);
- if (buff_size > IAVF_AQ_LARGE_BUF)
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
-
- desc.datalen = CPU_TO_LE16(buff_size);
-
- cmd->profile_track_id = CPU_TO_LE32(track_id);
-
- status = iavf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
- if (!status) {
- resp = (struct iavf_aqc_write_ddp_resp *)&desc.params.raw;
- if (error_offset)
- *error_offset = LE32_TO_CPU(resp->error_offset);
- if (error_info)
- *error_info = LE32_TO_CPU(resp->error_info);
- }
-
- return status;
-}
-
-/**
- * iavf_aq_get_ddp_list - Read dynamic device personalization (ddp)
- * @hw: pointer to the hw struct
- * @buff: command buffer (size in bytes = buff_size)
- * @buff_size: buffer size in bytes
- * @flags: AdminQ command flags
- * @cmd_details: pointer to command details structure or NULL
- **/
-enum
-iavf_status_code iavf_aq_get_ddp_list(struct iavf_hw *hw, void *buff,
- u16 buff_size, u8 flags,
- struct iavf_asq_cmd_details *cmd_details)
-{
- struct iavf_aq_desc desc;
- struct iavf_aqc_get_applied_profiles *cmd =
- (struct iavf_aqc_get_applied_profiles *)&desc.params.raw;
- enum iavf_status_code status;
-
- iavf_fill_default_direct_cmd_desc(&desc,
- iavf_aqc_opc_get_personalization_profile_list);
-
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
- if (buff_size > IAVF_AQ_LARGE_BUF)
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
- desc.datalen = CPU_TO_LE16(buff_size);
-
- cmd->flags = flags;
-
- status = iavf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
-
- return status;
-}
-
-/**
- * iavf_find_segment_in_package
- * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_IAVF)
- * @pkg_hdr: pointer to the package header to be searched
- *
- * This function searches a package file for a particular segment type. On
- * success it returns a pointer to the segment header, otherwise it will
- * return NULL.
- **/
-struct iavf_generic_seg_header *
-iavf_find_segment_in_package(u32 segment_type,
- struct iavf_package_header *pkg_hdr)
-{
- struct iavf_generic_seg_header *segment;
- u32 i;
-
- /* Search all package segments for the requested segment type */
- for (i = 0; i < pkg_hdr->segment_count; i++) {
- segment =
- (struct iavf_generic_seg_header *)((u8 *)pkg_hdr +
- pkg_hdr->segment_offset[i]);
-
- if (segment->type == segment_type)
- return segment;
- }
-
- return NULL;
-}
-
-/* Get section table in profile */
-#define IAVF_SECTION_TABLE(profile, sec_tbl) \
- do { \
- struct iavf_profile_segment *p = (profile); \
- u32 count; \
- u32 *nvm; \
- count = p->device_table_count; \
- nvm = (u32 *)&p->device_table[count]; \
- sec_tbl = (struct iavf_section_table *)&nvm[nvm[0] + 1]; \
- } while (0)
-
-/* Get section header in profile */
-#define IAVF_SECTION_HEADER(profile, offset) \
- (struct iavf_profile_section_header *)((u8 *)(profile) + (offset))
-
-/**
- * iavf_find_section_in_profile
- * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
- * @profile: pointer to the iavf segment header to be searched
- *
- * This function searches iavf segment for a particular section type. On
- * success it returns a pointer to the section header, otherwise it will
- * return NULL.
- **/
-struct iavf_profile_section_header *
-iavf_find_section_in_profile(u32 section_type,
- struct iavf_profile_segment *profile)
-{
- struct iavf_profile_section_header *sec;
- struct iavf_section_table *sec_tbl;
- u32 sec_off;
- u32 i;
-
- if (profile->header.type != SEGMENT_TYPE_IAVF)
- return NULL;
-
- IAVF_SECTION_TABLE(profile, sec_tbl);
-
- for (i = 0; i < sec_tbl->section_count; i++) {
- sec_off = sec_tbl->section_offset[i];
- sec = IAVF_SECTION_HEADER(profile, sec_off);
- if (sec->section.type == section_type)
- return sec;
- }
-
- return NULL;
-}
-
-/**
- * iavf_ddp_exec_aq_section - Execute generic AQ for DDP
- * @hw: pointer to the hw struct
- * @aq: command buffer containing all data to execute AQ
- **/
-STATIC enum
-iavf_status_code iavf_ddp_exec_aq_section(struct iavf_hw *hw,
- struct iavf_profile_aq_section *aq)
-{
- enum iavf_status_code status;
- struct iavf_aq_desc desc;
- u8 *msg = NULL;
- u16 msglen;
-
- iavf_fill_default_direct_cmd_desc(&desc, aq->opcode);
- desc.flags |= CPU_TO_LE16(aq->flags);
- iavf_memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw),
- IAVF_NONDMA_TO_NONDMA);
-
- msglen = aq->datalen;
- if (msglen) {
- desc.flags |= CPU_TO_LE16((u16)(IAVF_AQ_FLAG_BUF |
- IAVF_AQ_FLAG_RD));
- if (msglen > IAVF_AQ_LARGE_BUF)
- desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
- desc.datalen = CPU_TO_LE16(msglen);
- msg = &aq->data[0];
- }
-
- status = iavf_asq_send_command(hw, &desc, msg, msglen, NULL);
-
- if (status != IAVF_SUCCESS) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "unable to exec DDP AQ opcode %u, error %d\n",
- aq->opcode, status);
- return status;
- }
-
- /* copy returned desc to aq_buf */
- iavf_memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw),
- IAVF_NONDMA_TO_NONDMA);
-
- return IAVF_SUCCESS;
-}
-
-/**
- * iavf_validate_profile
- * @hw: pointer to the hardware structure
- * @profile: pointer to the profile segment of the package to be validated
- * @track_id: package tracking id
- * @rollback: flag if the profile is for rollback.
- *
- * Validates supported devices and profile's sections.
- */
-STATIC enum iavf_status_code
-iavf_validate_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
- u32 track_id, bool rollback)
-{
- struct iavf_profile_section_header *sec = NULL;
- enum iavf_status_code status = IAVF_SUCCESS;
- struct iavf_section_table *sec_tbl;
- u32 vendor_dev_id;
- u32 dev_cnt;
- u32 sec_off;
- u32 i;
-
- if (track_id == IAVF_DDP_TRACKID_INVALID) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE, "Invalid track_id\n");
- return IAVF_NOT_SUPPORTED;
- }
-
- dev_cnt = profile->device_table_count;
- for (i = 0; i < dev_cnt; i++) {
- vendor_dev_id = profile->device_table[i].vendor_dev_id;
- if ((vendor_dev_id >> 16) == IAVF_INTEL_VENDOR_ID &&
- hw->device_id == (vendor_dev_id & 0xFFFF))
- break;
- }
- if (dev_cnt && (i == dev_cnt)) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Device doesn't support DDP\n");
- return IAVF_ERR_DEVICE_NOT_SUPPORTED;
- }
-
- IAVF_SECTION_TABLE(profile, sec_tbl);
-
- /* Validate sections types */
- for (i = 0; i < sec_tbl->section_count; i++) {
- sec_off = sec_tbl->section_offset[i];
- sec = IAVF_SECTION_HEADER(profile, sec_off);
- if (rollback) {
- if (sec->section.type == SECTION_TYPE_MMIO ||
- sec->section.type == SECTION_TYPE_AQ ||
- sec->section.type == SECTION_TYPE_RB_AQ) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Not a roll-back package\n");
- return IAVF_NOT_SUPPORTED;
- }
- } else {
- if (sec->section.type == SECTION_TYPE_RB_AQ ||
- sec->section.type == SECTION_TYPE_RB_MMIO) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Not an original package\n");
- return IAVF_NOT_SUPPORTED;
- }
- }
- }
-
- return status;
-}
-
-/**
- * iavf_write_profile
- * @hw: pointer to the hardware structure
- * @profile: pointer to the profile segment of the package to be downloaded
- * @track_id: package tracking id
- *
- * Handles the download of a complete package.
- */
-enum iavf_status_code
-iavf_write_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
- u32 track_id)
-{
- enum iavf_status_code status = IAVF_SUCCESS;
- struct iavf_section_table *sec_tbl;
- struct iavf_profile_section_header *sec = NULL;
- struct iavf_profile_aq_section *ddp_aq;
- u32 section_size = 0;
- u32 offset = 0, info = 0;
- u32 sec_off;
- u32 i;
-
- status = iavf_validate_profile(hw, profile, track_id, false);
- if (status)
- return status;
-
- IAVF_SECTION_TABLE(profile, sec_tbl);
-
- for (i = 0; i < sec_tbl->section_count; i++) {
- sec_off = sec_tbl->section_offset[i];
- sec = IAVF_SECTION_HEADER(profile, sec_off);
- /* Process generic admin command */
- if (sec->section.type == SECTION_TYPE_AQ) {
- ddp_aq = (struct iavf_profile_aq_section *)&sec[1];
- status = iavf_ddp_exec_aq_section(hw, ddp_aq);
- if (status) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Failed to execute aq: section %d, opcode %u\n",
- i, ddp_aq->opcode);
- break;
- }
- sec->section.type = SECTION_TYPE_RB_AQ;
- }
-
- /* Skip any non-mmio sections */
- if (sec->section.type != SECTION_TYPE_MMIO)
- continue;
-
- section_size = sec->section.size +
- sizeof(struct iavf_profile_section_header);
-
- /* Write MMIO section */
- status = iavf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
- track_id, &offset, &info, NULL);
- if (status) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Failed to write profile: section %d, offset %d, info %d\n",
- i, offset, info);
- break;
- }
- }
- return status;
-}
-
-/**
- * iavf_rollback_profile
- * @hw: pointer to the hardware structure
- * @profile: pointer to the profile segment of the package to be removed
- * @track_id: package tracking id
- *
- * Rolls back previously loaded package.
- */
-enum iavf_status_code
-iavf_rollback_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
- u32 track_id)
-{
- struct iavf_profile_section_header *sec = NULL;
- enum iavf_status_code status = IAVF_SUCCESS;
- struct iavf_section_table *sec_tbl;
- u32 offset = 0, info = 0;
- u32 section_size = 0;
- u32 sec_off;
- int i;
-
- status = iavf_validate_profile(hw, profile, track_id, true);
- if (status)
- return status;
-
- IAVF_SECTION_TABLE(profile, sec_tbl);
-
- /* For rollback write sections in reverse */
- for (i = sec_tbl->section_count - 1; i >= 0; i--) {
- sec_off = sec_tbl->section_offset[i];
- sec = IAVF_SECTION_HEADER(profile, sec_off);
-
- /* Skip any non-rollback sections */
- if (sec->section.type != SECTION_TYPE_RB_MMIO)
- continue;
-
- section_size = sec->section.size +
- sizeof(struct iavf_profile_section_header);
-
- /* Write roll-back MMIO section */
- status = iavf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
- track_id, &offset, &info, NULL);
- if (status) {
- iavf_debug(hw, IAVF_DEBUG_PACKAGE,
- "Failed to write profile: section %d, offset %d, info %d\n",
- i, offset, info);
- break;
- }
- }
- return status;
-}
-
-/**
- * iavf_add_pinfo_to_list
- * @hw: pointer to the hardware structure
- * @profile: pointer to the profile segment of the package
- * @profile_info_sec: buffer for information section
- * @track_id: package tracking id
- *
- * Register a profile to the list of loaded profiles.
- */
-enum iavf_status_code
-iavf_add_pinfo_to_list(struct iavf_hw *hw,
- struct iavf_profile_segment *profile,
- u8 *profile_info_sec, u32 track_id)
-{
- enum iavf_status_code status = IAVF_SUCCESS;
- struct iavf_profile_section_header *sec = NULL;
- struct iavf_profile_info *pinfo;
- u32 offset = 0, info = 0;
-
- sec = (struct iavf_profile_section_header *)profile_info_sec;
- sec->tbl_size = 1;
- sec->data_end = sizeof(struct iavf_profile_section_header) +
- sizeof(struct iavf_profile_info);
- sec->section.type = SECTION_TYPE_INFO;
- sec->section.offset = sizeof(struct iavf_profile_section_header);
- sec->section.size = sizeof(struct iavf_profile_info);
- pinfo = (struct iavf_profile_info *)(profile_info_sec +
- sec->section.offset);
- pinfo->track_id = track_id;
- pinfo->version = profile->version;
- pinfo->op = IAVF_DDP_ADD_TRACKID;
- iavf_memcpy(pinfo->name, profile->name, IAVF_DDP_NAME_SIZE,
- IAVF_NONDMA_TO_NONDMA);
-
- status = iavf_aq_write_ddp(hw, (void *)sec, sec->data_end,
- track_id, &offset, &info, NULL);
- return status;
-}