Skip to content

Commit

Permalink
ice: avoid unnecessary single-member variable-length structs
Browse files Browse the repository at this point in the history
There are a number of structures that consist of a one-element array as the
only struct member.  Some of those are unused so remove them. Others are
used to index into a buffer/array consisting of a variable number of a
different data or structure type.  Those are unnecessary since we can use
simple pointer arithmetic or index directly into the buffer to access
individual elements of the buffer/array.

Additional code cleanups were done near areas affected by this change.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
  • Loading branch information
Bruce Allan authored and Tony Nguyen committed Jul 1, 2020
1 parent 8d7aab3 commit b3c3890
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 100 deletions.
39 changes: 1 addition & 38 deletions drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ struct ice_aqc_get_sw_cfg_resp_elem {
#define ICE_AQC_GET_SW_CONF_RESP_IS_VF BIT(15)
};

/* The response buffer is as follows. Note that the length of the
* elements array varies with the length of the command response.
*/
struct ice_aqc_get_sw_cfg_resp {
struct ice_aqc_get_sw_cfg_resp_elem elements[1];
};

/* These resource type defines are used for all switch resource
* commands where a resource type is required, such as:
* Get Resource Allocation command (indirect 0x0204)
Expand Down Expand Up @@ -695,14 +688,6 @@ struct ice_aqc_sched_elem_cmd {
__le32 addr_low;
};

/* This is the buffer for:
* Suspend Nodes (indirect 0x0409)
* Resume Nodes (indirect 0x040A)
*/
struct ice_aqc_suspend_resume_elem {
__le32 teid[1];
};

struct ice_aqc_elem_info_bw {
__le16 bw_profile_idx;
__le16 bw_alloc;
Expand Down Expand Up @@ -756,14 +741,6 @@ struct ice_aqc_add_elem {
struct ice_aqc_txsched_elem_data generic[1];
};

struct ice_aqc_conf_elem {
struct ice_aqc_txsched_elem_data generic[1];
};

struct ice_aqc_get_elem {
struct ice_aqc_txsched_elem_data generic[1];
};

struct ice_aqc_get_topo_elem {
struct ice_aqc_txsched_topo_grp_info_hdr hdr;
struct ice_aqc_txsched_elem_data
Expand Down Expand Up @@ -835,10 +812,6 @@ struct ice_aqc_rl_profile_elem {
__le16 rl_encode;
};

struct ice_aqc_rl_profile_generic_elem {
struct ice_aqc_rl_profile_elem generic[1];
};

/* Query Scheduler Resource Allocation (indirect 0x0412)
* This indirect command retrieves the scheduler resources allocated by
* EMP Firmware to the given PF.
Expand Down Expand Up @@ -1584,10 +1557,6 @@ struct ice_aqc_dis_txq_item {
(1 << ICE_AQC_Q_DIS_BUF_ELEM_TYPE_S)
};

struct ice_aqc_dis_txq {
struct ice_aqc_dis_txq_item qgrps[1];
};

/* Configure Firmware Logging Command (indirect 0xFF09)
* Logging Information Read Response (indirect 0xFF10)
* Note: The 0xFF10 command has no input parameters.
Expand Down Expand Up @@ -1636,12 +1605,7 @@ enum ice_aqc_fw_logging_mod {
ICE_AQC_FW_LOG_ID_MAX,
};

/* This is the buffer for both of the logging commands.
* The entry array size depends on the datalen parameter in the descriptor.
* There will be a total of datalen / 2 entries.
*/
struct ice_aqc_fw_logging_data {
__le16 entry[1];
/* Defines for both above FW logging command/response buffers */
#define ICE_AQC_FW_LOG_ID_S 0
#define ICE_AQC_FW_LOG_ID_M (0xFFF << ICE_AQC_FW_LOG_ID_S)

Expand All @@ -1654,7 +1618,6 @@ struct ice_aqc_fw_logging_data {
#define ICE_AQC_FW_LOG_INIT_EN BIT(13) /* Used by command */
#define ICE_AQC_FW_LOG_FLOW_EN BIT(14) /* Used by command */
#define ICE_AQC_FW_LOG_ERR_EN BIT(15) /* Used by command */
};

/* Get/Clear FW Log (indirect 0xFF11) */
struct ice_aqc_get_clear_fw_log {
Expand Down
29 changes: 12 additions & 17 deletions drivers/net/ethernet/intel/ice/ice_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,30 +440,24 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
devm_kfree(ice_hw_to_dev(hw), sw);
}

#define ICE_FW_LOG_DESC_SIZE(n) (sizeof(struct ice_aqc_fw_logging_data) + \
(((n) - 1) * sizeof(((struct ice_aqc_fw_logging_data *)0)->entry)))
#define ICE_FW_LOG_DESC_SIZE_MAX \
ICE_FW_LOG_DESC_SIZE(ICE_AQC_FW_LOG_ID_MAX)

/**
* ice_get_fw_log_cfg - get FW logging configuration
* @hw: pointer to the HW struct
*/
static enum ice_status ice_get_fw_log_cfg(struct ice_hw *hw)
{
struct ice_aqc_fw_logging_data *config;
struct ice_aq_desc desc;
enum ice_status status;
__le16 *config;
u16 size;

size = ICE_FW_LOG_DESC_SIZE_MAX;
size = sizeof(*config) * ICE_AQC_FW_LOG_ID_MAX;
config = devm_kzalloc(ice_hw_to_dev(hw), size, GFP_KERNEL);
if (!config)
return ICE_ERR_NO_MEMORY;

ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_fw_logging_info);

desc.flags |= cpu_to_le16(ICE_AQ_FLAG_BUF);
desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);

status = ice_aq_send_cmd(hw, &desc, config, size, NULL);
Expand All @@ -474,7 +468,7 @@ static enum ice_status ice_get_fw_log_cfg(struct ice_hw *hw)
for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++) {
u16 v, m, flgs;

v = le16_to_cpu(config->entry[i]);
v = le16_to_cpu(config[i]);
m = (v & ICE_AQC_FW_LOG_ID_M) >> ICE_AQC_FW_LOG_ID_S;
flgs = (v & ICE_AQC_FW_LOG_EN_M) >> ICE_AQC_FW_LOG_EN_S;

Expand Down Expand Up @@ -526,11 +520,11 @@ static enum ice_status ice_get_fw_log_cfg(struct ice_hw *hw)
*/
static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
{
struct ice_aqc_fw_logging_data *data = NULL;
struct ice_aqc_fw_logging *cmd;
enum ice_status status = 0;
u16 i, chgs = 0, len = 0;
struct ice_aq_desc desc;
__le16 *data = NULL;
u8 actv_evnts = 0;
void *buf = NULL;

Expand Down Expand Up @@ -571,16 +565,17 @@ static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
continue;

if (!data) {
data = devm_kzalloc(ice_hw_to_dev(hw),
ICE_FW_LOG_DESC_SIZE_MAX,
data = devm_kcalloc(ice_hw_to_dev(hw),
sizeof(*data),
ICE_AQC_FW_LOG_ID_MAX,
GFP_KERNEL);
if (!data)
return ICE_ERR_NO_MEMORY;
}

val = i << ICE_AQC_FW_LOG_ID_S;
val |= hw->fw_log.evnts[i].cfg << ICE_AQC_FW_LOG_EN_S;
data->entry[chgs++] = cpu_to_le16(val);
data[chgs++] = cpu_to_le16(val);
}

/* Only enable FW logging if at least one module is specified.
Expand All @@ -599,7 +594,7 @@ static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
cmd->log_ctrl |= ICE_AQC_FW_LOG_UART_EN;

buf = data;
len = ICE_FW_LOG_DESC_SIZE(chgs);
len = sizeof(*data) * chgs;
desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
}
}
Expand Down Expand Up @@ -629,7 +624,7 @@ static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
continue;
}

v = le16_to_cpu(data->entry[i]);
v = le16_to_cpu(data[i]);
m = (v & ICE_AQC_FW_LOG_ID_M) >> ICE_AQC_FW_LOG_ID_S;
hw->fw_log.evnts[m].cur = hw->fw_log.evnts[m].cfg;
}
Expand Down Expand Up @@ -3690,14 +3685,14 @@ ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
*/
enum ice_status
ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
struct ice_aqc_get_elem *buf)
struct ice_aqc_txsched_elem_data *buf)
{
u16 buf_size, num_elem_ret = 0;
enum ice_status status;

buf_size = sizeof(*buf);
memset(buf, 0, buf_size);
buf->generic[0].node_teid = cpu_to_le32(node_teid);
buf->node_teid = cpu_to_le32(node_teid);
status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
NULL);
if (status || num_elem_ret != 1)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/intel/ice/ice_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
u64 *prev_stat, u64 *cur_stat);
enum ice_status
ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
struct ice_aqc_get_elem *buf);
struct ice_aqc_txsched_elem_data *buf);
#endif /* _ICE_COMMON_H_ */
4 changes: 2 additions & 2 deletions drivers/net/ethernet/intel/ice/ice_dcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
struct ice_aqc_port_ets_elem *buf)
{
struct ice_sched_node *node, *tc_node;
struct ice_aqc_get_elem elem;
struct ice_aqc_txsched_elem_data elem;
enum ice_status status = 0;
u32 teid1, teid2;
u8 i, j;
Expand Down Expand Up @@ -1404,7 +1404,7 @@ ice_update_port_tc_tree_cfg(struct ice_port_info *pi,
/* new TC */
status = ice_sched_query_elem(pi->hw, teid2, &elem);
if (!status)
status = ice_sched_add_node(pi, 1, &elem.generic[0]);
status = ice_sched_add_node(pi, 1, &elem);
if (status)
break;
/* update the TC number */
Expand Down
Loading

0 comments on commit b3c3890

Please sign in to comment.