X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fnet%2Fice%2Fbase%2Fice_sched.c;h=1374b9a0968c900d012a343b0fa5b8ee36fceb75;hb=d58cc74ebd5723f07ada4722e6b82d8cbc0d9ee2;hp=237bf7350f2bd368655686618d1d4b4bc05875a7;hpb=6f59fc0f867514e56eb44f31b4880940a6dd86ee;p=dpdk.git diff --git a/drivers/net/ice/base/ice_sched.c b/drivers/net/ice/base/ice_sched.c index 237bf7350f..1374b9a096 100644 --- a/drivers/net/ice/base/ice_sched.c +++ b/drivers/net/ice/base/ice_sched.c @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2001-2018 + * Copyright(c) 2001-2020 Intel Corporation */ #include "ice_sched.h" - /** * ice_sched_add_root_node - Insert the Tx scheduler root node in SW DB * @pi: port information structure @@ -131,7 +130,7 @@ ice_aqc_send_sched_elem_cmd(struct ice_hw *hw, enum ice_adminq_opc cmd_opc, */ enum ice_status ice_aq_query_sched_elems(struct ice_hw *hw, u16 elems_req, - struct ice_aqc_get_elem *buf, u16 buf_size, + struct ice_aqc_txsched_elem_data *buf, u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd) { return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_get_sched_elems, @@ -151,8 +150,8 @@ enum ice_status ice_sched_add_node(struct ice_port_info *pi, u8 layer, struct ice_aqc_txsched_elem_data *info) { + struct ice_aqc_txsched_elem_data elem; struct ice_sched_node *parent; - struct ice_aqc_get_elem elem; struct ice_sched_node *node; enum ice_status status; struct ice_hw *hw; @@ -166,13 +165,12 @@ ice_sched_add_node(struct ice_port_info *pi, u8 layer, parent = ice_sched_find_node_by_teid(pi->root, LE32_TO_CPU(info->parent_teid)); if (!parent) { - ice_debug(hw, ICE_DBG_SCHED, - "Parent Node not found for parent_teid=0x%x\n", + ice_debug(hw, ICE_DBG_SCHED, "Parent Node not found for parent_teid=0x%x\n", LE32_TO_CPU(info->parent_teid)); return ICE_ERR_PARAM; } - /* query the current node information from FW before additing it + /* query the current node information from FW before adding it * to the SW DB */ status = ice_sched_query_elem(hw, LE32_TO_CPU(info->node_teid), &elem); @@ -195,7 +193,7 @@ ice_sched_add_node(struct ice_port_info *pi, u8 layer, node->parent = parent; node->tx_sched_layer = layer; parent->children[parent->num_children++] = node; - node->info = elem.generic[0]; + node->info = elem; return ICE_SUCCESS; } @@ -238,7 +236,7 @@ ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent, enum ice_status status; u16 buf_size; - buf_size = sizeof(*buf) + sizeof(u32) * (num_nodes - 1); + buf_size = ice_struct_size(buf, teid, num_nodes); buf = (struct ice_aqc_delete_elem *)ice_malloc(hw, buf_size); if (!buf) return ICE_ERR_NO_MEMORY; @@ -260,33 +258,17 @@ ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent, /** * ice_sched_get_first_node - get the first node of the given layer - * @hw: pointer to the HW struct + * @pi: port information structure * @parent: pointer the base node of the subtree * @layer: layer number * * This function retrieves the first node of the given layer from the subtree */ static struct ice_sched_node * -ice_sched_get_first_node(struct ice_hw *hw, struct ice_sched_node *parent, - u8 layer) +ice_sched_get_first_node(struct ice_port_info *pi, + struct ice_sched_node *parent, u8 layer) { - u8 i; - - if (layer < hw->sw_entry_point_layer) - return NULL; - for (i = 0; i < parent->num_children; i++) { - struct ice_sched_node *node = parent->children[i]; - - if (node) { - if (node->tx_sched_layer == layer) - return node; - /* this recursion is intentional, and wouldn't - * go more than 9 calls - */ - return ice_sched_get_first_node(hw, node, layer); - } - } - return NULL; + return pi->sib_head[parent->tc_num][layer]; } /** @@ -300,7 +282,7 @@ struct ice_sched_node *ice_sched_get_tc_node(struct ice_port_info *pi, u8 tc) { u8 i; - if (!pi) + if (!pi || !pi->root) return NULL; for (i = 0; i < pi->root->num_children; i++) if (pi->root->children[i]->tc_num == tc) @@ -342,7 +324,7 @@ void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node) parent = node->parent; /* root has no parent */ if (parent) { - struct ice_sched_node *p, *tc_node; + struct ice_sched_node *p; /* update the parent */ for (i = 0; i < parent->num_children; i++) @@ -354,16 +336,7 @@ void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node) break; } - /* search for previous sibling that points to this node and - * remove the reference - */ - tc_node = ice_sched_get_tc_node(pi, node->tc_num); - if (!tc_node) { - ice_debug(hw, ICE_DBG_SCHED, - "Invalid TC number %d\n", node->tc_num); - goto err_exit; - } - p = ice_sched_get_first_node(hw, tc_node, node->tx_sched_layer); + p = ice_sched_get_first_node(pi, node, node->tx_sched_layer); while (p) { if (p->sibling == node) { p->sibling = node->sibling; @@ -371,8 +344,13 @@ void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node) } p = p->sibling; } + + /* update the sibling head if head is getting removed */ + if (pi->sib_head[node->tc_num][node->tx_sched_layer] == node) + pi->sib_head[node->tc_num][node->tx_sched_layer] = + node->sibling; } -err_exit: + /* leaf nodes have no children */ if (node->children) ice_free(hw, node->children); @@ -443,7 +421,7 @@ ice_aq_add_sched_elems(struct ice_hw *hw, u16 grps_req, */ static enum ice_status ice_aq_cfg_sched_elems(struct ice_hw *hw, u16 elems_req, - struct ice_aqc_conf_elem *buf, u16 buf_size, + struct ice_aqc_txsched_elem_data *buf, u16 buf_size, u16 *elems_cfgd, struct ice_sq_cd *cd) { return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_cfg_sched_elems, @@ -462,7 +440,7 @@ ice_aq_cfg_sched_elems(struct ice_hw *hw, u16 elems_req, * * Move scheduling elements (0x0408) */ -enum ice_status +static enum ice_status ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req, struct ice_aqc_move_elem *buf, u16 buf_size, u16 *grps_movd, struct ice_sq_cd *cd) @@ -484,8 +462,7 @@ ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req, * Suspend scheduling elements (0x0409) */ static enum ice_status -ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req, - struct ice_aqc_suspend_resume_elem *buf, +ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req, __le32 *buf, u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd) { return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_suspend_sched_elems, @@ -505,8 +482,7 @@ ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req, * resume scheduling elements (0x040A) */ static enum ice_status -ice_aq_resume_sched_elems(struct ice_hw *hw, u16 elems_req, - struct ice_aqc_suspend_resume_elem *buf, +ice_aq_resume_sched_elems(struct ice_hw *hw, u16 elems_req, __le32 *buf, u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd) { return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_resume_sched_elems, @@ -547,18 +523,17 @@ static enum ice_status ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids, bool suspend) { - struct ice_aqc_suspend_resume_elem *buf; u16 i, buf_size, num_elem_ret = 0; enum ice_status status; + __le32 *buf; buf_size = sizeof(*buf) * num_nodes; - buf = (struct ice_aqc_suspend_resume_elem *) - ice_malloc(hw, buf_size); + buf = (__le32 *)ice_malloc(hw, buf_size); if (!buf) return ICE_ERR_NO_MEMORY; for (i = 0; i < num_nodes; i++) - buf->teid[i] = CPU_TO_LE32(node_teids[i]); + buf[i] = CPU_TO_LE32(node_teids[i]); if (suspend) status = ice_aq_suspend_sched_elems(hw, num_nodes, buf, @@ -575,21 +550,63 @@ ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids, return status; } +/** + * ice_alloc_lan_q_ctx - allocate LAN queue contexts for the given VSI and TC + * @hw: pointer to the HW struct + * @vsi_handle: VSI handle + * @tc: TC number + * @new_numqs: number of queues + */ +static enum ice_status +ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs) +{ + struct ice_vsi_ctx *vsi_ctx; + struct ice_q_ctx *q_ctx; + + vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle); + if (!vsi_ctx) + return ICE_ERR_PARAM; + /* allocate LAN queue contexts */ + if (!vsi_ctx->lan_q_ctx[tc]) { + vsi_ctx->lan_q_ctx[tc] = (struct ice_q_ctx *) + ice_calloc(hw, new_numqs, sizeof(*q_ctx)); + if (!vsi_ctx->lan_q_ctx[tc]) + return ICE_ERR_NO_MEMORY; + vsi_ctx->num_lan_q_entries[tc] = new_numqs; + return ICE_SUCCESS; + } + /* num queues are increased, update the queue contexts */ + if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) { + u16 prev_num = vsi_ctx->num_lan_q_entries[tc]; + + q_ctx = (struct ice_q_ctx *) + ice_calloc(hw, new_numqs, sizeof(*q_ctx)); + if (!q_ctx) + return ICE_ERR_NO_MEMORY; + ice_memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc], + prev_num * sizeof(*q_ctx), ICE_DMA_TO_NONDMA); + ice_free(hw, vsi_ctx->lan_q_ctx[tc]); + vsi_ctx->lan_q_ctx[tc] = q_ctx; + vsi_ctx->num_lan_q_entries[tc] = new_numqs; + } + return ICE_SUCCESS; +} + /** * ice_aq_rl_profile - performs a rate limiting task * @hw: pointer to the HW struct - * @opcode:opcode for add, query, or remove profile(s) + * @opcode: opcode for add, query, or remove profile(s) * @num_profiles: the number of profiles * @buf: pointer to buffer * @buf_size: buffer size in bytes * @num_processed: number of processed add or remove profile(s) to return * @cd: pointer to command details structure * - * Rl profile function to add, query, or remove profile(s) + * RL profile function to add, query, or remove profile(s) */ static enum ice_status ice_aq_rl_profile(struct ice_hw *hw, enum ice_adminq_opc opcode, - u16 num_profiles, struct ice_aqc_rl_profile_generic_elem *buf, + u16 num_profiles, struct ice_aqc_rl_profile_elem *buf, u16 buf_size, u16 *num_processed, struct ice_sq_cd *cd) { struct ice_aqc_rl_profile *cmd; @@ -620,13 +637,11 @@ ice_aq_rl_profile(struct ice_hw *hw, enum ice_adminq_opc opcode, */ static enum ice_status ice_aq_add_rl_profile(struct ice_hw *hw, u16 num_profiles, - struct ice_aqc_rl_profile_generic_elem *buf, - u16 buf_size, u16 *num_profiles_added, - struct ice_sq_cd *cd) + struct ice_aqc_rl_profile_elem *buf, u16 buf_size, + u16 *num_profiles_added, struct ice_sq_cd *cd) { - return ice_aq_rl_profile(hw, ice_aqc_opc_add_rl_profiles, - num_profiles, buf, - buf_size, num_profiles_added, cd); + return ice_aq_rl_profile(hw, ice_aqc_opc_add_rl_profiles, num_profiles, + buf, buf_size, num_profiles_added, cd); } /** @@ -641,8 +656,8 @@ ice_aq_add_rl_profile(struct ice_hw *hw, u16 num_profiles, */ enum ice_status ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles, - struct ice_aqc_rl_profile_generic_elem *buf, - u16 buf_size, struct ice_sq_cd *cd) + struct ice_aqc_rl_profile_elem *buf, u16 buf_size, + struct ice_sq_cd *cd) { return ice_aq_rl_profile(hw, ice_aqc_opc_query_rl_profiles, num_profiles, buf, buf_size, NULL, cd); @@ -661,13 +676,46 @@ ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles, */ static enum ice_status ice_aq_remove_rl_profile(struct ice_hw *hw, u16 num_profiles, - struct ice_aqc_rl_profile_generic_elem *buf, - u16 buf_size, u16 *num_profiles_removed, - struct ice_sq_cd *cd) + struct ice_aqc_rl_profile_elem *buf, u16 buf_size, + u16 *num_profiles_removed, struct ice_sq_cd *cd) { return ice_aq_rl_profile(hw, ice_aqc_opc_remove_rl_profiles, - num_profiles, buf, - buf_size, num_profiles_removed, cd); + num_profiles, buf, buf_size, + num_profiles_removed, cd); +} + +/** + * ice_sched_del_rl_profile - remove RL profile + * @hw: pointer to the HW struct + * @rl_info: rate limit profile information + * + * If the profile ID is not referenced anymore, it removes profile ID with + * its associated parameters from HW DB,and locally. The caller needs to + * hold scheduler lock. + */ +static enum ice_status +ice_sched_del_rl_profile(struct ice_hw *hw, + struct ice_aqc_rl_profile_info *rl_info) +{ + struct ice_aqc_rl_profile_elem *buf; + u16 num_profiles_removed; + enum ice_status status; + u16 num_profiles = 1; + + if (rl_info->prof_id_ref != 0) + return ICE_ERR_IN_USE; + + /* Safe to remove profile ID */ + buf = &rl_info->profile; + status = ice_aq_remove_rl_profile(hw, num_profiles, buf, sizeof(*buf), + &num_profiles_removed, NULL); + if (status || num_profiles_removed != num_profiles) + return ICE_ERR_CFG; + + /* Delete stale entry now */ + LIST_DEL(&rl_info->list_entry); + ice_free(hw, rl_info); + return status; } /** @@ -678,7 +726,7 @@ ice_aq_remove_rl_profile(struct ice_hw *hw, u16 num_profiles, */ static void ice_sched_clear_rl_prof(struct ice_port_info *pi) { - u8 ln; + u16 ln; for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) { struct ice_aqc_rl_profile_info *rl_prof_elem; @@ -693,8 +741,7 @@ static void ice_sched_clear_rl_prof(struct ice_port_info *pi) rl_prof_elem->prof_id_ref = 0; status = ice_sched_del_rl_profile(hw, rl_prof_elem); if (status) { - ice_debug(hw, ICE_DBG_SCHED, - "Remove rl profile failed\n"); + ice_debug(hw, ICE_DBG_SCHED, "Remove rl profile failed\n"); /* On error, free mem required */ LIST_DEL(&rl_prof_elem->list_entry); ice_free(hw, rl_prof_elem); @@ -733,7 +780,7 @@ void ice_sched_clear_agg(struct ice_hw *hw) } /** - * ice_sched_clear_tx_topo - clears the schduler tree nodes + * ice_sched_clear_tx_topo - clears the scheduler tree nodes * @pi: port information structure * * This function removes all the nodes from HW as well as from SW DB. @@ -784,8 +831,7 @@ void ice_sched_cleanup_all(struct ice_hw *hw) hw->layer_info = NULL; } - if (hw->port_info) - ice_sched_clear_port(hw->port_info); + ice_sched_clear_port(hw->port_info); hw->num_tx_sched_layers = 0; hw->num_tx_sched_phys_layers = 0; @@ -805,7 +851,7 @@ void ice_sched_cleanup_all(struct ice_hw *hw) */ enum ice_status ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_l2_nodes, - struct ice_aqc_cfg_l2_node_cgd_data *buf, + struct ice_aqc_cfg_l2_node_cgd_elem *buf, u16 buf_size, struct ice_sq_cd *cd) { struct ice_aqc_cfg_l2_node_cgd *cmd; @@ -819,7 +865,6 @@ ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_l2_nodes, return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd); } - /** * ice_sched_add_elems - add nodes to HW and SW DB * @pi: port information structure @@ -845,7 +890,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node, u16 buf_size; u32 teid; - buf_size = sizeof(*buf) + sizeof(*buf->generic) * (num_nodes - 1); + buf_size = ice_struct_size(buf, generic, num_nodes); buf = (struct ice_aqc_add_elem *)ice_malloc(hw, buf_size); if (!buf) return ICE_ERR_NO_MEMORY; @@ -883,8 +928,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node, for (i = 0; i < num_nodes; i++) { status = ice_sched_add_node(pi, layer, &buf->generic[i]); if (status != ICE_SUCCESS) { - ice_debug(hw, ICE_DBG_SCHED, - "add nodes in SW DB failed status =%d\n", + ice_debug(hw, ICE_DBG_SCHED, "add nodes in SW DB failed status =%d\n", status); break; } @@ -892,8 +936,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node, teid = LE32_TO_CPU(buf->generic[i].node_teid); new_node = ice_sched_find_node_by_teid(parent, teid); if (!new_node) { - ice_debug(hw, ICE_DBG_SCHED, - "Node is missing for teid =%d\n", teid); + ice_debug(hw, ICE_DBG_SCHED, "Node is missing for teid =%d\n", teid); break; } @@ -902,13 +945,17 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node, /* add it to previous node sibling pointer */ /* Note: siblings are not linked across branches */ - prev = ice_sched_get_first_node(hw, tc_node, layer); + prev = ice_sched_get_first_node(pi, tc_node, layer); if (prev && prev != new_node) { while (prev->sibling) prev = prev->sibling; prev->sibling = new_node; } + /* initialize the sibling head */ + if (!pi->sib_head[tc_node->tc_num][layer]) + pi->sib_head[tc_node->tc_num][layer] = new_node; + if (i == 0) *first_node_teid = teid; } @@ -1172,7 +1219,7 @@ enum ice_status ice_sched_init_port(struct ice_port_info *pi) goto err_init_port; } - /* If the last node is a leaf node then the index of the Q group + /* If the last node is a leaf node then the index of the queue group * layer is two less than the number of elements. */ if (num_elems > 2 && buf[0].generic[num_elems - 1].data.elem_type == @@ -1246,8 +1293,7 @@ struct ice_sched_node *ice_sched_get_node(struct ice_port_info *pi, u32 teid) ice_release_lock(&pi->sched_lock); if (!node) - ice_debug(pi->hw, ICE_DBG_SCHED, - "Node not found for teid=0x%x\n", teid); + ice_debug(pi->hw, ICE_DBG_SCHED, "Node not found for teid=0x%x\n", teid); return node; } @@ -1305,12 +1351,51 @@ enum ice_status ice_sched_query_res_alloc(struct ice_hw *hw) goto sched_query_out; } - sched_query_out: ice_free(hw, buf); return status; } +/** + * ice_sched_get_psm_clk_freq - determine the PSM clock frequency + * @hw: pointer to the HW struct + * + * Determine the PSM clock frequency and store in HW struct + */ +void ice_sched_get_psm_clk_freq(struct ice_hw *hw) +{ + u32 val, clk_src; + + val = rd32(hw, GLGEN_CLKSTAT_SRC); + clk_src = (val & GLGEN_CLKSTAT_SRC_PSM_CLK_SRC_M) >> + GLGEN_CLKSTAT_SRC_PSM_CLK_SRC_S; + +#define PSM_CLK_SRC_367_MHZ 0x0 +#define PSM_CLK_SRC_416_MHZ 0x1 +#define PSM_CLK_SRC_446_MHZ 0x2 +#define PSM_CLK_SRC_390_MHZ 0x3 + + switch (clk_src) { + case PSM_CLK_SRC_367_MHZ: + hw->psm_clk_freq = ICE_PSM_CLK_367MHZ_IN_HZ; + break; + case PSM_CLK_SRC_416_MHZ: + hw->psm_clk_freq = ICE_PSM_CLK_416MHZ_IN_HZ; + break; + case PSM_CLK_SRC_446_MHZ: + hw->psm_clk_freq = ICE_PSM_CLK_446MHZ_IN_HZ; + break; + case PSM_CLK_SRC_390_MHZ: + hw->psm_clk_freq = ICE_PSM_CLK_390MHZ_IN_HZ; + break; + default: + ice_debug(hw, ICE_DBG_SCHED, "PSM clk_src unexpected %u\n", + clk_src); + /* fall back to a safe default */ + hw->psm_clk_freq = ICE_PSM_CLK_446MHZ_IN_HZ; + } +} + /** * ice_sched_find_node_in_subtree - Find node in part of base node subtree * @hw: pointer to the HW struct @@ -1344,6 +1429,53 @@ ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base, return false; } +/** + * ice_sched_get_free_qgrp - Scan all queue group siblings and find a free node + * @pi: port information structure + * @vsi_node: software VSI handle + * @qgrp_node: first queue group node identified for scanning + * @owner: LAN or RDMA + * + * This function retrieves a free LAN or RDMA queue group node by scanning + * qgrp_node and its siblings for the queue group with the fewest number + * of queues currently assigned. + */ +static struct ice_sched_node * +ice_sched_get_free_qgrp(struct ice_port_info *pi, + struct ice_sched_node *vsi_node, + struct ice_sched_node *qgrp_node, u8 owner) +{ + struct ice_sched_node *min_qgrp; + u8 min_children; + + if (!qgrp_node) + return qgrp_node; + min_children = qgrp_node->num_children; + if (!min_children) + return qgrp_node; + min_qgrp = qgrp_node; + /* scan all queue groups until find a node which has less than the + * minimum number of children. This way all queue group nodes get + * equal number of shares and active. The bandwidth will be equally + * distributed across all queues. + */ + while (qgrp_node) { + /* make sure the qgroup node is part of the VSI subtree */ + if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node)) + if (qgrp_node->num_children < min_children && + qgrp_node->owner == owner) { + /* replace the new min queue group node */ + min_qgrp = qgrp_node; + min_children = min_qgrp->num_children; + /* break if it has no children, */ + if (!min_children) + break; + } + qgrp_node = qgrp_node->sibling; + } + return min_qgrp; +} + /** * ice_sched_get_free_qparent - Get a free LAN or RDMA queue group node * @pi: port information structure @@ -1357,7 +1489,7 @@ struct ice_sched_node * ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 owner) { - struct ice_sched_node *vsi_node, *qgrp_node = NULL; + struct ice_sched_node *vsi_node, *qgrp_node; struct ice_vsi_ctx *vsi_ctx; u16 max_children; u8 qgrp_layer; @@ -1371,10 +1503,10 @@ ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc, vsi_node = vsi_ctx->sched.vsi_node[tc]; /* validate invalid VSI ID */ if (!vsi_node) - goto lan_q_exit; + return NULL; /* get the first queue group node from VSI sub-tree */ - qgrp_node = ice_sched_get_first_node(pi->hw, vsi_node, qgrp_layer); + qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer); while (qgrp_node) { /* make sure the qgroup node is part of the VSI subtree */ if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node)) @@ -1384,13 +1516,13 @@ ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc, qgrp_node = qgrp_node->sibling; } -lan_q_exit: - return qgrp_node; + /* Select the best queue group */ + return ice_sched_get_free_qgrp(pi, vsi_node, qgrp_node, owner); } /** * ice_sched_get_vsi_node - Get a VSI node based on VSI ID - * @hw: pointer to the HW struct + * @pi: pointer to the port information structure * @tc_node: pointer to the TC node * @vsi_handle: software VSI handle * @@ -1398,14 +1530,14 @@ lan_q_exit: * TC branch */ struct ice_sched_node * -ice_sched_get_vsi_node(struct ice_hw *hw, struct ice_sched_node *tc_node, +ice_sched_get_vsi_node(struct ice_port_info *pi, struct ice_sched_node *tc_node, u16 vsi_handle) { struct ice_sched_node *node; u8 vsi_layer; - vsi_layer = ice_sched_get_vsi_layer(hw); - node = ice_sched_get_first_node(hw, tc_node, vsi_layer); + vsi_layer = ice_sched_get_vsi_layer(pi->hw); + node = ice_sched_get_first_node(pi, tc_node, vsi_layer); /* Check whether it already exists */ while (node) { @@ -1419,22 +1551,25 @@ ice_sched_get_vsi_node(struct ice_hw *hw, struct ice_sched_node *tc_node, /** * ice_sched_get_agg_node - Get an aggregator node based on aggregator ID - * @hw: pointer to the HW struct + * @pi: pointer to the port information structure * @tc_node: pointer to the TC node * @agg_id: aggregator ID * * This function retrieves an aggregator node for a given aggregator ID from * a given TC branch */ -struct ice_sched_node * -ice_sched_get_agg_node(struct ice_hw *hw, struct ice_sched_node *tc_node, +static struct ice_sched_node * +ice_sched_get_agg_node(struct ice_port_info *pi, struct ice_sched_node *tc_node, u32 agg_id) { struct ice_sched_node *node; + struct ice_hw *hw = pi->hw; u8 agg_layer; + if (!hw) + return NULL; agg_layer = ice_sched_get_agg_layer(hw); - node = ice_sched_get_first_node(hw, tc_node, agg_layer); + node = ice_sched_get_first_node(pi, tc_node, agg_layer); /* Check whether it already exists */ while (node) { @@ -1455,7 +1590,7 @@ ice_sched_get_agg_node(struct ice_hw *hw, struct ice_sched_node *tc_node, */ static bool ice_sched_check_node(struct ice_hw *hw, struct ice_sched_node *node) { - struct ice_aqc_get_elem buf; + struct ice_aqc_txsched_elem_data buf; enum ice_status status; u32 node_teid; @@ -1464,7 +1599,7 @@ static bool ice_sched_check_node(struct ice_hw *hw, struct ice_sched_node *node) if (status != ICE_SUCCESS) return false; - if (memcmp(buf.generic, &node->info, sizeof(*buf.generic))) { + if (memcmp(&buf, &node->info, sizeof(buf))) { ice_debug(hw, ICE_DBG_SCHED, "Node mismatch for teid=0x%x\n", node_teid); return false; @@ -1526,7 +1661,7 @@ ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle, qgl = ice_sched_get_qgrp_layer(hw); vsil = ice_sched_get_vsi_layer(hw); - parent = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); + parent = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); for (i = vsil + 1; i <= qgl; i++) { if (!parent) return ICE_ERR_CFG; @@ -1559,7 +1694,7 @@ ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle, /** * ice_sched_calc_vsi_support_nodes - calculate number of VSI support nodes - * @hw: pointer to the HW struct + * @pi: pointer to the port info structure * @tc_node: pointer to TC node * @num_nodes: pointer to num nodes array * @@ -1568,15 +1703,15 @@ ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle, * layers */ static void -ice_sched_calc_vsi_support_nodes(struct ice_hw *hw, +ice_sched_calc_vsi_support_nodes(struct ice_port_info *pi, struct ice_sched_node *tc_node, u16 *num_nodes) { struct ice_sched_node *node; u8 vsil; int i; - vsil = ice_sched_get_vsi_layer(hw); - for (i = vsil; i >= hw->sw_entry_point_layer; i--) + vsil = ice_sched_get_vsi_layer(pi->hw); + for (i = vsil; i >= pi->hw->sw_entry_point_layer; i--) /* Add intermediate nodes if TC has no children and * need at least one node for VSI */ @@ -1586,10 +1721,11 @@ ice_sched_calc_vsi_support_nodes(struct ice_hw *hw, /* If intermediate nodes are reached max children * then add a new one. */ - node = ice_sched_get_first_node(hw, tc_node, (u8)i); + node = ice_sched_get_first_node(pi, tc_node, (u8)i); /* scan all the siblings */ while (node) { - if (node->num_children < hw->max_children[i]) + if (node->num_children < + pi->hw->max_children[i]) break; node = node->sibling; } @@ -1669,14 +1805,13 @@ ice_sched_add_vsi_to_topo(struct ice_port_info *pi, u16 vsi_handle, u8 tc) { u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; struct ice_sched_node *tc_node; - struct ice_hw *hw = pi->hw; tc_node = ice_sched_get_tc_node(pi, tc); if (!tc_node) return ICE_ERR_PARAM; /* calculate number of supported nodes needed for this VSI */ - ice_sched_calc_vsi_support_nodes(hw, tc_node, num_nodes); + ice_sched_calc_vsi_support_nodes(pi, tc_node, num_nodes); /* add VSI supported nodes to TC subtree */ return ice_sched_add_vsi_support_nodes(pi, vsi_handle, tc_node, @@ -1709,7 +1844,7 @@ ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle, if (!tc_node) return ICE_ERR_CFG; - vsi_node = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); if (!vsi_node) return ICE_ERR_CFG; @@ -1717,14 +1852,14 @@ ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle, if (!vsi_ctx) return ICE_ERR_PARAM; - if (owner == ICE_SCHED_NODE_OWNER_LAN) - prev_numqs = vsi_ctx->sched.max_lanq[tc]; - else - return ICE_ERR_PARAM; - + prev_numqs = vsi_ctx->sched.max_lanq[tc]; /* num queues are not changed or less than the previous number */ if (new_numqs <= prev_numqs) return status; + status = ice_alloc_lan_q_ctx(hw, vsi_handle, tc, new_numqs); + if (status) + return status; + if (new_numqs) ice_sched_calc_vsi_child_nodes(hw, new_numqs, new_num_nodes); /* Keep the max number of queue configuration all the time. Update the @@ -1772,7 +1907,7 @@ ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs, vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle); if (!vsi_ctx) return ICE_ERR_PARAM; - vsi_node = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); /* suspend the VSI if TC is not enabled */ if (!enable) { @@ -1793,7 +1928,7 @@ ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs, if (status) return status; - vsi_node = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); if (!vsi_node) return ICE_ERR_CFG; @@ -1832,8 +1967,7 @@ ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs, * This function removes single aggregator VSI info entry from * aggregator list. */ -static void -ice_sched_rm_agg_vsi_info(struct ice_port_info *pi, u16 vsi_handle) +static void ice_sched_rm_agg_vsi_info(struct ice_port_info *pi, u16 vsi_handle) { struct ice_sched_agg_info *agg_info; struct ice_sched_agg_info *atmp; @@ -1904,13 +2038,12 @@ ice_sched_rm_vsi_cfg(struct ice_port_info *pi, u16 vsi_handle, u8 owner) if (!tc_node) continue; - vsi_node = ice_sched_get_vsi_node(pi->hw, tc_node, vsi_handle); + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); if (!vsi_node) continue; if (ice_sched_is_leaf_node_present(vsi_node)) { - ice_debug(pi->hw, ICE_DBG_SCHED, - "VSI has leaf nodes in TC %d\n", i); + ice_debug(pi->hw, ICE_DBG_SCHED, "VSI has leaf nodes in TC %d\n", i); status = ICE_ERR_IN_USE; goto exit_sched_rm_vsi_cfg; } @@ -1957,7 +2090,6 @@ enum ice_status ice_rm_vsi_lan_cfg(struct ice_port_info *pi, u16 vsi_handle) return ice_sched_rm_vsi_cfg(pi, vsi_handle, ICE_SCHED_NODE_OWNER_LAN); } - /** * ice_sched_is_tree_balanced - Check tree nodes are identical or not * @hw: pointer to the HW struct @@ -1995,7 +2127,7 @@ bool ice_sched_is_tree_balanced(struct ice_hw *hw, struct ice_sched_node *node) */ enum ice_status ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid, - struct ice_aqc_get_elem *buf, u16 buf_size, + struct ice_aqc_txsched_elem_data *buf, u16 buf_size, struct ice_sq_cd *cd) { struct ice_aqc_query_node_to_root *cmd; @@ -2015,7 +2147,7 @@ ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid, * This function validates aggregator ID. The function returns info if * aggregator ID is present in list otherwise it returns null. */ -static struct ice_sched_agg_info* +static struct ice_sched_agg_info * ice_get_agg_info(struct ice_hw *hw, u32 agg_id) { struct ice_sched_agg_info *agg_info; @@ -2029,2949 +2161,2962 @@ ice_get_agg_info(struct ice_hw *hw, u32 agg_id) } /** - * ice_move_all_vsi_to_dflt_agg - move all VSI(s) to default aggregator - * @pi: port information structure - * @agg_info: aggregator info - * @tc: traffic class number - * @rm_vsi_info: true or false + * ice_sched_get_free_vsi_parent - Find a free parent node in aggregator subtree + * @hw: pointer to the HW struct + * @node: pointer to a child node + * @num_nodes: num nodes count array * - * This function move all the VSI(s) to the default aggregator and delete - * aggregator VSI info based on passed in boolean parameter rm_vsi_info. The - * caller holds the scheduler lock. + * This function walks through the aggregator subtree to find a free parent + * node */ -static enum ice_status -ice_move_all_vsi_to_dflt_agg(struct ice_port_info *pi, - struct ice_sched_agg_info *agg_info, u8 tc, - bool rm_vsi_info) +static struct ice_sched_node * +ice_sched_get_free_vsi_parent(struct ice_hw *hw, struct ice_sched_node *node, + u16 *num_nodes) { - struct ice_sched_agg_vsi_info *agg_vsi_info; - struct ice_sched_agg_vsi_info *tmp; - enum ice_status status = ICE_SUCCESS; + u8 l = node->tx_sched_layer; + u8 vsil, i; - LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, tmp, &agg_info->agg_vsi_list, - ice_sched_agg_vsi_info, list_entry) { - u16 vsi_handle = agg_vsi_info->vsi_handle; + vsil = ice_sched_get_vsi_layer(hw); - /* Move VSI to default aggregator */ - if (!ice_is_tc_ena(agg_vsi_info->tc_bitmap[0], tc)) - continue; + /* Is it VSI parent layer ? */ + if (l == vsil - 1) + return (node->num_children < hw->max_children[l]) ? node : NULL; - status = ice_sched_move_vsi_to_agg(pi, vsi_handle, - ICE_DFLT_AGG_ID, tc); - if (status) - break; + /* We have intermediate nodes. Let's walk through the subtree. If the + * intermediate node has space to add a new node then clear the count + */ + if (node->num_children < hw->max_children[l]) + num_nodes[l] = 0; + /* The below recursive call is intentional and wouldn't go more than + * 2 or 3 iterations. + */ - ice_clear_bit(tc, agg_vsi_info->tc_bitmap); - if (rm_vsi_info && !agg_vsi_info->tc_bitmap[0]) { - LIST_DEL(&agg_vsi_info->list_entry); - ice_free(pi->hw, agg_vsi_info); - } + for (i = 0; i < node->num_children; i++) { + struct ice_sched_node *parent; + + parent = ice_sched_get_free_vsi_parent(hw, node->children[i], + num_nodes); + if (parent) + return parent; } - return status; + return NULL; } /** - * ice_rm_agg_cfg_tc - remove aggregator configuration for TC - * @pi: port information structure - * @agg_info: aggregator ID - * @tc: TC number - * @rm_vsi_info: bool value true or false + * ice_sched_update_parent - update the new parent in SW DB + * @new_parent: pointer to a new parent node + * @node: pointer to a child node * - * This function removes aggregator reference to VSI of given TC. It removes - * the aggregator configuration completely for requested TC. The caller needs - * to hold the scheduler lock. + * This function removes the child from the old parent and adds it to a new + * parent */ -static enum ice_status -ice_rm_agg_cfg_tc(struct ice_port_info *pi, struct ice_sched_agg_info *agg_info, - u8 tc, bool rm_vsi_info) +static void +ice_sched_update_parent(struct ice_sched_node *new_parent, + struct ice_sched_node *node) { - enum ice_status status = ICE_SUCCESS; - - /* If nothing to remove - return success */ - if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) - goto exit_rm_agg_cfg_tc; + struct ice_sched_node *old_parent; + u8 i, j; - status = ice_move_all_vsi_to_dflt_agg(pi, agg_info, tc, rm_vsi_info); - if (status) - goto exit_rm_agg_cfg_tc; + old_parent = node->parent; - /* Delete aggregator node(s) */ - status = ice_sched_rm_agg_cfg(pi, agg_info->agg_id, tc); - if (status) - goto exit_rm_agg_cfg_tc; + /* update the old parent children */ + for (i = 0; i < old_parent->num_children; i++) + if (old_parent->children[i] == node) { + for (j = i + 1; j < old_parent->num_children; j++) + old_parent->children[j - 1] = + old_parent->children[j]; + old_parent->num_children--; + break; + } - ice_clear_bit(tc, agg_info->tc_bitmap); -exit_rm_agg_cfg_tc: - return status; + /* now move the node to a new parent */ + new_parent->children[new_parent->num_children++] = node; + node->parent = new_parent; + node->info.parent_teid = new_parent->info.node_teid; } /** - * ice_save_agg_tc_bitmap - save aggregator TC bitmap + * ice_sched_move_nodes - move child nodes to a given parent * @pi: port information structure - * @agg_id: aggregator ID - * @tc_bitmap: 8 bits TC bitmap + * @parent: pointer to parent node + * @num_items: number of child nodes to be moved + * @list: pointer to child node teids * - * Save aggregator TC bitmap. This function needs to be called with scheduler - * lock held. + * This function move the child nodes to a given parent. */ static enum ice_status -ice_save_agg_tc_bitmap(struct ice_port_info *pi, u32 agg_id, - ice_bitmap_t *tc_bitmap) +ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent, + u16 num_items, u32 *list) { - struct ice_sched_agg_info *agg_info; + enum ice_status status = ICE_SUCCESS; + struct ice_aqc_move_elem *buf; + struct ice_sched_node *node; + u16 i, grps_movd = 0; + struct ice_hw *hw; + u16 buf_len; - agg_info = ice_get_agg_info(pi->hw, agg_id); - if (!agg_info) - return ICE_ERR_PARAM; - ice_cp_bitmap(agg_info->replay_tc_bitmap, tc_bitmap, - ICE_MAX_TRAFFIC_CLASS); - return ICE_SUCCESS; -} + hw = pi->hw; -/** - * ice_sched_cfg_agg - configure aggregator node - * @pi: port information structure - * @agg_id: aggregator ID - * @agg_type: aggregator type queue, VSI, or aggregator group - * @tc_bitmap: bits TC bitmap - * - * It registers a unique aggregator node into scheduler services. It - * allows a user to register with a unique ID to track it's resources. - * The aggregator type determines if this is a queue group, VSI group - * or aggregator group. It then creates the aggregator node(s) for requested - * TC(s) or removes an existing aggregator node including its configuration - * if indicated via tc_bitmap. Call ice_rm_agg_cfg to release aggregator - * resources and remove aggregator ID. - * This function needs to be called with scheduler lock held. - */ -static enum ice_status -ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id, - enum ice_agg_type agg_type, ice_bitmap_t *tc_bitmap) -{ - struct ice_sched_agg_info *agg_info; - enum ice_status status = ICE_SUCCESS; - struct ice_hw *hw = pi->hw; - u8 tc; + if (!parent || !num_items) + return ICE_ERR_PARAM; - agg_info = ice_get_agg_info(hw, agg_id); - if (!agg_info) { - /* Create new entry for new aggregator ID */ - agg_info = (struct ice_sched_agg_info *) - ice_malloc(hw, sizeof(*agg_info)); - if (!agg_info) { - status = ICE_ERR_NO_MEMORY; - goto exit_reg_agg; - } - agg_info->agg_id = agg_id; - agg_info->agg_type = agg_type; - agg_info->tc_bitmap[0] = 0; + /* Does parent have enough space */ + if (parent->num_children + num_items > + hw->max_children[parent->tx_sched_layer]) + return ICE_ERR_AQ_FULL; - /* Initialize the aggregator VSI list head */ - INIT_LIST_HEAD(&agg_info->agg_vsi_list); + buf_len = ice_struct_size(buf, teid, 1); + buf = (struct ice_aqc_move_elem *)ice_malloc(hw, buf_len); + if (!buf) + return ICE_ERR_NO_MEMORY; - /* Add new entry in aggregator list */ - LIST_ADD(&agg_info->list_entry, &hw->agg_list); - } - /* Create aggregator node(s) for requested TC(s) */ - ice_for_each_traffic_class(tc) { - if (!ice_is_tc_ena(*tc_bitmap, tc)) { - /* Delete aggregator cfg TC if it exists previously */ - status = ice_rm_agg_cfg_tc(pi, agg_info, tc, false); - if (status) - break; - continue; + for (i = 0; i < num_items; i++) { + node = ice_sched_find_node_by_teid(pi->root, list[i]); + if (!node) { + status = ICE_ERR_PARAM; + goto move_err_exit; } - /* Check if aggregator node for TC already exists */ - if (ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) - continue; - - /* Create new aggregator node for TC */ - status = ice_sched_add_agg_cfg(pi, agg_id, tc); - if (status) - break; + buf->hdr.src_parent_teid = node->info.parent_teid; + buf->hdr.dest_parent_teid = parent->info.node_teid; + buf->teid[0] = node->info.node_teid; + buf->hdr.num_elems = CPU_TO_LE16(1); + status = ice_aq_move_sched_elems(hw, 1, buf, buf_len, + &grps_movd, NULL); + if (status && grps_movd != 1) { + status = ICE_ERR_CFG; + goto move_err_exit; + } - /* Save aggregator node's TC information */ - ice_set_bit(tc, agg_info->tc_bitmap); + /* update the SW DB */ + ice_sched_update_parent(parent, node); } -exit_reg_agg: + +move_err_exit: + ice_free(hw, buf); return status; } /** - * ice_cfg_agg - config aggregator node + * ice_sched_move_vsi_to_agg - move VSI to aggregator node * @pi: port information structure + * @vsi_handle: software VSI handle * @agg_id: aggregator ID - * @agg_type: aggregator type queue, VSI, or aggregator group - * @tc_bitmap: bits TC bitmap + * @tc: TC number * - * This function configures aggregator node(s). + * This function moves a VSI to an aggregator node or its subtree. + * Intermediate nodes may be created if required. */ -enum ice_status -ice_cfg_agg(struct ice_port_info *pi, u32 agg_id, enum ice_agg_type agg_type, - u8 tc_bitmap) +static enum ice_status +ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id, + u8 tc) { - ice_bitmap_t bitmap = tc_bitmap; + struct ice_sched_node *vsi_node, *agg_node, *tc_node, *parent; + u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; + u32 first_node_teid, vsi_teid; enum ice_status status; + u16 num_nodes_added; + u8 aggl, vsil, i; - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_cfg_agg(pi, agg_id, agg_type, - (ice_bitmap_t *)&bitmap); - if (!status) - status = ice_save_agg_tc_bitmap(pi, agg_id, - (ice_bitmap_t *)&bitmap); - ice_release_lock(&pi->sched_lock); - return status; + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + return ICE_ERR_CFG; + + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + return ICE_ERR_DOES_NOT_EXIST; + + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); + if (!vsi_node) + return ICE_ERR_DOES_NOT_EXIST; + + /* Is this VSI already part of given aggregator? */ + if (ice_sched_find_node_in_subtree(pi->hw, agg_node, vsi_node)) + return ICE_SUCCESS; + + aggl = ice_sched_get_agg_layer(pi->hw); + vsil = ice_sched_get_vsi_layer(pi->hw); + + /* set intermediate node count to 1 between aggregator and VSI layers */ + for (i = aggl + 1; i < vsil; i++) + num_nodes[i] = 1; + + /* Check if the aggregator subtree has any free node to add the VSI */ + for (i = 0; i < agg_node->num_children; i++) { + parent = ice_sched_get_free_vsi_parent(pi->hw, + agg_node->children[i], + num_nodes); + if (parent) + goto move_nodes; + } + + /* add new nodes */ + parent = agg_node; + for (i = aggl + 1; i < vsil; i++) { + status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i, + num_nodes[i], + &first_node_teid, + &num_nodes_added); + if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added) + return ICE_ERR_CFG; + + /* The newly added node can be a new parent for the next + * layer nodes + */ + if (num_nodes_added) + parent = ice_sched_find_node_by_teid(tc_node, + first_node_teid); + else + parent = parent->children[0]; + + if (!parent) + return ICE_ERR_CFG; + } + +move_nodes: + vsi_teid = LE32_TO_CPU(vsi_node->info.node_teid); + return ice_sched_move_nodes(pi, parent, 1, &vsi_teid); } /** - * ice_get_agg_vsi_info - get the aggregator ID + * ice_move_all_vsi_to_dflt_agg - move all VSI(s) to default aggregator + * @pi: port information structure * @agg_info: aggregator info - * @vsi_handle: software VSI handle + * @tc: traffic class number + * @rm_vsi_info: true or false * - * The function returns aggregator VSI info based on VSI handle. This function - * needs to be called with scheduler lock held. + * This function move all the VSI(s) to the default aggregator and delete + * aggregator VSI info based on passed in boolean parameter rm_vsi_info. The + * caller holds the scheduler lock. */ -static struct ice_sched_agg_vsi_info* -ice_get_agg_vsi_info(struct ice_sched_agg_info *agg_info, u16 vsi_handle) +static enum ice_status +ice_move_all_vsi_to_dflt_agg(struct ice_port_info *pi, + struct ice_sched_agg_info *agg_info, u8 tc, + bool rm_vsi_info) { struct ice_sched_agg_vsi_info *agg_vsi_info; + struct ice_sched_agg_vsi_info *tmp; + enum ice_status status = ICE_SUCCESS; - LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list, - ice_sched_agg_vsi_info, list_entry) - if (agg_vsi_info->vsi_handle == vsi_handle) - return agg_vsi_info; + LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, tmp, &agg_info->agg_vsi_list, + ice_sched_agg_vsi_info, list_entry) { + u16 vsi_handle = agg_vsi_info->vsi_handle; - return NULL; + /* Move VSI to default aggregator */ + if (!ice_is_tc_ena(agg_vsi_info->tc_bitmap[0], tc)) + continue; + + status = ice_sched_move_vsi_to_agg(pi, vsi_handle, + ICE_DFLT_AGG_ID, tc); + if (status) + break; + + ice_clear_bit(tc, agg_vsi_info->tc_bitmap); + if (rm_vsi_info && !agg_vsi_info->tc_bitmap[0]) { + LIST_DEL(&agg_vsi_info->list_entry); + ice_free(pi->hw, agg_vsi_info); + } + } + + return status; } /** - * ice_get_vsi_agg_info - get the aggregator info of VSI - * @hw: pointer to the hardware structure - * @vsi_handle: Sw VSI handle + * ice_sched_is_agg_inuse - check whether the aggregator is in use or not + * @pi: port information structure + * @node: node pointer * - * The function returns aggregator info of VSI represented via vsi_handle. The - * VSI has in this case a different aggregator than the default one. This - * function needs to be called with scheduler lock held. + * This function checks whether the aggregator is attached with any VSI or not. */ -static struct ice_sched_agg_info* -ice_get_vsi_agg_info(struct ice_hw *hw, u16 vsi_handle) +static bool +ice_sched_is_agg_inuse(struct ice_port_info *pi, struct ice_sched_node *node) { - struct ice_sched_agg_info *agg_info; - - LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, - list_entry) { - struct ice_sched_agg_vsi_info *agg_vsi_info; + u8 vsil, i; - agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); - if (agg_vsi_info) - return agg_info; + vsil = ice_sched_get_vsi_layer(pi->hw); + if (node->tx_sched_layer < vsil - 1) { + for (i = 0; i < node->num_children; i++) + if (ice_sched_is_agg_inuse(pi, node->children[i])) + return true; + return false; + } else { + return node->num_children ? true : false; } - return NULL; } /** - * ice_save_agg_vsi_tc_bitmap - save aggregator VSI TC bitmap + * ice_sched_rm_agg_cfg - remove the aggregator node * @pi: port information structure * @agg_id: aggregator ID - * @vsi_handle: software VSI handle - * @tc_bitmap: TC bitmap of enabled TC(s) + * @tc: TC number * - * Save VSI to aggregator TC bitmap. This function needs to call with scheduler - * lock held. + * This function removes the aggregator node and intermediate nodes if any + * from the given TC */ static enum ice_status -ice_save_agg_vsi_tc_bitmap(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle, - ice_bitmap_t *tc_bitmap) +ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc) { - struct ice_sched_agg_vsi_info *agg_vsi_info; - struct ice_sched_agg_info *agg_info; + struct ice_sched_node *tc_node, *agg_node; + struct ice_hw *hw = pi->hw; - agg_info = ice_get_agg_info(pi->hw, agg_id); - if (!agg_info) - return ICE_ERR_PARAM; - /* check if entry already exist */ - agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); - if (!agg_vsi_info) - return ICE_ERR_PARAM; - ice_cp_bitmap(agg_vsi_info->replay_tc_bitmap, tc_bitmap, - ICE_MAX_TRAFFIC_CLASS); + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + return ICE_ERR_CFG; + + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + return ICE_ERR_DOES_NOT_EXIST; + + /* Can't remove the aggregator node if it has children */ + if (ice_sched_is_agg_inuse(pi, agg_node)) + return ICE_ERR_IN_USE; + + /* need to remove the whole subtree if aggregator node is the + * only child. + */ + while (agg_node->tx_sched_layer > hw->sw_entry_point_layer) { + struct ice_sched_node *parent = agg_node->parent; + + if (!parent) + return ICE_ERR_CFG; + + if (parent->num_children > 1) + break; + + agg_node = parent; + } + + ice_free_sched_node(pi, agg_node); return ICE_SUCCESS; } /** - * ice_sched_assoc_vsi_to_agg - associate/move VSI to new/default aggregator + * ice_rm_agg_cfg_tc - remove aggregator configuration for TC * @pi: port information structure - * @agg_id: aggregator ID - * @vsi_handle: software VSI handle - * @tc_bitmap: TC bitmap of enabled TC(s) + * @agg_info: aggregator ID + * @tc: TC number + * @rm_vsi_info: bool value true or false * - * This function moves VSI to a new or default aggregator node. If VSI is - * already associated to the aggregator node then no operation is performed on - * the tree. This function needs to be called with scheduler lock held. + * This function removes aggregator reference to VSI of given TC. It removes + * the aggregator configuration completely for requested TC. The caller needs + * to hold the scheduler lock. */ static enum ice_status -ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, - u16 vsi_handle, ice_bitmap_t *tc_bitmap) +ice_rm_agg_cfg_tc(struct ice_port_info *pi, struct ice_sched_agg_info *agg_info, + u8 tc, bool rm_vsi_info) { - struct ice_sched_agg_vsi_info *agg_vsi_info; - struct ice_sched_agg_info *agg_info; enum ice_status status = ICE_SUCCESS; - struct ice_hw *hw = pi->hw; - u8 tc; - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) - return ICE_ERR_PARAM; - agg_info = ice_get_agg_info(hw, agg_id); - if (!agg_info) - return ICE_ERR_PARAM; - /* check if entry already exist */ - agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); - if (!agg_vsi_info) { - /* Create new entry for VSI under aggregator list */ - agg_vsi_info = (struct ice_sched_agg_vsi_info *) - ice_malloc(hw, sizeof(*agg_vsi_info)); - if (!agg_vsi_info) - return ICE_ERR_PARAM; + /* If nothing to remove - return success */ + if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) + goto exit_rm_agg_cfg_tc; - /* add VSI ID into the aggregator list */ - agg_vsi_info->vsi_handle = vsi_handle; - LIST_ADD(&agg_vsi_info->list_entry, &agg_info->agg_vsi_list); - } - /* Move VSI node to new aggregator node for requested TC(s) */ - ice_for_each_traffic_class(tc) { - if (!ice_is_tc_ena(*tc_bitmap, tc)) - continue; + status = ice_move_all_vsi_to_dflt_agg(pi, agg_info, tc, rm_vsi_info); + if (status) + goto exit_rm_agg_cfg_tc; - /* Move VSI to new aggregator */ - status = ice_sched_move_vsi_to_agg(pi, vsi_handle, agg_id, tc); - if (status) - break; + /* Delete aggregator node(s) */ + status = ice_sched_rm_agg_cfg(pi, agg_info->agg_id, tc); + if (status) + goto exit_rm_agg_cfg_tc; - if (agg_id != ICE_DFLT_AGG_ID) - ice_set_bit(tc, agg_vsi_info->tc_bitmap); - else - ice_clear_bit(tc, agg_vsi_info->tc_bitmap); - } - /* If VSI moved back to default aggregator, delete agg_vsi_info. */ - if (!ice_is_any_bit_set(agg_vsi_info->tc_bitmap, - ICE_MAX_TRAFFIC_CLASS)) { - LIST_DEL(&agg_vsi_info->list_entry); - ice_free(hw, agg_vsi_info); - } + ice_clear_bit(tc, agg_info->tc_bitmap); +exit_rm_agg_cfg_tc: return status; } /** - * ice_move_vsi_to_agg - moves VSI to new or default aggregator + * ice_save_agg_tc_bitmap - save aggregator TC bitmap * @pi: port information structure * @agg_id: aggregator ID - * @vsi_handle: software VSI handle - * @tc_bitmap: TC bitmap of enabled TC(s) + * @tc_bitmap: 8 bits TC bitmap * - * Move or associate VSI to a new or default aggregator node. + * Save aggregator TC bitmap. This function needs to be called with scheduler + * lock held. */ -enum ice_status -ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle, - u8 tc_bitmap) +static enum ice_status +ice_save_agg_tc_bitmap(struct ice_port_info *pi, u32 agg_id, + ice_bitmap_t *tc_bitmap) { - ice_bitmap_t bitmap = tc_bitmap; - enum ice_status status; + struct ice_sched_agg_info *agg_info; - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_assoc_vsi_to_agg(pi, agg_id, vsi_handle, - (ice_bitmap_t *)&bitmap); - if (!status) - status = ice_save_agg_vsi_tc_bitmap(pi, agg_id, vsi_handle, - (ice_bitmap_t *)&bitmap); - ice_release_lock(&pi->sched_lock); - return status; + agg_info = ice_get_agg_info(pi->hw, agg_id); + if (!agg_info) + return ICE_ERR_PARAM; + ice_cp_bitmap(agg_info->replay_tc_bitmap, tc_bitmap, + ICE_MAX_TRAFFIC_CLASS); + return ICE_SUCCESS; } /** - * ice_rm_agg_cfg - remove aggregator configuration + * ice_sched_add_agg_cfg - create an aggregator node * @pi: port information structure * @agg_id: aggregator ID + * @tc: TC number * - * This function removes aggregator reference to VSI and delete aggregator ID - * info. It removes the aggregator configuration completely. + * This function creates an aggregator node and intermediate nodes if required + * for the given TC */ -enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id) +static enum ice_status +ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc) { - struct ice_sched_agg_info *agg_info; + struct ice_sched_node *parent, *agg_node, *tc_node; + u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; enum ice_status status = ICE_SUCCESS; - u8 tc; + struct ice_hw *hw = pi->hw; + u32 first_node_teid; + u16 num_nodes_added; + u8 i, aggl; - ice_acquire_lock(&pi->sched_lock); - agg_info = ice_get_agg_info(pi->hw, agg_id); - if (!agg_info) { - status = ICE_ERR_DOES_NOT_EXIST; - goto exit_ice_rm_agg_cfg; - } + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + return ICE_ERR_CFG; - ice_for_each_traffic_class(tc) { - status = ice_rm_agg_cfg_tc(pi, agg_info, tc, true); - if (status) - goto exit_ice_rm_agg_cfg; - } + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + /* Does Agg node already exist ? */ + if (agg_node) + return status; - if (ice_is_any_bit_set(agg_info->tc_bitmap, ICE_MAX_TRAFFIC_CLASS)) { - status = ICE_ERR_IN_USE; - goto exit_ice_rm_agg_cfg; + aggl = ice_sched_get_agg_layer(hw); + + /* need one node in Agg layer */ + num_nodes[aggl] = 1; + + /* Check whether the intermediate nodes have space to add the + * new aggregator. If they are full, then SW needs to allocate a new + * intermediate node on those layers + */ + for (i = hw->sw_entry_point_layer; i < aggl; i++) { + parent = ice_sched_get_first_node(pi, tc_node, i); + + /* scan all the siblings */ + while (parent) { + if (parent->num_children < hw->max_children[i]) + break; + parent = parent->sibling; + } + + /* all the nodes are full, reserve one for this layer */ + if (!parent) + num_nodes[i]++; } - /* Safe to delete entry now */ - LIST_DEL(&agg_info->list_entry); - ice_free(pi->hw, agg_info); + /* add the aggregator node */ + parent = tc_node; + for (i = hw->sw_entry_point_layer; i <= aggl; i++) { + if (!parent) + return ICE_ERR_CFG; - /* Remove unused RL profile IDs from HW and SW DB */ - ice_sched_rm_unused_rl_prof(pi); + status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i, + num_nodes[i], + &first_node_teid, + &num_nodes_added); + if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added) + return ICE_ERR_CFG; -exit_ice_rm_agg_cfg: - ice_release_lock(&pi->sched_lock); - return status; + /* The newly added node can be a new parent for the next + * layer nodes + */ + if (num_nodes_added) { + parent = ice_sched_find_node_by_teid(tc_node, + first_node_teid); + /* register aggregator ID with the aggregator node */ + if (parent && i == aggl) + parent->agg_id = agg_id; + } else { + parent = parent->children[0]; + } + } + + return ICE_SUCCESS; } /** - * ice_set_clear_cir_bw_alloc - set or clear CIR BW alloc information - * @bw_t_info: bandwidth type information structure - * @bw_alloc: Bandwidth allocation information + * ice_sched_cfg_agg - configure aggregator node + * @pi: port information structure + * @agg_id: aggregator ID + * @agg_type: aggregator type queue, VSI, or aggregator group + * @tc_bitmap: bits TC bitmap * - * Save or clear CIR BW alloc information (bw_alloc) in the passed param - * bw_t_info. + * It registers a unique aggregator node into scheduler services. It + * allows a user to register with a unique ID to track it's resources. + * The aggregator type determines if this is a queue group, VSI group + * or aggregator group. It then creates the aggregator node(s) for requested + * TC(s) or removes an existing aggregator node including its configuration + * if indicated via tc_bitmap. Call ice_rm_agg_cfg to release aggregator + * resources and remove aggregator ID. + * This function needs to be called with scheduler lock held. */ -static void -ice_set_clear_cir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc) +static enum ice_status +ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id, + enum ice_agg_type agg_type, ice_bitmap_t *tc_bitmap) { - bw_t_info->cir_bw.bw_alloc = bw_alloc; - if (bw_t_info->cir_bw.bw_alloc) - ice_set_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap); - else - ice_clear_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap); -} + struct ice_sched_agg_info *agg_info; + enum ice_status status = ICE_SUCCESS; + struct ice_hw *hw = pi->hw; + u8 tc; -/** - * ice_set_clear_eir_bw_alloc - set or clear EIR BW alloc information - * @bw_t_info: bandwidth type information structure - * @bw_alloc: Bandwidth allocation information - * - * Save or clear EIR BW alloc information (bw_alloc) in the passed param - * bw_t_info. - */ -static void -ice_set_clear_eir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc) -{ - bw_t_info->eir_bw.bw_alloc = bw_alloc; - if (bw_t_info->eir_bw.bw_alloc) - ice_set_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap); - else - ice_clear_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap); -} + agg_info = ice_get_agg_info(hw, agg_id); + if (!agg_info) { + /* Create new entry for new aggregator ID */ + agg_info = (struct ice_sched_agg_info *) + ice_malloc(hw, sizeof(*agg_info)); + if (!agg_info) { + status = ICE_ERR_NO_MEMORY; + goto exit_reg_agg; + } + agg_info->agg_id = agg_id; + agg_info->agg_type = agg_type; + agg_info->tc_bitmap[0] = 0; -/** - * ice_sched_save_vsi_bw_alloc - save VSI node's BW alloc information - * @pi: port information structure - * @vsi_handle: sw VSI handle - * @tc: traffic class - * @rl_type: rate limit type min or max - * @bw_alloc: Bandwidth allocation information - * - * Save BW alloc information of VSI type node for post replay use. - */ -static enum ice_status -ice_sched_save_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, - enum ice_rl_type rl_type, u16 bw_alloc) -{ - struct ice_vsi_ctx *vsi_ctx; + /* Initialize the aggregator VSI list head */ + INIT_LIST_HEAD(&agg_info->agg_vsi_list); - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) - return ICE_ERR_PARAM; - vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); - if (!vsi_ctx) - return ICE_ERR_PARAM; - switch (rl_type) { - case ICE_MIN_BW: - ice_set_clear_cir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc], - bw_alloc); - break; - case ICE_MAX_BW: - ice_set_clear_eir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc], - bw_alloc); - break; - default: - return ICE_ERR_PARAM; + /* Add new entry in aggregator list */ + LIST_ADD(&agg_info->list_entry, &hw->agg_list); } - return ICE_SUCCESS; + /* Create aggregator node(s) for requested TC(s) */ + ice_for_each_traffic_class(tc) { + if (!ice_is_tc_ena(*tc_bitmap, tc)) { + /* Delete aggregator cfg TC if it exists previously */ + status = ice_rm_agg_cfg_tc(pi, agg_info, tc, false); + if (status) + break; + continue; + } + + /* Check if aggregator node for TC already exists */ + if (ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) + continue; + + /* Create new aggregator node for TC */ + status = ice_sched_add_agg_cfg(pi, agg_id, tc); + if (status) + break; + + /* Save aggregator node's TC information */ + ice_set_bit(tc, agg_info->tc_bitmap); + } +exit_reg_agg: + return status; } /** - * ice_set_clear_cir_bw - set or clear CIR BW - * @bw_t_info: bandwidth type information structure - * @bw: bandwidth in Kbps - Kilo bits per sec + * ice_cfg_agg - config aggregator node + * @pi: port information structure + * @agg_id: aggregator ID + * @agg_type: aggregator type queue, VSI, or aggregator group + * @tc_bitmap: bits TC bitmap * - * Save or clear CIR bandwidth (BW) in the passed param bw_t_info. + * This function configures aggregator node(s). */ -static void -ice_set_clear_cir_bw(struct ice_bw_type_info *bw_t_info, u32 bw) +enum ice_status +ice_cfg_agg(struct ice_port_info *pi, u32 agg_id, enum ice_agg_type agg_type, + u8 tc_bitmap) { - if (bw == ICE_SCHED_DFLT_BW) { - ice_clear_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap); - bw_t_info->cir_bw.bw = 0; - } else { - /* Save type of BW information */ - ice_set_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap); - bw_t_info->cir_bw.bw = bw; - } + ice_bitmap_t bitmap = tc_bitmap; + enum ice_status status; + + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_cfg_agg(pi, agg_id, agg_type, + (ice_bitmap_t *)&bitmap); + if (!status) + status = ice_save_agg_tc_bitmap(pi, agg_id, + (ice_bitmap_t *)&bitmap); + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_set_clear_eir_bw - set or clear EIR BW - * @bw_t_info: bandwidth type information structure - * @bw: bandwidth in Kbps - Kilo bits per sec + * ice_get_agg_vsi_info - get the aggregator ID + * @agg_info: aggregator info + * @vsi_handle: software VSI handle * - * Save or clear EIR bandwidth (BW) in the passed param bw_t_info. + * The function returns aggregator VSI info based on VSI handle. This function + * needs to be called with scheduler lock held. */ -static void -ice_set_clear_eir_bw(struct ice_bw_type_info *bw_t_info, u32 bw) +static struct ice_sched_agg_vsi_info * +ice_get_agg_vsi_info(struct ice_sched_agg_info *agg_info, u16 vsi_handle) { - if (bw == ICE_SCHED_DFLT_BW) { - ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); - bw_t_info->eir_bw.bw = 0; - } else { - /* EIR BW and Shared BW profiles are mutually exclusive and - * hence only one of them may be set for any given element. - * First clear earlier saved shared BW information. - */ - ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); - bw_t_info->shared_bw = 0; - /* save EIR BW information */ - ice_set_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); - bw_t_info->eir_bw.bw = bw; - } + struct ice_sched_agg_vsi_info *agg_vsi_info; + + LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list, + ice_sched_agg_vsi_info, list_entry) + if (agg_vsi_info->vsi_handle == vsi_handle) + return agg_vsi_info; + + return NULL; } /** - * ice_set_clear_shared_bw - set or clear shared BW - * @bw_t_info: bandwidth type information structure - * @bw: bandwidth in Kbps - Kilo bits per sec + * ice_get_vsi_agg_info - get the aggregator info of VSI + * @hw: pointer to the hardware structure + * @vsi_handle: Sw VSI handle * - * Save or clear shared bandwidth (BW) in the passed param bw_t_info. + * The function returns aggregator info of VSI represented via vsi_handle. The + * VSI has in this case a different aggregator than the default one. This + * function needs to be called with scheduler lock held. */ -static void -ice_set_clear_shared_bw(struct ice_bw_type_info *bw_t_info, u32 bw) +static struct ice_sched_agg_info * +ice_get_vsi_agg_info(struct ice_hw *hw, u16 vsi_handle) { - if (bw == ICE_SCHED_DFLT_BW) { - ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); - bw_t_info->shared_bw = 0; - } else { - /* EIR BW and Shared BW profiles are mutually exclusive and - * hence only one of them may be set for any given element. - * First clear earlier saved EIR BW information. - */ - ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); - bw_t_info->eir_bw.bw = 0; - /* save shared BW information */ - ice_set_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); - bw_t_info->shared_bw = bw; + struct ice_sched_agg_info *agg_info; + + LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, + list_entry) { + struct ice_sched_agg_vsi_info *agg_vsi_info; + + agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); + if (agg_vsi_info) + return agg_info; } + return NULL; } /** - * ice_sched_save_vsi_bw - save VSI node's BW information + * ice_save_agg_vsi_tc_bitmap - save aggregator VSI TC bitmap * @pi: port information structure - * @vsi_handle: sw VSI handle - * @tc: traffic class - * @rl_type: rate limit type min, max, or shared - * @bw: bandwidth in Kbps - Kilo bits per sec + * @agg_id: aggregator ID + * @vsi_handle: software VSI handle + * @tc_bitmap: TC bitmap of enabled TC(s) * - * Save BW information of VSI type node for post replay use. + * Save VSI to aggregator TC bitmap. This function needs to call with scheduler + * lock held. */ static enum ice_status -ice_sched_save_vsi_bw(struct ice_port_info *pi, u16 vsi_handle, u8 tc, - enum ice_rl_type rl_type, u32 bw) +ice_save_agg_vsi_tc_bitmap(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle, + ice_bitmap_t *tc_bitmap) { - struct ice_vsi_ctx *vsi_ctx; + struct ice_sched_agg_vsi_info *agg_vsi_info; + struct ice_sched_agg_info *agg_info; - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) - return ICE_ERR_PARAM; - vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); - if (!vsi_ctx) + agg_info = ice_get_agg_info(pi->hw, agg_id); + if (!agg_info) return ICE_ERR_PARAM; - switch (rl_type) { - case ICE_MIN_BW: - ice_set_clear_cir_bw(&vsi_ctx->sched.bw_t_info[tc], bw); - break; - case ICE_MAX_BW: - ice_set_clear_eir_bw(&vsi_ctx->sched.bw_t_info[tc], bw); - break; - case ICE_SHARED_BW: - ice_set_clear_shared_bw(&vsi_ctx->sched.bw_t_info[tc], bw); - break; - default: + /* check if entry already exist */ + agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); + if (!agg_vsi_info) return ICE_ERR_PARAM; - } + ice_cp_bitmap(agg_vsi_info->replay_tc_bitmap, tc_bitmap, + ICE_MAX_TRAFFIC_CLASS); return ICE_SUCCESS; } /** - * ice_set_clear_prio - set or clear priority information - * @bw_t_info: bandwidth type information structure - * @prio: priority to save + * ice_sched_assoc_vsi_to_agg - associate/move VSI to new/default aggregator + * @pi: port information structure + * @agg_id: aggregator ID + * @vsi_handle: software VSI handle + * @tc_bitmap: TC bitmap of enabled TC(s) * - * Save or clear priority (prio) in the passed param bw_t_info. + * This function moves VSI to a new or default aggregator node. If VSI is + * already associated to the aggregator node then no operation is performed on + * the tree. This function needs to be called with scheduler lock held. */ -static void -ice_set_clear_prio(struct ice_bw_type_info *bw_t_info, u8 prio) +static enum ice_status +ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, + u16 vsi_handle, ice_bitmap_t *tc_bitmap) { - bw_t_info->generic = prio; - if (bw_t_info->generic) - ice_set_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap); - else - ice_clear_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap); -} - -/** - * ice_sched_save_vsi_prio - save VSI node's priority information - * @pi: port information structure - * @vsi_handle: Software VSI handle - * @tc: traffic class - * @prio: priority to save - * - * Save priority information of VSI type node for post replay use. - */ -static enum ice_status -ice_sched_save_vsi_prio(struct ice_port_info *pi, u16 vsi_handle, u8 tc, - u8 prio) -{ - struct ice_vsi_ctx *vsi_ctx; + struct ice_sched_agg_vsi_info *agg_vsi_info; + struct ice_sched_agg_info *agg_info; + enum ice_status status = ICE_SUCCESS; + struct ice_hw *hw = pi->hw; + u8 tc; if (!ice_is_vsi_valid(pi->hw, vsi_handle)) return ICE_ERR_PARAM; - vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); - if (!vsi_ctx) - return ICE_ERR_PARAM; - if (tc >= ICE_MAX_TRAFFIC_CLASS) + agg_info = ice_get_agg_info(hw, agg_id); + if (!agg_info) return ICE_ERR_PARAM; - ice_set_clear_prio(&vsi_ctx->sched.bw_t_info[tc], prio); - return ICE_SUCCESS; -} + /* check if entry already exist */ + agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle); + if (!agg_vsi_info) { + /* Create new entry for VSI under aggregator list */ + agg_vsi_info = (struct ice_sched_agg_vsi_info *) + ice_malloc(hw, sizeof(*agg_vsi_info)); + if (!agg_vsi_info) + return ICE_ERR_PARAM; -/** - * ice_sched_save_agg_bw_alloc - save aggregator node's BW alloc information - * @pi: port information structure - * @agg_id: node aggregator ID - * @tc: traffic class - * @rl_type: rate limit type min or max - * @bw_alloc: bandwidth alloc information - * - * Save BW alloc information of AGG type node for post replay use. - */ -static enum ice_status -ice_sched_save_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 tc, - enum ice_rl_type rl_type, u16 bw_alloc) -{ - struct ice_sched_agg_info *agg_info; + /* add VSI ID into the aggregator list */ + agg_vsi_info->vsi_handle = vsi_handle; + LIST_ADD(&agg_vsi_info->list_entry, &agg_info->agg_vsi_list); + } + /* Move VSI node to new aggregator node for requested TC(s) */ + ice_for_each_traffic_class(tc) { + if (!ice_is_tc_ena(*tc_bitmap, tc)) + continue; - agg_info = ice_get_agg_info(pi->hw, agg_id); - if (!agg_info) - return ICE_ERR_PARAM; - if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) - return ICE_ERR_PARAM; - switch (rl_type) { - case ICE_MIN_BW: - ice_set_clear_cir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc); - break; - case ICE_MAX_BW: - ice_set_clear_eir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc); - break; - default: - return ICE_ERR_PARAM; + /* Move VSI to new aggregator */ + status = ice_sched_move_vsi_to_agg(pi, vsi_handle, agg_id, tc); + if (status) + break; + + if (agg_id != ICE_DFLT_AGG_ID) + ice_set_bit(tc, agg_vsi_info->tc_bitmap); + else + ice_clear_bit(tc, agg_vsi_info->tc_bitmap); } - return ICE_SUCCESS; + /* If VSI moved back to default aggregator, delete agg_vsi_info. */ + if (!ice_is_any_bit_set(agg_vsi_info->tc_bitmap, + ICE_MAX_TRAFFIC_CLASS)) { + LIST_DEL(&agg_vsi_info->list_entry); + ice_free(hw, agg_vsi_info); + } + return status; } /** - * ice_sched_save_agg_bw - save aggregator node's BW information + * ice_sched_rm_unused_rl_prof - remove unused RL profile * @pi: port information structure - * @agg_id: node aggregator ID - * @tc: traffic class - * @rl_type: rate limit type min, max, or shared - * @bw: bandwidth in Kbps - Kilo bits per sec * - * Save BW information of AGG type node for post replay use. + * This function removes unused rate limit profiles from the HW and + * SW DB. The caller needs to hold scheduler lock. */ -static enum ice_status -ice_sched_save_agg_bw(struct ice_port_info *pi, u32 agg_id, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static void ice_sched_rm_unused_rl_prof(struct ice_port_info *pi) { - struct ice_sched_agg_info *agg_info; + u16 ln; - agg_info = ice_get_agg_info(pi->hw, agg_id); - if (!agg_info) - return ICE_ERR_PARAM; - if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) - return ICE_ERR_PARAM; - switch (rl_type) { - case ICE_MIN_BW: - ice_set_clear_cir_bw(&agg_info->bw_t_info[tc], bw); - break; - case ICE_MAX_BW: - ice_set_clear_eir_bw(&agg_info->bw_t_info[tc], bw); - break; - case ICE_SHARED_BW: - ice_set_clear_shared_bw(&agg_info->bw_t_info[tc], bw); - break; - default: - return ICE_ERR_PARAM; + for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) { + struct ice_aqc_rl_profile_info *rl_prof_elem; + struct ice_aqc_rl_profile_info *rl_prof_tmp; + + LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp, + &pi->rl_prof_list[ln], + ice_aqc_rl_profile_info, list_entry) { + if (!ice_sched_del_rl_profile(pi->hw, rl_prof_elem)) + ice_debug(pi->hw, ICE_DBG_SCHED, "Removed rl profile\n"); + } } - return ICE_SUCCESS; } /** - * ice_cfg_vsi_bw_lmt_per_tc - configure VSI BW limit per TC - * @pi: port information structure - * @vsi_handle: software VSI handle - * @tc: traffic class - * @rl_type: min or max - * @bw: bandwidth in Kbps + * ice_sched_update_elem - update element + * @hw: pointer to the HW struct + * @node: pointer to node + * @info: node info to update * - * This function configures BW limit of VSI scheduling node based on TC - * information. + * Update the HW DB, and local SW DB of node. Update the scheduling + * parameters of node from argument info data buffer (Info->data buf) and + * returns success or error on config sched element failure. The caller + * needs to hold scheduler lock. */ -enum ice_status -ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static enum ice_status +ice_sched_update_elem(struct ice_hw *hw, struct ice_sched_node *node, + struct ice_aqc_txsched_elem_data *info) { + struct ice_aqc_txsched_elem_data buf; enum ice_status status; + u16 elem_cfgd = 0; + u16 num_elems = 1; - status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle, - ICE_AGG_TYPE_VSI, - tc, rl_type, bw); - if (!status) { - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw); - ice_release_lock(&pi->sched_lock); + buf = *info; + /* Parent TEID is reserved field in this aq call */ + buf.parent_teid = 0; + /* Element type is reserved field in this aq call */ + buf.data.elem_type = 0; + /* Flags is reserved field in this aq call */ + buf.data.flags = 0; + + /* Update HW DB */ + /* Configure element node */ + status = ice_aq_cfg_sched_elems(hw, num_elems, &buf, sizeof(buf), + &elem_cfgd, NULL); + if (status || elem_cfgd != num_elems) { + ice_debug(hw, ICE_DBG_SCHED, "Config sched elem error\n"); + return ICE_ERR_CFG; } + + /* Config success case */ + /* Now update local SW DB */ + /* Only copy the data portion of info buffer */ + node->info.data = info->data; return status; } /** - * ice_cfg_dflt_vsi_bw_lmt_per_tc - configure default VSI BW limit per TC - * @pi: port information structure - * @vsi_handle: software VSI handle - * @tc: traffic class - * @rl_type: min or max + * ice_sched_cfg_node_bw_alloc - configure node BW weight/alloc params + * @hw: pointer to the HW struct + * @node: sched node to configure + * @rl_type: rate limit type CIR, EIR, or shared + * @bw_alloc: BW weight/allocation * - * This function configures default BW limit of VSI scheduling node based on TC - * information. + * This function configures node element's BW allocation. */ -enum ice_status -ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, - enum ice_rl_type rl_type) +static enum ice_status +ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node, + enum ice_rl_type rl_type, u16 bw_alloc) { + struct ice_aqc_txsched_elem_data buf; + struct ice_aqc_txsched_elem *data; enum ice_status status; - status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle, - ICE_AGG_TYPE_VSI, - tc, rl_type, - ICE_SCHED_DFLT_BW); - if (!status) { - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, - ICE_SCHED_DFLT_BW); - ice_release_lock(&pi->sched_lock); + buf = node->info; + data = &buf.data; + if (rl_type == ICE_MIN_BW) { + data->valid_sections |= ICE_AQC_ELEM_VALID_CIR; + data->cir_bw.bw_alloc = CPU_TO_LE16(bw_alloc); + } else if (rl_type == ICE_MAX_BW) { + data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; + data->eir_bw.bw_alloc = CPU_TO_LE16(bw_alloc); + } else { + return ICE_ERR_PARAM; } + + /* Configure element */ + status = ice_sched_update_elem(hw, node, &buf); return status; } /** - * ice_cfg_agg_bw_lmt_per_tc - configure aggregator BW limit per TC + * ice_move_vsi_to_agg - moves VSI to new or default aggregator * @pi: port information structure * @agg_id: aggregator ID - * @tc: traffic class - * @rl_type: min or max - * @bw: bandwidth in Kbps + * @vsi_handle: software VSI handle + * @tc_bitmap: TC bitmap of enabled TC(s) * - * This function applies BW limit to aggregator scheduling node based on TC - * information. + * Move or associate VSI to a new or default aggregator node. */ enum ice_status -ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc, - enum ice_rl_type rl_type, u32 bw) +ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle, + u8 tc_bitmap) { + ice_bitmap_t bitmap = tc_bitmap; enum ice_status status; - status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG, - tc, rl_type, bw); - if (!status) { - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw); - ice_release_lock(&pi->sched_lock); - } + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_assoc_vsi_to_agg(pi, agg_id, vsi_handle, + (ice_bitmap_t *)&bitmap); + if (!status) + status = ice_save_agg_vsi_tc_bitmap(pi, agg_id, vsi_handle, + (ice_bitmap_t *)&bitmap); + ice_release_lock(&pi->sched_lock); return status; } /** - * ice_cfg_agg_bw_dflt_lmt_per_tc - configure aggregator BW default limit per TC + * ice_rm_agg_cfg - remove aggregator configuration * @pi: port information structure * @agg_id: aggregator ID - * @tc: traffic class - * @rl_type: min or max * - * This function applies default BW limit to aggregator scheduling node based - * on TC information. - */ -enum ice_status -ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc, - enum ice_rl_type rl_type) + * This function removes aggregator reference to VSI and delete aggregator ID + * info. It removes the aggregator configuration completely. + */ +enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id) { - enum ice_status status; + struct ice_sched_agg_info *agg_info; + enum ice_status status = ICE_SUCCESS; + u8 tc; - status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG, - tc, rl_type, - ICE_SCHED_DFLT_BW); - if (!status) { - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, - ICE_SCHED_DFLT_BW); - ice_release_lock(&pi->sched_lock); + ice_acquire_lock(&pi->sched_lock); + agg_info = ice_get_agg_info(pi->hw, agg_id); + if (!agg_info) { + status = ICE_ERR_DOES_NOT_EXIST; + goto exit_ice_rm_agg_cfg; + } + + ice_for_each_traffic_class(tc) { + status = ice_rm_agg_cfg_tc(pi, agg_info, tc, true); + if (status) + goto exit_ice_rm_agg_cfg; + } + + if (ice_is_any_bit_set(agg_info->tc_bitmap, ICE_MAX_TRAFFIC_CLASS)) { + status = ICE_ERR_IN_USE; + goto exit_ice_rm_agg_cfg; } + + /* Safe to delete entry now */ + LIST_DEL(&agg_info->list_entry); + ice_free(pi->hw, agg_info); + + /* Remove unused RL profile IDs from HW and SW DB */ + ice_sched_rm_unused_rl_prof(pi); + +exit_ice_rm_agg_cfg: + ice_release_lock(&pi->sched_lock); return status; } /** - * ice_cfg_vsi_bw_shared_lmt - configure VSI BW shared limit - * @pi: port information structure - * @vsi_handle: software VSI handle - * @bw: bandwidth in Kbps + * ice_set_clear_cir_bw_alloc - set or clear CIR BW alloc information + * @bw_t_info: bandwidth type information structure + * @bw_alloc: Bandwidth allocation information * - * This function Configures shared rate limiter(SRL) of all VSI type nodes - * across all traffic classes for VSI matching handle. + * Save or clear CIR BW alloc information (bw_alloc) in the passed param + * bw_t_info. */ -enum ice_status -ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw) +static void +ice_set_clear_cir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc) { - return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, bw); + bw_t_info->cir_bw.bw_alloc = bw_alloc; + if (bw_t_info->cir_bw.bw_alloc) + ice_set_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap); + else + ice_clear_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap); } /** - * ice_cfg_vsi_bw_no_shared_lmt - configure VSI BW for no shared limiter - * @pi: port information structure - * @vsi_handle: software VSI handle + * ice_set_clear_eir_bw_alloc - set or clear EIR BW alloc information + * @bw_t_info: bandwidth type information structure + * @bw_alloc: Bandwidth allocation information * - * This function removes the shared rate limiter(SRL) of all VSI type nodes - * across all traffic classes for VSI matching handle. + * Save or clear EIR BW alloc information (bw_alloc) in the passed param + * bw_t_info. */ -enum ice_status -ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle) +static void +ice_set_clear_eir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc) { - return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, - ICE_SCHED_DFLT_BW); + bw_t_info->eir_bw.bw_alloc = bw_alloc; + if (bw_t_info->eir_bw.bw_alloc) + ice_set_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap); + else + ice_clear_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap); } /** - * ice_cfg_agg_bw_shared_lmt - configure aggregator BW shared limit + * ice_sched_save_vsi_bw_alloc - save VSI node's BW alloc information * @pi: port information structure - * @agg_id: aggregator ID - * @bw: bandwidth in Kbps + * @vsi_handle: sw VSI handle + * @tc: traffic class + * @rl_type: rate limit type min or max + * @bw_alloc: Bandwidth allocation information * - * This function configures the shared rate limiter(SRL) of all aggregator type - * nodes across all traffic classes for aggregator matching agg_id. + * Save BW alloc information of VSI type node for post replay use. */ -enum ice_status -ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw) +static enum ice_status +ice_sched_save_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + enum ice_rl_type rl_type, u16 bw_alloc) { - return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, bw); + struct ice_vsi_ctx *vsi_ctx; + + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; + vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); + if (!vsi_ctx) + return ICE_ERR_PARAM; + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc], + bw_alloc); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc], + bw_alloc); + break; + default: + return ICE_ERR_PARAM; + } + return ICE_SUCCESS; } /** - * ice_cfg_agg_bw_no_shared_lmt - configure aggregator BW for no shared limiter - * @pi: port information structure - * @agg_id: aggregator ID + * ice_set_clear_cir_bw - set or clear CIR BW + * @bw_t_info: bandwidth type information structure + * @bw: bandwidth in Kbps - Kilo bits per sec * - * This function removes the shared rate limiter(SRL) of all aggregator type - * nodes across all traffic classes for aggregator matching agg_id. + * Save or clear CIR bandwidth (BW) in the passed param bw_t_info. */ -enum ice_status -ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id) +static void ice_set_clear_cir_bw(struct ice_bw_type_info *bw_t_info, u32 bw) { - return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, ICE_SCHED_DFLT_BW); + if (bw == ICE_SCHED_DFLT_BW) { + ice_clear_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap); + bw_t_info->cir_bw.bw = 0; + } else { + /* Save type of BW information */ + ice_set_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap); + bw_t_info->cir_bw.bw = bw; + } } /** - * ice_config_vsi_queue_priority - config VSI queue priority of node - * @pi: port information structure - * @num_qs: number of VSI queues - * @q_ids: queue IDs array - * @q_ids: queue IDs array - * @q_prio: queue priority array + * ice_set_clear_eir_bw - set or clear EIR BW + * @bw_t_info: bandwidth type information structure + * @bw: bandwidth in Kbps - Kilo bits per sec * - * This function configures the queue node priority (Sibling Priority) of the - * passed in VSI's queue(s) for a given traffic class (TC). + * Save or clear EIR bandwidth (BW) in the passed param bw_t_info. */ -enum ice_status -ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids, - u8 *q_prio) +static void ice_set_clear_eir_bw(struct ice_bw_type_info *bw_t_info, u32 bw) { - enum ice_status status = ICE_ERR_PARAM; - struct ice_hw *hw = pi->hw; - u16 i; - - ice_acquire_lock(&pi->sched_lock); - - for (i = 0; i < num_qs; i++) { - struct ice_sched_node *node; - - node = ice_sched_find_node_by_teid(pi->root, q_ids[i]); - if (!node || node->info.data.elem_type != - ICE_AQC_ELEM_TYPE_LEAF) { - status = ICE_ERR_PARAM; - break; - } - /* Configure Priority */ - status = ice_sched_cfg_sibl_node_prio(hw, node, q_prio[i]); - if (status) - break; + if (bw == ICE_SCHED_DFLT_BW) { + ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); + bw_t_info->eir_bw.bw = 0; + } else { + /* EIR BW and Shared BW profiles are mutually exclusive and + * hence only one of them may be set for any given element. + * First clear earlier saved shared BW information. + */ + ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); + bw_t_info->shared_bw = 0; + /* save EIR BW information */ + ice_set_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); + bw_t_info->eir_bw.bw = bw; } +} - ice_release_lock(&pi->sched_lock); - return status; +/** + * ice_set_clear_shared_bw - set or clear shared BW + * @bw_t_info: bandwidth type information structure + * @bw: bandwidth in Kbps - Kilo bits per sec + * + * Save or clear shared bandwidth (BW) in the passed param bw_t_info. + */ +static void ice_set_clear_shared_bw(struct ice_bw_type_info *bw_t_info, u32 bw) +{ + if (bw == ICE_SCHED_DFLT_BW) { + ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); + bw_t_info->shared_bw = 0; + } else { + /* EIR BW and Shared BW profiles are mutually exclusive and + * hence only one of them may be set for any given element. + * First clear earlier saved EIR BW information. + */ + ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap); + bw_t_info->eir_bw.bw = 0; + /* save shared BW information */ + ice_set_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap); + bw_t_info->shared_bw = bw; + } } /** - * ice_cfg_agg_vsi_priority_per_tc - config aggregator's VSI priority per TC + * ice_sched_save_vsi_bw - save VSI node's BW information * @pi: port information structure - * @agg_id: Aggregator ID - * @num_vsis: number of VSI(s) - * @vsi_handle_arr: array of software VSI handles - * @node_prio: pointer to node priority + * @vsi_handle: sw VSI handle * @tc: traffic class + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth in Kbps - Kilo bits per sec * - * This function configures the node priority (Sibling Priority) of the - * passed in VSI's for a given traffic class (TC) of an Aggregator ID. + * Save BW information of VSI type node for post replay use. */ -enum ice_status -ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id, - u16 num_vsis, u16 *vsi_handle_arr, - u8 *node_prio, u8 tc) +static enum ice_status +ice_sched_save_vsi_bw(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + enum ice_rl_type rl_type, u32 bw) { - struct ice_sched_agg_vsi_info *agg_vsi_info; - struct ice_sched_node *tc_node, *agg_node; - enum ice_status status = ICE_ERR_PARAM; - struct ice_sched_agg_info *agg_info; - bool agg_id_present = false; - struct ice_hw *hw = pi->hw; - u16 i; - - ice_acquire_lock(&pi->sched_lock); - LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, - list_entry) - if (agg_info->agg_id == agg_id) { - agg_id_present = true; - break; - } - if (!agg_id_present) - goto exit_agg_priority_per_tc; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - goto exit_agg_priority_per_tc; + struct ice_vsi_ctx *vsi_ctx; - agg_node = ice_sched_get_agg_node(hw, tc_node, agg_id); - if (!agg_node) - goto exit_agg_priority_per_tc; - - if (num_vsis > hw->max_children[agg_node->tx_sched_layer]) - goto exit_agg_priority_per_tc; - - for (i = 0; i < num_vsis; i++) { - struct ice_sched_node *vsi_node; - bool vsi_handle_valid = false; - u16 vsi_handle; - - status = ICE_ERR_PARAM; - vsi_handle = vsi_handle_arr[i]; - if (!ice_is_vsi_valid(hw, vsi_handle)) - goto exit_agg_priority_per_tc; - /* Verify child nodes before applying settings */ - LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list, - ice_sched_agg_vsi_info, list_entry) - if (agg_vsi_info->vsi_handle == vsi_handle) { - vsi_handle_valid = true; - break; - } - if (!vsi_handle_valid) - goto exit_agg_priority_per_tc; - - vsi_node = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); - if (!vsi_node) - goto exit_agg_priority_per_tc; - - if (ice_sched_find_node_in_subtree(hw, agg_node, vsi_node)) { - /* Configure Priority */ - status = ice_sched_cfg_sibl_node_prio(hw, vsi_node, - node_prio[i]); - if (status) - break; - status = ice_sched_save_vsi_prio(pi, vsi_handle, tc, - node_prio[i]); - if (status) - break; - } + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; + vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); + if (!vsi_ctx) + return ICE_ERR_PARAM; + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw(&vsi_ctx->sched.bw_t_info[tc], bw); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw(&vsi_ctx->sched.bw_t_info[tc], bw); + break; + case ICE_SHARED_BW: + ice_set_clear_shared_bw(&vsi_ctx->sched.bw_t_info[tc], bw); + break; + default: + return ICE_ERR_PARAM; } + return ICE_SUCCESS; +} -exit_agg_priority_per_tc: - ice_release_lock(&pi->sched_lock); - return status; +/** + * ice_set_clear_prio - set or clear priority information + * @bw_t_info: bandwidth type information structure + * @prio: priority to save + * + * Save or clear priority (prio) in the passed param bw_t_info. + */ +static void ice_set_clear_prio(struct ice_bw_type_info *bw_t_info, u8 prio) +{ + bw_t_info->generic = prio; + if (bw_t_info->generic) + ice_set_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap); + else + ice_clear_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap); } /** - * ice_cfg_vsi_bw_alloc - config VSI BW alloc per TC + * ice_sched_save_vsi_prio - save VSI node's priority information * @pi: port information structure - * @vsi_handle: software VSI handle - * @ena_tcmap: enabled TC map - * @rl_type: Rate limit type CIR/EIR - * @bw_alloc: Array of BW alloc + * @vsi_handle: Software VSI handle + * @tc: traffic class + * @prio: priority to save * - * This function configures the BW allocation of the passed in VSI's - * node(s) for enabled traffic class. + * Save priority information of VSI type node for post replay use. */ -enum ice_status -ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap, - enum ice_rl_type rl_type, u8 *bw_alloc) +static enum ice_status +ice_sched_save_vsi_prio(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + u8 prio) { - enum ice_status status = ICE_SUCCESS; - u8 tc; + struct ice_vsi_ctx *vsi_ctx; if (!ice_is_vsi_valid(pi->hw, vsi_handle)) return ICE_ERR_PARAM; - - ice_acquire_lock(&pi->sched_lock); - - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - struct ice_sched_node *tc_node, *vsi_node; - - if (!ice_is_tc_ena(ena_tcmap, tc)) - continue; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - vsi_node = ice_sched_get_vsi_node(pi->hw, tc_node, vsi_handle); - if (!vsi_node) - continue; - - status = ice_sched_cfg_node_bw_alloc(pi->hw, vsi_node, rl_type, - bw_alloc[tc]); - if (status) - break; - status = ice_sched_save_vsi_bw_alloc(pi, vsi_handle, tc, - rl_type, bw_alloc[tc]); - if (status) - break; - } - - ice_release_lock(&pi->sched_lock); - return status; + vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); + if (!vsi_ctx) + return ICE_ERR_PARAM; + if (tc >= ICE_MAX_TRAFFIC_CLASS) + return ICE_ERR_PARAM; + ice_set_clear_prio(&vsi_ctx->sched.bw_t_info[tc], prio); + return ICE_SUCCESS; } /** - * ice_cfg_agg_bw_alloc - config aggregator BW alloc + * ice_sched_save_agg_bw_alloc - save aggregator node's BW alloc information * @pi: port information structure - * @agg_id: aggregator ID - * @ena_tcmap: enabled TC map - * @rl_type: rate limit type CIR/EIR - * @bw_alloc: array of BW alloc + * @agg_id: node aggregator ID + * @tc: traffic class + * @rl_type: rate limit type min or max + * @bw_alloc: bandwidth alloc information * - * This function configures the BW allocation of passed in aggregator for - * enabled traffic class(s). + * Save BW alloc information of AGG type node for post replay use. */ -enum ice_status -ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap, - enum ice_rl_type rl_type, u8 *bw_alloc) +static enum ice_status +ice_sched_save_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 tc, + enum ice_rl_type rl_type, u16 bw_alloc) { struct ice_sched_agg_info *agg_info; - bool agg_id_present = false; - enum ice_status status = ICE_SUCCESS; - struct ice_hw *hw = pi->hw; - u8 tc; - ice_acquire_lock(&pi->sched_lock); - LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, - list_entry) - if (agg_info->agg_id == agg_id) { - agg_id_present = true; - break; - } - if (!agg_id_present) { - status = ICE_ERR_PARAM; - goto exit_cfg_agg_bw_alloc; + agg_info = ice_get_agg_info(pi->hw, agg_id); + if (!agg_info) + return ICE_ERR_PARAM; + if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) + return ICE_ERR_PARAM; + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc); + break; + default: + return ICE_ERR_PARAM; } + return ICE_SUCCESS; +} - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - struct ice_sched_node *tc_node, *agg_node; - - if (!ice_is_tc_ena(ena_tcmap, tc)) - continue; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - agg_node = ice_sched_get_agg_node(hw, tc_node, agg_id); - if (!agg_node) - continue; +/** + * ice_sched_save_agg_bw - save aggregator node's BW information + * @pi: port information structure + * @agg_id: node aggregator ID + * @tc: traffic class + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth in Kbps - Kilo bits per sec + * + * Save BW information of AGG type node for post replay use. + */ +static enum ice_status +ice_sched_save_agg_bw(struct ice_port_info *pi, u32 agg_id, u8 tc, + enum ice_rl_type rl_type, u32 bw) +{ + struct ice_sched_agg_info *agg_info; - status = ice_sched_cfg_node_bw_alloc(hw, agg_node, rl_type, - bw_alloc[tc]); - if (status) - break; - status = ice_sched_save_agg_bw_alloc(pi, agg_id, tc, rl_type, - bw_alloc[tc]); - if (status) - break; + agg_info = ice_get_agg_info(pi->hw, agg_id); + if (!agg_info) + return ICE_ERR_PARAM; + if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc)) + return ICE_ERR_PARAM; + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw(&agg_info->bw_t_info[tc], bw); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw(&agg_info->bw_t_info[tc], bw); + break; + case ICE_SHARED_BW: + ice_set_clear_shared_bw(&agg_info->bw_t_info[tc], bw); + break; + default: + return ICE_ERR_PARAM; } - -exit_cfg_agg_bw_alloc: - ice_release_lock(&pi->sched_lock); - return status; + return ICE_SUCCESS; } /** - * ice_sched_calc_wakeup - calculate RL profile wakeup parameter + * ice_cfg_vsi_bw_lmt_per_tc - configure VSI BW limit per TC + * @pi: port information structure + * @vsi_handle: software VSI handle + * @tc: traffic class + * @rl_type: min or max * @bw: bandwidth in Kbps * - * This function calculates the wakeup parameter of RL profile. + * This function configures BW limit of VSI scheduling node based on TC + * information. */ -static u16 ice_sched_calc_wakeup(s32 bw) +enum ice_status +ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + enum ice_rl_type rl_type, u32 bw) { - s64 bytes_per_sec, wakeup_int, wakeup_a, wakeup_b, wakeup_f; - s32 wakeup_f_int; - u16 wakeup = 0; + enum ice_status status; - /* Get the wakeup integer value */ - bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE); - wakeup_int = DIV_64BIT(ICE_RL_PROF_FREQUENCY, bytes_per_sec); - if (wakeup_int > 63) { - wakeup = (u16)((1 << 15) | wakeup_int); - } else { - /* Calculate fraction value up to 4 decimals - * Convert Integer value to a constant multiplier - */ - wakeup_b = (s64)ICE_RL_PROF_MULTIPLIER * wakeup_int; - wakeup_a = DIV_64BIT((s64)ICE_RL_PROF_MULTIPLIER * - ICE_RL_PROF_FREQUENCY, bytes_per_sec); - - /* Get Fraction value */ - wakeup_f = wakeup_a - wakeup_b; - - /* Round up the Fractional value via Ceil(Fractional value) */ - if (wakeup_f > DIV_64BIT(ICE_RL_PROF_MULTIPLIER, 2)) - wakeup_f += 1; - - wakeup_f_int = (s32)DIV_64BIT(wakeup_f * ICE_RL_PROF_FRACTION, - ICE_RL_PROF_MULTIPLIER); - wakeup |= (u16)(wakeup_int << 9); - wakeup |= (u16)(0x1ff & wakeup_f_int); + status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle, + ICE_AGG_TYPE_VSI, + tc, rl_type, bw); + if (!status) { + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw); + ice_release_lock(&pi->sched_lock); } - - return wakeup; + return status; } /** - * ice_sched_bw_to_rl_profile - convert BW to profile parameters - * @bw: bandwidth in Kbps - * @profile: profile parameters to return + * ice_cfg_dflt_vsi_bw_lmt_per_tc - configure default VSI BW limit per TC + * @pi: port information structure + * @vsi_handle: software VSI handle + * @tc: traffic class + * @rl_type: min or max * - * This function converts the BW to profile structure format. + * This function configures default BW limit of VSI scheduling node based on TC + * information. */ -static enum ice_status -ice_sched_bw_to_rl_profile(u32 bw, struct ice_aqc_rl_profile_elem *profile) +enum ice_status +ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + enum ice_rl_type rl_type) { - enum ice_status status = ICE_ERR_PARAM; - s64 bytes_per_sec, ts_rate, mv_tmp; - bool found = false; - s32 encode = 0; - s64 mv = 0; - s32 i; - - /* Bw settings range is from 0.5Mb/sec to 100Gb/sec */ - if (bw < ICE_SCHED_MIN_BW || bw > ICE_SCHED_MAX_BW) - return status; - - /* Bytes per second from Kbps */ - bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE); - - /* encode is 6 bits but really useful are 5 bits */ - for (i = 0; i < 64; i++) { - u64 pow_result = BIT_ULL(i); - - ts_rate = DIV_64BIT((s64)ICE_RL_PROF_FREQUENCY, - pow_result * ICE_RL_PROF_TS_MULTIPLIER); - if (ts_rate <= 0) - continue; - - /* Multiplier value */ - mv_tmp = DIV_64BIT(bytes_per_sec * ICE_RL_PROF_MULTIPLIER, - ts_rate); - - /* Round to the nearest ICE_RL_PROF_MULTIPLIER */ - mv = round_up_64bit(mv_tmp, ICE_RL_PROF_MULTIPLIER); - - /* First multiplier value greater than the given - * accuracy bytes - */ - if (mv > ICE_RL_PROF_ACCURACY_BYTES) { - encode = i; - found = true; - break; - } - } - if (found) { - u16 wm; + enum ice_status status; - wm = ice_sched_calc_wakeup(bw); - profile->rl_multiply = CPU_TO_LE16(mv); - profile->wake_up_calc = CPU_TO_LE16(wm); - profile->rl_encode = CPU_TO_LE16(encode); - status = ICE_SUCCESS; - } else { - status = ICE_ERR_DOES_NOT_EXIST; + status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle, + ICE_AGG_TYPE_VSI, + tc, rl_type, + ICE_SCHED_DFLT_BW); + if (!status) { + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, + ICE_SCHED_DFLT_BW); + ice_release_lock(&pi->sched_lock); } - return status; } /** - * ice_sched_add_rl_profile - add RL profile + * ice_cfg_agg_bw_lmt_per_tc - configure aggregator BW limit per TC * @pi: port information structure - * @rl_type: type of rate limit BW - min, max, or shared - * @bw: bandwidth in Kbps - Kilo bits per sec - * @layer_num: specifies in which layer to create profile + * @agg_id: aggregator ID + * @tc: traffic class + * @rl_type: min or max + * @bw: bandwidth in Kbps * - * This function first checks the existing list for corresponding BW - * parameter. If it exists, it returns the associated profile otherwise - * it creates a new rate limit profile for requested BW, and adds it to - * the HW DB and local list. It returns the new profile or null on error. - * The caller needs to hold the scheduler lock. + * This function applies BW limit to aggregator scheduling node based on TC + * information. */ -static struct ice_aqc_rl_profile_info * -ice_sched_add_rl_profile(struct ice_port_info *pi, - enum ice_rl_type rl_type, u32 bw, u8 layer_num) +enum ice_status +ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc, + enum ice_rl_type rl_type, u32 bw) { - struct ice_aqc_rl_profile_generic_elem *buf; - struct ice_aqc_rl_profile_info *rl_prof_elem; - u16 profiles_added = 0, num_profiles = 1; - enum ice_status status = ICE_ERR_PARAM; - struct ice_hw *hw; - u8 profile_type; + enum ice_status status; - switch (rl_type) { - case ICE_MIN_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR; - break; - case ICE_MAX_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR; - break; - case ICE_SHARED_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL; - break; - default: - return NULL; + status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG, + tc, rl_type, bw); + if (!status) { + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw); + ice_release_lock(&pi->sched_lock); } - - if (!pi) - return NULL; - hw = pi->hw; - LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num], - ice_aqc_rl_profile_info, list_entry) - if (rl_prof_elem->profile.flags == profile_type && - rl_prof_elem->bw == bw) - /* Return existing profile ID info */ - return rl_prof_elem; - - /* Create new profile ID */ - rl_prof_elem = (struct ice_aqc_rl_profile_info *) - ice_malloc(hw, sizeof(*rl_prof_elem)); - - if (!rl_prof_elem) - return NULL; - - status = ice_sched_bw_to_rl_profile(bw, &rl_prof_elem->profile); - if (status != ICE_SUCCESS) - goto exit_add_rl_prof; - - rl_prof_elem->bw = bw; - /* layer_num is zero relative, and fw expects level from 1 to 9 */ - rl_prof_elem->profile.level = layer_num + 1; - rl_prof_elem->profile.flags = profile_type; - rl_prof_elem->profile.max_burst_size = CPU_TO_LE16(hw->max_burst_size); - - /* Create new entry in HW DB */ - buf = (struct ice_aqc_rl_profile_generic_elem *) - &rl_prof_elem->profile; - status = ice_aq_add_rl_profile(hw, num_profiles, buf, sizeof(*buf), - &profiles_added, NULL); - if (status || profiles_added != num_profiles) - goto exit_add_rl_prof; - - /* Good entry - add in the list */ - rl_prof_elem->prof_id_ref = 0; - LIST_ADD(&rl_prof_elem->list_entry, &pi->rl_prof_list[layer_num]); - return rl_prof_elem; - -exit_add_rl_prof: - ice_free(hw, rl_prof_elem); - return NULL; + return status; } /** - * ice_sched_del_rl_profile - remove rl profile - * @hw: pointer to the hw struct - * @rl_info: rate limit profile information + * ice_cfg_agg_bw_dflt_lmt_per_tc - configure aggregator BW default limit per TC + * @pi: port information structure + * @agg_id: aggregator ID + * @tc: traffic class + * @rl_type: min or max * - * If the profile id is not referenced anymore, it removes profile id with - * its associated parameters from hw db,and locally. The caller needs to - * hold scheduler lock. + * This function applies default BW limit to aggregator scheduling node based + * on TC information. */ enum ice_status -ice_sched_del_rl_profile(struct ice_hw *hw, - struct ice_aqc_rl_profile_info *rl_info) +ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc, + enum ice_rl_type rl_type) { - struct ice_aqc_rl_profile_generic_elem *buf; - u16 num_profiles_removed; enum ice_status status; - u16 num_profiles = 1; - - if (rl_info->prof_id_ref != 0) - return ICE_ERR_IN_USE; - - /* Safe to remove profile id */ - buf = (struct ice_aqc_rl_profile_generic_elem *) - &rl_info->profile; - status = ice_aq_remove_rl_profile(hw, num_profiles, buf, sizeof(*buf), - &num_profiles_removed, NULL); - if (status || num_profiles_removed != num_profiles) - return ICE_ERR_CFG; - /* Delete stale entry now */ - LIST_DEL(&rl_info->list_entry); - ice_free(hw, rl_info); + status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG, + tc, rl_type, + ICE_SCHED_DFLT_BW); + if (!status) { + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, + ICE_SCHED_DFLT_BW); + ice_release_lock(&pi->sched_lock); + } return status; } /** - * ice_sched_rm_unused_rl_prof - remove unused rl profile + * ice_cfg_vsi_bw_shared_lmt - configure VSI BW shared limit * @pi: port information structure + * @vsi_handle: software VSI handle + * @bw: bandwidth in Kbps * - * This function removes unused rate limit profiles from the hw and - * SW DB. The caller needs to hold scheduler lock. + * This function Configures shared rate limiter(SRL) of all VSI type nodes + * across all traffic classes for VSI matching handle. */ -void ice_sched_rm_unused_rl_prof(struct ice_port_info *pi) +enum ice_status +ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw) { - u8 ln; - - for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) { - struct ice_aqc_rl_profile_info *rl_prof_elem; - struct ice_aqc_rl_profile_info *rl_prof_tmp; - - LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp, - &pi->rl_prof_list[ln], - ice_aqc_rl_profile_info, list_entry) { - if (!ice_sched_del_rl_profile(pi->hw, rl_prof_elem)) - ice_debug(pi->hw, ICE_DBG_SCHED, - "Removed rl profile\n"); - } - } + return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, bw); } /** - * ice_sched_update_elem - update element - * @hw: pointer to the hw struct - * @node: pointer to node - * @info: node info to update + * ice_cfg_vsi_bw_no_shared_lmt - configure VSI BW for no shared limiter + * @pi: port information structure + * @vsi_handle: software VSI handle * - * It updates the HW DB, and local SW DB of node. It updates the scheduling - * parameters of node from argument info data buffer (Info->data buf) and - * returns success or error on config sched element failure. The caller - * needs to hold scheduler lock. + * This function removes the shared rate limiter(SRL) of all VSI type nodes + * across all traffic classes for VSI matching handle. */ -static enum ice_status -ice_sched_update_elem(struct ice_hw *hw, struct ice_sched_node *node, - struct ice_aqc_txsched_elem_data *info) +enum ice_status +ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle) { - struct ice_aqc_conf_elem buf; - enum ice_status status; - u16 elem_cfgd = 0; - u16 num_elems = 1; - - buf.generic[0] = *info; - /* Parent teid is reserved field in this aq call */ - buf.generic[0].parent_teid = 0; - /* Element type is reserved field in this aq call */ - buf.generic[0].data.elem_type = 0; - /* Flags is reserved field in this aq call */ - buf.generic[0].data.flags = 0; + return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, + ICE_SCHED_DFLT_BW); +} - /* Update HW DB */ - /* Configure element node */ - status = ice_aq_cfg_sched_elems(hw, num_elems, &buf, sizeof(buf), - &elem_cfgd, NULL); - if (status || elem_cfgd != num_elems) { - ice_debug(hw, ICE_DBG_SCHED, "Config sched elem error\n"); - return ICE_ERR_CFG; - } +/** + * ice_cfg_agg_bw_shared_lmt - configure aggregator BW shared limit + * @pi: port information structure + * @agg_id: aggregator ID + * @bw: bandwidth in Kbps + * + * This function configures the shared rate limiter(SRL) of all aggregator type + * nodes across all traffic classes for aggregator matching agg_id. + */ +enum ice_status +ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw) +{ + return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, bw); +} - /* Config success case */ - /* Now update local SW DB */ - /* Only copy the data portion of info buffer */ - node->info.data = info->data; - return status; +/** + * ice_cfg_agg_bw_no_shared_lmt - configure aggregator BW for no shared limiter + * @pi: port information structure + * @agg_id: aggregator ID + * + * This function removes the shared rate limiter(SRL) of all aggregator type + * nodes across all traffic classes for aggregator matching agg_id. + */ +enum ice_status +ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id) +{ + return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, ICE_SCHED_DFLT_BW); } /** - * ice_sched_cfg_node_bw_lmt - configure node sched params - * @hw: pointer to the HW struct - * @node: sched node to configure - * @rl_type: rate limit type CIR, EIR, or shared - * @rl_prof_id: rate limit profile ID + * ice_config_vsi_queue_priority - config VSI queue priority of node + * @pi: port information structure + * @num_qs: number of VSI queues + * @q_ids: queue IDs array + * @q_prio: queue priority array * - * This function configures node element's BW limit. + * This function configures the queue node priority (Sibling Priority) of the + * passed in VSI's queue(s) for a given traffic class (TC). */ -static enum ice_status -ice_sched_cfg_node_bw_lmt(struct ice_hw *hw, struct ice_sched_node *node, - enum ice_rl_type rl_type, u16 rl_prof_id) +enum ice_status +ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids, + u8 *q_prio) { - struct ice_aqc_txsched_elem_data buf; - struct ice_aqc_txsched_elem *data; + enum ice_status status = ICE_ERR_PARAM; + u16 i; - buf = node->info; - data = &buf.data; - switch (rl_type) { - case ICE_MIN_BW: - data->valid_sections |= ICE_AQC_ELEM_VALID_CIR; - data->cir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id); - break; - case ICE_MAX_BW: - /* EIR BW and Shared BW profiles are mutually exclusive and - * hence only one of them may be set for any given element - */ - if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED) - return ICE_ERR_CFG; - data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; - data->eir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id); - break; - case ICE_SHARED_BW: - /* Check for removing shared BW */ - if (rl_prof_id == ICE_SCHED_NO_SHARED_RL_PROF_ID) { - /* remove shared profile */ - data->valid_sections &= ~ICE_AQC_ELEM_VALID_SHARED; - data->srl_id = 0; /* clear SRL field */ + ice_acquire_lock(&pi->sched_lock); - /* enable back EIR to default profile */ - data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; - data->eir_bw.bw_profile_idx = - CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID); + for (i = 0; i < num_qs; i++) { + struct ice_sched_node *node; + + node = ice_sched_find_node_by_teid(pi->root, q_ids[i]); + if (!node || node->info.data.elem_type != + ICE_AQC_ELEM_TYPE_LEAF) { + status = ICE_ERR_PARAM; break; } - /* EIR BW and Shared BW profiles are mutually exclusive and - * hence only one of them may be set for any given element - */ - if ((data->valid_sections & ICE_AQC_ELEM_VALID_EIR) && - (LE16_TO_CPU(data->eir_bw.bw_profile_idx) != - ICE_SCHED_DFLT_RL_PROF_ID)) - return ICE_ERR_CFG; - /* EIR BW is set to default, disable it */ - data->valid_sections &= ~ICE_AQC_ELEM_VALID_EIR; - /* Okay to enable shared BW now */ - data->valid_sections |= ICE_AQC_ELEM_VALID_SHARED; - data->srl_id = CPU_TO_LE16(rl_prof_id); - break; - default: - /* Unknown rate limit type */ - return ICE_ERR_PARAM; + /* Configure Priority */ + status = ice_sched_cfg_sibl_node_prio(pi, node, q_prio[i]); + if (status) + break; } - /* Configure element */ - return ice_sched_update_elem(hw, node, &buf); + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_sched_get_node_rl_prof_id - get node's rate limit profile ID - * @node: sched node - * @rl_type: rate limit type + * ice_cfg_agg_vsi_priority_per_tc - config aggregator's VSI priority per TC + * @pi: port information structure + * @agg_id: Aggregator ID + * @num_vsis: number of VSI(s) + * @vsi_handle_arr: array of software VSI handles + * @node_prio: pointer to node priority + * @tc: traffic class * - * If existing profile matches, it returns the corresponding rate - * limit profile ID, otherwise it returns an invalid ID as error. + * This function configures the node priority (Sibling Priority) of the + * passed in VSI's for a given traffic class (TC) of an Aggregator ID. */ -static u16 -ice_sched_get_node_rl_prof_id(struct ice_sched_node *node, - enum ice_rl_type rl_type) +enum ice_status +ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id, + u16 num_vsis, u16 *vsi_handle_arr, + u8 *node_prio, u8 tc) { - u16 rl_prof_id = ICE_SCHED_INVAL_PROF_ID; - struct ice_aqc_txsched_elem *data; + struct ice_sched_agg_vsi_info *agg_vsi_info; + struct ice_sched_node *tc_node, *agg_node; + enum ice_status status = ICE_ERR_PARAM; + struct ice_sched_agg_info *agg_info; + bool agg_id_present = false; + struct ice_hw *hw = pi->hw; + u16 i; - data = &node->info.data; - switch (rl_type) { - case ICE_MIN_BW: - if (data->valid_sections & ICE_AQC_ELEM_VALID_CIR) - rl_prof_id = LE16_TO_CPU(data->cir_bw.bw_profile_idx); - break; - case ICE_MAX_BW: - if (data->valid_sections & ICE_AQC_ELEM_VALID_EIR) - rl_prof_id = LE16_TO_CPU(data->eir_bw.bw_profile_idx); - break; - case ICE_SHARED_BW: - if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED) - rl_prof_id = LE16_TO_CPU(data->srl_id); - break; - default: - break; + ice_acquire_lock(&pi->sched_lock); + LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, + list_entry) + if (agg_info->agg_id == agg_id) { + agg_id_present = true; + break; + } + if (!agg_id_present) + goto exit_agg_priority_per_tc; + + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + goto exit_agg_priority_per_tc; + + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + goto exit_agg_priority_per_tc; + + if (num_vsis > hw->max_children[agg_node->tx_sched_layer]) + goto exit_agg_priority_per_tc; + + for (i = 0; i < num_vsis; i++) { + struct ice_sched_node *vsi_node; + bool vsi_handle_valid = false; + u16 vsi_handle; + + status = ICE_ERR_PARAM; + vsi_handle = vsi_handle_arr[i]; + if (!ice_is_vsi_valid(hw, vsi_handle)) + goto exit_agg_priority_per_tc; + /* Verify child nodes before applying settings */ + LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list, + ice_sched_agg_vsi_info, list_entry) + if (agg_vsi_info->vsi_handle == vsi_handle) { + /* cppcheck-suppress unreadVariable */ + vsi_handle_valid = true; + break; + } + + if (!vsi_handle_valid) + goto exit_agg_priority_per_tc; + + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); + if (!vsi_node) + goto exit_agg_priority_per_tc; + + if (ice_sched_find_node_in_subtree(hw, agg_node, vsi_node)) { + /* Configure Priority */ + status = ice_sched_cfg_sibl_node_prio(pi, vsi_node, + node_prio[i]); + if (status) + break; + status = ice_sched_save_vsi_prio(pi, vsi_handle, tc, + node_prio[i]); + if (status) + break; + } } - return rl_prof_id; +exit_agg_priority_per_tc: + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_sched_get_rl_prof_layer - selects rate limit profile creation layer + * ice_cfg_vsi_bw_alloc - config VSI BW alloc per TC * @pi: port information structure - * @rl_type: type of rate limit BW - min, max, or shared - * @layer_index: layer index + * @vsi_handle: software VSI handle + * @ena_tcmap: enabled TC map + * @rl_type: Rate limit type CIR/EIR + * @bw_alloc: Array of BW alloc * - * This function returns requested profile creation layer. + * This function configures the BW allocation of the passed in VSI's + * node(s) for enabled traffic class. */ -static u8 -ice_sched_get_rl_prof_layer(struct ice_port_info *pi, enum ice_rl_type rl_type, - u8 layer_index) +enum ice_status +ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap, + enum ice_rl_type rl_type, u8 *bw_alloc) { - struct ice_hw *hw = pi->hw; + enum ice_status status = ICE_SUCCESS; + u8 tc; - if (layer_index >= hw->num_tx_sched_layers) - return ICE_SCHED_INVAL_LAYER_NUM; - switch (rl_type) { - case ICE_MIN_BW: - if (hw->layer_info[layer_index].max_cir_rl_profiles) - return layer_index; - break; - case ICE_MAX_BW: - if (hw->layer_info[layer_index].max_eir_rl_profiles) - return layer_index; - break; - case ICE_SHARED_BW: - /* if current layer doesn't support SRL profile creation - * then try a layer up or down. - */ - if (hw->layer_info[layer_index].max_srl_profiles) - return layer_index; - else if (layer_index < hw->num_tx_sched_layers - 1 && - hw->layer_info[layer_index + 1].max_srl_profiles) - return layer_index + 1; - else if (layer_index > 0 && - hw->layer_info[layer_index - 1].max_srl_profiles) - return layer_index - 1; - break; - default: - break; + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; + + ice_acquire_lock(&pi->sched_lock); + + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + struct ice_sched_node *tc_node, *vsi_node; + + if (!ice_is_tc_ena(ena_tcmap, tc)) + continue; + + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; + + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); + if (!vsi_node) + continue; + + status = ice_sched_cfg_node_bw_alloc(pi->hw, vsi_node, rl_type, + bw_alloc[tc]); + if (status) + break; + status = ice_sched_save_vsi_bw_alloc(pi, vsi_handle, tc, + rl_type, bw_alloc[tc]); + if (status) + break; } - return ICE_SCHED_INVAL_LAYER_NUM; -} -/** - * ice_sched_get_srl_node - get shared rate limit node - * @node: tree node - * @srl_layer: shared rate limit layer - * - * This function returns SRL node to be used for shared rate limit purpose. - * The caller needs to hold scheduler lock. - */ -static struct ice_sched_node * -ice_sched_get_srl_node(struct ice_sched_node *node, u8 srl_layer) -{ - if (srl_layer > node->tx_sched_layer) - return node->children[0]; - else if (srl_layer < node->tx_sched_layer) - /* Node can't be created without a parent. It will always - * have a valid parent except root node. - */ - return node->parent; - else - return node; + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_sched_rm_rl_profile - remove RL profile ID + * ice_cfg_agg_bw_alloc - config aggregator BW alloc * @pi: port information structure - * @layer_num: layer number where profiles are saved - * @profile_type: profile type like EIR, CIR, or SRL - * @profile_id: profile ID to remove + * @agg_id: aggregator ID + * @ena_tcmap: enabled TC map + * @rl_type: rate limit type CIR/EIR + * @bw_alloc: array of BW alloc * - * This function removes rate limit profile from layer 'layer_num' of type - * 'profile_type' and profile ID as 'profile_id'. The caller needs to hold - * scheduler lock. + * This function configures the BW allocation of passed in aggregator for + * enabled traffic class(s). */ -static enum ice_status -ice_sched_rm_rl_profile(struct ice_port_info *pi, u8 layer_num, u8 profile_type, - u16 profile_id) +enum ice_status +ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap, + enum ice_rl_type rl_type, u8 *bw_alloc) { - struct ice_aqc_rl_profile_info *rl_prof_elem; + struct ice_sched_agg_info *agg_info; + bool agg_id_present = false; enum ice_status status = ICE_SUCCESS; + struct ice_hw *hw = pi->hw; + u8 tc; - /* Check the existing list for RL profile */ - LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num], - ice_aqc_rl_profile_info, list_entry) - if (rl_prof_elem->profile.flags == profile_type && - LE16_TO_CPU(rl_prof_elem->profile.profile_id) == - profile_id) { - if (rl_prof_elem->prof_id_ref) - rl_prof_elem->prof_id_ref--; - - /* Remove old profile ID from database */ - status = ice_sched_del_rl_profile(pi->hw, rl_prof_elem); - if (status && status != ICE_ERR_IN_USE) - ice_debug(pi->hw, ICE_DBG_SCHED, - "Remove rl profile failed\n"); + ice_acquire_lock(&pi->sched_lock); + LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, + list_entry) + if (agg_info->agg_id == agg_id) { + agg_id_present = true; break; } - if (status == ICE_ERR_IN_USE) - status = ICE_SUCCESS; + if (!agg_id_present) { + status = ICE_ERR_PARAM; + goto exit_cfg_agg_bw_alloc; + } + + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + struct ice_sched_node *tc_node, *agg_node; + + if (!ice_is_tc_ena(ena_tcmap, tc)) + continue; + + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; + + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + continue; + + status = ice_sched_cfg_node_bw_alloc(hw, agg_node, rl_type, + bw_alloc[tc]); + if (status) + break; + status = ice_sched_save_agg_bw_alloc(pi, agg_id, tc, rl_type, + bw_alloc[tc]); + if (status) + break; + } + +exit_cfg_agg_bw_alloc: + ice_release_lock(&pi->sched_lock); return status; } /** - * ice_sched_set_node_bw_dflt - set node's bandwidth limit to default - * @pi: port information structure - * @node: pointer to node structure - * @rl_type: rate limit type min, max, or shared - * @layer_num: layer number where RL profiles are saved + * ice_sched_calc_wakeup - calculate RL profile wakeup parameter + * @hw: pointer to the HW struct + * @bw: bandwidth in Kbps * - * This function configures node element's BW rate limit profile ID of - * type CIR, EIR, or SRL to default. This function needs to be called - * with the scheduler lock held. + * This function calculates the wakeup parameter of RL profile. */ -static enum ice_status -ice_sched_set_node_bw_dflt(struct ice_port_info *pi, - struct ice_sched_node *node, - enum ice_rl_type rl_type, u8 layer_num) +static u16 ice_sched_calc_wakeup(struct ice_hw *hw, s32 bw) { - enum ice_status status; - struct ice_hw *hw; - u8 profile_type; - u16 rl_prof_id; - u16 old_id; + s64 bytes_per_sec, wakeup_int, wakeup_a, wakeup_b, wakeup_f; + s32 wakeup_f_int; + u16 wakeup = 0; - hw = pi->hw; - switch (rl_type) { - case ICE_MIN_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR; - rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID; - break; - case ICE_MAX_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR; - rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID; - break; - case ICE_SHARED_BW: - profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL; - /* No SRL is configured for default case */ - rl_prof_id = ICE_SCHED_NO_SHARED_RL_PROF_ID; - break; - default: - return ICE_ERR_PARAM; - } - /* Save existing RL prof ID for later clean up */ - old_id = ice_sched_get_node_rl_prof_id(node, rl_type); - /* Configure BW scheduling parameters */ - status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id); - if (status) - return status; + /* Get the wakeup integer value */ + bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE); + wakeup_int = DIV_64BIT(hw->psm_clk_freq, bytes_per_sec); + if (wakeup_int > 63) { + wakeup = (u16)((1 << 15) | wakeup_int); + } else { + /* Calculate fraction value up to 4 decimals + * Convert Integer value to a constant multiplier + */ + wakeup_b = (s64)ICE_RL_PROF_MULTIPLIER * wakeup_int; + wakeup_a = DIV_64BIT((s64)ICE_RL_PROF_MULTIPLIER * + hw->psm_clk_freq, bytes_per_sec); - /* Remove stale RL profile ID */ - if (old_id == ICE_SCHED_DFLT_RL_PROF_ID || - old_id == ICE_SCHED_INVAL_PROF_ID) - return ICE_SUCCESS; + /* Get Fraction value */ + wakeup_f = wakeup_a - wakeup_b; - return ice_sched_rm_rl_profile(pi, layer_num, profile_type, old_id); + /* Round up the Fractional value via Ceil(Fractional value) */ + if (wakeup_f > DIV_64BIT(ICE_RL_PROF_MULTIPLIER, 2)) + wakeup_f += 1; + + wakeup_f_int = (s32)DIV_64BIT(wakeup_f * ICE_RL_PROF_FRACTION, + ICE_RL_PROF_MULTIPLIER); + wakeup |= (u16)(wakeup_int << 9); + wakeup |= (u16)(0x1ff & wakeup_f_int); + } + + return wakeup; } /** - * ice_sched_set_eir_srl_excl - set EIR/SRL exclusiveness - * @pi: port information structure - * @node: pointer to node structure - * @layer_num: layer number where rate limit profiles are saved - * @rl_type: rate limit type min, max, or shared - * @bw: bandwidth value + * ice_sched_bw_to_rl_profile - convert BW to profile parameters + * @hw: pointer to the HW struct + * @bw: bandwidth in Kbps + * @profile: profile parameters to return * - * This function prepares node element's bandwidth to SRL or EIR exclusively. - * EIR BW and Shared BW profiles are mutually exclusive and hence only one of - * them may be set for any given element. This function needs to be called - * with the scheduler lock held. + * This function converts the BW to profile structure format. */ static enum ice_status -ice_sched_set_eir_srl_excl(struct ice_port_info *pi, - struct ice_sched_node *node, - u8 layer_num, enum ice_rl_type rl_type, u32 bw) +ice_sched_bw_to_rl_profile(struct ice_hw *hw, u32 bw, + struct ice_aqc_rl_profile_elem *profile) { - if (rl_type == ICE_SHARED_BW) { - /* SRL node passed in this case, it may be different node */ - if (bw == ICE_SCHED_DFLT_BW) - /* SRL being removed, ice_sched_cfg_node_bw_lmt() - * enables EIR to default. EIR is not set in this - * case, so no additional action is required. - */ - return ICE_SUCCESS; + enum ice_status status = ICE_ERR_PARAM; + s64 bytes_per_sec, ts_rate, mv_tmp; + bool found = false; + s32 encode = 0; + s64 mv = 0; + s32 i; - /* SRL being configured, set EIR to default here. - * ice_sched_cfg_node_bw_lmt() disables EIR when it - * configures SRL - */ - return ice_sched_set_node_bw_dflt(pi, node, ICE_MAX_BW, - layer_num); - } else if (rl_type == ICE_MAX_BW && - node->info.data.valid_sections & ICE_AQC_ELEM_VALID_SHARED) { - /* Remove Shared profile. Set default shared BW call - * removes shared profile for a node. - */ - return ice_sched_set_node_bw_dflt(pi, node, - ICE_SHARED_BW, - layer_num); - } - return ICE_SUCCESS; -} + /* Bw settings range is from 0.5Mb/sec to 100Gb/sec */ + if (bw < ICE_SCHED_MIN_BW || bw > ICE_SCHED_MAX_BW) + return status; -/** - * ice_sched_set_node_bw - set node's bandwidth - * @pi: port information structure - * @node: tree node - * @rl_type: rate limit type min, max, or shared - * @bw: bandwidth in Kbps - Kilo bits per sec - * @layer_num: layer number - * - * This function adds new profile corresponding to requested BW, configures - * node's RL profile ID of type CIR, EIR, or SRL, and removes old profile - * ID from local database. The caller needs to hold scheduler lock. - */ -static enum ice_status -ice_sched_set_node_bw(struct ice_port_info *pi, struct ice_sched_node *node, - enum ice_rl_type rl_type, u32 bw, u8 layer_num) -{ - struct ice_aqc_rl_profile_info *rl_prof_info; - enum ice_status status = ICE_ERR_PARAM; - struct ice_hw *hw = pi->hw; - u16 old_id, rl_prof_id; + /* Bytes per second from Kbps */ + bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE); - rl_prof_info = ice_sched_add_rl_profile(pi, rl_type, bw, layer_num); - if (!rl_prof_info) - return status; + /* encode is 6 bits but really useful are 5 bits */ + for (i = 0; i < 64; i++) { + u64 pow_result = BIT_ULL(i); - rl_prof_id = LE16_TO_CPU(rl_prof_info->profile.profile_id); + ts_rate = DIV_64BIT((s64)hw->psm_clk_freq, + pow_result * ICE_RL_PROF_TS_MULTIPLIER); + if (ts_rate <= 0) + continue; - /* Save existing RL prof ID for later clean up */ - old_id = ice_sched_get_node_rl_prof_id(node, rl_type); - /* Configure BW scheduling parameters */ - status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id); - if (status) - return status; + /* Multiplier value */ + mv_tmp = DIV_64BIT(bytes_per_sec * ICE_RL_PROF_MULTIPLIER, + ts_rate); - /* New changes has been applied */ - /* Increment the profile ID reference count */ - rl_prof_info->prof_id_ref++; + /* Round to the nearest ICE_RL_PROF_MULTIPLIER */ + mv = round_up_64bit(mv_tmp, ICE_RL_PROF_MULTIPLIER); - /* Check for old ID removal */ - if ((old_id == ICE_SCHED_DFLT_RL_PROF_ID && rl_type != ICE_SHARED_BW) || - old_id == ICE_SCHED_INVAL_PROF_ID || old_id == rl_prof_id) - return ICE_SUCCESS; + /* First multiplier value greater than the given + * accuracy bytes + */ + if (mv > ICE_RL_PROF_ACCURACY_BYTES) { + encode = i; + found = true; + break; + } + } + if (found) { + u16 wm; - return ice_sched_rm_rl_profile(pi, layer_num, - rl_prof_info->profile.flags, - old_id); + wm = ice_sched_calc_wakeup(hw, bw); + profile->rl_multiply = CPU_TO_LE16(mv); + profile->wake_up_calc = CPU_TO_LE16(wm); + profile->rl_encode = CPU_TO_LE16(encode); + status = ICE_SUCCESS; + } else { + status = ICE_ERR_DOES_NOT_EXIST; + } + + return status; } /** - * ice_sched_set_node_bw_lmt - set node's BW limit + * ice_sched_add_rl_profile - add RL profile * @pi: port information structure - * @node: tree node - * @rl_type: rate limit type min, max, or shared + * @rl_type: type of rate limit BW - min, max, or shared * @bw: bandwidth in Kbps - Kilo bits per sec + * @layer_num: specifies in which layer to create profile * - * It updates node's BW limit parameters like BW RL profile ID of type CIR, - * EIR, or SRL. The caller needs to hold scheduler lock. + * This function first checks the existing list for corresponding BW + * parameter. If it exists, it returns the associated profile otherwise + * it creates a new rate limit profile for requested BW, and adds it to + * the HW DB and local list. It returns the new profile or null on error. + * The caller needs to hold the scheduler lock. */ -enum ice_status -ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node, - enum ice_rl_type rl_type, u32 bw) +static struct ice_aqc_rl_profile_info * +ice_sched_add_rl_profile(struct ice_port_info *pi, + enum ice_rl_type rl_type, u32 bw, u8 layer_num) { - struct ice_sched_node *cfg_node = node; + struct ice_aqc_rl_profile_info *rl_prof_elem; + u16 profiles_added = 0, num_profiles = 1; + struct ice_aqc_rl_profile_elem *buf; enum ice_status status; - struct ice_hw *hw; - u8 layer_num; + u8 profile_type; + + if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM) + return NULL; + switch (rl_type) { + case ICE_MIN_BW: + profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR; + break; + case ICE_MAX_BW: + profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR; + break; + case ICE_SHARED_BW: + profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL; + break; + default: + return NULL; + } if (!pi) - return ICE_ERR_PARAM; + return NULL; hw = pi->hw; - /* Remove unused RL profile IDs from HW and SW DB */ - ice_sched_rm_unused_rl_prof(pi); - layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, - node->tx_sched_layer); - if (layer_num >= hw->num_tx_sched_layers) - return ICE_ERR_PARAM; + LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num], + ice_aqc_rl_profile_info, list_entry) + if ((rl_prof_elem->profile.flags & ICE_AQC_RL_PROFILE_TYPE_M) == + profile_type && rl_prof_elem->bw == bw) + /* Return existing profile ID info */ + return rl_prof_elem; - if (rl_type == ICE_SHARED_BW) { - /* SRL node may be different */ - cfg_node = ice_sched_get_srl_node(node, layer_num); - if (!cfg_node) - return ICE_ERR_CFG; - } - /* EIR BW and Shared BW profiles are mutually exclusive and - * hence only one of them may be set for any given element - */ - status = ice_sched_set_eir_srl_excl(pi, cfg_node, layer_num, rl_type, - bw); - if (status) - return status; - if (bw == ICE_SCHED_DFLT_BW) - return ice_sched_set_node_bw_dflt(pi, cfg_node, rl_type, - layer_num); - return ice_sched_set_node_bw(pi, cfg_node, rl_type, bw, layer_num); -} + /* Create new profile ID */ + rl_prof_elem = (struct ice_aqc_rl_profile_info *) + ice_malloc(hw, sizeof(*rl_prof_elem)); -/** - * ice_sched_set_node_bw_dflt_lmt - set node's BW limit to default - * @pi: port information structure - * @node: pointer to node structure - * @rl_type: rate limit type min, max, or shared - * - * This function configures node element's BW rate limit profile ID of - * type CIR, EIR, or SRL to default. This function needs to be called - * with the scheduler lock held. - */ -static enum ice_status -ice_sched_set_node_bw_dflt_lmt(struct ice_port_info *pi, - struct ice_sched_node *node, - enum ice_rl_type rl_type) -{ - return ice_sched_set_node_bw_lmt(pi, node, rl_type, - ICE_SCHED_DFLT_BW); -} + if (!rl_prof_elem) + return NULL; -/** - * ice_sched_validate_srl_node - Check node for SRL applicability - * @node: sched node to configure - * @sel_layer: selected SRL layer - * - * This function checks if the SRL can be applied to a selceted layer node on - * behalf of the requested node (first argument). This function needs to be - * called with scheduler lock held. - */ -static enum ice_status -ice_sched_validate_srl_node(struct ice_sched_node *node, u8 sel_layer) -{ - /* SRL profiles are not available on all layers. Check if the - * SRL profile can be applied to a node above or below the - * requested node. SRL configuration is possible only if the - * selected layer's node has single child. - */ - if (sel_layer == node->tx_sched_layer || - ((sel_layer == node->tx_sched_layer + 1) && - node->num_children == 1) || - ((sel_layer == node->tx_sched_layer - 1) && - (node->parent && node->parent->num_children == 1))) - return ICE_SUCCESS; + status = ice_sched_bw_to_rl_profile(hw, bw, &rl_prof_elem->profile); + if (status != ICE_SUCCESS) + goto exit_add_rl_prof; - return ICE_ERR_CFG; + rl_prof_elem->bw = bw; + /* layer_num is zero relative, and fw expects level from 1 to 9 */ + rl_prof_elem->profile.level = layer_num + 1; + rl_prof_elem->profile.flags = profile_type; + rl_prof_elem->profile.max_burst_size = CPU_TO_LE16(hw->max_burst_size); + + /* Create new entry in HW DB */ + buf = &rl_prof_elem->profile; + status = ice_aq_add_rl_profile(hw, num_profiles, buf, sizeof(*buf), + &profiles_added, NULL); + if (status || profiles_added != num_profiles) + goto exit_add_rl_prof; + + /* Good entry - add in the list */ + rl_prof_elem->prof_id_ref = 0; + LIST_ADD(&rl_prof_elem->list_entry, &pi->rl_prof_list[layer_num]); + return rl_prof_elem; + +exit_add_rl_prof: + ice_free(hw, rl_prof_elem); + return NULL; } /** - * ice_sched_set_q_bw_lmt - sets queue BW limit - * @pi: port information structure - * @q_id: queue ID (leaf node TEID) - * @rl_type: min, max, or shared - * @bw: bandwidth in Kbps + * ice_sched_cfg_node_bw_lmt - configure node sched params + * @hw: pointer to the HW struct + * @node: sched node to configure + * @rl_type: rate limit type CIR, EIR, or shared + * @rl_prof_id: rate limit profile ID * - * This function sets BW limit of queue scheduling node. + * This function configures node element's BW limit. */ static enum ice_status -ice_sched_set_q_bw_lmt(struct ice_port_info *pi, u32 q_id, - enum ice_rl_type rl_type, u32 bw) +ice_sched_cfg_node_bw_lmt(struct ice_hw *hw, struct ice_sched_node *node, + enum ice_rl_type rl_type, u16 rl_prof_id) { - enum ice_status status = ICE_ERR_PARAM; - struct ice_sched_node *node; - - ice_acquire_lock(&pi->sched_lock); - - node = ice_sched_find_node_by_teid(pi->root, q_id); - if (!node) { - ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong q_id\n"); - goto exit_q_bw_lmt; - } - - /* Return error if it is not a leaf node */ - if (node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF) - goto exit_q_bw_lmt; + struct ice_aqc_txsched_elem_data buf; + struct ice_aqc_txsched_elem *data; - /* SRL bandwidth layer selection */ - if (rl_type == ICE_SHARED_BW) { - u8 sel_layer; /* selected layer */ + buf = node->info; + data = &buf.data; + switch (rl_type) { + case ICE_MIN_BW: + data->valid_sections |= ICE_AQC_ELEM_VALID_CIR; + data->cir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id); + break; + case ICE_MAX_BW: + /* EIR BW and Shared BW profiles are mutually exclusive and + * hence only one of them may be set for any given element + */ + if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED) + return ICE_ERR_CFG; + data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; + data->eir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id); + break; + case ICE_SHARED_BW: + /* Check for removing shared BW */ + if (rl_prof_id == ICE_SCHED_NO_SHARED_RL_PROF_ID) { + /* remove shared profile */ + data->valid_sections &= ~ICE_AQC_ELEM_VALID_SHARED; + data->srl_id = 0; /* clear SRL field */ - sel_layer = ice_sched_get_rl_prof_layer(pi, rl_type, - node->tx_sched_layer); - if (sel_layer >= pi->hw->num_tx_sched_layers) { - status = ICE_ERR_PARAM; - goto exit_q_bw_lmt; + /* enable back EIR to default profile */ + data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; + data->eir_bw.bw_profile_idx = + CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID); + break; } - status = ice_sched_validate_srl_node(node, sel_layer); - if (status) - goto exit_q_bw_lmt; + /* EIR BW and Shared BW profiles are mutually exclusive and + * hence only one of them may be set for any given element + */ + if ((data->valid_sections & ICE_AQC_ELEM_VALID_EIR) && + (LE16_TO_CPU(data->eir_bw.bw_profile_idx) != + ICE_SCHED_DFLT_RL_PROF_ID)) + return ICE_ERR_CFG; + /* EIR BW is set to default, disable it */ + data->valid_sections &= ~ICE_AQC_ELEM_VALID_EIR; + /* Okay to enable shared BW now */ + data->valid_sections |= ICE_AQC_ELEM_VALID_SHARED; + data->srl_id = CPU_TO_LE16(rl_prof_id); + break; + default: + /* Unknown rate limit type */ + return ICE_ERR_PARAM; } - - if (bw == ICE_SCHED_DFLT_BW) - status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type); - else - status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw); - -exit_q_bw_lmt: - ice_release_lock(&pi->sched_lock); - return status; -} - -/** - * ice_cfg_q_bw_lmt - configure queue BW limit - * @pi: port information structure - * @q_id: queue ID (leaf node TEID) - * @rl_type: min, max, or shared - * @bw: bandwidth in Kbps - * - * This function configures BW limit of queue scheduling node. - */ -enum ice_status -ice_cfg_q_bw_lmt(struct ice_port_info *pi, u32 q_id, enum ice_rl_type rl_type, - u32 bw) -{ - return ice_sched_set_q_bw_lmt(pi, q_id, rl_type, bw); + + /* Configure element */ + return ice_sched_update_elem(hw, node, &buf); } /** - * ice_cfg_q_bw_dflt_lmt - configure queue BW default limit - * @pi: port information structure - * @q_id: queue ID (leaf node TEID) - * @rl_type: min, max, or shared + * ice_sched_get_node_rl_prof_id - get node's rate limit profile ID + * @node: sched node + * @rl_type: rate limit type * - * This function configures BW default limit of queue scheduling node. + * If existing profile matches, it returns the corresponding rate + * limit profile ID, otherwise it returns an invalid ID as error. */ -enum ice_status -ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u32 q_id, - enum ice_rl_type rl_type) +static u16 +ice_sched_get_node_rl_prof_id(struct ice_sched_node *node, + enum ice_rl_type rl_type) { - return ice_sched_set_q_bw_lmt(pi, q_id, rl_type, ICE_SCHED_DFLT_BW); + u16 rl_prof_id = ICE_SCHED_INVAL_PROF_ID; + struct ice_aqc_txsched_elem *data; + + data = &node->info.data; + switch (rl_type) { + case ICE_MIN_BW: + if (data->valid_sections & ICE_AQC_ELEM_VALID_CIR) + rl_prof_id = LE16_TO_CPU(data->cir_bw.bw_profile_idx); + break; + case ICE_MAX_BW: + if (data->valid_sections & ICE_AQC_ELEM_VALID_EIR) + rl_prof_id = LE16_TO_CPU(data->eir_bw.bw_profile_idx); + break; + case ICE_SHARED_BW: + if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED) + rl_prof_id = LE16_TO_CPU(data->srl_id); + break; + default: + break; + } + + return rl_prof_id; } /** - * ice_sched_save_tc_node_bw - save TC node BW limit + * ice_sched_get_rl_prof_layer - selects rate limit profile creation layer * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * @bw: bandwidth in Kbps + * @rl_type: type of rate limit BW - min, max, or shared + * @layer_index: layer index * - * This function saves the modified values of bandwidth settings for later - * replay purpose (restore) after reset. + * This function returns requested profile creation layer. */ -static enum ice_status -ice_sched_save_tc_node_bw(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static u8 +ice_sched_get_rl_prof_layer(struct ice_port_info *pi, enum ice_rl_type rl_type, + u8 layer_index) { struct ice_hw *hw = pi->hw; - if (tc >= ICE_MAX_TRAFFIC_CLASS) - return ICE_ERR_PARAM; + if (layer_index >= hw->num_tx_sched_layers) + return ICE_SCHED_INVAL_LAYER_NUM; switch (rl_type) { case ICE_MIN_BW: - ice_set_clear_cir_bw(&hw->tc_node_bw_t_info[tc], bw); + if (hw->layer_info[layer_index].max_cir_rl_profiles) + return layer_index; break; case ICE_MAX_BW: - ice_set_clear_eir_bw(&hw->tc_node_bw_t_info[tc], bw); + if (hw->layer_info[layer_index].max_eir_rl_profiles) + return layer_index; break; case ICE_SHARED_BW: - ice_set_clear_shared_bw(&hw->tc_node_bw_t_info[tc], bw); + /* if current layer doesn't support SRL profile creation + * then try a layer up or down. + */ + if (hw->layer_info[layer_index].max_srl_profiles) + return layer_index; + else if (layer_index < hw->num_tx_sched_layers - 1 && + hw->layer_info[layer_index + 1].max_srl_profiles) + return layer_index + 1; + else if (layer_index > 0 && + hw->layer_info[layer_index - 1].max_srl_profiles) + return layer_index - 1; break; default: - return ICE_ERR_PARAM; + break; } - return ICE_SUCCESS; + return ICE_SCHED_INVAL_LAYER_NUM; } /** - * ice_sched_set_tc_node_bw_lmt - sets TC node BW limit - * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * @bw: bandwidth in Kbps + * ice_sched_get_srl_node - get shared rate limit node + * @node: tree node + * @srl_layer: shared rate limit layer * - * This function configures bandwidth limit of TC node. + * This function returns SRL node to be used for shared rate limit purpose. + * The caller needs to hold scheduler lock. */ -static enum ice_status -ice_sched_set_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static struct ice_sched_node * +ice_sched_get_srl_node(struct ice_sched_node *node, u8 srl_layer) { - enum ice_status status = ICE_ERR_PARAM; - struct ice_sched_node *tc_node; - - if (tc >= ICE_MAX_TRAFFIC_CLASS) - return status; - ice_acquire_lock(&pi->sched_lock); - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - goto exit_set_tc_node_bw; - if (bw == ICE_SCHED_DFLT_BW) - status = ice_sched_set_node_bw_dflt_lmt(pi, tc_node, rl_type); + if (srl_layer > node->tx_sched_layer) + return node->children[0]; + else if (srl_layer < node->tx_sched_layer) + /* Node can't be created without a parent. It will always + * have a valid parent except root node. + */ + return node->parent; else - status = ice_sched_set_node_bw_lmt(pi, tc_node, rl_type, bw); - if (!status) - status = ice_sched_save_tc_node_bw(pi, tc, rl_type, bw); - -exit_set_tc_node_bw: - ice_release_lock(&pi->sched_lock); - return status; + return node; } /** - * ice_cfg_tc_node_bw_lmt - configure TC node BW limit + * ice_sched_rm_rl_profile - remove RL profile ID * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * @bw: bandwidth in Kbps + * @layer_num: layer number where profiles are saved + * @profile_type: profile type like EIR, CIR, or SRL + * @profile_id: profile ID to remove * - * This function configures BW limit of TC node. - * Note: The minimum guaranteed reservation is done via DCBX. + * This function removes rate limit profile from layer 'layer_num' of type + * 'profile_type' and profile ID as 'profile_id'. The caller needs to hold + * scheduler lock. */ -enum ice_status -ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static enum ice_status +ice_sched_rm_rl_profile(struct ice_port_info *pi, u8 layer_num, u8 profile_type, + u16 profile_id) { - return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, bw); -} + struct ice_aqc_rl_profile_info *rl_prof_elem; + enum ice_status status = ICE_SUCCESS; -/** - * ice_cfg_tc_node_bw_dflt_lmt - configure TC node BW default limit - * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * - * This function configures BW default limit of TC node. - */ -enum ice_status -ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type) -{ - return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, ICE_SCHED_DFLT_BW); + if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM) + return ICE_ERR_PARAM; + /* Check the existing list for RL profile */ + LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num], + ice_aqc_rl_profile_info, list_entry) + if ((rl_prof_elem->profile.flags & ICE_AQC_RL_PROFILE_TYPE_M) == + profile_type && + LE16_TO_CPU(rl_prof_elem->profile.profile_id) == + profile_id) { + if (rl_prof_elem->prof_id_ref) + rl_prof_elem->prof_id_ref--; + + /* Remove old profile ID from database */ + status = ice_sched_del_rl_profile(pi->hw, rl_prof_elem); + if (status && status != ICE_ERR_IN_USE) + ice_debug(pi->hw, ICE_DBG_SCHED, "Remove rl profile failed\n"); + break; + } + if (status == ICE_ERR_IN_USE) + status = ICE_SUCCESS; + return status; } /** - * ice_sched_save_tc_node_bw_alloc - save TC node's BW alloc information + * ice_sched_set_node_bw_dflt - set node's bandwidth limit to default * @pi: port information structure - * @tc: traffic class - * @rl_type: rate limit type min or max - * @bw_alloc: Bandwidth allocation information + * @node: pointer to node structure + * @rl_type: rate limit type min, max, or shared + * @layer_num: layer number where RL profiles are saved * - * Save BW alloc information of VSI type node for post replay use. + * This function configures node element's BW rate limit profile ID of + * type CIR, EIR, or SRL to default. This function needs to be called + * with the scheduler lock held. */ static enum ice_status -ice_sched_save_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u16 bw_alloc) +ice_sched_set_node_bw_dflt(struct ice_port_info *pi, + struct ice_sched_node *node, + enum ice_rl_type rl_type, u8 layer_num) { - struct ice_hw *hw = pi->hw; + enum ice_status status; + struct ice_hw *hw; + u8 profile_type; + u16 rl_prof_id; + u16 old_id; - if (tc >= ICE_MAX_TRAFFIC_CLASS) - return ICE_ERR_PARAM; + hw = pi->hw; switch (rl_type) { case ICE_MIN_BW: - ice_set_clear_cir_bw_alloc(&hw->tc_node_bw_t_info[tc], - bw_alloc); + profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR; + rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID; break; case ICE_MAX_BW: - ice_set_clear_eir_bw_alloc(&hw->tc_node_bw_t_info[tc], - bw_alloc); + profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR; + rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID; + break; + case ICE_SHARED_BW: + profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL; + /* No SRL is configured for default case */ + rl_prof_id = ICE_SCHED_NO_SHARED_RL_PROF_ID; break; default: return ICE_ERR_PARAM; } + /* Save existing RL prof ID for later clean up */ + old_id = ice_sched_get_node_rl_prof_id(node, rl_type); + /* Configure BW scheduling parameters */ + status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id); + if (status) + return status; + + /* Remove stale RL profile ID */ + if (old_id == ICE_SCHED_DFLT_RL_PROF_ID || + old_id == ICE_SCHED_INVAL_PROF_ID) + return ICE_SUCCESS; + + return ice_sched_rm_rl_profile(pi, layer_num, profile_type, old_id); +} + +/** + * ice_sched_set_eir_srl_excl - set EIR/SRL exclusiveness + * @pi: port information structure + * @node: pointer to node structure + * @layer_num: layer number where rate limit profiles are saved + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth value + * + * This function prepares node element's bandwidth to SRL or EIR exclusively. + * EIR BW and Shared BW profiles are mutually exclusive and hence only one of + * them may be set for any given element. This function needs to be called + * with the scheduler lock held. + */ +static enum ice_status +ice_sched_set_eir_srl_excl(struct ice_port_info *pi, + struct ice_sched_node *node, + u8 layer_num, enum ice_rl_type rl_type, u32 bw) +{ + if (rl_type == ICE_SHARED_BW) { + /* SRL node passed in this case, it may be different node */ + if (bw == ICE_SCHED_DFLT_BW) + /* SRL being removed, ice_sched_cfg_node_bw_lmt() + * enables EIR to default. EIR is not set in this + * case, so no additional action is required. + */ + return ICE_SUCCESS; + + /* SRL being configured, set EIR to default here. + * ice_sched_cfg_node_bw_lmt() disables EIR when it + * configures SRL + */ + return ice_sched_set_node_bw_dflt(pi, node, ICE_MAX_BW, + layer_num); + } else if (rl_type == ICE_MAX_BW && + node->info.data.valid_sections & ICE_AQC_ELEM_VALID_SHARED) { + /* Remove Shared profile. Set default shared BW call + * removes shared profile for a node. + */ + return ice_sched_set_node_bw_dflt(pi, node, + ICE_SHARED_BW, + layer_num); + } return ICE_SUCCESS; } /** - * ice_sched_set_tc_node_bw_alloc - set TC node BW alloc + * ice_sched_set_node_bw - set node's bandwidth * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * @bw_alloc: bandwidth alloc + * @node: tree node + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth in Kbps - Kilo bits per sec + * @layer_num: layer number * - * This function configures bandwidth alloc of TC node, also saves the - * changed settings for replay purpose, and return success if it succeeds - * in modifying bandwidth alloc setting. + * This function adds new profile corresponding to requested BW, configures + * node's RL profile ID of type CIR, EIR, or SRL, and removes old profile + * ID from local database. The caller needs to hold scheduler lock. */ static enum ice_status -ice_sched_set_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u8 bw_alloc) +ice_sched_set_node_bw(struct ice_port_info *pi, struct ice_sched_node *node, + enum ice_rl_type rl_type, u32 bw, u8 layer_num) { + struct ice_aqc_rl_profile_info *rl_prof_info; enum ice_status status = ICE_ERR_PARAM; - struct ice_sched_node *tc_node; + struct ice_hw *hw = pi->hw; + u16 old_id, rl_prof_id; - if (tc >= ICE_MAX_TRAFFIC_CLASS) + rl_prof_info = ice_sched_add_rl_profile(pi, rl_type, bw, layer_num); + if (!rl_prof_info) return status; - ice_acquire_lock(&pi->sched_lock); - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - goto exit_set_tc_node_bw_alloc; - status = ice_sched_cfg_node_bw_alloc(pi->hw, tc_node, rl_type, - bw_alloc); + + rl_prof_id = LE16_TO_CPU(rl_prof_info->profile.profile_id); + + /* Save existing RL prof ID for later clean up */ + old_id = ice_sched_get_node_rl_prof_id(node, rl_type); + /* Configure BW scheduling parameters */ + status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id); if (status) - goto exit_set_tc_node_bw_alloc; - status = ice_sched_save_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc); + return status; -exit_set_tc_node_bw_alloc: - ice_release_lock(&pi->sched_lock); - return status; -} + /* New changes has been applied */ + /* Increment the profile ID reference count */ + rl_prof_info->prof_id_ref++; -/** - * ice_cfg_tc_node_bw_alloc - configure TC node BW alloc - * @pi: port information structure - * @tc: TC number - * @rl_type: min or max - * @bw_alloc: bandwidth alloc - * - * This function configures BW limit of TC node. - * Note: The minimum guaranteed reservation is done via DCBX. - */ -enum ice_status -ice_cfg_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, - enum ice_rl_type rl_type, u8 bw_alloc) -{ - return ice_sched_set_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc); + /* Check for old ID removal */ + if ((old_id == ICE_SCHED_DFLT_RL_PROF_ID && rl_type != ICE_SHARED_BW) || + old_id == ICE_SCHED_INVAL_PROF_ID || old_id == rl_prof_id) + return ICE_SUCCESS; + + return ice_sched_rm_rl_profile(pi, layer_num, + rl_prof_info->profile.flags & + ICE_AQC_RL_PROFILE_TYPE_M, old_id); } /** - * ice_sched_set_agg_bw_dflt_lmt - set aggregator node's BW limit to default + * ice_sched_set_node_bw_lmt - set node's BW limit * @pi: port information structure - * @vsi_handle: software VSI handle + * @node: tree node + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth in Kbps - Kilo bits per sec * - * This function retrieves the aggregator ID based on VSI ID and TC, - * and sets node's BW limit to default. This function needs to be - * called with the scheduler lock held. + * It updates node's BW limit parameters like BW RL profile ID of type CIR, + * EIR, or SRL. The caller needs to hold scheduler lock. */ -enum ice_status -ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle) +static enum ice_status +ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node, + enum ice_rl_type rl_type, u32 bw) { - struct ice_vsi_ctx *vsi_ctx; - enum ice_status status = ICE_SUCCESS; - u8 tc; + struct ice_sched_node *cfg_node = node; + enum ice_status status; - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + struct ice_hw *hw; + u8 layer_num; + + if (!pi) return ICE_ERR_PARAM; - vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); - if (!vsi_ctx) + hw = pi->hw; + /* Remove unused RL profile IDs from HW and SW DB */ + ice_sched_rm_unused_rl_prof(pi); + layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, + node->tx_sched_layer); + if (layer_num >= hw->num_tx_sched_layers) return ICE_ERR_PARAM; - ice_for_each_traffic_class(tc) { - struct ice_sched_node *node; - - node = vsi_ctx->sched.ag_node[tc]; - if (!node) - continue; - - /* Set min profile to default */ - status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MIN_BW); - if (status) - break; - - /* Set max profile to default */ - status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MAX_BW); - if (status) - break; - - /* Remove shared profile, if there is one */ - status = ice_sched_set_node_bw_dflt_lmt(pi, node, - ICE_SHARED_BW); - if (status) - break; + if (rl_type == ICE_SHARED_BW) { + /* SRL node may be different */ + cfg_node = ice_sched_get_srl_node(node, layer_num); + if (!cfg_node) + return ICE_ERR_CFG; } - - return status; + /* EIR BW and Shared BW profiles are mutually exclusive and + * hence only one of them may be set for any given element + */ + status = ice_sched_set_eir_srl_excl(pi, cfg_node, layer_num, rl_type, + bw); + if (status) + return status; + if (bw == ICE_SCHED_DFLT_BW) + return ice_sched_set_node_bw_dflt(pi, cfg_node, rl_type, + layer_num); + return ice_sched_set_node_bw(pi, cfg_node, rl_type, bw, layer_num); } /** - * ice_sched_get_node_by_id_type - get node from ID type + * ice_sched_set_node_bw_dflt_lmt - set node's BW limit to default * @pi: port information structure - * @id: identifier - * @agg_type: type of aggregator - * @tc: traffic class + * @node: pointer to node structure + * @rl_type: rate limit type min, max, or shared * - * This function returns node identified by ID of type aggregator, and - * based on traffic class (TC). This function needs to be called with - * the scheduler lock held. + * This function configures node element's BW rate limit profile ID of + * type CIR, EIR, or SRL to default. This function needs to be called + * with the scheduler lock held. */ -static struct ice_sched_node * -ice_sched_get_node_by_id_type(struct ice_port_info *pi, u32 id, - enum ice_agg_type agg_type, u8 tc) +static enum ice_status +ice_sched_set_node_bw_dflt_lmt(struct ice_port_info *pi, + struct ice_sched_node *node, + enum ice_rl_type rl_type) { - struct ice_sched_node *node = NULL; - struct ice_sched_node *child_node; - - switch (agg_type) { - case ICE_AGG_TYPE_VSI: { - struct ice_vsi_ctx *vsi_ctx; - u16 vsi_handle = (u16)id; + return ice_sched_set_node_bw_lmt(pi, node, rl_type, + ICE_SCHED_DFLT_BW); +} - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) - break; - /* Get sched_vsi_info */ - vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); - if (!vsi_ctx) - break; - node = vsi_ctx->sched.vsi_node[tc]; - break; - } +/** + * ice_sched_validate_srl_node - Check node for SRL applicability + * @node: sched node to configure + * @sel_layer: selected SRL layer + * + * This function checks if the SRL can be applied to a selceted layer node on + * behalf of the requested node (first argument). This function needs to be + * called with scheduler lock held. + */ +static enum ice_status +ice_sched_validate_srl_node(struct ice_sched_node *node, u8 sel_layer) +{ + /* SRL profiles are not available on all layers. Check if the + * SRL profile can be applied to a node above or below the + * requested node. SRL configuration is possible only if the + * selected layer's node has single child. + */ + if (sel_layer == node->tx_sched_layer || + ((sel_layer == node->tx_sched_layer + 1) && + node->num_children == 1) || + ((sel_layer == node->tx_sched_layer - 1) && + (node->parent && node->parent->num_children == 1))) + return ICE_SUCCESS; - case ICE_AGG_TYPE_AGG: { - struct ice_sched_node *tc_node; + return ICE_ERR_CFG; +} - tc_node = ice_sched_get_tc_node(pi, tc); - if (tc_node) - node = ice_sched_get_agg_node(pi->hw, tc_node, id); +/** + * ice_sched_save_q_bw - save queue node's BW information + * @q_ctx: queue context structure + * @rl_type: rate limit type min, max, or shared + * @bw: bandwidth in Kbps - Kilo bits per sec + * + * Save BW information of queue type node for post replay use. + */ +static enum ice_status +ice_sched_save_q_bw(struct ice_q_ctx *q_ctx, enum ice_rl_type rl_type, u32 bw) +{ + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw(&q_ctx->bw_t_info, bw); break; - } - - case ICE_AGG_TYPE_Q: - /* The current implementation allows single queue to modify */ - node = ice_sched_get_node(pi, id); + case ICE_MAX_BW: + ice_set_clear_eir_bw(&q_ctx->bw_t_info, bw); break; - - case ICE_AGG_TYPE_QG: - /* The current implementation allows single qg to modify */ - child_node = ice_sched_get_node(pi, id); - if (!child_node) - break; - node = child_node->parent; + case ICE_SHARED_BW: + ice_set_clear_shared_bw(&q_ctx->bw_t_info, bw); break; - default: - break; + return ICE_ERR_PARAM; } - - return node; + return ICE_SUCCESS; } /** - * ice_sched_set_node_bw_lmt_per_tc - set node BW limit per TC + * ice_sched_set_q_bw_lmt - sets queue BW limit * @pi: port information structure - * @id: ID (software VSI handle or AGG ID) - * @agg_type: aggregator type (VSI or AGG type node) + * @vsi_handle: sw VSI handle * @tc: traffic class - * @rl_type: min or max + * @q_handle: software queue handle + * @rl_type: min, max, or shared * @bw: bandwidth in Kbps * - * This function sets BW limit of VSI or Aggregator scheduling node - * based on TC information from passed in argument BW. + * This function sets BW limit of queue scheduling node. */ -enum ice_status -ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id, - enum ice_agg_type agg_type, u8 tc, - enum ice_rl_type rl_type, u32 bw) +static enum ice_status +ice_sched_set_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + u16 q_handle, enum ice_rl_type rl_type, u32 bw) { enum ice_status status = ICE_ERR_PARAM; struct ice_sched_node *node; + struct ice_q_ctx *q_ctx; - if (!pi) - return status; - - if (rl_type == ICE_UNKNOWN_BW) - return status; - + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; ice_acquire_lock(&pi->sched_lock); - node = ice_sched_get_node_by_id_type(pi, id, agg_type, tc); + q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handle); + if (!q_ctx) + goto exit_q_bw_lmt; + node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid); if (!node) { - ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong id, agg type, or tc\n"); - goto exit_set_node_bw_lmt_per_tc; + ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong q_teid\n"); + goto exit_q_bw_lmt; + } + + /* Return error if it is not a leaf node */ + if (node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF) + goto exit_q_bw_lmt; + + /* SRL bandwidth layer selection */ + if (rl_type == ICE_SHARED_BW) { + u8 sel_layer; /* selected layer */ + + sel_layer = ice_sched_get_rl_prof_layer(pi, rl_type, + node->tx_sched_layer); + if (sel_layer >= pi->hw->num_tx_sched_layers) { + status = ICE_ERR_PARAM; + goto exit_q_bw_lmt; + } + status = ice_sched_validate_srl_node(node, sel_layer); + if (status) + goto exit_q_bw_lmt; } + if (bw == ICE_SCHED_DFLT_BW) status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type); else status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw); -exit_set_node_bw_lmt_per_tc: + if (!status) + status = ice_sched_save_q_bw(q_ctx, rl_type, bw); + +exit_q_bw_lmt: ice_release_lock(&pi->sched_lock); return status; } /** - * ice_sched_validate_vsi_srl_node - validate VSI SRL node + * ice_cfg_q_bw_lmt - configure queue BW limit * @pi: port information structure - * @vsi_handle: software VSI handle + * @vsi_handle: sw VSI handle + * @tc: traffic class + * @q_handle: software queue handle + * @rl_type: min, max, or shared + * @bw: bandwidth in Kbps * - * This function validates SRL node of the VSI node if available SRL layer is - * different than the VSI node layer on all TC(s).This function needs to be - * called with scheduler lock held. + * This function configures BW limit of queue scheduling node. */ -static enum ice_status -ice_sched_validate_vsi_srl_node(struct ice_port_info *pi, u16 vsi_handle) +enum ice_status +ice_cfg_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + u16 q_handle, enum ice_rl_type rl_type, u32 bw) { - u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM; - u8 tc; - - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) - return ICE_ERR_PARAM; - - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - struct ice_sched_node *tc_node, *vsi_node; - enum ice_rl_type rl_type = ICE_SHARED_BW; - enum ice_status status; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - vsi_node = ice_sched_get_vsi_node(pi->hw, tc_node, vsi_handle); - if (!vsi_node) - continue; - - /* SRL bandwidth layer selection */ - if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) { - u8 node_layer = vsi_node->tx_sched_layer; - u8 layer_num; - - layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, - node_layer); - if (layer_num >= pi->hw->num_tx_sched_layers) - return ICE_ERR_PARAM; - sel_layer = layer_num; - } - - status = ice_sched_validate_srl_node(vsi_node, sel_layer); - if (status) - return status; - } - return ICE_SUCCESS; + return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type, + bw); } /** - * ice_sched_set_vsi_bw_shared_lmt - set VSI BW shared limit + * ice_cfg_q_bw_dflt_lmt - configure queue BW default limit * @pi: port information structure - * @vsi_handle: software VSI handle - * @bw: bandwidth in Kbps + * @vsi_handle: sw VSI handle + * @tc: traffic class + * @q_handle: software queue handle + * @rl_type: min, max, or shared * - * This function Configures shared rate limiter(SRL) of all VSI type nodes - * across all traffic classes for VSI matching handle. When BW value of - * ICE_SCHED_DFLT_BW is passed, it removes the SRL from the node. + * This function configures BW default limit of queue scheduling node. */ enum ice_status -ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, - u32 bw) +ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc, + u16 q_handle, enum ice_rl_type rl_type) { - enum ice_status status = ICE_SUCCESS; - u8 tc; + return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type, + ICE_SCHED_DFLT_BW); +} - if (!pi) +/** + * ice_sched_save_tc_node_bw - save TC node BW limit + * @pi: port information structure + * @tc: TC number + * @rl_type: min or max + * @bw: bandwidth in Kbps + * + * This function saves the modified values of bandwidth settings for later + * replay purpose (restore) after reset. + */ +static enum ice_status +ice_sched_save_tc_node_bw(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u32 bw) +{ + if (tc >= ICE_MAX_TRAFFIC_CLASS) return ICE_ERR_PARAM; - - if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw(&pi->tc_node_bw_t_info[tc], bw); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw(&pi->tc_node_bw_t_info[tc], bw); + break; + case ICE_SHARED_BW: + ice_set_clear_shared_bw(&pi->tc_node_bw_t_info[tc], bw); + break; + default: return ICE_ERR_PARAM; - - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_validate_vsi_srl_node(pi, vsi_handle); - if (status) - goto exit_set_vsi_bw_shared_lmt; - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - struct ice_sched_node *tc_node, *vsi_node; - enum ice_rl_type rl_type = ICE_SHARED_BW; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - vsi_node = ice_sched_get_vsi_node(pi->hw, tc_node, vsi_handle); - if (!vsi_node) - continue; - - if (bw == ICE_SCHED_DFLT_BW) - /* It removes existing SRL from the node */ - status = ice_sched_set_node_bw_dflt_lmt(pi, vsi_node, - rl_type); - else - status = ice_sched_set_node_bw_lmt(pi, vsi_node, - rl_type, bw); - if (status) - break; - status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw); - if (status) - break; } - -exit_set_vsi_bw_shared_lmt: - ice_release_lock(&pi->sched_lock); - return status; + return ICE_SUCCESS; } /** - * ice_sched_validate_agg_srl_node - validate AGG SRL node + * ice_sched_set_tc_node_bw_lmt - sets TC node BW limit * @pi: port information structure - * @agg_id: aggregator ID + * @tc: TC number + * @rl_type: min or max + * @bw: bandwidth in Kbps * - * This function validates SRL node of the AGG node if available SRL layer is - * different than the AGG node layer on all TC(s).This function needs to be - * called with scheduler lock held. + * This function configures bandwidth limit of TC node. */ static enum ice_status -ice_sched_validate_agg_srl_node(struct ice_port_info *pi, u32 agg_id) +ice_sched_set_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u32 bw) { - u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM; - struct ice_sched_agg_info *agg_info; - bool agg_id_present = false; - enum ice_status status = ICE_SUCCESS; - u8 tc; - - LIST_FOR_EACH_ENTRY(agg_info, &pi->hw->agg_list, ice_sched_agg_info, - list_entry) - if (agg_info->agg_id == agg_id) { - agg_id_present = true; - break; - } - if (!agg_id_present) - return ICE_ERR_PARAM; - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - struct ice_sched_node *tc_node, *agg_node; - enum ice_rl_type rl_type = ICE_SHARED_BW; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - agg_node = ice_sched_get_agg_node(pi->hw, tc_node, agg_id); - if (!agg_node) - continue; - /* SRL bandwidth layer selection */ - if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) { - u8 node_layer = agg_node->tx_sched_layer; - u8 layer_num; + enum ice_status status = ICE_ERR_PARAM; + struct ice_sched_node *tc_node; - layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, - node_layer); - if (layer_num >= pi->hw->num_tx_sched_layers) - return ICE_ERR_PARAM; - sel_layer = layer_num; - } + if (tc >= ICE_MAX_TRAFFIC_CLASS) + return status; + ice_acquire_lock(&pi->sched_lock); + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + goto exit_set_tc_node_bw; + if (bw == ICE_SCHED_DFLT_BW) + status = ice_sched_set_node_bw_dflt_lmt(pi, tc_node, rl_type); + else + status = ice_sched_set_node_bw_lmt(pi, tc_node, rl_type, bw); + if (!status) + status = ice_sched_save_tc_node_bw(pi, tc, rl_type, bw); - status = ice_sched_validate_srl_node(agg_node, sel_layer); - if (status) - break; - } +exit_set_tc_node_bw: + ice_release_lock(&pi->sched_lock); return status; } /** - * ice_sched_set_agg_bw_shared_lmt - set aggregator BW shared limit + * ice_cfg_tc_node_bw_lmt - configure TC node BW limit + * @pi: port information structure + * @tc: TC number + * @rl_type: min or max + * @bw: bandwidth in Kbps + * + * This function configures BW limit of TC node. + * Note: The minimum guaranteed reservation is done via DCBX. + */ +enum ice_status +ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u32 bw) +{ + return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, bw); +} + +/** + * ice_cfg_tc_node_bw_dflt_lmt - configure TC node BW default limit * @pi: port information structure - * @agg_id: aggregator ID - * @bw: bandwidth in Kbps + * @tc: TC number + * @rl_type: min or max * - * This function configures the shared rate limiter(SRL) of all aggregator type - * nodes across all traffic classes for aggregator matching agg_id. When - * BW value of ICE_SCHED_DFLT_BW is passed, it removes SRL from the - * node(s). + * This function configures BW default limit of TC node. */ enum ice_status -ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw) +ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type) { - struct ice_sched_agg_info *agg_info; - struct ice_sched_agg_info *tmp; - bool agg_id_present = false; - enum ice_status status = ICE_SUCCESS; - u8 tc; + return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, ICE_SCHED_DFLT_BW); +} - if (!pi) +/** + * ice_sched_save_tc_node_bw_alloc - save TC node's BW alloc information + * @pi: port information structure + * @tc: traffic class + * @rl_type: rate limit type min or max + * @bw_alloc: Bandwidth allocation information + * + * Save BW alloc information of VSI type node for post replay use. + */ +static enum ice_status +ice_sched_save_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u16 bw_alloc) +{ + if (tc >= ICE_MAX_TRAFFIC_CLASS) + return ICE_ERR_PARAM; + switch (rl_type) { + case ICE_MIN_BW: + ice_set_clear_cir_bw_alloc(&pi->tc_node_bw_t_info[tc], + bw_alloc); + break; + case ICE_MAX_BW: + ice_set_clear_eir_bw_alloc(&pi->tc_node_bw_t_info[tc], + bw_alloc); + break; + default: return ICE_ERR_PARAM; - - ice_acquire_lock(&pi->sched_lock); - status = ice_sched_validate_agg_srl_node(pi, agg_id); - if (status) - goto exit_agg_bw_shared_lmt; - - LIST_FOR_EACH_ENTRY_SAFE(agg_info, tmp, &pi->hw->agg_list, - ice_sched_agg_info, list_entry) - if (agg_info->agg_id == agg_id) { - agg_id_present = true; - break; - } - - if (!agg_id_present) { - status = ICE_ERR_PARAM; - goto exit_agg_bw_shared_lmt; } + return ICE_SUCCESS; +} - /* Return success if no nodes are present across TC */ - ice_for_each_traffic_class(tc) { - enum ice_rl_type rl_type = ICE_SHARED_BW; - struct ice_sched_node *tc_node, *agg_node; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - continue; - - agg_node = ice_sched_get_agg_node(pi->hw, tc_node, agg_id); - if (!agg_node) - continue; +/** + * ice_sched_set_tc_node_bw_alloc - set TC node BW alloc + * @pi: port information structure + * @tc: TC number + * @rl_type: min or max + * @bw_alloc: bandwidth alloc + * + * This function configures bandwidth alloc of TC node, also saves the + * changed settings for replay purpose, and return success if it succeeds + * in modifying bandwidth alloc setting. + */ +static enum ice_status +ice_sched_set_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u8 bw_alloc) +{ + enum ice_status status = ICE_ERR_PARAM; + struct ice_sched_node *tc_node; - if (bw == ICE_SCHED_DFLT_BW) - /* It removes existing SRL from the node */ - status = ice_sched_set_node_bw_dflt_lmt(pi, agg_node, - rl_type); - else - status = ice_sched_set_node_bw_lmt(pi, agg_node, - rl_type, bw); - if (status) - break; - status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw); - if (status) - break; - } + if (tc >= ICE_MAX_TRAFFIC_CLASS) + return status; + ice_acquire_lock(&pi->sched_lock); + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + goto exit_set_tc_node_bw_alloc; + status = ice_sched_cfg_node_bw_alloc(pi->hw, tc_node, rl_type, + bw_alloc); + if (status) + goto exit_set_tc_node_bw_alloc; + status = ice_sched_save_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc); -exit_agg_bw_shared_lmt: +exit_set_tc_node_bw_alloc: ice_release_lock(&pi->sched_lock); return status; } /** - * ice_sched_cfg_sibl_node_prio - configure node sibling priority - * @hw: pointer to the hw struct - * @node: sched node to configure - * @priority: sibling priority + * ice_cfg_tc_node_bw_alloc - configure TC node BW alloc + * @pi: port information structure + * @tc: TC number + * @rl_type: min or max + * @bw_alloc: bandwidth alloc * - * This function configures node element's sibling priority only. This - * function needs to be called with scheduler lock held. + * This function configures BW limit of TC node. + * Note: The minimum guaranteed reservation is done via DCBX. */ enum ice_status -ice_sched_cfg_sibl_node_prio(struct ice_hw *hw, struct ice_sched_node *node, - u8 priority) +ice_cfg_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc, + enum ice_rl_type rl_type, u8 bw_alloc) { - struct ice_aqc_txsched_elem_data buf; - struct ice_aqc_txsched_elem *data; - enum ice_status status; - - buf = node->info; - data = &buf.data; - data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC; - priority = (priority << ICE_AQC_ELEM_GENERIC_PRIO_S) & - ICE_AQC_ELEM_GENERIC_PRIO_M; - data->generic &= ~ICE_AQC_ELEM_GENERIC_PRIO_M; - data->generic |= priority; - - /* Configure element */ - status = ice_sched_update_elem(hw, node, &buf); - return status; + return ice_sched_set_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc); } /** - * ice_sched_cfg_node_bw_alloc - configure node bw weight/alloc params - * @hw: pointer to the hw struct - * @node: sched node to configure - * @rl_type: rate limit type cir, eir, or shared - * @bw_alloc: bw weight/allocation + * ice_sched_set_agg_bw_dflt_lmt - set aggregator node's BW limit to default + * @pi: port information structure + * @vsi_handle: software VSI handle * - * This function configures node element's bw allocation. + * This function retrieves the aggregator ID based on VSI ID and TC, + * and sets node's BW limit to default. This function needs to be + * called with the scheduler lock held. */ enum ice_status -ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node, - enum ice_rl_type rl_type, u8 bw_alloc) +ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle) { - struct ice_aqc_txsched_elem_data buf; - struct ice_aqc_txsched_elem *data; - enum ice_status status; + struct ice_vsi_ctx *vsi_ctx; + enum ice_status status = ICE_SUCCESS; + u8 tc; - buf = node->info; - data = &buf.data; - if (rl_type == ICE_MIN_BW) { - data->valid_sections |= ICE_AQC_ELEM_VALID_CIR; - data->cir_bw.bw_alloc = CPU_TO_LE16(bw_alloc); - } else if (rl_type == ICE_MAX_BW) { - data->valid_sections |= ICE_AQC_ELEM_VALID_EIR; - data->eir_bw.bw_alloc = CPU_TO_LE16(bw_alloc); - } else { + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; + vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); + if (!vsi_ctx) return ICE_ERR_PARAM; + + ice_for_each_traffic_class(tc) { + struct ice_sched_node *node; + + node = vsi_ctx->sched.ag_node[tc]; + if (!node) + continue; + + /* Set min profile to default */ + status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MIN_BW); + if (status) + break; + + /* Set max profile to default */ + status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MAX_BW); + if (status) + break; + + /* Remove shared profile, if there is one */ + status = ice_sched_set_node_bw_dflt_lmt(pi, node, + ICE_SHARED_BW); + if (status) + break; } - /* Configure element */ - status = ice_sched_update_elem(hw, node, &buf); return status; } /** - * ice_sched_add_agg_cfg - create an aggregator node + * ice_sched_get_node_by_id_type - get node from ID type * @pi: port information structure - * @agg_id: aggregator id - * @tc: TC number + * @id: identifier + * @agg_type: type of aggregator + * @tc: traffic class * - * This function creates an aggregator node and intermediate nodes if required - * for the given TC + * This function returns node identified by ID of type aggregator, and + * based on traffic class (TC). This function needs to be called with + * the scheduler lock held. */ -enum ice_status -ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc) +static struct ice_sched_node * +ice_sched_get_node_by_id_type(struct ice_port_info *pi, u32 id, + enum ice_agg_type agg_type, u8 tc) { - struct ice_sched_node *parent, *agg_node, *tc_node; - u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; - enum ice_status status = ICE_SUCCESS; - struct ice_hw *hw = pi->hw; - u32 first_node_teid; - u16 num_nodes_added; - u8 i, aggl; - - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - return ICE_ERR_CFG; - - agg_node = ice_sched_get_agg_node(hw, tc_node, agg_id); - /* Does Agg node already exist ? */ - if (agg_node) - return status; - - aggl = ice_sched_get_agg_layer(hw); + struct ice_sched_node *node = NULL; + struct ice_sched_node *child_node; - /* need one node in Agg layer */ - num_nodes[aggl] = 1; + switch (agg_type) { + case ICE_AGG_TYPE_VSI: { + struct ice_vsi_ctx *vsi_ctx; + u16 vsi_handle = (u16)id; - /* Check whether the intermediate nodes have space to add the - * new agg. If they are full, then SW needs to allocate a new - * intermediate node on those layers - */ - for (i = hw->sw_entry_point_layer; i < aggl; i++) { - parent = ice_sched_get_first_node(hw, tc_node, i); + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + break; + /* Get sched_vsi_info */ + vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle); + if (!vsi_ctx) + break; + node = vsi_ctx->sched.vsi_node[tc]; + break; + } - /* scan all the siblings */ - while (parent) { - if (parent->num_children < hw->max_children[i]) - break; - parent = parent->sibling; - } + case ICE_AGG_TYPE_AGG: { + struct ice_sched_node *tc_node; - /* all the nodes are full, reserve one for this layer */ - if (!parent) - num_nodes[i]++; + tc_node = ice_sched_get_tc_node(pi, tc); + if (tc_node) + node = ice_sched_get_agg_node(pi, tc_node, id); + break; } - /* add the agg node */ - parent = tc_node; - for (i = hw->sw_entry_point_layer; i <= aggl; i++) { - if (!parent) - return ICE_ERR_CFG; + case ICE_AGG_TYPE_Q: + /* The current implementation allows single queue to modify */ + node = ice_sched_get_node(pi, id); + break; - status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i, - num_nodes[i], - &first_node_teid, - &num_nodes_added); - if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added) - return ICE_ERR_CFG; + case ICE_AGG_TYPE_QG: + /* The current implementation allows single qg to modify */ + child_node = ice_sched_get_node(pi, id); + if (!child_node) + break; + node = child_node->parent; + break; - /* The newly added node can be a new parent for the next - * layer nodes - */ - if (num_nodes_added) { - parent = ice_sched_find_node_by_teid(tc_node, - first_node_teid); - /* register the aggregator id with the agg node */ - if (parent && i == aggl) - parent->agg_id = agg_id; - } else { - parent = parent->children[0]; - } + default: + break; } - return ICE_SUCCESS; + return node; } /** - * ice_sched_is_agg_inuse - check whether the agg is in use or not + * ice_sched_set_node_bw_lmt_per_tc - set node BW limit per TC * @pi: port information structure - * @node: node pointer + * @id: ID (software VSI handle or AGG ID) + * @agg_type: aggregator type (VSI or AGG type node) + * @tc: traffic class + * @rl_type: min or max + * @bw: bandwidth in Kbps * - * This function checks whether the agg is attached with any vsi or not. + * This function sets BW limit of VSI or Aggregator scheduling node + * based on TC information from passed in argument BW. */ -static bool -ice_sched_is_agg_inuse(struct ice_port_info *pi, struct ice_sched_node *node) +enum ice_status +ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id, + enum ice_agg_type agg_type, u8 tc, + enum ice_rl_type rl_type, u32 bw) { - u8 vsil, i; + enum ice_status status = ICE_ERR_PARAM; + struct ice_sched_node *node; - vsil = ice_sched_get_vsi_layer(pi->hw); - if (node->tx_sched_layer < vsil - 1) { - for (i = 0; i < node->num_children; i++) - if (ice_sched_is_agg_inuse(pi, node->children[i])) - return true; - return false; - } else { - return node->num_children ? true : false; + if (!pi) + return status; + + if (rl_type == ICE_UNKNOWN_BW) + return status; + + ice_acquire_lock(&pi->sched_lock); + node = ice_sched_get_node_by_id_type(pi, id, agg_type, tc); + if (!node) { + ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong id, agg type, or tc\n"); + goto exit_set_node_bw_lmt_per_tc; } + if (bw == ICE_SCHED_DFLT_BW) + status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type); + else + status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw); + +exit_set_node_bw_lmt_per_tc: + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_sched_rm_agg_cfg - remove the aggregator node + * ice_sched_validate_vsi_srl_node - validate VSI SRL node * @pi: port information structure - * @agg_id: aggregator id - * @tc: TC number + * @vsi_handle: software VSI handle * - * This function removes the aggregator node and intermediate nodes if any - * from the given TC + * This function validates SRL node of the VSI node if available SRL layer is + * different than the VSI node layer on all TC(s).This function needs to be + * called with scheduler lock held. */ -enum ice_status -ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc) +static enum ice_status +ice_sched_validate_vsi_srl_node(struct ice_port_info *pi, u16 vsi_handle) { - struct ice_sched_node *tc_node, *agg_node; - struct ice_hw *hw = pi->hw; + u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM; + u8 tc; - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - return ICE_ERR_CFG; + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; - agg_node = ice_sched_get_agg_node(hw, tc_node, agg_id); - if (!agg_node) - return ICE_ERR_DOES_NOT_EXIST; + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + struct ice_sched_node *tc_node, *vsi_node; + enum ice_rl_type rl_type = ICE_SHARED_BW; + enum ice_status status; - /* Can't remove the agg node if it has children */ - if (ice_sched_is_agg_inuse(pi, agg_node)) - return ICE_ERR_IN_USE; + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; - /* need to remove the whole subtree if agg node is the - * only child. - */ - while (agg_node->tx_sched_layer > hw->sw_entry_point_layer) { - struct ice_sched_node *parent = agg_node->parent; + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); + if (!vsi_node) + continue; - if (!parent) - return ICE_ERR_CFG; + /* SRL bandwidth layer selection */ + if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) { + u8 node_layer = vsi_node->tx_sched_layer; + u8 layer_num; - if (parent->num_children > 1) - break; + layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, + node_layer); + if (layer_num >= pi->hw->num_tx_sched_layers) + return ICE_ERR_PARAM; + sel_layer = layer_num; + } - agg_node = parent; + status = ice_sched_validate_srl_node(vsi_node, sel_layer); + if (status) + return status; } - - ice_free_sched_node(pi, agg_node); return ICE_SUCCESS; } /** - * ice_sched_get_free_vsi_parent - Find a free parent node in agg subtree - * @hw: pointer to the hw struct - * @node: pointer to a child node - * @num_nodes: num nodes count array + * ice_sched_set_vsi_bw_shared_lmt - set VSI BW shared limit + * @pi: port information structure + * @vsi_handle: software VSI handle + * @bw: bandwidth in Kbps * - * This function walks through the aggregator subtree to find a free parent - * node + * This function Configures shared rate limiter(SRL) of all VSI type nodes + * across all traffic classes for VSI matching handle. When BW value of + * ICE_SCHED_DFLT_BW is passed, it removes the SRL from the node. */ -static struct ice_sched_node * -ice_sched_get_free_vsi_parent(struct ice_hw *hw, struct ice_sched_node *node, - u16 *num_nodes) +enum ice_status +ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, + u32 bw) { - u8 l = node->tx_sched_layer; - u8 vsil, i; - - vsil = ice_sched_get_vsi_layer(hw); - - /* Is it VSI parent layer ? */ - if (l == vsil - 1) - return (node->num_children < hw->max_children[l]) ? node : NULL; - - /* We have intermediate nodes. Let's walk through the subtree. If the - * intermediate node has space to add a new node then clear the count - */ - if (node->num_children < hw->max_children[l]) - num_nodes[l] = 0; - /* The below recursive call is intentional and wouldn't go more than - * 2 or 3 iterations. - */ + enum ice_status status = ICE_SUCCESS; + u8 tc; - for (i = 0; i < node->num_children; i++) { - struct ice_sched_node *parent; + if (!pi) + return ICE_ERR_PARAM; - parent = ice_sched_get_free_vsi_parent(hw, node->children[i], - num_nodes); - if (parent) - return parent; - } + if (!ice_is_vsi_valid(pi->hw, vsi_handle)) + return ICE_ERR_PARAM; - return NULL; -} + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_validate_vsi_srl_node(pi, vsi_handle); + if (status) + goto exit_set_vsi_bw_shared_lmt; + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + struct ice_sched_node *tc_node, *vsi_node; + enum ice_rl_type rl_type = ICE_SHARED_BW; -/** - * ice_sched_update_new_parent - update the new parent in SW DB - * @new_parent: pointer to a new parent node - * @node: pointer to a child node - * - * This function removes the child from the old parent and adds it to a new - * parent - */ -static void -ice_sched_update_parent(struct ice_sched_node *new_parent, - struct ice_sched_node *node) -{ - struct ice_sched_node *old_parent; - u8 i, j; + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; - old_parent = node->parent; + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); + if (!vsi_node) + continue; - /* update the old parent children */ - for (i = 0; i < old_parent->num_children; i++) - if (old_parent->children[i] == node) { - for (j = i + 1; j < old_parent->num_children; j++) - old_parent->children[j - 1] = - old_parent->children[j]; - old_parent->num_children--; + if (bw == ICE_SCHED_DFLT_BW) + /* It removes existing SRL from the node */ + status = ice_sched_set_node_bw_dflt_lmt(pi, vsi_node, + rl_type); + else + status = ice_sched_set_node_bw_lmt(pi, vsi_node, + rl_type, bw); + if (status) break; - } - - /* now move the node to a new parent */ - new_parent->children[new_parent->num_children++] = node; - node->parent = new_parent; - node->info.parent_teid = new_parent->info.node_teid; + status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw); + if (status) + break; + } + +exit_set_vsi_bw_shared_lmt: + ice_release_lock(&pi->sched_lock); + return status; } /** - * ice_sched_move_nodes - move child nodes to a given parent + * ice_sched_validate_agg_srl_node - validate AGG SRL node * @pi: port information structure - * @parent: pointer to parent node - * @num_items: number of child nodes to be moved - * @list: pointer to child node teids + * @agg_id: aggregator ID * - * This function move the child nodes to a given parent. + * This function validates SRL node of the AGG node if available SRL layer is + * different than the AGG node layer on all TC(s).This function needs to be + * called with scheduler lock held. */ static enum ice_status -ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent, - u16 num_items, u32 *list) +ice_sched_validate_agg_srl_node(struct ice_port_info *pi, u32 agg_id) { - struct ice_aqc_move_elem *buf; - struct ice_sched_node *node; + u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM; + struct ice_sched_agg_info *agg_info; + bool agg_id_present = false; enum ice_status status = ICE_SUCCESS; - struct ice_hw *hw; - u16 grps_movd = 0; - u8 i; - - hw = pi->hw; + u8 tc; - if (!parent || !num_items) + LIST_FOR_EACH_ENTRY(agg_info, &pi->hw->agg_list, ice_sched_agg_info, + list_entry) + if (agg_info->agg_id == agg_id) { + agg_id_present = true; + break; + } + if (!agg_id_present) return ICE_ERR_PARAM; + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + struct ice_sched_node *tc_node, *agg_node; + enum ice_rl_type rl_type = ICE_SHARED_BW; - /* Does parent have enough space */ - if (parent->num_children + num_items >= - hw->max_children[parent->tx_sched_layer]) - return ICE_ERR_AQ_FULL; - - buf = (struct ice_aqc_move_elem *) ice_malloc(hw, sizeof(*buf)); - if (!buf) - return ICE_ERR_NO_MEMORY; + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; - for (i = 0; i < num_items; i++) { - node = ice_sched_find_node_by_teid(pi->root, list[i]); - if (!node) { - status = ICE_ERR_PARAM; - goto move_err_exit; - } + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + continue; + /* SRL bandwidth layer selection */ + if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) { + u8 node_layer = agg_node->tx_sched_layer; + u8 layer_num; - buf->hdr.src_parent_teid = node->info.parent_teid; - buf->hdr.dest_parent_teid = parent->info.node_teid; - buf->teid[0] = node->info.node_teid; - buf->hdr.num_elems = CPU_TO_LE16(1); - status = ice_aq_move_sched_elems(hw, 1, buf, sizeof(*buf), - &grps_movd, NULL); - if (status && grps_movd != 1) { - status = ICE_ERR_CFG; - goto move_err_exit; + layer_num = ice_sched_get_rl_prof_layer(pi, rl_type, + node_layer); + if (layer_num >= pi->hw->num_tx_sched_layers) + return ICE_ERR_PARAM; + sel_layer = layer_num; } - /* update the SW DB */ - ice_sched_update_parent(parent, node); + status = ice_sched_validate_srl_node(agg_node, sel_layer); + if (status) + break; } - -move_err_exit: - ice_free(hw, buf); return status; } /** - * ice_sched_move_vsi_to_agg - move VSI to aggregator node + * ice_sched_set_agg_bw_shared_lmt - set aggregator BW shared limit * @pi: port information structure - * @vsi_handle: software VSI handle - * @agg_id: aggregator id - * @tc: TC number + * @agg_id: aggregator ID + * @bw: bandwidth in Kbps * - * This function moves a VSI to an aggregator node or its subtree. - * Intermediate nodes may be created if required. + * This function configures the shared rate limiter(SRL) of all aggregator type + * nodes across all traffic classes for aggregator matching agg_id. When + * BW value of ICE_SCHED_DFLT_BW is passed, it removes SRL from the + * node(s). */ enum ice_status -ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id, - u8 tc) +ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw) { - struct ice_sched_node *vsi_node, *agg_node, *tc_node, *parent; - u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; - u32 first_node_teid, vsi_teid; - enum ice_status status; - u16 num_nodes_added; - u8 aggl, vsil, i; + struct ice_sched_agg_info *agg_info; + struct ice_sched_agg_info *tmp; + bool agg_id_present = false; + enum ice_status status = ICE_SUCCESS; + u8 tc; - tc_node = ice_sched_get_tc_node(pi, tc); - if (!tc_node) - return ICE_ERR_CFG; + if (!pi) + return ICE_ERR_PARAM; - agg_node = ice_sched_get_agg_node(pi->hw, tc_node, agg_id); - if (!agg_node) - return ICE_ERR_DOES_NOT_EXIST; + ice_acquire_lock(&pi->sched_lock); + status = ice_sched_validate_agg_srl_node(pi, agg_id); + if (status) + goto exit_agg_bw_shared_lmt; - vsi_node = ice_sched_get_vsi_node(pi->hw, tc_node, vsi_handle); - if (!vsi_node) - return ICE_ERR_DOES_NOT_EXIST; + LIST_FOR_EACH_ENTRY_SAFE(agg_info, tmp, &pi->hw->agg_list, + ice_sched_agg_info, list_entry) + if (agg_info->agg_id == agg_id) { + agg_id_present = true; + break; + } - aggl = ice_sched_get_agg_layer(pi->hw); - vsil = ice_sched_get_vsi_layer(pi->hw); + if (!agg_id_present) { + status = ICE_ERR_PARAM; + goto exit_agg_bw_shared_lmt; + } - /* initialize intermediate node count to 1 between agg and VSI layers */ - for (i = aggl + 1; i < vsil; i++) - num_nodes[i] = 1; + /* Return success if no nodes are present across TC */ + ice_for_each_traffic_class(tc) { + enum ice_rl_type rl_type = ICE_SHARED_BW; + struct ice_sched_node *tc_node, *agg_node; - /* Check whether the agg subtree has any free node to add the VSI */ - for (i = 0; i < agg_node->num_children; i++) { - parent = ice_sched_get_free_vsi_parent(pi->hw, - agg_node->children[i], - num_nodes); - if (parent) - goto move_nodes; - } + tc_node = ice_sched_get_tc_node(pi, tc); + if (!tc_node) + continue; - /* add new nodes */ - parent = agg_node; - for (i = aggl + 1; i < vsil; i++) { - status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i, - num_nodes[i], - &first_node_teid, - &num_nodes_added); - if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added) - return ICE_ERR_CFG; + agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id); + if (!agg_node) + continue; - /* The newly added node can be a new parent for the next - * layer nodes - */ - if (num_nodes_added) - parent = ice_sched_find_node_by_teid(tc_node, - first_node_teid); + if (bw == ICE_SCHED_DFLT_BW) + /* It removes existing SRL from the node */ + status = ice_sched_set_node_bw_dflt_lmt(pi, agg_node, + rl_type); else - parent = parent->children[0]; - - if (!parent) - return ICE_ERR_CFG; + status = ice_sched_set_node_bw_lmt(pi, agg_node, + rl_type, bw); + if (status) + break; + status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw); + if (status) + break; } -move_nodes: - vsi_teid = LE32_TO_CPU(vsi_node->info.node_teid); - return ice_sched_move_nodes(pi, parent, 1, &vsi_teid); +exit_agg_bw_shared_lmt: + ice_release_lock(&pi->sched_lock); + return status; +} + +/** + * ice_sched_cfg_sibl_node_prio - configure node sibling priority + * @pi: port information structure + * @node: sched node to configure + * @priority: sibling priority + * + * This function configures node element's sibling priority only. This + * function needs to be called with scheduler lock held. + */ +enum ice_status +ice_sched_cfg_sibl_node_prio(struct ice_port_info *pi, + struct ice_sched_node *node, u8 priority) +{ + struct ice_aqc_txsched_elem_data buf; + struct ice_aqc_txsched_elem *data; + struct ice_hw *hw = pi->hw; + enum ice_status status; + + if (!hw) + return ICE_ERR_PARAM; + buf = node->info; + data = &buf.data; + data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC; + priority = (priority << ICE_AQC_ELEM_GENERIC_PRIO_S) & + ICE_AQC_ELEM_GENERIC_PRIO_M; + data->generic &= ~ICE_AQC_ELEM_GENERIC_PRIO_M; + data->generic |= priority; + + /* Configure element */ + status = ice_sched_update_elem(hw, node, &buf); + return status; } /** @@ -4990,16 +5135,15 @@ enum ice_status ice_cfg_rl_burst_size(struct ice_hw *hw, u32 bytes) if (bytes < ICE_MIN_BURST_SIZE_ALLOWED || bytes > ICE_MAX_BURST_SIZE_ALLOWED) return ICE_ERR_PARAM; - if (bytes <= ICE_MAX_BURST_SIZE_BYTE_GRANULARITY) { - /* byte granularity case */ + if (ice_round_to_num(bytes, 64) <= + ICE_MAX_BURST_SIZE_64_BYTE_GRANULARITY) { + /* 64 byte granularity case */ /* Disable MSB granularity bit */ - burst_size_to_prog = ICE_BYTE_GRANULARITY; - /* round number to nearest 256 granularity */ - bytes = ice_round_to_num(bytes, 256); - /* check rounding doesn't go beyond allowed */ - if (bytes > ICE_MAX_BURST_SIZE_BYTE_GRANULARITY) - bytes = ICE_MAX_BURST_SIZE_BYTE_GRANULARITY; - burst_size_to_prog |= (u16)bytes; + burst_size_to_prog = ICE_64_BYTE_GRANULARITY; + /* round number to nearest 64 byte granularity */ + bytes = ice_round_to_num(bytes, 64); + /* The value is in 64 byte chunks */ + burst_size_to_prog |= (u16)(bytes / 64); } else { /* k bytes granularity case */ /* Enable MSB granularity bit */ @@ -5016,7 +5160,7 @@ enum ice_status ice_cfg_rl_burst_size(struct ice_hw *hw, u32 bytes) return ICE_SUCCESS; } -/* +/** * ice_sched_replay_node_prio - re-configure node priority * @hw: pointer to the HW struct * @node: sched node to configure @@ -5128,7 +5272,7 @@ ice_sched_replay_agg_bw(struct ice_hw *hw, struct ice_sched_agg_info *agg_info) status = ICE_ERR_PARAM; break; } - agg_node = ice_sched_get_agg_node(hw, tc_node, + agg_node = ice_sched_get_agg_node(hw->port_info, tc_node, agg_info->agg_id); if (!agg_node) { status = ICE_ERR_PARAM; @@ -5180,7 +5324,7 @@ void ice_sched_replay_agg(struct ice_hw *hw) ice_acquire_lock(&pi->sched_lock); LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info, - list_entry) { + list_entry) /* replay aggregator (re-create aggregator node) */ if (!ice_cmp_bitmap(agg_info->tc_bitmap, agg_info->replay_tc_bitmap, @@ -5189,8 +5333,7 @@ void ice_sched_replay_agg(struct ice_hw *hw) ICE_MAX_TRAFFIC_CLASS); enum ice_status status; - ice_zero_bitmap(replay_bitmap, - sizeof(replay_bitmap) * BITS_PER_BYTE); + ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS); ice_sched_get_ena_tc_bitmap(pi, agg_info->replay_tc_bitmap, replay_bitmap); @@ -5210,7 +5353,6 @@ void ice_sched_replay_agg(struct ice_hw *hw) ice_info(hw, "Replay agg bw [id=%d] failed\n", agg_info->agg_id); } - } ice_release_lock(&pi->sched_lock); } @@ -5239,28 +5381,48 @@ void ice_sched_replay_agg_vsi_preinit(struct ice_hw *hw) ice_release_lock(&pi->sched_lock); } +/** + * ice_sched_replay_root_node_bw - replay root node BW + * @pi: port information structure + * + * Replay root node BW settings. + */ +enum ice_status ice_sched_replay_root_node_bw(struct ice_port_info *pi) +{ + enum ice_status status = ICE_SUCCESS; + + if (!pi->hw) + return ICE_ERR_PARAM; + ice_acquire_lock(&pi->sched_lock); + + status = ice_sched_replay_node_bw(pi->hw, pi->root, + &pi->root_node_bw_t_info); + ice_release_lock(&pi->sched_lock); + return status; +} + /** * ice_sched_replay_tc_node_bw - replay TC node(s) BW - * @hw: pointer to the HW struct + * @pi: port information structure * - * This function replay TC nodes. The caller needs to hold the scheduler lock. + * This function replay TC nodes. */ -enum ice_status -ice_sched_replay_tc_node_bw(struct ice_hw *hw) +enum ice_status ice_sched_replay_tc_node_bw(struct ice_port_info *pi) { - struct ice_port_info *pi = hw->port_info; enum ice_status status = ICE_SUCCESS; u8 tc; + if (!pi->hw) + return ICE_ERR_PARAM; ice_acquire_lock(&pi->sched_lock); ice_for_each_traffic_class(tc) { struct ice_sched_node *tc_node; - tc_node = ice_sched_get_tc_node(hw->port_info, tc); + tc_node = ice_sched_get_tc_node(pi, tc); if (!tc_node) continue; /* TC not present */ - status = ice_sched_replay_node_bw(hw, tc_node, - &hw->tc_node_bw_t_info[tc]); + status = ice_sched_replay_node_bw(pi->hw, tc_node, + &pi->tc_node_bw_t_info[tc]); if (status) break; } @@ -5297,7 +5459,7 @@ ice_sched_replay_vsi_bw(struct ice_hw *hw, u16 vsi_handle, tc_node = ice_sched_get_tc_node(pi, tc); if (!tc_node) continue; - vsi_node = ice_sched_get_vsi_node(hw, tc_node, vsi_handle); + vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle); if (!vsi_node) continue; bw_t_info = &vsi_ctx->sched.bw_t_info[tc]; @@ -5326,7 +5488,7 @@ ice_sched_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle) struct ice_sched_agg_info *agg_info; enum ice_status status; - ice_zero_bitmap(replay_bitmap, sizeof(replay_bitmap) * BITS_PER_BYTE); + ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS); if (!ice_is_vsi_valid(hw, vsi_handle)) return ICE_ERR_PARAM; agg_info = ice_get_vsi_agg_info(hw, vsi_handle); @@ -5368,8 +5530,7 @@ ice_sched_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle) * This function replays association of VSI to aggregator type nodes, and * node bandwidth information. */ -enum ice_status -ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle) +enum ice_status ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle) { struct ice_port_info *pi = hw->port_info; enum ice_status status; @@ -5379,3 +5540,23 @@ ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle) ice_release_lock(&pi->sched_lock); return status; } + +/** + * ice_sched_replay_q_bw - replay queue type node BW + * @pi: port information structure + * @q_ctx: queue context structure + * + * This function replays queue type node bandwidth. This function needs to be + * called with scheduler lock held. + */ +enum ice_status +ice_sched_replay_q_bw(struct ice_port_info *pi, struct ice_q_ctx *q_ctx) +{ + struct ice_sched_node *q_node; + + /* Following also checks the presence of node in tree */ + q_node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid); + if (!q_node) + return ICE_ERR_PARAM; + return ice_sched_replay_node_bw(pi->hw, q_node, &q_ctx->bw_t_info); +}