src/dpdk/drivers/net/ice/base/ice_sched.c
static enum ice_status
ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
		    struct ice_sched_node *parent, u8 layer, u16 num_nodes,
		    u16 *num_nodes_added, u32 *first_node_teid)
{
	struct ice_sched_node *prev, *new_node;
	struct ice_aqc_add_elem *buf;
	u16 i, num_groups_added = 0;
	enum ice_status status = ICE_SUCCESS;
	struct ice_hw *hw = pi->hw;
	u16 buf_size;
	u32 teid;

	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;

	buf->hdr.parent_teid = parent->info.node_teid;
	buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
	for (i = 0; i < num_nodes; i++) {
		buf->generic[i].parent_teid = parent->info.node_teid;
		buf->generic[i].data.elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC;
		buf->generic[i].data.valid_sections =
			ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
			ICE_AQC_ELEM_VALID_EIR;
		buf->generic[i].data.generic = 0;
		buf->generic[i].data.cir_bw.bw_profile_idx =
			CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
		buf->generic[i].data.cir_bw.bw_alloc =
			CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
		buf->generic[i].data.eir_bw.bw_profile_idx =
			CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
		buf->generic[i].data.eir_bw.bw_alloc =
			CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
	}

	status = ice_aq_add_sched_elems(hw, 1, buf, buf_size,
					&num_groups_added, NULL);
	if (status != ICE_SUCCESS || num_groups_added != 1) {
		ice_debug(hw, ICE_DBG_SCHED, "add node failed FW Error %d\n",
			  hw->adminq.sq_last_status);
		ice_free(hw, buf);
		return ICE_ERR_CFG;
	}

	*num_nodes_added = num_nodes;
	/* add nodes to the SW DB */
	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",
				  status);
			break;
		}

		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);
			break;
		}

		new_node->sibling = NULL;
		new_node->tc_num = tc_node->tc_num;

		/* add it to previous node sibling pointer */
		/* Note: siblings are not linked across branches */
		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;
	}

	ice_free(hw, buf);
	return status;
}
/**
 * ice_sched_add_elems - add nodes to HW and SW DB
 * @pi: port information structure
 * @tc_node: pointer to the branch node
 * @parent: pointer to the parent node
 * @layer: layer number to add nodes
 * @num_nodes: number of nodes
 * @num_nodes_added: pointer to num nodes added
 * @first_node_teid: if new nodes are added then return the TEID of first node
 *
 * This function add nodes to HW as well as to SW DB for a given layer
 */


This function add nodes to HW as well as to SW DB for a given layer
This function add nodes to HW as well as to SW DB for a given layer
static enum ice_status
ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
		    struct ice_sched_node *parent, u8 layer, u16 num_nodes,
		    u16 *num_nodes_added, u32 *first_node_teid)
{
	struct ice_sched_node *prev, *new_node;
	struct ice_aqc_add_elem *buf;
	u16 i, num_groups_added = 0;
	enum ice_status status = ICE_SUCCESS;
	struct ice_hw *hw = pi->hw;
	u16 buf_size;
	u32 teid;
	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;
	buf->hdr.parent_teid = parent->info.node_teid;
	buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
	for (i = 0; i < num_nodes; i++) {
		buf->generic[i].parent_teid = parent->info.node_teid;
		buf->generic[i].data.elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC;
		buf->generic[i].data.valid_sections =
			ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
			ICE_AQC_ELEM_VALID_EIR;
		buf->generic[i].data.generic = 0;
		buf->generic[i].data.cir_bw.bw_profile_idx =
			CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
		buf->generic[i].data.cir_bw.bw_alloc =
			CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
		buf->generic[i].data.eir_bw.bw_profile_idx =
			CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
		buf->generic[i].data.eir_bw.bw_alloc =
			CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
	}
	status = ice_aq_add_sched_elems(hw, 1, buf, buf_size,
					&num_groups_added, NULL);
	if (status != ICE_SUCCESS || num_groups_added != 1) {
		ice_debug(hw, ICE_DBG_SCHED, "add node failed FW Error %d\n",
			  hw->adminq.sq_last_status);
		ice_free(hw, buf);
		return ICE_ERR_CFG;
	}
	*num_nodes_added = num_nodes;
	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",
				  status);
			break;
		}
		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);
			break;
		}
		new_node->sibling = NULL;
		new_node->tc_num = tc_node->tc_num;
		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;
		}
		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;
	}
	ice_free(hw, buf);
	return status;
}
static enum ice_status ice_sched_add_elems ( struct ice_port_info * pi , struct ice_sched_node * tc_node , struct ice_sched_node * parent , u8 layer , u16 num_nodes , u16 * num_nodes_added , u32 * first_node_teid ) { struct ice_sched_node * prev , * new_node ; struct ice_aqc_add_elem * buf ; u16 i , num_groups_added = 0 ; enum ice_status status = ICE_SUCCESS ; struct ice_hw * hw = pi -> hw ; u16 buf_size ; u32 teid ; 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 ; buf -> hdr . parent_teid = parent -> info . node_teid ; buf -> hdr . num_elems = CPU_TO_LE16 ( num_nodes ) ; for ( i = 0 ; i < num_nodes ; i ++ ) { buf -> generic [ i ] . parent_teid = parent -> info . node_teid ; buf -> generic [ i ] . data . elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC ; buf -> generic [ i ] . data . valid_sections = ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR | ICE_AQC_ELEM_VALID_EIR ; buf -> generic [ i ] . data . generic = 0 ; buf -> generic [ i ] . data . cir_bw . bw_profile_idx = CPU_TO_LE16 ( ICE_SCHED_DFLT_RL_PROF_ID ) ; buf -> generic [ i ] . data . cir_bw . bw_alloc = CPU_TO_LE16 ( ICE_SCHED_DFLT_BW_WT ) ; buf -> generic [ i ] . data . eir_bw . bw_profile_idx = CPU_TO_LE16 ( ICE_SCHED_DFLT_RL_PROF_ID ) ; buf -> generic [ i ] . data . eir_bw . bw_alloc = CPU_TO_LE16 ( ICE_SCHED_DFLT_BW_WT ) ; } status = ice_aq_add_sched_elems ( hw , 1 , buf , buf_size , & num_groups_added , NULL ) ; if ( status != ICE_SUCCESS || num_groups_added != 1 ) { ice_debug ( hw , ICE_DBG_SCHED , " \n " , hw -> adminq . sq_last_status ) ; ice_free ( hw , buf ) ; return ICE_ERR_CFG ; } * num_nodes_added = num_nodes ; 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 , " \n " , status ) ; break ; } 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 , " \n " , teid ) ; break ; } new_node -> sibling = NULL ; new_node -> tc_num = tc_node -> tc_num ; 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 ; } 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 ; } ice_free ( hw , buf ) ; return status ; }
ice_sched_add_elems - add nodes to HW and SW DB
 @pi: port information structure
 @tc_node: pointer to the branch node
 @parent: pointer to the parent node
 @layer: layer number to add nodes
 @num_nodes: number of nodes
 @num_nodes_added: pointer to num nodes added
 @first_node_teid: if new nodes are added then return the TEID of first node
ice_sched_add_elems - add nodes to HW and SW DB @pi : port information structure @tc_node : pointer to the branch node @parent : pointer to the parent node @layer : layer number to add nodes @num_nodes : number of nodes @num_nodes_added : pointer to num nodes added @first_node_teid : if new nodes are added then return the TEID of first node
/* add nodes to the SW DB */ /* add it to previous node sibling pointer */ /* Note: siblings are not linked across branches */ /* initialize the sibling head */