1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2019
8 * ice_sched_add_root_node - Insert the Tx scheduler root node in SW DB
9 * @pi: port information structure
10 * @info: Scheduler element information from firmware
12 * This function inserts the root node of the scheduling tree topology
15 static enum ice_status
16 ice_sched_add_root_node(struct ice_port_info *pi,
17 struct ice_aqc_txsched_elem_data *info)
19 struct ice_sched_node *root;
27 root = (struct ice_sched_node *)ice_malloc(hw, sizeof(*root));
29 return ICE_ERR_NO_MEMORY;
31 /* coverity[suspicious_sizeof] */
32 root->children = (struct ice_sched_node **)
33 ice_calloc(hw, hw->max_children[0], sizeof(*root));
34 if (!root->children) {
36 return ICE_ERR_NO_MEMORY;
39 ice_memcpy(&root->info, info, sizeof(*info), ICE_DMA_TO_NONDMA);
45 * ice_sched_find_node_by_teid - Find the Tx scheduler node in SW DB
46 * @start_node: pointer to the starting ice_sched_node struct in a sub-tree
47 * @teid: node TEID to search
49 * This function searches for a node matching the TEID in the scheduling tree
50 * from the SW DB. The search is recursive and is restricted by the number of
51 * layers it has searched through; stopping at the max supported layer.
53 * This function needs to be called when holding the port_info->sched_lock
55 struct ice_sched_node *
56 ice_sched_find_node_by_teid(struct ice_sched_node *start_node, u32 teid)
60 /* The TEID is same as that of the start_node */
61 if (ICE_TXSCHED_GET_NODE_TEID(start_node) == teid)
64 /* The node has no children or is at the max layer */
65 if (!start_node->num_children ||
66 start_node->tx_sched_layer >= ICE_AQC_TOPO_MAX_LEVEL_NUM ||
67 start_node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF)
70 /* Check if TEID matches to any of the children nodes */
71 for (i = 0; i < start_node->num_children; i++)
72 if (ICE_TXSCHED_GET_NODE_TEID(start_node->children[i]) == teid)
73 return start_node->children[i];
75 /* Search within each child's sub-tree */
76 for (i = 0; i < start_node->num_children; i++) {
77 struct ice_sched_node *tmp;
79 tmp = ice_sched_find_node_by_teid(start_node->children[i],
89 * ice_aqc_send_sched_elem_cmd - send scheduling elements cmd
90 * @hw: pointer to the HW struct
91 * @cmd_opc: cmd opcode
92 * @elems_req: number of elements to request
93 * @buf: pointer to buffer
94 * @buf_size: buffer size in bytes
95 * @elems_resp: returns total number of elements response
96 * @cd: pointer to command details structure or NULL
98 * This function sends a scheduling elements cmd (cmd_opc)
100 static enum ice_status
101 ice_aqc_send_sched_elem_cmd(struct ice_hw *hw, enum ice_adminq_opc cmd_opc,
102 u16 elems_req, void *buf, u16 buf_size,
103 u16 *elems_resp, struct ice_sq_cd *cd)
105 struct ice_aqc_sched_elem_cmd *cmd;
106 struct ice_aq_desc desc;
107 enum ice_status status;
109 cmd = &desc.params.sched_elem_cmd;
110 ice_fill_dflt_direct_cmd_desc(&desc, cmd_opc);
111 cmd->num_elem_req = CPU_TO_LE16(elems_req);
112 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
113 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
114 if (!status && elems_resp)
115 *elems_resp = LE16_TO_CPU(cmd->num_elem_resp);
121 * ice_aq_query_sched_elems - query scheduler elements
122 * @hw: pointer to the HW struct
123 * @elems_req: number of elements to query
124 * @buf: pointer to buffer
125 * @buf_size: buffer size in bytes
126 * @elems_ret: returns total number of elements returned
127 * @cd: pointer to command details structure or NULL
129 * Query scheduling elements (0x0404)
132 ice_aq_query_sched_elems(struct ice_hw *hw, u16 elems_req,
133 struct ice_aqc_get_elem *buf, u16 buf_size,
134 u16 *elems_ret, struct ice_sq_cd *cd)
136 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_get_sched_elems,
137 elems_req, (void *)buf, buf_size,
142 * ice_sched_add_node - Insert the Tx scheduler node in SW DB
143 * @pi: port information structure
144 * @layer: Scheduler layer of the node
145 * @info: Scheduler element information from firmware
147 * This function inserts a scheduler node to the SW DB.
150 ice_sched_add_node(struct ice_port_info *pi, u8 layer,
151 struct ice_aqc_txsched_elem_data *info)
153 struct ice_sched_node *parent;
154 struct ice_aqc_get_elem elem;
155 struct ice_sched_node *node;
156 enum ice_status status;
160 return ICE_ERR_PARAM;
164 /* A valid parent node should be there */
165 parent = ice_sched_find_node_by_teid(pi->root,
166 LE32_TO_CPU(info->parent_teid));
168 ice_debug(hw, ICE_DBG_SCHED,
169 "Parent Node not found for parent_teid=0x%x\n",
170 LE32_TO_CPU(info->parent_teid));
171 return ICE_ERR_PARAM;
174 /* query the current node information from FW before additing it
177 status = ice_sched_query_elem(hw, LE32_TO_CPU(info->node_teid), &elem);
180 node = (struct ice_sched_node *)ice_malloc(hw, sizeof(*node));
182 return ICE_ERR_NO_MEMORY;
183 if (hw->max_children[layer]) {
184 /* coverity[suspicious_sizeof] */
185 node->children = (struct ice_sched_node **)
186 ice_calloc(hw, hw->max_children[layer], sizeof(*node));
187 if (!node->children) {
189 return ICE_ERR_NO_MEMORY;
194 node->parent = parent;
195 node->tx_sched_layer = layer;
196 parent->children[parent->num_children++] = node;
197 node->info = elem.generic[0];
202 * ice_aq_delete_sched_elems - delete scheduler elements
203 * @hw: pointer to the HW struct
204 * @grps_req: number of groups to delete
205 * @buf: pointer to buffer
206 * @buf_size: buffer size in bytes
207 * @grps_del: returns total number of elements deleted
208 * @cd: pointer to command details structure or NULL
210 * Delete scheduling elements (0x040F)
212 static enum ice_status
213 ice_aq_delete_sched_elems(struct ice_hw *hw, u16 grps_req,
214 struct ice_aqc_delete_elem *buf, u16 buf_size,
215 u16 *grps_del, struct ice_sq_cd *cd)
217 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_delete_sched_elems,
218 grps_req, (void *)buf, buf_size,
223 * ice_sched_remove_elems - remove nodes from HW
224 * @hw: pointer to the HW struct
225 * @parent: pointer to the parent node
226 * @num_nodes: number of nodes
227 * @node_teids: array of node teids to be deleted
229 * This function remove nodes from HW
231 static enum ice_status
232 ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent,
233 u16 num_nodes, u32 *node_teids)
235 struct ice_aqc_delete_elem *buf;
236 u16 i, num_groups_removed = 0;
237 enum ice_status status;
240 buf_size = sizeof(*buf) + sizeof(u32) * (num_nodes - 1);
241 buf = (struct ice_aqc_delete_elem *)ice_malloc(hw, buf_size);
243 return ICE_ERR_NO_MEMORY;
245 buf->hdr.parent_teid = parent->info.node_teid;
246 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
247 for (i = 0; i < num_nodes; i++)
248 buf->teid[i] = CPU_TO_LE32(node_teids[i]);
250 status = ice_aq_delete_sched_elems(hw, 1, buf, buf_size,
251 &num_groups_removed, NULL);
252 if (status != ICE_SUCCESS || num_groups_removed != 1)
253 ice_debug(hw, ICE_DBG_SCHED, "remove node failed FW error %d\n",
254 hw->adminq.sq_last_status);
261 * ice_sched_get_first_node - get the first node of the given layer
262 * @pi: port information structure
263 * @parent: pointer the base node of the subtree
264 * @layer: layer number
266 * This function retrieves the first node of the given layer from the subtree
268 static struct ice_sched_node *
269 ice_sched_get_first_node(struct ice_port_info *pi,
270 struct ice_sched_node *parent, u8 layer)
272 return pi->sib_head[parent->tc_num][layer];
276 * ice_sched_get_tc_node - get pointer to TC node
277 * @pi: port information structure
280 * This function returns the TC node pointer
282 struct ice_sched_node *ice_sched_get_tc_node(struct ice_port_info *pi, u8 tc)
286 if (!pi || !pi->root)
288 for (i = 0; i < pi->root->num_children; i++)
289 if (pi->root->children[i]->tc_num == tc)
290 return pi->root->children[i];
295 * ice_free_sched_node - Free a Tx scheduler node from SW DB
296 * @pi: port information structure
297 * @node: pointer to the ice_sched_node struct
299 * This function frees up a node from SW DB as well as from HW
301 * This function needs to be called with the port_info->sched_lock held
303 void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node)
305 struct ice_sched_node *parent;
306 struct ice_hw *hw = pi->hw;
309 /* Free the children before freeing up the parent node
310 * The parent array is updated below and that shifts the nodes
311 * in the array. So always pick the first child if num children > 0
313 while (node->num_children)
314 ice_free_sched_node(pi, node->children[0]);
316 /* Leaf, TC and root nodes can't be deleted by SW */
317 if (node->tx_sched_layer >= hw->sw_entry_point_layer &&
318 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
319 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT &&
320 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF) {
321 u32 teid = LE32_TO_CPU(node->info.node_teid);
323 ice_sched_remove_elems(hw, node->parent, 1, &teid);
325 parent = node->parent;
326 /* root has no parent */
328 struct ice_sched_node *p;
330 /* update the parent */
331 for (i = 0; i < parent->num_children; i++)
332 if (parent->children[i] == node) {
333 for (j = i + 1; j < parent->num_children; j++)
334 parent->children[j - 1] =
336 parent->num_children--;
340 p = ice_sched_get_first_node(pi, node, node->tx_sched_layer);
342 if (p->sibling == node) {
343 p->sibling = node->sibling;
349 /* update the sibling head if head is getting removed */
350 if (pi->sib_head[node->tc_num][node->tx_sched_layer] == node)
351 pi->sib_head[node->tc_num][node->tx_sched_layer] =
355 /* leaf nodes have no children */
357 ice_free(hw, node->children);
362 * ice_aq_get_dflt_topo - gets default scheduler topology
363 * @hw: pointer to the HW struct
364 * @lport: logical port number
365 * @buf: pointer to buffer
366 * @buf_size: buffer size in bytes
367 * @num_branches: returns total number of queue to port branches
368 * @cd: pointer to command details structure or NULL
370 * Get default scheduler topology (0x400)
372 static enum ice_status
373 ice_aq_get_dflt_topo(struct ice_hw *hw, u8 lport,
374 struct ice_aqc_get_topo_elem *buf, u16 buf_size,
375 u8 *num_branches, struct ice_sq_cd *cd)
377 struct ice_aqc_get_topo *cmd;
378 struct ice_aq_desc desc;
379 enum ice_status status;
381 cmd = &desc.params.get_topo;
382 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_dflt_topo);
383 cmd->port_num = lport;
384 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
385 if (!status && num_branches)
386 *num_branches = cmd->num_branches;
392 * ice_aq_add_sched_elems - adds scheduling element
393 * @hw: pointer to the HW struct
394 * @grps_req: the number of groups that are requested to be added
395 * @buf: pointer to buffer
396 * @buf_size: buffer size in bytes
397 * @grps_added: returns total number of groups added
398 * @cd: pointer to command details structure or NULL
400 * Add scheduling elements (0x0401)
402 static enum ice_status
403 ice_aq_add_sched_elems(struct ice_hw *hw, u16 grps_req,
404 struct ice_aqc_add_elem *buf, u16 buf_size,
405 u16 *grps_added, struct ice_sq_cd *cd)
407 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_add_sched_elems,
408 grps_req, (void *)buf, buf_size,
413 * ice_aq_cfg_sched_elems - configures scheduler elements
414 * @hw: pointer to the HW struct
415 * @elems_req: number of elements to configure
416 * @buf: pointer to buffer
417 * @buf_size: buffer size in bytes
418 * @elems_cfgd: returns total number of elements configured
419 * @cd: pointer to command details structure or NULL
421 * Configure scheduling elements (0x0403)
423 static enum ice_status
424 ice_aq_cfg_sched_elems(struct ice_hw *hw, u16 elems_req,
425 struct ice_aqc_conf_elem *buf, u16 buf_size,
426 u16 *elems_cfgd, struct ice_sq_cd *cd)
428 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_cfg_sched_elems,
429 elems_req, (void *)buf, buf_size,
434 * ice_aq_move_sched_elems - move scheduler elements
435 * @hw: pointer to the HW struct
436 * @grps_req: number of groups to move
437 * @buf: pointer to buffer
438 * @buf_size: buffer size in bytes
439 * @grps_movd: returns total number of groups moved
440 * @cd: pointer to command details structure or NULL
442 * Move scheduling elements (0x0408)
444 static enum ice_status
445 ice_aq_move_sched_elems(struct ice_hw *hw, u16 grps_req,
446 struct ice_aqc_move_elem *buf, u16 buf_size,
447 u16 *grps_movd, struct ice_sq_cd *cd)
449 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_move_sched_elems,
450 grps_req, (void *)buf, buf_size,
455 * ice_aq_suspend_sched_elems - suspend scheduler elements
456 * @hw: pointer to the HW struct
457 * @elems_req: number of elements to suspend
458 * @buf: pointer to buffer
459 * @buf_size: buffer size in bytes
460 * @elems_ret: returns total number of elements suspended
461 * @cd: pointer to command details structure or NULL
463 * Suspend scheduling elements (0x0409)
465 static enum ice_status
466 ice_aq_suspend_sched_elems(struct ice_hw *hw, u16 elems_req,
467 struct ice_aqc_suspend_resume_elem *buf,
468 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
470 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_suspend_sched_elems,
471 elems_req, (void *)buf, buf_size,
476 * ice_aq_resume_sched_elems - resume scheduler elements
477 * @hw: pointer to the HW struct
478 * @elems_req: number of elements to resume
479 * @buf: pointer to buffer
480 * @buf_size: buffer size in bytes
481 * @elems_ret: returns total number of elements resumed
482 * @cd: pointer to command details structure or NULL
484 * resume scheduling elements (0x040A)
486 static enum ice_status
487 ice_aq_resume_sched_elems(struct ice_hw *hw, u16 elems_req,
488 struct ice_aqc_suspend_resume_elem *buf,
489 u16 buf_size, u16 *elems_ret, struct ice_sq_cd *cd)
491 return ice_aqc_send_sched_elem_cmd(hw, ice_aqc_opc_resume_sched_elems,
492 elems_req, (void *)buf, buf_size,
497 * ice_aq_query_sched_res - query scheduler resource
498 * @hw: pointer to the HW struct
499 * @buf_size: buffer size in bytes
500 * @buf: pointer to buffer
501 * @cd: pointer to command details structure or NULL
503 * Query scheduler resource allocation (0x0412)
505 static enum ice_status
506 ice_aq_query_sched_res(struct ice_hw *hw, u16 buf_size,
507 struct ice_aqc_query_txsched_res_resp *buf,
508 struct ice_sq_cd *cd)
510 struct ice_aq_desc desc;
512 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_sched_res);
513 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
517 * ice_sched_suspend_resume_elems - suspend or resume HW nodes
518 * @hw: pointer to the HW struct
519 * @num_nodes: number of nodes
520 * @node_teids: array of node teids to be suspended or resumed
521 * @suspend: true means suspend / false means resume
523 * This function suspends or resumes HW nodes
525 static enum ice_status
526 ice_sched_suspend_resume_elems(struct ice_hw *hw, u8 num_nodes, u32 *node_teids,
529 struct ice_aqc_suspend_resume_elem *buf;
530 u16 i, buf_size, num_elem_ret = 0;
531 enum ice_status status;
533 buf_size = sizeof(*buf) * num_nodes;
534 buf = (struct ice_aqc_suspend_resume_elem *)
535 ice_malloc(hw, buf_size);
537 return ICE_ERR_NO_MEMORY;
539 for (i = 0; i < num_nodes; i++)
540 buf->teid[i] = CPU_TO_LE32(node_teids[i]);
543 status = ice_aq_suspend_sched_elems(hw, num_nodes, buf,
544 buf_size, &num_elem_ret,
547 status = ice_aq_resume_sched_elems(hw, num_nodes, buf,
548 buf_size, &num_elem_ret,
550 if (status != ICE_SUCCESS || num_elem_ret != num_nodes)
551 ice_debug(hw, ICE_DBG_SCHED, "suspend/resume failed\n");
558 * ice_alloc_lan_q_ctx - allocate LAN queue contexts for the given VSI and TC
559 * @hw: pointer to the HW struct
560 * @vsi_handle: VSI handle
562 * @new_numqs: number of queues
564 static enum ice_status
565 ice_alloc_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 new_numqs)
567 struct ice_vsi_ctx *vsi_ctx;
568 struct ice_q_ctx *q_ctx;
570 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
572 return ICE_ERR_PARAM;
573 /* allocate LAN queue contexts */
574 if (!vsi_ctx->lan_q_ctx[tc]) {
575 vsi_ctx->lan_q_ctx[tc] = (struct ice_q_ctx *)
576 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
577 if (!vsi_ctx->lan_q_ctx[tc])
578 return ICE_ERR_NO_MEMORY;
579 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
582 /* num queues are increased, update the queue contexts */
583 if (new_numqs > vsi_ctx->num_lan_q_entries[tc]) {
584 u16 prev_num = vsi_ctx->num_lan_q_entries[tc];
586 q_ctx = (struct ice_q_ctx *)
587 ice_calloc(hw, new_numqs, sizeof(*q_ctx));
589 return ICE_ERR_NO_MEMORY;
590 ice_memcpy(q_ctx, vsi_ctx->lan_q_ctx[tc],
591 prev_num * sizeof(*q_ctx), ICE_DMA_TO_NONDMA);
592 ice_free(hw, vsi_ctx->lan_q_ctx[tc]);
593 vsi_ctx->lan_q_ctx[tc] = q_ctx;
594 vsi_ctx->num_lan_q_entries[tc] = new_numqs;
600 * ice_aq_rl_profile - performs a rate limiting task
601 * @hw: pointer to the HW struct
602 * @opcode:opcode for add, query, or remove profile(s)
603 * @num_profiles: the number of profiles
604 * @buf: pointer to buffer
605 * @buf_size: buffer size in bytes
606 * @num_processed: number of processed add or remove profile(s) to return
607 * @cd: pointer to command details structure
609 * Rl profile function to add, query, or remove profile(s)
611 static enum ice_status
612 ice_aq_rl_profile(struct ice_hw *hw, enum ice_adminq_opc opcode,
613 u16 num_profiles, struct ice_aqc_rl_profile_generic_elem *buf,
614 u16 buf_size, u16 *num_processed, struct ice_sq_cd *cd)
616 struct ice_aqc_rl_profile *cmd;
617 struct ice_aq_desc desc;
618 enum ice_status status;
620 cmd = &desc.params.rl_profile;
622 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
623 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
624 cmd->num_profiles = CPU_TO_LE16(num_profiles);
625 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
626 if (!status && num_processed)
627 *num_processed = LE16_TO_CPU(cmd->num_processed);
632 * ice_aq_add_rl_profile - adds rate limiting profile(s)
633 * @hw: pointer to the HW struct
634 * @num_profiles: the number of profile(s) to be add
635 * @buf: pointer to buffer
636 * @buf_size: buffer size in bytes
637 * @num_profiles_added: total number of profiles added to return
638 * @cd: pointer to command details structure
640 * Add RL profile (0x0410)
642 static enum ice_status
643 ice_aq_add_rl_profile(struct ice_hw *hw, u16 num_profiles,
644 struct ice_aqc_rl_profile_generic_elem *buf,
645 u16 buf_size, u16 *num_profiles_added,
646 struct ice_sq_cd *cd)
648 return ice_aq_rl_profile(hw, ice_aqc_opc_add_rl_profiles,
650 buf_size, num_profiles_added, cd);
654 * ice_aq_query_rl_profile - query rate limiting profile(s)
655 * @hw: pointer to the HW struct
656 * @num_profiles: the number of profile(s) to query
657 * @buf: pointer to buffer
658 * @buf_size: buffer size in bytes
659 * @cd: pointer to command details structure
661 * Query RL profile (0x0411)
664 ice_aq_query_rl_profile(struct ice_hw *hw, u16 num_profiles,
665 struct ice_aqc_rl_profile_generic_elem *buf,
666 u16 buf_size, struct ice_sq_cd *cd)
668 return ice_aq_rl_profile(hw, ice_aqc_opc_query_rl_profiles,
669 num_profiles, buf, buf_size, NULL, cd);
673 * ice_aq_remove_rl_profile - removes RL profile(s)
674 * @hw: pointer to the HW struct
675 * @num_profiles: the number of profile(s) to remove
676 * @buf: pointer to buffer
677 * @buf_size: buffer size in bytes
678 * @num_profiles_removed: total number of profiles removed to return
679 * @cd: pointer to command details structure or NULL
681 * Remove RL profile (0x0415)
683 static enum ice_status
684 ice_aq_remove_rl_profile(struct ice_hw *hw, u16 num_profiles,
685 struct ice_aqc_rl_profile_generic_elem *buf,
686 u16 buf_size, u16 *num_profiles_removed,
687 struct ice_sq_cd *cd)
689 return ice_aq_rl_profile(hw, ice_aqc_opc_remove_rl_profiles,
691 buf_size, num_profiles_removed, cd);
695 * ice_sched_del_rl_profile - remove RL profile
696 * @hw: pointer to the HW struct
697 * @rl_info: rate limit profile information
699 * If the profile ID is not referenced anymore, it removes profile ID with
700 * its associated parameters from HW DB,and locally. The caller needs to
701 * hold scheduler lock.
703 static enum ice_status
704 ice_sched_del_rl_profile(struct ice_hw *hw,
705 struct ice_aqc_rl_profile_info *rl_info)
707 struct ice_aqc_rl_profile_generic_elem *buf;
708 u16 num_profiles_removed;
709 enum ice_status status;
710 u16 num_profiles = 1;
712 if (rl_info->prof_id_ref != 0)
713 return ICE_ERR_IN_USE;
715 /* Safe to remove profile ID */
716 buf = (struct ice_aqc_rl_profile_generic_elem *)
718 status = ice_aq_remove_rl_profile(hw, num_profiles, buf, sizeof(*buf),
719 &num_profiles_removed, NULL);
720 if (status || num_profiles_removed != num_profiles)
723 /* Delete stale entry now */
724 LIST_DEL(&rl_info->list_entry);
725 ice_free(hw, rl_info);
730 * ice_sched_clear_rl_prof - clears RL prof entries
731 * @pi: port information structure
733 * This function removes all RL profile from HW as well as from SW DB.
735 static void ice_sched_clear_rl_prof(struct ice_port_info *pi)
739 for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) {
740 struct ice_aqc_rl_profile_info *rl_prof_elem;
741 struct ice_aqc_rl_profile_info *rl_prof_tmp;
743 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
744 &pi->rl_prof_list[ln],
745 ice_aqc_rl_profile_info, list_entry) {
746 struct ice_hw *hw = pi->hw;
747 enum ice_status status;
749 rl_prof_elem->prof_id_ref = 0;
750 status = ice_sched_del_rl_profile(hw, rl_prof_elem);
752 ice_debug(hw, ICE_DBG_SCHED,
753 "Remove rl profile failed\n");
754 /* On error, free mem required */
755 LIST_DEL(&rl_prof_elem->list_entry);
756 ice_free(hw, rl_prof_elem);
763 * ice_sched_clear_agg - clears the aggregator related information
764 * @hw: pointer to the hardware structure
766 * This function removes aggregator list and free up aggregator related memory
767 * previously allocated.
769 void ice_sched_clear_agg(struct ice_hw *hw)
771 struct ice_sched_agg_info *agg_info;
772 struct ice_sched_agg_info *atmp;
774 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &hw->agg_list,
777 struct ice_sched_agg_vsi_info *agg_vsi_info;
778 struct ice_sched_agg_vsi_info *vtmp;
780 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
781 &agg_info->agg_vsi_list,
782 ice_sched_agg_vsi_info, list_entry) {
783 LIST_DEL(&agg_vsi_info->list_entry);
784 ice_free(hw, agg_vsi_info);
786 LIST_DEL(&agg_info->list_entry);
787 ice_free(hw, agg_info);
792 * ice_sched_clear_tx_topo - clears the schduler tree nodes
793 * @pi: port information structure
795 * This function removes all the nodes from HW as well as from SW DB.
797 static void ice_sched_clear_tx_topo(struct ice_port_info *pi)
801 /* remove RL profiles related lists */
802 ice_sched_clear_rl_prof(pi);
804 ice_free_sched_node(pi, pi->root);
810 * ice_sched_clear_port - clear the scheduler elements from SW DB for a port
811 * @pi: port information structure
813 * Cleanup scheduling elements from SW DB
815 void ice_sched_clear_port(struct ice_port_info *pi)
817 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
820 pi->port_state = ICE_SCHED_PORT_STATE_INIT;
821 ice_acquire_lock(&pi->sched_lock);
822 ice_sched_clear_tx_topo(pi);
823 ice_release_lock(&pi->sched_lock);
824 ice_destroy_lock(&pi->sched_lock);
828 * ice_sched_cleanup_all - cleanup scheduler elements from SW DB for all ports
829 * @hw: pointer to the HW struct
831 * Cleanup scheduling elements from SW DB for all the ports
833 void ice_sched_cleanup_all(struct ice_hw *hw)
838 if (hw->layer_info) {
839 ice_free(hw, hw->layer_info);
840 hw->layer_info = NULL;
844 ice_sched_clear_port(hw->port_info);
846 hw->num_tx_sched_layers = 0;
847 hw->num_tx_sched_phys_layers = 0;
848 hw->flattened_layers = 0;
853 * ice_aq_cfg_l2_node_cgd - configures L2 node to CGD mapping
854 * @hw: pointer to the HW struct
855 * @num_l2_nodes: the number of L2 nodes whose CGDs to configure
856 * @buf: pointer to buffer
857 * @buf_size: buffer size in bytes
858 * @cd: pointer to command details structure or NULL
860 * Configure L2 Node CGD (0x0414)
863 ice_aq_cfg_l2_node_cgd(struct ice_hw *hw, u16 num_l2_nodes,
864 struct ice_aqc_cfg_l2_node_cgd_data *buf,
865 u16 buf_size, struct ice_sq_cd *cd)
867 struct ice_aqc_cfg_l2_node_cgd *cmd;
868 struct ice_aq_desc desc;
870 cmd = &desc.params.cfg_l2_node_cgd;
871 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_cfg_l2_node_cgd);
872 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
874 cmd->num_l2_nodes = CPU_TO_LE16(num_l2_nodes);
875 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
879 * ice_sched_add_elems - add nodes to HW and SW DB
880 * @pi: port information structure
881 * @tc_node: pointer to the branch node
882 * @parent: pointer to the parent node
883 * @layer: layer number to add nodes
884 * @num_nodes: number of nodes
885 * @num_nodes_added: pointer to num nodes added
886 * @first_node_teid: if new nodes are added then return the TEID of first node
888 * This function add nodes to HW as well as to SW DB for a given layer
890 static enum ice_status
891 ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
892 struct ice_sched_node *parent, u8 layer, u16 num_nodes,
893 u16 *num_nodes_added, u32 *first_node_teid)
895 struct ice_sched_node *prev, *new_node;
896 struct ice_aqc_add_elem *buf;
897 u16 i, num_groups_added = 0;
898 enum ice_status status = ICE_SUCCESS;
899 struct ice_hw *hw = pi->hw;
903 buf_size = sizeof(*buf) + sizeof(*buf->generic) * (num_nodes - 1);
904 buf = (struct ice_aqc_add_elem *)ice_malloc(hw, buf_size);
906 return ICE_ERR_NO_MEMORY;
908 buf->hdr.parent_teid = parent->info.node_teid;
909 buf->hdr.num_elems = CPU_TO_LE16(num_nodes);
910 for (i = 0; i < num_nodes; i++) {
911 buf->generic[i].parent_teid = parent->info.node_teid;
912 buf->generic[i].data.elem_type = ICE_AQC_ELEM_TYPE_SE_GENERIC;
913 buf->generic[i].data.valid_sections =
914 ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
915 ICE_AQC_ELEM_VALID_EIR;
916 buf->generic[i].data.generic = 0;
917 buf->generic[i].data.cir_bw.bw_profile_idx =
918 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
919 buf->generic[i].data.cir_bw.bw_alloc =
920 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
921 buf->generic[i].data.eir_bw.bw_profile_idx =
922 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
923 buf->generic[i].data.eir_bw.bw_alloc =
924 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
927 status = ice_aq_add_sched_elems(hw, 1, buf, buf_size,
928 &num_groups_added, NULL);
929 if (status != ICE_SUCCESS || num_groups_added != 1) {
930 ice_debug(hw, ICE_DBG_SCHED, "add node failed FW Error %d\n",
931 hw->adminq.sq_last_status);
936 *num_nodes_added = num_nodes;
937 /* add nodes to the SW DB */
938 for (i = 0; i < num_nodes; i++) {
939 status = ice_sched_add_node(pi, layer, &buf->generic[i]);
940 if (status != ICE_SUCCESS) {
941 ice_debug(hw, ICE_DBG_SCHED,
942 "add nodes in SW DB failed status =%d\n",
947 teid = LE32_TO_CPU(buf->generic[i].node_teid);
948 new_node = ice_sched_find_node_by_teid(parent, teid);
950 ice_debug(hw, ICE_DBG_SCHED,
951 "Node is missing for teid =%d\n", teid);
955 new_node->sibling = NULL;
956 new_node->tc_num = tc_node->tc_num;
958 /* add it to previous node sibling pointer */
959 /* Note: siblings are not linked across branches */
960 prev = ice_sched_get_first_node(pi, tc_node, layer);
961 if (prev && prev != new_node) {
962 while (prev->sibling)
963 prev = prev->sibling;
964 prev->sibling = new_node;
967 /* initialize the sibling head */
968 if (!pi->sib_head[tc_node->tc_num][layer])
969 pi->sib_head[tc_node->tc_num][layer] = new_node;
972 *first_node_teid = teid;
980 * ice_sched_add_nodes_to_layer - Add nodes to a given layer
981 * @pi: port information structure
982 * @tc_node: pointer to TC node
983 * @parent: pointer to parent node
984 * @layer: layer number to add nodes
985 * @num_nodes: number of nodes to be added
986 * @first_node_teid: pointer to the first node TEID
987 * @num_nodes_added: pointer to number of nodes added
989 * This function add nodes to a given layer.
991 static enum ice_status
992 ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
993 struct ice_sched_node *tc_node,
994 struct ice_sched_node *parent, u8 layer,
995 u16 num_nodes, u32 *first_node_teid,
996 u16 *num_nodes_added)
998 u32 *first_teid_ptr = first_node_teid;
999 u16 new_num_nodes, max_child_nodes;
1000 enum ice_status status = ICE_SUCCESS;
1001 struct ice_hw *hw = pi->hw;
1005 *num_nodes_added = 0;
1010 if (!parent || layer < hw->sw_entry_point_layer)
1011 return ICE_ERR_PARAM;
1013 /* max children per node per layer */
1014 max_child_nodes = hw->max_children[parent->tx_sched_layer];
1016 /* current number of children + required nodes exceed max children ? */
1017 if ((parent->num_children + num_nodes) > max_child_nodes) {
1018 /* Fail if the parent is a TC node */
1019 if (parent == tc_node)
1022 /* utilize all the spaces if the parent is not full */
1023 if (parent->num_children < max_child_nodes) {
1024 new_num_nodes = max_child_nodes - parent->num_children;
1025 /* this recursion is intentional, and wouldn't
1026 * go more than 2 calls
1028 status = ice_sched_add_nodes_to_layer(pi, tc_node,
1033 if (status != ICE_SUCCESS)
1036 *num_nodes_added += num_added;
1038 /* Don't modify the first node TEID memory if the first node was
1039 * added already in the above call. Instead send some temp
1040 * memory for all other recursive calls.
1043 first_teid_ptr = &temp;
1045 new_num_nodes = num_nodes - num_added;
1047 /* This parent is full, try the next sibling */
1048 parent = parent->sibling;
1050 /* this recursion is intentional, for 1024 queues
1051 * per VSI, it goes max of 16 iterations.
1052 * 1024 / 8 = 128 layer 8 nodes
1053 * 128 /8 = 16 (add 8 nodes per iteration)
1055 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1056 layer, new_num_nodes,
1059 *num_nodes_added += num_added;
1063 status = ice_sched_add_elems(pi, tc_node, parent, layer, num_nodes,
1064 num_nodes_added, first_node_teid);
1069 * ice_sched_get_qgrp_layer - get the current queue group layer number
1070 * @hw: pointer to the HW struct
1072 * This function returns the current queue group layer number
1074 static u8 ice_sched_get_qgrp_layer(struct ice_hw *hw)
1076 /* It's always total layers - 1, the array is 0 relative so -2 */
1077 return hw->num_tx_sched_layers - ICE_QGRP_LAYER_OFFSET;
1081 * ice_sched_get_vsi_layer - get the current VSI layer number
1082 * @hw: pointer to the HW struct
1084 * This function returns the current VSI layer number
1086 static u8 ice_sched_get_vsi_layer(struct ice_hw *hw)
1088 /* Num Layers VSI layer
1091 * 5 or less sw_entry_point_layer
1093 /* calculate the VSI layer based on number of layers. */
1094 if (hw->num_tx_sched_layers > ICE_VSI_LAYER_OFFSET + 1) {
1095 u8 layer = hw->num_tx_sched_layers - ICE_VSI_LAYER_OFFSET;
1097 if (layer > hw->sw_entry_point_layer)
1100 return hw->sw_entry_point_layer;
1104 * ice_sched_get_agg_layer - get the current aggregator layer number
1105 * @hw: pointer to the HW struct
1107 * This function returns the current aggregator layer number
1109 static u8 ice_sched_get_agg_layer(struct ice_hw *hw)
1111 /* Num Layers aggregator layer
1113 * 7 or less sw_entry_point_layer
1115 /* calculate the aggregator layer based on number of layers. */
1116 if (hw->num_tx_sched_layers > ICE_AGG_LAYER_OFFSET + 1) {
1117 u8 layer = hw->num_tx_sched_layers - ICE_AGG_LAYER_OFFSET;
1119 if (layer > hw->sw_entry_point_layer)
1122 return hw->sw_entry_point_layer;
1126 * ice_rm_dflt_leaf_node - remove the default leaf node in the tree
1127 * @pi: port information structure
1129 * This function removes the leaf node that was created by the FW
1130 * during initialization
1132 static void ice_rm_dflt_leaf_node(struct ice_port_info *pi)
1134 struct ice_sched_node *node;
1138 if (!node->num_children)
1140 node = node->children[0];
1142 if (node && node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF) {
1143 u32 teid = LE32_TO_CPU(node->info.node_teid);
1144 enum ice_status status;
1146 /* remove the default leaf node */
1147 status = ice_sched_remove_elems(pi->hw, node->parent, 1, &teid);
1149 ice_free_sched_node(pi, node);
1154 * ice_sched_rm_dflt_nodes - free the default nodes in the tree
1155 * @pi: port information structure
1157 * This function frees all the nodes except root and TC that were created by
1158 * the FW during initialization
1160 static void ice_sched_rm_dflt_nodes(struct ice_port_info *pi)
1162 struct ice_sched_node *node;
1164 ice_rm_dflt_leaf_node(pi);
1166 /* remove the default nodes except TC and root nodes */
1169 if (node->tx_sched_layer >= pi->hw->sw_entry_point_layer &&
1170 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_TC &&
1171 node->info.data.elem_type != ICE_AQC_ELEM_TYPE_ROOT_PORT) {
1172 ice_free_sched_node(pi, node);
1176 if (!node->num_children)
1178 node = node->children[0];
1183 * ice_sched_init_port - Initialize scheduler by querying information from FW
1184 * @pi: port info structure for the tree to cleanup
1186 * This function is the initial call to find the total number of Tx scheduler
1187 * resources, default topology created by firmware and storing the information
1190 enum ice_status ice_sched_init_port(struct ice_port_info *pi)
1192 struct ice_aqc_get_topo_elem *buf;
1193 enum ice_status status;
1200 return ICE_ERR_PARAM;
1203 /* Query the Default Topology from FW */
1204 buf = (struct ice_aqc_get_topo_elem *)ice_malloc(hw,
1205 ICE_AQ_MAX_BUF_LEN);
1207 return ICE_ERR_NO_MEMORY;
1209 /* Query default scheduling tree topology */
1210 status = ice_aq_get_dflt_topo(hw, pi->lport, buf, ICE_AQ_MAX_BUF_LEN,
1211 &num_branches, NULL);
1215 /* num_branches should be between 1-8 */
1216 if (num_branches < 1 || num_branches > ICE_TXSCHED_MAX_BRANCHES) {
1217 ice_debug(hw, ICE_DBG_SCHED, "num_branches unexpected %d\n",
1219 status = ICE_ERR_PARAM;
1223 /* get the number of elements on the default/first branch */
1224 num_elems = LE16_TO_CPU(buf[0].hdr.num_elems);
1226 /* num_elems should always be between 1-9 */
1227 if (num_elems < 1 || num_elems > ICE_AQC_TOPO_MAX_LEVEL_NUM) {
1228 ice_debug(hw, ICE_DBG_SCHED, "num_elems unexpected %d\n",
1230 status = ICE_ERR_PARAM;
1234 /* If the last node is a leaf node then the index of the queue group
1235 * layer is two less than the number of elements.
1237 if (num_elems > 2 && buf[0].generic[num_elems - 1].data.elem_type ==
1238 ICE_AQC_ELEM_TYPE_LEAF)
1239 pi->last_node_teid =
1240 LE32_TO_CPU(buf[0].generic[num_elems - 2].node_teid);
1242 pi->last_node_teid =
1243 LE32_TO_CPU(buf[0].generic[num_elems - 1].node_teid);
1245 /* Insert the Tx Sched root node */
1246 status = ice_sched_add_root_node(pi, &buf[0].generic[0]);
1250 /* Parse the default tree and cache the information */
1251 for (i = 0; i < num_branches; i++) {
1252 num_elems = LE16_TO_CPU(buf[i].hdr.num_elems);
1254 /* Skip root element as already inserted */
1255 for (j = 1; j < num_elems; j++) {
1256 /* update the sw entry point */
1257 if (buf[0].generic[j].data.elem_type ==
1258 ICE_AQC_ELEM_TYPE_ENTRY_POINT)
1259 hw->sw_entry_point_layer = j;
1261 status = ice_sched_add_node(pi, j, &buf[i].generic[j]);
1267 /* Remove the default nodes. */
1269 ice_sched_rm_dflt_nodes(pi);
1271 /* initialize the port for handling the scheduler tree */
1272 pi->port_state = ICE_SCHED_PORT_STATE_READY;
1273 ice_init_lock(&pi->sched_lock);
1274 for (i = 0; i < ICE_AQC_TOPO_MAX_LEVEL_NUM; i++)
1275 INIT_LIST_HEAD(&pi->rl_prof_list[i]);
1278 if (status && pi->root) {
1279 ice_free_sched_node(pi, pi->root);
1288 * ice_sched_get_node - Get the struct ice_sched_node for given TEID
1289 * @pi: port information structure
1290 * @teid: Scheduler node TEID
1292 * This function retrieves the ice_sched_node struct for given TEID from
1293 * the SW DB and returns it to the caller.
1295 struct ice_sched_node *ice_sched_get_node(struct ice_port_info *pi, u32 teid)
1297 struct ice_sched_node *node;
1302 /* Find the node starting from root */
1303 ice_acquire_lock(&pi->sched_lock);
1304 node = ice_sched_find_node_by_teid(pi->root, teid);
1305 ice_release_lock(&pi->sched_lock);
1308 ice_debug(pi->hw, ICE_DBG_SCHED,
1309 "Node not found for teid=0x%x\n", teid);
1315 * ice_sched_query_res_alloc - query the FW for num of logical sched layers
1316 * @hw: pointer to the HW struct
1318 * query FW for allocated scheduler resources and store in HW struct
1320 enum ice_status ice_sched_query_res_alloc(struct ice_hw *hw)
1322 struct ice_aqc_query_txsched_res_resp *buf;
1323 enum ice_status status = ICE_SUCCESS;
1330 buf = (struct ice_aqc_query_txsched_res_resp *)
1331 ice_malloc(hw, sizeof(*buf));
1333 return ICE_ERR_NO_MEMORY;
1335 status = ice_aq_query_sched_res(hw, sizeof(*buf), buf, NULL);
1337 goto sched_query_out;
1339 hw->num_tx_sched_layers = LE16_TO_CPU(buf->sched_props.logical_levels);
1340 hw->num_tx_sched_phys_layers =
1341 LE16_TO_CPU(buf->sched_props.phys_levels);
1342 hw->flattened_layers = buf->sched_props.flattening_bitmap;
1343 hw->max_cgds = buf->sched_props.max_pf_cgds;
1345 /* max sibling group size of current layer refers to the max children
1346 * of the below layer node.
1347 * layer 1 node max children will be layer 2 max sibling group size
1348 * layer 2 node max children will be layer 3 max sibling group size
1349 * and so on. This array will be populated from root (index 0) to
1350 * qgroup layer 7. Leaf node has no children.
1352 for (i = 0; i < hw->num_tx_sched_layers - 1; i++) {
1353 max_sibl = buf->layer_props[i + 1].max_sibl_grp_sz;
1354 hw->max_children[i] = LE16_TO_CPU(max_sibl);
1357 hw->layer_info = (struct ice_aqc_layer_props *)
1358 ice_memdup(hw, buf->layer_props,
1359 (hw->num_tx_sched_layers *
1360 sizeof(*hw->layer_info)),
1362 if (!hw->layer_info) {
1363 status = ICE_ERR_NO_MEMORY;
1364 goto sched_query_out;
1373 * ice_sched_find_node_in_subtree - Find node in part of base node subtree
1374 * @hw: pointer to the HW struct
1375 * @base: pointer to the base node
1376 * @node: pointer to the node to search
1378 * This function checks whether a given node is part of the base node
1382 ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base,
1383 struct ice_sched_node *node)
1387 for (i = 0; i < base->num_children; i++) {
1388 struct ice_sched_node *child = base->children[i];
1393 if (child->tx_sched_layer > node->tx_sched_layer)
1396 /* this recursion is intentional, and wouldn't
1397 * go more than 8 calls
1399 if (ice_sched_find_node_in_subtree(hw, child, node))
1406 * ice_sched_get_free_qparent - Get a free LAN or RDMA queue group node
1407 * @pi: port information structure
1408 * @vsi_handle: software VSI handle
1409 * @tc: branch number
1410 * @owner: LAN or RDMA
1412 * This function retrieves a free LAN or RDMA queue group node
1414 struct ice_sched_node *
1415 ice_sched_get_free_qparent(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
1418 struct ice_sched_node *vsi_node, *qgrp_node = NULL;
1419 struct ice_vsi_ctx *vsi_ctx;
1423 qgrp_layer = ice_sched_get_qgrp_layer(pi->hw);
1424 max_children = pi->hw->max_children[qgrp_layer];
1426 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
1429 vsi_node = vsi_ctx->sched.vsi_node[tc];
1430 /* validate invalid VSI ID */
1434 /* get the first queue group node from VSI sub-tree */
1435 qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer);
1437 /* make sure the qgroup node is part of the VSI subtree */
1438 if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node))
1439 if (qgrp_node->num_children < max_children &&
1440 qgrp_node->owner == owner)
1442 qgrp_node = qgrp_node->sibling;
1450 * ice_sched_get_vsi_node - Get a VSI node based on VSI ID
1451 * @pi: pointer to the port information structure
1452 * @tc_node: pointer to the TC node
1453 * @vsi_handle: software VSI handle
1455 * This function retrieves a VSI node for a given VSI ID from a given
1458 struct ice_sched_node *
1459 ice_sched_get_vsi_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1462 struct ice_sched_node *node;
1465 vsi_layer = ice_sched_get_vsi_layer(pi->hw);
1466 node = ice_sched_get_first_node(pi, tc_node, vsi_layer);
1468 /* Check whether it already exists */
1470 if (node->vsi_handle == vsi_handle)
1472 node = node->sibling;
1479 * ice_sched_get_agg_node - Get an aggregator node based on aggregator ID
1480 * @pi: pointer to the port information structure
1481 * @tc_node: pointer to the TC node
1482 * @agg_id: aggregator ID
1484 * This function retrieves an aggregator node for a given aggregator ID from
1487 static struct ice_sched_node *
1488 ice_sched_get_agg_node(struct ice_port_info *pi, struct ice_sched_node *tc_node,
1491 struct ice_sched_node *node;
1492 struct ice_hw *hw = pi->hw;
1497 agg_layer = ice_sched_get_agg_layer(hw);
1498 node = ice_sched_get_first_node(pi, tc_node, agg_layer);
1500 /* Check whether it already exists */
1502 if (node->agg_id == agg_id)
1504 node = node->sibling;
1511 * ice_sched_check_node - Compare node parameters between SW DB and HW DB
1512 * @hw: pointer to the HW struct
1513 * @node: pointer to the ice_sched_node struct
1515 * This function queries and compares the HW element with SW DB node parameters
1517 static bool ice_sched_check_node(struct ice_hw *hw, struct ice_sched_node *node)
1519 struct ice_aqc_get_elem buf;
1520 enum ice_status status;
1523 node_teid = LE32_TO_CPU(node->info.node_teid);
1524 status = ice_sched_query_elem(hw, node_teid, &buf);
1525 if (status != ICE_SUCCESS)
1528 if (memcmp(buf.generic, &node->info, sizeof(*buf.generic))) {
1529 ice_debug(hw, ICE_DBG_SCHED, "Node mismatch for teid=0x%x\n",
1538 * ice_sched_calc_vsi_child_nodes - calculate number of VSI child nodes
1539 * @hw: pointer to the HW struct
1540 * @num_qs: number of queues
1541 * @num_nodes: num nodes array
1543 * This function calculates the number of VSI child nodes based on the
1547 ice_sched_calc_vsi_child_nodes(struct ice_hw *hw, u16 num_qs, u16 *num_nodes)
1552 qgl = ice_sched_get_qgrp_layer(hw);
1553 vsil = ice_sched_get_vsi_layer(hw);
1555 /* calculate num nodes from queue group to VSI layer */
1556 for (i = qgl; i > vsil; i--) {
1557 /* round to the next integer if there is a remainder */
1558 num = DIVIDE_AND_ROUND_UP(num, hw->max_children[i]);
1560 /* need at least one node */
1561 num_nodes[i] = num ? num : 1;
1566 * ice_sched_add_vsi_child_nodes - add VSI child nodes to tree
1567 * @pi: port information structure
1568 * @vsi_handle: software VSI handle
1569 * @tc_node: pointer to the TC node
1570 * @num_nodes: pointer to the num nodes that needs to be added per layer
1571 * @owner: node owner (LAN or RDMA)
1573 * This function adds the VSI child nodes to tree. It gets called for
1574 * LAN and RDMA separately.
1576 static enum ice_status
1577 ice_sched_add_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1578 struct ice_sched_node *tc_node, u16 *num_nodes,
1581 struct ice_sched_node *parent, *node;
1582 struct ice_hw *hw = pi->hw;
1583 enum ice_status status;
1584 u32 first_node_teid;
1588 qgl = ice_sched_get_qgrp_layer(hw);
1589 vsil = ice_sched_get_vsi_layer(hw);
1590 parent = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1591 for (i = vsil + 1; i <= qgl; i++) {
1595 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
1599 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1602 /* The newly added node can be a new parent for the next
1606 parent = ice_sched_find_node_by_teid(tc_node,
1610 node->owner = owner;
1611 node = node->sibling;
1614 parent = parent->children[0];
1622 * ice_sched_calc_vsi_support_nodes - calculate number of VSI support nodes
1623 * @pi: pointer to the port info structure
1624 * @tc_node: pointer to TC node
1625 * @num_nodes: pointer to num nodes array
1627 * This function calculates the number of supported nodes needed to add this
1628 * VSI into Tx tree including the VSI, parent and intermediate nodes in below
1632 ice_sched_calc_vsi_support_nodes(struct ice_port_info *pi,
1633 struct ice_sched_node *tc_node, u16 *num_nodes)
1635 struct ice_sched_node *node;
1639 vsil = ice_sched_get_vsi_layer(pi->hw);
1640 for (i = vsil; i >= pi->hw->sw_entry_point_layer; i--)
1641 /* Add intermediate nodes if TC has no children and
1642 * need at least one node for VSI
1644 if (!tc_node->num_children || i == vsil) {
1647 /* If intermediate nodes are reached max children
1648 * then add a new one.
1650 node = ice_sched_get_first_node(pi, tc_node, (u8)i);
1651 /* scan all the siblings */
1653 if (node->num_children <
1654 pi->hw->max_children[i])
1656 node = node->sibling;
1659 /* tree has one intermediate node to add this new VSI.
1660 * So no need to calculate supported nodes for below
1665 /* all the nodes are full, allocate a new one */
1671 * ice_sched_add_vsi_support_nodes - add VSI supported nodes into Tx tree
1672 * @pi: port information structure
1673 * @vsi_handle: software VSI handle
1674 * @tc_node: pointer to TC node
1675 * @num_nodes: pointer to num nodes array
1677 * This function adds the VSI supported nodes into Tx tree including the
1678 * VSI, its parent and intermediate nodes in below layers
1680 static enum ice_status
1681 ice_sched_add_vsi_support_nodes(struct ice_port_info *pi, u16 vsi_handle,
1682 struct ice_sched_node *tc_node, u16 *num_nodes)
1684 struct ice_sched_node *parent = tc_node;
1685 enum ice_status status;
1686 u32 first_node_teid;
1691 return ICE_ERR_PARAM;
1693 vsil = ice_sched_get_vsi_layer(pi->hw);
1694 for (i = pi->hw->sw_entry_point_layer; i <= vsil; i++) {
1695 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent,
1699 if (status != ICE_SUCCESS || num_nodes[i] != num_added)
1702 /* The newly added node can be a new parent for the next
1706 parent = ice_sched_find_node_by_teid(tc_node,
1709 parent = parent->children[0];
1715 parent->vsi_handle = vsi_handle;
1722 * ice_sched_add_vsi_to_topo - add a new VSI into tree
1723 * @pi: port information structure
1724 * @vsi_handle: software VSI handle
1727 * This function adds a new VSI into scheduler tree
1729 static enum ice_status
1730 ice_sched_add_vsi_to_topo(struct ice_port_info *pi, u16 vsi_handle, u8 tc)
1732 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1733 struct ice_sched_node *tc_node;
1735 tc_node = ice_sched_get_tc_node(pi, tc);
1737 return ICE_ERR_PARAM;
1739 /* calculate number of supported nodes needed for this VSI */
1740 ice_sched_calc_vsi_support_nodes(pi, tc_node, num_nodes);
1742 /* add VSI supported nodes to TC subtree */
1743 return ice_sched_add_vsi_support_nodes(pi, vsi_handle, tc_node,
1748 * ice_sched_update_vsi_child_nodes - update VSI child nodes
1749 * @pi: port information structure
1750 * @vsi_handle: software VSI handle
1752 * @new_numqs: new number of max queues
1753 * @owner: owner of this subtree
1755 * This function updates the VSI child nodes based on the number of queues
1757 static enum ice_status
1758 ice_sched_update_vsi_child_nodes(struct ice_port_info *pi, u16 vsi_handle,
1759 u8 tc, u16 new_numqs, u8 owner)
1761 u16 new_num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
1762 struct ice_sched_node *vsi_node;
1763 struct ice_sched_node *tc_node;
1764 struct ice_vsi_ctx *vsi_ctx;
1765 enum ice_status status = ICE_SUCCESS;
1766 struct ice_hw *hw = pi->hw;
1769 tc_node = ice_sched_get_tc_node(pi, tc);
1773 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1777 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1779 return ICE_ERR_PARAM;
1781 prev_numqs = vsi_ctx->sched.max_lanq[tc];
1782 /* num queues are not changed or less than the previous number */
1783 if (new_numqs <= prev_numqs)
1785 status = ice_alloc_lan_q_ctx(hw, vsi_handle, tc, new_numqs);
1790 ice_sched_calc_vsi_child_nodes(hw, new_numqs, new_num_nodes);
1791 /* Keep the max number of queue configuration all the time. Update the
1792 * tree only if number of queues > previous number of queues. This may
1793 * leave some extra nodes in the tree if number of queues < previous
1794 * number but that wouldn't harm anything. Removing those extra nodes
1795 * may complicate the code if those nodes are part of SRL or
1796 * individually rate limited.
1798 status = ice_sched_add_vsi_child_nodes(pi, vsi_handle, tc_node,
1799 new_num_nodes, owner);
1802 vsi_ctx->sched.max_lanq[tc] = new_numqs;
1808 * ice_sched_cfg_vsi - configure the new/existing VSI
1809 * @pi: port information structure
1810 * @vsi_handle: software VSI handle
1812 * @maxqs: max number of queues
1813 * @owner: LAN or RDMA
1814 * @enable: TC enabled or disabled
1816 * This function adds/updates VSI nodes based on the number of queues. If TC is
1817 * enabled and VSI is in suspended state then resume the VSI back. If TC is
1818 * disabled then suspend the VSI if it is not already.
1821 ice_sched_cfg_vsi(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 maxqs,
1822 u8 owner, bool enable)
1824 struct ice_sched_node *vsi_node, *tc_node;
1825 struct ice_vsi_ctx *vsi_ctx;
1826 enum ice_status status = ICE_SUCCESS;
1827 struct ice_hw *hw = pi->hw;
1829 ice_debug(pi->hw, ICE_DBG_SCHED, "add/config VSI %d\n", vsi_handle);
1830 tc_node = ice_sched_get_tc_node(pi, tc);
1832 return ICE_ERR_PARAM;
1833 vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
1835 return ICE_ERR_PARAM;
1836 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1838 /* suspend the VSI if TC is not enabled */
1840 if (vsi_node && vsi_node->in_use) {
1841 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1843 status = ice_sched_suspend_resume_elems(hw, 1, &teid,
1846 vsi_node->in_use = false;
1851 /* TC is enabled, if it is a new VSI then add it to the tree */
1853 status = ice_sched_add_vsi_to_topo(pi, vsi_handle, tc);
1857 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1861 vsi_ctx->sched.vsi_node[tc] = vsi_node;
1862 vsi_node->in_use = true;
1863 /* invalidate the max queues whenever VSI gets added first time
1864 * into the scheduler tree (boot or after reset). We need to
1865 * recreate the child nodes all the time in these cases.
1867 vsi_ctx->sched.max_lanq[tc] = 0;
1870 /* update the VSI child nodes */
1871 status = ice_sched_update_vsi_child_nodes(pi, vsi_handle, tc, maxqs,
1876 /* TC is enabled, resume the VSI if it is in the suspend state */
1877 if (!vsi_node->in_use) {
1878 u32 teid = LE32_TO_CPU(vsi_node->info.node_teid);
1880 status = ice_sched_suspend_resume_elems(hw, 1, &teid, false);
1882 vsi_node->in_use = true;
1889 * ice_sched_rm_agg_vsi_entry - remove aggregator related VSI info entry
1890 * @pi: port information structure
1891 * @vsi_handle: software VSI handle
1893 * This function removes single aggregator VSI info entry from
1897 ice_sched_rm_agg_vsi_info(struct ice_port_info *pi, u16 vsi_handle)
1899 struct ice_sched_agg_info *agg_info;
1900 struct ice_sched_agg_info *atmp;
1902 LIST_FOR_EACH_ENTRY_SAFE(agg_info, atmp, &pi->hw->agg_list,
1905 struct ice_sched_agg_vsi_info *agg_vsi_info;
1906 struct ice_sched_agg_vsi_info *vtmp;
1908 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, vtmp,
1909 &agg_info->agg_vsi_list,
1910 ice_sched_agg_vsi_info, list_entry)
1911 if (agg_vsi_info->vsi_handle == vsi_handle) {
1912 LIST_DEL(&agg_vsi_info->list_entry);
1913 ice_free(pi->hw, agg_vsi_info);
1920 * ice_sched_is_leaf_node_present - check for a leaf node in the sub-tree
1921 * @node: pointer to the sub-tree node
1923 * This function checks for a leaf node presence in a given sub-tree node.
1925 static bool ice_sched_is_leaf_node_present(struct ice_sched_node *node)
1929 for (i = 0; i < node->num_children; i++)
1930 if (ice_sched_is_leaf_node_present(node->children[i]))
1932 /* check for a leaf node */
1933 return (node->info.data.elem_type == ICE_AQC_ELEM_TYPE_LEAF);
1937 * ice_sched_rm_vsi_cfg - remove the VSI and its children nodes
1938 * @pi: port information structure
1939 * @vsi_handle: software VSI handle
1940 * @owner: LAN or RDMA
1942 * This function removes the VSI and its LAN or RDMA children nodes from the
1945 static enum ice_status
1946 ice_sched_rm_vsi_cfg(struct ice_port_info *pi, u16 vsi_handle, u8 owner)
1948 enum ice_status status = ICE_ERR_PARAM;
1949 struct ice_vsi_ctx *vsi_ctx;
1952 ice_debug(pi->hw, ICE_DBG_SCHED, "removing VSI %d\n", vsi_handle);
1953 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
1955 ice_acquire_lock(&pi->sched_lock);
1956 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
1958 goto exit_sched_rm_vsi_cfg;
1960 ice_for_each_traffic_class(i) {
1961 struct ice_sched_node *vsi_node, *tc_node;
1964 tc_node = ice_sched_get_tc_node(pi, i);
1968 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
1972 if (ice_sched_is_leaf_node_present(vsi_node)) {
1973 ice_debug(pi->hw, ICE_DBG_SCHED,
1974 "VSI has leaf nodes in TC %d\n", i);
1975 status = ICE_ERR_IN_USE;
1976 goto exit_sched_rm_vsi_cfg;
1978 while (j < vsi_node->num_children) {
1979 if (vsi_node->children[j]->owner == owner) {
1980 ice_free_sched_node(pi, vsi_node->children[j]);
1982 /* reset the counter again since the num
1983 * children will be updated after node removal
1990 /* remove the VSI if it has no children */
1991 if (!vsi_node->num_children) {
1992 ice_free_sched_node(pi, vsi_node);
1993 vsi_ctx->sched.vsi_node[i] = NULL;
1995 /* clean up aggregator related VSI info if any */
1996 ice_sched_rm_agg_vsi_info(pi, vsi_handle);
1998 if (owner == ICE_SCHED_NODE_OWNER_LAN)
1999 vsi_ctx->sched.max_lanq[i] = 0;
2001 status = ICE_SUCCESS;
2003 exit_sched_rm_vsi_cfg:
2004 ice_release_lock(&pi->sched_lock);
2009 * ice_rm_vsi_lan_cfg - remove VSI and its LAN children nodes
2010 * @pi: port information structure
2011 * @vsi_handle: software VSI handle
2013 * This function clears the VSI and its LAN children nodes from scheduler tree
2016 enum ice_status ice_rm_vsi_lan_cfg(struct ice_port_info *pi, u16 vsi_handle)
2018 return ice_sched_rm_vsi_cfg(pi, vsi_handle, ICE_SCHED_NODE_OWNER_LAN);
2022 * ice_sched_is_tree_balanced - Check tree nodes are identical or not
2023 * @hw: pointer to the HW struct
2024 * @node: pointer to the ice_sched_node struct
2026 * This function compares all the nodes for a given tree against HW DB nodes
2027 * This function needs to be called with the port_info->sched_lock held
2029 bool ice_sched_is_tree_balanced(struct ice_hw *hw, struct ice_sched_node *node)
2033 /* start from the leaf node */
2034 for (i = 0; i < node->num_children; i++)
2035 /* Fail if node doesn't match with the SW DB
2036 * this recursion is intentional, and wouldn't
2037 * go more than 9 calls
2039 if (!ice_sched_is_tree_balanced(hw, node->children[i]))
2042 return ice_sched_check_node(hw, node);
2046 * ice_aq_query_node_to_root - retrieve the tree topology for a given node TEID
2047 * @hw: pointer to the HW struct
2048 * @node_teid: node TEID
2049 * @buf: pointer to buffer
2050 * @buf_size: buffer size in bytes
2051 * @cd: pointer to command details structure or NULL
2053 * This function retrieves the tree topology from the firmware for a given
2054 * node TEID to the root node.
2057 ice_aq_query_node_to_root(struct ice_hw *hw, u32 node_teid,
2058 struct ice_aqc_get_elem *buf, u16 buf_size,
2059 struct ice_sq_cd *cd)
2061 struct ice_aqc_query_node_to_root *cmd;
2062 struct ice_aq_desc desc;
2064 cmd = &desc.params.query_node_to_root;
2065 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_node_to_root);
2066 cmd->teid = CPU_TO_LE32(node_teid);
2067 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2071 * ice_get_agg_info - get the aggregator ID
2072 * @hw: pointer to the hardware structure
2073 * @agg_id: aggregator ID
2075 * This function validates aggregator ID. The function returns info if
2076 * aggregator ID is present in list otherwise it returns null.
2078 static struct ice_sched_agg_info*
2079 ice_get_agg_info(struct ice_hw *hw, u32 agg_id)
2081 struct ice_sched_agg_info *agg_info;
2083 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2085 if (agg_info->agg_id == agg_id)
2092 * ice_sched_get_free_vsi_parent - Find a free parent node in aggregator subtree
2093 * @hw: pointer to the HW struct
2094 * @node: pointer to a child node
2095 * @num_nodes: num nodes count array
2097 * This function walks through the aggregator subtree to find a free parent
2100 static struct ice_sched_node *
2101 ice_sched_get_free_vsi_parent(struct ice_hw *hw, struct ice_sched_node *node,
2104 u8 l = node->tx_sched_layer;
2107 vsil = ice_sched_get_vsi_layer(hw);
2109 /* Is it VSI parent layer ? */
2111 return (node->num_children < hw->max_children[l]) ? node : NULL;
2113 /* We have intermediate nodes. Let's walk through the subtree. If the
2114 * intermediate node has space to add a new node then clear the count
2116 if (node->num_children < hw->max_children[l])
2118 /* The below recursive call is intentional and wouldn't go more than
2119 * 2 or 3 iterations.
2122 for (i = 0; i < node->num_children; i++) {
2123 struct ice_sched_node *parent;
2125 parent = ice_sched_get_free_vsi_parent(hw, node->children[i],
2135 * ice_sched_update_parent - update the new parent in SW DB
2136 * @new_parent: pointer to a new parent node
2137 * @node: pointer to a child node
2139 * This function removes the child from the old parent and adds it to a new
2143 ice_sched_update_parent(struct ice_sched_node *new_parent,
2144 struct ice_sched_node *node)
2146 struct ice_sched_node *old_parent;
2149 old_parent = node->parent;
2151 /* update the old parent children */
2152 for (i = 0; i < old_parent->num_children; i++)
2153 if (old_parent->children[i] == node) {
2154 for (j = i + 1; j < old_parent->num_children; j++)
2155 old_parent->children[j - 1] =
2156 old_parent->children[j];
2157 old_parent->num_children--;
2161 /* now move the node to a new parent */
2162 new_parent->children[new_parent->num_children++] = node;
2163 node->parent = new_parent;
2164 node->info.parent_teid = new_parent->info.node_teid;
2168 * ice_sched_move_nodes - move child nodes to a given parent
2169 * @pi: port information structure
2170 * @parent: pointer to parent node
2171 * @num_items: number of child nodes to be moved
2172 * @list: pointer to child node teids
2174 * This function move the child nodes to a given parent.
2176 static enum ice_status
2177 ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent,
2178 u16 num_items, u32 *list)
2180 enum ice_status status = ICE_SUCCESS;
2181 struct ice_aqc_move_elem *buf;
2182 struct ice_sched_node *node;
2183 u16 i, grps_movd = 0;
2188 if (!parent || !num_items)
2189 return ICE_ERR_PARAM;
2191 /* Does parent have enough space */
2192 if (parent->num_children + num_items >=
2193 hw->max_children[parent->tx_sched_layer])
2194 return ICE_ERR_AQ_FULL;
2196 buf = (struct ice_aqc_move_elem *)ice_malloc(hw, sizeof(*buf));
2198 return ICE_ERR_NO_MEMORY;
2200 for (i = 0; i < num_items; i++) {
2201 node = ice_sched_find_node_by_teid(pi->root, list[i]);
2203 status = ICE_ERR_PARAM;
2207 buf->hdr.src_parent_teid = node->info.parent_teid;
2208 buf->hdr.dest_parent_teid = parent->info.node_teid;
2209 buf->teid[0] = node->info.node_teid;
2210 buf->hdr.num_elems = CPU_TO_LE16(1);
2211 status = ice_aq_move_sched_elems(hw, 1, buf, sizeof(*buf),
2213 if (status && grps_movd != 1) {
2214 status = ICE_ERR_CFG;
2218 /* update the SW DB */
2219 ice_sched_update_parent(parent, node);
2228 * ice_sched_move_vsi_to_agg - move VSI to aggregator node
2229 * @pi: port information structure
2230 * @vsi_handle: software VSI handle
2231 * @agg_id: aggregator ID
2234 * This function moves a VSI to an aggregator node or its subtree.
2235 * Intermediate nodes may be created if required.
2237 static enum ice_status
2238 ice_sched_move_vsi_to_agg(struct ice_port_info *pi, u16 vsi_handle, u32 agg_id,
2241 struct ice_sched_node *vsi_node, *agg_node, *tc_node, *parent;
2242 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2243 u32 first_node_teid, vsi_teid;
2244 enum ice_status status;
2245 u16 num_nodes_added;
2248 tc_node = ice_sched_get_tc_node(pi, tc);
2252 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2254 return ICE_ERR_DOES_NOT_EXIST;
2256 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
2258 return ICE_ERR_DOES_NOT_EXIST;
2260 aggl = ice_sched_get_agg_layer(pi->hw);
2261 vsil = ice_sched_get_vsi_layer(pi->hw);
2263 /* set intermediate node count to 1 between aggregator and VSI layers */
2264 for (i = aggl + 1; i < vsil; i++)
2267 /* Check if the aggregator subtree has any free node to add the VSI */
2268 for (i = 0; i < agg_node->num_children; i++) {
2269 parent = ice_sched_get_free_vsi_parent(pi->hw,
2270 agg_node->children[i],
2278 for (i = aggl + 1; i < vsil; i++) {
2279 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2283 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2286 /* The newly added node can be a new parent for the next
2289 if (num_nodes_added)
2290 parent = ice_sched_find_node_by_teid(tc_node,
2293 parent = parent->children[0];
2300 vsi_teid = LE32_TO_CPU(vsi_node->info.node_teid);
2301 return ice_sched_move_nodes(pi, parent, 1, &vsi_teid);
2305 * ice_move_all_vsi_to_dflt_agg - move all VSI(s) to default aggregator
2306 * @pi: port information structure
2307 * @agg_info: aggregator info
2308 * @tc: traffic class number
2309 * @rm_vsi_info: true or false
2311 * This function move all the VSI(s) to the default aggregator and delete
2312 * aggregator VSI info based on passed in boolean parameter rm_vsi_info. The
2313 * caller holds the scheduler lock.
2315 static enum ice_status
2316 ice_move_all_vsi_to_dflt_agg(struct ice_port_info *pi,
2317 struct ice_sched_agg_info *agg_info, u8 tc,
2320 struct ice_sched_agg_vsi_info *agg_vsi_info;
2321 struct ice_sched_agg_vsi_info *tmp;
2322 enum ice_status status = ICE_SUCCESS;
2324 LIST_FOR_EACH_ENTRY_SAFE(agg_vsi_info, tmp, &agg_info->agg_vsi_list,
2325 ice_sched_agg_vsi_info, list_entry) {
2326 u16 vsi_handle = agg_vsi_info->vsi_handle;
2328 /* Move VSI to default aggregator */
2329 if (!ice_is_tc_ena(agg_vsi_info->tc_bitmap[0], tc))
2332 status = ice_sched_move_vsi_to_agg(pi, vsi_handle,
2333 ICE_DFLT_AGG_ID, tc);
2337 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2338 if (rm_vsi_info && !agg_vsi_info->tc_bitmap[0]) {
2339 LIST_DEL(&agg_vsi_info->list_entry);
2340 ice_free(pi->hw, agg_vsi_info);
2348 * ice_sched_is_agg_inuse - check whether the aggregator is in use or not
2349 * @pi: port information structure
2350 * @node: node pointer
2352 * This function checks whether the aggregator is attached with any VSI or not.
2355 ice_sched_is_agg_inuse(struct ice_port_info *pi, struct ice_sched_node *node)
2359 vsil = ice_sched_get_vsi_layer(pi->hw);
2360 if (node->tx_sched_layer < vsil - 1) {
2361 for (i = 0; i < node->num_children; i++)
2362 if (ice_sched_is_agg_inuse(pi, node->children[i]))
2366 return node->num_children ? true : false;
2371 * ice_sched_rm_agg_cfg - remove the aggregator node
2372 * @pi: port information structure
2373 * @agg_id: aggregator ID
2376 * This function removes the aggregator node and intermediate nodes if any
2379 static enum ice_status
2380 ice_sched_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2382 struct ice_sched_node *tc_node, *agg_node;
2383 struct ice_hw *hw = pi->hw;
2385 tc_node = ice_sched_get_tc_node(pi, tc);
2389 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2391 return ICE_ERR_DOES_NOT_EXIST;
2393 /* Can't remove the aggregator node if it has children */
2394 if (ice_sched_is_agg_inuse(pi, agg_node))
2395 return ICE_ERR_IN_USE;
2397 /* need to remove the whole subtree if aggregator node is the
2400 while (agg_node->tx_sched_layer > hw->sw_entry_point_layer) {
2401 struct ice_sched_node *parent = agg_node->parent;
2406 if (parent->num_children > 1)
2412 ice_free_sched_node(pi, agg_node);
2417 * ice_rm_agg_cfg_tc - remove aggregator configuration for TC
2418 * @pi: port information structure
2419 * @agg_info: aggregator ID
2421 * @rm_vsi_info: bool value true or false
2423 * This function removes aggregator reference to VSI of given TC. It removes
2424 * the aggregator configuration completely for requested TC. The caller needs
2425 * to hold the scheduler lock.
2427 static enum ice_status
2428 ice_rm_agg_cfg_tc(struct ice_port_info *pi, struct ice_sched_agg_info *agg_info,
2429 u8 tc, bool rm_vsi_info)
2431 enum ice_status status = ICE_SUCCESS;
2433 /* If nothing to remove - return success */
2434 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2435 goto exit_rm_agg_cfg_tc;
2437 status = ice_move_all_vsi_to_dflt_agg(pi, agg_info, tc, rm_vsi_info);
2439 goto exit_rm_agg_cfg_tc;
2441 /* Delete aggregator node(s) */
2442 status = ice_sched_rm_agg_cfg(pi, agg_info->agg_id, tc);
2444 goto exit_rm_agg_cfg_tc;
2446 ice_clear_bit(tc, agg_info->tc_bitmap);
2452 * ice_save_agg_tc_bitmap - save aggregator TC bitmap
2453 * @pi: port information structure
2454 * @agg_id: aggregator ID
2455 * @tc_bitmap: 8 bits TC bitmap
2457 * Save aggregator TC bitmap. This function needs to be called with scheduler
2460 static enum ice_status
2461 ice_save_agg_tc_bitmap(struct ice_port_info *pi, u32 agg_id,
2462 ice_bitmap_t *tc_bitmap)
2464 struct ice_sched_agg_info *agg_info;
2466 agg_info = ice_get_agg_info(pi->hw, agg_id);
2468 return ICE_ERR_PARAM;
2469 ice_cp_bitmap(agg_info->replay_tc_bitmap, tc_bitmap,
2470 ICE_MAX_TRAFFIC_CLASS);
2475 * ice_sched_add_agg_cfg - create an aggregator node
2476 * @pi: port information structure
2477 * @agg_id: aggregator ID
2480 * This function creates an aggregator node and intermediate nodes if required
2483 static enum ice_status
2484 ice_sched_add_agg_cfg(struct ice_port_info *pi, u32 agg_id, u8 tc)
2486 struct ice_sched_node *parent, *agg_node, *tc_node;
2487 u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 };
2488 enum ice_status status = ICE_SUCCESS;
2489 struct ice_hw *hw = pi->hw;
2490 u32 first_node_teid;
2491 u16 num_nodes_added;
2494 tc_node = ice_sched_get_tc_node(pi, tc);
2498 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
2499 /* Does Agg node already exist ? */
2503 aggl = ice_sched_get_agg_layer(hw);
2505 /* need one node in Agg layer */
2506 num_nodes[aggl] = 1;
2508 /* Check whether the intermediate nodes have space to add the
2509 * new aggregator. If they are full, then SW needs to allocate a new
2510 * intermediate node on those layers
2512 for (i = hw->sw_entry_point_layer; i < aggl; i++) {
2513 parent = ice_sched_get_first_node(pi, tc_node, i);
2515 /* scan all the siblings */
2517 if (parent->num_children < hw->max_children[i])
2519 parent = parent->sibling;
2522 /* all the nodes are full, reserve one for this layer */
2527 /* add the aggregator node */
2529 for (i = hw->sw_entry_point_layer; i <= aggl; i++) {
2533 status = ice_sched_add_nodes_to_layer(pi, tc_node, parent, i,
2537 if (status != ICE_SUCCESS || num_nodes[i] != num_nodes_added)
2540 /* The newly added node can be a new parent for the next
2543 if (num_nodes_added) {
2544 parent = ice_sched_find_node_by_teid(tc_node,
2546 /* register aggregator ID with the aggregator node */
2547 if (parent && i == aggl)
2548 parent->agg_id = agg_id;
2550 parent = parent->children[0];
2558 * ice_sched_cfg_agg - configure aggregator node
2559 * @pi: port information structure
2560 * @agg_id: aggregator ID
2561 * @agg_type: aggregator type queue, VSI, or aggregator group
2562 * @tc_bitmap: bits TC bitmap
2564 * It registers a unique aggregator node into scheduler services. It
2565 * allows a user to register with a unique ID to track it's resources.
2566 * The aggregator type determines if this is a queue group, VSI group
2567 * or aggregator group. It then creates the aggregator node(s) for requested
2568 * TC(s) or removes an existing aggregator node including its configuration
2569 * if indicated via tc_bitmap. Call ice_rm_agg_cfg to release aggregator
2570 * resources and remove aggregator ID.
2571 * This function needs to be called with scheduler lock held.
2573 static enum ice_status
2574 ice_sched_cfg_agg(struct ice_port_info *pi, u32 agg_id,
2575 enum ice_agg_type agg_type, ice_bitmap_t *tc_bitmap)
2577 struct ice_sched_agg_info *agg_info;
2578 enum ice_status status = ICE_SUCCESS;
2579 struct ice_hw *hw = pi->hw;
2582 agg_info = ice_get_agg_info(hw, agg_id);
2584 /* Create new entry for new aggregator ID */
2585 agg_info = (struct ice_sched_agg_info *)
2586 ice_malloc(hw, sizeof(*agg_info));
2588 status = ICE_ERR_NO_MEMORY;
2591 agg_info->agg_id = agg_id;
2592 agg_info->agg_type = agg_type;
2593 agg_info->tc_bitmap[0] = 0;
2595 /* Initialize the aggregator VSI list head */
2596 INIT_LIST_HEAD(&agg_info->agg_vsi_list);
2598 /* Add new entry in aggregator list */
2599 LIST_ADD(&agg_info->list_entry, &hw->agg_list);
2601 /* Create aggregator node(s) for requested TC(s) */
2602 ice_for_each_traffic_class(tc) {
2603 if (!ice_is_tc_ena(*tc_bitmap, tc)) {
2604 /* Delete aggregator cfg TC if it exists previously */
2605 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, false);
2611 /* Check if aggregator node for TC already exists */
2612 if (ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
2615 /* Create new aggregator node for TC */
2616 status = ice_sched_add_agg_cfg(pi, agg_id, tc);
2620 /* Save aggregator node's TC information */
2621 ice_set_bit(tc, agg_info->tc_bitmap);
2628 * ice_cfg_agg - config aggregator node
2629 * @pi: port information structure
2630 * @agg_id: aggregator ID
2631 * @agg_type: aggregator type queue, VSI, or aggregator group
2632 * @tc_bitmap: bits TC bitmap
2634 * This function configures aggregator node(s).
2637 ice_cfg_agg(struct ice_port_info *pi, u32 agg_id, enum ice_agg_type agg_type,
2640 ice_bitmap_t bitmap = tc_bitmap;
2641 enum ice_status status;
2643 ice_acquire_lock(&pi->sched_lock);
2644 status = ice_sched_cfg_agg(pi, agg_id, agg_type,
2645 (ice_bitmap_t *)&bitmap);
2647 status = ice_save_agg_tc_bitmap(pi, agg_id,
2648 (ice_bitmap_t *)&bitmap);
2649 ice_release_lock(&pi->sched_lock);
2654 * ice_get_agg_vsi_info - get the aggregator ID
2655 * @agg_info: aggregator info
2656 * @vsi_handle: software VSI handle
2658 * The function returns aggregator VSI info based on VSI handle. This function
2659 * needs to be called with scheduler lock held.
2661 static struct ice_sched_agg_vsi_info*
2662 ice_get_agg_vsi_info(struct ice_sched_agg_info *agg_info, u16 vsi_handle)
2664 struct ice_sched_agg_vsi_info *agg_vsi_info;
2666 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
2667 ice_sched_agg_vsi_info, list_entry)
2668 if (agg_vsi_info->vsi_handle == vsi_handle)
2669 return agg_vsi_info;
2675 * ice_get_vsi_agg_info - get the aggregator info of VSI
2676 * @hw: pointer to the hardware structure
2677 * @vsi_handle: Sw VSI handle
2679 * The function returns aggregator info of VSI represented via vsi_handle. The
2680 * VSI has in this case a different aggregator than the default one. This
2681 * function needs to be called with scheduler lock held.
2683 static struct ice_sched_agg_info*
2684 ice_get_vsi_agg_info(struct ice_hw *hw, u16 vsi_handle)
2686 struct ice_sched_agg_info *agg_info;
2688 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
2690 struct ice_sched_agg_vsi_info *agg_vsi_info;
2692 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2700 * ice_save_agg_vsi_tc_bitmap - save aggregator VSI TC bitmap
2701 * @pi: port information structure
2702 * @agg_id: aggregator ID
2703 * @vsi_handle: software VSI handle
2704 * @tc_bitmap: TC bitmap of enabled TC(s)
2706 * Save VSI to aggregator TC bitmap. This function needs to call with scheduler
2709 static enum ice_status
2710 ice_save_agg_vsi_tc_bitmap(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2711 ice_bitmap_t *tc_bitmap)
2713 struct ice_sched_agg_vsi_info *agg_vsi_info;
2714 struct ice_sched_agg_info *agg_info;
2716 agg_info = ice_get_agg_info(pi->hw, agg_id);
2718 return ICE_ERR_PARAM;
2719 /* check if entry already exist */
2720 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2722 return ICE_ERR_PARAM;
2723 ice_cp_bitmap(agg_vsi_info->replay_tc_bitmap, tc_bitmap,
2724 ICE_MAX_TRAFFIC_CLASS);
2729 * ice_sched_assoc_vsi_to_agg - associate/move VSI to new/default aggregator
2730 * @pi: port information structure
2731 * @agg_id: aggregator ID
2732 * @vsi_handle: software VSI handle
2733 * @tc_bitmap: TC bitmap of enabled TC(s)
2735 * This function moves VSI to a new or default aggregator node. If VSI is
2736 * already associated to the aggregator node then no operation is performed on
2737 * the tree. This function needs to be called with scheduler lock held.
2739 static enum ice_status
2740 ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
2741 u16 vsi_handle, ice_bitmap_t *tc_bitmap)
2743 struct ice_sched_agg_vsi_info *agg_vsi_info;
2744 struct ice_sched_agg_info *agg_info;
2745 enum ice_status status = ICE_SUCCESS;
2746 struct ice_hw *hw = pi->hw;
2749 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
2750 return ICE_ERR_PARAM;
2751 agg_info = ice_get_agg_info(hw, agg_id);
2753 return ICE_ERR_PARAM;
2754 /* check if entry already exist */
2755 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
2756 if (!agg_vsi_info) {
2757 /* Create new entry for VSI under aggregator list */
2758 agg_vsi_info = (struct ice_sched_agg_vsi_info *)
2759 ice_malloc(hw, sizeof(*agg_vsi_info));
2761 return ICE_ERR_PARAM;
2763 /* add VSI ID into the aggregator list */
2764 agg_vsi_info->vsi_handle = vsi_handle;
2765 LIST_ADD(&agg_vsi_info->list_entry, &agg_info->agg_vsi_list);
2767 /* Move VSI node to new aggregator node for requested TC(s) */
2768 ice_for_each_traffic_class(tc) {
2769 if (!ice_is_tc_ena(*tc_bitmap, tc))
2772 /* Move VSI to new aggregator */
2773 status = ice_sched_move_vsi_to_agg(pi, vsi_handle, agg_id, tc);
2777 if (agg_id != ICE_DFLT_AGG_ID)
2778 ice_set_bit(tc, agg_vsi_info->tc_bitmap);
2780 ice_clear_bit(tc, agg_vsi_info->tc_bitmap);
2782 /* If VSI moved back to default aggregator, delete agg_vsi_info. */
2783 if (!ice_is_any_bit_set(agg_vsi_info->tc_bitmap,
2784 ICE_MAX_TRAFFIC_CLASS)) {
2785 LIST_DEL(&agg_vsi_info->list_entry);
2786 ice_free(hw, agg_vsi_info);
2792 * ice_sched_rm_unused_rl_prof - remove unused RL profile
2793 * @pi: port information structure
2795 * This function removes unused rate limit profiles from the HW and
2796 * SW DB. The caller needs to hold scheduler lock.
2798 static void ice_sched_rm_unused_rl_prof(struct ice_port_info *pi)
2802 for (ln = 0; ln < pi->hw->num_tx_sched_layers; ln++) {
2803 struct ice_aqc_rl_profile_info *rl_prof_elem;
2804 struct ice_aqc_rl_profile_info *rl_prof_tmp;
2806 LIST_FOR_EACH_ENTRY_SAFE(rl_prof_elem, rl_prof_tmp,
2807 &pi->rl_prof_list[ln],
2808 ice_aqc_rl_profile_info, list_entry) {
2809 if (!ice_sched_del_rl_profile(pi->hw, rl_prof_elem))
2810 ice_debug(pi->hw, ICE_DBG_SCHED,
2811 "Removed rl profile\n");
2817 * ice_sched_update_elem - update element
2818 * @hw: pointer to the HW struct
2819 * @node: pointer to node
2820 * @info: node info to update
2822 * It updates the HW DB, and local SW DB of node. It updates the scheduling
2823 * parameters of node from argument info data buffer (Info->data buf) and
2824 * returns success or error on config sched element failure. The caller
2825 * needs to hold scheduler lock.
2827 static enum ice_status
2828 ice_sched_update_elem(struct ice_hw *hw, struct ice_sched_node *node,
2829 struct ice_aqc_txsched_elem_data *info)
2831 struct ice_aqc_conf_elem buf;
2832 enum ice_status status;
2836 buf.generic[0] = *info;
2837 /* Parent TEID is reserved field in this aq call */
2838 buf.generic[0].parent_teid = 0;
2839 /* Element type is reserved field in this aq call */
2840 buf.generic[0].data.elem_type = 0;
2841 /* Flags is reserved field in this aq call */
2842 buf.generic[0].data.flags = 0;
2845 /* Configure element node */
2846 status = ice_aq_cfg_sched_elems(hw, num_elems, &buf, sizeof(buf),
2848 if (status || elem_cfgd != num_elems) {
2849 ice_debug(hw, ICE_DBG_SCHED, "Config sched elem error\n");
2853 /* Config success case */
2854 /* Now update local SW DB */
2855 /* Only copy the data portion of info buffer */
2856 node->info.data = info->data;
2861 * ice_sched_cfg_node_bw_alloc - configure node BW weight/alloc params
2862 * @hw: pointer to the HW struct
2863 * @node: sched node to configure
2864 * @rl_type: rate limit type CIR, EIR, or shared
2865 * @bw_alloc: BW weight/allocation
2867 * This function configures node element's BW allocation.
2869 static enum ice_status
2870 ice_sched_cfg_node_bw_alloc(struct ice_hw *hw, struct ice_sched_node *node,
2871 enum ice_rl_type rl_type, u8 bw_alloc)
2873 struct ice_aqc_txsched_elem_data buf;
2874 struct ice_aqc_txsched_elem *data;
2875 enum ice_status status;
2879 if (rl_type == ICE_MIN_BW) {
2880 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
2881 data->cir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2882 } else if (rl_type == ICE_MAX_BW) {
2883 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
2884 data->eir_bw.bw_alloc = CPU_TO_LE16(bw_alloc);
2886 return ICE_ERR_PARAM;
2889 /* Configure element */
2890 status = ice_sched_update_elem(hw, node, &buf);
2895 * ice_move_vsi_to_agg - moves VSI to new or default aggregator
2896 * @pi: port information structure
2897 * @agg_id: aggregator ID
2898 * @vsi_handle: software VSI handle
2899 * @tc_bitmap: TC bitmap of enabled TC(s)
2901 * Move or associate VSI to a new or default aggregator node.
2904 ice_move_vsi_to_agg(struct ice_port_info *pi, u32 agg_id, u16 vsi_handle,
2907 ice_bitmap_t bitmap = tc_bitmap;
2908 enum ice_status status;
2910 ice_acquire_lock(&pi->sched_lock);
2911 status = ice_sched_assoc_vsi_to_agg(pi, agg_id, vsi_handle,
2912 (ice_bitmap_t *)&bitmap);
2914 status = ice_save_agg_vsi_tc_bitmap(pi, agg_id, vsi_handle,
2915 (ice_bitmap_t *)&bitmap);
2916 ice_release_lock(&pi->sched_lock);
2921 * ice_rm_agg_cfg - remove aggregator configuration
2922 * @pi: port information structure
2923 * @agg_id: aggregator ID
2925 * This function removes aggregator reference to VSI and delete aggregator ID
2926 * info. It removes the aggregator configuration completely.
2928 enum ice_status ice_rm_agg_cfg(struct ice_port_info *pi, u32 agg_id)
2930 struct ice_sched_agg_info *agg_info;
2931 enum ice_status status = ICE_SUCCESS;
2934 ice_acquire_lock(&pi->sched_lock);
2935 agg_info = ice_get_agg_info(pi->hw, agg_id);
2937 status = ICE_ERR_DOES_NOT_EXIST;
2938 goto exit_ice_rm_agg_cfg;
2941 ice_for_each_traffic_class(tc) {
2942 status = ice_rm_agg_cfg_tc(pi, agg_info, tc, true);
2944 goto exit_ice_rm_agg_cfg;
2947 if (ice_is_any_bit_set(agg_info->tc_bitmap, ICE_MAX_TRAFFIC_CLASS)) {
2948 status = ICE_ERR_IN_USE;
2949 goto exit_ice_rm_agg_cfg;
2952 /* Safe to delete entry now */
2953 LIST_DEL(&agg_info->list_entry);
2954 ice_free(pi->hw, agg_info);
2956 /* Remove unused RL profile IDs from HW and SW DB */
2957 ice_sched_rm_unused_rl_prof(pi);
2959 exit_ice_rm_agg_cfg:
2960 ice_release_lock(&pi->sched_lock);
2965 * ice_set_clear_cir_bw_alloc - set or clear CIR BW alloc information
2966 * @bw_t_info: bandwidth type information structure
2967 * @bw_alloc: Bandwidth allocation information
2969 * Save or clear CIR BW alloc information (bw_alloc) in the passed param
2973 ice_set_clear_cir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
2975 bw_t_info->cir_bw.bw_alloc = bw_alloc;
2976 if (bw_t_info->cir_bw.bw_alloc)
2977 ice_set_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
2979 ice_clear_bit(ICE_BW_TYPE_CIR_WT, bw_t_info->bw_t_bitmap);
2983 * ice_set_clear_eir_bw_alloc - set or clear EIR BW alloc information
2984 * @bw_t_info: bandwidth type information structure
2985 * @bw_alloc: Bandwidth allocation information
2987 * Save or clear EIR BW alloc information (bw_alloc) in the passed param
2991 ice_set_clear_eir_bw_alloc(struct ice_bw_type_info *bw_t_info, u16 bw_alloc)
2993 bw_t_info->eir_bw.bw_alloc = bw_alloc;
2994 if (bw_t_info->eir_bw.bw_alloc)
2995 ice_set_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
2997 ice_clear_bit(ICE_BW_TYPE_EIR_WT, bw_t_info->bw_t_bitmap);
3001 * ice_sched_save_vsi_bw_alloc - save VSI node's BW alloc information
3002 * @pi: port information structure
3003 * @vsi_handle: sw VSI handle
3004 * @tc: traffic class
3005 * @rl_type: rate limit type min or max
3006 * @bw_alloc: Bandwidth allocation information
3008 * Save BW alloc information of VSI type node for post replay use.
3010 static enum ice_status
3011 ice_sched_save_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3012 enum ice_rl_type rl_type, u16 bw_alloc)
3014 struct ice_vsi_ctx *vsi_ctx;
3016 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3017 return ICE_ERR_PARAM;
3018 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3020 return ICE_ERR_PARAM;
3023 ice_set_clear_cir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3027 ice_set_clear_eir_bw_alloc(&vsi_ctx->sched.bw_t_info[tc],
3031 return ICE_ERR_PARAM;
3037 * ice_set_clear_cir_bw - set or clear CIR BW
3038 * @bw_t_info: bandwidth type information structure
3039 * @bw: bandwidth in Kbps - Kilo bits per sec
3041 * Save or clear CIR bandwidth (BW) in the passed param bw_t_info.
3044 ice_set_clear_cir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3046 if (bw == ICE_SCHED_DFLT_BW) {
3047 ice_clear_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3048 bw_t_info->cir_bw.bw = 0;
3050 /* Save type of BW information */
3051 ice_set_bit(ICE_BW_TYPE_CIR, bw_t_info->bw_t_bitmap);
3052 bw_t_info->cir_bw.bw = bw;
3057 * ice_set_clear_eir_bw - set or clear EIR BW
3058 * @bw_t_info: bandwidth type information structure
3059 * @bw: bandwidth in Kbps - Kilo bits per sec
3061 * Save or clear EIR bandwidth (BW) in the passed param bw_t_info.
3064 ice_set_clear_eir_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3066 if (bw == ICE_SCHED_DFLT_BW) {
3067 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3068 bw_t_info->eir_bw.bw = 0;
3070 /* EIR BW and Shared BW profiles are mutually exclusive and
3071 * hence only one of them may be set for any given element.
3072 * First clear earlier saved shared BW information.
3074 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3075 bw_t_info->shared_bw = 0;
3076 /* save EIR BW information */
3077 ice_set_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3078 bw_t_info->eir_bw.bw = bw;
3083 * ice_set_clear_shared_bw - set or clear shared BW
3084 * @bw_t_info: bandwidth type information structure
3085 * @bw: bandwidth in Kbps - Kilo bits per sec
3087 * Save or clear shared bandwidth (BW) in the passed param bw_t_info.
3090 ice_set_clear_shared_bw(struct ice_bw_type_info *bw_t_info, u32 bw)
3092 if (bw == ICE_SCHED_DFLT_BW) {
3093 ice_clear_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3094 bw_t_info->shared_bw = 0;
3096 /* EIR BW and Shared BW profiles are mutually exclusive and
3097 * hence only one of them may be set for any given element.
3098 * First clear earlier saved EIR BW information.
3100 ice_clear_bit(ICE_BW_TYPE_EIR, bw_t_info->bw_t_bitmap);
3101 bw_t_info->eir_bw.bw = 0;
3102 /* save shared BW information */
3103 ice_set_bit(ICE_BW_TYPE_SHARED, bw_t_info->bw_t_bitmap);
3104 bw_t_info->shared_bw = bw;
3109 * ice_sched_save_vsi_bw - save VSI node's BW information
3110 * @pi: port information structure
3111 * @vsi_handle: sw VSI handle
3112 * @tc: traffic class
3113 * @rl_type: rate limit type min, max, or shared
3114 * @bw: bandwidth in Kbps - Kilo bits per sec
3116 * Save BW information of VSI type node for post replay use.
3118 static enum ice_status
3119 ice_sched_save_vsi_bw(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3120 enum ice_rl_type rl_type, u32 bw)
3122 struct ice_vsi_ctx *vsi_ctx;
3124 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3125 return ICE_ERR_PARAM;
3126 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3128 return ICE_ERR_PARAM;
3131 ice_set_clear_cir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3134 ice_set_clear_eir_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3137 ice_set_clear_shared_bw(&vsi_ctx->sched.bw_t_info[tc], bw);
3140 return ICE_ERR_PARAM;
3146 * ice_set_clear_prio - set or clear priority information
3147 * @bw_t_info: bandwidth type information structure
3148 * @prio: priority to save
3150 * Save or clear priority (prio) in the passed param bw_t_info.
3153 ice_set_clear_prio(struct ice_bw_type_info *bw_t_info, u8 prio)
3155 bw_t_info->generic = prio;
3156 if (bw_t_info->generic)
3157 ice_set_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3159 ice_clear_bit(ICE_BW_TYPE_PRIO, bw_t_info->bw_t_bitmap);
3163 * ice_sched_save_vsi_prio - save VSI node's priority information
3164 * @pi: port information structure
3165 * @vsi_handle: Software VSI handle
3166 * @tc: traffic class
3167 * @prio: priority to save
3169 * Save priority information of VSI type node for post replay use.
3171 static enum ice_status
3172 ice_sched_save_vsi_prio(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3175 struct ice_vsi_ctx *vsi_ctx;
3177 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3178 return ICE_ERR_PARAM;
3179 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
3181 return ICE_ERR_PARAM;
3182 if (tc >= ICE_MAX_TRAFFIC_CLASS)
3183 return ICE_ERR_PARAM;
3184 ice_set_clear_prio(&vsi_ctx->sched.bw_t_info[tc], prio);
3189 * ice_sched_save_agg_bw_alloc - save aggregator node's BW alloc information
3190 * @pi: port information structure
3191 * @agg_id: node aggregator ID
3192 * @tc: traffic class
3193 * @rl_type: rate limit type min or max
3194 * @bw_alloc: bandwidth alloc information
3196 * Save BW alloc information of AGG type node for post replay use.
3198 static enum ice_status
3199 ice_sched_save_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3200 enum ice_rl_type rl_type, u16 bw_alloc)
3202 struct ice_sched_agg_info *agg_info;
3204 agg_info = ice_get_agg_info(pi->hw, agg_id);
3206 return ICE_ERR_PARAM;
3207 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3208 return ICE_ERR_PARAM;
3211 ice_set_clear_cir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3214 ice_set_clear_eir_bw_alloc(&agg_info->bw_t_info[tc], bw_alloc);
3217 return ICE_ERR_PARAM;
3223 * ice_sched_save_agg_bw - save aggregator node's BW information
3224 * @pi: port information structure
3225 * @agg_id: node aggregator ID
3226 * @tc: traffic class
3227 * @rl_type: rate limit type min, max, or shared
3228 * @bw: bandwidth in Kbps - Kilo bits per sec
3230 * Save BW information of AGG type node for post replay use.
3232 static enum ice_status
3233 ice_sched_save_agg_bw(struct ice_port_info *pi, u32 agg_id, u8 tc,
3234 enum ice_rl_type rl_type, u32 bw)
3236 struct ice_sched_agg_info *agg_info;
3238 agg_info = ice_get_agg_info(pi->hw, agg_id);
3240 return ICE_ERR_PARAM;
3241 if (!ice_is_tc_ena(agg_info->tc_bitmap[0], tc))
3242 return ICE_ERR_PARAM;
3245 ice_set_clear_cir_bw(&agg_info->bw_t_info[tc], bw);
3248 ice_set_clear_eir_bw(&agg_info->bw_t_info[tc], bw);
3251 ice_set_clear_shared_bw(&agg_info->bw_t_info[tc], bw);
3254 return ICE_ERR_PARAM;
3260 * ice_cfg_vsi_bw_lmt_per_tc - configure VSI BW limit per TC
3261 * @pi: port information structure
3262 * @vsi_handle: software VSI handle
3263 * @tc: traffic class
3264 * @rl_type: min or max
3265 * @bw: bandwidth in Kbps
3267 * This function configures BW limit of VSI scheduling node based on TC
3271 ice_cfg_vsi_bw_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3272 enum ice_rl_type rl_type, u32 bw)
3274 enum ice_status status;
3276 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3280 ice_acquire_lock(&pi->sched_lock);
3281 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
3282 ice_release_lock(&pi->sched_lock);
3288 * ice_cfg_dflt_vsi_bw_lmt_per_tc - configure default VSI BW limit per TC
3289 * @pi: port information structure
3290 * @vsi_handle: software VSI handle
3291 * @tc: traffic class
3292 * @rl_type: min or max
3294 * This function configures default BW limit of VSI scheduling node based on TC
3298 ice_cfg_vsi_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
3299 enum ice_rl_type rl_type)
3301 enum ice_status status;
3303 status = ice_sched_set_node_bw_lmt_per_tc(pi, vsi_handle,
3308 ice_acquire_lock(&pi->sched_lock);
3309 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type,
3311 ice_release_lock(&pi->sched_lock);
3317 * ice_cfg_agg_bw_lmt_per_tc - configure aggregator BW limit per TC
3318 * @pi: port information structure
3319 * @agg_id: aggregator ID
3320 * @tc: traffic class
3321 * @rl_type: min or max
3322 * @bw: bandwidth in Kbps
3324 * This function applies BW limit to aggregator scheduling node based on TC
3328 ice_cfg_agg_bw_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3329 enum ice_rl_type rl_type, u32 bw)
3331 enum ice_status status;
3333 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3336 ice_acquire_lock(&pi->sched_lock);
3337 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
3338 ice_release_lock(&pi->sched_lock);
3344 * ice_cfg_agg_bw_dflt_lmt_per_tc - configure aggregator BW default limit per TC
3345 * @pi: port information structure
3346 * @agg_id: aggregator ID
3347 * @tc: traffic class
3348 * @rl_type: min or max
3350 * This function applies default BW limit to aggregator scheduling node based
3351 * on TC information.
3354 ice_cfg_agg_bw_dflt_lmt_per_tc(struct ice_port_info *pi, u32 agg_id, u8 tc,
3355 enum ice_rl_type rl_type)
3357 enum ice_status status;
3359 status = ice_sched_set_node_bw_lmt_per_tc(pi, agg_id, ICE_AGG_TYPE_AGG,
3363 ice_acquire_lock(&pi->sched_lock);
3364 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type,
3366 ice_release_lock(&pi->sched_lock);
3372 * ice_cfg_vsi_bw_shared_lmt - configure VSI BW shared limit
3373 * @pi: port information structure
3374 * @vsi_handle: software VSI handle
3375 * @bw: bandwidth in Kbps
3377 * This function Configures shared rate limiter(SRL) of all VSI type nodes
3378 * across all traffic classes for VSI matching handle.
3381 ice_cfg_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle, u32 bw)
3383 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle, bw);
3387 * ice_cfg_vsi_bw_no_shared_lmt - configure VSI BW for no shared limiter
3388 * @pi: port information structure
3389 * @vsi_handle: software VSI handle
3391 * This function removes the shared rate limiter(SRL) of all VSI type nodes
3392 * across all traffic classes for VSI matching handle.
3395 ice_cfg_vsi_bw_no_shared_lmt(struct ice_port_info *pi, u16 vsi_handle)
3397 return ice_sched_set_vsi_bw_shared_lmt(pi, vsi_handle,
3402 * ice_cfg_agg_bw_shared_lmt - configure aggregator BW shared limit
3403 * @pi: port information structure
3404 * @agg_id: aggregator ID
3405 * @bw: bandwidth in Kbps
3407 * This function configures the shared rate limiter(SRL) of all aggregator type
3408 * nodes across all traffic classes for aggregator matching agg_id.
3411 ice_cfg_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
3413 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, bw);
3417 * ice_cfg_agg_bw_no_shared_lmt - configure aggregator BW for no shared limiter
3418 * @pi: port information structure
3419 * @agg_id: aggregator ID
3421 * This function removes the shared rate limiter(SRL) of all aggregator type
3422 * nodes across all traffic classes for aggregator matching agg_id.
3425 ice_cfg_agg_bw_no_shared_lmt(struct ice_port_info *pi, u32 agg_id)
3427 return ice_sched_set_agg_bw_shared_lmt(pi, agg_id, ICE_SCHED_DFLT_BW);
3431 * ice_config_vsi_queue_priority - config VSI queue priority of node
3432 * @pi: port information structure
3433 * @num_qs: number of VSI queues
3434 * @q_ids: queue IDs array
3435 * @q_ids: queue IDs array
3436 * @q_prio: queue priority array
3438 * This function configures the queue node priority (Sibling Priority) of the
3439 * passed in VSI's queue(s) for a given traffic class (TC).
3442 ice_cfg_vsi_q_priority(struct ice_port_info *pi, u16 num_qs, u32 *q_ids,
3445 enum ice_status status = ICE_ERR_PARAM;
3448 ice_acquire_lock(&pi->sched_lock);
3450 for (i = 0; i < num_qs; i++) {
3451 struct ice_sched_node *node;
3453 node = ice_sched_find_node_by_teid(pi->root, q_ids[i]);
3454 if (!node || node->info.data.elem_type !=
3455 ICE_AQC_ELEM_TYPE_LEAF) {
3456 status = ICE_ERR_PARAM;
3459 /* Configure Priority */
3460 status = ice_sched_cfg_sibl_node_prio(pi, node, q_prio[i]);
3465 ice_release_lock(&pi->sched_lock);
3470 * ice_cfg_agg_vsi_priority_per_tc - config aggregator's VSI priority per TC
3471 * @pi: port information structure
3472 * @agg_id: Aggregator ID
3473 * @num_vsis: number of VSI(s)
3474 * @vsi_handle_arr: array of software VSI handles
3475 * @node_prio: pointer to node priority
3476 * @tc: traffic class
3478 * This function configures the node priority (Sibling Priority) of the
3479 * passed in VSI's for a given traffic class (TC) of an Aggregator ID.
3482 ice_cfg_agg_vsi_priority_per_tc(struct ice_port_info *pi, u32 agg_id,
3483 u16 num_vsis, u16 *vsi_handle_arr,
3484 u8 *node_prio, u8 tc)
3486 struct ice_sched_agg_vsi_info *agg_vsi_info;
3487 struct ice_sched_node *tc_node, *agg_node;
3488 enum ice_status status = ICE_ERR_PARAM;
3489 struct ice_sched_agg_info *agg_info;
3490 bool agg_id_present = false;
3491 struct ice_hw *hw = pi->hw;
3494 ice_acquire_lock(&pi->sched_lock);
3495 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3497 if (agg_info->agg_id == agg_id) {
3498 agg_id_present = true;
3501 if (!agg_id_present)
3502 goto exit_agg_priority_per_tc;
3504 tc_node = ice_sched_get_tc_node(pi, tc);
3506 goto exit_agg_priority_per_tc;
3508 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3510 goto exit_agg_priority_per_tc;
3512 if (num_vsis > hw->max_children[agg_node->tx_sched_layer])
3513 goto exit_agg_priority_per_tc;
3515 for (i = 0; i < num_vsis; i++) {
3516 struct ice_sched_node *vsi_node;
3517 bool vsi_handle_valid = false;
3520 status = ICE_ERR_PARAM;
3521 vsi_handle = vsi_handle_arr[i];
3522 if (!ice_is_vsi_valid(hw, vsi_handle))
3523 goto exit_agg_priority_per_tc;
3524 /* Verify child nodes before applying settings */
3525 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
3526 ice_sched_agg_vsi_info, list_entry)
3527 if (agg_vsi_info->vsi_handle == vsi_handle) {
3528 /* cppcheck-suppress unreadVariable */
3529 vsi_handle_valid = true;
3533 if (!vsi_handle_valid)
3534 goto exit_agg_priority_per_tc;
3536 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3538 goto exit_agg_priority_per_tc;
3540 if (ice_sched_find_node_in_subtree(hw, agg_node, vsi_node)) {
3541 /* Configure Priority */
3542 status = ice_sched_cfg_sibl_node_prio(pi, vsi_node,
3546 status = ice_sched_save_vsi_prio(pi, vsi_handle, tc,
3553 exit_agg_priority_per_tc:
3554 ice_release_lock(&pi->sched_lock);
3559 * ice_cfg_vsi_bw_alloc - config VSI BW alloc per TC
3560 * @pi: port information structure
3561 * @vsi_handle: software VSI handle
3562 * @ena_tcmap: enabled TC map
3563 * @rl_type: Rate limit type CIR/EIR
3564 * @bw_alloc: Array of BW alloc
3566 * This function configures the BW allocation of the passed in VSI's
3567 * node(s) for enabled traffic class.
3570 ice_cfg_vsi_bw_alloc(struct ice_port_info *pi, u16 vsi_handle, u8 ena_tcmap,
3571 enum ice_rl_type rl_type, u8 *bw_alloc)
3573 enum ice_status status = ICE_SUCCESS;
3576 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
3577 return ICE_ERR_PARAM;
3579 ice_acquire_lock(&pi->sched_lock);
3581 /* Return success if no nodes are present across TC */
3582 ice_for_each_traffic_class(tc) {
3583 struct ice_sched_node *tc_node, *vsi_node;
3585 if (!ice_is_tc_ena(ena_tcmap, tc))
3588 tc_node = ice_sched_get_tc_node(pi, tc);
3592 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
3596 status = ice_sched_cfg_node_bw_alloc(pi->hw, vsi_node, rl_type,
3600 status = ice_sched_save_vsi_bw_alloc(pi, vsi_handle, tc,
3601 rl_type, bw_alloc[tc]);
3606 ice_release_lock(&pi->sched_lock);
3611 * ice_cfg_agg_bw_alloc - config aggregator BW alloc
3612 * @pi: port information structure
3613 * @agg_id: aggregator ID
3614 * @ena_tcmap: enabled TC map
3615 * @rl_type: rate limit type CIR/EIR
3616 * @bw_alloc: array of BW alloc
3618 * This function configures the BW allocation of passed in aggregator for
3619 * enabled traffic class(s).
3622 ice_cfg_agg_bw_alloc(struct ice_port_info *pi, u32 agg_id, u8 ena_tcmap,
3623 enum ice_rl_type rl_type, u8 *bw_alloc)
3625 struct ice_sched_agg_info *agg_info;
3626 bool agg_id_present = false;
3627 enum ice_status status = ICE_SUCCESS;
3628 struct ice_hw *hw = pi->hw;
3631 ice_acquire_lock(&pi->sched_lock);
3632 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
3634 if (agg_info->agg_id == agg_id) {
3635 agg_id_present = true;
3638 if (!agg_id_present) {
3639 status = ICE_ERR_PARAM;
3640 goto exit_cfg_agg_bw_alloc;
3643 /* Return success if no nodes are present across TC */
3644 ice_for_each_traffic_class(tc) {
3645 struct ice_sched_node *tc_node, *agg_node;
3647 if (!ice_is_tc_ena(ena_tcmap, tc))
3650 tc_node = ice_sched_get_tc_node(pi, tc);
3654 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
3658 status = ice_sched_cfg_node_bw_alloc(hw, agg_node, rl_type,
3662 status = ice_sched_save_agg_bw_alloc(pi, agg_id, tc, rl_type,
3668 exit_cfg_agg_bw_alloc:
3669 ice_release_lock(&pi->sched_lock);
3674 * ice_sched_calc_wakeup - calculate RL profile wakeup parameter
3675 * @bw: bandwidth in Kbps
3677 * This function calculates the wakeup parameter of RL profile.
3679 static u16 ice_sched_calc_wakeup(s32 bw)
3681 s64 bytes_per_sec, wakeup_int, wakeup_a, wakeup_b, wakeup_f;
3685 /* Get the wakeup integer value */
3686 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3687 wakeup_int = DIV_64BIT(ICE_RL_PROF_FREQUENCY, bytes_per_sec);
3688 if (wakeup_int > 63) {
3689 wakeup = (u16)((1 << 15) | wakeup_int);
3691 /* Calculate fraction value up to 4 decimals
3692 * Convert Integer value to a constant multiplier
3694 wakeup_b = (s64)ICE_RL_PROF_MULTIPLIER * wakeup_int;
3695 wakeup_a = DIV_64BIT((s64)ICE_RL_PROF_MULTIPLIER *
3696 ICE_RL_PROF_FREQUENCY, bytes_per_sec);
3698 /* Get Fraction value */
3699 wakeup_f = wakeup_a - wakeup_b;
3701 /* Round up the Fractional value via Ceil(Fractional value) */
3702 if (wakeup_f > DIV_64BIT(ICE_RL_PROF_MULTIPLIER, 2))
3705 wakeup_f_int = (s32)DIV_64BIT(wakeup_f * ICE_RL_PROF_FRACTION,
3706 ICE_RL_PROF_MULTIPLIER);
3707 wakeup |= (u16)(wakeup_int << 9);
3708 wakeup |= (u16)(0x1ff & wakeup_f_int);
3715 * ice_sched_bw_to_rl_profile - convert BW to profile parameters
3716 * @bw: bandwidth in Kbps
3717 * @profile: profile parameters to return
3719 * This function converts the BW to profile structure format.
3721 static enum ice_status
3722 ice_sched_bw_to_rl_profile(u32 bw, struct ice_aqc_rl_profile_elem *profile)
3724 enum ice_status status = ICE_ERR_PARAM;
3725 s64 bytes_per_sec, ts_rate, mv_tmp;
3731 /* Bw settings range is from 0.5Mb/sec to 100Gb/sec */
3732 if (bw < ICE_SCHED_MIN_BW || bw > ICE_SCHED_MAX_BW)
3735 /* Bytes per second from Kbps */
3736 bytes_per_sec = DIV_64BIT(((s64)bw * 1000), BITS_PER_BYTE);
3738 /* encode is 6 bits but really useful are 5 bits */
3739 for (i = 0; i < 64; i++) {
3740 u64 pow_result = BIT_ULL(i);
3742 ts_rate = DIV_64BIT((s64)ICE_RL_PROF_FREQUENCY,
3743 pow_result * ICE_RL_PROF_TS_MULTIPLIER);
3747 /* Multiplier value */
3748 mv_tmp = DIV_64BIT(bytes_per_sec * ICE_RL_PROF_MULTIPLIER,
3751 /* Round to the nearest ICE_RL_PROF_MULTIPLIER */
3752 mv = round_up_64bit(mv_tmp, ICE_RL_PROF_MULTIPLIER);
3754 /* First multiplier value greater than the given
3757 if (mv > ICE_RL_PROF_ACCURACY_BYTES) {
3766 wm = ice_sched_calc_wakeup(bw);
3767 profile->rl_multiply = CPU_TO_LE16(mv);
3768 profile->wake_up_calc = CPU_TO_LE16(wm);
3769 profile->rl_encode = CPU_TO_LE16(encode);
3770 status = ICE_SUCCESS;
3772 status = ICE_ERR_DOES_NOT_EXIST;
3779 * ice_sched_add_rl_profile - add RL profile
3780 * @pi: port information structure
3781 * @rl_type: type of rate limit BW - min, max, or shared
3782 * @bw: bandwidth in Kbps - Kilo bits per sec
3783 * @layer_num: specifies in which layer to create profile
3785 * This function first checks the existing list for corresponding BW
3786 * parameter. If it exists, it returns the associated profile otherwise
3787 * it creates a new rate limit profile for requested BW, and adds it to
3788 * the HW DB and local list. It returns the new profile or null on error.
3789 * The caller needs to hold the scheduler lock.
3791 static struct ice_aqc_rl_profile_info *
3792 ice_sched_add_rl_profile(struct ice_port_info *pi,
3793 enum ice_rl_type rl_type, u32 bw, u8 layer_num)
3795 struct ice_aqc_rl_profile_generic_elem *buf;
3796 struct ice_aqc_rl_profile_info *rl_prof_elem;
3797 u16 profiles_added = 0, num_profiles = 1;
3798 enum ice_status status;
3802 if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM)
3806 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
3809 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
3812 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
3821 LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num],
3822 ice_aqc_rl_profile_info, list_entry)
3823 if (rl_prof_elem->profile.flags == profile_type &&
3824 rl_prof_elem->bw == bw)
3825 /* Return existing profile ID info */
3826 return rl_prof_elem;
3828 /* Create new profile ID */
3829 rl_prof_elem = (struct ice_aqc_rl_profile_info *)
3830 ice_malloc(hw, sizeof(*rl_prof_elem));
3835 status = ice_sched_bw_to_rl_profile(bw, &rl_prof_elem->profile);
3836 if (status != ICE_SUCCESS)
3837 goto exit_add_rl_prof;
3839 rl_prof_elem->bw = bw;
3840 /* layer_num is zero relative, and fw expects level from 1 to 9 */
3841 rl_prof_elem->profile.level = layer_num + 1;
3842 rl_prof_elem->profile.flags = profile_type;
3843 rl_prof_elem->profile.max_burst_size = CPU_TO_LE16(hw->max_burst_size);
3845 /* Create new entry in HW DB */
3846 buf = (struct ice_aqc_rl_profile_generic_elem *)
3847 &rl_prof_elem->profile;
3848 status = ice_aq_add_rl_profile(hw, num_profiles, buf, sizeof(*buf),
3849 &profiles_added, NULL);
3850 if (status || profiles_added != num_profiles)
3851 goto exit_add_rl_prof;
3853 /* Good entry - add in the list */
3854 rl_prof_elem->prof_id_ref = 0;
3855 LIST_ADD(&rl_prof_elem->list_entry, &pi->rl_prof_list[layer_num]);
3856 return rl_prof_elem;
3859 ice_free(hw, rl_prof_elem);
3864 * ice_sched_cfg_node_bw_lmt - configure node sched params
3865 * @hw: pointer to the HW struct
3866 * @node: sched node to configure
3867 * @rl_type: rate limit type CIR, EIR, or shared
3868 * @rl_prof_id: rate limit profile ID
3870 * This function configures node element's BW limit.
3872 static enum ice_status
3873 ice_sched_cfg_node_bw_lmt(struct ice_hw *hw, struct ice_sched_node *node,
3874 enum ice_rl_type rl_type, u16 rl_prof_id)
3876 struct ice_aqc_txsched_elem_data buf;
3877 struct ice_aqc_txsched_elem *data;
3883 data->valid_sections |= ICE_AQC_ELEM_VALID_CIR;
3884 data->cir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3887 /* EIR BW and Shared BW profiles are mutually exclusive and
3888 * hence only one of them may be set for any given element
3890 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
3892 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3893 data->eir_bw.bw_profile_idx = CPU_TO_LE16(rl_prof_id);
3896 /* Check for removing shared BW */
3897 if (rl_prof_id == ICE_SCHED_NO_SHARED_RL_PROF_ID) {
3898 /* remove shared profile */
3899 data->valid_sections &= ~ICE_AQC_ELEM_VALID_SHARED;
3900 data->srl_id = 0; /* clear SRL field */
3902 /* enable back EIR to default profile */
3903 data->valid_sections |= ICE_AQC_ELEM_VALID_EIR;
3904 data->eir_bw.bw_profile_idx =
3905 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
3908 /* EIR BW and Shared BW profiles are mutually exclusive and
3909 * hence only one of them may be set for any given element
3911 if ((data->valid_sections & ICE_AQC_ELEM_VALID_EIR) &&
3912 (LE16_TO_CPU(data->eir_bw.bw_profile_idx) !=
3913 ICE_SCHED_DFLT_RL_PROF_ID))
3915 /* EIR BW is set to default, disable it */
3916 data->valid_sections &= ~ICE_AQC_ELEM_VALID_EIR;
3917 /* Okay to enable shared BW now */
3918 data->valid_sections |= ICE_AQC_ELEM_VALID_SHARED;
3919 data->srl_id = CPU_TO_LE16(rl_prof_id);
3922 /* Unknown rate limit type */
3923 return ICE_ERR_PARAM;
3926 /* Configure element */
3927 return ice_sched_update_elem(hw, node, &buf);
3931 * ice_sched_get_node_rl_prof_id - get node's rate limit profile ID
3933 * @rl_type: rate limit type
3935 * If existing profile matches, it returns the corresponding rate
3936 * limit profile ID, otherwise it returns an invalid ID as error.
3939 ice_sched_get_node_rl_prof_id(struct ice_sched_node *node,
3940 enum ice_rl_type rl_type)
3942 u16 rl_prof_id = ICE_SCHED_INVAL_PROF_ID;
3943 struct ice_aqc_txsched_elem *data;
3945 data = &node->info.data;
3948 if (data->valid_sections & ICE_AQC_ELEM_VALID_CIR)
3949 rl_prof_id = LE16_TO_CPU(data->cir_bw.bw_profile_idx);
3952 if (data->valid_sections & ICE_AQC_ELEM_VALID_EIR)
3953 rl_prof_id = LE16_TO_CPU(data->eir_bw.bw_profile_idx);
3956 if (data->valid_sections & ICE_AQC_ELEM_VALID_SHARED)
3957 rl_prof_id = LE16_TO_CPU(data->srl_id);
3967 * ice_sched_get_rl_prof_layer - selects rate limit profile creation layer
3968 * @pi: port information structure
3969 * @rl_type: type of rate limit BW - min, max, or shared
3970 * @layer_index: layer index
3972 * This function returns requested profile creation layer.
3975 ice_sched_get_rl_prof_layer(struct ice_port_info *pi, enum ice_rl_type rl_type,
3978 struct ice_hw *hw = pi->hw;
3980 if (layer_index >= hw->num_tx_sched_layers)
3981 return ICE_SCHED_INVAL_LAYER_NUM;
3984 if (hw->layer_info[layer_index].max_cir_rl_profiles)
3988 if (hw->layer_info[layer_index].max_eir_rl_profiles)
3992 /* if current layer doesn't support SRL profile creation
3993 * then try a layer up or down.
3995 if (hw->layer_info[layer_index].max_srl_profiles)
3997 else if (layer_index < hw->num_tx_sched_layers - 1 &&
3998 hw->layer_info[layer_index + 1].max_srl_profiles)
3999 return layer_index + 1;
4000 else if (layer_index > 0 &&
4001 hw->layer_info[layer_index - 1].max_srl_profiles)
4002 return layer_index - 1;
4007 return ICE_SCHED_INVAL_LAYER_NUM;
4011 * ice_sched_get_srl_node - get shared rate limit node
4013 * @srl_layer: shared rate limit layer
4015 * This function returns SRL node to be used for shared rate limit purpose.
4016 * The caller needs to hold scheduler lock.
4018 static struct ice_sched_node *
4019 ice_sched_get_srl_node(struct ice_sched_node *node, u8 srl_layer)
4021 if (srl_layer > node->tx_sched_layer)
4022 return node->children[0];
4023 else if (srl_layer < node->tx_sched_layer)
4024 /* Node can't be created without a parent. It will always
4025 * have a valid parent except root node.
4027 return node->parent;
4033 * ice_sched_rm_rl_profile - remove RL profile ID
4034 * @pi: port information structure
4035 * @layer_num: layer number where profiles are saved
4036 * @profile_type: profile type like EIR, CIR, or SRL
4037 * @profile_id: profile ID to remove
4039 * This function removes rate limit profile from layer 'layer_num' of type
4040 * 'profile_type' and profile ID as 'profile_id'. The caller needs to hold
4043 static enum ice_status
4044 ice_sched_rm_rl_profile(struct ice_port_info *pi, u8 layer_num, u8 profile_type,
4047 struct ice_aqc_rl_profile_info *rl_prof_elem;
4048 enum ice_status status = ICE_SUCCESS;
4050 if (layer_num >= ICE_AQC_TOPO_MAX_LEVEL_NUM)
4051 return ICE_ERR_PARAM;
4052 /* Check the existing list for RL profile */
4053 LIST_FOR_EACH_ENTRY(rl_prof_elem, &pi->rl_prof_list[layer_num],
4054 ice_aqc_rl_profile_info, list_entry)
4055 if (rl_prof_elem->profile.flags == profile_type &&
4056 LE16_TO_CPU(rl_prof_elem->profile.profile_id) ==
4058 if (rl_prof_elem->prof_id_ref)
4059 rl_prof_elem->prof_id_ref--;
4061 /* Remove old profile ID from database */
4062 status = ice_sched_del_rl_profile(pi->hw, rl_prof_elem);
4063 if (status && status != ICE_ERR_IN_USE)
4064 ice_debug(pi->hw, ICE_DBG_SCHED,
4065 "Remove rl profile failed\n");
4068 if (status == ICE_ERR_IN_USE)
4069 status = ICE_SUCCESS;
4074 * ice_sched_set_node_bw_dflt - set node's bandwidth limit to default
4075 * @pi: port information structure
4076 * @node: pointer to node structure
4077 * @rl_type: rate limit type min, max, or shared
4078 * @layer_num: layer number where RL profiles are saved
4080 * This function configures node element's BW rate limit profile ID of
4081 * type CIR, EIR, or SRL to default. This function needs to be called
4082 * with the scheduler lock held.
4084 static enum ice_status
4085 ice_sched_set_node_bw_dflt(struct ice_port_info *pi,
4086 struct ice_sched_node *node,
4087 enum ice_rl_type rl_type, u8 layer_num)
4089 enum ice_status status;
4098 profile_type = ICE_AQC_RL_PROFILE_TYPE_CIR;
4099 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4102 profile_type = ICE_AQC_RL_PROFILE_TYPE_EIR;
4103 rl_prof_id = ICE_SCHED_DFLT_RL_PROF_ID;
4106 profile_type = ICE_AQC_RL_PROFILE_TYPE_SRL;
4107 /* No SRL is configured for default case */
4108 rl_prof_id = ICE_SCHED_NO_SHARED_RL_PROF_ID;
4111 return ICE_ERR_PARAM;
4113 /* Save existing RL prof ID for later clean up */
4114 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4115 /* Configure BW scheduling parameters */
4116 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4120 /* Remove stale RL profile ID */
4121 if (old_id == ICE_SCHED_DFLT_RL_PROF_ID ||
4122 old_id == ICE_SCHED_INVAL_PROF_ID)
4125 return ice_sched_rm_rl_profile(pi, layer_num, profile_type, old_id);
4129 * ice_sched_set_eir_srl_excl - set EIR/SRL exclusiveness
4130 * @pi: port information structure
4131 * @node: pointer to node structure
4132 * @layer_num: layer number where rate limit profiles are saved
4133 * @rl_type: rate limit type min, max, or shared
4134 * @bw: bandwidth value
4136 * This function prepares node element's bandwidth to SRL or EIR exclusively.
4137 * EIR BW and Shared BW profiles are mutually exclusive and hence only one of
4138 * them may be set for any given element. This function needs to be called
4139 * with the scheduler lock held.
4141 static enum ice_status
4142 ice_sched_set_eir_srl_excl(struct ice_port_info *pi,
4143 struct ice_sched_node *node,
4144 u8 layer_num, enum ice_rl_type rl_type, u32 bw)
4146 if (rl_type == ICE_SHARED_BW) {
4147 /* SRL node passed in this case, it may be different node */
4148 if (bw == ICE_SCHED_DFLT_BW)
4149 /* SRL being removed, ice_sched_cfg_node_bw_lmt()
4150 * enables EIR to default. EIR is not set in this
4151 * case, so no additional action is required.
4155 /* SRL being configured, set EIR to default here.
4156 * ice_sched_cfg_node_bw_lmt() disables EIR when it
4159 return ice_sched_set_node_bw_dflt(pi, node, ICE_MAX_BW,
4161 } else if (rl_type == ICE_MAX_BW &&
4162 node->info.data.valid_sections & ICE_AQC_ELEM_VALID_SHARED) {
4163 /* Remove Shared profile. Set default shared BW call
4164 * removes shared profile for a node.
4166 return ice_sched_set_node_bw_dflt(pi, node,
4174 * ice_sched_set_node_bw - set node's bandwidth
4175 * @pi: port information structure
4177 * @rl_type: rate limit type min, max, or shared
4178 * @bw: bandwidth in Kbps - Kilo bits per sec
4179 * @layer_num: layer number
4181 * This function adds new profile corresponding to requested BW, configures
4182 * node's RL profile ID of type CIR, EIR, or SRL, and removes old profile
4183 * ID from local database. The caller needs to hold scheduler lock.
4185 static enum ice_status
4186 ice_sched_set_node_bw(struct ice_port_info *pi, struct ice_sched_node *node,
4187 enum ice_rl_type rl_type, u32 bw, u8 layer_num)
4189 struct ice_aqc_rl_profile_info *rl_prof_info;
4190 enum ice_status status = ICE_ERR_PARAM;
4191 struct ice_hw *hw = pi->hw;
4192 u16 old_id, rl_prof_id;
4194 rl_prof_info = ice_sched_add_rl_profile(pi, rl_type, bw, layer_num);
4198 rl_prof_id = LE16_TO_CPU(rl_prof_info->profile.profile_id);
4200 /* Save existing RL prof ID for later clean up */
4201 old_id = ice_sched_get_node_rl_prof_id(node, rl_type);
4202 /* Configure BW scheduling parameters */
4203 status = ice_sched_cfg_node_bw_lmt(hw, node, rl_type, rl_prof_id);
4207 /* New changes has been applied */
4208 /* Increment the profile ID reference count */
4209 rl_prof_info->prof_id_ref++;
4211 /* Check for old ID removal */
4212 if ((old_id == ICE_SCHED_DFLT_RL_PROF_ID && rl_type != ICE_SHARED_BW) ||
4213 old_id == ICE_SCHED_INVAL_PROF_ID || old_id == rl_prof_id)
4216 return ice_sched_rm_rl_profile(pi, layer_num,
4217 rl_prof_info->profile.flags,
4222 * ice_sched_set_node_bw_lmt - set node's BW limit
4223 * @pi: port information structure
4225 * @rl_type: rate limit type min, max, or shared
4226 * @bw: bandwidth in Kbps - Kilo bits per sec
4228 * It updates node's BW limit parameters like BW RL profile ID of type CIR,
4229 * EIR, or SRL. The caller needs to hold scheduler lock.
4231 static enum ice_status
4232 ice_sched_set_node_bw_lmt(struct ice_port_info *pi, struct ice_sched_node *node,
4233 enum ice_rl_type rl_type, u32 bw)
4235 struct ice_sched_node *cfg_node = node;
4236 enum ice_status status;
4242 return ICE_ERR_PARAM;
4244 /* Remove unused RL profile IDs from HW and SW DB */
4245 ice_sched_rm_unused_rl_prof(pi);
4246 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4247 node->tx_sched_layer);
4248 if (layer_num >= hw->num_tx_sched_layers)
4249 return ICE_ERR_PARAM;
4251 if (rl_type == ICE_SHARED_BW) {
4252 /* SRL node may be different */
4253 cfg_node = ice_sched_get_srl_node(node, layer_num);
4257 /* EIR BW and Shared BW profiles are mutually exclusive and
4258 * hence only one of them may be set for any given element
4260 status = ice_sched_set_eir_srl_excl(pi, cfg_node, layer_num, rl_type,
4264 if (bw == ICE_SCHED_DFLT_BW)
4265 return ice_sched_set_node_bw_dflt(pi, cfg_node, rl_type,
4267 return ice_sched_set_node_bw(pi, cfg_node, rl_type, bw, layer_num);
4271 * ice_sched_set_node_bw_dflt_lmt - set node's BW limit to default
4272 * @pi: port information structure
4273 * @node: pointer to node structure
4274 * @rl_type: rate limit type min, max, or shared
4276 * This function configures node element's BW rate limit profile ID of
4277 * type CIR, EIR, or SRL to default. This function needs to be called
4278 * with the scheduler lock held.
4280 static enum ice_status
4281 ice_sched_set_node_bw_dflt_lmt(struct ice_port_info *pi,
4282 struct ice_sched_node *node,
4283 enum ice_rl_type rl_type)
4285 return ice_sched_set_node_bw_lmt(pi, node, rl_type,
4290 * ice_sched_validate_srl_node - Check node for SRL applicability
4291 * @node: sched node to configure
4292 * @sel_layer: selected SRL layer
4294 * This function checks if the SRL can be applied to a selceted layer node on
4295 * behalf of the requested node (first argument). This function needs to be
4296 * called with scheduler lock held.
4298 static enum ice_status
4299 ice_sched_validate_srl_node(struct ice_sched_node *node, u8 sel_layer)
4301 /* SRL profiles are not available on all layers. Check if the
4302 * SRL profile can be applied to a node above or below the
4303 * requested node. SRL configuration is possible only if the
4304 * selected layer's node has single child.
4306 if (sel_layer == node->tx_sched_layer ||
4307 ((sel_layer == node->tx_sched_layer + 1) &&
4308 node->num_children == 1) ||
4309 ((sel_layer == node->tx_sched_layer - 1) &&
4310 (node->parent && node->parent->num_children == 1)))
4317 * ice_sched_save_q_bw - save queue node's BW information
4318 * @q_ctx: queue context structure
4319 * @rl_type: rate limit type min, max, or shared
4320 * @bw: bandwidth in Kbps - Kilo bits per sec
4322 * Save BW information of queue type node for post replay use.
4324 static enum ice_status
4325 ice_sched_save_q_bw(struct ice_q_ctx *q_ctx, enum ice_rl_type rl_type, u32 bw)
4329 ice_set_clear_cir_bw(&q_ctx->bw_t_info, bw);
4332 ice_set_clear_eir_bw(&q_ctx->bw_t_info, bw);
4335 ice_set_clear_shared_bw(&q_ctx->bw_t_info, bw);
4338 return ICE_ERR_PARAM;
4344 * ice_sched_set_q_bw_lmt - sets queue BW limit
4345 * @pi: port information structure
4346 * @vsi_handle: sw VSI handle
4347 * @tc: traffic class
4348 * @q_handle: software queue handle
4349 * @rl_type: min, max, or shared
4350 * @bw: bandwidth in Kbps
4352 * This function sets BW limit of queue scheduling node.
4354 static enum ice_status
4355 ice_sched_set_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4356 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4358 enum ice_status status = ICE_ERR_PARAM;
4359 struct ice_sched_node *node;
4360 struct ice_q_ctx *q_ctx;
4362 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4363 return ICE_ERR_PARAM;
4364 ice_acquire_lock(&pi->sched_lock);
4365 q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handle);
4368 node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
4370 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong q_teid\n");
4374 /* Return error if it is not a leaf node */
4375 if (node->info.data.elem_type != ICE_AQC_ELEM_TYPE_LEAF)
4378 /* SRL bandwidth layer selection */
4379 if (rl_type == ICE_SHARED_BW) {
4380 u8 sel_layer; /* selected layer */
4382 sel_layer = ice_sched_get_rl_prof_layer(pi, rl_type,
4383 node->tx_sched_layer);
4384 if (sel_layer >= pi->hw->num_tx_sched_layers) {
4385 status = ICE_ERR_PARAM;
4388 status = ice_sched_validate_srl_node(node, sel_layer);
4393 if (bw == ICE_SCHED_DFLT_BW)
4394 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4396 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4399 status = ice_sched_save_q_bw(q_ctx, rl_type, bw);
4402 ice_release_lock(&pi->sched_lock);
4407 * ice_cfg_q_bw_lmt - configure queue BW limit
4408 * @pi: port information structure
4409 * @vsi_handle: sw VSI handle
4410 * @tc: traffic class
4411 * @q_handle: software queue handle
4412 * @rl_type: min, max, or shared
4413 * @bw: bandwidth in Kbps
4415 * This function configures BW limit of queue scheduling node.
4418 ice_cfg_q_bw_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4419 u16 q_handle, enum ice_rl_type rl_type, u32 bw)
4421 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4426 * ice_cfg_q_bw_dflt_lmt - configure queue BW default limit
4427 * @pi: port information structure
4428 * @vsi_handle: sw VSI handle
4429 * @tc: traffic class
4430 * @q_handle: software queue handle
4431 * @rl_type: min, max, or shared
4433 * This function configures BW default limit of queue scheduling node.
4436 ice_cfg_q_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
4437 u16 q_handle, enum ice_rl_type rl_type)
4439 return ice_sched_set_q_bw_lmt(pi, vsi_handle, tc, q_handle, rl_type,
4444 * ice_sched_save_tc_node_bw - save TC node BW limit
4445 * @pi: port information structure
4447 * @rl_type: min or max
4448 * @bw: bandwidth in Kbps
4450 * This function saves the modified values of bandwidth settings for later
4451 * replay purpose (restore) after reset.
4453 static enum ice_status
4454 ice_sched_save_tc_node_bw(struct ice_port_info *pi, u8 tc,
4455 enum ice_rl_type rl_type, u32 bw)
4457 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4458 return ICE_ERR_PARAM;
4461 ice_set_clear_cir_bw(&pi->tc_node_bw_t_info[tc], bw);
4464 ice_set_clear_eir_bw(&pi->tc_node_bw_t_info[tc], bw);
4467 ice_set_clear_shared_bw(&pi->tc_node_bw_t_info[tc], bw);
4470 return ICE_ERR_PARAM;
4476 * ice_sched_set_tc_node_bw_lmt - sets TC node BW limit
4477 * @pi: port information structure
4479 * @rl_type: min or max
4480 * @bw: bandwidth in Kbps
4482 * This function configures bandwidth limit of TC node.
4484 static enum ice_status
4485 ice_sched_set_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4486 enum ice_rl_type rl_type, u32 bw)
4488 enum ice_status status = ICE_ERR_PARAM;
4489 struct ice_sched_node *tc_node;
4491 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4493 ice_acquire_lock(&pi->sched_lock);
4494 tc_node = ice_sched_get_tc_node(pi, tc);
4496 goto exit_set_tc_node_bw;
4497 if (bw == ICE_SCHED_DFLT_BW)
4498 status = ice_sched_set_node_bw_dflt_lmt(pi, tc_node, rl_type);
4500 status = ice_sched_set_node_bw_lmt(pi, tc_node, rl_type, bw);
4502 status = ice_sched_save_tc_node_bw(pi, tc, rl_type, bw);
4504 exit_set_tc_node_bw:
4505 ice_release_lock(&pi->sched_lock);
4510 * ice_cfg_tc_node_bw_lmt - configure TC node BW limit
4511 * @pi: port information structure
4513 * @rl_type: min or max
4514 * @bw: bandwidth in Kbps
4516 * This function configures BW limit of TC node.
4517 * Note: The minimum guaranteed reservation is done via DCBX.
4520 ice_cfg_tc_node_bw_lmt(struct ice_port_info *pi, u8 tc,
4521 enum ice_rl_type rl_type, u32 bw)
4523 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, bw);
4527 * ice_cfg_tc_node_bw_dflt_lmt - configure TC node BW default limit
4528 * @pi: port information structure
4530 * @rl_type: min or max
4532 * This function configures BW default limit of TC node.
4535 ice_cfg_tc_node_bw_dflt_lmt(struct ice_port_info *pi, u8 tc,
4536 enum ice_rl_type rl_type)
4538 return ice_sched_set_tc_node_bw_lmt(pi, tc, rl_type, ICE_SCHED_DFLT_BW);
4542 * ice_sched_save_tc_node_bw_alloc - save TC node's BW alloc information
4543 * @pi: port information structure
4544 * @tc: traffic class
4545 * @rl_type: rate limit type min or max
4546 * @bw_alloc: Bandwidth allocation information
4548 * Save BW alloc information of VSI type node for post replay use.
4550 static enum ice_status
4551 ice_sched_save_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4552 enum ice_rl_type rl_type, u16 bw_alloc)
4554 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4555 return ICE_ERR_PARAM;
4558 ice_set_clear_cir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4562 ice_set_clear_eir_bw_alloc(&pi->tc_node_bw_t_info[tc],
4566 return ICE_ERR_PARAM;
4572 * ice_sched_set_tc_node_bw_alloc - set TC node BW alloc
4573 * @pi: port information structure
4575 * @rl_type: min or max
4576 * @bw_alloc: bandwidth alloc
4578 * This function configures bandwidth alloc of TC node, also saves the
4579 * changed settings for replay purpose, and return success if it succeeds
4580 * in modifying bandwidth alloc setting.
4582 static enum ice_status
4583 ice_sched_set_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4584 enum ice_rl_type rl_type, u8 bw_alloc)
4586 enum ice_status status = ICE_ERR_PARAM;
4587 struct ice_sched_node *tc_node;
4589 if (tc >= ICE_MAX_TRAFFIC_CLASS)
4591 ice_acquire_lock(&pi->sched_lock);
4592 tc_node = ice_sched_get_tc_node(pi, tc);
4594 goto exit_set_tc_node_bw_alloc;
4595 status = ice_sched_cfg_node_bw_alloc(pi->hw, tc_node, rl_type,
4598 goto exit_set_tc_node_bw_alloc;
4599 status = ice_sched_save_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4601 exit_set_tc_node_bw_alloc:
4602 ice_release_lock(&pi->sched_lock);
4607 * ice_cfg_tc_node_bw_alloc - configure TC node BW alloc
4608 * @pi: port information structure
4610 * @rl_type: min or max
4611 * @bw_alloc: bandwidth alloc
4613 * This function configures BW limit of TC node.
4614 * Note: The minimum guaranteed reservation is done via DCBX.
4617 ice_cfg_tc_node_bw_alloc(struct ice_port_info *pi, u8 tc,
4618 enum ice_rl_type rl_type, u8 bw_alloc)
4620 return ice_sched_set_tc_node_bw_alloc(pi, tc, rl_type, bw_alloc);
4624 * ice_sched_set_agg_bw_dflt_lmt - set aggregator node's BW limit to default
4625 * @pi: port information structure
4626 * @vsi_handle: software VSI handle
4628 * This function retrieves the aggregator ID based on VSI ID and TC,
4629 * and sets node's BW limit to default. This function needs to be
4630 * called with the scheduler lock held.
4633 ice_sched_set_agg_bw_dflt_lmt(struct ice_port_info *pi, u16 vsi_handle)
4635 struct ice_vsi_ctx *vsi_ctx;
4636 enum ice_status status = ICE_SUCCESS;
4639 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4640 return ICE_ERR_PARAM;
4641 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4643 return ICE_ERR_PARAM;
4645 ice_for_each_traffic_class(tc) {
4646 struct ice_sched_node *node;
4648 node = vsi_ctx->sched.ag_node[tc];
4652 /* Set min profile to default */
4653 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MIN_BW);
4657 /* Set max profile to default */
4658 status = ice_sched_set_node_bw_dflt_lmt(pi, node, ICE_MAX_BW);
4662 /* Remove shared profile, if there is one */
4663 status = ice_sched_set_node_bw_dflt_lmt(pi, node,
4673 * ice_sched_get_node_by_id_type - get node from ID type
4674 * @pi: port information structure
4676 * @agg_type: type of aggregator
4677 * @tc: traffic class
4679 * This function returns node identified by ID of type aggregator, and
4680 * based on traffic class (TC). This function needs to be called with
4681 * the scheduler lock held.
4683 static struct ice_sched_node *
4684 ice_sched_get_node_by_id_type(struct ice_port_info *pi, u32 id,
4685 enum ice_agg_type agg_type, u8 tc)
4687 struct ice_sched_node *node = NULL;
4688 struct ice_sched_node *child_node;
4691 case ICE_AGG_TYPE_VSI: {
4692 struct ice_vsi_ctx *vsi_ctx;
4693 u16 vsi_handle = (u16)id;
4695 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4697 /* Get sched_vsi_info */
4698 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
4701 node = vsi_ctx->sched.vsi_node[tc];
4705 case ICE_AGG_TYPE_AGG: {
4706 struct ice_sched_node *tc_node;
4708 tc_node = ice_sched_get_tc_node(pi, tc);
4710 node = ice_sched_get_agg_node(pi, tc_node, id);
4714 case ICE_AGG_TYPE_Q:
4715 /* The current implementation allows single queue to modify */
4716 node = ice_sched_get_node(pi, id);
4719 case ICE_AGG_TYPE_QG:
4720 /* The current implementation allows single qg to modify */
4721 child_node = ice_sched_get_node(pi, id);
4724 node = child_node->parent;
4735 * ice_sched_set_node_bw_lmt_per_tc - set node BW limit per TC
4736 * @pi: port information structure
4737 * @id: ID (software VSI handle or AGG ID)
4738 * @agg_type: aggregator type (VSI or AGG type node)
4739 * @tc: traffic class
4740 * @rl_type: min or max
4741 * @bw: bandwidth in Kbps
4743 * This function sets BW limit of VSI or Aggregator scheduling node
4744 * based on TC information from passed in argument BW.
4747 ice_sched_set_node_bw_lmt_per_tc(struct ice_port_info *pi, u32 id,
4748 enum ice_agg_type agg_type, u8 tc,
4749 enum ice_rl_type rl_type, u32 bw)
4751 enum ice_status status = ICE_ERR_PARAM;
4752 struct ice_sched_node *node;
4757 if (rl_type == ICE_UNKNOWN_BW)
4760 ice_acquire_lock(&pi->sched_lock);
4761 node = ice_sched_get_node_by_id_type(pi, id, agg_type, tc);
4763 ice_debug(pi->hw, ICE_DBG_SCHED, "Wrong id, agg type, or tc\n");
4764 goto exit_set_node_bw_lmt_per_tc;
4766 if (bw == ICE_SCHED_DFLT_BW)
4767 status = ice_sched_set_node_bw_dflt_lmt(pi, node, rl_type);
4769 status = ice_sched_set_node_bw_lmt(pi, node, rl_type, bw);
4771 exit_set_node_bw_lmt_per_tc:
4772 ice_release_lock(&pi->sched_lock);
4777 * ice_sched_validate_vsi_srl_node - validate VSI SRL node
4778 * @pi: port information structure
4779 * @vsi_handle: software VSI handle
4781 * This function validates SRL node of the VSI node if available SRL layer is
4782 * different than the VSI node layer on all TC(s).This function needs to be
4783 * called with scheduler lock held.
4785 static enum ice_status
4786 ice_sched_validate_vsi_srl_node(struct ice_port_info *pi, u16 vsi_handle)
4788 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4791 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4792 return ICE_ERR_PARAM;
4794 /* Return success if no nodes are present across TC */
4795 ice_for_each_traffic_class(tc) {
4796 struct ice_sched_node *tc_node, *vsi_node;
4797 enum ice_rl_type rl_type = ICE_SHARED_BW;
4798 enum ice_status status;
4800 tc_node = ice_sched_get_tc_node(pi, tc);
4804 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4808 /* SRL bandwidth layer selection */
4809 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4810 u8 node_layer = vsi_node->tx_sched_layer;
4813 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4815 if (layer_num >= pi->hw->num_tx_sched_layers)
4816 return ICE_ERR_PARAM;
4817 sel_layer = layer_num;
4820 status = ice_sched_validate_srl_node(vsi_node, sel_layer);
4828 * ice_sched_set_vsi_bw_shared_lmt - set VSI BW shared limit
4829 * @pi: port information structure
4830 * @vsi_handle: software VSI handle
4831 * @bw: bandwidth in Kbps
4833 * This function Configures shared rate limiter(SRL) of all VSI type nodes
4834 * across all traffic classes for VSI matching handle. When BW value of
4835 * ICE_SCHED_DFLT_BW is passed, it removes the SRL from the node.
4838 ice_sched_set_vsi_bw_shared_lmt(struct ice_port_info *pi, u16 vsi_handle,
4841 enum ice_status status = ICE_SUCCESS;
4845 return ICE_ERR_PARAM;
4847 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4848 return ICE_ERR_PARAM;
4850 ice_acquire_lock(&pi->sched_lock);
4851 status = ice_sched_validate_vsi_srl_node(pi, vsi_handle);
4853 goto exit_set_vsi_bw_shared_lmt;
4854 /* Return success if no nodes are present across TC */
4855 ice_for_each_traffic_class(tc) {
4856 struct ice_sched_node *tc_node, *vsi_node;
4857 enum ice_rl_type rl_type = ICE_SHARED_BW;
4859 tc_node = ice_sched_get_tc_node(pi, tc);
4863 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
4867 if (bw == ICE_SCHED_DFLT_BW)
4868 /* It removes existing SRL from the node */
4869 status = ice_sched_set_node_bw_dflt_lmt(pi, vsi_node,
4872 status = ice_sched_set_node_bw_lmt(pi, vsi_node,
4876 status = ice_sched_save_vsi_bw(pi, vsi_handle, tc, rl_type, bw);
4881 exit_set_vsi_bw_shared_lmt:
4882 ice_release_lock(&pi->sched_lock);
4887 * ice_sched_validate_agg_srl_node - validate AGG SRL node
4888 * @pi: port information structure
4889 * @agg_id: aggregator ID
4891 * This function validates SRL node of the AGG node if available SRL layer is
4892 * different than the AGG node layer on all TC(s).This function needs to be
4893 * called with scheduler lock held.
4895 static enum ice_status
4896 ice_sched_validate_agg_srl_node(struct ice_port_info *pi, u32 agg_id)
4898 u8 sel_layer = ICE_SCHED_INVAL_LAYER_NUM;
4899 struct ice_sched_agg_info *agg_info;
4900 bool agg_id_present = false;
4901 enum ice_status status = ICE_SUCCESS;
4904 LIST_FOR_EACH_ENTRY(agg_info, &pi->hw->agg_list, ice_sched_agg_info,
4906 if (agg_info->agg_id == agg_id) {
4907 agg_id_present = true;
4910 if (!agg_id_present)
4911 return ICE_ERR_PARAM;
4912 /* Return success if no nodes are present across TC */
4913 ice_for_each_traffic_class(tc) {
4914 struct ice_sched_node *tc_node, *agg_node;
4915 enum ice_rl_type rl_type = ICE_SHARED_BW;
4917 tc_node = ice_sched_get_tc_node(pi, tc);
4921 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
4924 /* SRL bandwidth layer selection */
4925 if (sel_layer == ICE_SCHED_INVAL_LAYER_NUM) {
4926 u8 node_layer = agg_node->tx_sched_layer;
4929 layer_num = ice_sched_get_rl_prof_layer(pi, rl_type,
4931 if (layer_num >= pi->hw->num_tx_sched_layers)
4932 return ICE_ERR_PARAM;
4933 sel_layer = layer_num;
4936 status = ice_sched_validate_srl_node(agg_node, sel_layer);
4944 * ice_sched_set_agg_bw_shared_lmt - set aggregator BW shared limit
4945 * @pi: port information structure
4946 * @agg_id: aggregator ID
4947 * @bw: bandwidth in Kbps
4949 * This function configures the shared rate limiter(SRL) of all aggregator type
4950 * nodes across all traffic classes for aggregator matching agg_id. When
4951 * BW value of ICE_SCHED_DFLT_BW is passed, it removes SRL from the
4955 ice_sched_set_agg_bw_shared_lmt(struct ice_port_info *pi, u32 agg_id, u32 bw)
4957 struct ice_sched_agg_info *agg_info;
4958 struct ice_sched_agg_info *tmp;
4959 bool agg_id_present = false;
4960 enum ice_status status = ICE_SUCCESS;
4964 return ICE_ERR_PARAM;
4966 ice_acquire_lock(&pi->sched_lock);
4967 status = ice_sched_validate_agg_srl_node(pi, agg_id);
4969 goto exit_agg_bw_shared_lmt;
4971 LIST_FOR_EACH_ENTRY_SAFE(agg_info, tmp, &pi->hw->agg_list,
4972 ice_sched_agg_info, list_entry)
4973 if (agg_info->agg_id == agg_id) {
4974 agg_id_present = true;
4978 if (!agg_id_present) {
4979 status = ICE_ERR_PARAM;
4980 goto exit_agg_bw_shared_lmt;
4983 /* Return success if no nodes are present across TC */
4984 ice_for_each_traffic_class(tc) {
4985 enum ice_rl_type rl_type = ICE_SHARED_BW;
4986 struct ice_sched_node *tc_node, *agg_node;
4988 tc_node = ice_sched_get_tc_node(pi, tc);
4992 agg_node = ice_sched_get_agg_node(pi, tc_node, agg_id);
4996 if (bw == ICE_SCHED_DFLT_BW)
4997 /* It removes existing SRL from the node */
4998 status = ice_sched_set_node_bw_dflt_lmt(pi, agg_node,
5001 status = ice_sched_set_node_bw_lmt(pi, agg_node,
5005 status = ice_sched_save_agg_bw(pi, agg_id, tc, rl_type, bw);
5010 exit_agg_bw_shared_lmt:
5011 ice_release_lock(&pi->sched_lock);
5016 * ice_sched_cfg_sibl_node_prio - configure node sibling priority
5017 * @pi: port information structure
5018 * @node: sched node to configure
5019 * @priority: sibling priority
5021 * This function configures node element's sibling priority only. This
5022 * function needs to be called with scheduler lock held.
5025 ice_sched_cfg_sibl_node_prio(struct ice_port_info *pi,
5026 struct ice_sched_node *node, u8 priority)
5028 struct ice_aqc_txsched_elem_data buf;
5029 struct ice_aqc_txsched_elem *data;
5030 struct ice_hw *hw = pi->hw;
5031 enum ice_status status;
5034 return ICE_ERR_PARAM;
5037 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5038 priority = (priority << ICE_AQC_ELEM_GENERIC_PRIO_S) &
5039 ICE_AQC_ELEM_GENERIC_PRIO_M;
5040 data->generic &= ~ICE_AQC_ELEM_GENERIC_PRIO_M;
5041 data->generic |= priority;
5043 /* Configure element */
5044 status = ice_sched_update_elem(hw, node, &buf);
5049 * ice_cfg_rl_burst_size - Set burst size value
5050 * @hw: pointer to the HW struct
5051 * @bytes: burst size in bytes
5053 * This function configures/set the burst size to requested new value. The new
5054 * burst size value is used for future rate limit calls. It doesn't change the
5055 * existing or previously created RL profiles.
5057 enum ice_status ice_cfg_rl_burst_size(struct ice_hw *hw, u32 bytes)
5059 u16 burst_size_to_prog;
5061 if (bytes < ICE_MIN_BURST_SIZE_ALLOWED ||
5062 bytes > ICE_MAX_BURST_SIZE_ALLOWED)
5063 return ICE_ERR_PARAM;
5064 if (ice_round_to_num(bytes, 64) <=
5065 ICE_MAX_BURST_SIZE_64_BYTE_GRANULARITY) {
5066 /* 64 byte granularity case */
5067 /* Disable MSB granularity bit */
5068 burst_size_to_prog = ICE_64_BYTE_GRANULARITY;
5069 /* round number to nearest 64 byte granularity */
5070 bytes = ice_round_to_num(bytes, 64);
5071 /* The value is in 64 byte chunks */
5072 burst_size_to_prog |= (u16)(bytes / 64);
5074 /* k bytes granularity case */
5075 /* Enable MSB granularity bit */
5076 burst_size_to_prog = ICE_KBYTE_GRANULARITY;
5077 /* round number to nearest 1024 granularity */
5078 bytes = ice_round_to_num(bytes, 1024);
5079 /* check rounding doesn't go beyond allowed */
5080 if (bytes > ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY)
5081 bytes = ICE_MAX_BURST_SIZE_KBYTE_GRANULARITY;
5082 /* The value is in k bytes */
5083 burst_size_to_prog |= (u16)(bytes / 1024);
5085 hw->max_burst_size = burst_size_to_prog;
5090 * ice_sched_replay_node_prio - re-configure node priority
5091 * @hw: pointer to the HW struct
5092 * @node: sched node to configure
5093 * @priority: priority value
5095 * This function configures node element's priority value. It
5096 * needs to be called with scheduler lock held.
5098 static enum ice_status
5099 ice_sched_replay_node_prio(struct ice_hw *hw, struct ice_sched_node *node,
5102 struct ice_aqc_txsched_elem_data buf;
5103 struct ice_aqc_txsched_elem *data;
5104 enum ice_status status;
5108 data->valid_sections |= ICE_AQC_ELEM_VALID_GENERIC;
5109 data->generic = priority;
5111 /* Configure element */
5112 status = ice_sched_update_elem(hw, node, &buf);
5117 * ice_sched_replay_node_bw - replay node(s) BW
5118 * @hw: pointer to the HW struct
5119 * @node: sched node to configure
5120 * @bw_t_info: BW type information
5122 * This function restores node's BW from bw_t_info. The caller needs
5123 * to hold the scheduler lock.
5125 static enum ice_status
5126 ice_sched_replay_node_bw(struct ice_hw *hw, struct ice_sched_node *node,
5127 struct ice_bw_type_info *bw_t_info)
5129 struct ice_port_info *pi = hw->port_info;
5130 enum ice_status status = ICE_ERR_PARAM;
5135 if (!ice_is_any_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CNT))
5137 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_PRIO)) {
5138 status = ice_sched_replay_node_prio(hw, node,
5139 bw_t_info->generic);
5143 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR)) {
5144 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MIN_BW,
5145 bw_t_info->cir_bw.bw);
5149 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_CIR_WT)) {
5150 bw_alloc = bw_t_info->cir_bw.bw_alloc;
5151 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MIN_BW,
5156 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR)) {
5157 status = ice_sched_set_node_bw_lmt(pi, node, ICE_MAX_BW,
5158 bw_t_info->eir_bw.bw);
5162 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_EIR_WT)) {
5163 bw_alloc = bw_t_info->eir_bw.bw_alloc;
5164 status = ice_sched_cfg_node_bw_alloc(hw, node, ICE_MAX_BW,
5169 if (ice_is_bit_set(bw_t_info->bw_t_bitmap, ICE_BW_TYPE_SHARED))
5170 status = ice_sched_set_node_bw_lmt(pi, node, ICE_SHARED_BW,
5171 bw_t_info->shared_bw);
5176 * ice_sched_replay_agg_bw - replay aggregator node(s) BW
5177 * @hw: pointer to the HW struct
5178 * @agg_info: aggregator data structure
5180 * This function re-creates aggregator type nodes. The caller needs to hold
5181 * the scheduler lock.
5183 static enum ice_status
5184 ice_sched_replay_agg_bw(struct ice_hw *hw, struct ice_sched_agg_info *agg_info)
5186 struct ice_sched_node *tc_node, *agg_node;
5187 enum ice_status status = ICE_SUCCESS;
5191 return ICE_ERR_PARAM;
5192 ice_for_each_traffic_class(tc) {
5193 if (!ice_is_any_bit_set(agg_info->bw_t_info[tc].bw_t_bitmap,
5196 tc_node = ice_sched_get_tc_node(hw->port_info, tc);
5198 status = ICE_ERR_PARAM;
5201 agg_node = ice_sched_get_agg_node(hw->port_info, tc_node,
5204 status = ICE_ERR_PARAM;
5207 status = ice_sched_replay_node_bw(hw, agg_node,
5208 &agg_info->bw_t_info[tc]);
5216 * ice_sched_get_ena_tc_bitmap - get enabled TC bitmap
5217 * @pi: port info struct
5218 * @tc_bitmap: 8 bits TC bitmap to check
5219 * @ena_tc_bitmap: 8 bits enabled TC bitmap to return
5221 * This function returns enabled TC bitmap in variable ena_tc_bitmap. Some TCs
5222 * may be missing, it returns enabled TCs. This function needs to be called with
5223 * scheduler lock held.
5226 ice_sched_get_ena_tc_bitmap(struct ice_port_info *pi, ice_bitmap_t *tc_bitmap,
5227 ice_bitmap_t *ena_tc_bitmap)
5231 /* Some TC(s) may be missing after reset, adjust for replay */
5232 ice_for_each_traffic_class(tc)
5233 if (ice_is_tc_ena(*tc_bitmap, tc) &&
5234 (ice_sched_get_tc_node(pi, tc)))
5235 ice_set_bit(tc, ena_tc_bitmap);
5239 * ice_sched_replay_agg - recreate aggregator node(s)
5240 * @hw: pointer to the HW struct
5242 * This function recreate aggregator type nodes which are not replayed earlier.
5243 * It also replay aggregator BW information. These aggregator nodes are not
5244 * associated with VSI type node yet.
5246 void ice_sched_replay_agg(struct ice_hw *hw)
5248 struct ice_port_info *pi = hw->port_info;
5249 struct ice_sched_agg_info *agg_info;
5251 ice_acquire_lock(&pi->sched_lock);
5252 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5254 /* replay aggregator (re-create aggregator node) */
5255 if (!ice_cmp_bitmap(agg_info->tc_bitmap,
5256 agg_info->replay_tc_bitmap,
5257 ICE_MAX_TRAFFIC_CLASS)) {
5258 ice_declare_bitmap(replay_bitmap,
5259 ICE_MAX_TRAFFIC_CLASS);
5260 enum ice_status status;
5262 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5263 ice_sched_get_ena_tc_bitmap(pi,
5264 agg_info->replay_tc_bitmap,
5266 status = ice_sched_cfg_agg(hw->port_info,
5271 ice_info(hw, "Replay agg id[%d] failed\n",
5273 /* Move on to next one */
5276 /* Replay aggregator node BW (restore aggregator BW) */
5277 status = ice_sched_replay_agg_bw(hw, agg_info);
5279 ice_info(hw, "Replay agg bw [id=%d] failed\n",
5283 ice_release_lock(&pi->sched_lock);
5287 * ice_sched_replay_agg_vsi_preinit - Agg/VSI replay pre initialization
5288 * @hw: pointer to the HW struct
5290 * This function initialize aggregator(s) TC bitmap to zero. A required
5291 * preinit step for replaying aggregators.
5293 void ice_sched_replay_agg_vsi_preinit(struct ice_hw *hw)
5295 struct ice_port_info *pi = hw->port_info;
5296 struct ice_sched_agg_info *agg_info;
5298 ice_acquire_lock(&pi->sched_lock);
5299 LIST_FOR_EACH_ENTRY(agg_info, &hw->agg_list, ice_sched_agg_info,
5301 struct ice_sched_agg_vsi_info *agg_vsi_info;
5303 agg_info->tc_bitmap[0] = 0;
5304 LIST_FOR_EACH_ENTRY(agg_vsi_info, &agg_info->agg_vsi_list,
5305 ice_sched_agg_vsi_info, list_entry)
5306 agg_vsi_info->tc_bitmap[0] = 0;
5308 ice_release_lock(&pi->sched_lock);
5312 * ice_sched_replay_tc_node_bw - replay TC node(s) BW
5313 * @pi: port information structure
5315 * This function replay TC nodes.
5318 ice_sched_replay_tc_node_bw(struct ice_port_info *pi)
5320 enum ice_status status = ICE_SUCCESS;
5324 return ICE_ERR_PARAM;
5325 ice_acquire_lock(&pi->sched_lock);
5326 ice_for_each_traffic_class(tc) {
5327 struct ice_sched_node *tc_node;
5329 tc_node = ice_sched_get_tc_node(pi, tc);
5331 continue; /* TC not present */
5332 status = ice_sched_replay_node_bw(pi->hw, tc_node,
5333 &pi->tc_node_bw_t_info[tc]);
5337 ice_release_lock(&pi->sched_lock);
5342 * ice_sched_replay_vsi_bw - replay VSI type node(s) BW
5343 * @hw: pointer to the HW struct
5344 * @vsi_handle: software VSI handle
5345 * @tc_bitmap: 8 bits TC bitmap
5347 * This function replays VSI type nodes bandwidth. This function needs to be
5348 * called with scheduler lock held.
5350 static enum ice_status
5351 ice_sched_replay_vsi_bw(struct ice_hw *hw, u16 vsi_handle,
5352 ice_bitmap_t *tc_bitmap)
5354 struct ice_sched_node *vsi_node, *tc_node;
5355 struct ice_port_info *pi = hw->port_info;
5356 struct ice_bw_type_info *bw_t_info;
5357 struct ice_vsi_ctx *vsi_ctx;
5358 enum ice_status status = ICE_SUCCESS;
5361 vsi_ctx = ice_get_vsi_ctx(pi->hw, vsi_handle);
5363 return ICE_ERR_PARAM;
5364 ice_for_each_traffic_class(tc) {
5365 if (!ice_is_tc_ena(*tc_bitmap, tc))
5367 tc_node = ice_sched_get_tc_node(pi, tc);
5370 vsi_node = ice_sched_get_vsi_node(pi, tc_node, vsi_handle);
5373 bw_t_info = &vsi_ctx->sched.bw_t_info[tc];
5374 status = ice_sched_replay_node_bw(hw, vsi_node, bw_t_info);
5382 * ice_sched_replay_vsi_agg - replay aggregator & VSI to aggregator node(s)
5383 * @hw: pointer to the HW struct
5384 * @vsi_handle: software VSI handle
5386 * This function replays aggregator node, VSI to aggregator type nodes, and
5387 * their node bandwidth information. This function needs to be called with
5388 * scheduler lock held.
5390 static enum ice_status
5391 ice_sched_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5393 ice_declare_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5394 struct ice_sched_agg_vsi_info *agg_vsi_info;
5395 struct ice_port_info *pi = hw->port_info;
5396 struct ice_sched_agg_info *agg_info;
5397 enum ice_status status;
5399 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5400 if (!ice_is_vsi_valid(hw, vsi_handle))
5401 return ICE_ERR_PARAM;
5402 agg_info = ice_get_vsi_agg_info(hw, vsi_handle);
5404 return ICE_SUCCESS; /* Not present in list - default Agg case */
5405 agg_vsi_info = ice_get_agg_vsi_info(agg_info, vsi_handle);
5407 return ICE_SUCCESS; /* Not present in list - default Agg case */
5408 ice_sched_get_ena_tc_bitmap(pi, agg_info->replay_tc_bitmap,
5410 /* Replay aggregator node associated to vsi_handle */
5411 status = ice_sched_cfg_agg(hw->port_info, agg_info->agg_id,
5412 ICE_AGG_TYPE_AGG, replay_bitmap);
5415 /* Replay aggregator node BW (restore aggregator BW) */
5416 status = ice_sched_replay_agg_bw(hw, agg_info);
5420 ice_zero_bitmap(replay_bitmap, ICE_MAX_TRAFFIC_CLASS);
5421 ice_sched_get_ena_tc_bitmap(pi, agg_vsi_info->replay_tc_bitmap,
5423 /* Move this VSI (vsi_handle) to above aggregator */
5424 status = ice_sched_assoc_vsi_to_agg(pi, agg_info->agg_id, vsi_handle,
5428 /* Replay VSI BW (restore VSI BW) */
5429 return ice_sched_replay_vsi_bw(hw, vsi_handle,
5430 agg_vsi_info->tc_bitmap);
5434 * ice_replay_vsi_agg - replay VSI to aggregator node
5435 * @hw: pointer to the HW struct
5436 * @vsi_handle: software VSI handle
5438 * This function replays association of VSI to aggregator type nodes, and
5439 * node bandwidth information.
5442 ice_replay_vsi_agg(struct ice_hw *hw, u16 vsi_handle)
5444 struct ice_port_info *pi = hw->port_info;
5445 enum ice_status status;
5447 ice_acquire_lock(&pi->sched_lock);
5448 status = ice_sched_replay_vsi_agg(hw, vsi_handle);
5449 ice_release_lock(&pi->sched_lock);
5454 * ice_sched_replay_q_bw - replay queue type node BW
5455 * @pi: port information structure
5456 * @q_ctx: queue context structure
5458 * This function replays queue type node bandwidth. This function needs to be
5459 * called with scheduler lock held.
5462 ice_sched_replay_q_bw(struct ice_port_info *pi, struct ice_q_ctx *q_ctx)
5464 struct ice_sched_node *q_node;
5466 /* Following also checks the presence of node in tree */
5467 q_node = ice_sched_find_node_by_teid(pi->root, q_ctx->q_teid);
5469 return ICE_ERR_PARAM;
5470 return ice_sched_replay_node_bw(pi->hw, q_node, &q_ctx->bw_t_info);